break apart minmo-narrow-notifier and minmo-linecol-total
This commit is contained in:
parent
33a3e603eb
commit
b11f89e650
1 changed files with 18 additions and 13 deletions
31
minmo.el
31
minmo.el
|
|
@ -413,7 +413,7 @@ Optional FORCE means ignore the minmo--git-directory-table."
|
||||||
))
|
))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;; line column
|
;;; line column narrow
|
||||||
|
|
||||||
(defcustom minmo-line-column-format "%l:%c" "format for line number and column."
|
(defcustom minmo-line-column-format "%l:%c" "format for line number and column."
|
||||||
:type '(string)
|
:type '(string)
|
||||||
|
|
@ -423,14 +423,14 @@ Optional FORCE means ignore the minmo--git-directory-table."
|
||||||
:type '(string)
|
:type '(string)
|
||||||
:group 'minmo)
|
:group 'minmo)
|
||||||
|
|
||||||
;; line count can be expensive for large files, when run continuously. cache it.
|
|
||||||
(defvar-local minmo--total-lines-cache nil
|
|
||||||
"Cached total line count for the current buffer.")
|
|
||||||
|
|
||||||
(defcustom minmo-narrow-face 'warning "face for narrow notifier."
|
(defcustom minmo-narrow-face 'warning "face for narrow notifier."
|
||||||
:type '(symbol)
|
:type '(symbol)
|
||||||
:group 'minmo)
|
:group 'minmo)
|
||||||
|
|
||||||
|
;; line count can be expensive for large files, when run continuously. cache it.
|
||||||
|
(defvar-local minmo--total-lines-cache nil
|
||||||
|
"Cached total line count for the current buffer.")
|
||||||
|
|
||||||
(defun minmo--cache-total-lines ()
|
(defun minmo--cache-total-lines ()
|
||||||
"Refresh the total line count cache."
|
"Refresh the total line count cache."
|
||||||
;; 'line-number-at-pos' is C-level:
|
;; 'line-number-at-pos' is C-level:
|
||||||
|
|
@ -440,17 +440,22 @@ Optional FORCE means ignore the minmo--git-directory-table."
|
||||||
(add-hook 'after-save-hook #'minmo--cache-total-lines)
|
(add-hook 'after-save-hook #'minmo--cache-total-lines)
|
||||||
(add-hook 'after-revert-hook #'minmo--cache-total-lines)
|
(add-hook 'after-revert-hook #'minmo--cache-total-lines)
|
||||||
|
|
||||||
|
(defun minmo-linecol-total ()
|
||||||
|
(when minmo--total-lines-cache
|
||||||
|
(concat minmo-line-column-format
|
||||||
|
minmo-line-column-suffix
|
||||||
|
(number-to-string minmo--total-lines-cache))))
|
||||||
|
|
||||||
|
(defun minmo-narrow-notifier ()
|
||||||
|
(if (buffer-narrowed-p)
|
||||||
|
(propertize "narrow" 'face minmo-narrow-face)
|
||||||
|
nil))
|
||||||
|
|
||||||
;; because when narrow is on, line count is meaningless:
|
;; because when narrow is on, line count is meaningless:
|
||||||
(defun minmo-narrow-or-linecol-total ()
|
(defun minmo-narrow-or-linecol-total ()
|
||||||
(when buffer-file-name
|
(when buffer-file-name
|
||||||
(if (buffer-narrowed-p)
|
(or (minmo-narrow-notifier)
|
||||||
(propertize "%n" 'face minmo-narrow-face)
|
(minmo-linecol-total))))
|
||||||
;; consult preview won't have filled out minmo--total-lines-cache:
|
|
||||||
(when minmo--total-lines-cache
|
|
||||||
(concat minmo-line-column-format
|
|
||||||
minmo-line-column-suffix
|
|
||||||
(number-to-string minmo--total-lines-cache)))
|
|
||||||
)))
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;; minor-modes
|
;;; minor-modes
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue