mirror of
https://github.com/larstvei/Focus.git
synced 2024-11-26 11:38:32 +00:00
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`.
This commit is contained in:
parent
871f3c60ce
commit
0a6e9624ea
28
focus.el
28
focus.el
@ -5,7 +5,7 @@
|
|||||||
;; Author: Lars Tveito <larstvei@ifi.uio.no>
|
;; Author: Lars Tveito <larstvei@ifi.uio.no>
|
||||||
;; URL: http://github.com/larstvei/Focus
|
;; URL: http://github.com/larstvei/Focus
|
||||||
;; Created: 11th May 2015
|
;; Created: 11th May 2015
|
||||||
;; Version: 0.0.2
|
;; Version: 0.1.0
|
||||||
;; Package-Requires: ((emacs "24") (cl-lib "0.5"))
|
;; Package-Requires: ((emacs "24") (cl-lib "0.5"))
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
;; 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)
|
:type '(float)
|
||||||
:group 'focus)
|
: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
|
(defvar 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.")
|
||||||
|
|
||||||
@ -82,13 +85,15 @@ The timer calls `focus-read-only-hide-cursor' after
|
|||||||
`focus-read-only-blink-seconds' seconds.")
|
`focus-read-only-blink-seconds' seconds.")
|
||||||
|
|
||||||
;; Use make-local-variable for backwards compatibility.
|
;; Use make-local-variable for backwards compatibility.
|
||||||
(dolist (var '(focus-pre-overlay
|
(dolist (var '(focus-current-thing
|
||||||
|
focus-pre-overlay
|
||||||
focus-post-overlay
|
focus-post-overlay
|
||||||
focus-read-only-blink-timer))
|
focus-read-only-blink-timer))
|
||||||
(make-local-variable var))
|
(make-local-variable var))
|
||||||
|
|
||||||
;; Changing major-mode should not affect Focus mode.
|
;; Changing major-mode should not affect Focus mode.
|
||||||
(dolist (var '(focus-pre-overlay
|
(dolist (var '(focus-current-thing
|
||||||
|
focus-pre-overlay
|
||||||
focus-post-overlay
|
focus-post-overlay
|
||||||
post-command-hook))
|
post-command-hook))
|
||||||
(put var 'permanent-local t))
|
(put var 'permanent-local t))
|
||||||
@ -101,9 +106,10 @@ The timer calls `focus-read-only-hide-cursor' after
|
|||||||
|
|
||||||
(defun focus-get-thing ()
|
(defun focus-get-thing ()
|
||||||
"Return the current thing, based on `focus-mode-to-thing'."
|
"Return the current thing, based on `focus-mode-to-thing'."
|
||||||
|
(or focus-current-thing
|
||||||
(let* ((modes (mapcar 'car focus-mode-to-thing))
|
(let* ((modes (mapcar 'car focus-mode-to-thing))
|
||||||
(mode (focus-any 'derived-mode-p modes)))
|
(mode (focus-any 'derived-mode-p modes)))
|
||||||
(if mode (cdr (assoc mode focus-mode-to-thing)) 'sentence)))
|
(if mode (cdr (assoc mode focus-mode-to-thing)) 'sentence))))
|
||||||
|
|
||||||
(defun focus-bounds ()
|
(defun focus-bounds ()
|
||||||
"Return the current bounds, based on `focus-get-thing'."
|
"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))
|
(goto-char (/ (+ (car bounds) (cdr bounds)) 2))
|
||||||
(recenter nil)))
|
(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)
|
(defun focus-next-thing (&optional n)
|
||||||
"Moves the point to the middle of the Nth next thing."
|
"Moves the point to the middle of the Nth next thing."
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
|
Loading…
Reference in New Issue
Block a user