unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#38427: 26.2; skeleton-insert does not set str consistently
@ 2019-11-29 15:59 Tim Landscheidt
  2020-11-01 14:45 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: Tim Landscheidt @ 2019-11-29 15:59 UTC (permalink / raw)
  To: 38427

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





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

* bug#38427: 26.2; skeleton-insert does not set str consistently
  2019-11-29 15:59 bug#38427: 26.2; skeleton-insert does not set str consistently Tim Landscheidt
@ 2020-11-01 14:45 ` Lars Ingebrigtsen
  2020-11-01 20:23   ` Jean Louis
  2020-12-09 15:14   ` Lars Ingebrigtsen
  0 siblings, 2 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2020-11-01 14:45 UTC (permalink / raw)
  To: Tim Landscheidt; +Cc: 38427

Tim Landscheidt <tim@tim-landscheidt.de> 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.  :-)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#38427: 26.2; skeleton-insert does not set str consistently
  2020-11-01 14:45 ` Lars Ingebrigtsen
@ 2020-11-01 20:23   ` Jean Louis
  2020-12-09 15:14   ` Lars Ingebrigtsen
  1 sibling, 0 replies; 4+ messages in thread
From: Jean Louis @ 2020-11-01 20:23 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 38427, Tim Landscheidt

* Lars Ingebrigtsen <larsi@gnus.org> [2020-11-01 17:48]:
> Tim Landscheidt <tim@tim-landscheidt.de> 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.





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

* bug#38427: 26.2; skeleton-insert does not set str consistently
  2020-11-01 14:45 ` Lars Ingebrigtsen
  2020-11-01 20:23   ` Jean Louis
@ 2020-12-09 15:14   ` Lars Ingebrigtsen
  1 sibling, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-09 15:14 UTC (permalink / raw)
  To: Tim Landscheidt; +Cc: 38427

Lars Ingebrigtsen <larsi@gnus.org> writes:

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

More information was requested, but no response was given within a 
month, so I'm closing this bug report.  If progress can be made,
please respond to this email and we'll reopen the bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2020-12-09 15:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-29 15:59 bug#38427: 26.2; skeleton-insert does not set str consistently Tim Landscheidt
2020-11-01 14:45 ` Lars Ingebrigtsen
2020-11-01 20:23   ` Jean Louis
2020-12-09 15:14   ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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