Skip to content

Commit

Permalink
feat: pre-process buffer file names.
Browse files Browse the repository at this point in the history
Close #673.
  • Loading branch information
seagle0128 committed Oct 23, 2023
1 parent 28b0dc3 commit f06950b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ Run `M-x customize-group RET doom-modeline RET` or set the variables.
;; If nil, display only if the mode line is active.
(setq doom-modeline-display-misc-in-all-mode-lines t)
;; The function to handle `buffer-file-name'.
(setq doom-modeline-buffer-file-name-function #'identity)
;; The function to handle `buffer-file-truename'.
(setq doom-modeline-buffer-file-truename-function #'identity)
;; Whether display the environment version.
(setq doom-modeline-env-version t)
;; Or for individual languages
Expand Down
31 changes: 28 additions & 3 deletions doom-modeline-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,16 @@ If nil, display only if the mode line is active."
:type '(repeat symbol)
:group 'doom-modeline)

(defcustom doom-modeline-buffer-file-name-function #'identity
"The function to handle `buffer-file-name'."
:type 'function
:group 'doom-modeline)

(defcustom doom-modeline-buffer-file-truename-function #'identity
"The function to handle `buffer-file-truename'."
:type 'function
:group 'doom-modeline)


;;
;; Faces
Expand Down Expand Up @@ -1412,11 +1422,26 @@ Return nil if no project was found."
Return `default-directory' if no project was found."
(or (doom-modeline--project-root) default-directory))

(defun doom-modeline--format-buffer-file-name ()
"Format `buffer-file-name'."
(let ((buffer-file-name (file-local-name
(or (buffer-file-name (buffer-base-buffer)) ""))))
(or (and doom-modeline-buffer-file-name-function
(funcall doom-modeline-buffer-file-name-function buffer-file-name))
buffer-file-name)))

(defun doom-modeline--format-buffer-file-truename ()
"Format `buffer-file-truename'."
(let ((buffer-file-truename (file-local-name
(or (file-truename buffer-file-name) ""))))
(or (and doom-modeline-buffer-file-truename-function
(funcall doom-modeline-buffer-file-truename-function buffer-file-truename))
buffer-file-truename)))

(defun doom-modeline-buffer-file-name ()
"Propertize file name based on `doom-modeline-buffer-file-name-style'."
(let* ((buffer-file-name (file-local-name (or (buffer-file-name (buffer-base-buffer)) "")))
(buffer-file-truename (file-local-name
(or buffer-file-truename (file-truename buffer-file-name) "")))
(let* ((buffer-file-name (doom-modeline--format-buffer-file-name))
(buffer-file-truename (doom-modeline--format-buffer-file-truename))
(file-name
(pcase doom-modeline-buffer-file-name-style
('auto
Expand Down

0 comments on commit f06950b

Please sign in to comment.