Mercurial > emacs
annotate lisp/hl-line.el @ 88265:defd9948075b
(rmail-highlight-face): Doc.
(rmail-font-lock-keywords): Add the stuff necessary to make
rmail-highlight-headers obsolete.
(rmail-toggle-header, rmail-show-message): Don't call
rmail-highlight-headers anymore.
(rmail-highlight-headers): Deleted.
author | Alex Schroeder <alex@gnu.org> |
---|---|
date | Sat, 21 Jan 2006 18:21:07 +0000 |
parents | d7ddb3e565de |
children |
rev | line source |
---|---|
24961 | 1 ;;; hl-line.el --- highlight the current line |
2 | |
88155 | 3 ;; Copyright (C) 1998, 2000, 2001, 2002, 2003, 2004, |
4 ;; 2005 Free Software Foundation, Inc. | |
24961 | 5 |
6 ;; Author: Dave Love <fx@gnu.org> | |
88155 | 7 ;; Maintainer: FSF |
24961 | 8 ;; Created: 1998-09-13 |
29369
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
9 ;; Keywords: faces, frames, emulation |
24961 | 10 |
29087 | 11 ;; This file is part of GNU Emacs. |
12 | |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
24961 | 14 ;; it under the terms of the GNU General Public License as published by |
15 ;; the Free Software Foundation; either version 2, or (at your option) | |
16 ;; any later version. | |
17 | |
29087 | 18 ;; GNU Emacs is distributed in the hope that it will be useful, |
24961 | 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. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
88155 | 25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 ;; Boston, MA 02110-1301, USA. | |
24961 | 27 |
28 ;;; Commentary: | |
29 | |
88155 | 30 ;; Provides a local minor mode (toggled by M-x hl-line-mode) and |
31 ;; a global minor mode (toggled by M-x global-hl-line-mode) to | |
32 ;; highlight, on a suitable terminal, the line on which point is. The | |
33 ;; global mode highlights the current line in the selected window only | |
34 ;; (except when the minibuffer window is selected). This was | |
35 ;; implemented to satisfy a request for a feature of Lesser Editors. | |
36 ;; The local mode is sticky: it highlights the line about the buffer's | |
37 ;; point even if the buffer's window is not selected. Caveat: the | |
38 ;; buffer's point might be different from the point of a non-selected | |
39 ;; window. Set the variable `hl-line-sticky-flag' to nil to make the | |
40 ;; local mode behave like the global mode. | |
24961 | 41 |
88155 | 42 ;; You probably don't really want to use the global mode; if the |
43 ;; cursor is difficult to spot, try changing its colour, relying on | |
44 ;; `blink-cursor-mode' or both. The hookery used might affect | |
45 ;; response noticeably on a slow machine. The local mode may be | |
46 ;; useful in non-editing buffers such as Gnus or PCL-CVS though. | |
24961 | 47 |
88155 | 48 ;; An overlay is used. In the non-sticky cases, this overlay is |
49 ;; active only on the selected window. A hook is added to | |
50 ;; `post-command-hook' to activate the overlay and move it to the line | |
51 ;; about point. To get the non-sticky behavior, `hl-line-unhighlight' | |
52 ;; is added to `pre-command-hook' as well. This function deactivates | |
53 ;; the overlay unconditionally in case the command changes the | |
54 ;; selected window. (It does so rather than keeping track of changes | |
55 ;; in the selected window). | |
56 | |
57 ;; You could make variable `global-hl-line-mode' buffer-local and set | |
58 ;; it to nil to avoid highlighting specific buffers, when the global | |
59 ;; mode is used. | |
60 | |
61 ;; In default whole the line is highlighted. The range of highlighting | |
62 ;; can be changed by defining an appropriate function as the | |
63 ;; buffer-local value of `hl-line-range-function'. | |
30274
428e9eb82841
(hl-line-highlight): Check hl-line-mode.
Dave Love <fx@gnu.org>
parents:
30034
diff
changeset
|
64 |
24961 | 65 ;;; Code: |
66 | |
67 (defgroup hl-line nil | |
35031 | 68 "Highlight the current line." |
25174 | 69 :version "21.1" |
24961 | 70 :group 'editing) |
71 | |
72 (defcustom hl-line-face 'highlight | |
73 "Face with which to highlight the current line." | |
74 :type 'face | |
75 :group 'hl-line) | |
76 | |
88155 | 77 (defcustom hl-line-sticky-flag t |
78 "*Non-nil means highlight the current line in all windows. | |
79 Otherwise Hl-Line mode will highlight only in the selected | |
80 window. Setting this variable takes effect the next time you use | |
81 the command `hl-line-mode' to turn Hl-Line mode on." | |
82 :type 'boolean | |
83 :version "22.1" | |
84 :group 'hl-line) | |
85 | |
86 (defvar hl-line-range-function nil | |
87 "If non-nil, function to call to return highlight range. | |
88 The function of no args should return a cons cell; its car value | |
89 is the beginning position of highlight and its cdr value is the | |
90 end position of highlight in the buffer. | |
91 It should return nil if there's no region to be highlighted. | |
92 | |
93 This variable is expected to be made buffer-local by modes.") | |
94 | |
95 (defvar hl-line-overlay nil | |
96 "Overlay used by Hl-Line mode to highlight the current line.") | |
97 (make-variable-buffer-local 'hl-line-overlay) | |
98 | |
99 (defvar global-hl-line-overlay nil | |
100 "Overlay used by Global-Hl-Line mode to highlight the current line.") | |
24961 | 101 |
25051
64e3159f0c7b
(hl-line-mode): Add autload cookies.
Dave Love <fx@gnu.org>
parents:
24961
diff
changeset
|
102 ;;;###autoload |
29369
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
103 (define-minor-mode hl-line-mode |
88155 | 104 "Buffer-local minor mode to highlight the line about point. |
24961 | 105 With ARG, turn Hl-Line mode on if ARG is positive, off otherwise. |
88155 | 106 |
107 If `hl-line-sticky-flag' is non-nil, Hl-Line mode highlights the | |
108 line about the buffer's point in all windows. Caveat: the | |
109 buffer's point might be different from the point of a | |
110 non-selected window. Hl-Line mode uses the function | |
111 `hl-line-highlight' on `post-command-hook' in this case. | |
112 | |
113 When `hl-line-sticky-flag' is nil, Hl-Line mode highlights the | |
114 line about point in the selected window only. In this case, it | |
115 uses the function `hl-line-unhighlight' on `pre-command-hook' in | |
116 addition to `hl-line-highlight' on `post-command-hook'." | |
117 :group 'hl-line | |
29369
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
118 (if hl-line-mode |
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
119 (progn |
88155 | 120 ;; In case `kill-all-local-variables' is called. |
121 (add-hook 'change-major-mode-hook #'hl-line-unhighlight nil t) | |
122 (if hl-line-sticky-flag | |
123 (remove-hook 'pre-command-hook #'hl-line-unhighlight t) | |
124 (add-hook 'pre-command-hook #'hl-line-unhighlight nil t)) | |
125 (hl-line-highlight) | |
126 (add-hook 'post-command-hook #'hl-line-highlight nil t)) | |
127 (remove-hook 'post-command-hook #'hl-line-highlight t) | |
29369
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
128 (hl-line-unhighlight) |
88155 | 129 (remove-hook 'change-major-mode-hook #'hl-line-unhighlight t) |
130 (remove-hook 'pre-command-hook #'hl-line-unhighlight t))) | |
38937
ff93d7955c3d
(hl-line-mode): Don't be a global mode.
Gerd Moellmann <gerd@gnu.org>
parents:
35031
diff
changeset
|
131 |
43031
46823e7a2cae
(hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents:
42842
diff
changeset
|
132 (defun hl-line-highlight () |
88155 | 133 "Active the Hl-Line overlay on the current line." |
134 (if hl-line-mode ; Might be changed outside the mode function. | |
135 (progn | |
136 (unless hl-line-overlay | |
137 (setq hl-line-overlay (make-overlay 1 1)) ; to be moved | |
138 (overlay-put hl-line-overlay 'face hl-line-face)) | |
139 (overlay-put hl-line-overlay | |
140 'window (unless hl-line-sticky-flag (selected-window))) | |
141 (hl-line-move hl-line-overlay)) | |
142 (hl-line-unhighlight))) | |
43031
46823e7a2cae
(hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents:
42842
diff
changeset
|
143 |
46823e7a2cae
(hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents:
42842
diff
changeset
|
144 (defun hl-line-unhighlight () |
88155 | 145 "Deactivate the Hl-Line overlay on the current line." |
43031
46823e7a2cae
(hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents:
42842
diff
changeset
|
146 (if hl-line-overlay |
46823e7a2cae
(hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents:
42842
diff
changeset
|
147 (delete-overlay hl-line-overlay))) |
46823e7a2cae
(hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents:
42842
diff
changeset
|
148 |
88155 | 149 ;;;###autoload |
150 (define-minor-mode global-hl-line-mode | |
151 "Global minor mode to highlight the line about point in the current window. | |
152 With ARG, turn Global-Hl-Line mode on if ARG is positive, off otherwise. | |
153 | |
154 Global-Hl-Line mode uses the functions `global-hl-line-unhighlight' and | |
155 `global-hl-line-highlight' on `pre-command-hook' and `post-command-hook'." | |
156 :global t | |
157 :group 'hl-line | |
158 (if global-hl-line-mode | |
159 (progn | |
160 (add-hook 'pre-command-hook #'global-hl-line-unhighlight) | |
161 (add-hook 'post-command-hook #'global-hl-line-highlight)) | |
162 (global-hl-line-unhighlight) | |
163 (remove-hook 'pre-command-hook #'global-hl-line-unhighlight) | |
164 (remove-hook 'post-command-hook #'global-hl-line-highlight))) | |
165 | |
166 (defun global-hl-line-highlight () | |
167 "Active the Global-Hl-Line overlay on the current line in the current window." | |
168 (when global-hl-line-mode ; Might be changed outside the mode function. | |
169 (unless (window-minibuffer-p (selected-window)) | |
170 (unless global-hl-line-overlay | |
171 (setq global-hl-line-overlay (make-overlay 1 1)) ; to be moved | |
172 (overlay-put global-hl-line-overlay 'face hl-line-face)) | |
173 (overlay-put global-hl-line-overlay 'window (selected-window)) | |
174 (hl-line-move global-hl-line-overlay)))) | |
175 | |
176 (defun global-hl-line-unhighlight () | |
177 "Deactivate the Global-Hl-Line overlay on the current line." | |
178 (if global-hl-line-overlay | |
179 (delete-overlay global-hl-line-overlay))) | |
180 | |
181 (defun hl-line-move (overlay) | |
182 "Move the hl-line-mode overlay. | |
183 If `hl-line-range-function' is non-nil, move the OVERLAY to the position | |
184 where the function returns. If `hl-line-range-function' is nil, fill | |
185 the line including the point by OVERLAY." | |
186 (let (tmp b e) | |
187 (if hl-line-range-function | |
188 (setq tmp (funcall hl-line-range-function) | |
189 b (car tmp) | |
190 e (cdr tmp)) | |
191 (setq tmp t | |
192 b (line-beginning-position) | |
193 e (line-beginning-position 2))) | |
194 (if tmp | |
195 (move-overlay overlay b e) | |
196 (move-overlay overlay 1 1)))) | |
197 | |
24961 | 198 (provide 'hl-line) |
199 | |
88155 | 200 ;;; arch-tag: ac806940-0876-4959-8c89-947563ee2833 |
24961 | 201 ;;; hl-line.el ends here |