unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How delete Dired buffer automatically when select a file in Dired?
@ 2008-12-08 19:04 seberino
  2008-12-08 19:54 ` Andy Stewart
  2008-12-09  0:00 ` Xah Lee
  0 siblings, 2 replies; 5+ messages in thread
From: seberino @ 2008-12-08 19:04 UTC (permalink / raw)
  To: help-gnu-emacs

When I select a file in Dired, it opens in a new buffer.

The old Dired buffer still exists.

How automatically delete the Dired buffer when I open a new buffer
with a new file from Dired?

Chris


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How delete Dired buffer automatically when select a file in Dired?
  2008-12-08 19:04 How delete Dired buffer automatically when select a file in Dired? seberino
@ 2008-12-08 19:54 ` Andy Stewart
  2008-12-09  0:00 ` Xah Lee
  1 sibling, 0 replies; 5+ messages in thread
From: Andy Stewart @ 2008-12-08 19:54 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

"seberino@spawar.navy.mil" <seberino@spawar.navy.mil> writes:

> When I select a file in Dired, it opens in a new buffer.
>
> The old Dired buffer still exists.
>
> How automatically delete the Dired buffer when I open a new buffer
> with a new file from Dired?
>
> Chris

Try to use my functions,

`dired-up-directory-single' for up directory.
`dired-find-file+' for open file or directory.

My function will kill old buffer when current directory in only visible
in current window, otherwise, stay current buffer.

,----
| 
| (defun dired-up-directory-single ()
|   "Return up directory in single window.
| When others visible window haven't current buffer, kill old buffer after `dired-up-directory'.
| Otherwise, just `dired-up-directory'."
|   (interactive)
|   (let ((old-buffer (current-buffer))
|         (current-window (selected-window)))
|     (dired-up-directory)
|     (catch 'found
|       (walk-windows
|        (lambda (w)
|          (with-selected-window w
|            (when (and (not (eq current-window (selected-window)))
|                       (equal old-buffer (current-buffer)))
|              (throw 'found "Found current dired buffer in others visible window.")))))
|       (kill-buffer old-buffer))))
| 
| (defun dired-find-file+ ()
|   "Like `dired-find-file'.
| When open directory, if others visible window have this directory, do `find-file'.
| Otherwise do `find-alternate-file'.
| When open file, always use `find-file'."
|   (interactive)
|   (set-buffer-modified-p nil)
|   (let ((file (dired-get-file-for-visit))
|         (old-buffer (current-buffer))
|         (current-window (selected-window)))
|     (if (file-directory-p file)
|         (catch 'found
|           (walk-windows
|            (lambda (w)
|              (with-selected-window w
|                (when (and (not (eq current-window (selected-window)))
|                           (equal old-buffer (current-buffer)))
|                  (find-file file)
|                  (throw 'found "Found current dired buffer in others visible window.")))))
|           (find-alternate-file file))
|       (find-file file))))
`----

Enjoy!

  -- Andy





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How delete Dired buffer automatically when select a file in  Dired?
  2008-12-08 19:04 How delete Dired buffer automatically when select a file in Dired? seberino
  2008-12-08 19:54 ` Andy Stewart
@ 2008-12-09  0:00 ` Xah Lee
  2008-12-10  3:47   ` seberino
  1 sibling, 1 reply; 5+ messages in thread
From: Xah Lee @ 2008-12-09  0:00 UTC (permalink / raw)
  To: help-gnu-emacs

On Dec 8, 11:04 am, "seber...@spawar.navy.mil"
<seber...@spawar.navy.mil> wrote:
> When I select a file in Dired, it opens in a new buffer.
>
> The old Dired buffer still exists.
>
> How automatically delete the Dired buffer when I open a new buffer
> with a new file from Dired?

in dired, you can use the shortcut “a” (which invokes dired-find-
alternate-file).

Or, you can use this code:

(put 'dired-find-alternate-file 'disabled nil)

(add-hook 'dired-mode-hook
 (lambda ()
  (define-key dired-mode-map (kbd "<return>")
    'dired-find-alternate-file) ; was dired-advertised-find-file
  (define-key dired-mode-map (kbd "^")
    (lambda () (interactive) (find-alternate-file "..")))
  ; was dired-up-directory
 ))

you might make it 'enabled ... i don't recall since i stopped using
the above.

I hope emacs developers makes the above into a dired preference
setting.

Your question is a recurring question. For some other dired faq, see
bottom:

• File Management with Emacs
  http://xahlee.org/emacs/file_management.html

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How delete Dired buffer automatically when select a file in  Dired?
  2008-12-09  0:00 ` Xah Lee
@ 2008-12-10  3:47   ` seberino
  2008-12-10 10:58     ` Leo
  0 siblings, 1 reply; 5+ messages in thread
From: seberino @ 2008-12-10  3:47 UTC (permalink / raw)
  To: help-gnu-emacs

On Dec 8, 4:00 pm, Xah Lee <xah...@gmail.com> wrote:

Thanks! Your code worked quite nicely.

> I hopeemacsdevelopers makes the above into adiredpreference
> setting.

I second that motion!

cs


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How delete Dired buffer automatically when select a file in Dired?
  2008-12-10  3:47   ` seberino
@ 2008-12-10 10:58     ` Leo
  0 siblings, 0 replies; 5+ messages in thread
From: Leo @ 2008-12-10 10:58 UTC (permalink / raw)
  To: help-gnu-emacs

On 2008-12-10 03:47 +0000, seberino@spawar.navy.mil wrote:
> On Dec 8, 4:00 pm, Xah Lee <xah...@gmail.com> wrote:
>
> Thanks! Your code worked quite nicely.
>
>> I hopeemacsdevelopers makes the above into adiredpreference
>> setting.
>
> I second that motion!
>
> cs

It won't happen unless you propose it to emacs-devel.

Bye,
-- 
.:  Leo  :.  [ sdl.web AT gmail.com ]  .: I use Emacs :.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-12-10 10:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-08 19:04 How delete Dired buffer automatically when select a file in Dired? seberino
2008-12-08 19:54 ` Andy Stewart
2008-12-09  0:00 ` Xah Lee
2008-12-10  3:47   ` seberino
2008-12-10 10:58     ` Leo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).