From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Miguel Guedes Newsgroups: gmane.emacs.help Subject: Custom mode-line format (bug) Date: 20 Mar 2013 13:53:04 GMT Message-ID: <5149bf3f$0$43297$862e30e2@ngroups.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1363798509 26107 80.91.229.3 (20 Mar 2013 16:55:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 20 Mar 2013 16:55:09 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Mar 20 17:55:35 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UIMIV-0005sx-AZ for geh-help-gnu-emacs@m.gmane.org; Wed, 20 Mar 2013 17:55:31 +0100 Original-Received: from localhost ([::1]:50121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIMI8-0004cN-6l for geh-help-gnu-emacs@m.gmane.org; Wed, 20 Mar 2013 12:55:08 -0400 Original-Path: usenet.stanford.edu!news.glorb.com!news-out.readnews.com!transit3.readnews.com!s09-11.readnews.com!not-for-mail Original-X-Trace: DXC=J?0^aeGaWZDdVhaoO6oYJ; NWfG42i0B?UG1dB]jf:JLDE8d Original-X-Complaints-To: abuse@blocknews.net Original-Newsgroups: gnu.emacs.help User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Original-Lines: 61 Original-NNTP-Posting-Host: 0b78b8b7.ngroups.net Original-Xref: usenet.stanford.edu gnu.emacs.help:197337 X-Mailman-Approved-At: Wed, 20 Mar 2013 12:52:40 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:89614 Archived-At: 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)