]> code.delx.au - gnu-emacs-elpa/commitdiff
New command ggtags-query-replace
authorLeo Liu <sdl.web@gmail.com>
Tue, 4 Jun 2013 06:37:23 +0000 (14:37 +0800)
committerLeo Liu <sdl.web@gmail.com>
Tue, 4 Jun 2013 07:50:33 +0000 (15:50 +0800)
ggtags.el

index 3fa79d0930748610a64b577c228b8f4e17c03d5a..ca82e8cfe616ee31f537ca2dbfd3f290907c8de6 100644 (file)
--- a/ggtags.el
+++ b/ggtags.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2013  Free Software Foundation, Inc.
 
 ;; Author: Leo Liu <sdl.web@gmail.com>
-;; Version: 0.6.5
+;; Version: 0.6.6
 ;; Keywords: tools, convenience
 ;; Created: 2013-01-29
 ;; URL: https://github.com/leoliu/ggtags
@@ -208,10 +208,7 @@ Return -1 if it does not exist."
     (if (ggtags-cache-stale-p root)
         (let* ((default-directory (file-name-as-directory root))
                (tags (with-demoted-errors
-                       (split-string
-                        (with-output-to-string
-                          (call-process "global" nil (list standard-output nil)
-                                        nil "-c" (or prefix "")))))))
+                       (process-lines "global" "-c" (or prefix "")))))
           (and tags (ggtags-cache-set root tags))
           tags)
       (cadr (ggtags-cache-get root)))))
@@ -309,6 +306,33 @@ When called with prefix, ask the name and kind of tag."
       (setq-local compilation-auto-jump-to-first-error nil)
       (remove-hook 'compilation-finish-functions 'ggtags-handle-single-match t))))
 
+(defun ggtags-query-replace (from to &optional delimited directory)
+  "Query replace FROM with TO on all files in DIRECTORY."
+  (interactive
+   (append (query-replace-read-args "Query replace (regexp)" t t)
+           (list (read-directory-name "In directory: " nil nil t))))
+  (let ((default-directory (file-name-as-directory directory)))
+    (ggtags-check-root-directory)
+    (dolist (file (process-lines "global" "-P" "-l" "."))
+      (let ((file (expand-file-name file directory)))
+        (when (file-exists-p file)
+          (let* ((message-log-max nil)
+                 (visited (get-file-buffer file))
+                 (buffer (or visited
+                             (with-demoted-errors
+                               (find-file-noselect file)))))
+            (when buffer
+              (set-buffer buffer)
+              (if (save-excursion
+                    (goto-char (point))
+                    (re-search-forward from nil t))
+                  (progn
+                    (switch-to-buffer (current-buffer))
+                    (perform-replace from to t t delimited
+                                     nil multi-query-replace-map))
+                (message "Nothing to do for `%s'" file)
+                (or visited (kill-buffer))))))))))
+
 (defun ggtags-delete-tag-files ()
   "Delete the tag files generated by gtags."
   (interactive)