[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master c84b434 1/8: Nicer behaviour from ack-skel-vc-grep when us
From: |
João Távora |
Subject: |
[elpa] master c84b434 1/8: Nicer behaviour from ack-skel-vc-grep when used in setup hook |
Date: |
Fri, 15 Mar 2019 18:33:10 -0400 (EDT) |
branch: master
commit c84b434c7c731057ec2b0f4fffd71c1a82c58dde
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Nicer behaviour from ack-skel-vc-grep when used in setup hook
Close #9, close #10.
Previously, if the user had ack-skel-vc-grep in the
ack-minibuffer-setup-hook and chose a directory without a vc project,
C-u C-u M-x ack would fail because ack-skel-vc-grep raised an error,
since it can't work under those circunstances. This commit makes it
give up in these situations and leave the (presumably ack) prompt
unchanged.
Additionally, if the user chose a subdirectory *within* a vc project,
C-u C-u M-x ack would surprisingly change the directory to the vc
project root. While this is probably intended in interactive calls to
ack-skel-vc-grep, it is not when that function is in the
ack-minibuffer-setup-hook.
* ack.el (ack-skel-vc-grep): Overhaul function. Distinguish
between interactive and non-interactive uses.
---
ack.el | 54 +++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 39 insertions(+), 15 deletions(-)
diff --git a/ack.el b/ack.el
index 11c1f93..fa2685a 100644
--- a/ack.el
+++ b/ack.el
@@ -279,21 +279,45 @@ This gets tacked on the end of the generated
expressions.")
;; Work around bug http://debbugs.gnu.org/13811
(defvar ack--project-root nil) ; dynamically bound in `ack'
-(defun ack-skel-vc-grep ()
- "Insert a template for vc grep search."
- (interactive)
- (let* ((regexp (concat "\\`" (regexp-opt
- (mapcar 'car ack-vc-grep-commands))
- "\\'"))
- (root (or (ack-guess-project-root default-directory regexp)
- (error "Cannot locate vc project root")))
- (which (car (directory-files root nil regexp)))
- (backend (downcase (substring which 1)))
- (cmd (or (cdr (assoc which ack-vc-grep-commands))
- (error "No command provided for `%s grep'" backend))))
- (setq ack--project-root root)
- (delete-minibuffer-contents)
- (skeleton-insert `(nil ,cmd " '" _ "'"))))
+(defun ack-skel-vc-grep (&optional interactive)
+ "Find a vc-controlled dir, insert a template for a vc grep search.
+If called interactively, INTERACTIVE is non-nil and calls to this
+function that cannot locate such a directory will produce an
+error, whereas in non-interactive calls they will silently exit,
+leaving the minibuffer unchanged.
+
+This function is a suitable addition to
+`ack-minibuffer-setup-hook'."
+ (interactive "p")
+ (catch 'giveup
+ (let* ((regexp (concat "\\`" (regexp-opt
+ (mapcar 'car ack-vc-grep-commands))
+ "\\'"))
+ (guessed-root (or (ack-guess-project-root ack--project-root regexp)
+ (if interactive
+ (user-error
+ "Cannot locate a vc project root from %s"
+ ack--project-root)
+ (throw 'giveup nil))))
+ (which (progn
+ (unless (or interactive
+ (equal
+ (file-truename ack--project-root)
+ (file-truename guessed-root)))
+ ;; See github
+ ;; https://github.com/leoliu/ack-el/issues/10
+ ;; for the reason for giving up here
+ ;; non-interactively.
+ (throw 'giveup nil))
+ (car (directory-files guessed-root nil regexp))))
+ (backend (downcase (substring which 1)))
+ (cmd (or (cdr (assoc which ack-vc-grep-commands))
+ (error "No command provided for `%s grep'" backend))))
+ (when interactive
+ (setq ack--project-root guessed-root)
+ (ack-update-minibuffer-prompt))
+ (delete-minibuffer-contents)
+ (skeleton-insert `(nil ,cmd " '" _ "'")))))
(defun ack-yank-symbol-at-point ()
"Yank the symbol from the window before entering the minibuffer."
- [elpa] master updated (dd10f4a -> 5c25a7d), João Távora, 2019/03/15
- [elpa] master 5c25a7d 8/8: Update packages/ack from upstream, João Távora, 2019/03/15
- [elpa] master ac696cd 6/8: Fix search directly from *ack* but in different dir, João Távora, 2019/03/15
- [elpa] master bc671ba 7/8: * ack.el (Version): Bump to 1.6, João Távora, 2019/03/15
- [elpa] master 6c65a62 5/8: * README.rst (Usage): fix rst formatting, João Távora, 2019/03/15
- [elpa] master a8857c1 4/8: * README.rst (Usage): Mention ack-minibuffer-setup-hook., João Távora, 2019/03/15
- [elpa] master 47a417d 3/8: Make myself the maintainer of this project, João Távora, 2019/03/15
- [elpa] master c84b434 1/8: Nicer behaviour from ack-skel-vc-grep when used in setup hook,
João Távora <=
- [elpa] master 382109a 2/8: ack-skel-vc-grep recalls previously inserted symbol, if any, João Távora, 2019/03/15