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

From: Tim Landscheidt <[email-masked]>
Date: Fri, 29 Nov 2019 15:59:41 +0000

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

However, with (B):

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

and input "a", it outputs "a" and then "123".

This appears to be due to str being set on the first use on
its own and being:

| (setq str (skeleton-read (quote "Prompt: ") nil nil))

before that (which is not a key in somevalues).

This is probably best shown by (C):

| (let
|     ((somevalues '(("a" . "123") ("b" . "456"))))
|   (skeleton-insert
|    '("Prompt: "
|      (cdr (assoc str somevalues)) | "nothing" ?\n)))

which immediately outputs "nothing", without prompting the
user.

This might be a case of PEBKAC, but to me it feels "unnatu-
ral" that removing "str ?\n" from (B) to (A) does not only
remove the line from the output, but changes the meaning of
the skeleton altogether.

(In my use case, I could work around that by outputting str
in a comment, and in general one could probable just add
some dummy like "str (delete-backward-char (length str))",
but this feels very hackish and brittle.)