Add possibility of customizing the face of the focused region

This commit is contained in:
Lars Tveito 2019-12-03 22:59:28 +01:00
parent 19b3c7b348
commit a80b7b6eba

View File

@ -59,12 +59,19 @@ Things that are defined include `symbol', `list', `sexp',
:type '(float) :type '(float)
:group 'focus) :group 'focus)
(defcustom focus-unfocused-face 'font-lock-comment-face
"The face that overlays the unfocused area."
:type '(face)
:group 'focus)
(defcustom focus-focused-face nil
"The face that overlays the focused area."
:type '(face)
:group 'focus)
(defvar focus-cursor-type cursor-type (defvar focus-cursor-type cursor-type
"Used to restore the users `cursor-type'") "Used to restore the users `cursor-type'")
(defvar focus-unfocused-face font-lock-comment-face
"Overrides the color used for dimmed text.")
(defvar-local focus-current-thing nil (defvar-local focus-current-thing nil
"Overrides the choice of thing dictated by `focus-mode-to-thing' if set.") "Overrides the choice of thing dictated by `focus-mode-to-thing' if set.")
@ -74,6 +81,9 @@ Things that are defined include `symbol', `list', `sexp',
(defvar-local focus-pre-overlay nil (defvar-local focus-pre-overlay nil
"The overlay that dims the text prior to the current-point.") "The overlay that dims the text prior to the current-point.")
(defvar-local focus-mid-overlay nil
"The overlay that surrounds the text of the current-point.")
(defvar-local focus-post-overlay nil (defvar-local focus-post-overlay nil
"The overlay that dims the text past the current-point.") "The overlay that dims the text past the current-point.")
@ -105,20 +115,24 @@ command."
(focus-move-overlays (car bounds) (cdr bounds)))))) (focus-move-overlays (car bounds) (cdr bounds))))))
(defun focus-move-overlays (low high) (defun focus-move-overlays (low high)
"Move `focus-pre-overlay' and `focus-post-overlay'." "Move `focus-pre-overlay', `focus-mid-overlay' and `focus-post-overlay'."
(move-overlay focus-pre-overlay (point-min) low) (move-overlay focus-pre-overlay (point-min) low)
(move-overlay focus-mid-overlay low high)
(move-overlay focus-post-overlay high (point-max))) (move-overlay focus-post-overlay high (point-max)))
(defun focus-init () (defun focus-init ()
"This function is run when command `focus-mode' is enabled. "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', `focus-min-overlay', and
overlays; these are invisible until `focus-move-focus' is run. It `focus-post-overlay' to overlays; these are invisible until
adds `focus-move-focus' to `post-command-hook'." `focus-move-focus' is run. It adds `focus-move-focus' to
`post-command-hook'."
(unless (or focus-pre-overlay focus-post-overlay) (unless (or focus-pre-overlay focus-post-overlay)
(setq focus-pre-overlay (make-overlay (point-min) (point-min)) (setq focus-pre-overlay (make-overlay (point-min) (point-min))
focus-mid-overlay (make-overlay (point-min) (point-max))
focus-post-overlay (make-overlay (point-max) (point-max)) focus-post-overlay (make-overlay (point-max) (point-max))
focus-buffer (current-buffer)) focus-buffer (current-buffer))
(overlay-put focus-mid-overlay 'face focus-focused-face)
(mapc (lambda (o) (overlay-put o 'face focus-unfocused-face)) (mapc (lambda (o) (overlay-put o 'face focus-unfocused-face))
(list focus-pre-overlay focus-post-overlay)) (list focus-pre-overlay focus-post-overlay))
(add-hook 'post-command-hook 'focus-move-focus nil t) (add-hook 'post-command-hook 'focus-move-focus nil t)
@ -127,12 +141,15 @@ adds `focus-move-focus' to `post-command-hook'."
(defun focus-terminate () (defun focus-terminate ()
"This function is run when command `focus-mode' is disabled. "This function is run when command `focus-mode' is disabled.
The overlays pointed to by `focus-pre-overlay' and `focus-post-overlay' are The overlays pointed to by `focus-pre-overlay',
deleted, and `focus-move-focus' is removed from `post-command-hook'." `focus-mid-overlay' and `focus-post-overlay' are deleted, and
`focus-move-focus' is removed from `post-command-hook'."
(when (and focus-pre-overlay focus-post-overlay) (when (and focus-pre-overlay focus-post-overlay)
(mapc 'delete-overlay (list focus-pre-overlay focus-post-overlay)) (mapc 'delete-overlay
(list focus-pre-overlay focus-mid-overlay focus-post-overlay))
(remove-hook 'post-command-hook 'focus-move-focus t) (remove-hook 'post-command-hook 'focus-move-focus t)
(setq focus-pre-overlay nil (setq focus-pre-overlay nil
focus-mid-overlay nil
focus-post-overlay nil))) focus-post-overlay nil)))
(defun focus-goto-thing (bounds) (defun focus-goto-thing (bounds)