(ospeed) [HAVE_SPEED_T]: Don't declare extern.
[bpt/emacs.git] / lisp / hl-line.el
CommitLineData
798330fe
DL
1;;; hl-line.el --- highlight the current line
2
c5967e91 3;; Copyright (C) 1998, 2000 Free Software Foundation, Inc.
798330fe
DL
4
5;; Author: Dave Love <fx@gnu.org>
6;; Created: 1998-09-13
7;; Keywords: faces, frames
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
28;; Provides a global minor mode (toggled by M-x hl-line-mode) to
c5967e91
DL
29;; highlight, on a suitable terminal, the line in the current window
30;; on which point is (except in a minibuffer window). Done to satisfy
31;; a request for a feature of Lesser Editors.
798330fe
DL
32
33;; You probably don't really want this; if the cursor is difficult to
c5967e91
DL
34;; spot, try changing its colour or relying on `blink-cursor-mode' The
35;; hookery involved here might slow Emacs noticeably on a slow
36;; machine.
798330fe
DL
37
38;; An overlay is used, active only on the selected window. Hooks are
39;; added to `pre-command-hook' and `post-command-hook' to activate and
40;; deactivate (by deleting) the overlay. `hl-line-unhighlight', on
41;; `pre-command-hook', deactivates it unconditionally in case the
42;; command changes the selected window. (It does so rather than
43;; keeping track of changes in the selected window).
44;; `hl-line-highlight', on `post-command-hook', activates it again
45;; across the window width.
46
47;;; Code:
48
49(defgroup hl-line nil
50 "Highliight the current line."
eee06d26 51 :version "21.1"
798330fe
DL
52 :group 'editing)
53
ceafc2fa 54;;;###autoload
798330fe 55(defcustom hl-line-mode nil
c5967e91
DL
56 "Toggle Hl-Line mode.
57Setting this variable directly does not take effect;
58use either \\[customize] or the function `hl-line-mode'."
798330fe
DL
59 :set (lambda (symbol value)
60 (hl-line-mode (or value 0)))
61 :initialize 'custom-initialize-default
62 :type 'boolean
63 :group 'hl-line
64 :require 'hl-line)
65
66(defcustom hl-line-face 'highlight
67 "Face with which to highlight the current line."
68 :type 'face
69 :group 'hl-line)
70
71(defvar hl-line-overlay nil)
72(make-variable-buffer-local 'hl-line-overlay)
73
74(defun hl-line-highlight ()
75 "Active the Hl-Line overlay on the current line in the current window.
76\(Unless it's a minibuffer window.)"
77 (unless (window-minibuffer-p (selected-window)) ; silly in minibuffer
78 (unless hl-line-overlay ; new overlay for this buffer
79 (setq hl-line-overlay (make-overlay 1 1)) ; to be moved
80 (overlay-put hl-line-overlay 'face hl-line-face))
81 (overlay-put hl-line-overlay 'window (selected-window))
82 (move-overlay hl-line-overlay
83 (line-beginning-position) (1+ (line-end-position)))))
84
85(defun hl-line-unhighlight ()
86 "Deactivate the Hl-Line overlay on the current line in the current window."
87 (if hl-line-overlay
88 (delete-overlay hl-line-overlay)))
89
ceafc2fa 90;;;###autoload
798330fe 91(defun hl-line-mode (&optional arg)
c5967e91 92 "Global minor mode to highlight the line about point in the current window.
798330fe
DL
93
94With ARG, turn Hl-Line mode on if ARG is positive, off otherwise.
798330fe
DL
95Uses functions `hl-line-unhighlight' and `hl-line-highlight' on
96`pre-command-hook' and `post-command-hook'."
97 (interactive "P")
98 (setq hl-line-mode (if (null arg)
99 (not hl-line-mode)
100 (> (prefix-numeric-value arg) 0)))
101 (cond (hl-line-mode
102 (add-hook 'pre-command-hook #'hl-line-unhighlight)
103 (add-hook 'post-command-hook #'hl-line-highlight))
104 (t
105 (hl-line-unhighlight)
106 (remove-hook 'pre-command-hook #'hl-line-unhighlight)
107 (remove-hook 'post-command-hook #'hl-line-highlight)))
108 (if (interactive-p)
109 (message "Hl-Line mode %sabled" (if hl-line-mode "en" "dis"))))
110
111(provide 'hl-line)
112
113;;; hl-line.el ends here