annotate lisp/packages/blink-cursor.el @ 147:e186c2b7192d xemacs-20-2

Added tag r20-2p1 for changeset 2af401a6ecca
author cvs
date Mon, 13 Aug 2007 09:34:48 +0200
parents 0d2f883870bc
children 8eaf7971accc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; blink-cursor.el --- Blink the cursor on or off
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Keywords: display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
20 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
22 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (defvar blink-cursor-last-selected-window nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (defvar blink-cursor-lost-focus nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (defun blink-cursor-callback (foo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (let ((inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (window (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (if blink-cursor-lost-focus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (or blink-cursor-last-selected-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (setq blink-cursor-last-selected-window window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (if (eq window blink-cursor-last-selected-window)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
41
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
42 (if (specifier-instance text-cursor-visible-p window)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
43 (if (let ((current-time (current-time)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
44 (or (> (car current-time) (car last-input-time))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
45 (> (cadr current-time) (cdr last-input-time))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
46 ;; turn cursor off only if more than a second since
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
47 ;; last input
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
48 (set-specifier text-cursor-visible-p nil window))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
49 (set-specifier text-cursor-visible-p t window))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
50
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (remove-specifier text-cursor-visible-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 blink-cursor-last-selected-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (setq blink-cursor-last-selected-window window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (set-specifier text-cursor-visible-p nil window)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
56 ; Turn on cursor after every command
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
57 (defun blink-cursor-post-command-hook ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
58 (let ((inhibit-quit t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
59 (window (selected-window)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
60 (if blink-cursor-lost-focus
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
61 nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
62 (set-specifier text-cursor-visible-p t window))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
63
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (defun blink-cursor-reenable-cursor ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (if blink-cursor-last-selected-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (remove-specifier text-cursor-visible-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 blink-cursor-last-selected-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (setq blink-cursor-last-selected-window nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (defun blink-cursor-deselect-frame-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (blink-cursor-reenable-cursor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (setq blink-cursor-lost-focus t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (defun blink-cursor-select-frame-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (setq blink-cursor-lost-focus nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (add-hook 'deselect-frame-hook 'blink-cursor-deselect-frame-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (add-hook 'select-frame-hook 'blink-cursor-select-frame-hook)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
80 (add-hook 'post-command-hook 'blink-cursor-post-command-hook)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (defvar blink-cursor-timeout 1.0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (defvar blink-cursor-timeout-id nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defvar blink-cursor-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (defun blink-cursor-mode (&optional timeout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 "Enable or disable a blinking cursor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 If TIMEOUT is nil, toggle on or off.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 If TIMEOUT is t, enable with the previous timeout value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 If TIMEOUT is 0, disable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 If TIMEOUT is greater than 0, then the cursor will blink once
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 each TIMEOUT secs (can be a float)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (cond ((not timeout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (setq timeout blink-cursor-timeout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (setq blink-cursor-mode (not blink-cursor-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ((eq timeout t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (setq timeout blink-cursor-timeout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (setq blink-cursor-mode t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ((<= timeout 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (setq blink-cursor-mode nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (setq blink-cursor-timeout timeout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (setq blink-cursor-mode t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (if blink-cursor-timeout-id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (disable-timeout blink-cursor-timeout-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (blink-cursor-reenable-cursor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (setq blink-cursor-timeout-id nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (if blink-cursor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (setq blink-cursor-timeout-id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (add-timeout (/ (float timeout) 2) 'blink-cursor-callback nil
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
114 (/ (float timeout) 2))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
115 ; initialize last-input-time
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
116 (if (not last-input-time)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
117 (setq last-input-time (cons 0 0))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
118
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
119 (provide 'blink-cursor)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
120
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
121 ;;; blink-cursor.el ends here