mirror of
https://github.com/larstvei/Focus.git
synced 2024-11-26 11:38:32 +00:00
Documented every function/variable
This commit is contained in:
parent
8028fc088f
commit
03e3cbc566
@ -1,15 +1,24 @@
|
|||||||
(require 'cl-lib)
|
(require 'cl-lib)
|
||||||
|
|
||||||
(defvar-local focus-pre-overlay nil)
|
(defvar-local focus-pre-overlay nil
|
||||||
(defvar-local focus-post-overlay nil)
|
"The overlay that dims the text prior to the current-point.")
|
||||||
|
|
||||||
|
(defvar-local focus-post-overlay nil
|
||||||
|
"The overlay that dims the text past the current-point.")
|
||||||
|
|
||||||
(defun focus-search-backward (regex)
|
(defun focus-search-backward (regex)
|
||||||
|
"A wrapper for re-search-backward, where the point does not move,
|
||||||
|
and if the search fails, it returns NIL."
|
||||||
(save-excursion (re-search-backward regex nil t)))
|
(save-excursion (re-search-backward regex nil t)))
|
||||||
|
|
||||||
(defun focus-search-forward (regex)
|
(defun focus-search-forward (regex)
|
||||||
|
"A wrapper for re-search-backward, where the point does not move,
|
||||||
|
and if the search fails, it returns NIL."
|
||||||
(save-excursion (re-search-forward regex nil t)))
|
(save-excursion (re-search-forward regex nil t)))
|
||||||
|
|
||||||
(defun focus-average-colors (color &rest colors)
|
(defun focus-average-colors (color &rest colors)
|
||||||
|
"This function takes one or more colors and returns the average
|
||||||
|
of RGB values of the given colors."
|
||||||
(let* ((colors (cons color colors))
|
(let* ((colors (cons color colors))
|
||||||
(colors (mapcar 'color-name-to-rgb colors))
|
(colors (mapcar 'color-name-to-rgb colors))
|
||||||
(len (length colors))
|
(len (length colors))
|
||||||
@ -18,12 +27,18 @@
|
|||||||
(apply 'color-rgb-to-hex avg)))
|
(apply 'color-rgb-to-hex avg)))
|
||||||
|
|
||||||
(defun focus-move-focus ()
|
(defun focus-move-focus ()
|
||||||
|
"If `focus-mode' is enabled, this command fires after each
|
||||||
|
command, and moves the dimming overlays."
|
||||||
(let* ((pre (or (focus-search-backward "^\n") (point-min)))
|
(let* ((pre (or (focus-search-backward "^\n") (point-min)))
|
||||||
(post (or (focus-search-forward "^\n") (point-max))))
|
(post (or (focus-search-forward "^\n") (point-max))))
|
||||||
(move-overlay focus-pre-overlay (point-min) pre)
|
(move-overlay focus-pre-overlay (point-min) pre)
|
||||||
(move-overlay focus-post-overlay post (point-max))))
|
(move-overlay focus-post-overlay post (point-max))))
|
||||||
|
|
||||||
(defun focus-init ()
|
(defun focus-init ()
|
||||||
|
"This function is run when focus-mode is enabled. 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))
|
(setq focus-pre-overlay (make-overlay (point-min) (point-min))
|
||||||
focus-post-overlay (make-overlay (point-max) (point-max)))
|
focus-post-overlay (make-overlay (point-max) (point-max)))
|
||||||
(let ((color (focus-average-colors
|
(let ((color (focus-average-colors
|
||||||
@ -34,6 +49,9 @@
|
|||||||
(add-hook 'post-command-hook 'focus-move-focus nil t))
|
(add-hook 'post-command-hook 'focus-move-focus nil t))
|
||||||
|
|
||||||
(defun focus-terminate ()
|
(defun focus-terminate ()
|
||||||
|
"When `focus-mode' is disabled the overlays pointed to by
|
||||||
|
`focus-pre-overlay' and `focus-post-overlay' are deleted, and
|
||||||
|
`focus-move-focus' is removed from `post-command-hook'."
|
||||||
(progn (mapc 'delete-overlay (list focus-pre-overlay focus-post-overlay))
|
(progn (mapc 'delete-overlay (list focus-pre-overlay focus-post-overlay))
|
||||||
(remove-hook 'post-command-hook 'focus-move-focus t)))
|
(remove-hook 'post-command-hook 'focus-move-focus t)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user