unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* highlight current line when Emacs is idle
@ 2006-09-04 18:04 Drew Adams
  2006-09-05  6:47 ` Drew Adams
  2007-07-13 14:16 ` Drew Adams
  0 siblings, 2 replies; 10+ messages in thread
From: Drew Adams @ 2006-09-04 18:04 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: highlight current line when Emacs is idle
  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
  2007-07-13 14:16 ` Drew Adams
  1 sibling, 1 reply; 10+ messages in thread
From: Drew Adams @ 2006-09-05  6:47 UTC (permalink / raw)


    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.

A follow-on to that follow-on: Perhaps optionally highlight the current
column as well.

I use code in Rick Bielawski's library column-marker.el to do this.
Highlighting (faintly) both the current line and column provides a
cross-hairs effect that makes the cursor very easy to locate.

One use of this might be for better accessibility for people who are
visually impaired. I use an idle timer of several seconds for this myself,
but setting the timer interval to zero gives a pair of cross hairs as wide
and high as the buffer that track the cursor continually.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: highlight current line when Emacs is idle
  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
  0 siblings, 2 replies; 10+ messages in thread
From: Masatake YAMATO @ 2006-09-05  7:15 UTC (permalink / raw)
  Cc: emacs-devel

(I know we are in pretest stage.)

> A follow-on to that follow-on: Perhaps optionally highlight the current
> column as well.

How about this one?

;;; hl-column.el --- highlight the current column

;; Copyright 2004 2005 Masatake YAMATO
;;
;; Author: Masatake YAMATO<jet@gyve.org>
;; Keywords:
;; X-URL: not distributed yet

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

;;; Commentary:

;;  This is the column version of hl-line.el.
;;
;; Put this file into your load-path and the following into your ~/.emacs:
;;   (require 'hl-column)
;; then
;;   M-x hl-column-mode
;;
;; Next key binding is optional.
;;   (define-key global-map "\C-x|" 'hl-column-highlight)
;;
;; TODO
;; - Stocking the overlays

;;; Code:

(provide 'hl-column)
(eval-when-compile
  (require 'cl))

\f
;;;;##########################################################################
;;;;  User Options, Variables
;;;;##########################################################################
(defgroup hl-column nil
  "Highlight the current column."
  :group 'editing)

(defcustom hl-column-face 'highlight
  "Face with which to highlight the current column."
  :type 'face
  :group 'hl-column)

(defcustom hl-column-string nil
  "String to indicate the current column."
  :type '(choice (const  :tag "No overlay string" nil)
                 (const  :tag "Bar"               "|")
                 (string))
  :group 'hl-column)

(defcustom hl-column-accept-tab t
  "Highlight tab character or not.
Generally tab character takes wider area than the other."
  :type 'boolean
  :group 'hl-column)

;;;;##########################################################################
;;;;  Functions
;;;;##########################################################################
	
;; Requirement
;; line-number-at-pos
;; line-move-to-column

(defun hl-column-highlight (&optional column)
  "Highlight the current columns."
  (interactive "P")
  (let* ((start-line (line-number-at-pos (window-start)))
         (end-line   (line-number-at-pos (window-end)))
         (cc    (if column
                    (prefix-numeric-value column)
                  (current-column)))
         (goal-column cc)
         (p (point))
         l overlays overlay)
    (unwind-protect
        (progn
          (save-excursion
            (setq l (line-number-at-pos))
            (while (<= start-line l)
              (when (and
                     ;(not (zerop (current-column)))
                     (or (eq cc (current-column))
                         (and (< cc (current-column))
                              (< 1 (char-width (char-before)))
                              (prog1 t (goto-char (1- (point))))))
		     (or hl-column-accept-tab
			 (not (eq (char-after) ?\t)))
                     (not (eolp)))
                (setq overlay (make-overlay (point) (1+ (point)))
                      overlays (cons overlay overlays))
                (overlay-put overlay 'face hl-column-face)
                (when hl-column-string
                  (overlay-put overlay 'display hl-column-string)))
              (condition-case nil
                  (progn (previous-line 1)
                         (setq l (line-number-at-pos)))
                (error (setq l (1- start-line)))))
            (goto-char p)
            (while (<= (line-number-at-pos) end-line)
              (line-move-to-column cc)
              ;(move-to-column cc t)
              (when (and
                     ;(not (zerop (current-column)))
                     (or (eq cc (current-column))
                         (and (< cc (current-column))
                              (< 1 (char-width (char-before)))
                              (prog1 t (goto-char (1- (point))))))
                     (not (eq (char-after) ?\t))
                     (not (eolp)))
                (setq overlay (make-overlay (point) (1+ (point)))
                      overlays (cons overlay overlays))
                (overlay-put overlay 'face hl-column-face)
                (when hl-column-string
                    (overlay-put overlay 'display hl-column-string)))
              (when (or (< 0 (forward-line 1))
                        (eobp))
                (setq end-line -1))))
          (sit-for 99999))
      (mapc (lambda (o) (delete-overlay o)) overlays))))

(define-minor-mode hl-column-mode
  "Buffer-local minor mode to highlight the column about point."
  nil nil
  nil
  :group 'hl-column-mode
  (if hl-column-mode
      (add-hook 'post-command-hook 'hl-column-highlight nil t)
    (remove-hook 'post-command-hook 'hl-column-highlight t)))

;; arch-tag: 8d30b572-81a8-4b7b-acb5-d2f8a03ae6bf
;;; hl-column.el ends here

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: highlight current line when Emacs is idle
  2006-09-05  7:15   ` Masatake YAMATO
