aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Stephani2016-09-10 10:16:32 +0200
committerPhilipp Stephani2016-10-02 19:49:37 +0200
commite0ac09906b68a6d96466fd12faf45a6e94f9ebbf (patch)
treef588ce3c8692e44e9f6468eff1bec4c9d2a5b235
parent08b386db1f4212ce90f726442fcf356885fb31ae (diff)
downloademacs-e0ac09906b68a6d96466fd12faf45a6e94f9ebbf.tar.gz
emacs-e0ac09906b68a6d96466fd12faf45a6e94f9ebbf.zip
Restart blink cursor timers on interval changes
This prevents surprising behavior when timer interval customizations are only applied whenever the timers happen to be restarted (see Bug#24372). * lisp/frame.el (blink-cursor--start-idle-timer) (blink-cursor--start-timer): New functions. (blink-cursor-start, blink-cursor-check, blink-cursor-mode): Use the new helper functions. (blink-cursor-delay, blink-cursor-interval): Restart timers when the value is changed.
-rw-r--r--lisp/frame.el49
1 files changed, 30 insertions, 19 deletions
diff --git a/lisp/frame.el b/lisp/frame.el
index d3b6353d2a2..ab3b722d993 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -2029,12 +2029,18 @@ widths."
2029(defcustom blink-cursor-delay 0.5 2029(defcustom blink-cursor-delay 0.5
2030 "Seconds of idle time after which cursor starts to blink." 2030 "Seconds of idle time after which cursor starts to blink."
2031 :type 'number 2031 :type 'number
2032 :group 'cursor) 2032 :group 'cursor
2033 :set (lambda (symbol value)
2034 (set-default symbol value)
2035 (when blink-cursor-idle-timer (blink-cursor--start-idle-timer))))
2033 2036
2034(defcustom blink-cursor-interval 0.5 2037(defcustom blink-cursor-interval 0.5
2035 "Length of cursor blink interval in seconds." 2038 "Length of cursor blink interval in seconds."
2036 :type 'number 2039 :type 'number
2037 :group 'cursor) 2040 :group 'cursor
2041 :set (lambda (symbol value)
2042 (set-default symbol value)
2043 (when blink-cursor-timer (blink-cursor--start-timer))))
2038 2044
2039(defcustom blink-cursor-blinks 10 2045(defcustom blink-cursor-blinks 10
2040 "How many times to blink before using a solid cursor on NS, X, and MS-Windows. 2046 "How many times to blink before using a solid cursor on NS, X, and MS-Windows.
@@ -2055,6 +2061,24 @@ The function `blink-cursor-start' is called when the timer fires.")
2055This timer calls `blink-cursor-timer-function' every 2061This timer calls `blink-cursor-timer-function' every
2056`blink-cursor-interval' seconds.") 2062`blink-cursor-interval' seconds.")
2057 2063
2064(defun blink-cursor--start-idle-timer ()
2065 "Start the `blink-cursor-idle-timer'."
2066 (when blink-cursor-idle-timer (cancel-timer blink-cursor-idle-timer))
2067 (setq blink-cursor-idle-timer
2068 ;; The 0.2 sec limitation from below is to avoid erratic
2069 ;; behavior (or downright failure to display the cursor
2070 ;; during command execution) if they set blink-cursor-delay
2071 ;; to a very small or even zero value.
2072 (run-with-idle-timer (max 0.2 blink-cursor-delay)
2073 :repeat #'blink-cursor-start)))
2074
2075(defun blink-cursor--start-timer ()
2076 "Start the `blink-cursor-timer'."
2077 (when blink-cursor-timer (cancel-timer blink-cursor-timer))
2078 (setq blink-cursor-timer
2079 (run-with-timer blink-cursor-interval blink-cursor-interval
2080 #'blink-cursor-timer-function)))
2081
2058(defun blink-cursor-start () 2082(defun blink-cursor-start ()
2059 "Timer function called from the timer `blink-cursor-idle-timer'. 2083 "Timer function called from the timer `blink-cursor-idle-timer'.
2060This starts the timer `blink-cursor-timer', which makes the cursor blink 2084This starts the timer `blink-cursor-timer', which makes the cursor blink
@@ -2064,9 +2088,7 @@ command starts, by installing a pre-command hook."
2064 ;; Set up the timer first, so that if this signals an error, 2088 ;; Set up the timer first, so that if this signals an error,
2065 ;; blink-cursor-end is not added to pre-command-hook. 2089 ;; blink-cursor-end is not added to pre-command-hook.
2066 (setq blink-cursor-blinks-done 1) 2090 (setq blink-cursor-blinks-done 1)
2067 (setq blink-cursor-timer 2091 (blink-cursor--start-timer)
2068 (run-with-timer blink-cursor-interval blink-cursor-interval
2069 'blink-cursor-timer-function))
2070 (add-hook 'pre-command-hook 'blink-cursor-end) 2092 (add-hook 'pre-command-hook 'blink-cursor-end)
2071 (internal-show-cursor nil nil))) 2093 (internal-show-cursor nil nil)))
2072 2094
@@ -2113,13 +2135,7 @@ This is done when a frame gets focus. Blink timers may be stopped by
2113 (when (and blink-cursor-mode 2135 (when (and blink-cursor-mode
2114 (not blink-cursor-idle-timer)) 2136 (not blink-cursor-idle-timer))
2115 (remove-hook 'post-command-hook 'blink-cursor-check) 2137 (remove-hook 'post-command-hook 'blink-cursor-check)
2116 (setq blink-cursor-idle-timer 2138 (blink-cursor--start-idle-timer)))
2117 ;; The 0.2 sec limitation from below is to avoid erratic
2118 ;; behavior (or downright failure to display the cursor
2119 ;; during command execution) if they set blink-cursor-delay
2120 ;; to a very small or even zero value.
2121 (run-with-idle-timer (max 0.2 blink-cursor-delay)
2122 :repeat #'blink-cursor-start))))
2123 2139
2124(define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1") 2140(define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1")
2125 2141
@@ -2150,13 +2166,8 @@ terminals, cursor blinking is controlled by the terminal."
2150 (when blink-cursor-mode 2166 (when blink-cursor-mode
2151 (add-hook 'focus-in-hook #'blink-cursor-check) 2167 (add-hook 'focus-in-hook #'blink-cursor-check)
2152 (add-hook 'focus-out-hook #'blink-cursor-suspend) 2168 (add-hook 'focus-out-hook #'blink-cursor-suspend)
2153 (setq blink-cursor-idle-timer 2169 (blink-cursor--start-idle-timer)))
2154 ;; The 0.2 sec limitation from below is to avoid erratic 2170
2155 ;; behavior (or downright failure to display the cursor
2156 ;; during command execution) if they set blink-cursor-delay
2157 ;; to a very small or even zero value.
2158 (run-with-idle-timer (max 0.2 blink-cursor-delay)
2159 :repeat #'blink-cursor-start))))
2160 2171
2161 2172
2162;; Frame maximization/fullscreen 2173;; Frame maximization/fullscreen