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