forked from mhayashi1120/Emacs-wgrep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwgrep-ag.el
72 lines (53 loc) · 2.11 KB
/
wgrep-ag.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
;;; wgrep-ag.el --- Writable ag buffer and apply the changes to files
;; Author: Masahiro Hayashi <[email protected]>
;; Keywords: grep edit extensions
;; Package-Requires: ((wgrep "2.1.5"))
;; URL: http://github.com/mhayashi1120/Emacs-wgrep/raw/master/wgrep-ag.el
;; Emacs: GNU Emacs 22 or later
;; Version: 0.1.3
;; 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 3, 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 GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; wgrep-ag allows you to edit a ag buffer and apply those changes to
;; the file buffer.
;;; Install:
;; 1. Install ag.el
;;
;; https://github.com/Wilfred/ag.el
;; 2. Install wgrep.el
;; 3. Put this file into load-path'ed directory, and byte compile it if
;; desired. And put the following expression into your ~/.emacs.
;;
;; (autoload 'wgrep-ag-setup "wgrep-ag")
;; (add-hook 'ag-mode-hook 'wgrep-ag-setup)
;;; Usage:
;; See wgrep.el
;;; Code:
(require 'wgrep)
;;;###autoload
(defun wgrep-ag-setup ()
;; ag.el prints a column number too, so we catch that
;; if it exists. Here \2 is a colon + whitespace separator. This
;; might need to change if (caar grep-regexp-alist) does.
(set (make-local-variable 'wgrep-line-file-regexp)
(concat
wgrep-default-line-header-regexp
"\\(?:\\([1-9][0-9]*\\)\\2\\)?"))
(wgrep-setup-internal))
;;;###autoload
(add-hook 'ag-mode-hook 'wgrep-ag-setup)
;; For `unload-feature'
(defun wgrep-ag-unload-function ()
(remove-hook 'ag-mode-hook 'wgrep-ag-setup))
(provide 'wgrep-ag)
;;; wgrep-ag.el ends here