[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [PATCH] Add idle-cursor-morph.
From: |
Drew Adams |
Subject: |
RE: [PATCH] Add idle-cursor-morph. |
Date: |
Sun, 18 Oct 2015 09:00:34 -0700 (PDT) |
> This is for ELPA.
>
> Admittedly this is pretty hacky, but it has worked for me since ages.
>
> It also has a bug I have no idea how to chase: every once in a blue moon
> it will fail to restore the cursor color. I'm guessing it's probably a
> bug in Emacs since the implementation is so simple and restoring the
> style works, but don't know really.
FWIW, this has been in my code (in `oneonone.el') since 2006.
(I haven't come across that blue-moon problem, BTW.)
---
(defun 1on1-toggle-box-cursor-when-idle (&optional arg)
"Turn on or off automatically changing to a box cursor when idle.
When on, the cursor is changed to a box whenever Emacs is idle.
With prefix argument, turn on if ARG > 0; else turn off."
(interactive "P")
(setq 1on1-box-cursor-when-idle-p
(if arg
(> (prefix-numeric-value arg) 0)
(not 1on1-box-cursor-when-idle-p)))
(cond (1on1-box-cursor-when-idle-p
(timer-activate-when-idle 1on1-box-cursor-when-idle-timer)
(add-hook 'pre-command-hook '1on1-box-cursor-when-idle-off)
(message "Turned ON making cursor a box when Emacs is idle."))
(t
(cancel-timer 1on1-box-cursor-when-idle-timer)
(remove-hook 'pre-command-hook '1on1-box-cursor-when-idle-off)
(message "Turned OFF making cursor a box when Emacs is idle."))))
(defun 1on1-set-cursor-type (cursor-type)
"Set the cursor type of the selected frame to CURSOR-TYPE.
When called interactively, prompt for the type to use.
To get the frame's current cursor type, use `frame-parameters'."
(interactive
(list (intern (completing-read
"Cursor type: "
(mapcar 'list '("box" "hollow" "bar" "hbar" nil))))))
(modify-frame-parameters (selected-frame)
(list (cons 'cursor-type cursor-type))))
(defun 1on1-box-cursor-when-idle ()
"Change the cursor to a box cursor when Emacs is idle."
(let ((type (cdr (assoc 'cursor-type (frame-parameters)))))
(unless (eq type 'box)
(setq 1on1-last-cursor-type type)
(1on1-set-cursor-type 'box))))
(defun 1on1-box-cursor-when-idle-off ()
"Turn off changing the cursor to a box cursor when Emacs is idle."
(when 1on1-last-cursor-type
(1on1-set-cursor-type 1on1-last-cursor-type)))
(defvar 1on1-box-cursor-when-idle-p t
"Non-nil means to use a box cursor whenever Emacs is idle.
Do NOT change this yourself; instead, use \
`\\[1on1-toggle-box-cursor-when-idle]'.")
(defvar 1on1-box-cursor-when-idle-interval 2
"Number of seconds to wait before changing cursor type to box.
Do NOT change this yourself to change the wait period; instead, use
`\\[1on1-set-box-cursor-when-idle-interval]'.")
(defvar 1on1-box-cursor-when-idle-timer
(progn
(when (boundp '1on1-box-cursor-when-idle-timer)
(cancel-timer 1on1-box-cursor-when-idle-timer))
(run-with-idle-timer 1on1-box-cursor-when-idle-interval t
'1on1-box-cursor-when-idle))
"Timer used to change the cursor to a box cursor when Emacs is idle.")
(cancel-timer 1on1-box-cursor-when-idle-timer)