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

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

[nongnu] elpa/focus 02cec3494d 01/82: Initial commit


From: ELPA Syncer
Subject: [nongnu] elpa/focus 02cec3494d 01/82: Initial commit
Date: Tue, 6 Sep 2022 04:58:53 -0400 (EDT)

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

    Initial commit
---
 focus-mode.el | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/focus-mode.el b/focus-mode.el
new file mode 100644
index 0000000000..665aaaa375
--- /dev/null
+++ b/focus-mode.el
@@ -0,0 +1,34 @@
+(defvar-local focus-pre-overlay nil)
+(defvar-local focus-post-overlay nil)
+
+(defun focus-hexstr-to-int (str)
+  (read (concat "#x" (substring str 1))))
+
+(defun focus-average-colors (hstr1 hstr2 &rest hstrs)
+  (let* ((strs (cons hstr1 (cons hstr2 hstrs)))
+         (avg (/ (apply '+ (mapcar 'focus-hexstr-to-int strs)) 2)))
+    (format "#%X" avg)))
+
+(defun focus-move-focus ()
+  (save-excursion
+    (let* ((pre  (or (re-search-backward "^\n" nil t) 1))
+           (post (1- (or (re-search-forward "^\n" nil t 2)
+                         (1+ (point-max))))))
+      (move-overlay focus-pre-overlay  (point-min) pre)
+      (move-overlay focus-post-overlay post (point-max)))))
+
+;;;###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)))



reply via email to

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