From d1bd81ee4dfc56471fcca677bdf6408aeaee07e0 Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Sun, 24 May 2015 02:04:40 +0200 Subject: [PATCH] Added focus-read-only-mode --- focus.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/focus.el b/focus.el index 4a76846..e79aa47 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