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