[英]How do I display the total number of lines in the Emacs modeline
默認的Emacs模式行僅顯示當前行號及其相對於總行數的百分比。 如何讓它顯示總線數?
這可能有點棘手,因為如果你一直更新行數並且有一個大的緩沖區,它可能會使Emacs有些反應遲鈍,因為它一遍又一遍地計算行數。 我寫這個是為了采取一種懶惰的計數方法:它只在首次讀入文件時或保存/恢復它后才會這樣做。 如果緩沖區被修改,它不會與行計數有關,它只是在您再次保存之前不會顯示。
(defvar my-mode-line-buffer-line-count nil)
(make-variable-buffer-local 'my-mode-line-buffer-line-count)
(setq-default mode-line-format
'(" " mode-line-modified
(list 'line-number-mode " ")
(:eval (when line-number-mode
(let ((str "L%l"))
(when (and (not (buffer-modified-p)) my-mode-line-buffer-line-count)
(setq str (concat str "/" my-mode-line-buffer-line-count)))
str)))
" %p"
(list 'column-number-mode " C%c")
" " mode-line-buffer-identification
" " mode-line-modes))
(defun my-mode-line-count-lines ()
(setq my-mode-line-buffer-line-count (int-to-string (count-lines (point-min) (point-max)))))
(add-hook 'find-file-hook 'my-mode-line-count-lines)
(add-hook 'after-save-hook 'my-mode-line-count-lines)
(add-hook 'after-revert-hook 'my-mode-line-count-lines)
(add-hook 'dired-after-readin-hook 'my-mode-line-count-lines)
你可能想調整mode-line-format
以適合你的口味,上面是我個人喜歡的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.