From e691113e4b3fd2447bbb5f680d0717b13a2a07e5 Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Tue, 12 May 2015 01:12:32 +0200 Subject: [PATCH] Moved init/termination to separate functions --- focus-mode.el | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/focus-mode.el b/focus-mode.el index 963b6f4..47d6825 100644 --- a/focus-mode.el +++ b/focus-mode.el @@ -21,18 +21,22 @@ (move-overlay focus-pre-overlay (point-min) pre) (move-overlay focus-post-overlay post (point-max)))) +(defun focus-init () + (setq focus-pre-overlay (make-overlay (point-min) (point-min)) + focus-post-overlay (make-overlay (point-max) (point-max))) + (let ((color (focus-average-colors + (face-attribute 'default :foreground) + (face-attribute 'default :background)))) + (mapc (lambda (o) (overlay-put o 'face (cons 'foreground-color color))) + (list focus-pre-overlay focus-post-overlay))) + (add-hook 'post-command-hook 'focus-move-focus nil t)) + +(defun focus-terminate () + (progn (mapc 'delete-overlay (list focus-pre-overlay focus-post-overlay)) + (remove-hook 'post-command-hook 'focus-move-focus t))) + ;;;###autoload (define-minor-mode focus-mode "Dim the font color text in surrounding paragraphs." :init-value nil - (if (not focus-mode) - (progn (mapc 'delete-overlay (list focus-pre-overlay focus-post-overlay)) - (remove-hook 'post-command-hook 'focus-move-focus t)) - (setq focus-pre-overlay (make-overlay (point-min) (point-min)) - focus-post-overlay (make-overlay (point-max) (point-max))) - (let ((color (focus-average-colors - (face-attribute 'default :foreground) - (face-attribute 'default :background)))) - (mapc (lambda (o) (overlay-put o 'face (cons 'foreground-color color))) - (list focus-pre-overlay focus-post-overlay))) - (add-hook 'post-command-hook 'focus-move-focus nil t))) + (if focus-mode (focus-init) (focus-terminate)))