Mercurial > emacs
annotate lisp/hl-line.el @ 83919:8b35bdec6c3b
Move to ../doc/lispintro
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Thu, 06 Sep 2007 03:56:58 +0000 |
parents | 9355f9b7bbff |
children | 73661ddc7ac7 f55f9811f5d7 |
rev | line source |
---|---|
24961 | 1 ;;; hl-line.el --- highlight the current line |
2 | |
64762
41bb365f41c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64091
diff
changeset
|
3 ;; Copyright (C) 1998, 2000, 2001, 2002, 2003, 2004, |
75347 | 4 ;; 2005, 2006, 2007 Free Software Foundation, Inc. |
24961 | 5 |
6 ;; Author: Dave Love <fx@gnu.org> | |
52777 | 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 |
78236
9355f9b7bbff
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
15 ;; the Free Software Foundation; either version 3, or (at your option) |
24961 | 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 | |
64091 | 25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 ;; Boston, MA 02110-1301, USA. | |
24961 | 27 |
28 ;;; Commentary: | |
29 | |
52496
3570fa254081
Documentation (comments-only) fix.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
30 ;; Provides a local minor mode (toggled by M-x hl-line-mode) and |
3570fa254081
Documentation (comments-only) fix.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
31 ;; a global minor mode (toggled by M-x global-hl-line-mode) to |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
32 ;; highlight, on a suitable terminal, the line on which point is. The |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
33 ;; global mode highlights the current line in the selected window only |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
34 ;; (except when the minibuffer window is selected). This was |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
35 ;; implemented to satisfy a request for a feature of Lesser Editors. |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
36 ;; The local mode is sticky: it highlights the line about the buffer's |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
37 ;; point even if the buffer's window is not selected. Caveat: the |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
38 ;; buffer's point might be different from the point of a non-selected |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
39 ;; window. Set the variable `hl-line-sticky-flag' to nil to make the |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
40 ;; local mode behave like the global mode. |
24961 | 41 |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
42 ;; You probably don't really want to use the global mode; if the |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
43 ;; cursor is difficult to spot, try changing its colour, relying on |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
44 ;; `blink-cursor-mode' or both. The hookery used might affect |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
45 ;; response noticeably on a slow machine. The local mode may be |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
46 ;; useful in non-editing buffers such as Gnus or PCL-CVS though. |
24961 | 47 |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
48 ;; An overlay is used. In the non-sticky cases, this overlay is |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
49 ;; active only on the selected window. A hook is added to |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
50 ;; `post-command-hook' to activate the overlay and move it to the line |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
51 ;; about point. To get the non-sticky behavior, `hl-line-unhighlight' |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
52 ;; is added to `pre-command-hook' as well. This function deactivates |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
53 ;; the overlay unconditionally in case the command changes the |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
54 ;; selected window. (It does so rather than keeping track of changes |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
55 ;; in the selected window). |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
56 |
52834
7d40f75d6c53
Revert part of 2003-09-13 change.
Lute Kamstra <lute@gnu.org>
parents:
52777
diff
changeset
|
57 ;; You could make variable `global-hl-line-mode' buffer-local and set |
7d40f75d6c53
Revert part of 2003-09-13 change.
Lute Kamstra <lute@gnu.org>
parents:
52777
diff
changeset
|
58 ;; it to nil to avoid highlighting specific buffers, when the global |
7d40f75d6c53
Revert part of 2003-09-13 change.
Lute Kamstra <lute@gnu.org>
parents:
52777
diff
changeset
|
59 ;; mode is used. |
7d40f75d6c53
Revert part of 2003-09-13 change.
Lute Kamstra <lute@gnu.org>
parents:
52777
diff
changeset
|
60 |
68328
ea3b2a2d848c
(hl-line-highlight, hl-line-move): Doc fixes.
John Paul Wallington <jpw@pobox.com>
parents:
64762
diff
changeset
|
61 ;; By default the whole line is highlighted. The range of highlighting |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
54399
diff
changeset
|
62 ;; can be changed by defining an appropriate function as the |
54399
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
63 ;; buffer-local value of `hl-line-range-function'. |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
64 |
24961 | 65 ;;; Code: |
66 | |
72572
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
67 (defvar hl-line-overlay nil |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
68 "Overlay used by Hl-Line mode to highlight the current line.") |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
69 (make-variable-buffer-local 'hl-line-overlay) |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
70 |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
71 (defvar global-hl-line-overlay nil |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
72 "Overlay used by Global-Hl-Line mode to highlight the current line.") |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
73 |
24961 | 74 (defgroup hl-line nil |
35031 | 75 "Highlight the current line." |
25174 | 76 :version "21.1" |
24961 | 77 :group 'editing) |
78 | |
72572
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
79 (defface hl-line |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
80 '((t :inherit highlight)) |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
81 "Default face for highlighting the current line in Hl-Line mode." |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
82 :version "22.1" |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
83 :group 'hl-line) |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
84 |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
85 (defcustom hl-line-face 'hl-line |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
86 "Face with which to highlight the current line in Hl-Line mode." |
24961 | 87 :type 'face |
72572
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
88 :group 'hl-line |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
89 :set (lambda (symbol value) |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
90 (set symbol value) |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
91 (dolist (buffer (buffer-list)) |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
92 (with-current-buffer buffer |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
93 (when hl-line-overlay |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
94 (overlay-put hl-line-overlay 'face hl-line-face)))) |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
95 (when global-hl-line-overlay |
daa3868065ff
* hl-line.el (hl-line): New face.
Chong Yidong <cyd@stupidchicken.com>
parents:
68328
diff
changeset
|
96 (overlay-put global-hl-line-overlay 'face hl-line-face)))) |
24961 | 97 |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
98 (defcustom hl-line-sticky-flag t |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
99 "*Non-nil means highlight the current line in all windows. |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
100 Otherwise Hl-Line mode will highlight only in the selected |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
101 window. Setting this variable takes effect the next time you use |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
102 the command `hl-line-mode' to turn Hl-Line mode on." |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
103 :type 'boolean |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
54399
diff
changeset
|
104 :version "22.1" |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
105 :group 'hl-line) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
106 |
54399
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
107 (defvar hl-line-range-function nil |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
108 "If non-nil, function to call to return highlight range. |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
109 The function of no args should return a cons cell; its car value |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
54399
diff
changeset
|
110 is the beginning position of highlight and its cdr value is the |
54399
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
111 end position of highlight in the buffer. |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
112 It should return nil if there's no region to be highlighted. |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
113 |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
114 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:
52834
diff
changeset
|
115 |
25051
64e3159f0c7b
(hl-line-mode): Add autload cookies.
Dave Love <fx@gnu.org>
parents:
24961
diff
changeset
|
116 ;;;###autoload |
29369
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
117 (define-minor-mode hl-line-mode |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
118 "Buffer-local minor mode to highlight the line about point. |
24961 | 119 With ARG, turn Hl-Line mode on if ARG is positive, off otherwise. |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
120 |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
121 If `hl-line-sticky-flag' is non-nil, Hl-Line mode highlights the |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
122 line about the buffer's point in all windows. Caveat: the |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
123 buffer's point might be different from the point of a |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
124 non-selected window. Hl-Line mode uses the function |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
125 `hl-line-highlight' on `post-command-hook' in this case. |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
126 |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
127 When `hl-line-sticky-flag' is nil, Hl-Line mode highlights the |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
128 line about point in the selected window only. In this case, it |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
129 uses the function `hl-line-unhighlight' on `pre-command-hook' in |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
130 addition to `hl-line-highlight' on `post-command-hook'." |
61271
1d02878293f3
(hl-line-mode): Specify :group.
Lute Kamstra <lute@gnu.org>
parents:
59996
diff
changeset
|
131 :group 'hl-line |
29369
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
132 (if hl-line-mode |
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
133 (progn |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
134 ;; In case `kill-all-local-variables' is called. |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
135 (add-hook 'change-major-mode-hook #'hl-line-unhighlight nil t) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
136 (if hl-line-sticky-flag |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
137 (remove-hook 'pre-command-hook #'hl-line-unhighlight t) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
138 (add-hook 'pre-command-hook #'hl-line-unhighlight nil t)) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
139 (hl-line-highlight) |
50847
47453bc2423e
Removed an erroneous comment.
Lute Kamstra <lute@gnu.org>
parents:
44172
diff
changeset
|
140 (add-hook 'post-command-hook #'hl-line-highlight nil t)) |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
141 (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
|
142 (hl-line-unhighlight) |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
143 (remove-hook 'change-major-mode-hook #'hl-line-unhighlight t) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
144 (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
|
145 |
43031
46823e7a2cae
(hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents:
42842
diff
changeset
|
146 (defun hl-line-highlight () |
68328
ea3b2a2d848c
(hl-line-highlight, hl-line-move): Doc fixes.
John Paul Wallington <jpw@pobox.com>
parents:
64762
diff
changeset
|
147 "Activate the Hl-Line overlay on the current line." |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
148 (if hl-line-mode ; Might be changed outside the mode function. |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
149 (progn |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
150 (unless hl-line-overlay |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
151 (setq hl-line-overlay (make-overlay 1 1)) ; to be moved |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
152 (overlay-put hl-line-overlay 'face hl-line-face)) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
153 (overlay-put hl-line-overlay |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
154 'window (unless hl-line-sticky-flag (selected-window))) |
54399
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
155 (hl-line-move hl-line-overlay)) |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
156 (hl-line-unhighlight))) |
43031
46823e7a2cae
(hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents:
42842
diff
changeset
|
157 |
46823e7a2cae
(hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents:
42842
diff
changeset
|
158 (defun hl-line-unhighlight () |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
159 "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
|
160 (if hl-line-overlay |
46823e7a2cae
(hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents:
42842
diff
changeset
|
161 (delete-overlay hl-line-overlay))) |
46823e7a2cae
(hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents:
42842
diff
changeset
|
162 |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
163 ;;;###autoload |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
164 (define-minor-mode global-hl-line-mode |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
165 "Global minor mode to highlight the line about point in the current window. |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
166 With ARG, turn Global-Hl-Line mode on if ARG is positive, off otherwise. |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
167 |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
168 Global-Hl-Line mode uses the functions `global-hl-line-unhighlight' and |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
169 `global-hl-line-highlight' on `pre-command-hook' and `post-command-hook'." |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
170 :global t |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
171 :group 'hl-line |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
172 (if global-hl-line-mode |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
173 (progn |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
174 (add-hook 'pre-command-hook #'global-hl-line-unhighlight) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
175 (add-hook 'post-command-hook #'global-hl-line-highlight)) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
176 (global-hl-line-unhighlight) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
177 (remove-hook 'pre-command-hook #'global-hl-line-unhighlight) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
178 (remove-hook 'post-command-hook #'global-hl-line-highlight))) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
179 |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
180 (defun global-hl-line-highlight () |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
181 "Active the Global-Hl-Line overlay on the current line in the current window." |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
182 (when global-hl-line-mode ; Might be changed outside the mode function. |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
183 (unless (window-minibuffer-p (selected-window)) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
184 (unless global-hl-line-overlay |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
185 (setq global-hl-line-overlay (make-overlay 1 1)) ; to be moved |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
186 (overlay-put global-hl-line-overlay 'face hl-line-face)) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
187 (overlay-put global-hl-line-overlay 'window (selected-window)) |
54399
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
188 (hl-line-move global-hl-line-overlay)))) |
51010
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
189 |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
190 (defun global-hl-line-unhighlight () |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
191 "Deactivate the Global-Hl-Line overlay on the current line." |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
192 (if global-hl-line-overlay |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
193 (delete-overlay global-hl-line-overlay))) |
f79532778159
Rewrote the local minor mode so that it can be
Lute Kamstra <lute@gnu.org>
parents:
50847
diff
changeset
|
194 |
54399
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
195 (defun hl-line-move (overlay) |
68328
ea3b2a2d848c
(hl-line-highlight, hl-line-move): Doc fixes.
John Paul Wallington <jpw@pobox.com>
parents:
64762
diff
changeset
|
196 "Move the Hl-Line overlay. |
54399
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
197 If `hl-line-range-function' is non-nil, move the OVERLAY to the position |
68328
ea3b2a2d848c
(hl-line-highlight, hl-line-move): Doc fixes.
John Paul Wallington <jpw@pobox.com>
parents:
64762
diff
changeset
|
198 where the function returns. If `hl-line-range-function' is nil, fill |
54399
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
199 the line including the point by OVERLAY." |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
200 (let (tmp b e) |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
201 (if hl-line-range-function |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
202 (setq tmp (funcall hl-line-range-function) |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
203 b (car tmp) |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
204 e (cdr tmp)) |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
205 (setq tmp t |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
206 b (line-beginning-position) |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
207 e (line-beginning-position 2))) |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
208 (if tmp |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
209 (move-overlay overlay b e) |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
210 (move-overlay overlay 1 1)))) |
ad02f6299e9a
2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents:
52834
diff
changeset
|
211 |
24961 | 212 (provide 'hl-line) |
213 | |
52401 | 214 ;;; arch-tag: ac806940-0876-4959-8c89-947563ee2833 |
24961 | 215 ;;; hl-line.el ends here |