[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 8556274 045/110: avy.el (avy-org-goto-heading-timer): Simp
From: |
Oleh Krehel |
Subject: |
[elpa] master 8556274 045/110: avy.el (avy-org-goto-heading-timer): Simplify |
Date: |
Sat, 11 May 2019 10:15:40 -0400 (EDT) |
branch: master
commit 8556274978be5ca2947777dc5e28f5487e069449
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
avy.el (avy-org-goto-heading-timer): Simplify
Re #214
---
avy.el | 55 ++++++++++++++++++++++---------------------------------
1 file changed, 22 insertions(+), 33 deletions(-)
diff --git a/avy.el b/avy.el
index 0eabc4c..64353a6 100644
--- a/avy.el
+++ b/avy.el
@@ -560,33 +560,16 @@ multiple DISPLAY-FN invokations."
"Read one or many characters and jump to matching Org headings.
The window scope is determined by `avy-all-windows' (ARG negates it)."
(interactive "P")
- (let* ((avy-all-windows (if arg
- (not avy-all-windows)
- avy-all-windows))
- (input (avy--read-string-with-timeout))
- (regexp (rx-to-string `(seq bol (1+ "*") (1+ space) (0+ not-newline)
- ,input (0+ not-newline) eol))))
+ (let ((avy-all-windows (if arg
+ (not avy-all-windows)
+ avy-all-windows)))
(avy-with avy-goto-char-timer
- (avy--process (avy--regex-candidates regexp)
- (avy--style-fn avy-style)))))
-
-(defun avy--read-string-with-timeout ()
- "Read string from minibuffer with a timeout."
- ;; It's a shame that only `read-char' has the timeout option, so we
- ;; have to do this funky loop ourselves, instead of
- ;; e.g. `read-string' with a timeout.
- (cl-loop with charnum
- with string = ""
- while (not (equal 13 charnum))
- for charnum = (read-char (format "Prompt: %s" string )
- t
- (unless (string-empty-p string)
- avy-timeout-seconds))
- if (and charnum
- (not (equal 13 charnum)))
- concat (make-string 1 charnum) into string
- else do (setq charnum 13)
- finally return string))
+ (avy--process
+ (avy--read-candidates
+ (lambda (input)
+ (format "^\\*+ .*\\(%s\\)" input)))
+ (avy--style-fn avy-style))
+ (org-back-to-heading))))
;;** Rest
(defun avy-window-list ()
@@ -1809,7 +1792,7 @@ newline."
"How many seconds to wait for the second char."
:type 'float)
-(defun avy--read-candidates ()
+(defun avy--read-candidates (&optional re-builder)
"Read as many chars as possible and return their occurences.
At least one char must be read, and then repeatedly one next char
may be read if it is entered before `avy-timeout-seconds'. `C-h'
@@ -1817,8 +1800,14 @@ or `DEL' deletes the last char entered, and `RET' exits
with the
currently read string immediately instead of waiting for another
char for `avy-timeout-seconds'.
The format of the result is the same as that of `avy--regex-candidates'.
-This function obeys `avy-all-windows' setting."
- (let ((str "") char break overlays regex)
+This function obeys `avy-all-windows' setting.
+RE-BUILDER is a function that takes a string and returns a regex.
+When nil, `regexp-quote' is used.
+If a group is captured, the first group is highlighted.
+Otherwise, the whole regex is highlighted."
+ (let ((str "")
+ (re-builder (or re-builder #'regexp-quote))
+ char break overlays regex)
(unwind-protect
(progn
(while (and (not break)
@@ -1856,12 +1845,12 @@ This function obeys `avy-all-windows' setting."
(window-end (selected-window) t)))
(save-excursion
(goto-char (car pair))
- (setq regex (regexp-quote str))
+ (setq regex (funcall re-builder str))
(while (re-search-forward regex (cdr pair) t)
(unless (get-char-property (1- (point)) 'invisible)
- (let ((ov (make-overlay
- (match-beginning 0)
- (match-end 0))))
+ (let* ((idx (if (= (length (match-data)) 4) 1 0))
+ (ov (make-overlay
+ (match-beginning idx) (match-end idx))))
(setq found t)
(push ov overlays)
(overlay-put
- [elpa] master dee0284 056/110: avy.el (avy-action-kill-move): Adjust for avy-goto-line, (continued)
- [elpa] master dee0284 056/110: avy.el (avy-action-kill-move): Adjust for avy-goto-line, Oleh Krehel, 2019/05/11
- [elpa] master 56f6590 054/110: avy.el (avy-action-copy): Adjust for avy-goto-line, Oleh Krehel, 2019/05/11
- [elpa] master c08fc7c 049/110: Add option to match newline in avy-goto-char-timer, Oleh Krehel, 2019/05/11
- [elpa] master 245b5d6 046/110: avy.el: Fix compile warnings, Oleh Krehel, 2019/05/11
- [elpa] master 0ed6408 043/110: avy.el: Fix checkdoc warnings, Oleh Krehel, 2019/05/11
- [elpa] master 36f768d 047/110: avy.el (avy-words): Specify custom type, Oleh Krehel, 2019/05/11
- [elpa] master 9103291 048/110: Update description to be easier to understand., Oleh Krehel, 2019/05/11
- [elpa] master f4c45d3 044/110: avy.el: Add org-mode commands for jumping to and refiling headings, Oleh Krehel, 2019/05/11
- [elpa] master 4af1993 053/110: avy.el (avy-read): Update avy-current-path before returning, Oleh Krehel, 2019/05/11
- [elpa] master 176f34f 051/110: avy.el (avy-handler-default): Error msg on mouse clicks, Oleh Krehel, 2019/05/11
- [elpa] master 8556274 045/110: avy.el (avy-org-goto-heading-timer): Simplify,
Oleh Krehel <=
- [elpa] master 83859c3 040/110: avy.el: Add new avy-style to use words as sequences, Oleh Krehel, 2019/05/11
- [elpa] master 240d717 041/110: Makefile: Add target checkdoc to check documentation guidelines of lisp files, Oleh Krehel, 2019/05/11
- [elpa] master 3980c03 035/110: avy.el (avy-move-region): Insert in original window, Oleh Krehel, 2019/05/11
- [elpa] master 54bce2c 036/110: avy.el (avy-move-region): Update, Oleh Krehel, 2019/05/11
- [elpa] master 49b070d 042/110: avy-test.el: Fix checkdoc warnings, Oleh Krehel, 2019/05/11
- [elpa] master 228ed97 039/110: avy.el (avy-action-teleport): Add and bind to "t", Oleh Krehel, 2019/05/11
- [elpa] master f2bedee 038/110: Allow "C-h" to delete for avy-goto-char-timer, Oleh Krehel, 2019/05/11
- [elpa] master d609eb9 033/110: Add avy-goto-word-0-below and avy-goto-word-0-above, Oleh Krehel, 2019/05/11
- [elpa] master b8d7163 032/110: avy.el (avy-action-goto): Add raise-frame, Oleh Krehel, 2019/05/11
- [elpa] master 07153e4 026/110: Add kill and save region functionality., Oleh Krehel, 2019/05/11