[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: change cursor type when idle
From: |
Kim F. Storm |
Subject: |
Re: change cursor type when idle |
Date: |
Mon, 28 Aug 2006 11:54:08 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
"Drew Adams" <address@hidden> writes:
> Another possible (minor) feature to consider for after the release: As an
> option, let users switch cursor type automatically when Emacs is idle.
>
> I've been using this for a while, and I like it. I like a bar cursor for
> editing, but the bar cursor is hard to locate, when I'm not already looking
> at it or near it. So, I use an idle timer to change it to a (blinking) box
> cursor while Emacs is idle. I find this helps quite a bit - without it, it's
> hard to use a bar cursor, IMO.
>
> Users can choose not to use this, and they can toggle it on and off. They
> can also change the number of seconds to wait before the automatic
> cursor-type change (2 sec, by default).
Brilliant idea!
Here's one way to do it.
If people don't like a blinking cursor normally, they just have to define
blink-cursor-delay to the same value as blink-cursor-idle-cursor-delay.
*** frame.el 22 Aug 2006 08:59:52 +0200 1.239
--- frame.el 28 Aug 2006 11:49:02 +0200
***************
*** 1244,1249 ****
--- 1244,1259 ----
:type 'number
:group 'cursor)
+ (defcustom blink-cursor-idle-cursor-delay 5.0
+ "*Seconds of idle time after which cursor changes shape."
+ :type 'number
+ :group 'cursor)
+
+ (defcustom blink-cursor-idle-cursor-type 'box
+ "*Type of cursor which idle cursor changes shape into."
+ :type 'number
+ :group 'cursor)
+
(defvar blink-cursor-idle-timer nil
"Timer started after `blink-cursor-delay' seconds of Emacs idle time.
The function `blink-cursor-start' is called when the timer fires.")
***************
*** 1253,1258 ****
--- 1263,1271 ----
This timer calls `blink-cursor-timer-function' every
`blink-cursor-interval' seconds.")
+ (defvar blink-cursor-saved-cursor-type nil
+ "Saved type of cursor if changed.")
+
(defun blink-cursor-start ()
"Timer function called from the timer `blink-cursor-idle-timer'.
This starts the timer `blink-cursor-timer', which makes the cursor blink
***************
*** 1261,1267 ****
(when (null blink-cursor-timer)
;; Set up the timer first, so that if this signals an error,
;; blink-cursor-end is not added to pre-command-hook.
! (setq blink-cursor-timer
(run-with-timer blink-cursor-interval blink-cursor-interval
'blink-cursor-timer-function))
(add-hook 'pre-command-hook 'blink-cursor-end)
--- 1274,1281 ----
(when (null blink-cursor-timer)
;; Set up the timer first, so that if this signals an error,
;; blink-cursor-end is not added to pre-command-hook.
! (setq blink-cursor-saved-cursor-type nil
! blink-cursor-timer
(run-with-timer blink-cursor-interval blink-cursor-interval
'blink-cursor-timer-function))
(add-hook 'pre-command-hook 'blink-cursor-end)
***************
*** 1269,1274 ****
--- 1283,1296 ----
(defun blink-cursor-timer-function ()
"Timer function of timer `blink-cursor-timer'."
+ (if (and (not blink-cursor-saved-cursor-type)
+ blink-cursor-idle-cursor-type
+ (not (equal cursor-type blink-cursor-idle-cursor-type))
+ (numberp blink-cursor-idle-cursor-delay)
+ (>= (float-time (or (current-idle-time) '(0 0)))
+ blink-cursor-idle-cursor-delay))
+ (setq blink-cursor-saved-cursor-type cursor-type
+ cursor-type blink-cursor-idle-cursor-type))
(internal-show-cursor nil (not (internal-show-cursor-p))))
(defun blink-cursor-end ()
***************
*** 1277,1282 ****
--- 1299,1308 ----
When run, it cancels the timer `blink-cursor-timer' and removes
itself as a pre-command hook."
(remove-hook 'pre-command-hook 'blink-cursor-end)
+ (when blink-cursor-saved-cursor-type
+ (if (eq blink-cursor-idle-cursor-type cursor-type)
+ (setq cursor-type blink-cursor-saved-cursor-type))
+ (setq blink-cursor-saved-cursor-type nil))
(internal-show-cursor nil t)
(when blink-cursor-timer
(cancel-timer blink-cursor-timer)
--
Kim F. Storm <address@hidden> http://www.cua.dk
- change cursor type when idle, Drew Adams, 2006/08/28
- Re: change cursor type when idle,
Kim F. Storm <=
- RE: change cursor type when idle, Drew Adams, 2006/08/28
- Re: change cursor type when idle, Lennart Borgman, 2006/08/28
- RE: change cursor type when idle, Drew Adams, 2006/08/28
- Re: change cursor type when idle, Lennart Borgman, 2006/08/28
- RE: change cursor type when idle, Drew Adams, 2006/08/28
- Re: change cursor type when idle, Juri Linkov, 2006/08/28
- RE: change cursor type when idle, Drew Adams, 2006/08/28
- Re: change cursor type when idle, Juri Linkov, 2006/08/29
- RE: change cursor type when idle, Drew Adams, 2006/08/29
- Re: change cursor type when idle, Mathias Dahl, 2006/08/29