aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugh Brown2016-02-29 16:20:05 +1100
committerLars Ingebrigtsen2016-02-29 16:20:05 +1100
commit90c36173fdcc7dbe1fa150784a4784a9c0cb7bbc (patch)
tree6a3dd4fbfcb4c0c0823406340aa915be6fd4c72a
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.
-rw-r--r--doc/emacs/building.texi8
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/progmodes/grep.el28
3 files changed, 40 insertions, 0 deletions
diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi
index 3fa89d9062d..03fa0ed83b2 100644
--- a/doc/emacs/building.texi
+++ b/doc/emacs/building.texi
@@ -382,6 +382,14 @@ use of this feature by setting @code{grep-highlight-matches} to
382@code{t}. When displaying a match in the source buffer, the exact 382@code{t}. When displaying a match in the source buffer, the exact
383match will be highlighted, instead of the entire source line. 383match will be highlighted, instead of the entire source line.
384 384
385 The @command{grep} commands will offer to save buffers before
386running. This is controlled by the @code{grep-save-buffers} variable.
387The possible values are either @code{nil} (don't save), @code{ask}
388(ask before saving), a function which will be used as a predicate (and
389is called with the file name as the parameter and should return
390non-nil if the buffer is to be saved), and any other non-@code{nil}
391value means that all buffers should be saved without asking.
392
385@findex grep-find 393@findex grep-find
386@findex find-grep 394@findex find-grep
387 The command @kbd{M-x grep-find} (also available as @kbd{M-x 395 The command @kbd{M-x grep-find} (also available as @kbd{M-x
diff --git a/etc/NEWS b/etc/NEWS
index 12b98fa989d..8c4fb63fbd4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1676,6 +1676,10 @@ behavior, set `diff-switches' to `-c'.
1676dynamically. Any third-party code that changes these templates should 1676dynamically. Any third-party code that changes these templates should
1677be updated accordingly. 1677be updated accordingly.
1678 1678
1679** The grep/rgrep/lgrep functions will now ask about saving files
1680before running. This is controlled by the `grep-save-buffers'
1681variable.
1682
1679+++ 1683+++
1680** ‘(/ N)’ is now equivalent to ‘(/ 1 N)’ rather than to ‘(/ N 1)’. 1684** ‘(/ N)’ is now equivalent to ‘(/ 1 N)’ rather than to ‘(/ N 1)’.
1681The new behavior is compatible with Common Lisp and with XEmacs. 1685The new behavior is compatible with Common Lisp and with XEmacs.
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.