Commit | Line | Data |
---|---|---|
479d4d97 | 1 | ;;; ruler-mode.el --- display a ruler in the header line |
4f4ff50a GM |
2 | |
3 | ;; Copyright (C) 2001 Free Software Foundation, Inc. | |
4 | ||
5 | ;; Author: David Ponce <david@dponce.com> | |
6 | ;; Maintainer: David Ponce <david@dponce.com> | |
7 | ;; Created: 24 Mar 2001 | |
a5f7cb26 | 8 | ;; Version: 1.4 |
479d4d97 | 9 | ;; Keywords: environment 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 | |
25 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
26 | ;; Boston, MA 02111-1307, USA. | |
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 | ;; | |
33 | ;; You can use the mouse to change the `fill-column', `window-margins' | |
34 | ;; and `tab-stop-list' settings: | |
35 | ;; | |
36 | ;; [header-line (shift down-mouse-1)] set left margin to the ruler | |
37 | ;; graduation where the mouse pointer is on. | |
38 | ;; | |
39 | ;; [header-line (shift down-mouse-3)] set right margin to the ruler | |
40 | ;; graduation where the mouse pointer is on. | |
41 | ;; | |
42 | ;; [header-line down-mouse-2] set `fill-column' to the ruler | |
43 | ;; graduation where the mouse pointer is on. | |
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 | |
58 | ;; the `fill-column' location and `ruler-mode-tab-stop-char' shows tab | |
59 | ;; stop locations. `window-margins' areas are shown with a different | |
60 | ;; background color. | |
61 | ;; | |
62 | ;; It is also possible to customize the following characters: | |
63 | ;; | |
64 | ;; - `ruler-mode-margins-char' character used to pad margin areas | |
65 | ;; (space by default). | |
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 | ;; | |
73 | ;; - `ruler-mode-default-face' the ruler default face. | |
74 | ;; - `ruler-mode-fill-column-face' the face used to highlight the | |
75 | ;; `fill-column' character. | |
76 | ;; - `ruler-mode-current-column-face' the face used to highlight the | |
77 | ;; `current-column' character. | |
78 | ;; - `ruler-mode-tab-stop-face' the face used to highlight tab stop | |
79 | ;; characters. | |
80 | ;; - `ruler-mode-margins-face' the face used to highlight the | |
81 | ;; `window-margins' areas. | |
82 | ;; - `ruler-mode-column-number-face' the face used to highlight the | |
83 | ;; number graduations. | |
84 | ;; | |
85 | ;; `ruler-mode-default-face' inherits from the built-in `default' face. | |
86 | ;; All `ruler-mode' faces inerit from `ruler-mode-default-face'. | |
87 | ;; | |
88 | ;; WARNING: To keep ruler graduations aligned on text columns it is | |
89 | ;; important to use the same font family and size for ruler and text | |
90 | ;; areas. | |
91 | ||
92 | ;; Installation | |
93 | ;; | |
94 | ;; To automatically display the ruler in specific major modes use: | |
95 | ;; | |
96 | ;; (add-hook '<major-mode>-hook 'ruler-mode) | |
97 | ;; | |
98 | ||
99 | ;;; History: | |
100 | ;; | |
bfba6c09 | 101 | \f |
4f4ff50a GM |
102 | ;;; Code: |
103 | (eval-when-compile | |
104 | (require 'wid-edit)) | |
105 | ||
106 | (defgroup ruler-mode nil | |
107 | "Display a ruler in the header line." | |
479d4d97 | 108 | :version "21.3" |
4f4ff50a GM |
109 | :group 'environment) |
110 | ||
111 | (defcustom ruler-mode-show-tab-stops nil | |
112 | "*If non-nil the ruler shows tab stop positions. | |
113 | Also allowing to visually change `tab-stop-list' setting using | |
114 | <C-down-mouse-1> and <C-down-mouse-3> on the ruler to respectively add | |
115 | or remove a tab stop. \\[ruler-mode-toggle-show-tab-stops] or | |
116 | <C-down-mouse-2> on the ruler toggles showing/editing of tab stops." | |
117 | :group 'ruler-mode | |
118 | :type 'boolean) | |
119 | ||
120 | ;; IMPORTANT: This function must be defined before the following | |
121 | ;; defcustoms because it is used in their :validate clause. | |
122 | (defun ruler-mode-character-validate (widget) | |
123 | "Ensure WIDGET value is a valid character value." | |
124 | (save-excursion | |
125 | (let ((value (widget-value widget))) | |
126 | (if (char-valid-p value) | |
127 | nil | |
128 | (widget-put widget :error | |
129 | (format "Invalid character value: %S" value)) | |
130 | widget)))) | |
131 | ||
132 | (defcustom ruler-mode-fill-column-char (if window-system | |
133 |