all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: taylanbayirli@gmail.com, emacs-devel@gnu.org
Subject: RE: [PATCH] Add idle-cursor-morph.
Date: Sun, 18 Oct 2015 09:00:34 -0700 (PDT)	[thread overview]
Message-ID: <1a53f340-60a0-43d4-b168-09fffcc8b187@default> (raw)
In-Reply-To: <876124ryoz.fsf@T420.taylan>

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



  reply	other threads:[~2015-10-18 16:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-18 15:19 [PATCH] Add idle-cursor-morph Taylan Ulrich Bayırlı/Kammer
2015-10-18 16:00 ` Drew Adams [this message]
2015-10-18 16:39   ` Taylan Ulrich Bayırlı/Kammer
2015-10-18 16:17 ` John Wiegley
2015-10-19  1:47   ` 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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1a53f340-60a0-43d4-b168-09fffcc8b187@default \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=taylanbayirli@gmail.com \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.