all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Using key q to quit temporary buffer window
@ 2022-08-23  4:38 wilnerthomas--- via Users list for the GNU Emacs text editor
  2022-08-23 15:11 ` Marcin Borkowski
  0 siblings, 1 reply; 15+ messages in thread
From: wilnerthomas--- via Users list for the GNU Emacs text editor @ 2022-08-23  4:38 UTC (permalink / raw)
  To: Help Gnu Emacs


I am printing some text in a temporary buffer

(defconst principles  "Text for display in temporary buffer")

(with-output-to-temp-buffer "*andromeda*"
       (print principles)

Is it technically possible to use the key `q' to quit the temporary buffer window as one can do
with the `*Backtrace*' window?



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

* Re: Using key q to quit temporary buffer window
  2022-08-23  4:38 Using key q to quit temporary buffer window wilnerthomas--- via Users list for the GNU Emacs text editor
@ 2022-08-23 15:11 ` Marcin Borkowski
  2022-08-24  0:32   ` uzibalqa
  0 siblings, 1 reply; 15+ messages in thread
From: Marcin Borkowski @ 2022-08-23 15:11 UTC (permalink / raw)
  To: wilnerthomas; +Cc: Help Gnu Emacs


On 2022-08-23, at 06:38, wilnerthomas--- via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:

> I am printing some text in a temporary buffer
>
> (defconst principles "Text for display in temporary buffer")
>
> (with-output-to-temp-buffer "*andromeda*"
>  (print principles)
>
> Is it technically possible to use the key `q' to quit the temporary buffer window as one can do
> with the `*Backtrace*' window?

AFAIK, it already works this way - thing is, the temp buffer window is
not selected by default.

I'd probably look at `display-buffer'.

Hth,

-- 
Marcin Borkowski
http://mbork.pl



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

* Re: Using key q to quit temporary buffer window
  2022-08-23 15:11 ` Marcin Borkowski
@ 2022-08-24  0:32   ` uzibalqa
  2022-08-24  1:42     ` Emanuel Berg
  0 siblings, 1 reply; 15+ messages in thread
From: uzibalqa @ 2022-08-24  0:32 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: wilnerthomas, Help Gnu Emacs

------- Original Message -------
On Tuesday, August 23rd, 2022 at 3:11 PM, Marcin Borkowski <mbork@mbork.pl> wrote:


> On 2022-08-23, at 06:38, wilnerthomas--- via Users list for the GNU Emacs text editor help-gnu-emacs@gnu.org wrote:
> 
> > I am printing some text in a temporary buffer
> > 
> > (defconst principles "Text for display in temporary buffer")
> > 
> > (with-output-to-temp-buffer "andromeda"
> > (print principles)
> > 
> > Is it technically possible to use the key `q' to quit the temporary buffer window as one can do with the` Backtrace' window?
> 
> 
> AFAIK, it already works this way - thing is, the temp buffer window is
> not selected by default.
> 
> I'd probably look at `display-buffer'.
> 
> Hth,

You are right.  After switching to the temporary buffer, hitting `q' does quit the temporary buffer window.

Have made this, but want to switch to the temp buffer automatically.  What commands should I introduce? 

(defun help-show (bufrnm msg)
  "Display the output of MSG in buffer named BUFRNM."
  (if (stringp msg)
      (with-output-to-temp-buffer bufrnm
	(print msg))))





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

* Re: Using key q to quit temporary buffer window
  2022-08-24  0:32   ` uzibalqa
@ 2022-08-24  1:42     ` Emanuel Berg
  2022-08-24  3:54       ` uzibalqa
  0 siblings, 1 reply; 15+ messages in thread
From: Emanuel Berg @ 2022-08-24  1:42 UTC (permalink / raw)
  To: help-gnu-emacs

uzibalqa wrote:

