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