Prove rename function now a bit smarter.
[ShellArchive.git] / ack.el
blob2615f9ed13a984ae431b9bbafe36f3a64e419b58
1 ;;; ack.el --- Use ack where you might usually use grep.
3 ;; Copyright (C) 2008 Philip Jackson
5 ;; Author: Philip Jackson <phil@shellarchive.co.uk>
6 ;; Version: 0.4
8 ;; This file is not currently part of GNU Emacs.
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program ; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; Commentary:
27 ;; ack.el provides a simple compilation mode for the perl grep-a-like
28 ;; ack (http://petdance.com/ack/).
30 ;; If `ack-guess-type' is non-nil and `ack-mode-type-map' has a
31 ;; reasonable value then ack.el will try and guess what you would like
32 ;; in the --type argument for ack.
34 ;; To install/use put ack.el in your load-path and (require 'ack) in
35 ;; your initialisation file. You can then M-x ack and you're off.
37 (require 'compile)
39 (defvar ack-guess-type nil
40 "Setting this value to `t' will have `ack' do its best to fill
41 in the --type argument to the ack command")
43 (defvar ack-command "ack --nocolor --nogroup "
44 "The command to be run by the ack function.")
46 (defvar ack-mode-type-map
47 '(((c++-mode) . "cpp")
48 ((c-mode) . "cc")
49 ((css-mode) . "css")
50 ((emacs-lisp-mode) . "elisp")
51 ((fortran-mode) . "fortran")
52 ((html-mode) . "html")
53 ((xml-mode nxml-mode) . "xml")
54 ((java-mode) . "java")
55 ((lisp-mode) . "lisp")
56 ((perl-mode cperl-mode) . "perl"))
57 "alist describing how to fill in the '--type=' argument to ack")
59 (defun ack-find-type-for-mode ()
60 (catch 'found
61 (dolist (mode-type ack-mode-type-map)
62 (when (member major-mode (car mode-type))
63 (throw 'found (cdr mode-type))))))
65 (defun ack-build-command ()
66 (let ((type (ack-find-type-for-mode)))
67 (concat ack-command
68 (when (and ack-guess-type type)
69 (concat " --type=" type)) " -- ")))
71 (define-compilation-mode ack-mode "Ack"
72 "Ack compilation mode."
73 (set (make-local-variable 'compilation-disable-input) t)
74 (set (make-local-variable 'compilation-error-face)
75 grep-hit-face))
77 ;;;###autoload
78 (defun ack (command-args)
79 (interactive
80 (list (read-from-minibuffer "Run ack (like this): "
81 (ack-build-command)
82 nil
83 nil
84 'ack-history)))
85 (compilation-start command-args 'ack-mode))
87 (provide 'ack)