mirror of
https://github.com/larstvei/Focus.git
synced 2024-11-26 11:38:32 +00:00
Split activation/deactivation into functions
This commit is contained in:
parent
1423efbd25
commit
fe94e0de69
30
focus.el
30
focus.el
@ -197,6 +197,28 @@ This is added to the `pre-command-hook' when
|
|||||||
(run-at-time focus-read-only-blink-seconds nil
|
(run-at-time focus-read-only-blink-seconds nil
|
||||||
'focus-read-only-hide-cursor (current-buffer)))))
|
'focus-read-only-hide-cursor (current-buffer)))))
|
||||||
|
|
||||||
|
(defun focus-read-only-init ()
|
||||||
|
"Run when `focus-read-only-mode' is activated.
|
||||||
|
Enables `read-only-mode', hides the cursor and adds
|
||||||
|
`focus-read-only-cursor-blink' to `pre-command-hook'. Also
|
||||||
|
`focus-read-only-terminate' is added to the `kill-buffer-hook'."
|
||||||
|
(read-only-mode 1)
|
||||||
|
(setq cursor-type nil)
|
||||||
|
(add-hook 'pre-command-hook 'focus-read-only-cursor-blink nil t)
|
||||||
|
(add-hook 'kill-buffer-hook 'focus-read-only-terminate t))
|
||||||
|
|
||||||
|
(defun focus-read-only-terminate ()
|
||||||
|
"Run when `focus-read-only-mode' is deactivated.
|
||||||
|
Disables `read-only-mode' and shows the cursor again. It cleans
|
||||||
|
up the `focus-read-only-blink-timer' and hooks."
|
||||||
|
(read-only-mode -1)
|
||||||
|
(setq cursor-type t)
|
||||||
|
(when focus-read-only-blink-timer
|
||||||
|
(cancel-timer focus-read-only-blink-timer))
|
||||||
|
(setq focus-read-only-blink-timer nil)
|
||||||
|
(remove-hook 'pre-command-hook 'focus-read-only-cursor-blink t)
|
||||||
|
(remove-hook 'kill-buffer-hook 'focus-read-only-terminate t))
|
||||||
|
|
||||||
(defun turn-off-focus-read-only-mode ()
|
(defun turn-off-focus-read-only-mode ()
|
||||||
"Turn off `focus-read-only-mode'."
|
"Turn off `focus-read-only-mode'."
|
||||||
(interactive)
|
(interactive)
|
||||||
@ -223,13 +245,7 @@ This is added to the `pre-command-hook' when
|
|||||||
(define-key map (kbd "i") 'turn-off-focus-read-only-mode)
|
(define-key map (kbd "i") 'turn-off-focus-read-only-mode)
|
||||||
(define-key map (kbd "q") 'turn-off-focus-read-only-mode)
|
(define-key map (kbd "q") 'turn-off-focus-read-only-mode)
|
||||||
map)
|
map)
|
||||||
(read-only-mode (if focus-read-only-mode 1 -1))
|
(if focus-read-only-mode (focus-read-only-init) (focus-read-only-terminate)))
|
||||||
(when focus-read-only-blink-timer (cancel-timer focus-read-only-blink-timer))
|
|
||||||
(setq cursor-type (not focus-read-only-mode))
|
|
||||||
(setq focus-read-only-blink-timer nil)
|
|
||||||
(remove-hook 'pre-command-hook 'focus-read-only-cursor-blink t)
|
|
||||||
(when focus-read-only-mode
|
|
||||||
(add-hook 'pre-command-hook 'focus-read-only-cursor-blink nil t)))
|
|
||||||
|
|
||||||
(provide 'focus)
|
(provide 'focus)
|
||||||
;;; focus.el ends here
|
;;; focus.el ends here
|
||||||
|
Loading…
Reference in New Issue
Block a user