help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using button-label in pcase


From: Stephen Berman
Subject: Re: Using button-label in pcase
Date: Mon, 24 Jul 2023 22:07:11 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

On Mon, 24 Jul 2023 19:14:27 +0000 uzibalqa <uzibalqa@proton.me> wrote:

> Want to print some text as a result of clicking a button.  With the code below
> I end up with
>
> (wrong-type-argument integer-or-marker-p nil)
>   buffer-substring-no-properties(nil nil)
>   button-label(#<overlay in no buffer>)
>   (let* ((val (button-label button))) (if (equal val '"[FA]") (let nil 
> (insert qrh-c))))
>   (closure ((button . #<overlay in no buffer>)) nil (let* ((val (button-label 
> button))) (if (equal val '"[FA]") (let nil (insert qrh-c)))))()
>   help--window-setup("*Help*" (closure ((button . #<overlay in no buffer>)) 
> nil (let* ((val (button-label button))) (if (equal val '"[FA]") (let nil 
> (insert qrh-c))))))
>   qrh-b(#<overlay in no buffer>)
>   button-activate(#<overlay in no buffer> t)
>   push-button(3 t)
>
> What is going on.  Is there a fix?
>
> (defconst qrh-c "[FA] Some Text")
>
> (defun qrh-b (button)
>   "Prints information about how to install emacs."
>   (with-help-window (help-buffer)
>     (pcase (button-label button)
>       ("[FA]" (insert qrh-c))) ))
>
> (defun qrh-a ()
>   "Prints information about how to install emacs."
>   (interactive)
>   (with-help-window (help-buffer)
>     (insert-button "[FC]"
>       'action 'qrh-b 'follow-link t) ))

The error is raised because qrh-b calls with-help-window with the *Help*
buffer current, but with-help-window erases the buffer, so when
`(button-label button)' is evaluated, there is no button and this
signals the error.

If you want to use the existing *Help* buffer, just remove the call to
with-help-window in qrh-b.  However, *Help* buffers are read-only, so
trying to insert text will raise another error.  To avoid this, you can
let-bind buffer-read-only in qrh-b.  However, since qrh-a inserts "[FC]"
but qrh-b tries to match "[FA]", the match will fail, so the insertion
in qrh-b will not happen.

Steve Berman



reply via email to

[Prev in Thread] Current Thread [Next in Thread]