changeset 109084:9e474f641740

Don't always set ruler-mode-header-line-format-old (Bug#5370). * ruler-mode.el (ruler--save-header-line-format): New fun. (ruler-mode): Use it as a setter function, so as not to overwrite ruler-mode-header-line-format-old if Ruler mode is on (Bug#5370).
author Chong Yidong <cyd@stupidchicken.com>
date Wed, 30 Jun 2010 18:43:52 -0400
parents 52060ddf14aa
children 6a23dfd2048b 10cf940285f9
files lisp/ChangeLog lisp/ruler-mode.el
diffstat 2 files changed, 32 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Wed Jun 30 13:16:01 2010 +0200
+++ b/lisp/ChangeLog	Wed Jun 30 18:43:52 2010 -0400
@@ -1,3 +1,9 @@
+2010-06-30  Chong Yidong  <cyd@stupidchicken.com>
+
+	* ruler-mode.el (ruler--save-header-line-format): New fun.
+	(ruler-mode): Use it as a setter function, so as not to overwrite
+	ruler-mode-header-line-format-old if Ruler mode is on (Bug#5370).
+
 2010-06-29  Chong Yidong  <cyd@stupidchicken.com>
 
 	* vc/vc.el (vc-deduce-backend): New fun.  Handle diff buffers.
--- a/lisp/ruler-mode.el	Wed Jun 30 13:16:01 2010 +0200
+++ b/lisp/ruler-mode.el	Wed Jun 30 18:43:52 2010 -0400
@@ -550,21 +550,37 @@
 Call `ruler-mode-ruler-function' to compute the ruler value.")
 
 ;;;###autoload
+(defvar ruler-mode nil
+  "Non-nil if Ruler mode is enabled.
+Use the command `ruler-mode' to change this variable.")
+(make-variable-buffer-local 'ruler-mode)
+
+(defun ruler--save-header-line-format ()
+  "Install the header line format for Ruler mode.
+Unless if Ruler mode is already enabled, save the old header line
+format first."
+  (when enable
+    (when (and (not ruler-mode)
+	       (local-variable-p 'header-line-format)
+	       (not (local-variable-p 'ruler-mode-header-line-format-old)))
+      (set (make-local-variable 'ruler-mode-header-line-format-old)
+	   header-line-format))
+    (setq header-line-format ruler-mode-header-line-format)))
+
+;;;###autoload
 (define-minor-mode ruler-mode
-  "Display a ruler in the header line if ARG > 0."
+  "Toggle Ruler mode.
+In Ruler mode, Emacs displays a ruler in the header line."
   nil nil
   ruler-mode-map
   :group 'ruler-mode
+  :variable (ruler-mode
+	     . (lambda (enable)
+		 (when enable
+		   (ruler--save-header-line-format))
+		 (setq ruler-mode enable)))
   (if ruler-mode
-      (progn
-        ;; When `ruler-mode' is on save previous header line format
-        ;; and install the ruler header line format.
-        (when (and (local-variable-p 'header-line-format)
-		   (not (local-variable-p 'ruler-mode-header-line-format-old)))
-          (set (make-local-variable 'ruler-mode-header-line-format-old)
-               header-line-format))
-        (setq header-line-format ruler-mode-header-line-format)
-        (add-hook 'post-command-hook 'force-mode-line-update nil t))
+      (add-hook 'post-command-hook 'force-mode-line-update nil t)
     ;; When `ruler-mode' is off restore previous header line format if
     ;; the current one is the ruler header line format.
     (when (eq header-line-format ruler-mode-header-line-format)