From cd2aad55905aa3068655e553b8d3efba900dab6a Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Mon, 18 May 2015 23:03:39 +0200 Subject: [PATCH 01/10] Cleaned up focus-dimness docstring --- focus.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/focus.el b/focus.el index 563f9d4..1d31acc 100644 --- a/focus.el +++ b/focus.el @@ -41,12 +41,11 @@ (defcustom focus-dimness 0 "Amount of dimness in out of focus sections is determined by this integer. -A positive value increases the dimness of the sections. A +A positive value increases the dimness of the sections. +A negative value decreases the dimness. -negative value decreases the dimness. - -The default is 0 which means a 50/50 mixture of the background and foreground -color." +The default is 0 which means a 50/50 mixture of the background +and foreground color." :type '(integer) :group 'focus) From 497d13d758c428c06499e681e83b71aac81aead8 Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Sun, 24 May 2015 01:56:36 +0200 Subject: [PATCH 02/10] Added functions for jumping between things --- focus.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/focus.el b/focus.el index 1d31acc..32d4093 100644 --- a/focus.el +++ b/focus.el @@ -145,6 +145,18 @@ deleted, and `focus-move-focus' is removed from `post-command-hook'." (progn (mapc 'delete-overlay (list focus-pre-overlay focus-post-overlay)) (remove-hook 'post-command-hook 'focus-move-focus t))) +(defun focus-next-thing (&optional n) + "Moves the point to the middle of the Nth next thing." + (interactive "p") + (forward-thing (focus-get-thing) (+ 1 n)) + (let ((bounds (focus-bounds))) + (goto-char (/ (+ (car bounds) (cdr bounds)) 2))) + (recenter nil)) + +(defun focus-prev-thing (&optional n) + "Moves the point to the middle of the Nth previous thing." + (interactive "p") + (focus-next-thing (- (+ 2 n)))) ;;;###autoload (define-minor-mode focus-mode "Dim the font color of text in surrounding sections." From 284a1240ce21e2e7ce658b2ee603861064910fe6 Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Sun, 24 May 2015 01:59:28 +0200 Subject: [PATCH 03/10] Cleaned up doc in `focus-average-colors' --- focus.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/focus.el b/focus.el index 32d4093..fa22c87 100644 --- a/focus.el +++ b/focus.el @@ -96,7 +96,10 @@ Things that are defined include `symbol', `list', `sexp', (bounds-of-thing-at-point thing))) (defun focus-average-colors (color &rest colors) - "Takes one or more COLORS and returns the average of the RGB-values." + "Takes an average of the colors given by argument. +Argument COLOR is a color name, and so are the COLORS; COLOR is +there to ensure that the the function receives at least one +argument." (let* ((colors (cons color colors)) (colors (mapcar 'color-name-to-rgb colors)) (len (length colors)) From 58a91b29aa414a24decb8bbe5adac41c3ac4624d Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Sun, 24 May 2015 02:00:06 +0200 Subject: [PATCH 04/10] Split focus-bounds into two functions --- focus.el | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/focus.el b/focus.el index fa22c87..636d83a 100644 --- a/focus.el +++ b/focus.el @@ -88,12 +88,15 @@ Things that are defined include `symbol', `list', `sexp', (let ((v (funcall f (car lst)))) (if v v (focus-any f (cdr lst)))))) -(defun focus-bounds () - "Return the current bounds, based on `focus-mode-to-thing'." +(defun focus-get-thing () + "Return the current thing, based on `focus-mode-to-thing'." (let* ((modes (mapcar 'car focus-mode-to-thing)) - (mode (focus-any 'derived-mode-p modes)) - (thing (if mode (cdr (assoc mode focus-mode-to-thing)) 'sentence))) - (bounds-of-thing-at-point thing))) + (mode (focus-any 'derived-mode-p modes))) + (if mode (cdr (assoc mode focus-mode-to-thing)) 'sentence))) + +(defun focus-bounds () + "Return the current bounds, based on `focus-get-thing'." + (bounds-of-thing-at-point (focus-get-thing))) (defun focus-average-colors (color &rest colors) "Takes an average of the colors given by argument. From ac711fe13a5ae0dce4d0eefa80737493ba82187b Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Sun, 24 May 2015 02:01:08 +0200 Subject: [PATCH 05/10] Whitespace cleanup --- focus.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/focus.el b/focus.el index 636d83a..de01b85 100644 --- a/focus.el +++ b/focus.el @@ -133,7 +133,7 @@ each command." (defun focus-init () "This function is run when command `focus-mode' is enabled. - It sets the `focus-pre-overlay' and `focus-post-overlay' to +It sets the `focus-pre-overlay' and `focus-post-overlay' to overlays; these are invisible until `focus-move-focus' is run. It adds `focus-move-focus' to `post-command-hook'." (setq focus-pre-overlay (make-overlay (point-min) (point-min)) From 94ed8ab68b8ce8ea19d63d3b21867ae5099595ba Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Sun, 24 May 2015 02:02:03 +0200 Subject: [PATCH 06/10] Defined variables to help hide the cursor Used in focus-read-only-mode --- focus.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/focus.el b/focus.el index de01b85..335eab0 100644 --- a/focus.el +++ b/focus.el @@ -65,15 +65,26 @@ Things that are defined include `symbol', `list', `sexp', :type '(repeat symbol) :group 'focus) +(defcustom focus-read-only-blink-seconds 1 + "The duration of a cursor blink in `focus-read-only-mode'." + :type '(float) + :group 'focus) + (defvar focus-pre-overlay nil "The overlay that dims the text prior to the current-point.") (defvar focus-post-overlay nil "The overlay that dims the text past the current-point.") +(defvar focus-read-only-blink-timer nil + "Timer started from `focus-read-only-cursor-blink'. +The timer calls `focus-read-only-hide-cursor' after +`focus-read-only-blink-seconds' seconds.") + ;; Use make-local-variable for backwards compatibility. (dolist (var '(focus-pre-overlay - focus-post-overlay)) + focus-post-overlay + focus-read-only-blink-timer)) (make-local-variable var)) ;; Changing major-mode should not affect Focus mode. From a723f78dc40581a943c5a2307c9ec63a73580cb4 Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Sun, 24 May 2015 02:03:46 +0200 Subject: [PATCH 07/10] Added function for hiding the cursor --- focus.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/focus.el b/focus.el index 335eab0..0c63baf 100644 --- a/focus.el +++ b/focus.el @@ -174,6 +174,15 @@ deleted, and `focus-move-focus' is removed from `post-command-hook'." "Moves the point to the middle of the Nth previous thing." (interactive "p") (focus-next-thing (- (+ 2 n)))) + +(defun focus-read-only-hide-cursor (&optional buffer) + "Hide the cursor. +This function is triggered by the `focus-read-only-blink-timer', +when `focus-read-only-mode' is activated." + (with-current-buffer (or buffer (current-buffer)) + (when (and focus-read-only-mode (not (null focus-read-only-blink-timer))) + (setq focus-read-only-blink-timer nil) + (setq cursor-type nil)))) ;;;###autoload (define-minor-mode focus-mode "Dim the font color of text in surrounding sections." From b21341bd40561165b13c72378cb2fb66836409cc Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Sun, 24 May 2015 02:04:02 +0200 Subject: [PATCH 08/10] Added function for briefly showing the cursor --- focus.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/focus.el b/focus.el index 0c63baf..4a76846 100644 --- a/focus.el +++ b/focus.el @@ -183,6 +183,18 @@ when `focus-read-only-mode' is activated." (when (and focus-read-only-mode (not (null focus-read-only-blink-timer))) (setq focus-read-only-blink-timer nil) (setq cursor-type nil)))) + +(defun focus-read-only-cursor-blink () + "Make the cursor visible for `focus-read-only-blink-seconds'. +This is added to the `pre-command-hook' when +`focus-read-only-mode' is active." + (when (and focus-read-only-mode + (not (member last-command '(focus-next-thing focus-prev-thing)))) + (when focus-read-only-blink-timer (cancel-timer focus-read-only-blink-timer)) + (setq cursor-type t) + (setq focus-read-only-blink-timer + (run-at-time focus-read-only-blink-seconds nil + 'focus-read-only-hide-cursor (current-buffer))))) ;;;###autoload (define-minor-mode focus-mode "Dim the font color of text in surrounding sections." From d1bd81ee4dfc56471fcca677bdf6408aeaee07e0 Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Sun, 24 May 2015 02:04:40 +0200 Subject: [PATCH 09/10] 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 From 27eda82b953f153199d3622e86e2a84d35e9ccbe Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Sun, 24 May 2015 02:04:50 +0200 Subject: [PATCH 10/10] Binding for enabling focus-read-only-mode in focus-mode --- focus.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/focus.el b/focus.el index e79aa47..2386733 100644 --- a/focus.el +++ b/focus.el @@ -205,6 +205,9 @@ This is added to the `pre-command-hook' when (define-minor-mode focus-mode "Dim the font color of text in surrounding sections." :init-value nil + :keymap (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-c C-q") 'focus-read-only-mode) + map) (if focus-mode (focus-init) (focus-terminate))) ;;;###autoload