Merge branch 'xmlgen-bug-fixes'
[ShellArchive.git] / ack.el
blob5a327392be8cbfc7bca26156b7cf732147936937
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)
38 (require 'grep)
40 (defvar ack-guess-type nil
41 "Setting this value to `t' will have `ack' do its best to fill
42 in the --type argument to the ack command")
44 (defvar ack-command "ack --nocolor --nogroup "
45 "The command to be run by the ack function.")
47 (defvar ack-mode-type-map
48 '(((c++-mode) . "cpp")
49 ((c-mode) . "cc")
50 ((css-mode) . "css")
51 ((emacs-lisp-mode) . "elisp")
52 ((fortran-mode) . "fortran")
53 ((html-mode) . "html")
54 ((xml-mode nxml-mode) . "xml")
55 ((java-mode) . "java")
56 ((lisp-mode) . "lisp")
57 ((perl-mode cperl-mode) . "perl"))
58 "alist describing how to fill in the '--type=' argument to ack")
60 (defun ack-find-type-for-mode ()
61 (catch 'found
62 (dolist (mode-type ack-mode-type-map)
63 (when (member major-mode (car mode-type))
64 (throw 'found (cdr mode-type))))))
66 (defun ack-build-command ()
67 (let ((type (ack-find-type-for-mode)))
68 (concat ack-command
69 (when (and ack-guess-type type)
70 (concat " --type=" type)) " -- ")))
72 (define-compilation-mode ack-mode "Ack"
73 "Ack compilation mode."
74 (set (make-local-variable 'compilation-disable-input) t)
75 (set (make-local-variable 'compilation-error-face)
76 grep-hit-face))
78 ;;;###autoload
79 (defun ack (command-args)
80 (interactive
81 (list (read-from-minibuffer "Run ack (like this): "
82 (ack-build-command)
83 nil
84 nil
85 'ack-history)))
86 (compilation-start command-args 'ack-mode))
88 (provide 'ack)