all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Custom mode-line format (bug)
@ 2013-03-20 13:53 Miguel Guedes
  2013-03-20 17:07 ` Michael Heerdegen
       [not found] ` <mailman.22546.1363799292.855.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 3+ messages in thread
From: Miguel Guedes @ 2013-03-20 13:53 UTC (permalink / raw)
  To: help-gnu-emacs

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)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-03-21  7:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-20 13:53 Custom mode-line format (bug) Miguel Guedes
2013-03-20 17:07 ` Michael Heerdegen
     [not found] ` <mailman.22546.1363799292.855.help-gnu-emacs@gnu.org>
2013-03-21  7:57   ` Miguel Guedes

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.