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