Created
July 28, 2009 23:51
-
-
Save markhepburn/157761 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Problem solved, by subterfuge. | |
(defadvice rgrep (around rgrep-rename-previous-buffer activate compile) | |
"If a previous *grep* buffer exists, offer to rename it before | |
running the new process." | |
(interactive | |
(let ((old-grep-buf (get-buffer "*grep*"))) | |
(if (and old-grep-buf | |
(y-or-n-p "Grep results buffer already exists; rename it first? ")) | |
(let ((new-buf-name (read-string "New name: "))) | |
(with-current-buffer old-grep-buf | |
(rename-buffer new-buf-name)))) | |
;; Sneaky: we need to match the interactive spec for the original | |
;; rgrep, but we also just want to use the original | |
;; interactivity. Hence, this dummy list followed by | |
;; 'call-interactively (and no reference to ad-do-it) | |
(list 'ignored-re 'ignored-files 'ignored-dirs))) | |
(call-interactively 'ad-Orig-rgrep)) | |
;;; This doesn't work: I want to advise rgrep so that if an existing | |
;;; set of results exists, offer the user the opportunity to rename | |
;;; them before they get clobbered. Currently it errors because the | |
;;; argument lists don't match (due to the interactive form), but I | |
;;; also want to continue using the original definition's interaction, | |
;;; just tack some extra before it. Can I do this? | |
;; (defadvice rgrep (around rgrep-rename-previous-buffer activate compile) | |
;; "If a previous *grep* buffer exists, offer to rename it before | |
;; running the new process." | |
;; (interactive) | |
;; (let ((old-grep-buf (get-buffer "*grep*"))) | |
;; (if (and old-grep-buf | |
;; (y-or-n-p "Grep results buffer already exists; rename it first? ")) | |
;; (let ((new-buf-name (read-string "New name: "))) | |
;; (with-current-buffer old-grep-buf | |
;; (rename-buffer new-buf-name))))) | |
;; (call-interactively 'ad-Orig-rgrep)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment