[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Define skeleton from alist?
From: |
John Mastro |
Subject: |
Re: Define skeleton from alist? |
Date: |
Wed, 13 Jul 2016 19:38:00 -0700 |
Paul Rankin <hello@paulwrankin.com> wrote:
> I'd like to create a skeleton with define-skeleton using strings from
> an alist. The skeleton should loop through the alist using the car of
> each element as both the prompt and first string inserted, then the
> cadr as initial value for user input.
I've never used skeleton but, from a quick look, it seems to me you
might be better served by a normal command. Is there a specific reason
you want/need to use skeleton?
If I understand correctly, this will achieve something like the final
result you want:
(defun fountain-title-page-function ()
(interactive)
(dolist (elt fountain-title-page-list)
(let ((key (car elt))
(val (cadr elt)))
(insert key ": " (read-string (concat key ": ") val) "\n"))))
The reason this seems preferable to me, based on the stated problem, is
that it's impossible for a solution with skeleton to be much simpler
than the command above. By definition, the solution with skeleton will
still need a loop, etc.
Back to your question, I don't see how you could do it with
define-skeleton directly.
I looked at the implementation of define-skeleton, and it hands off the
work to a function called skeleton-proxy-new. I suppose you could call
it directly with something ugly like the below.
That's admittedly unsatisfying, so hopefully someone who actually knows
skeleton will be along with a better answer shortly.
(progn
(put 'fountain-title-page-skeleton 'no-self-insert t)
(defun fountain-title-page-skeleton (&optional str arg)
(interactive "*P\nP")
(skeleton-proxy-new
`(nil ,@(let ((i 0))
(apply #'append
(mapcar
(lambda (elt)
(let ((key (concat (car elt) ": "))
(val (cadr elt))
(sym (intern (format "v%d" (setq i (1+ i))))))
`(> ,key (setq ,sym (skeleton-read ,key ,val)) \n)))
fountain-title-page-list))))
str arg)))
Hope that helps
John