(mouse-wheel-down-event, mouse-wheel-up-event):
[bpt/emacs.git] / lisp / ruler-mode.el
CommitLineData
479d4d97 1;;; ruler-mode.el --- display a ruler in the header line
4f4ff50a 2
60ab677b 3;; Copyright (C) 2001, 2002, 2003 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
60ab677b 8;; Version: 1.5
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
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;;
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
GM
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;;
60ab677b
JB
42;; [header-line down-mouse-2] set `fill-column', `comment-column' or
43;; `goal-column' to the ruler graduation with the mouse dragging.
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
60;; the `goal-column' and `ruler-mode-tab-stop-char' shows tab
4f4ff50a
GM
61;; stop locations. `window-margins' areas are shown with a different
62;; background color.
63;;
64;; It is also possible to customize the following characters:
65;;
66;; - `ruler-mode-margins-char' character used to pad margin areas
67;; (space by default).
68;; - `ruler-mode-basic-graduation-char' character used for basic
69;; graduations ('.' by default).
70;; - `ruler-mode-inter-graduation-char' character used for
71;; intermediate graduations ('!' by default).
72;;
73;; The following faces are customizable:
74;;
75;; - `ruler-mode-default-face' the ruler default face.
76;; - `ruler-mode-fill-column-face' the face used to highlight the
77;; `fill-column' character.
60ab677b
JB
78;; - `ruler-mode-comment-column-face' the face used to highlight the
79;; `comment-column' character.
80;; - `ruler-mode-goal-column-face' the face used to highlight the
81;; `goal-column' character.
4f4ff50a
GM
82;; - `ruler-mode-current-column-face' the face used to highlight the
83;; `current-column' character.
84;; - `ruler-mode-tab-stop-face' the face used to highlight tab stop
85;; characters.
86;; - `ruler-mode-margins-face' the face used to highlight the
87;; `window-margins' areas.
88;; - `ruler-mode-column-number-face' the face used to highlight the
89;; number graduations.
90;;
91;; `ruler-mode-default-face' inherits from the built-in `default' face.
92;; All `ruler-mode' faces inerit from `ruler-mode-default-face'.
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.
97
98;; Installation
99;;
100;; To automatically display the ruler in specific major modes use:
101;;
102;; (add-hook '<major-mode>-hook 'ruler-mode)
103;;
104
105;;; History:
106;;
bfba6c09 107\f
4f4ff50a
GM
108;;; Code:
109(eval-when-compile
110 (require 'wid-edit))
111
112(defgroup ruler-mode nil
113 "Display a ruler in the header line."
89e7ad59 114 :version "21.4"
2a8f99fa 115 :group 'convenience)
4f4ff50a
GM
116
117(defcustom ruler-mode-show-tab-stops nil
118 "*If non-nil the ruler shows tab stop positions.
119Also allowing to visually change `tab-stop-list' setting using
120<C-down-mouse-1> and <C-down-mouse-3> on the ruler to respectively add
121or remove a tab stop. \\[ruler-mode-toggle-show-tab-stops] or
122<C-down-mouse-2> on the ruler toggles showing/editing of tab stops."
123 :group 'ruler-mode
124 :type 'boolean)
125
126;; IMPORTANT: This function must be defined before the following
127;; defcustoms because it is used in their :validate clause.
128(defun ruler-mode-character-validate (widget)
129 "Ensure WIDGET value is a valid character value."
130 (save-excursion
131 (let ((value (widget-value widget)))
132 (if (char-valid-p value)
133 nil
134 (widget-put widget :error
135 (format "Invalid character value: %S" value))
136 widget))))
60ab677b 137
4f4ff50a
GM
138(defcustom ruler-mode-fill-column-char (if window-system
139