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