]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/ack/ack.el
Reverted commits 312, 313, and 315.
[gnu-emacs-elpa] / packages / ack / ack.el
index 78bfd81790957f82be0092e30d390eaf59d56b1d..d58a7ff1e8a277307471131a1cbed32e89351bf1 100644 (file)
@@ -1,6 +1,6 @@
 ;;; ack.el --- Emacs interface to ack
 
-;; Copyright (C) 2012  Leo Liu
+;; Copyright (C) 2012  Free Software Foundation, Inc.
 
 ;; Author: Leo Liu <sdl.web@gmail.com>
 ;; Version: 0.8
@@ -57,6 +57,12 @@ environment variable and ~/.ackrc, which you can disable by the
   :type 'string
   :group 'ack)
 
+(defcustom ack-buffer-name-function nil
+  "If non-nil, a function to compute the name of an ack buffer.
+See `compilation-buffer-name-function' for details."
+  :type '(choice function (const nil))
+  :group 'ack)
+
 (defcustom ack-vc-grep-commands
   '((".git" . "git --no-pager grep --color -n -i")
     (".hg" . "hg grep -n -i")
@@ -267,6 +273,13 @@ This gets tacked on the end of the generated expressions.")
                 (ansi-color-apply-on-region beg ack--ansi-color-last-marker))
               nil))))))
 
+(defun ack-update-minibuffer-prompt (prompt)
+  "Visually replace minibuffer prompt with PROMPT."
+  (when (minibufferp)
+    (let ((inhibit-read-only t))
+      (put-text-property
+       (point-min) (minibuffer-prompt-end) 'display prompt))))
+
 (defun ack-skel-file ()
   "Insert a template for case-insensitive file name search."
   (interactive)
@@ -285,10 +298,13 @@ This gets tacked on the end of the generated expressions.")
          (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'"
-                         (substring which 1)))))
+                  (error "No command provided for `%s grep'" backend))))
     (setq project-root root)
+    (ack-update-minibuffer-prompt
+     (format "Run %s grep in `%s': " backend
+             (file-name-nondirectory (directory-file-name project-root))))
     (delete-minibuffer-contents)
     (skeleton-insert '(nil cmd " '" _ "'"))))
 
@@ -338,20 +354,27 @@ minibuffer:
 
 \\{ack-minibuffer-local-map}"
   (interactive
-   (let ((project-root (funcall ack-default-directory-function
-                                current-prefix-arg))
+   (let ((project-root (or (funcall ack-default-directory-function
+                                    current-prefix-arg)
+                           default-directory))
          ;; Disable completion cycling; see http://debbugs.gnu.org/12221
          (completion-cycle-threshold nil))
      (list (minibuffer-with-setup-hook (if (>= emacs-major-version 24)
                                            'shell-completion-vars
                                          'pcomplete-shell-setup)
-             (read-from-minibuffer "Run ack (like this): "
-                                   ack-command ack-minibuffer-local-map
-                                   nil 'ack-history))
+             (read-from-minibuffer
+              (format "Run ack in `%s': "
+                      (file-name-nondirectory
+                       (directory-file-name project-root)))
+              ack-command ack-minibuffer-local-map nil 'ack-history))
            project-root)))
   (let ((default-directory (expand-file-name
                             (or directory default-directory))))
-    (compilation-start command-args 'ack-mode)))
+    ;; Change to the compilation buffer so that `ack-buffer-name-function' can
+    ;; make use of `compilation-arguments'.
+    (with-current-buffer (compilation-start command-args 'ack-mode)
+      (when ack-buffer-name-function
+        (rename-buffer (funcall ack-buffer-name-function "ack"))))))
 
 (provide 'ack)
 ;;; ack.el ends here