From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: change cursor type when idle Date: Mon, 28 Aug 2006 11:54:08 +0200 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1156759135 8183 80.91.229.2 (28 Aug 2006 09:58:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 28 Aug 2006 09:58:55 +0000 (UTC) Cc: Emacs-Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 28 11:58:46 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GHdtC-0003RV-AG for ged-emacs-devel@m.gmane.org; Mon, 28 Aug 2006 11:58:42 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GHdtB-00059P-W7 for ged-emacs-devel@m.gmane.org; Mon, 28 Aug 2006 05:58:42 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GHdpy-0002zG-Ti for emacs-devel@gnu.org; Mon, 28 Aug 2006 05:55:22 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GHdpx-0002yO-Tb for emacs-devel@gnu.org; Mon, 28 Aug 2006 05:55:22 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GHdpx-0002yF-N7 for emacs-devel@gnu.org; Mon, 28 Aug 2006 05:55:21 -0400 Original-Received: from [195.41.46.235] (helo=pfepa.post.tele.dk) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GHdys-0001gS-PE for emacs-devel@gnu.org; Mon, 28 Aug 2006 06:04:35 -0400 Original-Received: from kfs-l.imdomain.dk.cua.dk (unknown [80.165.4.124]) by pfepa.post.tele.dk (Postfix) with SMTP id 2093DFAC055; Mon, 28 Aug 2006 11:55:19 +0200 (CEST) Original-To: "Drew Adams" In-Reply-To: (Drew Adams's message of "Mon, 28 Aug 2006 00:48:10 -0700") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:58983 Archived-At: "Drew Adams" 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 http://www.cua.dk