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