emacs-devel
[Top][All Lists]
Advanced

[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 23:44:06 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

address@hidden (Kim F. Storm) writes:

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

Here is a version that does this correctly.

If people just wants the cursor type to change after, say, 3 seconds, but
don't want a blinking cursor, do:

(setq cursor-type 'bar
      blink-cursor-delay 3.0
      blink-cursor-idle-cursor-delay blink-cursor-delay
      blink-cursor-interval 10e7)
      


*** frame.el    22 Aug 2006 08:59:52 +0200      1.239
--- frame.el    28 Aug 2006 23:37:26 +0200      
***************
*** 1244,1249 ****
--- 1244,1261 ----
    :type 'number
    :group 'cursor)
  
+ (defcustom blink-cursor-idle-cursor-delay 5.0
+   "*Seconds of idle time after which cursor changes shape."
+   :type 'number
+   :version "22.1"
+   :group 'cursor)
+ 
+ (defcustom blink-cursor-idle-cursor-type 'box
+   "*Type of cursor which idle cursor changes shape into."
+   :type 'number
+   :version "22.1"
+   :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 ****
--- 1265,1273 ----
  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,1275 ****
    (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)
!     (internal-show-cursor nil nil)))
  
! (defun blink-cursor-timer-function ()
    "Timer function of timer `blink-cursor-timer'."
!   (internal-show-cursor nil (not (internal-show-cursor-p))))
  
  (defun blink-cursor-end ()
    "Stop cursor blinking.
--- 1276,1299 ----
    (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 t))
      (add-hook 'pre-command-hook 'blink-cursor-end)
!     (blink-cursor-timer-function nil)))
  
! (defun blink-cursor-timer-function (&optional toggle)
    "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 (and toggle (not (internal-show-cursor-p))))))
  
  (defun blink-cursor-end ()
    "Stop cursor blinking.
***************
*** 1277,1282 ****
--- 1301,1310 ----
  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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]