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

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

[nongnu] elpa/focus 0a6e9624ea 49/82: Allow for changing the current thi


From: ELPA Syncer
Subject: [nongnu] elpa/focus 0a6e9624ea 49/82: Allow for changing the current thing interactively
Date: Tue, 6 Sep 2022 04:58:57 -0400 (EDT)

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

    Allow for changing the current thing interactively
    
    The `focus-mode-to-thing` variable dictates what thing to use according
    to the currently enabled mode. Changing this if you only wished to
    change the thing for a single session seems tedious. Now this can be
    achieved by `M-x focus-change-thing`.
---
 focus.el | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/focus.el b/focus.el
index 46a7ad353e..3d492cf1f8 100644
--- a/focus.el
+++ b/focus.el
@@ -5,7 +5,7 @@
 ;; Author: Lars Tveito <larstvei@ifi.uio.no>
 ;; URL: http://github.com/larstvei/Focus
 ;; Created: 11th May 2015
-;; Version: 0.0.2
+;; Version: 0.1.0
 ;; Package-Requires: ((emacs "24") (cl-lib "0.5"))
 
 ;; This program is free software; you can redistribute it and/or modify
@@ -70,6 +70,9 @@ Things that are defined include `symbol', `list', `sexp',
   :type '(float)
   :group 'focus)
 
+(defvar focus-current-thing nil
+  "Overrides the choice of thing dictated by `focus-mode-to-thing' if set.")
+
 (defvar focus-pre-overlay nil
   "The overlay that dims the text prior to the current-point.")
 
@@ -82,13 +85,15 @@ The timer calls `focus-read-only-hide-cursor' after
 `focus-read-only-blink-seconds' seconds.")
 
 ;; Use make-local-variable for backwards compatibility.
-(dolist (var '(focus-pre-overlay
+(dolist (var '(focus-current-thing
+               focus-pre-overlay
                focus-post-overlay
                focus-read-only-blink-timer))
   (make-local-variable var))
 
 ;; Changing major-mode should not affect Focus mode.
-(dolist (var '(focus-pre-overlay
+(dolist (var '(focus-current-thing
+               focus-pre-overlay
                focus-post-overlay
                post-command-hook))
   (put var 'permanent-local t))
@@ -101,9 +106,10 @@ The timer calls `focus-read-only-hide-cursor' after
 
 (defun focus-get-thing ()
   "Return the current thing, based on `focus-mode-to-thing'."
-  (let* ((modes (mapcar 'car focus-mode-to-thing))
-         (mode  (focus-any 'derived-mode-p modes)))
-    (if mode (cdr (assoc mode focus-mode-to-thing)) 'sentence)))
+  (or focus-current-thing
+   (let* ((modes (mapcar 'car focus-mode-to-thing))
+          (mode  (focus-any 'derived-mode-p modes)))
+     (if mode (cdr (assoc mode focus-mode-to-thing)) 'sentence))))
 
 (defun focus-bounds ()
   "Return the current bounds, based on `focus-get-thing'."
@@ -168,6 +174,20 @@ deleted, and `focus-move-focus' is removed from 
`post-command-hook'."
     (goto-char (/ (+ (car bounds) (cdr bounds)) 2))
     (recenter nil)))
 
+(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)
+  (let* ((candidates '(symbol list sexp defun
+                      filename url email word
+                      sentence whitespace line page))
+         (thing (completing-read "Thing: " candidates)))
+    (setq focus-current-thing (intern thing))))
+
 (defun focus-next-thing (&optional n)
   "Moves the point to the middle of the Nth next thing."
   (interactive "p")



reply via email to

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