Mercurial > emacs
annotate lisp/ruler-mode.el @ 89657:899286e38bef
*** empty log message ***
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 24 Nov 2003 08:28:58 +0000 |
parents | 2f877ed80fa6 |
children | 68c22ea6027c |
rev | line source |
---|---|
42836
c6bcb27e426f
(ruler-mode): New keyword. Fix :version.
Pavel Janík <Pavel@Janik.cz>
parents:
42706
diff
changeset
|
1 ;;; ruler-mode.el --- display a ruler in the header line |
39731 | 2 |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
3 ;; Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. |
39731 | 4 |
5 ;; Author: David Ponce <david@dponce.com> | |
6 ;; Maintainer: David Ponce <david@dponce.com> | |
7 ;; Created: 24 Mar 2001 | |
51389 | 8 ;; Version: 1.6 |
47183
865837df3fe7
(defgroup ruler-mode): Use `convenience' as parent.
Richard M. Stallman <rms@gnu.org>
parents:
45255
diff
changeset
|
9 ;; Keywords: convenience |
39731 | 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 ;; | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
33 ;; You can use the mouse to change the `fill-column' `comment-column', |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
34 ;; `goal-column', `window-margins' and `tab-stop-list' settings: |
39731 | 35 ;; |
51389 | 36 ;; [header-line (shift down-mouse-1)] set left margin end to the ruler |
39731 | 37 ;; graduation where the mouse pointer is on. |
38 ;; | |
51389 | 39 ;; [header-line (shift down-mouse-3)] set right margin beginning to |
40 ;; the ruler graduation where the mouse pointer is on. | |
39731 | 41 ;; |
51389 | 42 ;; [header-line down-mouse-2] Drag the `fill-column', `comment-column' |
43 ;; or `goal-column' to a ruler graduation. | |
39731 | 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 | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
58 ;; the `fill-column' location, `ruler-mode-comment-column-char' shows |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
59 ;; the `comment-column' location, `ruler-mode-goal-column-char' shows |
51389 | 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. | |
39731 | 63 ;; |
64 ;; It is also possible to customize the following characters: | |
65 ;; | |
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. | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
76 ;; - `ruler-mode-comment-column-face' the face used to highlight the |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
77 ;; `comment-column' character. |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
78 ;; - `ruler-mode-goal-column-face' the face used to highlight the |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
79 ;; `goal-column' character. |
39731 | 80 ;; - `ruler-mode-current-column-face' the face used to highlight the |
81 ;; `current-column' character. | |
82 ;; - `ruler-mode-tab-stop-face' the face used to highlight tab stop | |
83 ;; characters. | |
51389 | 84 ;; - `ruler-mode-margins-face' the face used to highlight graduations |
85 ;; in the `window-margins' areas. | |
86 ;; - `ruler-mode-fringes-face' the face used to highlight graduations | |
87 ;; in the `window-fringes' areas. | |
39731 | 88 ;; - `ruler-mode-column-number-face' the face used to highlight the |
51389 | 89 ;; numbered graduations. |
39731 | 90 ;; |
91 ;; `ruler-mode-default-face' inherits from the built-in `default' face. | |
51389 | 92 ;; All `ruler-mode' faces inherit from `ruler-mode-default-face'. |
39731 | 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 ;; | |
41461 | 107 |
39731 | 108 ;;; Code: |
109 (eval-when-compile | |
110 (require 'wid-edit)) | |
111 | |
112 (defgroup ruler-mode nil | |
113 "Display a ruler in the header line." | |
45255
20c79f08a7da
Change all post-21.1 :version attributes to 21.4.
Eli Zaretskii <eliz@gnu.org>
parents:
42836
diff
changeset
|
114 :version "21.4" |
47183
865837df3fe7
(defgroup ruler-mode): Use `convenience' as parent.
Richard M. Stallman <rms@gnu.org>
parents:
45255
diff
changeset
|
115 :group 'convenience) |
39731 | 116 |
117 (defcustom ruler-mode-show-tab-stops nil | |
118 "*If non-nil the ruler shows tab stop positions. | |
119 Also 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 | |
121 or 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))) | |
88997
71bcf52caa3b
(ruler-mode-character-validate): Use characterp.
Dave Love <fx@gnu.org>
parents:
42836
diff
changeset
|
132 (unless (characterp value) |
39731 | 133 (widget-put widget :error |
134 (format "Invalid character value: %S" value)) | |
135 widget)))) | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
136 |
39731 | 137 (defcustom ruler-mode-fill-column-char (if window-system |
138 ?\¶ | |
139 ?\|) | |
140 "*Character used at the `fill-column' location." | |
141 :group 'ruler-mode | |
142 :type '(choice | |
143 (character :tag "Character") | |
144 (integer :tag "Integer char value" | |
145 :validate ruler-mode-character-validate))) | |
146 | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
147 (defcustom ruler-mode-comment-column-char ?\# |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
148 "*Character used at the `comment-column' location." |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
149 :group 'ruler-mode |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
150 :type '(choice |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
151 (character :tag "Character") |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
152 (integer :tag "Integer char value" |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
153 :validate ruler-mode-character-validate))) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
154 |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
155 (defcustom ruler-mode-goal-column-char ?G |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
156 "*Character used at the `goal-column' location." |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
157 :group 'ruler-mode |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
158 :type '(choice |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
159 (character :tag "Character") |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
160 (integer :tag "Integer char value" |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
161 :validate ruler-mode-character-validate))) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
162 |
39731 | 163 (defcustom ruler-mode-current-column-char (if window-system |
164 ?\¦ | |
165 ?\@) | |
166 "*Character used at the `current-column' location." | |
167 :group 'ruler-mode | |
168 :type '(choice | |
169 (character :tag "Character") | |
170 (integer :tag "Integer char value" | |
171 :validate ruler-mode-character-validate))) | |
172 | |
173 (defcustom ruler-mode-tab-stop-char ?\T | |
174 "*Character used at `tab-stop-list' locations." | |
175 :group 'ruler-mode | |
176 :type '(choice | |
177 (character :tag "Character") | |
178 (integer :tag "Integer char value" | |
179 :validate ruler-mode-character-validate))) | |
180 | |
181 (defcustom ruler-mode-basic-graduation-char ?\. | |
182 "*Character used for basic graduations." | |
183 :group 'ruler-mode | |
184 :type '(choice | |
185 (character :tag "Character") | |
186 (integer :tag "Integer char value" | |
187 :validate ruler-mode-character-validate))) | |
188 | |
189 (defcustom ruler-mode-inter-graduation-char ?\! | |
190 "*Character used for intermediate graduations." | |
191 :group 'ruler-mode | |
192 :type '(choice | |
193 (character :tag "Character") | |
194 (integer :tag "Integer char value" | |
195 :validate ruler-mode-character-validate))) | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
196 |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
197 (defcustom ruler-mode-set-goal-column-ding-flag t |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
198 "*Non-nil means do `ding' when `goal-column' is set." |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
199 :group 'ruler-mode |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
200 :type 'boolean) |
41461 | 201 |
39731 | 202 (defface ruler-mode-default-face |
203 '((((type tty)) | |
204 (:inherit default | |
205 :background "grey64" | |
206 :foreground "grey50" | |
207 )) | |
208 (t | |
209 (:inherit default | |
210 :background "grey76" | |
211 :foreground "grey64" | |
212 :box (:color "grey76" | |
213 :line-width 1 | |
214 :style released-button) | |
215 ))) | |
216 "Default face used by the ruler." | |
217 :group 'ruler-mode) | |
218 | |
51389 | 219 (defface ruler-mode-pad-face |
220 '((((type tty)) | |
221 (:inherit ruler-mode-default-face | |
222 :background "grey50" | |
223 )) | |
224 (t | |
225 (:inherit ruler-mode-default-face | |
226 :background "grey64" | |
227 ))) | |
228 "Face used to pad inactive ruler areas." | |
229 :group 'ruler-mode) | |
230 | |
231 (defface ruler-mode-margins-face | |
232 '((t | |
233 (:inherit ruler-mode-default-face | |
234 :foreground "white" | |
235 ))) | |
236 "Face used to highlight margin areas." | |
237 :group 'ruler-mode) | |
238 | |
239 (defface ruler-mode-fringes-face | |
240 '((t | |
241 (:inherit ruler-mode-default-face | |
242 :foreground "green" | |
243 ))) | |
244 "Face used to highlight fringes areas." | |
245 :group 'ruler-mode) | |
246 | |
39731 | 247 (defface ruler-mode-column-number-face |
248 '((t | |
249 (:inherit ruler-mode-default-face | |
250 :foreground "black" | |
251 ))) | |
252 "Face used to highlight number graduations." | |
253 :group 'ruler-mode) | |
254 | |
255 (defface ruler-mode-fill-column-face | |
256 '((t | |
257 (:inherit ruler-mode-default-face | |
258 :foreground "red" | |
259 ))) | |
260 "Face used to highlight the fill column character." | |
261 :group 'ruler-mode) | |
262 | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
263 (defface ruler-mode-comment-column-face |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
264 '((t |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
265 (:inherit ruler-mode-default-face |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
266 :foreground "red" |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
267 ))) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
268 "Face used to highlight the comment column character." |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
269 :group 'ruler-mode) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
270 |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
271 (defface ruler-mode-goal-column-face |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
272 '((t |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
273 (:inherit ruler-mode-default-face |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
274 :foreground "red" |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
275 ))) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
276 "Face used to highlight the goal column character." |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
277 :group 'ruler-mode) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
278 |
39731 | 279 (defface ruler-mode-tab-stop-face |
280 '((t | |
281 (:inherit ruler-mode-default-face | |
282 :foreground "steelblue" | |
283 ))) | |
284 "Face used to highlight tab stop characters." | |
285 :group 'ruler-mode) | |
286 | |
287 (defface ruler-mode-current-column-face | |
288 '((t | |
289 (:inherit ruler-mode-default-face | |
290 :weight bold | |
291 :foreground "yellow" | |
292 ))) | |
293 "Face used to highlight the `current-column' character." | |
294 :group 'ruler-mode) | |
41461 | 295 |
51389 | 296 (defmacro ruler-mode-left-fringe-cols () |
297 "Return the width, measured in columns, of the left fringe area." | |
298 '(ceiling (or (car (window-fringes)) 0) | |
299 (frame-char-width))) | |
300 | |
301 (defmacro ruler-mode-right-fringe-cols () | |
302 "Return the width, measured in columns, of the right fringe area." | |
303 '(ceiling (or (nth 1 (window-fringes)) 0) | |
304 (frame-char-width))) | |
305 | |
306 (defun ruler-mode-left-scroll-bar-cols () | |
307 "Return the width, measured in columns, of the right vertical scrollbar." | |
308 (let* ((wsb (window-scroll-bars)) | |
309 (vtype (nth 2 wsb)) | |
310 (cols (nth 1 wsb))) | |
311 (if (or (eq vtype 'left) | |
312 (and (eq vtype t) | |
313 (eq (frame-parameter nil 'vertical-scroll-bars) 'left))) | |
314 (or cols | |
315 (ceiling | |
316 ;; nil means it's a non-toolkit scroll bar, | |
317 ;; and its width in columns is 14 pixels rounded up. | |
318 (or (frame-parameter nil 'scroll-bar-width) 14) | |
319 ;; Always round up to multiple of columns. | |
320 (frame-char-width))) | |
321 0))) | |
322 | |
323 (defun ruler-mode-right-scroll-bar-cols () | |
324 "Return the width, measured in columns, of the right vertical scrollbar." | |
325 (let* ((wsb (window-scroll-bars)) | |
326 (vtype (nth 2 wsb)) | |
327 (cols (nth 1 wsb))) | |
328 (if (or (eq vtype 'right) | |
329 (and (eq vtype t) | |
330 (eq (frame-parameter nil 'vertical-scroll-bars) 'right))) | |
331 (or cols | |
332 (ceiling | |
333 ;; nil means it's a non-toolkit scroll bar, | |
334 ;; and its width in columns is 14 pixels rounded up. | |
335 (or (frame-parameter nil 'scroll-bar-width) 14) | |
336 ;; Always round up to multiple of columns. | |
337 (frame-char-width))) | |
338 0))) | |
339 | |
340 (defsubst ruler-mode-full-window-width () | |
341 "Return the full width of the selected window." | |
342 (let ((edges (window-edges))) | |
343 (- (nth 2 edges) (nth 0 edges)))) | |
344 | |
345 (defsubst ruler-mode-window-col (n) | |
346 "Return a column number relative to the selected window. | |
347 N is a column number relative to selected frame." | |
348 (- n | |
349 (car (window-edges)) | |
350 (or (car (window-margins)) 0) | |
351 (ruler-mode-left-fringe-cols) | |
352 (ruler-mode-left-scroll-bar-cols))) | |
353 | |
39731 | 354 (defun ruler-mode-mouse-set-left-margin (start-event) |
51389 | 355 "Set left margin end to the graduation where the mouse pointer is on. |
39731 | 356 START-EVENT is the mouse click event." |
357 (interactive "e") | |
358 (let* ((start (event-start start-event)) | |
359 (end (event-end start-event)) | |
51389 | 360 col w lm rm) |
361 (when (eq start end) ;; mouse click | |
362 (save-selected-window | |
363 (select-window (posn-window start)) | |
364 (setq col (- (car (posn-col-row start)) (car (window-edges)) | |
365 (ruler-mode-left-scroll-bar-cols)) | |
366 w (- (ruler-mode-full-window-width) | |
367 (ruler-mode-left-scroll-bar-cols) | |
368 (ruler-mode-right-scroll-bar-cols))) | |
369 (when (and (>= col 0) (< col w)) | |
370 (setq lm (window-margins) | |
371 rm (or (cdr lm) 0) | |
372 lm (or (car lm) 0)) | |
373 (message "Left margin set to %d (was %d)" col lm) | |
374 (set-window-margins nil col rm)))))) | |
39731 | 375 |
376 (defun ruler-mode-mouse-set-right-margin (start-event) | |
51389 | 377 "Set right margin beginning to the graduation where the mouse pointer is on. |
39731 | 378 START-EVENT is the mouse click event." |
379 (interactive "e") | |
380 (let* ((start (event-start start-event)) | |
381 (end (event-end start-event)) | |
51389 | 382 col w lm rm) |
383 (when (eq start end) ;; mouse click | |
384 (save-selected-window | |
385 (select-window (posn-window start)) | |
386 (setq col (- (car (posn-col-row start)) (car (window-edges)) | |
387 (ruler-mode-left-scroll-bar-cols)) | |
388 w (- (ruler-mode-full-window-width) | |
389 (ruler-mode-left-scroll-bar-cols) | |
390 (ruler-mode-right-scroll-bar-cols))) | |
391 (when (and (>= col 0) (< col w)) | |
392 (setq lm (window-margins) | |
393 rm (or (cdr lm) 0) | |
394 lm (or (car lm) 0) | |
395 col (- w col 1)) | |
396 (message "Right margin set to %d (was %d)" col rm) | |
397 (set-window-margins nil lm col)))))) | |
39731 | 398 |
51389 | 399 (defvar ruler-mode-dragged-symbol nil |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
400 "Column symbol dragged in the ruler. |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
401 That is `fill-column', `comment-column', `goal-column', or nil when |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
402 nothing is dragged.") |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
403 |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
404 (defun ruler-mode-mouse-grab-any-column (start-event) |
51389 | 405 "Drag a column symbol on the ruler. |
406 Start dragging on mouse down event START-EVENT, and update the column | |
407 symbol value with the current value of the ruler graduation while | |
408 dragging. See also the variable `ruler-mode-dragged-symbol'." | |
39731 | 409 (interactive "e") |
51389 | 410 (setq ruler-mode-dragged-symbol nil) |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
411 (let* ((start (event-start start-event)) |
51389 | 412 col newc oldc) |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
413 (save-selected-window |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
414 (select-window (posn-window start)) |
51389 | 415 (setq col (ruler-mode-window-col (car (posn-col-row start))) |
416 newc (+ col (window-hscroll))) | |
417 (and | |
418 (>= col 0) (< col (window-width)) | |
419 (cond | |
420 | |
421 ;; Handle the fill column. | |
422 ((eq newc fill-column) | |
423 (setq oldc fill-column | |
424 ruler-mode-dragged-symbol 'fill-column) | |
425 t) ;; Start dragging | |
426 | |
427 ;; Handle the comment column. | |
428 ((eq newc comment-column) | |
429 (setq oldc comment-column | |
430 ruler-mode-dragged-symbol 'comment-column) | |
431 t) ;; Start dragging | |
39731 | 432 |
51389 | 433 ;; Handle the goal column. |
434 ;; A. On mouse down on the goal column character on the ruler, | |
435 ;; update the `goal-column' value while dragging. | |
436 ;; B. If `goal-column' is nil, set the goal column where the | |
437 ;; mouse is clicked. | |
438 ;; C. On mouse click on the goal column character on the | |
439 ;; ruler, unset the goal column. | |
440 ((eq newc goal-column) ; A. Drag the goal column. | |
441 (setq oldc goal-column | |
442 ruler-mode-dragged-symbol 'goal-column) | |
443 t) ;; Start dragging | |
444 | |
445 ((null goal-column) ; B. Set the goal column. | |
446 (setq oldc goal-column | |
447 goal-column newc) | |
448 ;; mouse-2 coming AFTER drag-mouse-2 invokes `ding'. This | |
449 ;; `ding' flushes the next messages about setting goal | |
450 ;; column. So here I force fetch the event(mouse-2) and | |
451 ;; throw away. | |
452 (read-event) | |
453 ;; Ding BEFORE `message' is OK. | |
454 (when ruler-mode-set-goal-column-ding-flag | |
455 (ding)) | |
456 (message "Goal column set to %d (click on %s again to unset it)" | |
457 newc | |
458 (propertize (char-to-string ruler-mode-goal-column-char) | |
459 'face 'ruler-mode-goal-column-face)) | |
460 nil) ;; Don't start dragging. | |
461 ) | |
462 (if (eq 'click (ruler-mode-mouse-drag-any-column-iteration | |
463 (posn-window start))) | |
464 (when (eq 'goal-column ruler-mode-dragged-symbol) | |
465 ;; C. Unset the goal column. | |
466 (set-goal-column t)) | |
467 ;; At end of dragging, report the updated column symbol. | |
468 (message "%s is set to %d (was %d)" | |
469 ruler-mode-dragged-symbol | |
470 (symbol-value ruler-mode-dragged-symbol) | |
471 oldc)))))) | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
472 |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
473 (defun ruler-mode-mouse-drag-any-column-iteration (window) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
474 "Update the ruler while dragging the mouse. |
51389 | 475 WINDOW is the window where occurred the last down-mouse event. |
476 Return the symbol `drag' if the mouse has been dragged, or `click' if | |
477 the mouse has been clicked." | |
478 (let ((drags 0) | |
479 event) | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
480 (track-mouse |
51389 | 481 (while (mouse-movement-p (setq event (read-event))) |
482 (setq drags (1+ drags)) | |
483 (when (eq window (posn-window (event-end event))) | |
484 (ruler-mode-mouse-drag-any-column event) | |
485 (force-mode-line-update)))) | |
486 (if (and (zerop drags) (eq 'click (car (event-modifiers event)))) | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
487 'click |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
488 'drag))) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
489 |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
490 (defun ruler-mode-mouse-drag-any-column (start-event) |
51389 | 491 "Update the value of the symbol dragged on the ruler. |
492 Called on each mouse motion event START-EVENT." | |
39731 | 493 (let* ((start (event-start start-event)) |
494 (end (event-end start-event)) | |
51389 | 495 col newc) |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
496 (save-selected-window |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
497 (select-window (posn-window start)) |
51389 | 498 (setq col (ruler-mode-window-col (car (posn-col-row end))) |
499 newc (+ col (window-hscroll))) | |
500 (when (and (>= col 0) (< col (window-width))) | |
501 (set ruler-mode-dragged-symbol newc))))) | |
41461 | 502 |
39731 | 503 (defun ruler-mode-mouse-add-tab-stop (start-event) |
504 "Add a tab stop to the graduation where the mouse pointer is on. | |
505 START-EVENT is the mouse click event." | |
506 (interactive "e") | |
51389 | 507 (when ruler-mode-show-tab-stops |
508 (let* ((start (event-start start-event)) | |
509 (end (event-end start-event)) | |
510 col ts) | |
511 (when (eq start end) ;; mouse click | |
512 (save-selected-window | |
513 (select-window (posn-window start)) | |
514 (setq col (ruler-mode-window-col (car (posn-col-row start))) | |
515 ts (+ col (window-hscroll))) | |
516 (and (>= col 0) (< col (window-width)) | |
517 (not (member ts tab-stop-list)) | |
518 (progn | |
519 (message "Tab stop set to %d" ts) | |
520 (setq tab-stop-list (sort (cons ts tab-stop-list) | |
521 #'<))))))))) | |
39731 | 522 |
523 (defun ruler-mode-mouse-del-tab-stop (start-event) | |
524 "Delete tab stop at the graduation where the mouse pointer is on. | |
525 START-EVENT is the mouse click event." | |
526 (interactive "e") | |
51389 | 527 (when ruler-mode-show-tab-stops |
528 (let* ((start (event-start start-event)) | |
529 (end (event-end start-event)) | |
530 col ts) | |
531 (when (eq start end) ;; mouse click | |
532 (save-selected-window | |
533 (select-window (posn-window start)) | |
534 (setq col (ruler-mode-window-col (car (posn-col-row start))) | |
535 ts (+ col (window-hscroll))) | |
536 (and (>= col 0) (< col (window-width)) | |
537 (member ts tab-stop-list) | |
538 (progn | |
539 (message "Tab stop at %d deleted" ts) | |
540 (setq tab-stop-list (delete ts tab-stop-list))))))))) | |
39731 | 541 |
542 (defun ruler-mode-toggle-show-tab-stops () | |
543 "Toggle showing of tab stops on the ruler." | |
544 (interactive) | |
41461 | 545 (setq ruler-mode-show-tab-stops (not ruler-mode-show-tab-stops)) |
546 (force-mode-line-update)) | |
547 | |
39731 | 548 (defvar ruler-mode-map |
549 (let ((km (make-sparse-keymap))) | |
550 (define-key km [header-line down-mouse-1] | |
551 #'ignore) | |
552 (define-key km [header-line down-mouse-3] | |
553 #'ignore) | |
554 (define-key km [header-line down-mouse-2] | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
555 #'ruler-mode-mouse-grab-any-column) |
39731 | 556 (define-key km [header-line (shift down-mouse-1)] |
557 #'ruler-mode-mouse-set-left-margin) | |
558 (define-key km [header-line (shift down-mouse-3)] | |
559 #'ruler-mode-mouse-set-right-margin) | |
560 (define-key km [header-line (control down-mouse-1)] | |
561 #'ruler-mode-mouse-add-tab-stop) | |
562 (define-key km [header-line (control down-mouse-3)] | |
563 #'ruler-mode-mouse-del-tab-stop) | |
564 (define-key km [header-line (control down-mouse-2)] | |
565 #'ruler-mode-toggle-show-tab-stops) | |
566 km) | |
567 "Keymap for ruler minor mode.") | |
568 | |
569 (defvar ruler-mode-header-line-format-old nil | |
570 "Hold previous value of `header-line-format'.") | |
571 (make-variable-buffer-local 'ruler-mode-header-line-format-old) | |
572 | |
573 (defconst ruler-mode-header-line-format | |
574 '(:eval (ruler-mode-ruler)) | |
575 "`header-line-format' used in ruler mode.") | |
576 | |
577 ;;;###autoload | |
578 (define-minor-mode ruler-mode | |
579 "Display a ruler in the header line if ARG > 0." | |
580 nil nil | |
581 ruler-mode-map | |
582 :group 'ruler-mode | |
583 (if ruler-mode | |
584 (progn | |
585 ;; When `ruler-mode' is on save previous header line format | |
586 ;; and install the ruler header line format. | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
587 (when (local-variable-p 'header-line-format) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
588 (setq ruler-mode-header-line-format-old header-line-format)) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
589 (setq header-line-format ruler-mode-header-line-format) |
39731 | 590 (add-hook 'post-command-hook ; add local hook |
591 #'force-mode-line-update nil t)) | |
592 ;; When `ruler-mode' is off restore previous header line format if | |
593 ;; the current one is the ruler header line format. | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
594 (when (eq header-line-format ruler-mode-header-line-format) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
595 (kill-local-variable 'header-line-format) |
51389 | 596 (when (local-variable-p 'ruler-mode-header-line-format-old) |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
597 (setq header-line-format ruler-mode-header-line-format-old))) |
39731 | 598 (remove-hook 'post-command-hook ; remove local hook |
599 #'force-mode-line-update t))) | |
41461 | 600 |
42706 | 601 ;; Add ruler-mode to the minor mode menu in the mode line |
39731 | 602 (define-key mode-line-mode-menu [ruler-mode] |
603 `(menu-item "Ruler" ruler-mode | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
604 :button (:toggle . ruler-mode))) |
39731 | 605 |
606 (defconst ruler-mode-ruler-help-echo | |
607 "\ | |
608 S-mouse-1/3: set L/R margin, \ | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
609 mouse-2: set goal column, \ |
39731 | 610 C-mouse-2: show tabs" |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
611 "Help string shown when mouse is over the ruler. |
39731 | 612 `ruler-mode-show-tab-stops' is nil.") |
613 | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
614 (defconst ruler-mode-ruler-help-echo-when-goal-column |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
615 "\ |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
616 S-mouse-1/3: set L/R margin, \ |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
617 C-mouse-2: show tabs" |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
618 "Help string shown when mouse is over the ruler. |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
619 `goal-column' is set and `ruler-mode-show-tab-stops' is nil.") |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
620 |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
621 (defconst ruler-mode-ruler-help-echo-when-tab-stops |
39731 | 622 "\ |
623 C-mouse1/3: set/unset tab, \ | |
624 C-mouse-2: hide tabs" | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
625 "Help string shown when mouse is over the ruler. |
39731 | 626 `ruler-mode-show-tab-stops' is non-nil.") |
627 | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
628 (defconst ruler-mode-fill-column-help-echo |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
629 "drag-mouse-2: set fill column" |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
630 "Help string shown when mouse is on the fill column character.") |
39731 | 631 |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
632 (defconst ruler-mode-comment-column-help-echo |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
633 "drag-mouse-2: set comment column" |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
634 "Help string shown when mouse is on the comment column character.") |
42020
6e891121e1cc
(ruler-mode-extra-left-cols): Removed.
Richard M. Stallman <rms@gnu.org>
parents:
42003
diff
changeset
|
635 |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
636 (defconst ruler-mode-goal-column-help-echo |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
637 "\ |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
638 drag-mouse-2: set goal column, \ |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
639 mouse-2: unset goal column" |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
640 "Help string shown when mouse is on the goal column character.") |
42020
6e891121e1cc
(ruler-mode-extra-left-cols): Removed.
Richard M. Stallman <rms@gnu.org>
parents:
42003
diff
changeset
|
641 |
51389 | 642 (defconst ruler-mode-margin-help-echo |
643 "%s margin %S" | |
644 "Help string shown when mouse is over a margin area.") | |
42020
6e891121e1cc
(ruler-mode-extra-left-cols): Removed.
Richard M. Stallman <rms@gnu.org>
parents:
42003
diff
changeset
|
645 |
51389 | 646 (defconst ruler-mode-fringe-help-echo |
647 "%s fringe %S" | |
648 "Help string shown when mouse is over a fringe area.") | |
41461 | 649 |
39731 | 650 (defun ruler-mode-ruler () |
651 "Return a string ruler." | |
51389 | 652 (when ruler-mode |
653 (let* ((fullw (ruler-mode-full-window-width)) | |
654 (w (window-width)) | |
655 (m (window-margins)) | |
656 (lsb (ruler-mode-left-scroll-bar-cols)) | |
657 (lf (ruler-mode-left-fringe-cols)) | |
658 (lm (or (car m) 0)) | |
659 (rsb (ruler-mode-right-scroll-bar-cols)) | |
660 (rf (ruler-mode-right-fringe-cols)) | |
661 (rm (or (cdr m) 0)) | |
662 (ruler (make-string fullw ruler-mode-basic-graduation-char)) | |
663 (o (+ lsb lf lm)) | |
664 (x 0) | |
665 (i o) | |
666 (j (window-hscroll)) | |
667 k c l1 l2 r2 r1 h1 h2 f1 f2) | |
39731 | 668 |
51389 | 669 ;; Setup the default properties. |
670 (put-text-property 0 fullw 'face 'ruler-mode-default-face ruler) | |
671 (put-text-property 0 fullw | |
672 'help-echo | |
673 (cond | |
674 (ruler-mode-show-tab-stops | |
675 ruler-mode-ruler-help-echo-when-tab-stops) | |
676 (goal-column | |
677 ruler-mode-ruler-help-echo-when-goal-column) | |
678 (t | |
679 ruler-mode-ruler-help-echo)) | |
680 ruler) | |
681 ;; Setup the local map. | |
682 (put-text-property 0 fullw 'local-map ruler-mode-map ruler) | |
39731 | 683 |
51389 | 684 ;; Setup the active area. |
685 (while (< x w) | |
686 ;; Graduations. | |
687 (cond | |
688 ;; Show a number graduation. | |
689 ((= (mod j 10) 0) | |
690 (setq c (number-to-string (/ j 10)) | |
691 m (length c) | |
692 k i) | |
693 (put-text-property | |
694 i (1+ i) 'face 'ruler-mode-column-number-face | |
695 ruler) | |
696 (while (and (> m 0) (>= k 0)) | |
697 (aset ruler k (aref c (setq m (1- m)))) | |
698 (setq k (1- k)))) | |
699 ;; Show an intermediate graduation. | |
700 ((= (mod j 5) 0) | |
701 (aset ruler i ruler-mode-inter-graduation-char))) | |
702 ;; Special columns. | |
703 (cond | |
704 ;; Show the `current-column' marker. | |
705 ((= j (current-column)) | |
706 (aset ruler i ruler-mode-current-column-char) | |
707 (put-text-property | |
708 i (1+ i) 'face 'ruler-mode-current-column-face | |
709 ruler)) | |
710 ;; Show the `goal-column' marker. | |
711 ((and goal-column (= j goal-column)) | |
712 (aset ruler i ruler-mode-goal-column-char) | |
713 (put-text-property | |
714 i (1+ i) 'face 'ruler-mode-goal-column-face | |
715 ruler) | |
716 (put-text-property | |
717 i (1+ i) 'help-echo ruler-mode-goal-column-help-echo | |
718 ruler)) | |
719 ;; Show the `comment-column' marker. | |
720 ((= j comment-column) | |
721 (aset ruler i ruler-mode-comment-column-char) | |
722 (put-text-property | |
723 i (1+ i) 'face 'ruler-mode-comment-column-face | |
724 ruler) | |
725 (put-text-property | |
726 i (1+ i) 'help-echo ruler-mode-comment-column-help-echo | |
727 ruler)) | |
728 ;; Show the `fill-column' marker. | |
729 ((= j fill-column) | |
730 (aset ruler i ruler-mode-fill-column-char) | |
731 (put-text-property | |
732 i (1+ i) 'face 'ruler-mode-fill-column-face | |
733 ruler) | |
734 (put-text-property | |
735 i (1+ i) 'help-echo ruler-mode-fill-column-help-echo | |
736 ruler)) | |
737 ;; Show the `tab-stop-list' markers. | |
738 ((and ruler-mode-show-tab-stops (member j tab-stop-list)) | |
739 (aset ruler i ruler-mode-tab-stop-char) | |
740 (put-text-property | |
741 i (1+ i) 'face 'ruler-mode-tab-stop-face | |
742 ruler))) | |
743 (setq i (1+ i) | |
744 j (1+ j) | |
745 x (1+ x))) | |
39731 | 746 |
51389 | 747 ;; Highlight the fringes and margins. |
748 (if (nth 2 (window-fringes)) | |
749 ;; fringes outside margins. | |
750 (setq l1 lf | |
751 l2 lm | |
752 r2 rm | |
753 r1 rf | |
754 h1 ruler-mode-fringe-help-echo | |
755 h2 ruler-mode-margin-help-echo | |
756 f1 'ruler-mode-fringes-face | |
757 f2 'ruler-mode-margins-face) | |
758 ;; fringes inside margins. | |
759 (setq l1 lm | |
760 l2 lf | |
761 r2 rf | |
762 r1 rm | |
763 h1 ruler-mode-margin-help-echo | |
764 h2 ruler-mode-fringe-help-echo | |
765 f1 'ruler-mode-margins-face | |
766 f2 'ruler-mode-fringes-face)) | |
767 (setq i lsb j (+ i l1)) | |
768 (put-text-property i j 'face f1 ruler) | |
769 (put-text-property i j 'help-echo (format h1 "Left" l1) ruler) | |
770 (setq i j j (+ i l2)) | |
771 (put-text-property i j 'face f2 ruler) | |
772 (put-text-property i j 'help-echo (format h2 "Left" l2) ruler) | |
773 (setq i (+ o w) j (+ i r2)) | |
774 (put-text-property i j 'face f2 ruler) | |
775 (put-text-property i j 'help-echo (format h2 "Right" r2) ruler) | |
776 (setq i j j (+ i r1)) | |
777 (put-text-property i j 'face f1 ruler) | |
778 (put-text-property i j 'help-echo (format h1 "Right" r1) ruler) | |
39731 | 779 |
51389 | 780 ;; Show inactive areas. |
781 (put-text-property 0 lsb 'face 'ruler-mode-pad-face ruler) | |
782 (put-text-property j fullw 'face 'ruler-mode-pad-face ruler) | |
39731 | 783 |
51389 | 784 ;; Return the ruler propertized string. |
785 ruler))) | |
39731 | 786 |
787 (provide 'ruler-mode) | |
788 | |
789 ;; Local Variables: | |
790 ;; coding: iso-latin-1 | |
791 ;; End: | |
792 | |
793 ;;; ruler-mode.el ends here |