Subject: Re: bug#38427: 26.2; skeleton-insert does not set str consistently

From: Jean Louis <[email-masked]>
Date: Sun, 1 Nov 2020 23:23:29 +0300

* Lars Ingebrigtsen <[email-masked]> [2020-11-01 17:48]:
> Tim Landscheidt <[email-masked]> writes:
> 
> > Given (A):
> >
> > | (let
> > |     ((somevalues '(("a" . "123") ("b" . "456"))))
> > |   (skeleton-insert
> > |    '("Prompt: "
> > |      (cdr (assoc str somevalues)) | str ?\n)))
> >
> > Emacs asks for input with "Prompt: " and with "a" given, it
> > outputs "a" instead of the expected "123".
> 
> Evaluating that form gives me:
> 
> Debugger entered--Lisp error: (void-variable somevalues)
>   (assoc str somevalues)
>   (cdr (assoc str somevalues))
>   eval((cdr (assoc str somevalues)))
>   skeleton-internal-1((cdr (assoc str somevalues)) nil nil)
> 
> I'm not at all familiar with how skeleton works, but a test case that
> works would help when trying to debug.  :-)

I am using skeletong often. And I was of opinion it was made to create
M-x interactive functions as skeletons to quickly insert such snippets
or interactive templates:

(define-skeleton dear-friend
  "Start a letter"
  nil
  "Dear " (setq name (skeleton-read "Name: ")) ", 

Thank you for your feedback.

" _ "

Greetings,
Joe
")

This gives me M-x dear-friend

If there is region marked the _ will replace it with region. It is
very handy.

Tim, I suggest that you define skeleton that works by
`define-skeleton' and then try using it in a function. On the other
hand using skeletons in function somehow beats their purpose.

(let ((somevalues '(("a" . "123") ("b" . "456"))))
(skeleton-insert
 '(nil (setq str (skeleton-read "Var: "))
 (cdr (assoc str somevalues)) | str ?\n)))

Does that work?

I have no idea what | means here.