help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing open file buffer handling


From: Ehud Karni
Subject: Re: Changing open file buffer handling
Date: Wed, 5 Mar 2003 22:16:39 +0200

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 05 Mar 2003 13:28:01 -0500, jeff.rancier@softechnics.com (Jeffery B. 
Rancier) wrote:
> >
> > Add this to your .emacs:
> >
> > (defun dired-find-alternate-file 
> >   "In dired, visit this file or directory instead of dired buffer."
> >   (interactive "P")
> >        (find-alternate-file (dired-get-filename)))
> >
> 
> Should that be
> 
> (defun dired-find-alternate-file 
>   "In dired, visit this file or directory instead of dired buffer."
>   (interactive)
>        (find-alternate-file (dired-get-filename)))

Sorry. It was "too quick" hack of my real function which is:

(defun dired-find-alternate-file (&optional as-directory)
  "In dired, visit this file or directory instead of dired buffer."
  (interactive "P")
       (if as-directory
           (ek-find-alternate-file nil as-directory)
           (ek-find-alternate-file (dired-get-filename))))

;;------------- find-alternate-file (modified from files) ---------------

(defun ek-find-alternate-file (&optional filename as-directory)
  "Find file FILENAME, select its buffer, kill previous buffer.
If the current buffer now contains an empty file that you just visited
\(presumably by mistake), use this command to visit the file you really want.

With non-nil prefix argument AS-DIRECTORY do `dired' on the file-name."
  (interactive)
       (setq as-directory current-prefix-arg)
       (let ((file buffer-file-name)
             (obuf (current-buffer))
             (ofile buffer-file-name)
             (onum buffer-file-number)
             (otrue buffer-file-truename)
             (oname (buffer-name))
             file-name file-dir)
           (or filename
               (and file
                    (setq file-name (file-name-nondirectory file)
                          file-dir (file-name-directory file))
                    nil)
               (setq filename (read-file-name (concat "Find alternate "
                                                   (if as-directory "(dired): " 
"file: "))
                                              file-dir nil nil file-name)))
           (and (buffer-modified-p) (buffer-file-name)
       ;;       (not buffer-read-only)
                (not (yes-or-no-p (format "Buffer %s is modified, kill anyway? "
                                          (buffer-name))))
                (error "Aborted"))
           (if (get-buffer " **lose**")
               (kill-buffer " **lose**"))
           (rename-buffer " **lose**")
           (unwind-protect
               (progn
                   (unlock-buffer)
                   (setq buffer-file-name nil)
                   (setq buffer-file-number nil)
                   (setq buffer-file-truename nil)
                   (if as-directory
                       (dired filename)
                       (find-file filename))
               (cond (
                   (eq obuf (current-buffer))
                   (setq buffer-file-name ofile)
                      (setq buffer-file-number onum)
                      (setq buffer-file-truename otrue)
                      (lock-buffer)
                      (rename-buffer oname))))
           (or (eq (current-buffer) obuf)
               (kill-buffer obuf)))))

Ehud.


- -- 
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 mailto:ehud@unix.mvs.co.il                  Better  Safe  Than  Sorry
-----BEGIN PGP SIGNATURE-----
Comment: use http://www.keyserver.net/ to get my key (and others)

iD4DBQE+ZlsnLFvTvpjqOY0RAr03AJ9YLLiL866oq4weVk8uA/LirQfHxwCVEQaV
vAzXxqidzRRm/tXNQOoLAg==
=u/9s
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]