unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Looping through sequence of buttons and labels
@ 2024-07-02 23:19 Heime
  2024-07-03  4:13 ` CToID
  2024-07-03  4:15 ` CToID
  0 siblings, 2 replies; 5+ messages in thread
From: Heime @ 2024-07-02 23:19 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

This function prints a line with two buttons.  I would like to extend this so that
I can have N rows, rather than just a single row as done here.


(defun mondu (monbf funcs labels)
  "Insert buttons in buffer MONBF, using FUNCS for button actions
with LABELS as button labels."

  (with-current-buffer (get-buffer-create monbf)
    (insert " DU \n\n")
    (insert " ")

    (insert-button "[-]" 'action (nth 0 funcs))
    (insert (format " %s  " (nth 0 labels)))

    (insert-button "[-]" 'action (nth 1 funcs))
    (insert (format " %s  " (nth 1 labels))))

  (pop-to-buffer monbf))




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

* Re: Looping through sequence of buttons and labels
  2024-07-02 23:19 Looping through sequence of buttons and labels Heime
@ 2024-07-03  4:13 ` CToID
  2024-07-03  4:15 ` CToID
  1 sibling, 0 replies; 5+ messages in thread
From: CToID @ 2024-07-03  4:13 UTC (permalink / raw)
  To: help-gnu-emacs

```
(dolist (VAR LIST [RESULT]) BODY...)

Loop over a list.
Evaluate BODY with VAR bound to each car from LIST, in turn.
Then evaluate RESULT to get return value, default nil.
```

-- 
Best,

ID




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

* Re: Looping through sequence of buttons and labels
  2024-07-02 23:19 Looping through sequence of buttons and labels Heime
  2024-07-03  4:13 ` CToID
@ 2024-07-03  4:15 ` CToID
  2024-07-03  8:10   ` Heime
  2024-07-03 19:24   ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 2 replies; 5+ messages in thread
From: CToID @ 2024-07-03  4:15 UTC (permalink / raw)
  To: help-gnu-emacs

Just saw you have two lists here, then you should use `dotimes` instead 
of `dolist`.

-- 
Best,

ID




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

* Re: Looping through sequence of buttons and labels
  2024-07-03  4:15 ` CToID
@ 2024-07-03  8:10   ` Heime
  2024-07-03 19:24   ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 5+ messages in thread
From: Heime @ 2024-07-03  8:10 UTC (permalink / raw)
  To: CToID; +Cc: help-gnu-emacs


On Wednesday, July 3rd, 2024 at 4:15 AM, CToID <funk443@yahoo.com.tw> wrote:

> Just saw you have two lists here, then you should use `dotimes` instead
> of `dolist`.
> 
> --
> Best,
> ID

 Your update helps a lot.






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

* Re: Looping through sequence of buttons and labels
  2024-07-03  4:15 ` CToID
  2024-07-03  8:10   ` Heime
@ 2024-07-03 19:24   ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-07-03 19:24 UTC (permalink / raw)
  To: help-gnu-emacs

> Just saw you have two lists here, then you should use `dotimes` instead of
> `dolist`.

This is a good recipe if you want to suffer from O(N²) complexity 🙁
I'd go with `while`, `named-let`, or `cl-loop` instead, tho before that
I'd try to replace the two lists by a list of pairs so I can
just use `(pcase-)dolist`.


        Stefan




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

end of thread, other threads:[~2024-07-03 19:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-02 23:19 Looping through sequence of buttons and labels Heime
2024-07-03  4:13 ` CToID
2024-07-03  4:15 ` CToID
2024-07-03  8:10   ` Heime
2024-07-03 19:24   ` Stefan Monnier via Users list for the GNU Emacs text editor

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