* How to visit a file and kill the current buffer?
@ 2017-09-10 17:13 Mario Castelán Castro
2017-09-10 17:24 ` tomas
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Mario Castelán Castro @ 2017-09-10 17:13 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 895 bytes --]
Hello.
Is there a way to visit a file in the current window and at the same
time kill the previous buffer that occupied the current window? I am
looking for something that behaves like the “Open” functionality in
simple GUI text editors (like leafpad).
Very often I have a frame displaying a file, but I no longer need to
have that file open. I wish to instead open another file. What I do
currently is to do C-x C-f and visit the new file, then kill the now
unneeded buffer, but it is annoying to have to do this in 2 steps.
Moreover, I tend to forget the later step and then I accumulate a lot of
“garbage” buffers that are visiting files that I am no longer interested in.
I must note that I use IDO in case it makes any difference.
Thanks.
--
Do not eat animals; respect them as you respect people.
https://duckduckgo.com/?q=how+to+(become+OR+eat)+vegan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to visit a file and kill the current buffer?
2017-09-10 17:13 Mario Castelán Castro
@ 2017-09-10 17:24 ` tomas
2017-09-10 17:48 ` Mario Castelán Castro
2017-09-10 18:01 ` Eli Zaretskii
2017-09-10 18:16 ` Drew Adams
2 siblings, 1 reply; 11+ messages in thread
From: tomas @ 2017-09-10 17:24 UTC (permalink / raw)
To: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sun, Sep 10, 2017 at 12:13:51PM -0500, Mario Castelán Castro wrote:
> Hello.
>
> Is there a way to visit a file in the current window and at the same
> time kill the previous buffer that occupied the current window?
I think you are looking for replace-buffer-contents, bound to C-x v
Cheers
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlm1dTgACgkQBcgs9XrR2kZrVACZATdXQ1g/MlerbR3ulCzkZOFt
KEIAnjOEb34kjyAaJfSMOfdFtiXVtJsd
=FRJn
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to visit a file and kill the current buffer?
2017-09-10 17:24 ` tomas
@ 2017-09-10 17:48 ` Mario Castelán Castro
2017-09-10 18:37 ` Emanuel Berg
0 siblings, 1 reply; 11+ messages in thread
From: Mario Castelán Castro @ 2017-09-10 17:48 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 425 bytes --]
On 10/09/17 12:24, tomas@tuxteam.de wrote:
> I think you are looking for replace-buffer-contents, bound to C-x v
I can neither find that function by name (“C-h f”) nor by invoking it
directly with “M-x”.
Is it a recent introduction? I am using GNU Emacs 24.5.1 as shipped in
Debian 9.
--
Do not eat animals; respect them as you respect people.
https://duckduckgo.com/?q=how+to+(become+OR+eat)+vegan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to visit a file and kill the current buffer?
2017-09-10 17:13 Mario Castelán Castro
2017-09-10 17:24 ` tomas
@ 2017-09-10 18:01 ` Eli Zaretskii
2017-09-10 18:18 ` Drew Adams
2017-09-10 18:16 ` Drew Adams
2 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2017-09-10 18:01 UTC (permalink / raw)
To: help-gnu-emacs
> From: Mario Castelán Castro <marioxcc.MT@yandex.com>
> Date: Sun, 10 Sep 2017 12:13:51 -0500
>
> Very often I have a frame displaying a file, but I no longer need to
> have that file open.
Emacs doesn't keep the file open after visiting it. The file's
contents is read into a buffer, and the file is closed. So you
shouldn't worry about leaving the file open.
> I wish to instead open another file. What I do
> currently is to do C-x C-f and visit the new file, then kill the now
> unneeded buffer, but it is annoying to have to do this in 2 steps.
You don't need to kill the buffer.
> Moreover, I tend to forget the later step and then I accumulate a lot of
> “garbage” buffers that are visiting files that I am no longer interested in.
Activate midnight-mode, and all those buffers will be automatically
killed for you.
IOW, I think you are looking for a solution to a problem that doesn't
really exists in Emacs. It only exists in those "simple GUI editors".
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to visit a file and kill the current buffer?
[not found] <mailman.245.1505063646.14750.help-gnu-emacs@gnu.org>
@ 2017-09-10 18:15 ` Marco Wahl
2017-09-10 18:27 ` Mario Castelán Castro
0 siblings, 1 reply; 11+ messages in thread
From: Marco Wahl @ 2017-09-10 18:15 UTC (permalink / raw)
To: help-gnu-emacs
Mario Castelán Castro <marioxcc.MT@yandex.com> writes:
> Is there a way to visit a file in the current window and at the same
> time kill the previous buffer that occupied the current window?
There is `find-alternate-file' which meets your requirements AFAICS.
I use it mostly from dired buffers where the function (actually
`dired-find-alternate-file') is bound to "a".
Ciao
Marco
https://marcowahl.github.io
^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: How to visit a file and kill the current buffer?
2017-09-10 17:13 Mario Castelán Castro
2017-09-10 17:24 ` tomas
2017-09-10 18:01 ` Eli Zaretskii
@ 2017-09-10 18:16 ` Drew Adams
2 siblings, 0 replies; 11+ messages in thread
From: Drew Adams @ 2017-09-10 18:16 UTC (permalink / raw)
To: Mario Castelán Castro, help-gnu-emacs
> Is there a way to visit a file in the current window and at the same
> time kill the previous buffer that occupied the current window? I am
> looking for something that behaves like the “Open” functionality in
> simple GUI text editors (like leafpad).
>
> Very often I have a frame displaying a file, but I no longer need to
> have that file open. I wish to instead open another file. What I do
> currently is to do C-x C-f and visit the new file, then kill the now
> unneeded buffer, but it is annoying to have to do this in 2 steps.
> Moreover, I tend to forget the later step and then I accumulate a lot of
> “garbage” buffers that are visiting files that I am no longer interested in.
Yes. `C-x C-v' (`find-alternate-file') does what you want.
It prompts for the name of a file to visit, visits that
file in the selected window, and kills the buffer that
was displayed there.
^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: How to visit a file and kill the current buffer?
2017-09-10 18:01 ` Eli Zaretskii
@ 2017-09-10 18:18 ` Drew Adams
0 siblings, 0 replies; 11+ messages in thread
From: Drew Adams @ 2017-09-10 18:18 UTC (permalink / raw)
To: Eli Zaretskii, help-gnu-emacs
> > Very often I have a frame displaying a file, but I no longer need to
> > have that file open.
>
> Emacs doesn't keep the file open after visiting it. The file's
> contents is read into a buffer, and the file is closed. So you
> shouldn't worry about leaving the file open.
>
> > I wish to instead open another file. What I do
> > currently is to do C-x C-f and visit the new file, then kill the now
> > unneeded buffer, but it is annoying to have to do this in 2 steps.
>
> You don't need to kill the buffer.
>
> > Moreover, I tend to forget the later step and then I accumulate a lot of
> > “garbage” buffers that are visiting files that I am no longer interested
> in.
>
> Activate midnight-mode, and all those buffers will be automatically
> killed for you.
>
> IOW, I think you are looking for a solution to a problem that doesn't
> really exists in Emacs. It only exists in those "simple GUI editors".
I think that perhaps you and others who have replied to this
so far have misunderstood what the request is (or else I have).
I think he's asking to kill the current buffer and visit a file in
its window. That's `C-x C-v'.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to visit a file and kill the current buffer?
2017-09-10 18:15 ` How to visit a file and kill the current buffer? Marco Wahl
@ 2017-09-10 18:27 ` Mario Castelán Castro
0 siblings, 0 replies; 11+ messages in thread
From: Mario Castelán Castro @ 2017-09-10 18:27 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 623 bytes --]
On 10/09/17 13:15, Marco Wahl wrote:
> There is `find-alternate-file' which meets your requirements AFAICS.
>
> I use it mostly from dired buffers where the function (actually
> `dired-find-alternate-file') is bound to "a".
This is what I was looking for. I will also use the dired keystroke you
mentioned.
I noticed that IDO binds C-x C-v to its own variant of this function,
which does the same but uses the IDO facility for entering the file-name.
Thanks to everybody who replied.
--
Do not eat animals; respect them as you respect people.
https://duckduckgo.com/?q=how+to+(become+OR+eat)+vegan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to visit a file and kill the current buffer?
2017-09-10 17:48 ` Mario Castelán Castro
@ 2017-09-10 18:37 ` Emanuel Berg
2017-09-10 19:14 ` tomas
[not found] ` <mailman.265.1505070877.14750.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 11+ messages in thread
From: Emanuel Berg @ 2017-09-10 18:37 UTC (permalink / raw)
To: help-gnu-emacs
Mario Castelán Castro wrote:
>> I think you are looking for
>> replace-buffer-contents, bound to C-x v
>
> I can neither find that function by name
> (“C-h f”) nor by invoking it directly with
> “M-x”.
I don't have that either and what's more for me
`C-x v' is a prefix key.
But anyway, why do you want to kill buffers?
You don't have to kill the old buffers just
because you open a new file!
You can do something like this (the below code)
- however, I strongly disencourage from doing
this, because it'll explode in your face
like instantly!
Just to take one example, remember that Emacs
isn't just about editing files. It is also
about running programs, for example Gnus,
a shell, or actually just about anything.
Because opening/finding files is so common,
it (the keyboard shortcut) will enter your
muscle memory and you will unintentionally kill
all kinds of buffers before long.
Still,
(defun find-file-kill-buffer (filename &optional wildcards)
(interactive
(find-file-read-args "Find file: "
(confirm-nonexistent-file-or-buffer)))
(let ((buffer (current-buffer)))
(when (find-file filename wildcards)
(when buffer (kill-buffer buffer) ))))
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to visit a file and kill the current buffer?
2017-09-10 18:37 ` Emanuel Berg
@ 2017-09-10 19:14 ` tomas
[not found] ` <mailman.265.1505070877.14750.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 11+ messages in thread
From: tomas @ 2017-09-10 19:14 UTC (permalink / raw)
To: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sun, Sep 10, 2017 at 08:37:37PM +0200, Emanuel Berg wrote:
> Mario Castelán Castro wrote:
>
> >> I think you are looking for
> >> replace-buffer-contents, bound to C-x v
> >
> > I can neither find that function by name
> > (“C-h f”) nor by invoking it directly with
> > “M-x”.
>
> I don't have that either and what's more for me
> `C-x v' is a prefix key.
Oops, sorry. I'm "on" 26.0.50 -- pretty bleeding edge,
it seems :-/
Sorry for the noise (but then, that'd be a motivator for
upgrading, wouldn't it ;-)
Cheers
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlm1jxQACgkQBcgs9XrR2kbdbACeLV+See1PLAXxwaHsTPekUhwV
98IAni4x4b+BkYyYCcoscSQH03jI3dBK
=5eMd
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to visit a file and kill the current buffer?
[not found] ` <mailman.265.1505070877.14750.help-gnu-emacs@gnu.org>
@ 2017-09-10 22:13 ` Emanuel Berg
0 siblings, 0 replies; 11+ messages in thread
From: Emanuel Berg @ 2017-09-10 22:13 UTC (permalink / raw)
To: help-gnu-emacs
tomas wrote:
> Oops, sorry. I'm "on" 26.0.50 -- pretty
> bleeding edge, it seems :-/
>
> Sorry for the noise (but then, that'd be
> a motivator for upgrading, wouldn't it ;-)
Perhaps not. Because again, why would you
want that?
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2017-09-10 22:13 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.245.1505063646.14750.help-gnu-emacs@gnu.org>
2017-09-10 18:15 ` How to visit a file and kill the current buffer? Marco Wahl
2017-09-10 18:27 ` Mario Castelán Castro
2017-09-10 17:13 Mario Castelán Castro
2017-09-10 17:24 ` tomas
2017-09-10 17:48 ` Mario Castelán Castro
2017-09-10 18:37 ` Emanuel Berg
2017-09-10 19:14 ` tomas
[not found] ` <mailman.265.1505070877.14750.help-gnu-emacs@gnu.org>
2017-09-10 22:13 ` Emanuel Berg
2017-09-10 18:01 ` Eli Zaretskii
2017-09-10 18:18 ` Drew Adams
2017-09-10 18:16 ` Drew Adams
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.