1

I like the way org-capture works, it promotes a buffer for selecting predefined templates. I am trying to do something similar for setting variables.

For example, I have three HTML themes, one for office, one general use, and one for journal. I am trying to define a choose-html-themes() function which has similar behaviour.

I defined a list of options,

(setq html-themes-list 
  '((Office . "<link rel=\"stylesheet\" ..... " )
    (General . "<link rel=\"stylesheet\" ..... ")
    (Journal . "<link rel=\"stylesheet\" ..... "))

When I call choose-html-themes function, then type

  • "o" to set the /entry/ variable to "Office"
  • "g" to "General"
  • "j" to "Journal".

Then it will look up the list using entry as key, and set the org-html-head variable to the returning value, something like

(setq org-html-head (assoc entry html-themes-list))

I wonder how to popup a buffer, and capture keyboard input from that buffer?

  • Doesn't answer the question but have you tried using the hydra package to do something similar? – Kaushal Modi Aug 8 '15 at 2:33
  • @kaushalmodi I tried using hydra, it can solve the problem, but complting-read is more elegant for this case. Thanks. – yi.tang.uni Aug 10 '15 at 8:19
1

Use completing-read. See C-h f completing-read.

(let* ((user-input  (completing-read "Theme: " html-themes-list nil t))
       (theme-link  (cdr (assoc user-input html-themes-list))))
  (DO-SOMETHING-WITH theme-link))
  • Great! I have been looking for this function for a long time! Compared with hydra, I like it more for providing the keys of the list as the selection candidates and I can use helm to choose. Very handy function. Thank you very much! – yi.tang.uni Aug 10 '15 at 8:23
  • I hesitated to write this answer because you specifically asked for org-capture stuff. But it seemed that this does correspond to what you were really trying to do, so I posted it. – Drew Aug 10 '15 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.