annotate lisp/hl-line.el @ 27728:01121d3b9952

Remove LISP_FLOAT_TYPE.
author Gerd Moellmann <gerd@gnu.org>
date Thu, 17 Feb 2000 09:47:23 +0000
parents b4676dda4b53
children d6e90113152f
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
27228
b4676dda4b53 (hl-line-mode): Fix defcustom.
Dave Love <fx@gnu.org>
parents: 25174
diff changeset
3 ;; Copyright (C) 1998, 2000 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
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
7 ;; Keywords: faces, frames
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
8
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
9 ;; Hl-Line mode is free software; you can redistribute it and/or modify
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
12 ;; any later version.
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
13
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
14 ;; Hl-Line mode is distributed in the hope that it will be useful,
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
18
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
23
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
24 ;;; Commentary:
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
25
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
26 ;; Provides a global minor mode (toggled by M-x hl-line-mode) to
27228
b4676dda4b53 (hl-line-mode): Fix defcustom.
Dave Love <fx@gnu.org>
parents: 25174
diff changeset
27 ;; highlight, on a suitable terminal, the line in the current window
b4676dda4b53 (hl-line-mode): Fix defcustom.
Dave Love <fx@gnu.org>
parents: 25174
diff changeset
28 ;; on which point is (except in a minibuffer window). Done to satisfy
b4676dda4b53 (hl-line-mode): Fix defcustom.
Dave Love <fx@gnu.org>
parents: 25174
diff changeset
29 ;; a request for a feature of Lesser Editors.
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
30
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
31 ;; You probably don't really want this; if the cursor is difficult to
27228
b4676dda4b53 (hl-line-mode): Fix defcustom.
Dave Love <fx@gnu.org>
parents: 25174
diff changeset
32 ;; spot, try changing its colour or relying on `blink-cursor-mode' The
b4676dda4b53 (hl-line-mode): Fix defcustom.
Dave Love <fx@gnu.org>
parents: 25174
diff changeset
33 ;; hookery involved here might slow Emacs noticeably on a slow
b4676dda4b53 (hl-line-mode): Fix defcustom.
Dave Love <fx@gnu.org>
parents: 25174
diff changeset
34 ;; machine.
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
35
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
36 ;; An overlay is used, active only on the selected window. Hooks are
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
37 ;; added to `pre-command-hook' and `post-command-hook' to activate and
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
38 ;; deactivate (by deleting) the overlay. `hl-line-unhighlight', on
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
39 ;; `pre-command-hook', deactivates it unconditionally in case the
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
40 ;; command changes the selected window. (It does so rather than
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
41 ;; keeping track of changes in the selected window).
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
42 ;; `hl-line-highlight', on `post-command-hook', activates it again
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
43 ;; across the window width.
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
44
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
45 ;;; Code:
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
46
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
47 (defgroup hl-line nil
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
48 "Highliight the current line."
25174
caaa177b2390 (hl-line): Fix :version.
Dave Love <fx@gnu.org>
parents: 25051
diff changeset
49 :version "21.1"
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
50 :group 'editing)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
51
25051
64e3159f0c7b (hl-line-mode): Add autload cookies.
Dave Love <fx@gnu.org>
parents: 24961
diff changeset
52 ;;;###autoload
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
53 (defcustom hl-line-mode nil
27228
b4676dda4b53 (hl-line-mode): Fix defcustom.
Dave Love <fx@gnu.org>
parents: 25174
diff changeset
54 "Toggle Hl-Line mode.
b4676dda4b53 (hl-line-mode): Fix defcustom.
Dave Love <fx@gnu.org>
parents: 25174
diff changeset
55 Setting this variable directly does not take effect;
b4676dda4b53 (hl-line-mode): Fix defcustom.
Dave Love <fx@gnu.org>
parents: 25174
diff changeset
56 use either \\[customize] or the function `hl-line-mode'."
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
57 :set (lambda (symbol value)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
58 (hl-line-mode (or value 0)))
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
59 :initialize 'custom-initialize-default
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
60 :type 'boolean
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
61 :group 'hl-line
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
62 :require '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 (defcustom hl-line-face 'highlight
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
65 "Face with which to highlight the current line."
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
66 :type 'face
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
67 :group 'hl-line)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
68
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
69 (defvar hl-line-overlay nil)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
70 (make-variable-buffer-local 'hl-line-overlay)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
71
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
72 (defun hl-line-highlight ()
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
73 "Active the Hl-Line overlay on the current line in the current window.
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
74 \(Unless it's a minibuffer window.)"
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
75 (unless (window-minibuffer-p (selected-window)) ; silly in minibuffer
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
76 (unless hl-line-overlay ; new overlay for this buffer
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
77 (setq hl-line-overlay (make-overlay 1 1)) ; to be moved
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
78 (overlay-put hl-line-overlay 'face hl-line-face))
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
79 (overlay-put hl-line-overlay 'window (selected-window))
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
80 (move-overlay hl-line-overlay
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
81 (line-beginning-position) (1+ (line-end-position)))))
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
82
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
83 (defun hl-line-unhighlight ()
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
84 "Deactivate the Hl-Line overlay on the current line in the current window."
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
85 (if hl-line-overlay
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
86 (delete-overlay hl-line-overlay)))
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
87
25051
64e3159f0c7b (hl-line-mode): Add autload cookies.
Dave Love <fx@gnu.org>
parents: 24961
diff changeset
88 ;;;###autoload
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
89 (defun hl-line-mode (&optional arg)
27228
b4676dda4b53 (hl-line-mode): Fix defcustom.
Dave Love <fx@gnu.org>
parents: 25174
diff changeset
90 "Global minor mode to highlight the line about point in the current window.
24961
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
91
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
92 With ARG, turn Hl-Line mode on if ARG is positive, off otherwise.
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
93 Uses functions `hl-line-unhighlight' and `hl-line-highlight' on
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
94 `pre-command-hook' and `post-command-hook'."
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
95 (interactive "P")
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
96 (setq hl-line-mode (if (null arg)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
97 (not hl-line-mode)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
98 (> (prefix-numeric-value arg) 0)))
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
99 (cond (hl-line-mode
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
100 (add-hook 'pre-command-hook #'hl-line-unhighlight)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
101 (add-hook 'post-command-hook #'hl-line-highlight))
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
102 (t
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
103 (hl-line-unhighlight)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
104 (remove-hook 'pre-command-hook #'hl-line-unhighlight)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
105 (remove-hook 'post-command-hook #'hl-line-highlight)))
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
106 (if (interactive-p)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
107 (message "Hl-Line mode %sabled" (if hl-line-mode "en" "dis"))))
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
108
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
109 (provide 'hl-line)
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
110
4d9ce81656da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
111 ;;; hl-line.el ends here