[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)
- [elpa] master 05e5c4d 06/36: README.md: mention avy-goto-line -> goto-line, (continued)
- [elpa] master 05e5c4d 06/36: README.md: mention avy-goto-line -> goto-line, Oleh Krehel, 2015/05/19
- [elpa] master 755c25a 09/36: Add a new face for 'at-full style, Oleh Krehel, 2015/05/19
- [elpa] master cd8e626 02/36: avy-jump.el (avy-dowindows): Simplify, Oleh Krehel, 2015/05/19
- [elpa] master 3716cd0 03/36: avy-jump.el (avy-goto-subword-0): Update candidate order, Oleh Krehel, 2015/05/19
- [elpa] master dfbf0e2 13/36: targets/avy-init.el: Update, Oleh Krehel, 2015/05/19
- [elpa] master 60dd24b 12/36: Update avy-jump mentions in the README, Oleh Krehel, 2015/05/19
- [elpa] master a08b049 04/36: Fix jumping to newlines with at-full style, Oleh Krehel, 2015/05/19
- [elpa] master eed8f6f 15/36: avy.el (avy--regex-candidates): Add optional group arg, Oleh Krehel, 2015/05/19
- [elpa] master 0d83599 16/36: Update group name, Oleh Krehel, 2015/05/19
- [elpa] master ca69b1f 14/36: Add debug declarations, Oleh Krehel, 2015/05/19
- [elpa] master a53ffb7 05/36: Allow to break from `avy-goto-line' into `goto-line',
Oleh Krehel <=
- [elpa] master ca302b4 08/36: targets/avy-init.el: Move, Oleh Krehel, 2015/05/19
- [elpa] master b0512fc 21/36: avy.el (avy--overlay-at): Use `avy--overlay-offset', Oleh Krehel, 2015/05/19
- [elpa] master 04d26c4 07/36: avy-jump.el (avy-case-fold-search): New defcustom, Oleh Krehel, 2015/05/19
- [elpa] master b602a56 17/36: Stop 'at-full from shifting text, Oleh Krehel, 2015/05/19
- [elpa] master ea6f5c5 25/36: Customize how `avy-lead-face-0' is applied, Oleh Krehel, 2015/05/19
- [elpa] master 8efed40 20/36: Add `avy-lead-face-1' for dimmed matched chars, Oleh Krehel, 2015/05/19
- [elpa] master 410c4ac 11/36: Merge avy-jump.el into avy.el, Oleh Krehel, 2015/05/19
- [elpa] master 7433f30 18/36: With 'at-full style, use full len to check for overlap, Oleh Krehel, 2015/05/19
- [elpa] master f0694a2 23/36: Remove empty line after original one being moved, Oleh Krehel, 2015/05/19
- [elpa] master 1127467 24/36: avy.el (avy-move-line): Use ARG lines, Oleh Krehel, 2015/05/19