initial commit
[emacs-init.git] / auto-install / hl-line+.el
1 ;;; hl-line+.el --- Extensions to hl-line.el.
2 ;; 
3 ;; Filename: hl-line+.el
4 ;; Description: Extensions to hl-line.el.
5 ;; Author: Drew Adams
6 ;; Maintainer: Drew Adams
7 ;; Copyright (C) 2006-2011, Drew Adams, all rights reserved.
8 ;; Created: Sat Aug 26 18:17:18 2006
9 ;; Version: 22.0
10 ;; Last-Updated: Thu Feb 24 15:22:18 2011 (-0800)
11 ;;           By: dradams
12 ;;     Update #: 434
13 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/hl-line+.el
14 ;; Keywords: highlight, cursor, accessibility
15 ;; Compatibility: GNU Emacs: 22.x, 23.x
16 ;; 
17 ;; Features that might be required by this library:
18 ;;
19 ;;   `hl-line'.
20 ;;
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 ;; 
23 ;;; Commentary: 
24 ;;
25 ;;  This library extends standard library `hl-line.el' in these ways:
26 ;;
27 ;;  1. As an alternative to turning on `hl-line' highlighting at all
28 ;;     times, you can turn it on only when Emacs is idle.  To do that,
29 ;;     use command `toggle-hl-line-when-idle' and customize
30 ;;     `global-hl-line-mode' to nil.
31 ;;
32 ;;  2. As another alternative, you can turn it on for only a few
33 ;;     seconds.  To do that, use command `flash-line-highlight' and
34 ;;     customize `global-hl-line-mode' to nil.
35 ;;
36 ;;  3. It provides a face, `hl-line', that you can customize, instead
37 ;;     of using option `hl-line-face'.  
38 ;;
39 ;;     I suggested #3 to the Emacs developers, and it has been added
40 ;;     to Emacs 22, but with a different default value.  If you use
41 ;;     library `crosshairs.el', you might want to customize this to a
42 ;;     value similar to what is used there, so that the horizontal and
43 ;;     vertical highlights will be the same.
44 ;;
45 ;;  To use this library, put this in your Emacs init file (~/.emacs):
46 ;;
47 ;;    (require 'hl-line+) ; Load this file (it will load `hl-line.el')
48 ;;
49 ;;  To turn on `global-hl-line-mode' only when Emacs is idle, by
50 ;;  default, add this line also to your init file:
51 ;;
52 ;;    (toggle-hl-line-when-idle 1) ; Highlight only when idle
53 ;;
54 ;;  You can use command `toggle-hl-line-when-idle' to turn idle
55 ;;  highlighting on and off at any time.  You can use command
56 ;;  `hl-line-when-idle-interval' to change the number of idle seconds
57 ;;  to wait before highlighting.
58 ;;
59 ;;
60 ;;  See also these libraries:
61 ;;
62 ;;  * `col-highlight.el', which highlights the current column.
63 ;;
64 ;;  * `crosshairs.el', which highlights the current line and the
65 ;;    current column, at the same time.  It requires libraries
66 ;;    `col-highlight.el' and `hl-line+.el'.
67 ;;
68 ;;  * `hl-spotlight.el', which extends `hl-line.el' by spotlighting
69 ;;    the lines around the cursor.
70 ;;
71 ;;  * `cursor-chg.el' or library `oneonone.el', to change the cursor
72 ;;    type when Emacs is idle.
73 ;;
74 ;;
75 ;;  Faces defined here:
76 ;;
77 ;;    `hl-line'.
78 ;;
79 ;;  User options defined here:
80 ;;
81 ;;    `hl-line-flash-show-period',
82 ;;    `hl-line-inhibit-highlighting-for-modes'.
83 ;;
84 ;;  Commands defined here:
85 ;;
86 ;;    `flash-line-highlight', `hl-line-flash',
87 ;;    `hl-line-toggle-when-idle', `hl-line-when-idle-interval',
88 ;;    `toggle-hl-line-when-idle'.
89 ;;
90 ;;  Non-interactive functions defined here:
91 ;;
92 ;;    `hl-line-highlight-now', `hl-line-unhighlight-now'.
93 ;;
94 ;;  Internal variables defined here:
95 ;;
96 ;;    `hl-line-idle-interval', `hl-line-idle-timer',
97 ;;    `hl-line-when-idle-p'.
98 ;;
99 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
100 ;; 
101 ;;; Change log:
102 ;;
103 ;; 2011/01/04 dadams
104 ;;     Added autoload cookies for defcustom, defface and commands.
105 ;; 2010/10/03 dadams
106 ;;     hl-line-flash:
107 ;;       Set ARG in interactive spec and use it.  Thx to Philip Weaver.
108 ;; 2009/12/18 dadams
109 ;;     Added: hl-line-inhibit-highlighting-for-modes.
110 ;;     hl-line-highlight-now: Respect hl-line-inhibit-for-modes.  Thx to Sylecn.
111 ;; 2009/02/16 dadams
112 ;;     Removed spotlight stuff - moved to new library hl-spotlight.el.
113 ;; 2009/02/15 dadams
114 ;;     Added: hl-spotlight(-height|-old-state|widen|limits|mode),
115 ;;            global-hl-spotlight-mode.
116 ;; 2008/01/28 dadams
117 ;;     Fix from Yann Yodique: Moved adding/removing hl-line-unhighlight-now as
118 ;;     pre-command-hook from hl-line-toggle-when-idle to hl-line-(un)highlight-now.
119 ;; 2008/01/20 dadams
120 ;;     Renamed: line-show-period to hl-line-flash-show-period.
121 ;; 2007/10/11 dadams
122 ;;     Commentary typo: toggle-cursor-type-when-idle -> toggle-hl-line-when-idle.
123 ;; 2007/01/10 dadams
124 ;;     Update commentary to indicate that the face is now provided by default.
125 ;; 2006/09/08 dadams
126 ;;     Added: flash-line-highlight, hl-line-flash.
127 ;;     Renamed: hl-line-when-idle(-off) to hl-line-(un)highlight-now.
128 ;; 2006/09/04 dadams
129 ;;     Added: hl-line-when-idle-p, hl-line-idle-interval, hl-line-idle-timer,
130 ;;            hl-line-toggle-when-idle, hl-line-when-idle-interval,
131 ;;            hl-line-when-idle(-off).
132 ;;
133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
134 ;; 
135 ;; This program is free software; you can redistribute it and/or
136 ;; modify it under the terms of the GNU General Public License as
137 ;; published by the Free Software Foundation; either version 3, or
138 ;; (at your option) any later version.
139 ;; 
140 ;; This program is distributed in the hope that it will be useful,
141 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
142 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
143 ;; General Public License for more details.
144 ;; 
145 ;; You should have received a copy of the GNU General Public License
146 ;; along with this program; see the file COPYING.  If not, write to
147 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
148 ;; Floor, Boston, MA 02110-1301, USA.
149 ;; 
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
151 ;; 
152 ;;; Code:
153
154 (require 'hl-line)
155
156 (defvar hl-line-face)                   ; Quiet the byte-compiler.
157 (defvar global-hl-line-mode)            ; Quiet the byte-compiler.
158
159 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
160
161 ;; This will be ignored, since this is now defined by default in Emacs 22.
162 ;; I include it here as a different face definition that you might want to try.
163 ;;;###autoload
164 (defface hl-line '((t (:background "SlateGray3"))) ; Try also (:underline "Yellow")
165   "*Face to use for `hl-line-face'." :group 'hl-line)
166 (setq hl-line-face 'hl-line)
167
168 ;;;###autoload
169 (defcustom hl-line-flash-show-period 1
170   "*Number of seconds for `hl-line-flash' to highlight the line."
171   :type 'integer :group 'cursor :group 'hl-line)
172
173 ;; Possible value: `(Info-mode help-mode view-mode Man-mode)'
174 ;;;###autoload
175 (defcustom hl-line-inhibit-highlighting-for-modes ()
176   "*Modes where highlighting is inhibited for `hl-line-highlight-now'.
177 A list of `major-mode' values (symbols)."
178   :type 'list :group 'hl-line)
179
180 (defvar hl-line-idle-interval 5
181   "Number of seconds to wait before turning on `global-hl-line-mode'.
182 Do NOT change this yourself to change the wait period; instead, use
183 `\\[hl-line-when-idle-interval]'.")
184
185 (defvar hl-line-idle-timer
186   (progn                                ; Cancel to prevent duplication.
187     (when (boundp 'hl-line-idle-timer) (cancel-timer hl-line-idle-timer))
188     (run-with-idle-timer hl-line-idle-interval t 'hl-line-highlight-now))
189   "Timer used to turn on `global-hl-line-mode' whenever Emacs is idle.")
190
191 ;; Turn it off, by default.  You must use `toggle-hl-line-when-idle' to turn it on.
192 (cancel-timer hl-line-idle-timer)
193
194 (defvar hl-line-when-idle-p nil
195   "Non-nil means to turn on `global-hl-line-mode' whenever Emacs is idle.
196 Do NOT change this yourself; instead, use `\\[toggle-hl-line-when-idle]'.")
197
198 ;;;###autoload
199 (defalias 'toggle-hl-line-when-idle 'hl-line-toggle-when-idle)
200 ;;;###autoload
201 (defun hl-line-toggle-when-idle (&optional arg)
202   "Turn on or off using `global-hl-line-mode' when Emacs is idle.
203 When on, use `global-hl-line-mode' whenever Emacs is idle.
204 With prefix argument, turn on if ARG > 0; else turn off."
205   (interactive "P")
206   (setq hl-line-when-idle-p
207         (if arg (> (prefix-numeric-value arg) 0) (not hl-line-when-idle-p)))
208   (cond (hl-line-when-idle-p
209          (timer-activate-when-idle hl-line-idle-timer)
210          (message "Turned ON using `global-hl-line-mode' when Emacs is idle."))
211         (t
212          (cancel-timer hl-line-idle-timer)
213          (message "Turned OFF using `global-hl-line-mode' when Emacs is idle."))))
214
215 ;;;###autoload
216 (defun hl-line-when-idle-interval (secs)
217   "Set wait until using `global-hl-line-mode' when Emacs is idle.
218 Whenever Emacs is idle for this many seconds, `global-hl-line-mode'
219 will be turned on.
220
221 To turn on or off using `global-hl-line-mode' when idle,
222 use `\\[toggle-hl-line-when-idle]."
223   (interactive "nSeconds to idle, before using `global-hl-line-mode': ")
224   (timer-set-idle-time hl-line-idle-timer (setq hl-line-idle-interval secs) t))
225
226 (defun hl-line-highlight-now ()
227   "Turn on `global-hl-line-mode' and highlight current line now."
228   (unless (or global-hl-line-mode
229               (member major-mode hl-line-inhibit-highlighting-for-modes))
230     (global-hl-line-mode 1)
231     (global-hl-line-highlight)
232     (add-hook 'pre-command-hook 'hl-line-unhighlight-now)))
233     
234 (defun hl-line-unhighlight-now ()
235   "Turn off `global-hl-line-mode' and unhighlight current line now."
236   (global-hl-line-mode -1)
237   (global-hl-line-unhighlight)
238   (remove-hook 'pre-command-hook 'hl-line-unhighlight-now))
239
240 ;;;###autoload
241 (defalias 'flash-line-highlight 'hl-line-flash)
242 ;;;###autoload
243 (defun hl-line-flash (&optional arg)
244   "Highlight the current line for `hl-line-flash-show-period' seconds.
245 With a prefix argument, highlight for that many seconds."
246   (interactive "P")
247   (hl-line-highlight-now)
248   (let ((line-period  hl-line-flash-show-period))
249     (when arg (setq line-period  (prefix-numeric-value arg)))
250     (run-at-time line-period nil #'hl-line-unhighlight-now)))
251
252 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
253
254 (provide 'hl-line+)
255
256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
257 ;;; hl-line+.el ends here