(buffer-syntactic-context): Don't quote nil and t in docstrings.
[emacs.git] / lisp / hl-line.el
blob727f859a32e2542a6a272589febbdeed44ab290f
1 ;;; hl-line.el --- highlight the current line
3 ;; Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc.
5 ;; Author: Dave Love <fx@gnu.org>
6 ;; Created: 1998-09-13
7 ;; Keywords: faces, frames, emulation
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
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.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
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.
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.
26 ;;; Commentary:
28 ;; Provides a minor mode (toggled by M-x hl-line-mode) 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.
34 ;; You probably don't really want this; if the cursor is difficult to
35 ;; spot, try changing its colour, relying on `blink-cursor-mode' or
36 ;; both. The hookery used might affect response noticeably on a slow
37 ;; machine. It may be useful in "non-text" buffers such as Gnus or
38 ;; PCL-CVS though.
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.
49 ;;; Code:
51 (defgroup hl-line nil
52 "Highlight the current line."
53 :version "21.1"
54 :group 'editing)
56 (defcustom hl-line-face 'highlight
57 "Face with which to highlight the current line."
58 :type 'face
59 :group 'hl-line)
61 (defvar hl-line-overlay nil)
63 ;;;###autoload
64 (define-minor-mode hl-line-mode
65 "Minor mode to highlight the line about point in the current window.
66 With ARG, turn Hl-Line mode on if ARG is positive, off otherwise.
67 Uses functions `hl-line-unhighlight' and `hl-line-highlight' on
68 `pre-command-hook' and `post-command-hook'."
69 nil nil nil
70 (if hl-line-mode
71 (progn
72 (add-hook 'pre-command-hook #'hl-line-unhighlight nil t)
73 (add-hook 'post-command-hook #'hl-line-highlight nil t))
74 (hl-line-unhighlight)
75 (remove-hook 'pre-command-hook #'hl-line-unhighlight t)
76 (remove-hook 'post-command-hook #'hl-line-highlight t)))
78 ;;;###autoload
79 (easy-mmode-define-global-mode
80 global-hl-line-mode hl-line-mode (lambda () (hl-line-mode 1))
81 :group 'hl-line)
83 (defun hl-line-highlight ()
84 "Active the Hl-Line overlay on the current line in the current window.
85 \(Unless it's a minibuffer window.)"
86 (when hl-line-mode ; Might be changed outside the mode function.
87 (unless (window-minibuffer-p (selected-window)) ; silly in minibuffer
88 (unless hl-line-overlay
89 (setq hl-line-overlay (make-overlay 1 1)) ; to be moved
90 (overlay-put hl-line-overlay 'face hl-line-face))
91 (overlay-put hl-line-overlay 'window (selected-window))
92 (move-overlay hl-line-overlay
93 (line-beginning-position) (1+ (line-end-position))
94 (current-buffer)))))
96 (defun hl-line-unhighlight ()
97 "Deactivate the Hl-Line overlay on the current line in the current window."
98 (if hl-line-overlay
99 (delete-overlay hl-line-overlay)))
101 (provide 'hl-line)
103 ;;; hl-line.el ends here