Fix #147: Buffer does not seem to be associated with any file.

Introduced by 605c5615c1.
This commit is contained in:
Vincent Zhang 2019-03-14 15:27:43 +07:00
parent 2b0f9ea1df
commit 7aa92a7a43
2 changed files with 54 additions and 27 deletions

View file

@ -31,10 +31,6 @@
(require 'eldoc-eval)
(require 'shrink-path)
(require 'subr-x)
(when (>= emacs-major-version 26)
(require 'project))
(when (bound-and-true-p doom-modeline-icon)
(require 'all-the-icons))
;;
@ -91,7 +87,7 @@ Given ~/Projects/FOSS/emacs/lisp/comint.el
"Whether show `all-the-icons' or not.
Non-nil to show the icons in mode-line.
The icons may not be showed correctly in terminal and on Windows.")
The icons may not be showed correctly in terminal.")
(defvar doom-modeline-major-mode-icon t
"Whether show the icon for major mode. It respects `doom-modeline-icon'.")
@ -247,7 +243,6 @@ The icons may not be showed correctly in terminal and on Windows.")
(declare-function all-the-icons-material 'all-the-icons)
(declare-function all-the-icons-octicon 'all-the-icons)
(declare-function face-remap-remove-relative 'face-remap)
(declare-function project-current 'project)
(declare-function project-roots 'project)
(declare-function projectile-project-root 'projectile)

View file

@ -29,16 +29,18 @@
;;; Code:
(require 'all-the-icons)
(require 'subr-x)
(require 'doom-modeline-core)
(require 'doom-modeline-env)
(when (bound-and-true-p doom-modeline-icon)
(require 'all-the-icons))
;;
;; Externals
;;
(defvar all-the-icons-scale-factor)
(defvar anzu--cached-count)
(defvar anzu--current-position)
(defvar anzu--overflow-p)
@ -78,6 +80,8 @@
(defvar winum-auto-setup-mode-line)
(defvar xah-fly-insert-state-q)
(declare-function all-the-icons-auto-mode-match? 'all-the-icons)
(declare-function all-the-icons-icon-family 'all-the-icons)
(declare-function anzu--reset-status 'anzu)
(declare-function anzu--where-is-here 'anzu)
(declare-function async-inject-variables 'async)
@ -163,26 +167,6 @@
(declare-function winum--install-mode-line 'winum)
(declare-function winum-get-number-string 'winum)
;;
;; global watchers
;;
(when (>= emacs-major-version 26)
(add-variable-watcher
'doom-modeline-icon
(lambda (_sym val op _where)
(when (eq op 'set)
(setq doom-modeline-icon val)
(revert-buffer t t))))
(add-variable-watcher
'all-the-icons-scale-factor
(lambda (_sym val op _where)
(when (eq op 'set)
(setq all-the-icons-scale-factor val)
(revert-buffer t t)))))
;;
;; buffer information
;;
@ -224,6 +208,14 @@ buffer where knowing the current project directory is important."
(add-hook 'after-change-major-mode-hook #'doom-modeline-update-buffer-file-icon)
(add-hook 'clone-indirect-buffer-hook #'doom-modeline-update-buffer-file-icon)
(when (>= emacs-major-version 26)
(add-variable-watcher
'all-the-icons-scale-factor
(lambda (_sym val op _where)
(when (eq op 'set)
(setq all-the-icons-scale-factor val)
(doom-modeline-update-buffer-file-icon)))))
(defun doom-modeline-buffer-file-state-icon (icon &optional text face height voffset)
"Displays an ICON with FACE, HEIGHT and VOFFSET.
TEXT is the alternative if it is not applicable.
@ -286,6 +278,20 @@ Uses `all-the-icons-material' to fetch the icon."
(lambda (_sym val op _where)
(when (eq op 'set)
(setq buffer-read-only val)
(doom-modeline-update-buffer-file-state-icon))))
(add-variable-watcher
'doom-modeline-icon
(lambda (_sym val op _where)
(when (eq op 'set)
(setq doom-modeline-icon val)
(doom-modeline-update-buffer-file-state-icon))))
(add-variable-watcher
'all-the-icons-scale-factor
(lambda (_sym val op _where)
(when (eq op 'set)
(setq all-the-icons-scale-factor val)
(doom-modeline-update-buffer-file-state-icon)))))
(defvar-local doom-modeline--buffer-file-name nil)
@ -529,6 +535,14 @@ Uses `all-the-icons-octicon' to fetch the icon."
(add-hook 'after-save-hook #'doom-modeline--update-vcs-icon)
(advice-add #'vc-refresh-state :after #'doom-modeline--update-vcs-icon)
(when (>= emacs-major-version 26)
(add-variable-watcher
'doom-modeline-icon
(lambda (_sym val op _where)
(when (eq op 'set)
(setq doom-modeline-icon val)
(doom-modeline--update-vcs-icon)))))
(defvar-local doom-modeline--vcs-text nil)
(defun doom-modeline-update-vcs-text (&rest _)
"Update text of vsc state in mode-line."
@ -643,6 +657,15 @@ mouse-2: Show help for minor mode")
(add-hook 'flycheck-status-changed-functions #'doom-modeline-update-flycheck-icon)
(add-hook 'flycheck-mode-hook #'doom-modeline-update-flycheck-icon)
(when (>= emacs-major-version 26)
(add-variable-watcher
'doom-modeline-icon
(lambda (_sym val op _where)
(when (eq op 'set)
(setq doom-modeline-icon val)
(when (bound-and-true-p flycheck-mode)
(flycheck-buffer))))))
(defvar-local doom-modeline--flycheck-text nil)
(defun doom-modeline-update-flycheck-text (&optional status)
"Update flycheck text via STATUS."
@ -769,6 +792,15 @@ mouse-2: Show help for minor mode"
map))))))
(advice-add #'flymake--handle-report :after #'doom-modeline-update-flymake-icon)
(when (>= emacs-major-version 26)
(add-variable-watcher
'doom-modeline-icon
(lambda (_sym val op _where)
(when (eq op 'set)
(setq doom-modeline-icon val)
(when (bound-and-true-p flymake-mode)
(flymake-start))))))
(defvar-local doom-modeline--flymake-text nil)
(defun doom-modeline-update-flymake-text (&rest _)
"Update flymake text."