;;; ruler-mode.el --- display a ruler in the header line
-;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006,
-;; 2007 Free Software Foundation, Inc.
+;; Copyright (C) 2001-2014 Free Software Foundation, Inc.
;; Author: David Ponce <david@dponce.com>
;; Maintainer: David Ponce <david@dponce.com>
;; This file is part of GNU Emacs.
-;; This program is free software; you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License as
-;; published by the Free Software Foundation; either version 2, or (at
-;; your option) any later version.
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
-;; This program is distributed in the hope that it will be useful, but
-;; WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-;; General Public License for more details.
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with this program; see the file COPYING. If not, write to
-;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
:group 'convenience)
(defcustom ruler-mode-show-tab-stops nil
- "*If non-nil the ruler shows tab stop positions.
+ "If non-nil the ruler shows tab stop positions.
Also allowing to visually change `tab-stop-list' setting using
<C-down-mouse-1> and <C-down-mouse-3> on the ruler to respectively add
or remove a tab stop. \\[ruler-mode-toggle-show-tab-stops] or
"Ensure WIDGET value is a valid character value."
(save-excursion
(let ((value (widget-value widget)))
- (if (char-valid-p value)
- nil
+ (unless (characterp value)
(widget-put widget :error
(format "Invalid character value: %S" value))
widget))))
-(defcustom ruler-mode-fill-column-char (if (char-displayable-p ?¶)
- ?\¶
+(defcustom ruler-mode-fill-column-char (if (char-displayable-p ?¶)
+ ?\¶
?\|)
- "*Character used at the `fill-column' location."
+ "Character used at the `fill-column' location."
:group 'ruler-mode
:type '(choice
(character :tag "Character")
:validate ruler-mode-character-validate)))
(defcustom ruler-mode-comment-column-char ?\#
- "*Character used at the `comment-column' location."
+ "Character used at the `comment-column' location."
:group 'ruler-mode
:type '(choice
(character :tag "Character")
:validate ruler-mode-character-validate)))
(defcustom ruler-mode-goal-column-char ?G
- "*Character used at the `goal-column' location."
+ "Character used at the `goal-column' location."
:group 'ruler-mode
:type '(choice
(character :tag "Character")
(integer :tag "Integer char value"
:validate ruler-mode-character-validate)))
-(defcustom ruler-mode-current-column-char (if (char-displayable-p ?¦)
- ?\¦
+(defcustom ruler-mode-current-column-char (if (char-displayable-p ?¦)
+ ?\¦
?\@)
- "*Character used at the `current-column' location."
+ "Character used at the `current-column' location."
:group 'ruler-mode
:type '(choice
(character :tag "Character")
:validate ruler-mode-character-validate)))
(defcustom ruler-mode-tab-stop-char ?\T
- "*Character used at `tab-stop-list' locations."
+ "Character used at `tab-stop-list' locations."
:group 'ruler-mode
:type '(choice
(character :tag "Character")
:validate ruler-mode-character-validate)))
(defcustom ruler-mode-basic-graduation-char ?\.
- "*Character used for basic graduations."
+ "Character used for basic graduations."
:group 'ruler-mode
:type '(choice
(character :tag "Character")
:validate ruler-mode-character-validate)))
(defcustom ruler-mode-inter-graduation-char ?\!
- "*Character used for intermediate graduations."
+ "Character used for intermediate graduations."
:group 'ruler-mode
:type '(choice
(character :tag "Character")
:validate ruler-mode-character-validate)))
(defcustom ruler-mode-set-goal-column-ding-flag t
- "*Non-nil means do `ding' when `goal-column' is set."
+ "Non-nil means do `ding' when `goal-column' is set."
:group 'ruler-mode
:type 'boolean)
\f
"Return a column number relative to the selected window.
N is a column number relative to selected frame."
(- n
- (car (window-edges))
(or (car (window-margins)) 0)
(fringe-columns 'left)
(scroll-bar-columns 'left)))
(when (eq start end) ;; mouse click
(save-selected-window
(select-window (posn-window start))
- (setq col (- (car (posn-col-row start)) (car (window-edges))
+ (setq col (- (car (posn-col-row start))
(scroll-bar-columns 'left))
w (- (ruler-mode-full-window-width)
(scroll-bar-columns 'left)
(when (eq start end) ;; mouse click
(save-selected-window
(select-window (posn-window start))
- (setq col (- (car (posn-col-row start)) (car (window-edges))
+ (setq col (- (car (posn-col-row start))
(scroll-bar-columns 'left))
w (- (ruler-mode-full-window-width)
(scroll-bar-columns 'left)
(not (member ts tab-stop-list))
(progn
(message "Tab stop set to %d" ts)
- (setq tab-stop-list (sort (cons ts tab-stop-list)
- #'<)))))))))
+ (when (null tab-stop-list)
+ (setq tab-stop-list (indent-accumulate-tab-stops (1- ts))))
+ (setq tab-stop-list (sort (cons ts tab-stop-list) #'<)))))))))
(defun ruler-mode-mouse-del-tab-stop (start-event)
"Delete tab stop at the graduation where the mouse pointer is on.
"`header-line-format' used in ruler mode.
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 Ruler mode is already enabled, save the old header line
+format first."
+ (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 display of ruler in header line (Ruler mode).
+With a prefix argument ARG, enable Ruler mode if ARG is positive,
+and disable it otherwise. If called from Lisp, enable the mode
+if ARG is omitted or nil."
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)
;; Create an "clean" ruler.
(ruler
(propertize
- (make-string w ruler-mode-basic-graduation-char)
+ (string-to-multibyte
+ (make-string w ruler-mode-basic-graduation-char))
'face 'ruler-mode-default
'local-map ruler-mode-map
'help-echo (cond
i (1+ i) 'help-echo ruler-mode-fill-column-help-echo
ruler))
;; Show the `tab-stop-list' markers.
- ((and ruler-mode-show-tab-stops (member j tab-stop-list))
+ ((and ruler-mode-show-tab-stops (= j (indent-next-tab-stop (1- j))))
(aset ruler i ruler-mode-tab-stop-char)
(put-text-property
i (1+ i) 'face 'ruler-mode-tab-stop
(provide 'ruler-mode)
;; Local Variables:
-;; coding: iso-latin-1
+;; coding: utf-8
;; End:
-;;; arch-tag: b2f24546-5605-44c4-b67b-c9a4eeba3ee8
;;; ruler-mode.el ends here