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