@ 2006-09-05 14:14     ` Drew Adams
  2006-09-06  8:50     ` Richard Stallman
  1 sibling, 0 replies; 10+ messages in thread
From: Drew Adams @ 2006-09-05 14:14 UTC (permalink / raw)


Yes, your code does some of what Rick Bielawski's library column-marker.el
does. If you are interested, his code is here:
http://www.emacswiki.org/cgi-bin/wiki/column-marker.el.

My suggestion was to use such a feature with an idle timer, to show the
column after a certain number of seconds. I use Rick's code to do that, but
your's should work as well.

    > A follow-on to that follow-on: Perhaps optionally highlight
    > the current column as well.

    How about this one?
    ;;; hl-column.el --- highlight the current column
    ;; Copyright 2004 2005 Masatake YAMATO
    ;;  This is the column version of hl-line.el.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: highlight current line when Emacs is idle
  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
  1 sibling, 2 replies; 10+ messages in thread
From: Richard Stallman @ 2006-09-06  8:50 UTC (permalink / raw)
  Cc: drew.adams, emacs-devel

What's the purpose of hl-column?
Once the current line is highlighted, it should be easy enough
to find the cursor within that line, since you have just one line
to search thru -- right?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: highlight current line when Emacs is idle
  2006-09-06  8:50     ` Richard Stallman
@ 2006-09-06  9:44       ` Masatake YAMATO
  2006-09-06 13:39       ` Drew Adams
  1 sibling, 0 replies; 10+ messages in thread
From: Masatake YAMATO @ 2006-09-06  9:44 UTC (permalink / raw)
  Cc: drew.adams, emacs-devel

> What's the purpose of hl-column?
> Once the current line is highlighted, it should be easy enough
> to find the cursor within that line, since you have just one line
> to search thru -- right?

Yes. hl-column is too much for finding the curusor.

Here after off topic.

hl-column is useful to check the column alignment of source code.

For example gtk+ project uses the column aligned coding style like:
----------------------------------------V------------------------
#define GTK_TYPE_WINDOW			(gtk_window_get_type ())
#define GTK_WINDOW(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WINDOW, GtkWindow))
#define GTK_WINDOW_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WINDOW, GtkWindowClass))
#define GTK_IS_WINDOW(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WINDOW))
#define GTK_IS_WINDOW_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WINDOW))
#define GTK_WINDOW_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WINDOW, GtkWindowClass))
----------------------------------------^------------------------

--------------------------------------V------------------------
typedef struct _GtkWindow             GtkWindow;
typedef struct _GtkWindowClass        GtkWindowClass;
typedef struct _GtkWindowGeometryInfo GtkWindowGeometryInfo;
typedef struct _GtkWindowGroup        GtkWindowGroup;
typedef struct _GtkWindowGroupClass   GtkWindowGroupClass;
--------------------------------------^------------------------

When you want to send a patch to gtk+ project, you may want to check
column alignment of your new code before sending. hl-column may be useful
such situation. 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: highlight current line when Emacs is idle
  2006-09-06  8:50     ` Richard Stallman
  2006-09-06  9:44       ` Masatake YAMATO
@ 2006-09-06 13:39       ` Drew Adams
  1 sibling, 0 replies; 10+ messages in thread
