From: "Drew Adams" <drew.adams@oracle.com>
To: "Emacs-Devel" <emacs-devel@gnu.org>
Subject: RE: highlight current line when Emacs is idle
Date: Fri, 13 Jul 2007 07:16:58 -0700 [thread overview]
Message-ID: <EIENLHALHGIMHGDOLMIMKEBNDDAA.drew.adams@oracle.com> (raw)
In-Reply-To: <MEEKKIABFKKDFJMPIOEBOELIDEAA.drew.adams@oracle.com>
I sent this last September. Here is a patch that lets you, as two
alternatives to the current hl-line feature:
* Turn on hl-line highlighting only when Emacs is idle.
* Turn on hl-line highlighting for only a few seconds, on demand.
The patch also changes the default value of face `hl-line' for light
backgrounds. Suggestions welcome for other backgrounds. In general, I don't
think `highlight' is a good default choice for this. Many people will make
`highlight' fairly bright, to, well, highlight, whereas the hl-line
highlighting should be somewhat subtle, IMO.
> From: Drew Adams Sent: Monday, September 04, 2006 11:04 AM
>
> This suggestion (for after the release) is a follow-on to my
> suggestion to change the cursor to a box when Emacs is idle in
> order to more easily spot it.
>
> Suggestion: Optionally turn on `global-hl-line-mode' and
> highlight the current line only when Emacs is idle. I use such an
> option in my code, and I find it useful, for the same reason that
> changing to a box cursor when idle is useful. I use a similar
> implementation for both (an input event ends the highlighting).
>
> I use a (configurable) idle-timer interval of several seconds -
> longer than the timer interval for the cursor-type change. I also
> use a less-obtrusive, yellow underline face for the highlighting
> (my background is light blue).
>
> My guess is that more people might find hl-line useful with this
> option added. The main reason some people don't like it is that
> it is very intrusive and can be distracting.
>
> In fact, I suspect that most people who use `global-hl-line-mode'
> (or `hl-line-mode') would prefer this idle-only highlighting:
> there is usually no need to continue highlighting the line after
> you have already noticed it.
Here is the patch.
---------------8<--------------------------------------
*** hl-line-CVS-2007-07-13.el Fri Jul 13 06:55:06 2007
--- hl-line-CVS-patched-2007-07-13.el Fri Jul 13 07:02:18 2007
***************
*** 77,83 ****
:group 'editing)
(defface hl-line
! '((t :inherit highlight))
"Default face for highlighting the current line in Hl-Line mode."
:version "22.1"
:group 'hl-line)
--- 77,84 ----
:group 'editing)
(defface hl-line
! '((((class color) (min-colors 88) (background light)) :background
"SlateGray3")
! (t :inherit highlight))
"Default face for highlighting the current line in Hl-Line mode."
:version "22.1"
:group 'hl-line)
***************
*** 104,109 ****
--- 105,114 ----
:version "22.1"
:group 'hl-line)
+ (defcustom line-show-period 1
+ "Number of seconds to highlight the current line."
+ :type 'integer :group 'cursor :group 'hl-line)
+
(defvar hl-line-range-function nil
"If non-nil, function to call to return highlight range.
The function of no args should return a cons cell; its car value
***************
*** 113,118 ****
--- 118,141 ----
This variable is expected to be made buffer-local by modes.")
+ (defvar hl-line-idle-interval 5
+ "Number of seconds to wait before turning on `global-hl-line-mode'.
+ Do NOT change this yourself to change the wait period; instead, use
+ `\\[hl-line-when-idle-interval]'.")
+
+ (defvar hl-line-idle-timer
+ (progn ; Cancel to prevent duplication.
+ (when (boundp 'hl-line-idle-timer) (cancel-timer hl-line-idle-timer))
+ (run-with-idle-timer hl-line-idle-interval t 'hl-line-highlight-now))
+ "Timer used to turn on `global-hl-line-mode' whenever Emacs is idle.")
+
+ ;; Turn it off, by default. You must use `toggle-hl-line-when-idle' to
turn it on.
+ (cancel-timer hl-line-idle-timer)
+
+ (defvar hl-line-when-idle-p nil
+ "Non-nil means to use turn on `global-hl-line-mode' whenever Emacs is
idle.
+ Do NOT change this yourself; instead, use
`\\[toggle-hl-line-when-idle]'.")
+
;;;###autoload
(define-minor-mode hl-line-mode
"Buffer-local minor mode to highlight the line about point.
***************
*** 209,214 ****
--- 232,288 ----
(move-overlay overlay b e)
(move-overlay overlay 1 1))))
+ (defalias 'toggle-hl-line-when-idle 'hl-line-toggle-when-idle)
+ (defun hl-line-toggle-when-idle (&optional arg)
+ "Turn on or off using `global-hl-line-mode' when Emacs is idle.
+ When on, use `global-hl-line-mode' whenever Emacs is idle.
+ With prefix argument, turn on if ARG > 0; else turn off."
+ (interactive "P")
+ (setq hl-line-when-idle-p
+ (if arg (> (prefix-numeric-value arg) 0) (not
hl-line-when-idle-p)))
+ (cond (hl-line-when-idle-p
+ (timer-activate-when-idle hl-line-idle-timer)
+ (add-hook 'pre-command-hook 'hl-line-unhighlight-now)
+ (message "Turned ON using `global-hl-line-mode' when Emacs is
idle."))
+ (t
+ (cancel-timer hl-line-idle-timer)
+ (remove-hook 'pre-command-hook 'hl-line-unhighlight-now)
+ (message "Turned OFF using `global-hl-line-mode' when Emacs is
idle."))))
+
+ (defun hl-line-when-idle-interval (secs)
+ "Set wait until using `global-hl-line-mode' when Emacs is idle.
+ Whenever Emacs is idle for this many seconds, `global-hl-line-mode'
+ will be turned on.
+
+ To turn on or off using `global-hl-line-mode' when idle,
+ use `\\[toggle-hl-line-when-idle]."
+ (interactive "nSeconds to idle, before using `global-hl-line-mode': ")
+ (timer-set-idle-time hl-line-idle-timer
+ (setq hl-line-idle-interval secs)
+ t))
+
+ (defun hl-line-highlight-now ()
+ "Turn on `global-hl-line-mode' and highlight current line now."
+ (unless global-hl-line-mode
+ (global-hl-line-mode 1)
+ (global-hl-line-highlight)))
+
+ (defun hl-line-unhighlight-now ()
+ "Turn off `global-hl-line-mode' and unhighlight current line now."
+ (global-hl-line-mode -1)
+ (global-hl-line-unhighlight))
+
+ (defalias 'flash-line-highlight 'hl-line-flash)
+ (defun hl-line-flash (&optional arg)
+ "Highlight the current line for `line-show-period' seconds.
+ With a prefix argument, highlight for that many seconds."
+ (interactive)
+ (hl-line-highlight-now)
+ (let ((line-period line-show-period))
+ (when current-prefix-arg
+ (setq line-period (prefix-numeric-value current-prefix-arg)))
+ (run-at-time line-period nil #'hl-line-unhighlight-now)))
+
(provide 'hl-line)
;;; arch-tag: ac806940-0876-4959-8c89-947563ee2833
next prev parent reply other threads:[~2007-07-13 14:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-04 18:04 highlight current line when Emacs is idle Drew Adams
2006-09-05 6:47 ` Drew Adams
2006-09-05 7:15 ` Masatake YAMATO
2006-09-05 14:14 ` Drew Adams
2006-09-06 8:50 ` Richard Stallman
2006-09-06 9:44 ` Masatake YAMATO
2006-09-06 13:39 ` Drew Adams
2007-07-13 14:16 ` Drew Adams [this message]
2007-07-13 15:13 ` Stefan Monnier
2007-07-13 21:22 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=EIENLHALHGIMHGDOLMIMKEBNDDAA.drew.adams@oracle.com \
--to=drew.adams@oracle.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).