aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorHugh Brown2016-02-29 16:20:05 +1100
committerLars Ingebrigtsen2016-02-29 16:20:05 +1100
commit90c36173fdcc7dbe1fa150784a4784a9c0cb7bbc (patch)
tree6a3dd4fbfcb4c0c0823406340aa915be6fd4c72a /lisp
parent04289d1cd863fa8cc0c8a9b976a8e27d9a0b4dd1 (diff)
downloademacs-90c36173fdcc7dbe1fa150784a4784a9c0cb7bbc.tar.gz
emacs-90c36173fdcc7dbe1fa150784a4784a9c0cb7bbc.zip
Save buffers before running grep commands
* lisp/progmodes/grep.el (grep-ask-about-save): New variable (bug#96). (grep, lgrep, rgrep): Use it (bug#96). * doc/emacs/building.texi (Grep Searching): Document `grep-save-buffers'. * lisp/progmodes/grep.el (grep-save-buffers): Rename from `grep-ask-about-save'. (grep--save-buffers): New function. (grep, lgrep, rgrep): Use it.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/grep.el28
1 files changed, 28 insertions, 0 deletions
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index f04a7226d18..b035528d4b2 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -227,6 +227,25 @@ to determine whether cdr should not be excluded."
227 (const :tag "No ignored files" nil)) 227 (const :tag "No ignored files" nil))
228 :group 'grep) 228 :group 'grep)
229 229
230;;;###autoload
231(defcustom grep-save-buffers 'ask
232 "If non-nil, save buffers before running the grep commands.
233If `ask', ask before saving. If the variable is a function, it
234will be used as a predicate that should say whether the buffer should
235be saved or not.
236E.g., one can set this to
237 (lambda ()
238 (string-prefix-p my-grep-root (file-truename (buffer-file-name))))
239to limit saving to files located under `my-grep-root'."
240 :version "25.2"
241 :type '(choice
242 (const :tag "Default (ask before saving)" ask)
243 (const :tag "Don't save buffers" nil)
244 (const :tag "Save all buffers" t)
245 function)
246 :type 'boolean
247 :group 'grep)
248
230(defcustom grep-error-screen-columns nil 249(defcustom grep-error-screen-columns nil
231 "If non-nil, column numbers in grep hits are screen columns. 250 "If non-nil, column numbers in grep hits are screen columns.
232See `compilation-error-screen-columns'" 251See `compilation-error-screen-columns'"
@@ -728,6 +747,12 @@ This function is called from `compilation-filter-hook'."
728 grep-error-screen-columns) 747 grep-error-screen-columns)
729 (add-hook 'compilation-filter-hook 'grep-filter nil t)) 748 (add-hook 'compilation-filter-hook 'grep-filter nil t))
730 749
750(defun grep--save-buffers ()
751 (when grep-save-buffers
752 (save-some-buffers (and (not (eq grep-save-buffers 'ask))
753 (not (functionp grep-save-buffers)))
754 (and (functionp grep-save-buffers)
755 grep-save-buffers))))
731 756
732;;;###autoload 757;;;###autoload
733(defun grep (command-args) 758(defun grep (command-args)
@@ -759,6 +784,7 @@ list is empty)."
759 'grep-history 784 'grep-history
760 (if current-prefix-arg nil default)))))) 785 (if current-prefix-arg nil default))))))
761 786
787 (grep--save-buffers)
762 ;; Setting process-setup-function makes exit-message-function work 788 ;; Setting process-setup-function makes exit-message-function work
763 ;; even when async processes aren't supported. 789 ;; even when async processes aren't supported.
764 (compilation-start (if (and grep-use-null-device null-device) 790 (compilation-start (if (and grep-use-null-device null-device)
@@ -952,6 +978,7 @@ This command shares argument histories with \\[rgrep] and \\[grep]."
952 (let ((default-directory dir)) 978 (let ((default-directory dir))
953 ;; Setting process-setup-function makes exit-message-function work 979 ;; Setting process-setup-function makes exit-message-function work
954 ;; even when async processes aren't supported. 980 ;; even when async processes aren't supported.
981 (grep--save-buffers)
955 (compilation-start (if (and grep-use-null-device null-device) 982 (compilation-start (if (and grep-use-null-device null-device)
956 (concat command " " null-device) 983 (concat command " " null-device)
957 command) 984 command)
@@ -1014,6 +1041,7 @@ to specify a command to run."
1014 (read-from-minibuffer "Confirm: " 1041 (read-from-minibuffer "Confirm: "
1015 command nil nil 'grep-find-history)) 1042 command nil nil 'grep-find-history))
1016 (add-to-history 'grep-find-history command)) 1043 (add-to-history 'grep-find-history command))
1044 (grep--save-buffers)
1017 (let ((default-directory dir)) 1045 (let ((default-directory dir))
1018 (compilation-start command 'grep-mode)) 1046 (compilation-start command 'grep-mode))
1019 ;; Set default-directory if we started rgrep in the *grep* buffer. 1047 ;; Set default-directory if we started rgrep in the *grep* buffer.