emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/focus d1bd81ee4d 39/82: Added focus-read-only-mode


From: ELPA Syncer
Subject: [nongnu] elpa/focus d1bd81ee4d 39/82: Added focus-read-only-mode
Date: Tue, 6 Sep 2022 04:58:56 -0400 (EDT)

branch: elpa/focus
commit d1bd81ee4dfc56471fcca677bdf6408aeaee07e0
Author: Lars Tveito <larstvei@ifi.uio.no>
Commit: Lars Tveito <larstvei@ifi.uio.no>

    Added focus-read-only-mode
---
 focus.el | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/focus.el b/focus.el
index 4a76846b41..e79aa47787 100644
--- a/focus.el
+++ b/focus.el
@@ -195,11 +195,37 @@ This is added to the `pre-command-hook' when
     (setq focus-read-only-blink-timer
           (run-at-time focus-read-only-blink-seconds nil
                        'focus-read-only-hide-cursor (current-buffer)))))
+
+(defun turn-off-focus-read-only-mode ()
+  "Turn off `focus-read-only-mode'."
+  (interactive)
+  (focus-read-only-mode -1))
+
 ;;;###autoload
 (define-minor-mode focus-mode
   "Dim the font color of text in surrounding sections."
   :init-value nil
   (if focus-mode (focus-init) (focus-terminate)))
 
+;;;###autoload
+(define-minor-mode focus-read-only-mode
+  "A read-only mode optimized for `focus-mode'."
+  :init-value nil
+  :keymap (let ((map (make-sparse-keymap)))
+            (define-key map (kbd "n") 'focus-next-thing)
+            (define-key map (kbd "SPC") 'focus-next-thing)
+            (define-key map (kbd "p") 'focus-prev-thing)
+            (define-key map (kbd "S-SPC") 'focus-prev-thing)
+            (define-key map (kbd "i") 'turn-off-focus-read-only-mode)
+            (define-key map (kbd "q") 'turn-off-focus-read-only-mode)
+            map)
+  (read-only-mode (if focus-read-only-mode 1 -1))
+  (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)
 ;;; focus.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]