Commit | Line | Data |
---|---|---|
479d4d97 | 1 | ;;; ruler-mode.el --- display a ruler in the header line |
4f4ff50a | 2 | |
eb3fa2cf GM |
3 | ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
4 | ;; 2008 Free Software Foundation, Inc. | |
4f4ff50a GM |
5 | |
6 | ;; Author: David Ponce <david@dponce.com> | |
7 | ;; Maintainer: David Ponce <david@dponce.com> | |
8 | ;; Created: 24 Mar 2001 | |
3bb804d0 | 9 | ;; Version: 1.6 |
2a8f99fa | 10 | ;; Keywords: convenience |
4f4ff50a GM |
11 | |
12 | ;; This file is part of GNU Emacs. | |
13 | ||
eb3fa2cf GM |
14 | ;; GNU Emacs is free software; you can redistribute it and/or modify |
15 | ;; it under the terms of the GNU General Public License as published by | |
16 | ;; the Free Software Foundation, either version 3 of the License, or | |
17 | ;; (at your option) any later version. | |
4f4ff50a | 18 | |
eb3fa2cf GM |
19 | ;; This program is distributed in the hope that it will be useful, |
20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | ;; GNU General Public License for more details. | |
4f4ff50a GM |
23 | |
24 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 25 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
4f4ff50a GM |
26 | |
27 | ;;; Commentary: | |
28 | ||
29 | ;; This library provides a minor mode to display a ruler in the header | |
68130af7 | 30 | ;; line. It works from Emacs 21 onwards. |
4f4ff50a | 31 | ;; |
60ab677b JB |
32 | ;; You can use the mouse to change the `fill-column' `comment-column', |
33 | ;; `goal-column', `window-margins' and `tab-stop-list' settings: | |
4f4ff50a | 34 | ;; |
3bb804d0 | 35 | ;; [header-line (shift down-mouse-1)] set left margin end to the ruler |
4f4ff50a GM |
36 | ;; graduation where the mouse pointer is on. |
37 | ;; | |
3bb804d0 JB |
38 | ;; [header-line (shift down-mouse-3)] set right margin beginning to |
39 | ;; the ruler graduation where the mouse pointer is on. | |
4f4ff50a | 40 | ;; |
3bb804d0 JB |
41 | ;; [header-line down-mouse-2] Drag the `fill-column', `comment-column' |
42 | ;; or `goal-column' to a ruler graduation. | |
4f4ff50a GM |
43 | ;; |
44 | ;; [header-line (control down-mouse-1)] add a tab stop to the ruler | |
45 | ;; graduation where the mouse pointer is on. | |
46 | ;; | |
47 | ;; [header-line (control down-mouse-3)] remove the tab stop at the | |
48 | ;; ruler graduation where the mouse pointer is on. | |
49 | ;; | |
50 | ;; [header-line (control down-mouse-2)] or M-x | |
51 | ;; `ruler-mode-toggle-show-tab-stops' toggle showing and visually | |
52 | ;; editing `tab-stop-list' setting. The `ruler-mode-show-tab-stops' | |
53 | ;; option controls if the ruler shows tab stops by default. | |
54 | ;; | |
55 | ;; In the ruler the character `ruler-mode-current-column-char' shows | |
56 | ;; the `current-column' location, `ruler-mode-fill-column-char' shows | |
60ab677b JB |
57 | ;; the `fill-column' location, `ruler-mode-comment-column-char' shows |
58 | ;; the `comment-column' location, `ruler-mode-goal-column-char' shows | |
3bb804d0 JB |
59 | ;; the `goal-column' and `ruler-mode-tab-stop-char' shows tab stop |
60 | ;; locations. Graduations in `window-margins' and `window-fringes' | |
61 | ;; areas are shown with a different foreground color. | |
4f4ff50a GM |
62 | ;; |
63 | ;; It is also possible to customize the following characters: | |
64 | ;; | |
4f4ff50a GM |
65 | ;; - `ruler-mode-basic-graduation-char' character used for basic |
66 | ;; graduations ('.' by default). | |
67 | ;; - `ruler-mode-inter-graduation-char' character used for | |
68 | ;; intermediate graduations ('!' by default). | |
69 | ;; | |
70 | ;; The following faces are customizable: | |
71 | ;; | |
42e64878 MB |
72 | ;; - `ruler-mode-default' the ruler default face. |
73 | ;; - `ruler-mode-fill-column' the face used to highlight the | |
4f4ff50a | 74 | ;; `fill-column' character. |
42e64878 | 75 | ;; - `ruler-mode-comment-column' the face used to highlight the |
60ab677b | 76 | ;; `comment-column' character. |
42e64878 | 77 | ;; - `ruler-mode-goal-column' the face used to highlight the |
60ab677b | 78 | ;; `goal-column' character. |
42e64878 | 79 | ;; - `ruler-mode-current-column' the face used to highlight the |
4f4ff50a | 80 | ;; `current-column' character. |
42e64878 | 81 | ;; - `ruler-mode-tab-stop' the face used to highlight tab stop |
4f4ff50a | 82 | ;; characters. |
42e64878 | 83 | ;; - `ruler-mode-margins' the face used to highlight graduations |
3bb804d0 | 84 | ;; in the `window-margins' areas. |
42e64878 | 85 | ;; - `ruler-mode-fringes' the face used to highlight graduations |
3bb804d0 | 86 | ;; in the `window-fringes' areas. |
42e64878 | 87 | ;; - `ruler-mode-column-number' the face used to highlight the |
3bb804d0 | 88 | ;; numbered graduations. |
4f4ff50a | 89 | ;; |
42e64878 MB |
90 | ;; `ruler-mode-default' inherits from the built-in `default' face. |
91 | ;; All `ruler-mode' faces inherit from `ruler-mode-default'. | |
4f4ff50a GM |
92 | ;; |
93 | ;; WARNING: To keep ruler graduations aligned on text columns it is | |
94 | ;; important to use the same font family and size for ruler and text | |
95 | ;; areas. | |
6b61353c KH |
96 | ;; |
97 | ;; You can override the ruler format by defining an appropriate | |
98 | ;; function as the buffer-local value of `ruler-mode-ruler-function'. | |
4f4ff50a GM |
99 | |
100 | ;; Installation | |
101 | ;; | |
102 | ;; To automatically display the ruler in specific major modes use: | |
103 | ;; | |
104 | ;; (add-hook '<major-mode>-hook 'ruler-mode) | |
105 | ;; | |
106 | ||
107 | ;;; History: | |
108 | ;; | |
bfba6c09 | 109 | \f |
4f4ff50a GM |
110 | ;;; Code: |
111 | (eval-when-compile | |
112 | (require 'wid-edit)) | |
6b61353c KH |
113 | (require 'scroll-bar) |
114 | (require 'fringe) | |
4f4ff50a GM |
115 | |
116 | (defgroup ruler-mode nil | |
117 | "Display a ruler in the header line." | |
bf247b6e | 118 | :version "22.1" |
2a8f99fa | 119 | :group 'convenience) |
4f4ff50a GM |
120 | |
121 | (defcustom ruler-mode-show-tab-stops nil | |
122 | "*If non-nil the ruler shows tab stop positions. | |
123 | Also allowing to visually change `tab-stop-list' setting using | |
124 | <C-down-mouse-1> and <C-down-mouse-3> on the ruler to respectively add | |
125 | or remove a tab stop. \\[ruler-mode-toggle-show-tab-stops] or | |
126 | <C-down-mouse-2> on the ruler toggles showing/editing of tab stops." | |
127 | :group 'ruler-mode | |
128 | :type 'boolean) | |
129 | ||
130 | ;; IMPORTANT: This function must be defined before the following | |
131 | ;; defcustoms because it is used in their :validate clause. | |
132 | (defun ruler-mode-character-validate (widget) | |
133 | "Ensure WIDGET value is a valid character value." | |
134 | (save-excursion | |
135 | (let ((value (widget-value widget))) | |
ab2cbf67 | 136 | (unless (characterp value) |
4f4ff50a GM |
137 | (widget-put widget :error |
138 | (format "Invalid character value: %S" value)) | |
139 | widget)))) | |
60ab677b | 140 | |
6b61353c | 141 | Content-type: text/html