diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 048fa11..27afc80 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -227,6 +227,28 @@ to determine whether cdr should not be excluded." (const :tag "No ignored files" nil)) :group 'grep) +;;;###autoload +(defcustom grep-ask-about-save t + "Non-nil means \\[grep], \\[lgrep] and \\[rgrep] ask which buffers to save before running. +Otherwise, it saves all modified buffers without asking." + :type 'boolean + :group 'grep) + +(defcustom grep-save-buffers-predicate nil + "The second argument (PRED) passed to `save-some-buffers' before compiling. +E.g., one can set this to + (lambda () + (string-prefix-p my-grep-root (file-truename (buffer-file-name)))) +to limit saving to files located under `my-grep-root'. +Note, that, in general, `grep-directory' cannot be used instead +of `my-grep-root' here." + :type '(choice + (const :tag "Default (save all file-visiting buffers)" nil) + (const :tag "Save all buffers" t) + function) + :group 'grep + :version "25.1") + (defcustom grep-error-screen-columns nil "If non-nil, column numbers in grep hits are screen columns. See `compilation-error-screen-columns'" @@ -753,6 +775,8 @@ list is empty)." 'grep-history (if current-prefix-arg nil default)))))) + (save-some-buffers (not grep-ask-about-save) + grep-save-buffers-predicate) ;; Setting process-setup-function makes exit-message-function work ;; even when async processes aren't supported. (compilation-start (if (and grep-use-null-device null-device) @@ -937,6 +961,8 @@ This command shares argument histories with \\[rgrep] and \\[grep]." (let ((default-directory dir)) ;; Setting process-setup-function makes exit-message-function work ;; even when async processes aren't supported. + (save-some-buffers (not grep-ask-about-save) + grep-save-buffers-predicate) (compilation-start (if (and grep-use-null-device null-device) (concat command " " null-device) command) @@ -1050,6 +1076,8 @@ to specify a command to run." (read-from-minibuffer "Confirm: " command nil nil 'grep-find-history)) (add-to-history 'grep-find-history command)) + (save-some-buffers (not grep-ask-about-save) + grep-save-buffers-predicate) (let ((default-directory dir)) (compilation-start command 'grep-mode)) ;; Set default-directory if we started rgrep in the *grep* buffer.