Mercurial > emacs
annotate lisp/ruler-mode.el @ 89930:de927c4adfc4
(unicode-data): Fix the previous change.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 27 Apr 2004 10:54:16 +0000 |
parents | 68c22ea6027c |
children | 3ebd9bdb4fe5 |
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 |
89909 | 3 ;; Copyright (C) 2001, 2002, 2003, 2004 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. | |
89909 | 97 ;; |
98 ;; You can override the ruler format by defining an appropriate | |
99 ;; function as the buffer-local value of `ruler-mode-ruler-function'. | |
39731 | 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 ;; | |
41461 | 110 |
39731 | 111 ;;; Code: |
112 (eval-when-compile | |
113 (require 'wid-edit)) | |
89909 | 114 (require 'scroll-bar) |
115 (require 'fringe) | |
39731 | 116 |
117 (defgroup ruler-mode nil | |
118 "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
|
119 :version "21.4" |
47183
865837df3fe7
(defgroup ruler-mode): Use `convenience' as parent.
Richard M. Stallman <rms@gnu.org>
parents:
45255
diff
changeset
|
120 :group 'convenience) |
39731 | 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))) | |
88997
71bcf52caa3b
(ruler-mode-character-validate): Use characterp.
Dave Love <fx@gnu.org>
parents:
42836
diff
changeset
|
137 (unless (characterp value) |
39731 | 138 (widget-put widget :error |
139 (format "Invalid character value: %S" value)) | |
140 widget)))) | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
141 |
89909 | 142 (defcustom ruler-mode-fill-column-char (if (char-displayable-p ?¶) |
39731 | 143 ?\¶ |
144 ?\|) | |
145 "*Character used at the `fill-column' location." | |
146 :group 'ruler-mode | |
147 :type '(choice | |
148 (character :tag "Character") | |
149 (integer :tag "Integer char value" | |
150 :validate ruler-mode-character-validate))) | |
151 | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
152 (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
|
153 "*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
|
154 :group 'ruler-mode |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
155 :type '(choice |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
156 (character :tag "Character") |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
157 (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
|
158 :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
|
159 |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
160 (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
|
161 "*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
|
162 :group 'ruler-mode |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
163 :type '(choice |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
164 (character :tag "Character") |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
165 (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
|
166 :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
|
167 |
89909 | 168 (defcustom ruler-mode-current-column-char (if (char-displayable-p ?¦) |
39731 | 169 ?\¦ |
170 ?\@) | |
171 "*Character used at the `current-column' location." | |
172 :group 'ruler-mode | |
173 :type '(choice | |
174 (character :tag "Character") | |
175 (integer :tag "Integer char value" | |
176 :validate ruler-mode-character-validate))) | |
177 | |
178 (defcustom ruler-mode-tab-stop-char ?\T | |
179 "*Character used at `tab-stop-list' locations." | |
180 :group 'ruler-mode | |
181 :type '(choice | |
182 (character :tag "Character") | |
183 (integer :tag "Integer char value" | |
184 :validate ruler-mode-character-validate))) | |
185 | |
186 (defcustom ruler-mode-basic-graduation-char ?\. | |
187 "*Character used for basic graduations." | |
188 :group 'ruler-mode | |
189 :type '(choice | |
190 (character :tag "Character") | |
191 (integer :tag "Integer char value" | |
192 :validate ruler-mode-character-validate))) | |
193 | |
194 (defcustom ruler-mode-inter-graduation-char ?\! | |
195 "*Character used for intermediate graduations." | |
196 :group 'ruler-mode | |
197 :type '(choice | |
198 (character :tag "Character") | |
199 (integer :tag "Integer char value" | |
200 :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
|
201 |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
202 (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
|
203 "*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
|
204 :group 'ruler-mode |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
205 :type 'boolean) |
41461 | 206 |
39731 | 207 (defface ruler-mode-default-face |
208 '((((type tty)) | |
209 (:inherit default | |
210 :background "grey64" | |
211 :foreground "grey50" | |
212 )) | |
213 (t | |
214 (:inherit default | |
215 :background "grey76" | |
216 :foreground "grey64" | |
217 :box (:color "grey76" | |
218 :line-width 1 | |
219 :style released-button) | |
220 ))) | |
221 "Default face used by the ruler." | |
222 :group 'ruler-mode) | |
223 | |
51389 | 224 (defface ruler-mode-pad-face |
225 '((((type tty)) | |
226 (:inherit ruler-mode-default-face | |
227 :background "grey50" | |
228 )) | |
229 (t | |
230 (:inherit ruler-mode-default-face | |
231 :background "grey64" | |
232 ))) | |
233 "Face used to pad inactive ruler areas." | |
234 :group 'ruler-mode) | |
235 | |
236 (defface ruler-mode-margins-face | |
237 '((t | |
238 (:inherit ruler-mode-default-face | |
239 :foreground "white" | |
240 ))) | |
241 "Face used to highlight margin areas." | |
242 :group 'ruler-mode) | |
243 | |
244 (defface ruler-mode-fringes-face | |
245 '((t | |
246 (:inherit ruler-mode-default-face | |
247 :foreground "green" | |
248 ))) | |
249 "Face used to highlight fringes areas." | |
250 :group 'ruler-mode) | |
251 | |
39731 | 252 (defface ruler-mode-column-number-face |
253 '((t | |
254 (:inherit ruler-mode-default-face | |
255 :foreground "black" | |
256 ))) | |
257 "Face used to highlight number graduations." | |
258 :group 'ruler-mode) | |
259 | |
260 (defface ruler-mode-fill-column-face | |
261 '((t | |
262 (:inherit ruler-mode-default-face | |
263 :foreground "red" | |
264 ))) | |
265 "Face used to highlight the fill column character." | |
266 :group 'ruler-mode) | |
267 | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
268 (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
|
269 '((t |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
270 (: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
|
271 :foreground "red" |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
272 ))) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
273 "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
|
274 :group 'ruler-mode) |
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 (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
|
277 '((t |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
278 (: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
|
279 :foreground "red" |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
280 ))) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
281 "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
|
282 :group 'ruler-mode) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
283 |
39731 | 284 (defface ruler-mode-tab-stop-face |
285 '((t | |
286 (:inherit ruler-mode-default-face | |
287 :foreground "steelblue" | |
288 ))) | |
289 "Face used to highlight tab stop characters." | |
290 :group 'ruler-mode) | |
291 | |
292 (defface ruler-mode-current-column-face | |
293 '((t | |
294 (:inherit ruler-mode-default-face | |
295 :weight bold | |
296 :foreground "yellow" | |
297 ))) | |
298 "Face used to highlight the `current-column' character." | |
299 :group 'ruler-mode) | |
41461 | 300 |
51389 | 301 |
302 (defsubst ruler-mode-full-window-width () | |
303 "Return the full width of the selected window." | |
304 (let ((edges (window-edges))) | |
305 (- (nth 2 edges) (nth 0 edges)))) | |
306 | |
307 (defsubst ruler-mode-window-col (n) | |
308 "Return a column number relative to the selected window. | |
309 N is a column number relative to selected frame." | |
310 (- n | |
311 (car (window-edges)) | |
312 (or (car (window-margins)) 0) | |
89909 | 313 (fringe-columns 'left) |
314 (scroll-bar-columns 'left))) | |
51389 | 315 |
39731 | 316 (defun ruler-mode-mouse-set-left-margin (start-event) |
51389 | 317 "Set left margin end to the graduation where the mouse pointer is on. |
39731 | 318 START-EVENT is the mouse click event." |
319 (interactive "e") | |
320 (let* ((start (event-start start-event)) | |
321 (end (event-end start-event)) | |
51389 | 322 col w lm rm) |
323 (when (eq start end) ;; mouse click | |
324 (save-selected-window | |
325 (select-window (posn-window start)) | |
326 (setq col (- (car (posn-col-row start)) (car (window-edges)) | |
89909 | 327 (scroll-bar-columns 'left)) |
51389 | 328 w (- (ruler-mode-full-window-width) |
89909 | 329 (scroll-bar-columns 'left) |
330 (scroll-bar-columns 'right))) | |
51389 | 331 (when (and (>= col 0) (< col w)) |
332 (setq lm (window-margins) | |
333 rm (or (cdr lm) 0) | |
334 lm (or (car lm) 0)) | |
335 (message "Left margin set to %d (was %d)" col lm) | |
336 (set-window-margins nil col rm)))))) | |
39731 | 337 |
338 (defun ruler-mode-mouse-set-right-margin (start-event) | |
51389 | 339 "Set right margin beginning to the graduation where the mouse pointer is on. |
39731 | 340 START-EVENT is the mouse click event." |
341 (interactive "e") | |
342 (let* ((start (event-start start-event)) | |
343 (end (event-end start-event)) | |
51389 | 344 col w lm rm) |
345 (when (eq start end) ;; mouse click | |
346 (save-selected-window | |
347 (select-window (posn-window start)) | |
348 (setq col (- (car (posn-col-row start)) (car (window-edges)) | |
89909 | 349 (scroll-bar-columns 'left)) |
51389 | 350 w (- (ruler-mode-full-window-width) |
89909 | 351 (scroll-bar-columns 'left) |
352 (scroll-bar-columns 'right))) | |
51389 | 353 (when (and (>= col 0) (< col w)) |
354 (setq lm (window-margins) | |
355 rm (or (cdr lm) 0) | |
356 lm (or (car lm) 0) | |
357 col (- w col 1)) | |
358 (message "Right margin set to %d (was %d)" col rm) | |
359 (set-window-margins nil lm col)))))) | |
39731 | 360 |
51389 | 361 (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
|
362 "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
|
363 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
|
364 nothing is dragged.") |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
365 |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
366 (defun ruler-mode-mouse-grab-any-column (start-event) |
51389 | 367 "Drag a column symbol on the ruler. |
368 Start dragging on mouse down event START-EVENT, and update the column | |
369 symbol value with the current value of the ruler graduation while | |
370 dragging. See also the variable `ruler-mode-dragged-symbol'." | |
39731 | 371 (interactive "e") |
51389 | 372 (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
|
373 (let* ((start (event-start start-event)) |
51389 | 374 col newc oldc) |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
375 (save-selected-window |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
376 (select-window (posn-window start)) |
51389 | 377 (setq col (ruler-mode-window-col (car (posn-col-row start))) |
378 newc (+ col (window-hscroll))) | |
379 (and | |
380 (>= col 0) (< col (window-width)) | |
381 (cond | |
382 | |
383 ;; Handle the fill column. | |
384 ((eq newc fill-column) | |
385 (setq oldc fill-column | |
386 ruler-mode-dragged-symbol 'fill-column) | |
387 t) ;; Start dragging | |
388 | |
389 ;; Handle the comment column. | |
390 ((eq newc comment-column) | |
391 (setq oldc comment-column | |
392 ruler-mode-dragged-symbol 'comment-column) | |
393 t) ;; Start dragging | |
39731 | 394 |
51389 | 395 ;; Handle the goal column. |
396 ;; A. On mouse down on the goal column character on the ruler, | |
397 ;; update the `goal-column' value while dragging. | |
398 ;; B. If `goal-column' is nil, set the goal column where the | |
399 ;; mouse is clicked. | |
400 ;; C. On mouse click on the goal column character on the | |
401 ;; ruler, unset the goal column. | |
402 ((eq newc goal-column) ; A. Drag the goal column. | |
403 (setq oldc goal-column | |
404 ruler-mode-dragged-symbol 'goal-column) | |
405 t) ;; Start dragging | |
406 | |
407 ((null goal-column) ; B. Set the goal column. | |
408 (setq oldc goal-column | |
409 goal-column newc) | |
410 ;; mouse-2 coming AFTER drag-mouse-2 invokes `ding'. This | |
411 ;; `ding' flushes the next messages about setting goal | |
412 ;; column. So here I force fetch the event(mouse-2) and | |
413 ;; throw away. | |
414 (read-event) | |
415 ;; Ding BEFORE `message' is OK. | |
416 (when ruler-mode-set-goal-column-ding-flag | |
417 (ding)) | |
418 (message "Goal column set to %d (click on %s again to unset it)" | |
419 newc | |
420 (propertize (char-to-string ruler-mode-goal-column-char) | |
421 'face 'ruler-mode-goal-column-face)) | |
422 nil) ;; Don't start dragging. | |
423 ) | |
424 (if (eq 'click (ruler-mode-mouse-drag-any-column-iteration | |
425 (posn-window start))) | |
426 (when (eq 'goal-column ruler-mode-dragged-symbol) | |
427 ;; C. Unset the goal column. | |
428 (set-goal-column t)) | |
429 ;; At end of dragging, report the updated column symbol. | |
430 (message "%s is set to %d (was %d)" | |
431 ruler-mode-dragged-symbol | |
432 (symbol-value ruler-mode-dragged-symbol) | |
433 oldc)))))) | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
434 |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
435 (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
|
436 "Update the ruler while dragging the mouse. |
51389 | 437 WINDOW is the window where occurred the last down-mouse event. |
438 Return the symbol `drag' if the mouse has been dragged, or `click' if | |
439 the mouse has been clicked." | |
440 (let ((drags 0) | |
441 event) | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
442 (track-mouse |
51389 | 443 (while (mouse-movement-p (setq event (read-event))) |
444 (setq drags (1+ drags)) | |
445 (when (eq window (posn-window (event-end event))) | |
446 (ruler-mode-mouse-drag-any-column event) | |
447 (force-mode-line-update)))) | |
448 (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
|
449 'click |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
450 'drag))) |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
451 |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
452 (defun ruler-mode-mouse-drag-any-column (start-event) |
51389 | 453 "Update the value of the symbol dragged on the ruler. |
454 Called on each mouse motion event START-EVENT." | |
39731 | 455 (let* ((start (event-start start-event)) |
456 (end (event-end start-event)) | |
51389 | 457 col newc) |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
458 (save-selected-window |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
459 (select-window (posn-window start)) |
51389 | 460 (setq col (ruler-mode-window-col (car (posn-col-row end))) |
461 newc (+ col (window-hscroll))) | |
462 (when (and (>= col 0) (< col (window-width))) | |
463 (set ruler-mode-dragged-symbol newc))))) | |
41461 | 464 |
39731 | 465 (defun ruler-mode-mouse-add-tab-stop (start-event) |
466 "Add a tab stop to the graduation where the mouse pointer is on. | |
467 START-EVENT is the mouse click event." | |
468 (interactive "e") | |
51389 | 469 (when ruler-mode-show-tab-stops |
470 (let* ((start (event-start start-event)) | |
471 (end (event-end start-event)) | |
472 col ts) | |
473 (when (eq start end) ;; mouse click | |
474 (save-selected-window | |
475 (select-window (posn-window start)) | |
476 (setq col (ruler-mode-window-col (car (posn-col-row start))) | |
477 ts (+ col (window-hscroll))) | |
478 (and (>= col 0) (< col (window-width)) | |
479 (not (member ts tab-stop-list)) | |
480 (progn | |
481 (message "Tab stop set to %d" ts) | |
482 (setq tab-stop-list (sort (cons ts tab-stop-list) | |
483 #'<))))))))) | |
39731 | 484 |
485 (defun ruler-mode-mouse-del-tab-stop (start-event) | |
486 "Delete tab stop at the graduation where the mouse pointer is on. | |
487 START-EVENT is the mouse click event." | |
488 (interactive "e") | |
51389 | 489 (when ruler-mode-show-tab-stops |
490 (let* ((start (event-start start-event)) | |
491 (end (event-end start-event)) | |
492 col ts) | |
493 (when (eq start end) ;; mouse click | |
494 (save-selected-window | |
495 (select-window (posn-window start)) | |
496 (setq col (ruler-mode-window-col (car (posn-col-row start))) | |
497 ts (+ col (window-hscroll))) | |
498 (and (>= col 0) (< col (window-width)) | |
499 (member ts tab-stop-list) | |
500 (progn | |
501 (message "Tab stop at %d deleted" ts) | |
502 (setq tab-stop-list (delete ts tab-stop-list))))))))) | |
39731 | 503 |
504 (defun ruler-mode-toggle-show-tab-stops () | |
505 "Toggle showing of tab stops on the ruler." | |
506 (interactive) | |
41461 | 507 (setq ruler-mode-show-tab-stops (not ruler-mode-show-tab-stops)) |
508 (force-mode-line-update)) | |
509 | |
39731 | 510 (defvar ruler-mode-map |
511 (let ((km (make-sparse-keymap))) | |
512 (define-key km [header-line down-mouse-1] | |
513 #'ignore) | |
514 (define-key km [header-line down-mouse-3] | |
515 #'ignore) | |
516 (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
|
517 #'ruler-mode-mouse-grab-any-column) |
39731 | 518 (define-key km [header-line (shift down-mouse-1)] |
519 #'ruler-mode-mouse-set-left-margin) | |
520 (define-key km [header-line (shift down-mouse-3)] | |
521 #'ruler-mode-mouse-set-right-margin) | |
522 (define-key km [header-line (control down-mouse-1)] | |
523 #'ruler-mode-mouse-add-tab-stop) | |
524 (define-key km [header-line (control down-mouse-3)] | |
525 #'ruler-mode-mouse-del-tab-stop) | |
526 (define-key km [header-line (control down-mouse-2)] | |
527 #'ruler-mode-toggle-show-tab-stops) | |
528 km) | |
529 "Keymap for ruler minor mode.") | |
530 | |
531 (defvar ruler-mode-header-line-format-old nil | |
532 "Hold previous value of `header-line-format'.") | |
89909 | 533 |
534 (defvar ruler-mode-ruler-function 'ruler-mode-ruler | |
535 "Function to call to return ruler header line format. | |
536 This variable is expected to be made buffer-local by modes.") | |
39731 | 537 |
538 (defconst ruler-mode-header-line-format | |
89909 | 539 '(:eval (funcall ruler-mode-ruler-function)) |
540 "`header-line-format' used in ruler mode. | |
541 Call `ruler-mode-ruler-function' to compute the ruler value.") | |
39731 | 542 |
543 ;;;###autoload | |
544 (define-minor-mode ruler-mode | |
545 "Display a ruler in the header line if ARG > 0." | |
546 nil nil | |
547 ruler-mode-map | |
548 :group 'ruler-mode | |
549 (if ruler-mode | |
550 (progn | |
551 ;; When `ruler-mode' is on save previous header line format | |
552 ;; 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
|
553 (when (local-variable-p 'header-line-format) |
89909 | 554 (set (make-local-variable 'ruler-mode-header-line-format-old) |
555 header-line-format)) | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
556 (setq header-line-format ruler-mode-header-line-format) |
89909 | 557 (add-hook 'post-command-hook 'force-mode-line-update nil t)) |
39731 | 558 ;; When `ruler-mode' is off restore previous header line format if |
559 ;; 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
|
560 (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
|
561 (kill-local-variable 'header-line-format) |
51389 | 562 (when (local-variable-p 'ruler-mode-header-line-format-old) |
89909 | 563 (setq header-line-format ruler-mode-header-line-format-old) |
564 (kill-local-variable 'ruler-mode-header-line-format-old))) | |
565 (remove-hook 'post-command-hook 'force-mode-line-update t))) | |
41461 | 566 |
42706 | 567 ;; Add ruler-mode to the minor mode menu in the mode line |
39731 | 568 (define-key mode-line-mode-menu [ruler-mode] |
569 `(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
|
570 :button (:toggle . ruler-mode))) |
39731 | 571 |
572 (defconst ruler-mode-ruler-help-echo | |
573 "\ | |
574 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
|
575 mouse-2: set goal column, \ |
39731 | 576 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
|
577 "Help string shown when mouse is over the ruler. |
39731 | 578 `ruler-mode-show-tab-stops' is nil.") |
579 | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
580 (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
|
581 "\ |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
582 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
|
583 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
|
584 "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
|
585 `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
|
586 |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
587 (defconst ruler-mode-ruler-help-echo-when-tab-stops |
39731 | 588 "\ |
589 C-mouse1/3: set/unset tab, \ | |
590 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
|
591 "Help string shown when mouse is over the ruler. |
39731 | 592 `ruler-mode-show-tab-stops' is non-nil.") |
593 | |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
594 (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
|
595 "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
|
596 "Help string shown when mouse is on the fill column character.") |
39731 | 597 |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
598 (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
|
599 "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
|
600 "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
|
601 |
49195
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
602 (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
|
603 "\ |
c297d31ef382
(ruler-mode-comment-column-char, ruler-mode-goal-column-char)
Juanma Barranquero <lekktu@gmail.com>
parents:
47425
diff
changeset
|
604 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
|
605 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
|
606 "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
|
607 |
51389 | 608 (defconst ruler-mode-margin-help-echo |
609 "%s margin %S" | |
610 "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
|
611 |
51389 | 612 (defconst ruler-mode-fringe-help-echo |
613 "%s fringe %S" | |
614 "Help string shown when mouse is over a fringe area.") | |
89909 | 615 |
616 (defsubst ruler-mode-space (width &rest props) | |
617 "Return a single space string of WIDTH times the normal character width. | |
618 Optional argument PROPS specifies other text properties to apply." | |
619 (apply 'propertize " " 'display (list 'space :width width) props)) | |
41461 | 620 |
39731 | 621 (defun ruler-mode-ruler () |
89909 | 622 "Compute and return an header line ruler." |
623 (let* ((w (window-width)) | |
624 (m (window-margins)) | |
625 (f (window-fringes)) | |
626 (i 0) | |
627 (j (window-hscroll)) | |
628 ;; Setup the scrollbar, fringes, and margins areas. | |
629 (lf (ruler-mode-space | |
630 'left-fringe | |
631 'face 'ruler-mode-fringes-face | |
632 'help-echo (format ruler-mode-fringe-help-echo | |
633 "Left" (or (car f) 0)))) | |
634 (rf (ruler-mode-space | |
635 'right-fringe | |
636 'face 'ruler-mode-fringes-face | |
637 'help-echo (format ruler-mode-fringe-help-echo | |
638 "Right" (or (cadr f) 0)))) | |
639 (lm (ruler-mode-space | |
640 'left-margin | |
641 'face 'ruler-mode-margins-face | |
642 'help-echo (format ruler-mode-margin-help-echo | |
643 "Left" (or (car m) 0)))) | |
644 (rm (ruler-mode-space | |
645 'right-margin | |
646 'face 'ruler-mode-margins-face | |
647 'help-echo (format ruler-mode-margin-help-echo | |
648 "Right" (or (cdr m) 0)))) | |
649 (sb (ruler-mode-space | |
650 'scroll-bar | |
651 'face 'ruler-mode-pad-face)) | |
652 ;; Remember the scrollbar vertical type. | |
653 (sbvt (car (window-current-scroll-bars))) | |
654 ;; Create an "clean" ruler. | |
655 (ruler | |
656 (propertize | |
657 (make-string w ruler-mode-basic-graduation-char) | |
658 'face 'ruler-mode-default-face | |
659 'local-map ruler-mode-map | |
660 'help-echo (cond | |
661 (ruler-mode-show-tab-stops | |
662 ruler-mode-ruler-help-echo-when-tab-stops) | |
663 (goal-column | |
664 ruler-mode-ruler-help-echo-when-goal-column) | |
665 (ruler-mode-ruler-help-echo)))) | |
666 k c) | |
667 ;; Setup the active area. | |
668 (while (< i w) | |
669 ;; Graduations. | |
670 (cond | |
671 ;; Show a number graduation. | |
672 ((= (mod j 10) 0) | |
673 (setq c (number-to-string (/ j 10)) | |
674 m (length c) | |
675 k i) | |
676 (put-text-property | |
677 i (1+ i) 'face 'ruler-mode-column-number-face | |
678 ruler) | |
679 (while (and (> m 0) (>= k 0)) | |
680 (aset ruler k (aref c (setq m (1- m)))) | |
681 (setq k (1- k)))) | |
682 ;; Show an intermediate graduation. | |
683 ((= (mod j 5) 0) | |
684 (aset ruler i ruler-mode-inter-graduation-char))) | |
685 ;; Special columns. | |
686 (cond | |
687 ;; Show the `current-column' marker. | |
688 ((= j (current-column)) | |
689 (aset ruler i ruler-mode-current-column-char) | |
690 (put-text-property | |
691 i (1+ i) 'face 'ruler-mode-current-column-face | |
692 ruler)) | |
693 ;; Show the `goal-column' marker. | |
694 ((and goal-column (= j goal-column)) | |
695 (aset ruler i ruler-mode-goal-column-char) | |
696 (put-text-property | |
697 i (1+ i) 'face 'ruler-mode-goal-column-face | |
698 ruler) | |
699 (put-text-property | |
700 i (1+ i) 'help-echo ruler-mode-goal-column-help-echo | |
701 ruler)) | |
702 ;; Show the `comment-column' marker. | |
703 ((= j comment-column) | |
704 (aset ruler i ruler-mode-comment-column-char) | |
705 (put-text-property | |
706 i (1+ i) 'face 'ruler-mode-comment-column-face | |
707 ruler) | |
708 (put-text-property | |
709 i (1+ i) 'help-echo ruler-mode-comment-column-help-echo | |
710 ruler)) | |
711 ;; Show the `fill-column' marker. | |
712 ((= j fill-column) | |
713 (aset ruler i ruler-mode-fill-column-char) | |
714 (put-text-property | |
715 i (1+ i) 'face 'ruler-mode-fill-column-face | |
716 ruler) | |
717 (put-text-property | |
718 i (1+ i) 'help-echo ruler-mode-fill-column-help-echo | |
719 ruler)) | |
720 ;; Show the `tab-stop-list' markers. | |
721 ((and ruler-mode-show-tab-stops (member j tab-stop-list)) | |
722 (aset ruler i ruler-mode-tab-stop-char) | |
723 (put-text-property | |
724 i (1+ i) 'face 'ruler-mode-tab-stop-face | |
725 ruler))) | |
726 (setq i (1+ i) | |
727 j (1+ j))) | |
728 ;; Return the ruler propertized string. Using list here, | |
729 ;; instead of concat visually separate the different areas. | |
730 (if (nth 2 (window-fringes)) | |
731 ;; fringes outside margins. | |
732 (list "" (and (eq 'left sbvt) sb) lf lm | |
733 ruler rm rf (and (eq 'right sbvt) sb)) | |
734 ;; fringes inside margins. | |
735 (list "" (and (eq 'left sbvt) sb) lm lf | |
736 ruler rf rm (and (eq 'right sbvt) sb))))) | |
39731 | 737 |
738 (provide 'ruler-mode) | |
739 | |
740 ;; Local Variables: | |
741 ;; coding: iso-latin-1 | |
742 ;; End: | |
743 | |
89909 | 744 ;;; arch-tag: b2f24546-5605-44c4-b67b-c9a4eeba3ee8 |
39731 | 745 ;;; ruler-mode.el ends here |