Stefan Monnier <[EMAIL PROTECTED]> writes:

> E.g. find-file might require confirmation before opening
> a non-existent file.  I'll love such a new feature, seeing how often I do
> "C-x C-f emacs/src/rege TAB RET" only to find myself in "regexp." rather
> than in the "regexp.c" that I intended to open.

Here is what I use in Easymacs, which I have modified from
http://www-xray.ast.cam.ac.uk/~gmorris/dotemacs.html -- I just added the
make-directory bit.

  (defadvice find-file (around confirm-new-file activate)
    "If file does not exist, prompt."
    (let ((file (ad-get-arg 0)))
      (when (or (not (interactive-p))
               (find-buffer-visiting file)
               (string-match "\\`/\\[" file) ; old-style TRAMP
               (string-match "\\`/[EMAIL PROTECTED]:" file) ; new-style TRAMP
               (file-directory-p file)
               ;; file-exists-p does not handle wildcards.
               (file-expand-wildcards file)
               ;; A nice trick, but not necessary.
;;;         (string-match "0\n\\'" (shell-command-to-string
;;;                                 (format "ls %s; echo $?" file)))
               (yes-or-no-p
                (format "`%s' does not exist, create new file? " file)))
        
        ;; Is this a good idea? If we open a new file by accident,
        ;; despite the confirmation, we probably don't want the directory.
        (unless (file-directory-p (file-name-directory file))
          (make-directory (file-name-directory file) t))
        ad-do-it)))

  (defadvice switch-to-buffer (around confirm-new-buffer activate)
    "If buffer does not exist, prompt."
    (let ((buff (ad-get-arg 0)))
      (if (or (not (interactive-p))
              (get-buffer buff)
              (yes-or-no-p
               (format "`%s' does not exist, create new file? " buff)))
          ad-do-it)))



_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

Reply via email to