all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: John Mastro <john.b.mastro@gmail.com>
To: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: Define skeleton from alist?
Date: Wed, 13 Jul 2016 19:38:00 -0700	[thread overview]
Message-ID: <CAOj2CQSHOHrAHe9TaZ7HAt06x5cizHJ9MjH=RaUGez9HZA4hmQ@mail.gmail.com> (raw)
In-Reply-To: <1468397487.752665.664828897.4AC040A5@webmail.messagingengine.com>

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



  reply	other threads:[~2016-07-14  2:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-13  8:11 Define skeleton from alist? Paul Rankin
2016-07-14  2:38 ` John Mastro [this message]
2016-07-14  6:00   ` Paul Rankin
     [not found] <mailman.1264.1468397506.26859.help-gnu-emacs@gnu.org>
2016-07-13 21:37 ` Gene
2016-07-14  1:12   ` Paul Rankin
     [not found]   ` <mailman.1366.1468458751.26859.help-gnu-emacs@gnu.org>
2016-07-15  1:13     ` Gene

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOj2CQSHOHrAHe9TaZ7HAt06x5cizHJ9MjH=RaUGez9HZA4hmQ@mail.gmail.com' \
    --to=john.b.mastro@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.