help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Custom mode-line format (bug)


From: Miguel Guedes
Subject: Custom mode-line format (bug)
Date: 20 Mar 2013 13:53:04 GMT
User-agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2)

The attached relevant snippet of code (see below),

 - defines a custom face group

   - creates a face

 - sets up a hook to find-file-hook and dired-mode-hook

 - then whenever a file is visited the hook is executed which then checks 
to see if the file is being opened with root privileges (/su(do):). If 
so, it changes the face of the mode line to the custom one created 
previously.

The objective is to have the mode line switch to a white fg over red bg 
whenever a file is opened as root.

However, it's not working as intended. The mode-line reflects the status 
of the previously active buffer and only when I run (revert-buffer) does 
the mode line finally reflect the status of the active buffer. 

For instance, if I visit file '/su::/etc/fstab' and the currently active 
buffer is 'something-other' the mode line shows the status for 'something-
other' and not '/su::/etc/fstab' as expected. Only after reverting the 
buffer does the mode-line update and reflect the status of the correct 
buffer.

Two questions then:

 1) is this a bug or am I violating the way emacs operates?

 2) if it is a bug, what sort of workaround (if any) would you recommend?




 Snippet of code follows 
-------------------------
;; Display a warning signal in the mode line when visiting a file with 
root
;; privileges.
(defgroup mode-line-custom nil
  "Faces used by mode-line-custom."
  :group 'mode-line-custom
  :group 'faces)

(defface mode-line-custom-warning-face
  '((t (:background "dark red" :foreground "white")))
  "Face used for custom mode line warnings."
  :group 'mode-line-custom
  :version "22.1")

(defun root-file-warning ()
  (when (string-match "^/su\\(do\\)?:" default-directory)
    (setq mode-line-format
          (format-mode-line mode-line-format 'mode-line-custom-warning-
face))
    (server-start-timed))
  )
          
(add-hook 'find-file-hook 'root-file-warning)
(add-hook 'dired-mode-hook 'root-file-warning)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]