> (defun help-show (bufrnm msg)
>   "Display the output of MSG in buffer named BUFRNM."

Order ...

>   (if (stringp msg)
>       (with-output-to-temp-buffer bufrnm
> 	(print msg)))

`when'

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Using key q to quit temporary buffer window
  2022-08-24  1:42     ` Emanuel Berg
@ 2022-08-24  3:54       ` uzibalqa
  2022-08-24  4:07         ` uzibalqa
  0 siblings, 1 reply; 15+ messages in thread
From: uzibalqa @ 2022-08-24  3:54 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

------- Original Message -------
On Wednesday, August 24th, 2022 at 1:42 AM, Emanuel Berg <incal@dataswamp.org> wrote:


> uzibalqa wrote:
> 
> > (defun help-show (bufrnm msg)
> > "Display the output of MSG in buffer named BUFRNM."
> 
> 
> Order ...
> 
> > (if (stringp msg)
> > (with-output-to-temp-buffer bufrnm
> > (print msg)))
> 
> 
> `when'

You are correct, I did not include an alternative.



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

* Re: Using key q to quit temporary buffer window
  2022-08-24  3:54       ` uzibalqa
@ 2022-08-24  4:07         ` uzibalqa
  2022-08-24  5:35           ` Emanuel Berg
  0 siblings, 1 reply; 15+ messages in thread
From: uzibalqa @ 2022-08-24  4:07 UTC (permalink / raw)
  To: uzibalqa; +Cc: Emanuel Berg, help-gnu-emacs

------- Original Message -------
On Wednesday, August 24th, 2022 at 3:54 AM, uzibalqa <uzibalqa@proton.me> wrote:


> ------- Original Message -------
> On Wednesday, August 24th, 2022 at 1:42 AM, Emanuel Berg incal@dataswamp.org wrote:
> 
> 
> 
> > uzibalqa wrote:
> > 
> > > (defun help-show (bufrnm msg)
> > > "Display the output of MSG in buffer named BUFRNM."
> > 
> > Order ...
> > 
> > > (if (stringp msg)
> > > (with-output-to-temp-buffer bufrnm
> > > (print msg)))
> > 
> > `when'
> 
> 
> You are correct, I did not include an alternative.

Also included (switch-to-buffer bfname) to get

(defun help-show (bfname msg)
  "Display the output of MSG"
  (when (stringp msg)
    (with-output-to-temp-buffer bfname
      (switch-to-buffer bfname)
      (print msg))))

But (switch-to-buffer bfname) replaces the buffer.  Without it, a new buffer is generated
underneath the current buffer.  All I want is to make the temporary buffer to become the 
current buffer.









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

* Re: Using key q to quit temporary buffer window
  2022-08-24  4:07         ` uzibalqa
@ 2022-08-24  5:35           ` Emanuel Berg
  2022-08-24  5:56             ` uzibalqa
  0 siblings, 1 reply; 15+ messages in thread
From: Emanuel Berg @ 2022-08-24  5:35 UTC (permalink / raw)
  To: help-gnu-emacs

uzibalqa wrote:

> Also included (switch-to-buffer bfname) to get
>
> (defun help-show (bfname msg)
>   "Display the output of MSG"

Still not good ...

>   (when (stringp msg)
>     (with-output-to-temp-buffer bfname
>       (switch-to-buffer bfname)
>       (print msg))))
>
> But (switch-to-buffer bfname) replaces the buffer.
> Without it, a new buffer is generated underneath the current
> buffer. All I want is to make the temporary buffer to become
> the current buffer.

`get-buffer-create', then `with-current-buffer', then
`pop-to-buffer'.

See `print-roll-outs' here

  https://dataswamp.org/~incal/emacs-init/bike.el

for an example.

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Using key q to quit temporary buffer window
  2022-08-24  5:35           ` Emanuel Berg
@ 2022-08-24  5:56             ` uzibalqa
  2022-08-24  6:00               ` Emanuel Berg
  0 siblings, 1 reply; 15+ messages in thread
From: uzibalqa @ 2022-08-24  5:56 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

------- Original Message -------
On Wednesday, August 24th, 2022 at 5:35 AM, Emanuel Berg <incal@dataswamp.org> wrote:


> uzibalqa wrote:
> 
> > Also included (switch-to-buffer bfname) to get
> > 
> > (defun help-show (bfname msg)
> > "Display the output of MSG"
> 
> 
> Still not good ...
> 
> > (when (stringp msg)
> > (with-output-to-temp-buffer bfname
> > (switch-to-buffer bfname)
> > (print msg))))
> > 
> > But (switch-to-buffer bfname) replaces the buffer.
> > Without it, a new buffer is generated underneath the current
> > buffer. All I want is to make the temporary buffer to become
> > the current buffer.
> 
> 
> `get-buffer-create', then` with-current-buffer', then
> `pop-to-buffer'. See` print-roll-outs' here

This fails because I end up with an empty buffer.

(defun help-show-b (bfname msg)
  "Display the output of MSG"

  (when (stringp msg)
    (get-buffer-create bfname)
    (with-current-buffer bfname
      (pop-to-buffer bfname)
      (print msg))))

I want a temporary buffer, where I can hit `q' to get out of it as
happens with the buffer *Backtrace*.




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

* Re: Using key q to quit temporary buffer window
  2022-08-24  5:56             ` uzibalqa
@ 2022-08-24  6:00               ` Emanuel Berg
  2022-08-24  6:14                 ` uzibalqa
  0 siblings, 1 reply; 15+ messages in thread
From: Emanuel Berg @ 2022-08-24  6:00 UTC (permalink / raw)
  To: help-gnu-emacs

uzibalqa wrote:

> This fails [...]

See the URL in the previous mail ...

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Using key q to quit temporary buffer window
  2022-08-24  6:00               ` Emanuel Berg
@ 2022-08-24  6:14                 ` uzibalqa
  2022-08-24  6:23                   ` Emanuel Berg
  0 siblings, 1 reply; 15+ messages in thread
From: uzibalqa @ 2022-08-24  6:14 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

------- Original Message -------
On Wednesday, August 24th, 2022 at 6:00 AM, Emanuel Berg <incal@dataswamp.org> wrote:


> uzibalqa wrote:
> 
> > This fails [...]
> 
> 
> See the URL in the previous mail ...

Have looked at the url and the particular function you pointed out.
I actually get two buffers, and as soon as I use the mouse, the buffer
gets blanked out.

Have done

(defun help-show (bfname msg)
  "Display the output of MSG"

  (let ( (bfr  (get-buffer-create bfname)) )

    (when (stringp msg)
      (with-current-buffer bfr
	(print msg)
	(pop-to-buffer bfr))) ))





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

* Re: Using key q to quit temporary buffer window
  2022-08-24  6:14                 ` uzibalqa
@ 2022-08-24  6:23                   ` Emanuel Berg
  2022-08-24  6:30                     ` uzibalqa
  0 siblings, 1 reply; 15+ messages in thread
From: Emanuel Berg @ 2022-08-24  6:23 UTC (permalink / raw)
  To: help-gnu-emacs

uzibalqa wrote:

> Have done
>
> (defun help-show (bfname msg)
>   "Display the output of MSG"
>
>   (let ( (bfr  (get-buffer-create bfname)) )
>
>     (when (stringp msg)
>       (with-current-buffer bfr
> 	(print msg)
> 	(pop-to-buffer bfr))) ))

(let ((buf (get-buffer-create "*Test Buffer*")))
  (with-current-buffer buf
    (insert "Lamers 'R Us\n") )
  (pop-to-buffer buf) )

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Using key q to quit temporary buffer window
  2022-08-24  6:23                   ` Emanuel Berg
@ 2022-08-24  6:30                     ` uzibalqa
  2022-08-24  6:45                       ` Emanuel Berg
  0 siblings, 1 reply; 15+ messages in thread
From: uzibalqa @ 2022-08-24  6:30 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

------- Original Message -------
On Wednesday, August 24th, 2022 at 6:23 AM, Emanuel Berg <incal@dataswamp.org> wrote:


> uzibalqa wrote:
> 
> > Have done
> > 
> > (defun help-show (bfname msg)
> > "Display the output of MSG"
> > 
> > (let ( (bfr (get-buffer-create bfname)) )
> > 
> > (when (stringp msg)
> > (with-current-buffer bfr
> > (print msg)
> > (pop-to-buffer bfr))) ))
> 
> 
> (let ((buf (get-buffer-create "Test Buffer")))
> (with-current-buffer buf
> (insert "Lamers 'R Us\n") )
> (pop-to-buffer buf) )

Lastly I need the buffer to quit by hitting `q'.



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

* Re: Using key q to quit temporary buffer window
  2022-08-24  6:30                     ` uzibalqa
@ 2022-08-24  6:45                       ` Emanuel Berg
  2022-08-24  7:16                         ` uzibalqa
  0 siblings, 1 reply; 15+ messages in thread
From: Emanuel Berg @ 2022-08-24  6:45 UTC (permalink / raw)
  To: help-gnu-emacs

uzibalqa wrote:

>>> Have done
>>> 
>>> (defun help-show (bfname msg)
>>> "Display the output of MSG"
>>> 
>>> (let ( (bfr (get-buffer-create bfname)) )
>>> 
>>> (when (stringp msg)
>>> (with-current-buffer bfr
>>> (print msg)
>>> (pop-to-buffer bfr))) ))
>> 
>> (let ((buf (get-buffer-create "Test Buffer")))
>> (with-current-buffer buf
>> (insert "Lamers 'R Us\n") )
>> (pop-to-buffer buf) )
>
> Lastly I need the buffer to quit by hitting `q'.

How do a programmer do that?

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Using key q to quit temporary buffer window
  2022-08-24  6:45                       ` Emanuel Berg
@ 2022-08-24  7:16                         ` uzibalqa
  2022-08-24 10:41                           ` Jean Louis
  0 siblings, 1 reply; 15+ messages in thread
From: uzibalqa @ 2022-08-24  7:16 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

------- Original Message -------
On Wednesday, August 24th, 2022 at 6:45 AM, Emanuel Berg <incal@dataswamp.org> wrote:


> uzibalqa wrote:
> 
> > > > Have done
> > > > 
> > > > (defun help-show (bfname msg)
> > > > "Display the output of MSG"
> > > > 
> > > > (let ( (bfr (get-buffer-create bfname)) )
> > > > 
> > > > (when (stringp msg)
> > > > (with-current-buffer bfr
> > > > (print msg)
> > > > (pop-to-buffer bfr))) ))
> > > 
> > > (let ((buf (get-buffer-create "Test Buffer")))
> > > (with-current-buffer buf
> > > (insert "Lamers 'R Us\n") )
> > > (pop-to-buffer buf) )
> > 
> > Lastly I need the buffer to quit by hitting `q'.
> 
> 
> How do a programmer do that?

I have reverted back to using `with-output-to-temp-buffer' but taking out
`pop-to-buffer' from inside `with-output-to-temp-buffer'.  Then hitting
`q' gets me to quit the buffer and its window.

Here is the updated function

(defun help-show (buf msg)
  "Display the output of MSG"

  (when (stringp msg)
    (with-output-to-temp-buffer buf
      (princ msg))
    (pop-to-buffer buf)))





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

* Re: Using key q to quit temporary buffer window
  2022-08-24  7:16                         ` uzibalqa
@ 2022-08-24 10:41                           ` Jean Louis
  0 siblings, 0 replies; 15+ messages in thread
From: Jean Louis @ 2022-08-24 10:41 UTC (permalink / raw)
  To: uzibalqa; +Cc: Emanuel Berg, help-gnu-emacs

* uzibalqa <uzibalqa@proton.me> [2022-08-24 10:21]:
> I have reverted back to using `with-output-to-temp-buffer' but taking out
> `pop-to-buffer' from inside `with-output-to-temp-buffer'.  Then hitting
> `q' gets me to quit the buffer and its window.
> 
> Here is the updated function
> 
> (defun help-show (buf msg)
>   "Display the output of MSG"
> 
>   (when (stringp msg)
>     (with-output-to-temp-buffer buf
>       (princ msg))
>     (pop-to-buffer buf)))

If you review description of the function `with-output-to-temp-buffer'
it will tell you:

,----
| It does not make the buffer current for BODY.  Instead it binds
| ‘standard-output’ to that buffer, so that output generated with
| ‘prin1’ and similar functions in BODY goes into the buffer.
| 
| At the end of BODY, this marks buffer BUFNAME unmodified and displays
| it in a window, but does not select it.
`----

That means it is for some kind of messages, but not to put the buffer
at front.

I am using similar function here below `rcd-message', as I want
messages from my programs not only in the default message buffer but
in my own, with date and time of message.

(defcustom rcd-message-active t
  "Utilize `rcd-message-buffer' if TRUE."
  :group 'rcd
  :type 'boolean)

(defvar rcd-message-buffer "*RCD Message Buffer*"
  "Default RCD Utilities message buffer.")

(defun rcd-message (format-string &rest message)
  (let ((current (current-buffer))
	(format-string (concat (rcd-timestamp) " " format-string)))
    (when rcd-message-active
      (get-buffer-create rcd-message-buffer)
      (switch-to-buffer rcd-message-buffer)
      (goto-char (point-max))
      (insert 
       (apply 'format format-string message)
       "\n")
      (goto-char (point-max))
      (switch-to-buffer current))
    (apply 'message format-string message)))

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

end of thread, other threads:[~2022-08-24 10:41 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-23  4:38 Using key q to quit temporary buffer window wilnerthomas--- via Users list for the GNU Emacs text editor
2022-08-23 15:11 ` Marcin Borkowski
2022-08-24  0:32   ` uzibalqa
2022-08-24  1:42     ` Emanuel Berg
2022-08-24  3:54       ` uzibalqa
2022-08-24  4:07         ` uzibalqa
2022-08-24  5:35           ` Emanuel Berg
2022-08-24  5:56             ` uzibalqa
2022-08-24  6:00               ` Emanuel Berg
2022-08-24  6:14                 ` uzibalqa
2022-08-24  6:23                   ` Emanuel Berg
2022-08-24  6:30                     ` uzibalqa
2022-08-24  6:45                       ` Emanuel Berg
2022-08-24  7:16                         ` uzibalqa
2022-08-24 10:41                           ` Jean Louis

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.