From: Drew Adams @ 2006-09-06 13:39 UTC (permalink / raw)


    What's the purpose of hl-column?
    Once the current line is highlighted, it should be easy enough
    to find the cursor within that line, since you have just one line
    to search thru -- right?

My suggestion was to (optionally) display the column, as well as the line,
when Emacs is idle. The aim was to save the trouble of searching through the
line, in particular for those with vision problems.

The library I mentioned, column-marker.el does what hl-column does
(highlights the current line), but it is more general. You can have any
number of highlighted columns (in different colors), and you can set the
column to highlight in various ways. It is easy to toggle highlighting of
any highlighted column or all such columns. One use is as a visual
line-length limit.

So, I can't answer for hl-column per se, but 1) my suggestion concerned idle
column highlighting and 2) column highlighting can be useful, generally,
beyond locating the cursor.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: highlight current line when Emacs is idle
  2006-09-04 18:04 highlight current line when Emacs is idle Drew Adams
  2006-09-05  6:47 ` Drew Adams
@ 2007-07-13 14:16 ` Drew Adams
  2007-07-13 15:13   ` Stefan Monnier
  1 sibling, 1 reply; 10+ messages in thread
From: Drew Adams @ 2007-07-13 14:16 UTC (permalink / raw)
  To: Emacs-Devel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: highlight current line when Emacs is idle
  2007-07-13 14:16 ` Drew Adams
@ 2007-07-13 15:13   ` Stefan Monnier
  2007-07-13 21:22     ` Drew Adams
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2007-07-13 15:13 UTC (permalink / raw)
  To: Drew Adams; +Cc: Emacs-Devel

>   (defface hl-line
> !     '((((class color) (min-colors 88) (background light)) :background
> "SlateGray3")
> !       (t :inherit highlight))

I think it is generally an error for a face to inherit in some cases and not
in others.

I.e. the above should be

  (defface hl-line
     '((default :inherit highlight)
       (((class color) (min-colors 88) (background light))
        :background "SlateGray3"))


-- Stefan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: highlight current line when Emacs is idle
  2007-07-13 15:13   ` Stefan Monnier
@ 2007-07-13 21:22     ` Drew Adams
  0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2007-07-13 21:22 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs-Devel

> >   (defface hl-line
> > !     '((((class color) (min-colors 88) (background light)) :background
> > "SlateGray3")
> > !       (t :inherit highlight))
>
> I think it is generally an error for a face to inherit in some
> cases and not in others.
>
> I.e. the above should be
>
>   (defface hl-line
>      '((default :inherit highlight)
>        (((class color) (min-colors 88) (background light))
>         :background "SlateGray3"))

You're probably right. And we probably need better default behavior for
non-light-bg color displays too.

(1) Ignorance - I wasn't aware of the guideline involving :inherit, and I
haven't used `default' before.

(2) Laziness - I threw together the face definition quickly to provide
something for the non-light background cases. All I use, myself, is the
light-bg case, so the rest is suspect.

Suggestions welcome. Likewise, for other faces. It's easier for people who
use dark backgrounds to propose something reasonable - likewise for
non-color.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2007-07-13 21:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2007-07-13 15:13   ` Stefan Monnier
2007-07-13 21:22     ` Drew Adams

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).