(imenu--generic-function): Use font-lock-defaults
[bpt/emacs.git] / lisp / hl-line.el
CommitLineData
798330fe
DL
1;;; hl-line.el --- highlight the current line
2
b184b2dd 3;; Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc.
798330fe
DL
4
5;; Author: Dave Love <fx@gnu.org>
6;; Created: 1998-09-13
3a850efa 7;; Keywords: faces, frames, emulation
798330fe 8
643c911e
DL
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
798330fe
DL
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
643c911e 16;; GNU Emacs is distributed in the hope that it will be useful,
798330fe
DL
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
10cccf1b 28;; Provides a minor mode (toggled by M-x hl-line-mode) and a global minor
7f68bf91
RS
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.
798330fe
DL
33
34;; You probably don't really want this; if the cursor is difficult to
3a850efa 35;; spot, try changing its colour, relying on `blink-cursor-mode' or
6b567d50 36;; both. The hookery used might affect response noticeably on a slow
7f68bf91
RS
37;; machine. It may be useful in "non-text" buffers such as Gnus or
38;; PCL-CVS though.
798330fe
DL
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
7013279c 49;; You could make variable `hl-line-mode' buffer-local to avoid
7f68bf91 50;; highlighting specific buffers, when the global mode is used.
7013279c 51
798330fe
DL
52;;; Code:
53
54(defgroup hl-line nil
99f2fb1f 55 "Highlight the current line."
eee06d26 56 :version "21.1"
798330fe
DL
57 :group 'editing)
58
798330fe
DL
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)
798330fe 65
ceafc2fa 66;;;###autoload
3a850efa 67(define-minor-mode hl-line-mode
b184b2dd 68 "Minor mode to highlight the line about point in the current window.
798330fe 69With ARG, turn Hl-Line mode on if ARG is positive, off otherwise.
798330fe
DL
70Uses functions `hl-line-unhighlight' and `hl-line-highlight' on
71`pre-command-hook' and `post-command-hook'."
08ead67b 72 nil nil nil
3a850efa
DL
73 (if hl-line-mode
74 (progn
75 (add-hook 'pre-command-hook #'hl-line-unhighlight)
76 (add-hook 'post-command-hook #'hl-line-highlight))
77 (hl-line-unhighlight)
78 (remove-hook 'pre-command-hook #'hl-line-unhighlight)
79 (remove-hook 'post-command-hook #'hl-line-highlight)))
798330fe 80
b184b2dd
GM
81;;;###autoload
82(easy-mmode-define-global-mode
83 global-hl-line-mode hl-line-mode hl-line-mode
84 :group 'hl-line)
85
57e46f94
RS
86(defun hl-line-highlight ()
87 "Active the Hl-Line overlay on the current line in the current window.
88\(Unless it's a minibuffer window.)"
89 (when hl-line-mode ; Could be made buffer-local.
90 (unless (window-minibuffer-p (selected-window)) ; silly in minibuffer
91 (unless hl-line-overlay
92 (setq hl-line-overlay (make-overlay 1 1)) ; to be moved
93 (overlay-put hl-line-overlay 'face hl-line-face))
94 (overlay-put hl-line-overlay 'window (selected-window))
95 (move-overlay hl-line-overlay
96 (line-beginning-position) (1+ (line-end-position))
97 (current-buffer)))))
98
99(defun hl-line-unhighlight ()
100 "Deactivate the Hl-Line overlay on the current line in the current window."
101 (if hl-line-overlay
102 (delete-overlay hl-line-overlay)))
103
798330fe
DL
104(provide 'hl-line)
105
106;;; hl-line.el ends here