Mercurial > emacs
comparison lisp/hl-line.el @ 89909:68c22ea6027c
Sync to HEAD
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 16 Apr 2004 12:51:06 +0000 |
parents | 375f2633d815 |
children | 3ebd9bdb4fe5 |
comparison
equal
deleted
inserted
replaced
89908:ee1402f7b568 | 89909:68c22ea6027c |
---|---|
1 ;;; hl-line.el --- highlight the current line | 1 ;;; hl-line.el --- highlight the current line |
2 | 2 |
3 ;; Copyright (C) 1998, 2000, 2001, 2003 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1998, 2000, 2001, 2003 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Dave Love <fx@gnu.org> | 5 ;; Author: Dave Love <fx@gnu.org> |
6 ;; Maintainer: FSF | |
6 ;; Created: 1998-09-13 | 7 ;; Created: 1998-09-13 |
7 ;; Keywords: faces, frames, emulation | 8 ;; Keywords: faces, frames, emulation |
8 | 9 |
9 ;; This file is part of GNU Emacs. | 10 ;; This file is part of GNU Emacs. |
10 | 11 |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
24 ;; Boston, MA 02111-1307, USA. | 25 ;; Boston, MA 02111-1307, USA. |
25 | 26 |
26 ;;; Commentary: | 27 ;;; Commentary: |
27 | 28 |
28 ;; Provides a buffer-local minor mode (toggled by M-x hl-line-mode) | 29 ;; Provides a local minor mode (toggled by M-x hl-line-mode) and |
29 ;; and a global minor mode (toggled by M-x global-hl-line-mode) to | 30 ;; a global minor mode (toggled by M-x global-hl-line-mode) to |
30 ;; highlight, on a suitable terminal, the line on which point is. The | 31 ;; highlight, on a suitable terminal, the line on which point is. The |
31 ;; global mode highlights the current line in the selected window only | 32 ;; global mode highlights the current line in the selected window only |
32 ;; (except when the minibuffer window is selected). This was | 33 ;; (except when the minibuffer window is selected). This was |
33 ;; implemented to satisfy a request for a feature of Lesser Editors. | 34 ;; implemented to satisfy a request for a feature of Lesser Editors. |
34 ;; The local mode is sticky: it highlights the line about the buffer's | 35 ;; The local mode is sticky: it highlights the line about the buffer's |
54 | 55 |
55 ;; You could make variable `global-hl-line-mode' buffer-local and set | 56 ;; You could make variable `global-hl-line-mode' buffer-local and set |
56 ;; it to nil to avoid highlighting specific buffers, when the global | 57 ;; it to nil to avoid highlighting specific buffers, when the global |
57 ;; mode is used. | 58 ;; mode is used. |
58 | 59 |
60 ;; In default whole the line is highlighted. The range of highlighting | |
61 ;; can be changed by defining an appropriate function as the | |
62 ;; buffer-local value of `hl-line-range-function'. | |
63 | |
59 ;;; Code: | 64 ;;; Code: |
60 | 65 |
61 (defgroup hl-line nil | 66 (defgroup hl-line nil |
62 "Highlight the current line." | 67 "Highlight the current line." |
63 :version "21.1" | 68 :version "21.1" |
74 window. Setting this variable takes effect the next time you use | 79 window. Setting this variable takes effect the next time you use |
75 the command `hl-line-mode' to turn Hl-Line mode on." | 80 the command `hl-line-mode' to turn Hl-Line mode on." |
76 :type 'boolean | 81 :type 'boolean |
77 :version "21.4" | 82 :version "21.4" |
78 :group 'hl-line) | 83 :group 'hl-line) |
84 | |
85 (defvar hl-line-range-function nil | |
86 "If non-nil, function to call to return highlight range. | |
87 The function of no args should return a cons cell; its car value | |
88 is the beginning position of highlight and its cdr value is the | |
89 end position of highlight in the buffer. | |
90 It should return nil if there's no region to be highlighted. | |
91 | |
92 This variable is expected to be made buffer-local by modes.") | |
79 | 93 |
80 (defvar hl-line-overlay nil | 94 (defvar hl-line-overlay nil |
81 "Overlay used by Hl-Line mode to highlight the current line.") | 95 "Overlay used by Hl-Line mode to highlight the current line.") |
82 (make-variable-buffer-local 'hl-line-overlay) | 96 (make-variable-buffer-local 'hl-line-overlay) |
83 | 97 |
121 (unless hl-line-overlay | 135 (unless hl-line-overlay |
122 (setq hl-line-overlay (make-overlay 1 1)) ; to be moved | 136 (setq hl-line-overlay (make-overlay 1 1)) ; to be moved |
123 (overlay-put hl-line-overlay 'face hl-line-face)) | 137 (overlay-put hl-line-overlay 'face hl-line-face)) |
124 (overlay-put hl-line-overlay | 138 (overlay-put hl-line-overlay |
125 'window (unless hl-line-sticky-flag (selected-window))) | 139 'window (unless hl-line-sticky-flag (selected-window))) |
126 (move-overlay hl-line-overlay | 140 (hl-line-move hl-line-overlay)) |
127 (line-beginning-position) (line-beginning-position 2))) | |
128 (hl-line-unhighlight))) | 141 (hl-line-unhighlight))) |
129 | 142 |
130 (defun hl-line-unhighlight () | 143 (defun hl-line-unhighlight () |
131 "Deactivate the Hl-Line overlay on the current line." | 144 "Deactivate the Hl-Line overlay on the current line." |
132 (if hl-line-overlay | 145 (if hl-line-overlay |
155 (unless (window-minibuffer-p (selected-window)) | 168 (unless (window-minibuffer-p (selected-window)) |
156 (unless global-hl-line-overlay | 169 (unless global-hl-line-overlay |
157 (setq global-hl-line-overlay (make-overlay 1 1)) ; to be moved | 170 (setq global-hl-line-overlay (make-overlay 1 1)) ; to be moved |
158 (overlay-put global-hl-line-overlay 'face hl-line-face)) | 171 (overlay-put global-hl-line-overlay 'face hl-line-face)) |
159 (overlay-put global-hl-line-overlay 'window (selected-window)) | 172 (overlay-put global-hl-line-overlay 'window (selected-window)) |
160 (move-overlay global-hl-line-overlay | 173 (hl-line-move global-hl-line-overlay)))) |
161 (line-beginning-position) (line-beginning-position 2))))) | |
162 | 174 |
163 (defun global-hl-line-unhighlight () | 175 (defun global-hl-line-unhighlight () |
164 "Deactivate the Global-Hl-Line overlay on the current line." | 176 "Deactivate the Global-Hl-Line overlay on the current line." |
165 (if global-hl-line-overlay | 177 (if global-hl-line-overlay |
166 (delete-overlay global-hl-line-overlay))) | 178 (delete-overlay global-hl-line-overlay))) |
167 | 179 |
180 (defun hl-line-move (overlay) | |
181 "Move the hl-line-mode overlay. | |
182 If `hl-line-range-function' is non-nil, move the OVERLAY to the position | |
183 where the function returns. If `hl-line-range-function' is nil, fill | |
184 the line including the point by OVERLAY." | |
185 (let (tmp b e) | |
186 (if hl-line-range-function | |
187 (setq tmp (funcall hl-line-range-function) | |
188 b (car tmp) | |
189 e (cdr tmp)) | |
190 (setq tmp t | |
191 b (line-beginning-position) | |
192 e (line-beginning-position 2))) | |
193 (if tmp | |
194 (move-overlay overlay b e) | |
195 (move-overlay overlay 1 1)))) | |
196 | |
168 (provide 'hl-line) | 197 (provide 'hl-line) |
169 | 198 |
199 ;;; arch-tag: ac806940-0876-4959-8c89-947563ee2833 | |
170 ;;; hl-line.el ends here | 200 ;;; hl-line.el ends here |