annotate lisp/hl-line.el @ 46483:7350385eb42a

(tool-bar-add-item-from-menu): Make sure to change the global tool-bar-map.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 16 Jul 2002 22:46:09 +0000
parents 23f28487b3a4
children 47453bc2423e d7ddb3e565de
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
38937
ff93d7955c3d (hl-line-mode): Don't be a global mode.
Gerd Moellmann <gerd@gnu.org>
parents: 35031
diff changeset
3 ;; Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc.
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
4
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
5 ;; Author: Dave Love <fx@gnu.org>
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
6 ;; Created: 1998-09-13
29369
48dc52f114f3 Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents: 29087
diff changeset
7 ;; Keywords: faces, frames, emulation
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
8
29087
d6e90113152f Fix boilerplate comments.
Dave Love <fx@gnu.org>
parents: 27228
diff changeset
9 ;; This file is part of GNU Emacs.
d6e90113152f Fix boilerplate comments.
Dave Love <fx@gnu.org>
parents: 27228
diff changeset
10
d6e90113152f Fix boilerplate comments.
Dave Love <fx@gnu.org>
parents: 27228
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
14 ;; any later version.
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
15
29087
d6e90113152f Fix boilerplate comments.
Dave Love <fx@gnu.org>
parents: 27228
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
20
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
25
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
27
44172
23f28487b3a4 Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 43031
diff changeset
28 ;; Provides a minor mode (toggled by M-x hl-line-mode) and a global minor
42842
f56af27693dc Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 38955
diff changeset
29 ;; mode (toggled by M-x global-hl-line-mode) to highlight, on a
f56af27693dc Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 38955
diff changeset
30 ;; suitable terminal, the line in the current window on which point is
f56af27693dc Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 38955
diff changeset
31 ;; (except in a minibuffer window). Done to satisfy a request for a
f56af27693dc Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 38955
diff changeset
32 ;; feature of Lesser Editors.
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
33
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
34 ;; You probably don't really want this; if the cursor is difficult to
29369
48dc52f114f3 Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents: 29087
diff changeset
35 ;; spot, try changing its colour, relying on `blink-cursor-mode' or
29610
a66af23236bf Fixed a typo in commentary.
Eli Zaretskii <eliz@gnu.org>
parents: 29425
diff changeset
36 ;; both. The hookery used might affect response noticeably on a slow
42842
f56af27693dc Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 38955
diff changeset
37 ;; machine. It may be useful in "non-text" buffers such as Gnus or
f56af27693dc Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 38955
diff changeset
38 ;; PCL-CVS though.
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
39
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
40 ;; An overlay is used, active only on the selected window. Hooks are
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
41 ;; added to `pre-command-hook' and `post-command-hook' to activate and
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
42 ;; deactivate (by deleting) the overlay. `hl-line-unhighlight', on
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
43 ;; `pre-command-hook', deactivates it unconditionally in case the
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
44 ;; command changes the selected window. (It does so rather than
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
45 ;; keeping track of changes in the selected window).
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
46 ;; `hl-line-highlight', on `post-command-hook', activates it again
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
47 ;; across the window width.
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
48
30274
428e9eb82841 (hl-line-highlight): Check hl-line-mode.
Dave Love <fx@gnu.org>
parents: 30034
diff changeset
49 ;; You could make variable `hl-line-mode' buffer-local to avoid
42842
f56af27693dc Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 38955
diff changeset
50 ;; highlighting specific buffers, when the global mode is used.
30274
428e9eb82841 (hl-line-highlight): Check hl-line-mode.
Dave Love <fx@gnu.org>
parents: 30034
diff changeset
51
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
52 ;;; Code:
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
53
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
54 (defgroup hl-line nil
35031
c42fc96648de (hl-line): Doc fix.
Dave Love <fx@gnu.org>
parents: 33187
diff changeset
55 "Highlight the current line."
25174
caaa177b2390 (hl-line): Fix :version.
Dave Love <fx@gnu.org>
parents: 25051
diff changeset
56 :version "21.1"
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
57 :group 'editing)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
58
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
59 (defcustom hl-line-face 'highlight
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
60 "Face with which to highlight the current line."
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
61 :type 'face
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
62 :group 'hl-line)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
63
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
64 (defvar hl-line-overlay nil)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
65
25051
64e3159f0c7b (hl-line-mode): Add autload cookies.
Dave Love <fx@gnu.org>
parents: 24961
diff changeset
66 ;;;###autoload
29369
48dc52f114f3 Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents: 29087
diff changeset
67 (define-minor-mode hl-line-mode
38937
ff93d7955c3d (hl-line-mode): Don't be a global mode.
Gerd Moellmann <gerd@gnu.org>
parents: 35031
diff changeset
68 "Minor mode to highlight the line about point in the current window.
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
69 With ARG, turn Hl-Line mode on if ARG is positive, off otherwise.
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
70 Uses functions `hl-line-unhighlight' and `hl-line-highlight' on
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
71 `pre-command-hook' and `post-command-hook'."
38955
9bdcb656d1cf (hl-line-mode): Add args INIT-VALUE, LIGHTER, and
Gerd Moellmann <gerd@gnu.org>
parents: 38937
diff changeset
72 nil nil nil
29369
48dc52f114f3 Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents: 29087
diff changeset
73 (if hl-line-mode
48dc52f114f3 Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents: 29087
diff changeset
74 (progn
48dc52f114f3 Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents: 29087
diff changeset
75 (add-hook 'pre-command-hook #'hl-line-unhighlight)
48dc52f114f3 Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents: 29087
diff changeset
76 (add-hook 'post-command-hook #'hl-line-highlight))
48dc52f114f3 Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents: 29087
diff changeset
77 (hl-line-unhighlight)
48dc52f114f3 Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents: 29087
diff changeset
78 (remove-hook 'pre-command-hook #'hl-line-unhighlight)
48dc52f114f3 Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents: 29087
diff changeset
79 (remove-hook 'post-command-hook #'hl-line-highlight)))
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
80
38937
ff93d7955c3d (hl-line-mode): Don't be a global mode.
Gerd Moellmann <gerd@gnu.org>
parents: 35031
diff changeset
81 ;;;###autoload
ff93d7955c3d (hl-line-mode): Don't be a global mode.
Gerd Moellmann <gerd@gnu.org>
parents: 35031
diff changeset
82 (easy-mmode-define-global-mode
ff93d7955c3d (hl-line-mode): Don't be a global mode.
Gerd Moellmann <gerd@gnu.org>
parents: 35031
diff changeset
83 global-hl-line-mode hl-line-mode hl-line-mode
ff93d7955c3d (hl-line-mode): Don't be a global mode.
Gerd Moellmann <gerd@gnu.org>
parents: 35031
diff changeset
84 :group 'hl-line)
ff93d7955c3d (hl-line-mode): Don't be a global mode.
Gerd Moellmann <gerd@gnu.org>
parents: 35031
diff changeset
85
43031
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
86 (defun hl-line-highlight ()
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
87 "Active the Hl-Line overlay on the current line in the current window.
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
88 \(Unless it's a minibuffer window.)"
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
89 (when hl-line-mode ; Could be made buffer-local.
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
90 (unless (window-minibuffer-p (selected-window)) ; silly in minibuffer
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
91 (unless hl-line-overlay
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
92 (setq hl-line-overlay (make-overlay 1 1)) ; to be moved
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
93 (overlay-put hl-line-overlay 'face hl-line-face))
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
94 (overlay-put hl-line-overlay 'window (selected-window))
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
95 (move-overlay hl-line-overlay
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
96 (line-beginning-position) (1+ (line-end-position))
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
97 (current-buffer)))))
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
98
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
99 (defun hl-line-unhighlight ()
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
100 "Deactivate the Hl-Line overlay on the current line in the current window."
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
101 (if hl-line-overlay
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
102 (delete-overlay hl-line-overlay)))
46823e7a2cae (hl-line-highlight, hl-line-unhighlight):
Richard M. Stallman <rms@gnu.org>
parents: 42842
diff changeset
103
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
104 (provide 'hl-line)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
105
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
106 ;;; hl-line.el ends here