unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Visiting buffers programmatically
@ 2021-06-10 21:17 Tim Johnson
  2021-06-10 23:31 ` pillule
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Tim Johnson @ 2021-06-10 21:17 UTC (permalink / raw)
  To: MLEmacs

GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, 
cairo version 1.16.0)
  of 2021-06-04 ubuntu 20.04

I would like to write three simple elisp routines that would each visit 
one of:
*scratch*, *messages* and *shell*

For *messages* I would only be reading or copying text.
For *scratch* and *shell* I would be modifying those buffers.

which elisp function is best for each of
these buffers?

Would it be switch-to-buffer, display-buffer, set-buffer or something else.?
Thanks
-- 

Tim
tj49.com




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

* Re: Visiting buffers programmatically
  2021-06-10 21:17 Visiting buffers programmatically Tim Johnson
@ 2021-06-10 23:31 ` pillule
  2021-06-11  0:12   ` Tim Johnson
  2021-06-11  0:47 ` Jean Louis
  2021-06-11  0:51 ` Jean Louis
  2 siblings, 1 reply; 8+ messages in thread
From: pillule @ 2021-06-10 23:31 UTC (permalink / raw)
  To: Tim Johnson; +Cc: help-gnu-emacs


Tim Johnson <tim@akwebsoft.com> writes:

> GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
>  of 2021-06-04 ubuntu 20.04
>
> I would like to write three simple elisp routines that would each visit one of:
> *scratch*, *messages* and *shell*
>
> For *messages* I would only be reading or copying text.
> For *scratch* and *shell* I would be modifying those buffers.
>
> which elisp function is best for each of
> these buffers?
>
> Would it be switch-to-buffer, display-buffer, set-buffer or something else.?
> Thanks

Do you need to see the window displaying the buffer ?

If not you can use 'set-buffer' or the macro 'with-current-buffer' that call it.

The others options are meant to display a buffer and not for batch processing.

--



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

* Re: Visiting buffers programmatically
  2021-06-10 23:31 ` pillule
@ 2021-06-11  0:12   ` Tim Johnson
  2021-06-11  0:17     ` pillule
  0 siblings, 1 reply; 8+ messages in thread
From: Tim Johnson @ 2021-06-11  0:12 UTC (permalink / raw)
  To: help-gnu-emacs


On 6/10/21 3:31 PM, pillule wrote:
> Tim Johnson <tim@akwebsoft.com> writes:
>
>> GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
>>   of 2021-06-04 ubuntu 20.04
>>
>> I would like to write three simple elisp routines that would each visit one of:
>> *scratch*, *messages* and *shell*
>>
>> For *messages* I would only be reading or copying text.
>> For *scratch* and *shell* I would be modifying those buffers.
>>
>> which elisp function is best for each of
>> these buffers?
>>
>> Would it be switch-to-buffer, display-buffer, set-buffer or something else.?
>> Thanks
> Do you need to see the window displaying the buffer ?
Yes. I would need to see the window that displays the buffer.
> If not you can use 'set-buffer' or the macro 'with-current-buffer' that call it.
>
> The others options are meant to display a buffer and not for batch processing.
If I grok you correctly, batch processing would mean that a whole list 
of buffers
would be processed and displayed.

No, I would not need to do that.

It sounds like switch-to-buffer would work fine?

Thanks pillule
>
> --
>

-- 
Tim
tj49.com




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

* Re: Visiting buffers programmatically
  2021-06-11  0:12   ` Tim Johnson
@ 2021-06-11  0:17     ` pillule
  2021-06-11  0:32       ` Tim Johnson
  0 siblings, 1 reply; 8+ messages in thread
From: pillule @ 2021-06-11  0:17 UTC (permalink / raw)
  To: Tim Johnson; +Cc: help-gnu-emacs


Tim Johnson <tim@akwebsoft.com> writes:

> On 6/10/21 3:31 PM, pillule wrote:
>> Tim Johnson <tim@akwebsoft.com> writes:
>>
>>> GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
>>>   of 2021-06-04 ubuntu 20.04
>>>
>>> I would like to write three simple elisp routines that would each visit one of:
>>> *scratch*, *messages* and *shell*
>>>
>>> For *messages* I would only be reading or copying text.
>>> For *scratch* and *shell* I would be modifying those buffers.
>>>
>>> which elisp function is best for each of
>>> these buffers?
>>>
>>> Would it be switch-to-buffer, display-buffer, set-buffer or something else.?
>>> Thanks
>> Do you need to see the window displaying the buffer ?
> Yes. I would need to see the window that displays the buffer.
>
>> If not you can use 'set-buffer' or the macro 'with-current-buffer' that call it.
>>
>> The others options are meant to display a buffer and not for batch processing.

> If I grok you correctly, batch processing would mean that a whole list of buffers
> would be processed and displayed.

No. what I call batch processing is exactly when you do not display things and programmatically do all your tasks.

> No, I would not need to do that.
>
> It sounds like switch-to-buffer would work fine?

Yes. 'switch-to-buffer' should display the buffer in the selected window (except unordinary cases).

--



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

* Re: Visiting buffers programmatically
  2021-06-11  0:17     ` pillule
