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

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

[elpa] master a53ffb7 05/36: Allow to break from `avy-goto-line' into `g


From: Oleh Krehel
Subject: [elpa] master a53ffb7 05/36: Allow to break from `avy-goto-line' into `goto-line'
Date: Tue, 19 May 2015 12:38:08 +0000

branch: master
commit a53ffb7cec37ff69bc48f95ef072b8716fddf655
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Allow to break from `avy-goto-line' into `goto-line'
    
    * avy.el (avy-handler-default): New defun.
    (avy-handler-function): New variable. Bind this temporarily to catch bad 
chars.
    (avy-read): Forward to `avy-handler-default'.
    
    * avy-jump.el (avy--goto): Consider the case of 'exit symbol being
      returned.
    (avy-goto-line): Bind `avy-handler-function' to catch digits and call
    `goto-line' in that case.
    
    Fixes #29
---
 avy-jump.el |   34 +++++++++++++++++++++++++---------
 avy.el      |   11 +++++++++--
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/avy-jump.el b/avy-jump.el
index 93569d0..0edb29a 100644
--- a/avy-jump.el
+++ b/avy-jump.el
@@ -137,14 +137,19 @@ When nil, punctuation chars will not be matched.
   "Goto X.
 X is (POS . WND)
 POS is either a position or (BEG . END)."
-  (if (null x)
-      (message "zero candidates")
-    (select-window (cdr x))
-    (let ((pt (car x)))
-      (when (consp pt)
-        (setq pt (car pt)))
-      (unless (= pt (point)) (push-mark))
-      (goto-char pt))))
+  (cond ((null x)
+         (message "zero candidates"))
+
+        ;; ignore exit from `avy-handler-function'
+        ((eq x 'exit))
+
+        (t
+         (select-window (cdr x))
+         (let ((pt (car x)))
+           (when (consp pt)
+             (setq pt (car pt)))
+           (unless (= pt (point)) (push-mark))
+           (goto-char pt)))))
 
 (defun avy--process (candidates overlay-fn)
   "Select one of CANDIDATES using `avy-read'.
@@ -474,7 +479,18 @@ The window scope is determined by `avy-all-windows' (ARG 
negates it)."
 The window scope is determined by `avy-all-windows' (ARG negates it)."
   (interactive "P")
   (avy--with-avy-keys avy-goto-line
-    (avy--goto (avy--line arg))))
+    (let ((avy-handler-function
+           (lambda (char)
+             (if (or (< char ?0)
+                     (> char ?9))
+                 (avy-handler-default char)
+               (let ((line (read-from-minibuffer
+                            "Goto line: " (string char))))
+                 (when line
+                   (goto-char (point-min))
+                   (forward-line (1- (string-to-number line)))
+                   (throw 'done 'exit)))))))
+      (avy--goto (avy--line arg)))))
 
 ;;;###autoload
 (defun avy-copy-line (arg)
diff --git a/avy.el b/avy.el
index da1f747..5bcf020 100644
--- a/avy.el
+++ b/avy.el
@@ -109,6 +109,14 @@ KEYS is the path from the root of `avy-tree' to LEAF."
           (funcall walker key (cddr br))
         (avy-traverse (cdr br) walker key)))))
 
+(defun avy-handler-default (char)
+  "The default hander for a bad CHAR."
+  (signal 'user-error (list "No such candidate" char))
+  (throw 'done nil))
+
+(defvar avy-handler-function 'avy-handler-default
+  "A function to call for a bad `read-char' in `avy-read'.")
+
 (defun avy-read (tree display-fn cleanup-fn)
   "Select a leaf from TREE using consecutive `read-char'.
 
@@ -127,8 +135,7 @@ multiple DISPLAY-FN invokations."
         (if (setq branch (assoc char tree))
             (if (eq (car (setq tree (cdr branch))) 'leaf)
                 (throw 'done (cdr tree)))
-          (signal 'user-error (list "No such candidate" char))
-          (throw 'done nil))))))
+          (funcall avy-handler-function char))))))
 
 (provide 'avy)
 



reply via email to

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