I customized my mode-line on my laptop (emacs 23.3) and it works perfect.
But when I tried to get it to work on my desktop at school (emacs 21.4) it doesn't update when using Ctrl-f, Ctrl-b, Ctrl-a, etc. unless I actually modify the buffer.
I made a case statement to change the code depending on the computer I'm on, so all the functions work properly, its just that the mode-line doesn't update when moving the point
I tried doing the following
(add-hook 'move-beginning-of-line 'force-mode-line-update)
(add-hook 'move-end-of-line 'force-mode-line-update)
(add-hook 'forward-char 'force-mode-line-update)
(add-hook 'backward-char 'force-mode-line-update)
(add-hook 'next-line 'force-mode-line-update)
(add-hook 'previous-line 'force-mode-line-update)
But it still doesn't update
Any suggestions?
Code:
(setq-default mode-line-format
(list
"---- "
;; Modified shows *
"["
'(:eval
(if (buffer-modified-p)
"*"
(if buffer-read-only
"!"
" "
)))
"] "
;; Buffer (tooltip - file name)
'(:eval (propertize "%b" 'face 'bold 'help-echo (buffer-file-name)))
" "
;; Spaces 12 - "buffer"
'(:eval
(make-string
(- 12
(min
12
(length (buffer-name))))
?-))
" "
;; Current (row,column)
"(" '(:eval (number-to-string (count-lines 1 (point))))
"," '(:eval (number-to-string (current-column)))
") "
;; Spaces 7 - "(r,c)"
'(:eval
(make-string
(- 7
(min
4
(length (number-to-string (current-column)))
)
(min
3
(length (number-to-string (1+ (count-lines 1 (point)))))))
?-))
;; Percentage of file traversed (current line/total lines)
" ["
'(:eval (number-to-string (/ (* (1+ (count-lines 1 (point))) 100) (count-lines 1 (point-max)))) )
"%%] "
;; Spaces 3 - %
'(:eval
(make-string
(- 3 (length (number-to-string (/ (* (1+ (count-lines 1 (point))) 100) (count-lines 1 (point-max))))))
?-))
;; Major Mode
" [" '(:eval mode-name) "] "
;; Spaces 16 + (6 - %)
'(:eval
(make-string
(- 22
(min
6
(length mode-name)))
?-))
" ("
;; Time
'(:eval (format-time-string "%H:%M"))
;; Fill with '-'
") %-"
))
Thanks in advance
In the comments on the original post, you mention the following information you'd like in the mode line:
I've used emacs forever and all of (1), (3), and (5) are in the default emacs mode line for every buffer already, and have been for a very long time. To enable (2) and (6), add
to
~/.emacs
. From what I can find online,column-number-mode
postdates emacs 21.Note that none of this requires explicitly redefining
mode-line
, overriding any functions, or adding any hooks. I haven't provided an answer for (4) because I don't know what you mean by it.