How can I display the max line of a file in the bar at the bottom? So, how could it say "L1/L1300" instead of just "Top L1", if the respective happens to have 1300 lines?
count-lines (also used by
line-number-at-pos) is increasingly less efficient as the buffer grows in size/length, whereas
(format-mode-line "%l") does not have those limitations -- however, there are other limitations. See the related thread entitled "A faster method to obtain
line-number-at-pos in large buffers": A faster method to obtain `line-number-at-pos` in large buffers
Performing anything remotely significant in the mode-line can cause a slow down (in part) because the mode-line for more than one visible window may be updated during redisplay. The following example updates the total line numbers in only the selected-window (i.e., active window). See the related thread entitled "Show something in active mode line instead of all mode lines": Show something in active mode line instead of all mode lines
The mode-line for the inactive window uses the previously recorded value for the total number of lines if said value exists, otherwise calculate said value.
Add additional hooks as needed to call
(defvar ml-selected-window nil) (defvar ml-total-lines nil "Previously recorded total lines in a buffer -- used for inactive windows.") (make-variable-buffer-local 'ml-total-lines) (defun ml-record-selected-window () (setq ml-selected-window (selected-window))) (defun ml-update-all () (force-mode-line-update t)) (add-hook 'post-command-hook 'ml-record-selected-window) (add-hook 'buffer-list-update-hook 'ml-update-all) (setq-default mode-line-format '( " %l | " (:eval (let ((win (selected-window))) (with-current-buffer (window-buffer win) (if (or (eq ml-selected-window win) (null ml-total-lines)) (save-excursion (goto-char (point-max)) (setq ml-total-lines (format-mode-line "%l"))) ml-total-lines))))))