comparison lisp/ruler-mode.el @ 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 1d1d5d9bd884
children 4de0b34e2c2e
comparison
equal deleted inserted replaced
109083:52060ddf14aa 109084:9e474f641740
548 '(:eval (funcall ruler-mode-ruler-function)) 548 '(:eval (funcall ruler-mode-ruler-function))
549 "`header-line-format' used in ruler mode. 549 "`header-line-format' used in ruler mode.
550 Call `ruler-mode-ruler-function' to compute the ruler value.") 550 Call `ruler-mode-ruler-function' to compute the ruler value.")
551 551
552 ;;;###autoload 552 ;;;###autoload
553 (defvar ruler-mode nil
554 "Non-nil if Ruler mode is enabled.
555 Use the command `ruler-mode' to change this variable.")
556 (make-variable-buffer-local 'ruler-mode)
557
558 (defun ruler--save-header-line-format ()
559 "Install the header line format for Ruler mode.
560 Unless if Ruler mode is already enabled, save the old header line
561 format first."
562 (when enable
563 (when (and (not ruler-mode)
564 (local-variable-p 'header-line-format)
565 (not (local-variable-p 'ruler-mode-header-line-format-old)))
566 (set (make-local-variable 'ruler-mode-header-line-format-old)
567 header-line-format))
568 (setq header-line-format ruler-mode-header-line-format)))
569
570 ;;;###autoload
553 (define-minor-mode ruler-mode 571 (define-minor-mode ruler-mode
554 "Display a ruler in the header line if ARG > 0." 572 "Toggle Ruler mode.
573 In Ruler mode, Emacs displays a ruler in the header line."
555 nil nil 574 nil nil
556 ruler-mode-map 575 ruler-mode-map
557 :group 'ruler-mode 576 :group 'ruler-mode
577 :variable (ruler-mode
578 . (lambda (enable)
579 (when enable
580 (ruler--save-header-line-format))
581 (setq ruler-mode enable)))
558 (if ruler-mode 582 (if ruler-mode
559 (progn 583 (add-hook 'post-command-hook 'force-mode-line-update nil t)
560 ;; When `ruler-mode' is on save previous header line format
561 ;; and install the ruler header line format.
562 (when (and (local-variable-p 'header-line-format)
563 (not (local-variable-p 'ruler-mode-header-line-format-old)))
564 (set (make-local-variable 'ruler-mode-header-line-format-old)
565 header-line-format))
566 (setq header-line-format ruler-mode-header-line-format)
567 (add-hook 'post-command-hook 'force-mode-line-update nil t))
568 ;; When `ruler-mode' is off restore previous header line format if 584 ;; When `ruler-mode' is off restore previous header line format if
569 ;; the current one is the ruler header line format. 585 ;; the current one is the ruler header line format.
570 (when (eq header-line-format ruler-mode-header-line-format) 586 (when (eq header-line-format ruler-mode-header-line-format)
571 (kill-local-variable 'header-line-format) 587 (kill-local-variable 'header-line-format)
572 (when (local-variable-p 'ruler-mode-header-line-format-old) 588 (when (local-variable-p 'ruler-mode-header-line-format-old)