* Writing text to a dedicated buffer
@ 2021-05-02 12:48 Christopher Dimech
2021-05-02 13:05 ` Christopher Dimech
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Christopher Dimech @ 2021-05-02 12:48 UTC (permalink / raw)
To: Help Gnu Emacs
I am writing text to a package dedicated buffer. Is this the way to
go about doing that. Or are there neater ways?
(defun gungadin-guidance-message ()
"Displays embedded rudimentary help for gungadin.
Gungadin forms part of Behistun, a Gnu Package."
(let ((out-buffer (get-buffer-create "*Gungadin*")))
(with-current-buffer out-buffer
(insert "\nGungadin\n\n")
(insert "Gungadin is part of Behistun, a Gnu Package.\n\n")
(insert "Gungadin 1.0 of 2017-05-02")
(insert "\nCopyright (C) 2017 Christopher Dimech\n")
(insert "\nAuthor: Christopher Dimech")
(insert gungadin-guidance-message)
(pop-to-buffer out-buffer))) )
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Writing text to a dedicated buffer
2021-05-02 12:48 Writing text to a dedicated buffer Christopher Dimech
@ 2021-05-02 13:05 ` Christopher Dimech
2021-05-02 17:08 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-02 13:25 ` Christopher Dimech
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Christopher Dimech @ 2021-05-02 13:05 UTC (permalink / raw)
To: Christopher Dimech; +Cc: Help Gnu Emacs
I would like to write more things to the created buffer from
other functions. Not so sure if it is good to call get-buffer-create
on the created buffer every time I want to write to it.
Is there some good scheme for writing to a user defined buffer from
various elisp files?
> Sent: Monday, May 03, 2021 at 12:48 AM
> From: "Christopher Dimech" <dimech@gmx.com>
> To: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: Writing text to a dedicated buffer
>
> I am writing text to a package dedicated buffer. Is this the way to
> go about doing that. Or are there neater ways?
>
>
> (defun gungadin-guidance-message ()
> "Displays embedded rudimentary help for gungadin.
> Gungadin forms part of Behistun, a Gnu Package."
>
> (let ((out-buffer (get-buffer-create "*Gungadin*")))
> (with-current-buffer out-buffer
> (insert "\nGungadin\n\n")
> (insert "Gungadin is part of Behistun, a Gnu Package.\n\n")
> (insert "Gungadin 1.0 of 2017-05-02")
> (insert "\nCopyright (C) 2017 Christopher Dimech\n")
> (insert "\nAuthor: Christopher Dimech")
>
> (insert gungadin-guidance-message)
> (pop-to-buffer out-buffer))) )
>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Writing text to a dedicated buffer
2021-05-02 13:05 ` Christopher Dimech
@ 2021-05-02 17:08 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 7+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-05-02 17:08 UTC (permalink / raw)
To: help-gnu-emacs
Christopher Dimech wrote:
> I would like to write more things to the created buffer from
> other functions. Not so sure if it is good to call
> get-buffer-create on the created buffer every time I want to
> write to it.
Why not?
Write one function to write, then everyone else who has
something to say calls that function.
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Writing text to a dedicated buffer
2021-05-02 12:48 Writing text to a dedicated buffer Christopher Dimech
2021-05-02 13:05 ` Christopher Dimech
@ 2021-05-02 13:25 ` Christopher Dimech
2021-05-02 14:23 ` Joost Kremers
2021-05-02 17:06 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-04 13:07 ` Filipp Gunbin
3 siblings, 1 reply; 7+ messages in thread
From: Christopher Dimech @ 2021-05-02 13:25 UTC (permalink / raw)
To: Christopher Dimech; +Cc: Help Gnu Emacs
I have done the writing to a dedicated buffer as follows,
using "gungadin-bufr-insert" for writing to the Gungadin buffer.
-------- code --------
(setq gungadin-bufr (generate-new-buffer "*Gungadin*"))
(defvar gungadin-guidance-message
"C-h f flight\n")
(defun gungadin-guidance-message ()
"Displays embedded rudimentary help for gungadin in a dedicated buffer."
(message "%s" gungadin-guidance-message)
(let (($out-buffer (get-buffer-create "*Gungadin*")))
(with-current-buffer $out-buffer
(insert "\nGungadin\n\n")
(insert "Gungadin is part of Behistun, a Gnu Package.\n\n")
(insert "Gungadin 1.0 of 2017-05-02\n")
(insert "Copyright (C) 2017 Christopher Dimech\n\n")
(insert "Author: Christopher Dimech\n\n")
(insert gungadin-guidance-message)
(pop-to-buffer $out-buffer))) )
;; (switch-to-buffer GdBfr)
(defun gungadin-bufr-insert (format-string)
"Display a message at the bottom of the Gungadin Buffer."
(set-buffer gungadin-bufr)
(with-current-buffer gungadin-bufr
(insert format-string)) )
(gungadin-guidance-message)
(gungadin-bufr-insert "***** TEST")
> Sent: Monday, May 03, 2021 at 12:48 AM
> From: "Christopher Dimech" <dimech@gmx.com>
> To: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: Writing text to a dedicated buffer
>
> I am writing text to a package dedicated buffer. Is this the way to
> go about doing that. Or are there neater ways?
>
>
> (defun gungadin-guidance-message ()
> "Displays embedded rudimentary help for gungadin.
> Gungadin forms part of Behistun, a Gnu Package."
>
> (let ((out-buffer (get-buffer-create "*Gungadin*")))
> (with-current-buffer out-buffer
> (insert "\nGungadin\n\n")
> (insert "Gungadin is part of Behistun, a Gnu Package.\n\n")
> (insert "Gungadin 1.0 of 2017-05-02")
> (insert "\nCopyright (C) 2017 Christopher Dimech\n")
> (insert "\nAuthor: Christopher Dimech")
>
> (insert gungadin-guidance-message)
> (pop-to-buffer out-buffer))) )
>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Writing text to a dedicated buffer
2021-05-02 13:25 ` Christopher Dimech
@ 2021-05-02 14:23 ` Joost Kremers
0 siblings, 0 replies; 7+ messages in thread
From: Joost Kremers @ 2021-05-02 14:23 UTC (permalink / raw)
To: Christopher Dimech; +Cc: help-gnu-emacs
On Sun, May 02 2021, Christopher Dimech wrote:
> I have done the writing to a dedicated buffer as follows,
> using "gungadin-bufr-insert" for writing to the Gungadin buffer.
>
> -------- code --------
>
> (setq gungadin-bufr (generate-new-buffer "*Gungadin*"))
This should be a `defvar`. Personally, I would probably initialise it to
`nil` and create a buffer on the first call to `gungadin-bufr-insert`. But more
likely, I would probably do something like this:
(defvar gungadin-buffer-name "*Gungadin*")
(defun gungadin-buffer-insert (message)
(with-current-buffer (get-buffer-create gungadin-buffer-name)
...))
There is no problem calling `get-buffer-create` on a buffer that already exists.
Just make sure you pass it the name of the buffer, not the buffer object itself,
because in the latter case you may get back a dead buffer which you cannot write
to anymore. (You never know when a user accidentally kills the Gungadin buffer.)
Do `C-h f get-buffer-create RET` for details.
> (defun gungadin-bufr-insert (format-string)
> "Display a message at the bottom of the Gungadin Buffer."
>
> (set-buffer gungadin-bufr)
> (with-current-buffer gungadin-bufr
> (insert format-string)) )
If you check the source code of `with-current-buffer`, you'll notice that it
uses `set-buffer`. There is no need to call `set-buffer` if you're going to use
`with-current-buffer`. (And you should be using `with-current-buffer`.)
--
Joost Kremers
Life has its moments
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Writing text to a dedicated buffer
2021-05-02 12:48 Writing text to a dedicated buffer Christopher Dimech
2021-05-02 13:05 ` Christopher Dimech
2021-05-02 13:25 ` Christopher Dimech
@ 2021-05-02 17:06 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-04 13:07 ` Filipp Gunbin
3 siblings, 0 replies; 7+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-05-02 17:06 UTC (permalink / raw)
To: help-gnu-emacs
Christopher Dimech wrote:
> I am writing text to a package dedicated buffer. Is this the
> way to go about doing that. Or are there neater ways?
>
> (let ((out-buffer (get-buffer-create "*Gungadin*")))
> (with-current-buffer out-buffer
Where did you get that code? :)
But to answer your question with a question, what not neat
with that?
Looks good to me. Ha :)
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Writing text to a dedicated buffer
2021-05-02 12:48 Writing text to a dedicated buffer Christopher Dimech
` (2 preceding siblings ...)
2021-05-02 17:06 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-05-04 13:07 ` Filipp Gunbin
3 siblings, 0 replies; 7+ messages in thread
From: Filipp Gunbin @ 2021-05-04 13:07 UTC (permalink / raw)
To: Christopher Dimech; +Cc: Help Gnu Emacs
On 02/05/2021 14:48 +0200, Christopher Dimech wrote:
> I am writing text to a package dedicated buffer. Is this the way to
> go about doing that. Or are there neater ways?
Check out with-output-to-temp-buffer, looks like it fits your use case.
Filipp
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-05-04 13:07 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-02 12:48 Writing text to a dedicated buffer Christopher Dimech
2021-05-02 13:05 ` Christopher Dimech
2021-05-02 17:08 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-02 13:25 ` Christopher Dimech
2021-05-02 14:23 ` Joost Kremers
2021-05-02 17:06 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-04 13:07 ` Filipp Gunbin
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.