2015-05-17 10:41:18 +00:00
|
|
|
|
;;; focus.el --- Dim the font color of text in surrounding sections -*- lexical-binding: t; -*-
|
2015-05-12 20:42:01 +00:00
|
|
|
|
|
|
|
|
|
;; Copyright (C) 2015 Lars Tveito
|
|
|
|
|
|
|
|
|
|
;; Author: Lars Tveito <larstvei@ifi.uio.no>
|
|
|
|
|
;; URL: http://github.com/larstvei/Focus
|
|
|
|
|
;; Created: 11th May 2015
|
2019-12-09 22:10:50 +00:00
|
|
|
|
;; Version: 1.0.0
|
2019-03-09 14:01:43 +00:00
|
|
|
|
;; Package-Requires: ((emacs "24.3") (cl-lib "0.5"))
|
2015-05-12 20:42:01 +00:00
|
|
|
|
|
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
2015-05-17 10:41:18 +00:00
|
|
|
|
;; Focus provides `focus-mode` that dims the text of surrounding sections,
|
2015-05-12 21:21:33 +00:00
|
|
|
|
;; similar to [iA Writer's](https://ia.net/writer) Focus Mode.
|
2015-05-12 20:42:01 +00:00
|
|
|
|
;;
|
2015-05-12 21:21:33 +00:00
|
|
|
|
;; Enable the mode with `M-x focus-mode'.
|
2015-05-12 20:42:01 +00:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2015-05-11 23:54:10 +00:00
|
|
|
|
(require 'cl-lib)
|
2020-02-21 21:45:27 +00:00
|
|
|
|
(require 'org-element)
|
2015-05-16 22:58:20 +00:00
|
|
|
|
(require 'thingatpt)
|
2015-05-11 23:54:10 +00:00
|
|
|
|
|
2015-05-17 18:28:40 +00:00
|
|
|
|
(defgroup focus ()
|
2015-05-17 10:41:33 +00:00
|
|
|
|
"Dim the font color of text in surrounding sections."
|
2015-05-17 18:28:40 +00:00
|
|
|
|
:group 'font-lock
|
|
|
|
|
:prefix "focus-")
|
2015-05-17 10:41:33 +00:00
|
|
|
|
|
2020-02-21 21:45:27 +00:00
|
|
|
|
(defcustom focus-mode-to-thing '((prog-mode . defun)
|
|
|
|
|
(text-mode . paragraph)
|
|
|
|
|
(org-mode . org-element))
|
2015-05-17 10:36:20 +00:00
|
|
|
|
"An associated list between mode and thing.
|
|
|
|
|
|
|
|
|
|
A thing is defined in thingatpt.el; the thing determines the
|
|
|
|
|
narrowness of the focused section.
|
2015-05-16 22:58:20 +00:00
|
|
|
|
|
|
|
|
|
Note that the order of the list matters. The first mode that the
|
|
|
|
|
current mode is derived from is used, so more modes that have
|
|
|
|
|
many derivatives should be placed by the end of the list.
|
|
|
|
|
|
|
|
|
|
Things that are defined include `symbol', `list', `sexp',
|
|
|
|
|
`defun', `filename', `url', `email', `word', `sentence',
|
|
|
|
|
`whitespace', `line', and `page'."
|
|
|
|
|
:type '(repeat symbol)
|
|
|
|
|
:group 'focus)
|
|
|
|
|
|
2015-05-24 00:02:03 +00:00
|
|
|
|
(defcustom focus-read-only-blink-seconds 1
|
|
|
|
|
"The duration of a cursor blink in `focus-read-only-mode'."
|
|
|
|
|
:type '(float)
|
|
|
|
|
:group 'focus)
|
|
|
|
|
|
2020-02-22 02:06:40 +00:00
|
|
|
|
(defcustom focus-fraction 0.5
|
|
|
|
|
"Determines the amount of dimness in out of focus sections (0.0 – 1.0)."
|
|
|
|
|
:type '(float)
|
|
|
|
|
:group 'focus)
|
|
|
|
|
|
|
|
|
|
(defface focus-unfocused nil
|
2019-12-03 21:59:28 +00:00
|
|
|
|
"The face that overlays the unfocused area."
|
|
|
|
|
:group 'focus)
|
|
|
|
|
|
2019-12-04 15:33:56 +00:00
|
|
|
|
(defface focus-focused nil
|
2019-12-03 21:59:28 +00:00
|
|
|
|
"The face that overlays the focused area."
|
|
|
|
|
:group 'focus)
|
|
|
|
|
|
2017-05-20 15:55:40 +00:00
|
|
|
|
(defvar focus-cursor-type cursor-type
|
2020-02-23 22:44:14 +00:00
|
|
|
|
"Used to restore the users `cursor-type'.")
|
2017-05-20 15:55:40 +00:00
|
|
|
|
|
2019-03-18 02:42:47 +00:00
|
|
|
|
(defvar-local focus-current-thing nil
|
2015-11-18 08:15:29 +00:00
|
|
|
|
"Overrides the choice of thing dictated by `focus-mode-to-thing' if set.")
|
|
|
|
|
|
2019-03-18 02:42:47 +00:00
|
|
|
|
(defvar-local focus-buffer nil
|
2017-06-12 14:43:59 +00:00
|
|
|
|
"Local reference to the buffer focus functions operate on.")
|
|
|
|
|
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(defvar-local focus-unfocused-overlays nil
|
|
|
|
|
"The overlays that dims the unfocused area.")
|
2015-05-12 20:23:36 +00:00
|
|
|
|
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(defvar-local focus-focused-overlay nil
|
|
|
|
|
"The overlay that is added to the focused area.")
|
2015-05-11 22:48:09 +00:00
|
|
|
|
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(defvar-local focus-pin-bounds nil
|
|
|
|
|
"Bounds set by `focus-pin'.")
|
2020-02-22 02:06:40 +00:00
|
|
|
|
|
2020-02-23 15:20:12 +00:00
|
|
|
|
(defvar-local focus-last-bounds nil
|
|
|
|
|
"Used to identify changes in `focus-bounds'.")
|
2020-02-22 02:06:40 +00:00
|
|
|
|
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(defvar-local focus-last-window-bounds nil
|
|
|
|
|
"Used to identify changes in `window-start' and `window-end'.")
|
|
|
|
|
|
2020-02-23 15:20:12 +00:00
|
|
|
|
(defvar-local focus-last-background nil
|
|
|
|
|
"Used to identify changes in the background.")
|
2020-02-22 02:06:40 +00:00
|
|
|
|
|
2019-03-18 02:42:47 +00:00
|
|
|
|
(defvar-local focus-read-only-blink-timer nil
|
2015-05-24 00:02:03 +00:00
|
|
|
|
"Timer started from `focus-read-only-cursor-blink'.
|
|
|
|
|
The timer calls `focus-read-only-hide-cursor' after
|
|
|
|
|
`focus-read-only-blink-seconds' seconds.")
|
|
|
|
|
|
2020-02-22 02:06:40 +00:00
|
|
|
|
|
2015-05-24 00:00:06 +00:00
|
|
|
|
(defun focus-get-thing ()
|
|
|
|
|
"Return the current thing, based on `focus-mode-to-thing'."
|
2015-11-18 08:15:29 +00:00
|
|
|
|
(or focus-current-thing
|
2016-11-25 15:27:46 +00:00
|
|
|
|
(let* ((modes (mapcar 'car focus-mode-to-thing))
|
2017-12-04 04:57:30 +00:00
|
|
|
|
(mode (or (cl-find major-mode modes)
|
2017-12-04 05:03:32 +00:00
|
|
|
|
(apply #'derived-mode-p modes))))
|
2016-11-25 15:27:46 +00:00
|
|
|
|
(if mode (cdr (assoc mode focus-mode-to-thing)) 'sentence))))
|
2015-05-24 00:00:06 +00:00
|
|
|
|
|
|
|
|
|
(defun focus-bounds ()
|
|
|
|
|
"Return the current bounds, based on `focus-get-thing'."
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(or focus-pin-bounds
|
|
|
|
|
(let ((thing (focus-get-thing)))
|
|
|
|
|
(cond ((eq thing 'org-element)
|
|
|
|
|
(let* ((elem (org-element-at-point))
|
|
|
|
|
(beg (org-element-property :begin elem))
|
|
|
|
|
(end (org-element-property :end elem)))
|
|
|
|
|
(and beg end (cons beg end))))
|
|
|
|
|
(t (bounds-of-thing-at-point thing))))))
|
|
|
|
|
|
|
|
|
|
(defun focus-window-bounds ()
|
|
|
|
|
(cons (window-start) (window-end nil t)))
|
|
|
|
|
|
|
|
|
|
(defun focus-lerp (c1 c2 d)
|
|
|
|
|
"Interpolate C1 with C2, where D controls the amount."
|
|
|
|
|
(apply 'color-rgb-to-hex
|
|
|
|
|
(cl-mapcar (lambda (x y) (+ (* x (- 1 d)) (* y d))) c1 c2)))
|
|
|
|
|
|
|
|
|
|
(defun focus-make-unfocused-face (fg)
|
|
|
|
|
"Add dimmed foreground color FG to the `focus-unfocused` face."
|
|
|
|
|
(let ((bg (face-background 'default)))
|
|
|
|
|
(when (and fg bg (color-defined-p fg) (color-defined-p bg))
|
|
|
|
|
(if (color-defined-p (face-attribute 'focus-unfocused :foreground))
|
|
|
|
|
'focus-unfocused
|
|
|
|
|
(plist-put (face-attr-construct 'focus-unfocused)
|
|
|
|
|
:foreground (focus-lerp (color-name-to-rgb fg)
|
|
|
|
|
(color-name-to-rgb bg)
|
|
|
|
|
focus-fraction))))))
|
2020-02-23 22:43:13 +00:00
|
|
|
|
|
|
|
|
|
(defun focus-foreground-from-face (face)
|
|
|
|
|
"Return foreground color for FACE, or 'default if nil."
|
|
|
|
|
(if (facep face)
|
|
|
|
|
(face-attribute face :foreground)
|
|
|
|
|
(face-attribute 'default :foreground)))
|
|
|
|
|
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(defun focus-dim-area (low high)
|
2020-02-23 22:43:13 +00:00
|
|
|
|
"Restore original colors between LOW and HIGH.
|
|
|
|
|
|
|
|
|
|
Returns the list of added overlays."
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(while (< low high)
|
|
|
|
|
(let ((next (next-single-property-change low 'face nil high)))
|
|
|
|
|
(if (invisible-p low)
|
|
|
|
|
(setq low (next-single-char-property-change low 'invisible nil high))
|
|
|
|
|
(let* ((face (get-text-property low 'face))
|
|
|
|
|
(fg (focus-foreground-from-face face))
|
|
|
|
|
(unfocused-face (focus-make-unfocused-face fg))
|
|
|
|
|
(o (make-overlay low next)))
|
|
|
|
|
(overlay-put o 'face unfocused-face)
|
|
|
|
|
(push o focus-unfocused-overlays)
|
|
|
|
|
(setq low next))))))
|
|
|
|
|
|
|
|
|
|
(defun focus-remove-unfocused-overlays ()
|
|
|
|
|
(while focus-unfocused-overlays
|
|
|
|
|
(delete-overlay (pop focus-unfocused-overlays))))
|
|
|
|
|
|
|
|
|
|
(defun focus-move-focus (&rest args)
|
2019-03-09 14:05:51 +00:00
|
|
|
|
"Move the focused section according to `focus-bounds'.
|
2015-05-17 10:36:20 +00:00
|
|
|
|
|
2020-03-08 17:32:39 +00:00
|
|
|
|
If `focus-mode' is enabled, this function is added to
|
|
|
|
|
`post-command-hook' and `window-scroll-functions'. The function
|
|
|
|
|
can be called with an arbitrary number of ARGS to support being
|
|
|
|
|
called from `window-scroll-functions'."
|
2017-06-12 14:43:59 +00:00
|
|
|
|
(with-current-buffer focus-buffer
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(let* ((bg (face-background 'default))
|
|
|
|
|
(window-bounds (focus-window-bounds))
|
|
|
|
|
(bounds (focus-bounds)))
|
2020-02-23 15:20:12 +00:00
|
|
|
|
(when (and bounds (or (not (equal bg focus-last-background))
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(not (equal window-bounds focus-last-window-bounds))
|
2020-02-23 15:20:12 +00:00
|
|
|
|
(not (equal bounds focus-last-bounds))))
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(let ((start (car window-bounds))
|
|
|
|
|
(end (cdr window-bounds))
|
|
|
|
|
(low (car bounds))
|
2020-02-22 02:06:40 +00:00
|
|
|
|
(high (cdr bounds)))
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(focus-remove-unfocused-overlays)
|
|
|
|
|
(focus-dim-area start low)
|
|
|
|
|
(focus-dim-area high end)
|
|
|
|
|
(move-overlay focus-focused-overlay low high)))
|
|
|
|
|
(setq focus-last-background bg)
|
|
|
|
|
(setq focus-last-window-bounds window-bounds)
|
|
|
|
|
(setq focus-last-bounds bounds))))
|
|
|
|
|
|
|
|
|
|
(defun focus-make-focused-overlay ()
|
|
|
|
|
(let ((o (make-overlay (point-min) (point-max))))
|
|
|
|
|
(overlay-put o 'face 'focus-focused)
|
|
|
|
|
o))
|
2015-05-11 22:48:09 +00:00
|
|
|
|
|
2015-05-11 23:12:32 +00:00
|
|
|
|
(defun focus-init ()
|
2020-02-23 22:44:14 +00:00
|
|
|
|
"This function run when command `focus-mode' is enabled.
|
2015-05-17 10:36:20 +00:00
|
|
|
|
|
2019-12-03 21:59:28 +00:00
|
|
|
|
It sets the `focus-pre-overlay', `focus-min-overlay', and
|
|
|
|
|
`focus-post-overlay' to overlays; these are invisible until
|
2020-02-22 02:06:40 +00:00
|
|
|
|
`focus-move-focus' runs. It adds `focus-move-focus' to
|
2019-12-03 21:59:28 +00:00
|
|
|
|
`post-command-hook'."
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(focus-cleanup)
|
|
|
|
|
(setq focus-buffer (current-buffer))
|
|
|
|
|
(setq focus-focused-overlay (focus-make-focused-overlay))
|
|
|
|
|
(add-hook 'post-command-hook 'focus-move-focus t t)
|
|
|
|
|
(add-hook 'window-scroll-functions 'focus-move-focus t t)
|
|
|
|
|
(add-hook 'change-major-mode-hook 'focus-cleanup t t)
|
|
|
|
|
(focus-move-focus))
|
|
|
|
|
|
|
|
|
|
(defun focus-cleanup ()
|
2015-05-17 10:36:20 +00:00
|
|
|
|
"This function is run when command `focus-mode' is disabled.
|
|
|
|
|
|
2020-02-22 02:06:40 +00:00
|
|
|
|
Overlays are deleted. `focus-move-focus' is removed from
|
|
|
|
|
`post-command-hook'."
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(let ((overlays (cons focus-focused-overlay focus-unfocused-overlays)))
|
2020-02-22 02:06:40 +00:00
|
|
|
|
(mapc (lambda (o) (and (overlayp o) (delete-overlay o))) overlays)
|
2016-01-11 13:22:48 +00:00
|
|
|
|
(remove-hook 'post-command-hook 'focus-move-focus t)
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(remove-hook 'window-scroll-functions 'focus-move-focus t)
|
|
|
|
|
(setq focus-unfocused-overlays nil
|
|
|
|
|
focus-focused-overlay nil
|
2020-02-22 02:06:40 +00:00
|
|
|
|
focus-last-bounds nil
|
|
|
|
|
focus-last-background nil)))
|
2015-05-11 23:12:32 +00:00
|
|
|
|
|
2015-05-24 15:47:39 +00:00
|
|
|
|
(defun focus-goto-thing (bounds)
|
|
|
|
|
"Move point to the middle of BOUNDS."
|
|
|
|
|
(when bounds
|
|
|
|
|
(goto-char (/ (+ (car bounds) (cdr bounds)) 2))
|
|
|
|
|
(recenter nil)))
|
|
|
|
|
|
2015-11-18 08:15:29 +00:00
|
|
|
|
(defun focus-change-thing ()
|
|
|
|
|
"Adjust the narrowness of the focused section for the current buffer.
|
|
|
|
|
|
|
|
|
|
The variable `focus-mode-to-thing' dictates the default thing
|
|
|
|
|
according to major-mode. If `focus-current-thing' is set, this
|
|
|
|
|
default is overwritten. This function simply helps set the
|
|
|
|
|
`focus-current-thing'."
|
|
|
|
|
(interactive)
|
2020-02-21 21:45:27 +00:00
|
|
|
|
(let* ((candidates '(defun line list org-element paragraph sentence sexp symbol word))
|
2015-11-18 08:15:29 +00:00
|
|
|
|
(thing (completing-read "Thing: " candidates)))
|
|
|
|
|
(setq focus-current-thing (intern thing))))
|
|
|
|
|
|
2016-01-31 22:14:57 +00:00
|
|
|
|
(defun focus-pin ()
|
2019-03-09 14:05:51 +00:00
|
|
|
|
"Pin the focused section to its current location or the region, if active."
|
2016-01-31 22:14:57 +00:00
|
|
|
|
(interactive)
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(when (and (bound-and-true-p focus-mode)
|
|
|
|
|
(region-active-p))
|
|
|
|
|
(setq focus-pin-bounds (cons (region-beginning) (region-end)))))
|
2016-01-31 22:14:57 +00:00
|
|
|
|
|
|
|
|
|
(defun focus-unpin ()
|
|
|
|
|
"Unpin the focused section."
|
|
|
|
|
(interactive)
|
2019-03-09 13:59:30 +00:00
|
|
|
|
(when (bound-and-true-p focus-mode)
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(setq focus-pin-bounds nil)))
|
2016-01-31 22:14:57 +00:00
|
|
|
|
|
2015-05-23 23:56:36 +00:00
|
|
|
|
(defun focus-next-thing (&optional n)
|
2019-03-09 14:05:51 +00:00
|
|
|
|
"Move the point to the middle of the Nth next thing."
|
2015-05-23 23:56:36 +00:00
|
|
|
|
(interactive "p")
|
2015-05-24 15:47:39 +00:00
|
|
|
|
(let ((current-bounds (focus-bounds))
|
|
|
|
|
(thing (focus-get-thing)))
|
|
|
|
|
(forward-thing thing n)
|
|
|
|
|
(when (equal current-bounds (focus-bounds))
|
2016-10-13 06:49:57 +00:00
|
|
|
|
(forward-thing thing (cl-signum n)))
|
2015-05-24 15:47:39 +00:00
|
|
|
|
(focus-goto-thing (focus-bounds))))
|
2015-05-23 23:56:36 +00:00
|
|
|
|
|
|
|
|
|
(defun focus-prev-thing (&optional n)
|
2019-03-09 14:05:51 +00:00
|
|
|
|
"Move the point to the middle of the Nth previous thing."
|
2015-05-23 23:56:36 +00:00
|
|
|
|
(interactive "p")
|
2015-05-24 15:47:39 +00:00
|
|
|
|
(focus-next-thing (- n)))
|
2015-05-24 00:03:46 +00:00
|
|
|
|
|
2017-06-12 14:43:59 +00:00
|
|
|
|
(defun focus-read-only-hide-cursor ()
|
2015-05-24 00:03:46 +00:00
|
|
|
|
"Hide the cursor.
|
|
|
|
|
This function is triggered by the `focus-read-only-blink-timer',
|
|
|
|
|
when `focus-read-only-mode' is activated."
|
2017-06-12 14:43:59 +00:00
|
|
|
|
(with-current-buffer focus-buffer
|
2019-03-09 13:59:30 +00:00
|
|
|
|
(when (and (bound-and-true-p focus-read-only-mode)
|
|
|
|
|
(not (null focus-read-only-blink-timer)))
|
2015-05-24 15:47:39 +00:00
|
|
|
|
(setq focus-read-only-blink-timer nil)
|
|
|
|
|
(setq cursor-type nil))))
|
2015-05-24 00:04:02 +00:00
|
|
|
|
|
|
|
|
|
(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."
|
2017-06-12 14:43:59 +00:00
|
|
|
|
(with-current-buffer focus-buffer
|
2019-03-09 13:59:30 +00:00
|
|
|
|
(when (and (bound-and-true-p focus-read-only-mode)
|
2017-06-12 14:43:59 +00:00
|
|
|
|
(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 focus-cursor-type)
|
|
|
|
|
(setq focus-read-only-blink-timer
|
|
|
|
|
(run-at-time focus-read-only-blink-seconds nil
|
|
|
|
|
'focus-read-only-hide-cursor)))))
|
2015-05-24 00:04:40 +00:00
|
|
|
|
|
2015-05-24 00:41:19 +00:00
|
|
|
|
(defun focus-read-only-init ()
|
|
|
|
|
"Run when `focus-read-only-mode' is activated.
|
|
|
|
|
Enables `read-only-mode', hides the cursor and adds
|
2019-03-09 14:05:51 +00:00
|
|
|
|
`focus-read-only-cursor-blink' to `pre-command-hook'.
|
|
|
|
|
Also `focus-read-only-terminate' is added to the `kill-buffer-hook'."
|
2015-05-24 00:41:19 +00:00
|
|
|
|
(read-only-mode 1)
|
2017-06-12 14:43:59 +00:00
|
|
|
|
(setq cursor-type nil
|
|
|
|
|
focus-buffer (current-buffer))
|
2015-05-24 00:41:19 +00:00
|
|
|
|
(add-hook 'pre-command-hook 'focus-read-only-cursor-blink nil t)
|
2017-06-12 14:43:59 +00:00
|
|
|
|
(add-hook 'kill-buffer-hook 'focus-read-only-terminate nil t))
|
2015-05-24 00:41:19 +00:00
|
|
|
|
|
|
|
|
|
(defun focus-read-only-terminate ()
|
|
|
|
|
"Run when `focus-read-only-mode' is deactivated.
|
2019-03-09 14:05:51 +00:00
|
|
|
|
Disables `read-only-mode' and shows the cursor again.
|
|
|
|
|
It cleans up the `focus-read-only-blink-timer' and hooks."
|
2015-05-24 00:41:19 +00:00
|
|
|
|
(read-only-mode -1)
|
2017-05-20 15:55:40 +00:00
|
|
|
|
(setq cursor-type focus-cursor-type)
|
2015-05-24 00:41:19 +00:00
|
|
|
|
(when focus-read-only-blink-timer
|
|
|
|
|
(cancel-timer focus-read-only-blink-timer))
|
|
|
|
|
(setq focus-read-only-blink-timer nil)
|
|
|
|
|
(remove-hook 'pre-command-hook 'focus-read-only-cursor-blink t)
|
|
|
|
|
(remove-hook 'kill-buffer-hook 'focus-read-only-terminate t))
|
|
|
|
|
|
2019-03-09 14:01:43 +00:00
|
|
|
|
(defun focus-turn-off-focus-read-only-mode ()
|
2015-05-24 00:04:40 +00:00
|
|
|
|
"Turn off `focus-read-only-mode'."
|
|
|
|
|
(interactive)
|
|
|
|
|
(focus-read-only-mode -1))
|
|
|
|
|
|
2015-05-11 22:48:09 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(define-minor-mode focus-mode
|
2015-05-17 10:41:18 +00:00
|
|
|
|
"Dim the font color of text in surrounding sections."
|
2015-05-11 22:48:09 +00:00
|
|
|
|
:init-value nil
|
2015-05-24 00:04:50 +00:00
|
|
|
|
:keymap (let ((map (make-sparse-keymap)))
|
|
|
|
|
(define-key map (kbd "C-c C-q") 'focus-read-only-mode)
|
|
|
|
|
map)
|
2020-03-08 17:32:39 +00:00
|
|
|
|
(if focus-mode (focus-init) (focus-cleanup)))
|
2015-05-12 20:42:01 +00:00
|
|
|
|
|
2015-05-24 00:04:40 +00:00
|
|
|
|
;;;###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)
|
2019-03-09 14:01:43 +00:00
|
|
|
|
(define-key map (kbd "i") 'focus-turn-off-focus-read-only-mode)
|
|
|
|
|
(define-key map (kbd "q") 'focus-turn-off-focus-read-only-mode)
|
2015-05-24 00:04:40 +00:00
|
|
|
|
map)
|
2017-05-20 15:55:40 +00:00
|
|
|
|
(when cursor-type
|
|
|
|
|
(setq focus-cursor-type cursor-type))
|
2015-05-24 00:41:19 +00:00
|
|
|
|
(if focus-read-only-mode (focus-read-only-init) (focus-read-only-terminate)))
|
2015-05-24 00:04:40 +00:00
|
|
|
|
|
2015-05-12 20:42:01 +00:00
|
|
|
|
(provide 'focus)
|
|
|
|
|
;;; focus.el ends here
|