changelog shortlog tags changeset files revisions annotate raw

ack.el

changeset 66: 5b737eefe5ea
author: kim.vanwyk
date: Wed Nov 10 15:19:03 2010 +0200 (18 months ago)
permissions: -rw-r--r--
description: Adding CSharp Mode and Google Weather
1;;; ack.el --- Use ack where you might usually use grep.
2
3;; Copyright (C) 2008 Philip Jackson
4
5;; Author: Philip Jackson <phil@shellarchive.co.uk>
6;; Version: 0.4
7
8;; This file is not currently part of GNU Emacs.
9
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.
14
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.
19
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.
24
25;;; Commentary:
26
27;; ack.el provides a simple compilation mode for the perl grep-a-like
28;; ack (http://petdance.com/ack/).
29
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.
33
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.
36
37(require 'compile)
38
39(defvar ack-guess-type nil
40 "Setting this value to `t' will have `ack' do its best to fill
41in the --type argument to the ack command")
42
43(defvar ack-command "ack --nocolor --nogroup"
44 "The command to be run by the ack function.")
45
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")
58
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))))))
64
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)) " -- ")))
70
71(define-compilation-mode ack-mode "Ack"
72 "Ack compilation mode."
73 nil)
74
75;;;###autoload
76(defun ack (command-args)
77 (interactive
78 (list (read-from-minibuffer "Run ack (like this): "
79 (ack-build-command)
80 nil
81 nil
82 'ack-history)))
83 (compilation-start command-args 'ack-mode))
84
85(provide 'ack)