@ 2021-06-11  0:32       ` Tim Johnson
  0 siblings, 0 replies; 8+ messages in thread
From: Tim Johnson @ 2021-06-11  0:32 UTC (permalink / raw)
  To: help-gnu-emacs



On 6/10/21 4:17 PM, pillule wrote:
> Tim Johnson <tim@akwebsoft.com> writes:
>
>> On 6/10/21 3:31 PM, pillule wrote:
>>> Tim Johnson <tim@akwebsoft.com> writes:
>>>
>>>> GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
>>>>    of 2021-06-04 ubuntu 20.04
>>>>
>>>> I would like to write three simple elisp routines that would each visit one of:
>>>> *scratch*, *messages* and *shell*
>>> Do you need to see the window displaying the buffer ?
>> Yes. I would need to see the window that displays the buffer.
>> If I grok you correctly, batch processing would mean that a whole list of buffers
>> would be processed and displayed.
> No. what I call batch processing is exactly when you do not display things and programmatically do all your tasks.
>
Understood. I stand corrected. :)
>> No, I would not need to do that.
>>
>> It sounds like switch-to-buffer would work fine?
> Yes. 'switch-to-buffer' should display the buffer in the selected window (except unordinary cases).
>
Thanks again. I am good to go.

-- 
Tim
tj49.com




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

* Re: Visiting buffers programmatically
  2021-06-10 21:17 Visiting buffers programmatically Tim Johnson
  2021-06-10 23:31 ` pillule
@ 2021-06-11  0:47 ` Jean Louis
  2021-06-11  0:51 ` Jean Louis
  2 siblings, 0 replies; 8+ messages in thread
From: Jean Louis @ 2021-06-11  0:47 UTC (permalink / raw)
  To: Tim Johnson; +Cc: MLEmacs

* Tim Johnson <tim@akwebsoft.com> [2021-06-11 00:18]:
> GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo
> version 1.16.0)
>  of 2021-06-04 ubuntu 20.04
> 
> I would like to write three simple elisp routines that would each visit one
> of:
> *scratch*, *messages* and *shell*
> 
> For *messages* I would only be reading or copying text.
> For *scratch* and *shell* I would be modifying those buffers.
> 
> which elisp function is best for each of
> these buffers?

Here is function that will cycle over the list of buffer names:

(defvar rcd-switch-to-buffer-list '("*scratch*" "*shell*" "*Messages*"))

(defun rcd-switch-to-buffer ()
  (interactive)
  (if (member (current-buffer) (mapcar (lambda (buffer) (get-buffer buffer))
				       rcd-switch-to-buffer-list))
      (when (buffer-live-p (next-circular-list-item 
			    (mapcar (lambda (buffer) (get-buffer buffer))
				    rcd-switch-to-buffer-list)
			    (current-buffer)))
	(switch-to-buffer 
	 (next-circular-list-item 
	  (mapcar (lambda (buffer) (get-buffer buffer))
		  rcd-switch-to-buffer-list)
	  (current-buffer))))
    (when (buffer-live-p (get-buffer (nth 0 rcd-switch-to-buffer-list)))
      (switch-to-buffer (nth 0 rcd-switch-to-buffer-list)))))

and you need this one too:

(defun next-circular-list-item (list previous-item)
  "Return the next element in the LIST by looking at PREVIOUS-ITEM.

All elements in the LIST have to be different.

If last element of LIST is equal to PREVIOUS-ITEM then first element is returned."
  (let ((last-element (car (last list))))
    (cond ((eq last-element previous-item) (car list))
	  (t (nth 1 (member previous-item list))))))


Then M-x rcd-switch-to-buffer will cycle over the list of buffers.

-- 
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] 8+ messages in thread

