[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Functions behaving according to button presses
From: |
Jean Louis |
Subject: |
Re: Functions behaving according to button presses |
Date: |
Tue, 29 Aug 2023 10:04:40 +0300 |
User-agent: |
Mutt/2.2.10+64 (b470a9a) (2023-06-05) |
* Heime <heimeborgia@protonmail.com> [2023-08-28 21:13]:
>
> Have noticed that I can have a function like this, which I can
> use with elisp code, using for example
>
> (insert-button "[Next]" 'action 'action-snapshot 'follow-link t)
>
> The above will also work with any button property name like "[Next]".
> Alternatively I can execute only the "[B5]" part using
>
> (insert-button "[B5]" 'action 'action-snapshot 'follow-link t)
>
> Or call it interactively with 'M-x action-snapshot'. In such case,
> the function would execute '(insert "that")'.
>
> (defun action-snapshot (&optional button)
>
> (pcase (button-label button)
> ("[B5]"
> (insert "this"))
> (_
> (insert "that"))))
>
> Is the aforementioned description correct. Is there anything else,
> alternative
> ways of using function that react according to button clicks ?
I understand you wish to have function that recognize the button label
and act accordingly.
(rcd-button-insert "CLICK ME" 'action-function)CLICK ME ➜ nil
(defun action-function (&optional button)
(message "%s" (button-label button)))
The above worked for me.
(rcd-button-insert "CLICK ME" 'action-function)CLICK ME ➜ nil
(rcd-button-insert "CLICK ME HARD" 'action-function)CLICK ME HARD ➜ nil
(defun action-function (&optional button)
(cond ((and button (string= (button-label button) "CLICK ME")) (message
"Clicked me"))
((and button (string= (button-label button) "CLICK ME HARD")) (message
"Clicked me hard"))))
action-function
Clicked me [2 times]
Clicked me hard
Auto-saving...done
I see it works, you can have function that acts different according to
(button-label) results.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/