1 ;;; ruler-mode.el --- display a ruler in the header line
3 ;; Copyright (C) 2001-2017 Free Software Foundation, Inc.
5 ;; Author: David Ponce <david@dponce.com>
6 ;; Maintainer: David Ponce <david@dponce.com>
7 ;; Created: 24 Mar 2001
9 ;; Keywords: convenience
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
28 ;; This library provides a minor mode to display a ruler in the header
29 ;; line. It works from Emacs 21 onwards.
31 ;; You can use the mouse to change the `fill-column' `comment-column',
32 ;; `goal-column', `window-margins' and `tab-stop-list' settings:
34 ;; [header-line (shift down-mouse-1)] set left margin end to the ruler
35 ;; graduation where the mouse pointer is on.
37 ;; [header-line (shift down-mouse-3)] set right margin beginning to
38 ;; the ruler graduation where the mouse pointer is on.
40 ;; [header-line down-mouse-2] Drag the `fill-column', `comment-column'
41 ;; or `goal-column' to a ruler graduation.
43 ;; [header-line (control down-mouse-1)] add a tab stop to the ruler
44 ;; graduation where the mouse pointer is on.
46 ;; [header-line (control down-mouse-3)] remove the tab stop at the
47 ;; ruler graduation where the mouse pointer is on.
49 ;; [header-line (control down-mouse-2)] or M-x
50 ;; `ruler-mode-toggle-show-tab-stops' toggle showing and visually
51 ;; editing `tab-stop-list' setting. The `ruler-mode-show-tab-stops'
52 ;; option controls if the ruler shows tab stops by default.
54 ;; In the ruler the character `ruler-mode-current-column-char' shows
55 ;; the `current-column' location, `ruler-mode-fill-column-char' shows
56 ;; the `fill-column' location, `ruler-mode-comment-column-char' shows
57 ;; the `comment-column' location, `ruler-mode-goal-column-char' shows
58 ;; the `goal-column' and `ruler-mode-tab-stop-char' shows tab stop
59 ;; locations. Graduations in `window-margins' and `window-fringes'
60 ;; areas are shown with a different foreground color.
62 ;; It is also possible to customize the following characters:
64 ;; - `ruler-mode-basic-graduation-char' character used for basic
65 ;; graduations ('.' by default).
66 ;; - `ruler-mode-inter-graduation-char' character used for
67 ;; intermediate graduations ('!' by default).
69 ;; The following faces are customizable:
71 ;; - `ruler-mode-default' the ruler default face.
72 ;; - `ruler-mode-fill-column' the face used to highlight the
73 ;; `fill-column' character.
74 ;; - `ruler-mode-comment-column' the face used to highlight the
75 ;; `comment-column' character.
76 ;; - `ruler-mode-goal-column' the face used to highlight the
77 ;; `goal-column' character.
78 ;; - `ruler-mode-current-column' the face used to highlight the
79 ;; `current-column' character.
80 ;; - `ruler-mode-tab-stop' the face used to highlight tab stop
82 ;; - `ruler-mode-margins' the face used to highlight graduations
83 ;; in the `window-margins' areas.
84 ;; - `ruler-mode-fringes' the face used to highlight graduations
85 ;; in the `window-fringes' areas.
86 ;; - `ruler-mode-column-number' the face used to highlight the
87 ;; numbered graduations.
89 ;; `ruler-mode-default' inherits from the built-in `default' face.
90 ;; All `ruler-mode' faces inherit from `ruler-mode-default'.
92 ;; WARNING: To keep ruler graduations aligned on text columns it is
93 ;; important to use the same font family and size for ruler and text
96 ;; You can override the ruler format by defining an appropriate
97 ;; function as the buffer-local value of `ruler-mode-ruler-function'.
101 ;; To automatically display the ruler in specific major modes use:
103 ;; (add-hook '<major-mode>-hook 'ruler-mode)
112 (require 'scroll-bar
)
115 (defgroup ruler-mode nil
116 "Display a ruler in the header line."
120 (defcustom ruler-mode-show-tab-stops nil
121 "If non-nil the ruler shows tab stop positions.
122 Also allowing to visually change `tab-stop-list' setting using
123 <C-down-mouse-1> and <C-down-mouse-3> on the ruler to respectively add
124 or remove a tab stop. \\[ruler-mode-toggle-show-tab-stops] or
125 <C-down-mouse-2> on the ruler toggles showing/editing of tab stops."
129 ;; IMPORTANT: This function must be defined before the following
130 ;; defcustoms because it is used in their :validate clause.
131 (defun ruler-mode-character-validate (widget)
132 "Ensure WIDGET value is a valid character value."
134 (let ((value (widget-value widget
)))
135 (unless (characterp value
)
136 (widget-put widget
:error
137 (format "Invalid character value: %S" value
))
140 (defcustom ruler-mode-fill-column-char
(if (char-displayable-p ?¶
)
143 "Character used at the `fill-column' location."
146 (character :tag
"Character")
147 (integer :tag
"Integer char value"
148 :validate ruler-mode-character-validate
)))
150 (defcustom ruler-mode-comment-column-char ?\
#
151 "Character used at the `comment-column' location."
154 (character :tag
"Character")
155 (integer :tag
"Integer char value"
156 :validate ruler-mode-character-validate
)))
158 (defcustom ruler-mode-goal-column-char ?G
159 "Character used at the `goal-column' location."
162 (character :tag
"Character")
163 (integer :tag
"Integer char value"
164 :validate ruler-mode-character-validate
)))
166 (defcustom ruler-mode-current-column-char
(if (char-displayable-p ?¦
)
169 "Character used at the `current-column' location."
172 (character :tag
"Character")
173 (integer :tag
"Integer char value"
174 :validate ruler-mode-character-validate
)))
176 (defcustom ruler-mode-tab-stop-char ?\T
177 "Character used at `tab-stop-list' locations."
180 (character :tag
"Character")
181 (integer :tag
"Integer char value"
182 :validate ruler-mode-character-validate
)))
184 (defcustom ruler-mode-basic-graduation-char ?\.
185 "Character used for basic graduations."
188 (character :tag
"Character")
189 (integer :tag
"Integer char value"
190 :validate ruler-mode-character-validate
)))
192 (defcustom ruler-mode-inter-graduation-char ?\
!
193 "Character used for intermediate graduations."
196 (character :tag
"Character")
197 (integer :tag
"Integer char value"
198 :validate ruler-mode-character-validate
)))
200 (defcustom ruler-mode-set-goal-column-ding-flag t
201 "Non-nil means do `ding' when `goal-column' is set."
205 (defface ruler-mode-default
215 :box
(:color
"grey76"
217 :style released-button
)
219 "Default face used by the ruler."
222 (defface ruler-mode-pad
224 (:inherit ruler-mode-default
228 (:inherit ruler-mode-default
231 "Face used to pad inactive ruler areas."
234 (defface ruler-mode-margins
236 (:inherit ruler-mode-default
239 "Face used to highlight margin areas."
242 (defface ruler-mode-fringes
244 (:inherit ruler-mode-default
247 "Face used to highlight fringes areas."
250 (defface ruler-mode-column-number
252 (:inherit ruler-mode-default
255 "Face used to highlight number graduations."
258 (defface ruler-mode-fill-column
260 (:inherit ruler-mode-default
263 "Face used to highlight the fill column character."
266 (defface ruler-mode-comment-column
268 (:inherit ruler-mode-default
271 "Face used to highlight the comment column character."
274 (defface ruler-mode-goal-column
276 (:inherit ruler-mode-default
279 "Face used to highlight the goal column character."
282 (defface ruler-mode-tab-stop
284 (:inherit ruler-mode-default
285 :foreground
"steelblue"
287 "Face used to highlight tab stop characters."
290 (defface ruler-mode-current-column
292 (:inherit ruler-mode-default
296 "Face used to highlight the `current-column' character."
300 (defsubst ruler-mode-full-window-width
()
301 "Return the full width of the selected window."
302 (let ((edges (window-edges)))
303 (- (nth 2 edges
) (nth 0 edges
))))
305 (defsubst ruler-mode-window-col
(n)
306 "Return a column number relative to the selected window.
307 N is a column number relative to selected frame.
308 If required, account for screen estate taken by `display-line-numbers'."
309 (if display-line-numbers
310 (setq n
(- n
(line-number-display-width) 2)))
312 (or (car (window-margins)) 0)
313 (fringe-columns 'left
)
314 (scroll-bar-columns 'left
)))
316 (defun ruler-mode-mouse-set-left-margin (start-event)
317 "Set left margin end to the graduation where the mouse pointer is on.
318 START-EVENT is the mouse click event."
320 (let* ((start (event-start start-event
))
321 (end (event-end start-event
))
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
))
327 (scroll-bar-columns 'left
))
328 w
(- (ruler-mode-full-window-width)
329 (scroll-bar-columns 'left
)
330 (scroll-bar-columns 'right
)))
331 (when (and (>= col
0) (< col w
))
332 (setq lm
(window-margins)
335 (message "Left margin set to %d (was %d)" col lm
)
336 (set-window-margins nil col rm
))))))
338 (defun ruler-mode-mouse-set-right-margin (start-event)
339 "Set right margin beginning to the graduation where the mouse pointer is on.
340 START-EVENT is the mouse click event."
342 (let* ((start (event-start start-event
))
343 (end (event-end start-event
))
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
))
349 (scroll-bar-columns 'left
))
350 w
(- (ruler-mode-full-window-width)
351 (scroll-bar-columns 'left
)
352 (scroll-bar-columns 'right
)))
353 (when (and (>= col
0) (< col w
))
354 (setq lm
(window-margins)
358 (message "Right margin set to %d (was %d)" col rm
)
359 (set-window-margins nil lm col
))))))
361 (defvar ruler-mode-dragged-symbol nil
362 "Column symbol dragged in the ruler.
363 That is `fill-column', `comment-column', `goal-column', or nil when
364 nothing is dragged.")
366 (defun ruler-mode-text-scaled-width (width)
367 "Compute scaled text width according to current font scaling.
368 Convert a width of char units into a text-scaled char width units,
369 Ex. `window-hscroll'."
370 (/ (* width
(frame-char-width)) (default-font-width)))
372 (defun ruler-mode-text-scaled-window-hscroll ()
373 "Text scaled `window-hscroll'."
374 (ruler-mode-text-scaled-width (window-hscroll)))
376 (defun ruler-mode-text-scaled-window-width ()
377 "Text scaled `window-width'."
378 (ruler-mode-text-scaled-width (window-width)))
380 (defun ruler-mode-mouse-grab-any-column (start-event)
381 "Drag a column symbol on the ruler.
382 Start dragging on mouse down event START-EVENT, and update the column
383 symbol value with the current value of the ruler graduation while
384 dragging. See also the variable `ruler-mode-dragged-symbol'."
386 (setq ruler-mode-dragged-symbol nil
)
387 (let* ((start (event-start start-event
))
389 (save-selected-window
390 (select-window (posn-window start
))
391 (setq col
(ruler-mode-window-col (car (posn-col-row start
)))
392 newc
(+ col
(ruler-mode-text-scaled-window-hscroll)))
394 (>= col
0) (< col
(ruler-mode-text-scaled-window-width))
397 ;; Handle the fill column.
398 ((eq newc fill-column
)
399 (setq oldc fill-column
400 ruler-mode-dragged-symbol
'fill-column
)
403 ;; Handle the comment column.
404 ((eq newc comment-column
)
405 (setq oldc comment-column
406 ruler-mode-dragged-symbol
'comment-column
)
409 ;; Handle the goal column.
410 ;; A. On mouse down on the goal column character on the ruler,
411 ;; update the `goal-column' value while dragging.
412 ;; B. If `goal-column' is nil, set the goal column where the
414 ;; C. On mouse click on the goal column character on the
415 ;; ruler, unset the goal column.
416 ((eq newc goal-column
) ; A. Drag the goal column.
417 (setq oldc goal-column
418 ruler-mode-dragged-symbol
'goal-column
)
421 ((null goal-column
) ; B. Set the goal column.
422 (setq oldc goal-column
424 ;; mouse-2 coming AFTER drag-mouse-2 invokes `ding'. This
425 ;; `ding' flushes the next messages about setting goal
426 ;; column. So here I force fetch the event(mouse-2) and
429 ;; Ding BEFORE `message' is OK.
430 (when ruler-mode-set-goal-column-ding-flag
432 (message "Goal column set to %d (click on %s again to unset it)"
434 (propertize (char-to-string ruler-mode-goal-column-char
)
435 'face
'ruler-mode-goal-column
))
436 nil
) ;; Don't start dragging.
438 (if (eq 'click
(ruler-mode-mouse-drag-any-column-iteration
439 (posn-window start
)))
440 (when (eq 'goal-column ruler-mode-dragged-symbol
)
441 ;; C. Unset the goal column.
443 ;; At end of dragging, report the updated column symbol.
444 (message "%s is set to %d (was %d)"
445 ruler-mode-dragged-symbol
446 (symbol-value ruler-mode-dragged-symbol
)
449 (defun ruler-mode-mouse-drag-any-column-iteration (window)
450 "Update the ruler while dragging the mouse.
451 WINDOW is the window where occurred the last down-mouse event.
452 Return the symbol `drag' if the mouse has been dragged, or `click' if
453 the mouse has been clicked."
457 ;; Signal the display engine to freeze the mouse pointer shape.
458 (setq track-mouse
'dragging
)
459 (while (mouse-movement-p (setq event
(read-event)))
460 (setq drags
(1+ drags
))
461 (when (eq window
(posn-window (event-end event
)))
462 (ruler-mode-mouse-drag-any-column event
)
463 (force-mode-line-update))))
464 (if (and (zerop drags
) (eq 'click
(car (event-modifiers event
))))
468 (defun ruler-mode-mouse-drag-any-column (start-event)
469 "Update the value of the symbol dragged on the ruler.
470 Called on each mouse motion event START-EVENT."
471 (let* ((start (event-start start-event
))
472 (end (event-end start-event
))
474 (save-selected-window
475 (select-window (posn-window start
))
476 (setq col
(ruler-mode-window-col (car (posn-col-row end
)))
477 newc
(+ col
(ruler-mode-text-scaled-window-hscroll)))
478 (when (and (>= col
0) (< col
(ruler-mode-text-scaled-window-width)))
479 (set ruler-mode-dragged-symbol newc
)))))
481 (defun ruler-mode-mouse-add-tab-stop (start-event)
482 "Add a tab stop to the graduation where the mouse pointer is on.
483 START-EVENT is the mouse click event."
485 (when ruler-mode-show-tab-stops
486 (let* ((start (event-start start-event
))
487 (end (event-end start-event
))
489 (when (eq start end
) ;; mouse click
490 (save-selected-window
491 (select-window (posn-window start
))
492 (setq col
(ruler-mode-window-col (car (posn-col-row start
)))
493 ts
(+ col
(ruler-mode-text-scaled-window-hscroll)))
494 (and (>= col
0) (< col
(ruler-mode-text-scaled-window-width))
495 (not (member ts tab-stop-list
))
497 (message "Tab stop set to %d" ts
)
498 (when (null tab-stop-list
)
499 (setq tab-stop-list
(indent-accumulate-tab-stops (1- ts
))))
500 (setq tab-stop-list
(sort (cons ts tab-stop-list
) #'<)))))))))
502 (defun ruler-mode-mouse-del-tab-stop (start-event)
503 "Delete tab stop at the graduation where the mouse pointer is on.
504 START-EVENT is the mouse click event."
506 (when ruler-mode-show-tab-stops
507 (let* ((start (event-start start-event
))
508 (end (event-end start-event
))
510 (when (eq start end
) ;; mouse click
511 (save-selected-window
512 (select-window (posn-window start
))
513 (setq col
(ruler-mode-window-col (car (posn-col-row start
)))
514 ts
(+ col
(ruler-mode-text-scaled-window-hscroll)))
515 (and (>= col
0) (< col
(ruler-mode-text-scaled-window-width))
516 (member ts tab-stop-list
)
518 (message "Tab stop at %d deleted" ts
)
519 (setq tab-stop-list
(delete ts tab-stop-list
)))))))))
521 (defun ruler-mode-toggle-show-tab-stops ()
522 "Toggle showing of tab stops on the ruler."
524 (setq ruler-mode-show-tab-stops
(not ruler-mode-show-tab-stops
))
525 (force-mode-line-update))
527 (defvar ruler-mode-map
528 (let ((km (make-sparse-keymap)))
529 (define-key km
[header-line down-mouse-1
]
531 (define-key km
[header-line down-mouse-3
]
533 (define-key km
[header-line down-mouse-2
]
534 #'ruler-mode-mouse-grab-any-column
)
535 (define-key km
[header-line
(shift down-mouse-1
)]
536 #'ruler-mode-mouse-set-left-margin
)
537 (define-key km
[header-line
(shift down-mouse-3
)]
538 #'ruler-mode-mouse-set-right-margin
)
539 (define-key km
[header-line
(control down-mouse-1
)]
540 #'ruler-mode-mouse-add-tab-stop
)
541 (define-key km
[header-line
(control down-mouse-3
)]
542 #'ruler-mode-mouse-del-tab-stop
)
543 (define-key km
[header-line
(control down-mouse-2
)]
544 #'ruler-mode-toggle-show-tab-stops
)
545 (define-key km
[header-line
(shift mouse-1
)]
547 (define-key km
[header-line
(shift mouse-3
)]
549 (define-key km
[header-line
(control mouse-1
)]
551 (define-key km
[header-line
(control mouse-3
)]
553 (define-key km
[header-line
(control mouse-2
)]
556 "Keymap for ruler minor mode.")
558 (defvar ruler-mode-header-line-format-old nil
559 "Hold previous value of `header-line-format'.")
561 (defvar ruler-mode-ruler-function
'ruler-mode-ruler
562 "Function to call to return ruler header line format.
563 This variable is expected to be made buffer-local by modes.")
565 (defconst ruler-mode-header-line-format
566 '(:eval
(funcall ruler-mode-ruler-function
))
567 "`header-line-format' used in ruler mode.
568 Call `ruler-mode-ruler-function' to compute the ruler value.")
571 (defvar ruler-mode nil
572 "Non-nil if Ruler mode is enabled.
573 Use the command `ruler-mode' to change this variable.")
574 (make-variable-buffer-local 'ruler-mode
)
576 (defun ruler--save-header-line-format ()
577 "Install the header line format for Ruler mode.
578 Unless Ruler mode is already enabled, save the old header line
580 (when (and (not ruler-mode
)
581 (local-variable-p 'header-line-format
)
582 (not (local-variable-p 'ruler-mode-header-line-format-old
)))
583 (set (make-local-variable 'ruler-mode-header-line-format-old
)
585 (setq header-line-format ruler-mode-header-line-format
))
588 (define-minor-mode ruler-mode
589 "Toggle display of ruler in header line (Ruler mode).
590 With a prefix argument ARG, enable Ruler mode if ARG is positive,
591 and disable it otherwise. If called from Lisp, enable the mode
592 if ARG is omitted or nil."
596 :variable
(ruler-mode
599 (ruler--save-header-line-format))
600 (setq ruler-mode enable
)))
602 (add-hook 'post-command-hook
'force-mode-line-update nil t
)
603 ;; When `ruler-mode' is off restore previous header line format if
604 ;; the current one is the ruler header line format.
605 (when (eq header-line-format ruler-mode-header-line-format
)
606 (kill-local-variable 'header-line-format
)
607 (when (local-variable-p 'ruler-mode-header-line-format-old
)
608 (setq header-line-format ruler-mode-header-line-format-old
)
609 (kill-local-variable 'ruler-mode-header-line-format-old
)))
610 (remove-hook 'post-command-hook
'force-mode-line-update t
)))
612 ;; Add ruler-mode to the minor mode menu in the mode line
613 (define-key mode-line-mode-menu
[ruler-mode
]
614 `(menu-item "Ruler" ruler-mode
615 :button
(:toggle . ruler-mode
)))
617 (defconst ruler-mode-ruler-help-echo
619 S-mouse-1/3: set L/R margin, \
620 mouse-2: set goal column, \
621 C-mouse-2: show tabs"
622 "Help string shown when mouse is over the ruler.
623 `ruler-mode-show-tab-stops' is nil.")
625 (defconst ruler-mode-ruler-help-echo-when-goal-column
627 S-mouse-1/3: set L/R margin, \
628 C-mouse-2: show tabs"
629 "Help string shown when mouse is over the ruler.
630 `goal-column' is set and `ruler-mode-show-tab-stops' is nil.")
632 (defconst ruler-mode-ruler-help-echo-when-tab-stops
634 C-mouse1/3: set/unset tab, \
635 C-mouse-2: hide tabs"
636 "Help string shown when mouse is over the ruler.
637 `ruler-mode-show-tab-stops' is non-nil.")
639 (defconst ruler-mode-fill-column-help-echo
640 "drag-mouse-2: set fill column"
641 "Help string shown when mouse is on the fill column character.")
643 (defconst ruler-mode-comment-column-help-echo
644 "drag-mouse-2: set comment column"
645 "Help string shown when mouse is on the comment column character.")
647 (defconst ruler-mode-goal-column-help-echo
649 drag-mouse-2: set goal column, \
650 mouse-2: unset goal column"
651 "Help string shown when mouse is on the goal column character.")
653 (defconst ruler-mode-margin-help-echo
655 "Help string shown when mouse is over a margin area.")
657 (defconst ruler-mode-fringe-help-echo
659 "Help string shown when mouse is over a fringe area.")
661 (defsubst ruler-mode-space
(width &rest props
)
662 "Return a single space string of WIDTH times the normal character width.
663 Optional argument PROPS specifies other text properties to apply."
664 (apply 'propertize
" " 'display
(list 'space
:width width
) props
))
666 (defun ruler-mode-ruler ()
667 "Compute and return a header line ruler."
668 (let* ((w (ruler-mode-text-scaled-window-width))
671 (i (if display-line-numbers
(+ (line-number-display-width) 2) 0))
672 (j (ruler-mode-text-scaled-window-hscroll))
673 ;; Setup the scrollbar, fringes, and margins areas.
674 (lf (ruler-mode-space
676 'face
'ruler-mode-fringes
677 'help-echo
(format ruler-mode-fringe-help-echo
678 "Left" (or (car f
) 0))))
679 (rf (ruler-mode-space
681 'face
'ruler-mode-fringes
682 'help-echo
(format ruler-mode-fringe-help-echo
683 "Right" (or (cadr f
) 0))))
684 (lm (ruler-mode-space
686 'face
'ruler-mode-margins
687 'help-echo
(format ruler-mode-margin-help-echo
688 "Left" (or (car m
) 0))))
689 (rm (ruler-mode-space
691 'face
'ruler-mode-margins
692 'help-echo
(format ruler-mode-margin-help-echo
693 "Right" (or (cdr m
) 0))))
694 (sb (ruler-mode-space
696 'face
'ruler-mode-pad
))
697 ;; Remember the scrollbar vertical type.
698 (sbvt (car (window-current-scroll-bars)))
699 ;; Create an "clean" ruler.
702 ;; FIXME: `make-string' returns a unibyte string if it's ASCII-only,
703 ;; which prevents further `aset' from inserting non-ASCII chars,
704 ;; hence the need for `string-to-multibyte'.
705 ;; https://lists.gnu.org/archive/html/emacs-devel/2017-05/msg00841.html
707 ;; Make the part of header-line corresponding to the
708 ;; line-number display be blank, not filled with
709 ;; ruler-mode-basic-graduation-char.
710 (if display-line-numbers
711 (let* ((lndw (+ (line-number-display-width) 2))
712 (s (make-string lndw ?\s
)))
713 (concat s
(make-string (- w lndw
)
714 ruler-mode-basic-graduation-char
)))
715 (make-string w ruler-mode-basic-graduation-char
)))
716 'face
'ruler-mode-default
717 'local-map ruler-mode-map
719 (ruler-mode-show-tab-stops
720 ruler-mode-ruler-help-echo-when-tab-stops
)
722 ruler-mode-ruler-help-echo-when-goal-column
)
723 (ruler-mode-ruler-help-echo))))
725 ;; Setup the active area.
729 ;; Show a number graduation.
731 (setq c
(number-to-string (/ j
10))
735 i
(1+ i
) 'face
'ruler-mode-column-number
737 (while (and (> m
0) (>= k
0))
738 (aset ruler k
(aref c
(setq m
(1- m
))))
740 ;; Show an intermediate graduation.
742 (aset ruler i ruler-mode-inter-graduation-char
)))
745 ;; Show the `current-column' marker.
746 ((= j
(current-column))
747 (aset ruler i ruler-mode-current-column-char
)
749 i
(1+ i
) 'face
'ruler-mode-current-column
751 ;; Show the `goal-column' marker.
752 ((and goal-column
(= j goal-column
))
753 (aset ruler i ruler-mode-goal-column-char
)
755 i
(1+ i
) 'face
'ruler-mode-goal-column
758 i
(1+ i
) 'mouse-face
'mode-line-highlight
761 i
(1+ i
) 'help-echo ruler-mode-goal-column-help-echo
763 ;; Show the `comment-column' marker.
764 ((= j comment-column
)
765 (aset ruler i ruler-mode-comment-column-char
)
767 i
(1+ i
) 'face
'ruler-mode-comment-column
770 i
(1+ i
) 'mouse-face
'mode-line-highlight
773 i
(1+ i
) 'help-echo ruler-mode-comment-column-help-echo
775 ;; Show the `fill-column' marker.
777 (aset ruler i ruler-mode-fill-column-char
)
779 i
(1+ i
) 'face
'ruler-mode-fill-column
782 i
(1+ i
) 'mouse-face
'mode-line-highlight
785 i
(1+ i
) 'help-echo ruler-mode-fill-column-help-echo
787 ;; Show the `tab-stop-list' markers.
788 ((and ruler-mode-show-tab-stops
(= j
(indent-next-tab-stop (1- j
))))
789 (aset ruler i ruler-mode-tab-stop-char
)
791 i
(1+ i
) 'face
'ruler-mode-tab-stop
795 ;; Return the ruler propertized string. Using list here,
796 ;; instead of concat visually separate the different areas.
797 (if (nth 2 (window-fringes))
798 ;; fringes outside margins.
799 (list "" (and (eq 'left sbvt
) sb
) lf lm
800 ruler rm rf
(and (eq 'right sbvt
) sb
))
801 ;; fringes inside margins.
802 (list "" (and (eq 'left sbvt
) sb
) lm lf
803 ruler rf rm
(and (eq 'right sbvt
) sb
)))))
805 (provide 'ruler-mode
)
807 ;;; ruler-mode.el ends here