* Re: Visiting buffers programmatically
  2021-06-10 21:17 Visiting buffers programmatically Tim Johnson
  2021-06-10 23:31 ` pillule
  2021-06-11  0:47 ` Jean Louis
@ 2021-06-11  0:51 ` Jean Louis
  2021-06-11 17:27   ` Tim Johnson
  2 siblings, 1 reply; 8+ messages in thread
From: Jean Louis @ 2021-06-11  0:51 UTC (permalink / raw)
  To: Tim Johnson; +Cc: MLEmacs

The previous one was repetitive, here is shorter version:

(defvar rcd-switch-to-buffer-list '("*scratch*" "*shell*" "*Messages*"))

(defun rcd-switch-to-buffer ()
  (interactive)
  (let ((buffers (mapcar (lambda (buffer) (get-buffer buffer)) rcd-switch-to-buffer-list)))
    (if (member (current-buffer) buffers)
	(when (buffer-live-p (next-circular-list-item buffers (current-buffer)))
	  (switch-to-buffer 
	   (next-circular-list-item buffers (current-buffer))))
      (when (buffer-live-p (get-buffer (nth 0 rcd-switch-to-buffer-list)))
	(switch-to-buffer (nth 0 rcd-switch-to-buffer-list))))))

and you need this one:

(defun next-circular-list-item (list previous-item)
  "Return the next element in the LIST by looking at PREVIOUS-ITEM.

All elements in the LIST have to be different.

If last element of LIST is equal to PREVIOUS-ITEM then first element is returned."
  (let ((last-element (car (last list))))
    (cond ((eq last-element previous-item) (car list))
	  (t (nth 1 (member previous-item list))))))

-- 
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] 8+ messages in thread

* Re: Visiting buffers programmatically
  2021-06-11  0:51 ` Jean Louis
@ 2021-06-11 17:27   ` Tim Johnson
  0 siblings, 0 replies; 8+ messages in thread
From: Tim Johnson @ 2021-06-11 17:27 UTC (permalink / raw)
  To: help-gnu-emacs



On 6/10/21 4:51 PM, Jean Louis wrote:
> The previous one was repetitive, here is shorter version:
>
> (defvar rcd-switch-to-buffer-list '("*scratch*" "*shell*" "*Messages*"))
>
> (defun rcd-switch-to-buffer ()
>    (interactive)
>    (let ((buffers (mapcar (lambda (buffer) (get-buffer buffer)) rcd-switch-to-buffer-list)))
>      (if (member (current-buffer) buffers)
> 	(when (buffer-live-p (next-circular-list-item buffers (current-buffer)))
> 	  (switch-to-buffer
> 	   (next-circular-list-item buffers (current-buffer))))
>        (when (buffer-live-p (get-buffer (nth 0 rcd-switch-to-buffer-list)))
> 	(switch-to-buffer (nth 0 rcd-switch-to-buffer-list))))))
>
> and you need this one:
>
> (defun next-circular-list-item (list previous-item)
>    "Return the next element in the LIST by looking at PREVIOUS-ITEM.
>
> All elements in the LIST have to be different.
>
> If last element of LIST is equal to PREVIOUS-ITEM then first element is returned."
>    (let ((last-element (car (last list))))
>      (cond ((eq last-element previous-item) (car list))
> 	  (t (nth 1 (member previous-item list))))))
>
> Serendipity!It is more than I was looking for to roll my own,
but you have rolled some interesting code. I will give it a home.
Thank you Jean

-- 
Tim
tj49.com




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

end of thread, other threads:[~2021-06-11 17:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-10 21:17 Visiting buffers programmatically Tim Johnson
2021-06-10 23:31 ` pillule
2021-06-11  0:12   ` Tim Johnson
2021-06-11  0:17     ` pillule
2021-06-11  0:32       ` Tim Johnson
2021-06-11  0:47 ` Jean Louis
2021-06-11  0:51 ` Jean Louis
2021-06-11 17:27   ` Tim Johnson

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).