[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/focus 35f3cf5d52 20/82: Use things as defined in thingatpt
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/focus 35f3cf5d52 20/82: Use things as defined in thingatpt as bounds |
Date: |
Tue, 6 Sep 2022 04:58:55 -0400 (EDT) |
branch: elpa/focus
commit 35f3cf5d520c742eb9786afab0bb43172787295d
Author: Lars Tveito <larstvei@ifi.uio.no>
Commit: Lars Tveito <larstvei@ifi.uio.no>
Use things as defined in thingatpt as bounds
One can customize what sort of bounds should be used for a mode, where
derived modes are used to generalize. By default text-mode and prog-mode
are defined.
---
focus.el | 47 ++++++++++++++++++++++++++++++++++-------------
1 file changed, 34 insertions(+), 13 deletions(-)
diff --git a/focus.el b/focus.el
index e20356f4af..5638e39149 100644
--- a/focus.el
+++ b/focus.el
@@ -31,6 +31,7 @@
;;; Code:
(require 'cl-lib)
+(require 'thingatpt)
(defcustom focus-dimness 0
"When `focus-mode' is enabled, the dimness of the sections that
@@ -43,21 +44,41 @@ and foreground color."
:type '(integer)
:group 'focus)
+(defcustom focus-mode-to-thing '((prog-mode . defun) (text-mode . sentence))
+ "An associated list between mode and thing (defined in
+thingatpt), which determines the narrowness of the focused
+section.
+
+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)
+
(defvar-local focus-pre-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)
- "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)))
-
-(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)))
+(defun focus-any (f lst)
+ "This function takes a function and a list, and returns the
+first NON-NIL value from applying F to an element in LST."
+ (when lst
+ (let ((v (funcall f (car lst))))
+ (if v v (focus-any f (cdr lst))))))
+
+(defun focus-bounds ()
+ "Returns the bounds of the first thing in `focus-things-order' that
+is NON-NIL."
+ (let* ((modes (mapcar 'car focus-things-order))
+ (mode (focus-any 'derived-mode-p modes))
+ (thing (if mode (cdr (assoc mode focus-things-order)) 'sentence)))
+ (bounds-of-thing-at-point thing)))
(defun focus-average-colors (color &rest colors)
"This function takes one or more colors and returns the average
@@ -83,10 +104,10 @@ be generated, and returns this color."
(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)))
- (post (or (focus-search-forward "^\n") (point-max))))
- (move-overlay focus-pre-overlay (point-min) pre)
- (move-overlay focus-post-overlay post (point-max))))
+ (let* ((bounds (focus-bounds)))
+ (when bounds
+ (move-overlay focus-pre-overlay (point-min) (car bounds))
+ (move-overlay focus-post-overlay (cdr bounds) (point-max)))))
(defun focus-init ()
"This function is run when focus-mode is enabled. It sets the
- [nongnu] elpa/focus 3fafdc7947 62/82: Allow explicitly setting derived modes in focus-mode-to-thing, (continued)
- [nongnu] elpa/focus 3fafdc7947 62/82: Allow explicitly setting derived modes in focus-mode-to-thing, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus 9a5cf4f972 77/82: Formatting, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus 663205443c 21/82: Forgot to rename variables everywhere, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus 4d31363bf9 54/82: Use cl-lib function instead of cl.el, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus af9fbfd9cb 06/82: Changed name and added header, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus 02cec3494d 01/82: Initial commit, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus e691113e4b 03/82: Moved init/termination to separate functions, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus 284a1240ce 33/82: Cleaned up doc in `focus-average-colors', ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus 58a91b29aa 34/82: Split focus-bounds into two functions, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus ac711fe13a 35/82: Whitespace cleanup, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus 35f3cf5d52 20/82: Use things as defined in thingatpt as bounds,
ELPA Syncer <=
- [nongnu] elpa/focus 871f3c60ce 48/82: Fixed matching parenthesis, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus fe94e0de69 43/82: Split activation/deactivation into functions, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus 2fbf024c53 79/82: Fix bug introduced in d5631db, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus 6add57b887 59/82: Fix indentation, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus 563a3bd188 47/82: Updated README, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus d1bd81ee4d 39/82: Added focus-read-only-mode, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus 4c8391ea32 29/82: Fixed bug in defgroup, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus b21341bd40 38/82: Added function for briefly showing the cursor, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus 246eaeb8d1 72/82: Define faces for the unfocused and focused regions, ELPA Syncer, 2022/09/06
- [nongnu] elpa/focus b90cfb3c27 50/82: Fix #4, ELPA Syncer, 2022/09/06