Remove doom*set-indirect-buffer-filename hack

This was done to help the modeline build its file path in indirect
buffers, but this has been fixed by using buffer-base-buffer.

Both ui/modeline and ui/doom-modeline have been refactored to
accommodate this.
This commit is contained in:
Henrik Lissner 2018-09-01 12:31:37 +02:00
parent 72d8c5dd56
commit 712b775f36
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 33 additions and 40 deletions

View file

@ -288,19 +288,6 @@ enable multiple minor modes for the same regexp.")
(setq alist (cdr alist)))))) (setq alist (cdr alist))))))
(add-hook 'find-file-hook #'doom|enable-minor-mode-maybe) (add-hook 'find-file-hook #'doom|enable-minor-mode-maybe)
(defun doom*set-indirect-buffer-filename (orig-fn base-buffer name &optional clone)
"In indirect buffers, `buffer-file-name' is nil, which can cause problems
with functions that require it (like modeline segments)."
(let ((file-name (buffer-file-name base-buffer))
(buffer (funcall orig-fn base-buffer name clone)))
(when (and file-name buffer)
(with-current-buffer buffer
(unless buffer-file-name
(setq buffer-file-name file-name
buffer-file-truename (file-truename file-name)))))
buffer))
(advice-add #'make-indirect-buffer :around #'doom*set-indirect-buffer-filename)
(defun doom*symbol-file (orig-fn symbol &optional type) (defun doom*symbol-file (orig-fn symbol &optional type)
"If a `doom-file' symbol property exists on SYMBOL, use that instead of the "If a `doom-file' symbol property exists on SYMBOL, use that instead of the
original value of `symbol-file'." original value of `symbol-file'."

View file

@ -294,16 +294,23 @@ file-name => comint.el")
(defun +doom-modeline-buffer-file-name () (defun +doom-modeline-buffer-file-name ()
"Propertized `buffer-file-name' based on `+doom-modeline-buffer-file-name-style'." "Propertized `buffer-file-name' based on `+doom-modeline-buffer-file-name-style'."
(let ((buffer-file-name (or buffer-file-name "")) (let ((buffer-file-name (or (buffer-file-name (buffer-base-buffer)) "")))
(buffer-file-truename (or buffer-file-truename ""))) (unless buffer-file-truename
(setq buffer-file-truename (file-truename buffer-file-name)))
(propertize (propertize
(pcase +doom-modeline-buffer-file-name-style (pcase +doom-modeline-buffer-file-name-style
(`truncate-upto-project (+doom-modeline--buffer-file-name 'shrink)) (`truncate-upto-project
(`truncate-upto-root (+doom-modeline--buffer-file-name-truncate)) (+doom-modeline--buffer-file-name buffer-file-name buffer-file-truename 'shrink))
(`truncate-all (+doom-modeline--buffer-file-name-truncate t)) (`truncate-upto-root
(`relative-to-project (+doom-modeline--buffer-file-name-relative)) (+doom-modeline--buffer-file-name-truncate buffer-file-name buffer-file-truename))
(`relative-from-project (+doom-modeline--buffer-file-name-relative 'include-project)) (`truncate-all
(`file-name (propertize (file-name-nondirectory buffer-file-name) (+doom-modeline--buffer-file-name-truncate buffer-file-name buffer-file-truename t))
(`relative-to-project
(+doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename))
(`relative-from-project
(+doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename 'include-project))
(`file-name
(propertize (file-name-nondirectory buffer-file-name)
'face 'face
(let ((face (or (and (buffer-modified-p) (let ((face (or (and (buffer-modified-p)
'doom-modeline-buffer-modified) 'doom-modeline-buffer-modified)
@ -312,10 +319,10 @@ file-name => comint.el")
(when face `(:inherit ,face)))))) (when face `(:inherit ,face))))))
'help-echo buffer-file-truename))) 'help-echo buffer-file-truename)))
(defun +doom-modeline--buffer-file-name-truncate (&optional truncate-tail) (defun +doom-modeline--buffer-file-name-truncate (file-path true-file-path &optional truncate-tail)
"Propertized `buffer-file-name' that truncates every dir along path. "Propertized `buffer-file-name' that truncates every dir along path.
If TRUNCATE-TAIL is t also truncate the parent directory of the file." If TRUNCATE-TAIL is t also truncate the parent directory of the file."
(let ((dirs (shrink-path-prompt (file-name-directory buffer-file-truename))) (let ((dirs (shrink-path-prompt (file-name-directory true-file-path)))
(active (active))) (active (active)))
(if (null dirs) (if (null dirs)
(propertize "%b" 'face (if active 'doom-modeline-buffer-file)) (propertize "%b" 'face (if active 'doom-modeline-buffer-file))
@ -328,27 +335,26 @@ If TRUNCATE-TAIL is t also truncate the parent directory of the file."
(if truncate-tail (substring basename 0 1) basename) (if truncate-tail (substring basename 0 1) basename)
"/") "/")
'face (if dir-faces `(:inherit ,dir-faces))) 'face (if dir-faces `(:inherit ,dir-faces)))
(propertize (file-name-nondirectory buffer-file-name) (propertize (file-name-nondirectory file-path)
'face (if file-faces `(:inherit ,file-faces))))))))) 'face (if file-faces `(:inherit ,file-faces)))))))))
(defun +doom-modeline--buffer-file-name-relative (&optional include-project) (defun +doom-modeline--buffer-file-name-relative (_file-path true-file-path &optional include-project)
"Propertized `buffer-file-name' showing directories relative to project's root only." "Propertized `buffer-file-name' showing directories relative to project's root only."
(let ((root (doom-project-root)) (let ((root (doom-project-root))
(active (active))) (active (active)))
(if (null root) (if (null root)
(propertize "%b" 'face (if active 'doom-modeline-buffer-file)) (propertize "%b" 'face (if active 'doom-modeline-buffer-file))
(let* ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified)) (let* ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified))
(true-filename (file-truename buffer-file-name)) (relative-dirs (file-relative-name (file-name-directory true-file-path)
(relative-dirs (file-relative-name (file-name-directory true-filename)
(if include-project (concat root "../") root))) (if include-project (concat root "../") root)))
(relative-faces (or modified-faces (if active 'doom-modeline-buffer-path))) (relative-faces (or modified-faces (if active 'doom-modeline-buffer-path)))
(file-faces (or modified-faces (if active 'doom-modeline-buffer-file)))) (file-faces (or modified-faces (if active 'doom-modeline-buffer-file))))
(if (equal "./" relative-dirs) (setq relative-dirs "")) (if (equal "./" relative-dirs) (setq relative-dirs ""))
(concat (propertize relative-dirs 'face (if relative-faces `(:inherit ,relative-faces))) (concat (propertize relative-dirs 'face (if relative-faces `(:inherit ,relative-faces)))
(propertize (file-name-nondirectory true-filename) (propertize (file-name-nondirectory true-file-path)
'face (if file-faces `(:inherit ,file-faces)))))))) 'face (if file-faces `(:inherit ,file-faces))))))))
(defun +doom-modeline--buffer-file-name (truncate-project-root-parent) (defun +doom-modeline--buffer-file-name (file-path _true-file-path &optional truncate-project-root-parent)
"Propertized `buffer-file-name'. "Propertized `buffer-file-name'.
If TRUNCATE-PROJECT-ROOT-PARENT is t space will be saved by truncating it down If TRUNCATE-PROJECT-ROOT-PARENT is t space will be saved by truncating it down
fish-shell style. fish-shell style.
@ -357,12 +363,12 @@ Example:
~/Projects/FOSS/emacs/lisp/comint.el => ~/P/F/emacs/lisp/comint.el" ~/Projects/FOSS/emacs/lisp/comint.el => ~/P/F/emacs/lisp/comint.el"
(let* ((project-root (doom-project-root)) (let* ((project-root (doom-project-root))
(file-name-split (shrink-path-file-mixed project-root (file-name-split (shrink-path-file-mixed project-root
(file-name-directory buffer-file-name) (file-name-directory file-path)
buffer-file-name)) file-path))
(active (active))) (active (active)))
(if (null file-name-split) (if (null file-name-split)
(propertize "%b" 'face (if active 'doom-modeline-buffer-file)) (propertize "%b" 'face (if active 'doom-modeline-buffer-file))
(pcase-let ((`(,root-path-parent ,project ,relative-path ,filename) file-name-split)) (pcase-let ((`(,root-path-parent ,project ,relative-path ,file-path) file-name-split))
(let ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified))) (let ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified)))
(let ((sp-faces (or modified-faces (if active 'font-lock-comment-face))) (let ((sp-faces (or modified-faces (if active 'font-lock-comment-face)))
(project-faces (or modified-faces (if active 'font-lock-string-face))) (project-faces (or modified-faces (if active 'font-lock-string-face)))
@ -378,7 +384,7 @@ Example:
'face sp-props) 'face sp-props)
(propertize (concat project "/") 'face project-props) (propertize (concat project "/") 'face project-props)
(if relative-path (propertize relative-path 'face relative-props)) (if relative-path (propertize relative-path 'face relative-props))
(propertize filename 'face file-props))))))))) (propertize file-path 'face file-props)))))))))
;; ;;

View file

@ -434,7 +434,7 @@ Meant for `+modeline-buffer-path-function'."
:init "%b" :init "%b"
:faces t :faces t
(if buffer-file-name (if buffer-file-name
(+modeline-build-path buffer-file-name) (+modeline-build-path (buffer-file-name (buffer-base-buffer)))
"%b")) "%b"))
(def-modeline-segment! +modeline-buffer-directory (def-modeline-segment! +modeline-buffer-directory