[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: find-file-noselect
From: |
Stefan Monnier |
Subject: |
Re: find-file-noselect |
Date: |
Thu, 30 Aug 2012 21:48:21 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) |
> (save-excursion
> (let ((foo (get-buffer (find-file-noselect "/home/drain/foo.org"))))
> (set-buffer foo)
> (insert "test operation")))
To clarify: in the above, find-file-noselect returns a buffer, so
`get-buffer' just returns its argument. And save-excursion + set-buffer
is better replaced by with-current-buffer. All in all:
(with-current-buffer (find-file-noselect "/home/drain/foo.org")
(insert "test operation"))
> I want to open a shell buffer, but do not want to select it (so I stay in
> the current buffer). Just like the above, but with the shell instead of
> foo.org.
find-file-noselect re-uses an existing buffer (if there is one). So if
you want the equivalent for a shell-style buffer, you could try
(with-current-buffer
(or (get-buffer "*shell*")
(make-comint-in-buffer "shell" nil "/bin/bash"))
(unless (derived-mode-p 'comint-mode) (shell-mode))
(insert "test operation"))
-- Stefan