all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Add idle-cursor-morph.
@ 2015-10-18 15:19 Taylan Ulrich Bayırlı/Kammer
  2015-10-18 16:00 ` Drew Adams
  2015-10-18 16:17 ` John Wiegley
  0 siblings, 2 replies; 5+ messages in thread
From: Taylan Ulrich Bayırlı/Kammer @ 2015-10-18 15:19 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 341 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-idle-cursor-morph.patch --]
[-- Type: text/x-diff, Size: 4500 bytes --]

From 64d1d46fd3a393cea8922661bc809012f50da301 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Taylan=20Ulrich=20Bay=C4=B1rl=C4=B1/Kammer?=
 <taylanbayirli@gmail.com>
Date: Sun, 18 Oct 2015 17:12:12 +0200
Subject: [PATCH] Add idle-cursor-morph.

---
 packages/idle-cursor-morph/idle-cursor-morph.el | 115 ++++++++++++++++++++++++
 1 file changed, 115 insertions(+)
 create mode 100644 packages/idle-cursor-morph/idle-cursor-morph.el

diff --git a/packages/idle-cursor-morph/idle-cursor-morph.el b/packages/idle-cursor-morph/idle-cursor-morph.el
new file mode 100644
index 0000000..a1deb5e
--- /dev/null
+++ b/packages/idle-cursor-morph/idle-cursor-morph.el
@@ -0,0 +1,115 @@
+;;; idle-cursor-morph.el --- Morph cursor when idle.
+
+;; Copyright (C) 2015  Free Software Foundation, Inc.
+
+;; Author: Taylan Ulrich B. <taylanbayirli@gmail.com>
+;; Keywords: convenience
+
+;; 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Change the cursor appearance after a certain time of inactivity, so it is
+;; easier to find after a pause or distraction.
+;;
+;; You can configure the parameters via the Customize system.
+
+;;; Code:
+
+(defgroup idle-cursor-morph nil
+  "Morph cursor when idle."
+  :group 'convenience)
+
+(defcustom idle-cursor-timeout 20
+  "Seconds to wait before morphing the cursor.
+
+After setting this, run `idle-cursor-activate' to apply the new
+value."
+  :type 'number
+  :group 'idle-cursor-morph)
+
+(defcustom idle-cursor-color "red"
+  "Color of cursor when idle."
+  :type 'string
+  :group 'idle-cursor-morph)
+
+(defcustom idle-cursor-non-idle-color "white"
+  "Color of cursor when not idle."
+  :type 'string
+  :group 'idle-cursor-morph)
+
+(defcustom idle-cursor-type 'box
+  "Type of cursor when idle."
+  :type '(choice (const t)
+                 (const nil)
+                 (const box)
+                 (cons (const bar) number)
+                 (const hbar)
+                 (cons (const hbar) number))
+  :group 'idle-cursor-morph)
+
+(defcustom idle-cursor-non-idle-type cursor-type
+  "Type of cursor when not idle."
+  :type '(choice (const t)
+                 (const nil)
+                 (const box)
+                 (cons (const bar) number)
+                 (const hbar)
+                 (cons (const hbar) number))
+  :group 'idle-cursor-morph)
+
+(defcustom idle-cursor-blinking (not no-blinking-cursor)
+  "Whether the cursor should blink when idle."
+  :type 'boolean
+  :group 'idle-cursor-morph)
+
+(defcustom idle-cursor-non-idle-blinking (not no-blinking-cursor)
+  "Whether the cursor should blink when not idle.")
+
+(defun idle-cursor-morph ()
+  "Set the cursor color and type to `idle-cursor-color' and
+`idle-cursor-type', respectively."
+  (set-cursor-color idle-cursor-color)
+  (setq-default cursor-type idle-cursor-type)
+  (setq no-blinking-cursor (not idle-cursor-blinking))
+  (add-hook 'post-command-hook 'idle-cursor-restore))
+
+(defun idle-cursor-restore ()
+  "Restore the cursor color and type to the values they had
+before `idle-cursor-morph' changed them."
+  (set-cursor-color idle-cursor-non-idle-color)
+  (setq-default cursor-type idle-cursor-non-idle-type)
+  (setq no-blinking-cursor (not idle-cursor-non-idle-blinking))
+  (remove-hook 'post-command-hook 'idle-cursor-restore))
+
+(defvar idle-cursor-morph-timer nil)
+
+(defun idle-cursor-activate ()
+  "Activate the idle-cursor-morphing functionality."
+  (interactive)
+  (if idle-cursor-morph-timer
+      (idle-cursor-deactivate))
+  (setq idle-cursor-morph-timer
+        (run-with-idle-timer idle-cursor-timeout t 'idle-cursor-morph)))
+
+(defun idle-cursor-deactivate ()
+  "Deactivate the idle-cursor-morphing functionality."
+  (interactive)
+  (if idle-cursor-morph-timer
+      (cancel-timer idle-cursor-morph-timer)))
+
+(idle-cursor-activate)
+
+(provide 'idle-cursor-morph)
+;;; idle-cursor-morph.el ends here
-- 
2.5.0


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

* RE: [PATCH] Add idle-cursor-morph.
  2015-10-18 15:19 [PATCH] Add idle-cursor-morph Taylan Ulrich Bayırlı/Kammer
@ 2015-10-18 16:00 ` Drew Adams
  2015-10-18 16:39   ` Taylan Ulrich Bayırlı/Kammer
  2015-10-18 16:17 ` John Wiegley
  1 sibling, 1 reply; 5+ messages in thread
From: Drew Adams @ 2015-10-18 16:00 UTC (permalink / raw)
  To: taylanbayirli, emacs-devel

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



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

* Re: [PATCH] Add idle-cursor-morph.
  2015-10-18 15:19 [PATCH] Add idle-cursor-morph Taylan Ulrich Bayırlı/Kammer
  2015-10-18 16:00 ` Drew Adams
@ 2015-10-18 16:17 ` John Wiegley
  2015-10-19  1:47   ` Drew Adams
  1 sibling, 1 reply; 5+ messages in thread
From: John Wiegley @ 2015-10-18 16:17 UTC (permalink / raw)
  To: emacs-devel

>>>>> Taylan Ulrich "Bayırlı/Kammer" <taylanbayirli@gmail.com> writes:

> Admittedly this is pretty hacky, but it has worked for me since ages.

Have you seen the module cursor-chg.el, by Drew Adams? It performs a similar
function and has been working well for me for many years.

John



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

* Re: [PATCH] Add idle-cursor-morph.
  2015-10-18 16:00 ` Drew Adams
@ 2015-10-18 16:39   ` Taylan Ulrich Bayırlı/Kammer
  0 siblings, 0 replies; 5+ messages in thread
From: Taylan Ulrich Bayırlı/Kammer @ 2015-10-18 16:39 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel

Drew Adams <drew.adams@oracle.com> writes:

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

Oh, cool, I'll look into it.

Taylan



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

* RE: [PATCH] Add idle-cursor-morph.
  2015-10-18 16:17 ` John Wiegley
@ 2015-10-19  1:47   ` Drew Adams
  0 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2015-10-19  1:47 UTC (permalink / raw)
  To: John Wiegley, emacs-devel

> Have you seen the module cursor-chg.el, by Drew Adams? It performs
> a similar function and has been working well for me for many years.

That's what I should have mentioned, instead of pointing to the
similar code in oneonone.el.  Thanks for the reminder.

I use oneonone.el, and I forgot (!) that I had broken that piece
of it out as a separate library, cursor-chg.el.  I could have
just pointed to that instead of inlining the relevant bits of code.

The Commentary of curseor-chg.el says this about that:

;;  Note: Library `oneonone.el' provides the same functionality as
;;  library `cursor-chg.el', and more.  If you use library
;;  `oneonone.el', then do NOT also use library `cursor-chg.el'.



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

end of thread, other threads:[~2015-10-19  1:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-18 15:19 [PATCH] Add idle-cursor-morph Taylan Ulrich Bayırlı/Kammer
2015-10-18 16:00 ` Drew Adams
2015-10-18 16:39   ` Taylan Ulrich Bayırlı/Kammer
2015-10-18 16:17 ` John Wiegley
2015-10-19  1:47   ` Drew Adams

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.