1

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

Michael Hoffman
  • 32,526
  • 7
  • 64
  • 86
Yuuta
  • 414
  • 2
  • 13
  • What information are you trying to put in the mode line? It's difficult to answer the question without know what you are trying to do. – scottfrazer Dec 05 '11 at 14:47
  • @Yuuta functions are supposed to be advised if needed. and also functions can be added to hooks with `add-hook` again if needed. – kindahero Dec 05 '11 at 17:44
  • @scottfrazer I added the code in the question. But I'm adding information about the buffer to see if its modified or read only, current column/line, buffer name, how far from the top of the page I am, major mode and time. – Yuuta Dec 05 '11 at 18:01
  • @kindahero I'm looking up advised functions, thanks for the information ^^ – Yuuta Dec 05 '11 at 18:01
  • Tangentially, does your school realise they are providing such an old version of Emacs? Perhaps you could get them to update it. – phils Dec 05 '11 at 21:12
  • @phils They use Fedora/Red hat and for some reason that's the latest version of emacs they currently support =/ – Yuuta Dec 05 '11 at 21:36

1 Answers1

1

In the comments on the original post, you mention the following information you'd like in the mode line:

  1. modified or read only
  2. column / line number
  3. buffer name
  4. how far from the top of the page I am
  5. major mode
  6. current time

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

(display-time-mode 1)
(setq line-number-mode t)
(setq column-number-mode t)

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.

Dale Hagglund
  • 16,074
  • 4
  • 30
  • 37