Mercurial > emacs
annotate lisp/hl-line.el @ 43017:a73bc2f013fc
(normal-splash-screen, display-splash-screen): New functions (separated
from command-line-1).
(command-line-1): Use them.
author | Pavel Janík <Pavel@Janik.cz> |
---|---|
date | Tue, 29 Jan 2002 13:54:39 +0000 |
parents | f56af27693dc |
children | 46823e7a2cae |
rev | line source |
---|---|
24961 | 1 ;;; hl-line.el --- highlight the current line |
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 | 4 |
5 ;; Author: Dave Love <fx@gnu.org> | |
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 | 8 |
29087 | 9 ;; This file is part of GNU Emacs. |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
24961 | 12 ;; it under the terms of the GNU General Public License as published by |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
29087 | 16 ;; GNU Emacs is distributed in the hope that it will be useful, |
24961 | 17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
42842 | 28 ;; Provides a minor mode (toggled by M-x hl-line-ode) and a global minor |
29 ;; mode (toggled by M-x global-hl-line-mode) to highlight, on a | |
30 ;; suitable terminal, the line in the current window on which point is | |
31 ;; (except in a minibuffer window). Done to satisfy a request for a | |
32 ;; feature of Lesser Editors. | |
24961 | 33 |
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 | 36 ;; both. The hookery used might affect response noticeably on a slow |
42842 | 37 ;; machine. It may be useful in "non-text" buffers such as Gnus or |
38 ;; PCL-CVS though. | |
24961 | 39 |
40 ;; An overlay is used, active only on the selected window. Hooks are | |
41 ;; added to `pre-command-hook' and `post-command-hook' to activate and | |
42 ;; deactivate (by deleting) the overlay. `hl-line-unhighlight', on | |
43 ;; `pre-command-hook', deactivates it unconditionally in case the | |
44 ;; command changes the selected window. (It does so rather than | |
45 ;; keeping track of changes in the selected window). | |
46 ;; `hl-line-highlight', on `post-command-hook', activates it again | |
47 ;; across the window width. | |
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 | 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 | 52 ;;; Code: |
53 | |
54 (defgroup hl-line nil | |
35031 | 55 "Highlight the current line." |
25174 | 56 :version "21.1" |
24961 | 57 :group 'editing) |
58 | |
59 (defcustom hl-line-face 'highlight | |
60 "Face with which to highlight the current line." | |
61 :type 'face | |
62 :group 'hl-line) | |
63 | |
64 (defvar hl-line-overlay nil) | |
65 | |
66 (defun hl-line-highlight () | |
67 "Active the Hl-Line overlay on the current line in the current window. | |
68 \(Unless it's a minibuffer window.)" | |
30274
428e9eb82841
(hl-line-highlight): Check hl-line-mode.
Dave Love <fx@gnu.org>
parents:
30034
diff
changeset
|
69 (when hl-line-mode ; Could be made buffer-local. |
428e9eb82841
(hl-line-highlight): Check hl-line-mode.
Dave Love <fx@gnu.org>
parents:
30034
diff
changeset
|
70 (unless (window-minibuffer-p (selected-window)) ; silly in minibuffer |
31846
6e48fd527039
(hl-line-overlay): Don't make it buffer-local.
Dave Love <fx@gnu.org>
parents:
30274
diff
changeset
|
71 (unless hl-line-overlay |
30274
428e9eb82841
(hl-line-highlight): Check hl-line-mode.
Dave Love <fx@gnu.org>
parents:
30034
diff
changeset
|
72 (setq hl-line-overlay (make-overlay 1 1)) ; to be moved |
428e9eb82841
(hl-line-highlight): Check hl-line-mode.
Dave Love <fx@gnu.org>
parents:
30034
diff
changeset
|
73 (overlay-put hl-line-overlay 'face hl-line-face)) |
428e9eb82841
(hl-line-highlight): Check hl-line-mode.
Dave Love <fx@gnu.org>
parents:
30034
diff
changeset
|
74 (overlay-put hl-line-overlay 'window (selected-window)) |
428e9eb82841
(hl-line-highlight): Check hl-line-mode.
Dave Love <fx@gnu.org>
parents:
30034
diff
changeset
|
75 (move-overlay hl-line-overlay |
31846
6e48fd527039
(hl-line-overlay): Don't make it buffer-local.
Dave Love <fx@gnu.org>
parents:
30274
diff
changeset
|
76 (line-beginning-position) (1+ (line-end-position)) |
6e48fd527039
(hl-line-overlay): Don't make it buffer-local.
Dave Love <fx@gnu.org>
parents:
30274
diff
changeset
|
77 (current-buffer))))) |
24961 | 78 |
79 (defun hl-line-unhighlight () | |
80 "Deactivate the Hl-Line overlay on the current line in the current window." | |
81 (if hl-line-overlay | |
82 (delete-overlay hl-line-overlay))) | |
83 | |
25051
64e3159f0c7b
(hl-line-mode): Add autload cookies.
Dave Love <fx@gnu.org>
parents:
24961
diff
changeset
|
84 ;;;###autoload |
29369
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
85 (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
|
86 "Minor mode to highlight the line about point in the current window. |
24961 | 87 With ARG, turn Hl-Line mode on if ARG is positive, off otherwise. |
88 Uses functions `hl-line-unhighlight' and `hl-line-highlight' on | |
89 `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
|
90 nil nil nil |
29369
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
91 (if hl-line-mode |
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
92 (progn |
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
93 (add-hook 'pre-command-hook #'hl-line-unhighlight) |
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
94 (add-hook 'post-command-hook #'hl-line-highlight)) |
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
95 (hl-line-unhighlight) |
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
96 (remove-hook 'pre-command-hook #'hl-line-unhighlight) |
48dc52f114f3
Rewritten using define-minor-mode.
Dave Love <fx@gnu.org>
parents:
29087
diff
changeset
|
97 (remove-hook 'post-command-hook #'hl-line-highlight))) |
24961 | 98 |
38937
ff93d7955c3d
(hl-line-mode): Don't be a global mode.
Gerd Moellmann <gerd@gnu.org>
parents:
35031
diff
changeset
|
99 ;;;###autoload |
ff93d7955c3d
(hl-line-mode): Don't be a global mode.
Gerd Moellmann <gerd@gnu.org>
parents:
35031
diff
changeset
|
100 (easy-mmode-define-global-mode |
ff93d7955c3d
(hl-line-mode): Don't be a global mode.
Gerd Moellmann <gerd@gnu.org>
parents:
35031
diff
changeset
|
101 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
|
102 :group 'hl-line) |
ff93d7955c3d
(hl-line-mode): Don't be a global mode.
Gerd Moellmann <gerd@gnu.org>
parents:
35031
diff
changeset
|
103 |
24961 | 104 (provide 'hl-line) |
105 | |
106 ;;; hl-line.el ends here |