From: Nordlöw <per.nordlow@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Notes: Auto-Generation of Sub-Menu Items (Keys) from a list of lists
Date: Wed, 17 Sep 2008 04:21:22 -0700 (PDT) [thread overview]
Message-ID: <419677f0-d39b-41b0-86a7-758397be5385@m3g2000hsc.googlegroups.com> (raw)
In-Reply-To: 2b204852-9a90-49ea-b3e8-ac2e4a3be5e6@2g2000hsn.googlegroups.com
On 17 Sep, 12:41, Nordlöw <per.nord...@gmail.com> wrote:
> I am trying to automatically create a Sub-menu to "C++"-menu from the
> list c++-iostream-objects in the following way:
>
> (defvar c++-iostream-objects
> '(
> ("cin" [cin] "Standard input stream." 'object)
> ("cout" [cout] "Standard output stream." 'object)
> ("cerr" [cerr] "Standard output stream for errors." 'object)
> ("clog" [clog] "Standard output stream for logging." 'object)
> )
> "List of C++ IOstream Objects.")
>
> (defun generate-keymap-menu (keymap-menu-name insert-prefix alist)
> (let ((m (make-sparse-keymap keymap-menu-name)))
> (dolist (elm (reverse alist))
> (let* ((str (concat insert-prefix (elt elm 0)))
> (key (elt elm 1))
> (doc (elt elm 2))
> )
> (define-key m key `(menu-item ,str '(lambda () (interactive)
> (insert ,str)) :help ,doc))))
> m))
>
> (defvar c++-iostream-objects-menu)
> (setq c++-iostream-objects-menu
> (generate-keymap-menu "IOstream Objects" "std::" c++-iostream-
> objects))
>
> (add-hook 'c++-mode-hook
> '(lambda () (define-key-after c-c++-menu [iostream-objects]
> (cons "IOstream Objects" c++-iostream-objects-
> menu) t))
> t)
>
> The value of c++-iostream-objects-menu after evaluating the above is:
>
> (keymap
> (cin menu-item "std::cin"
> '(lambda nil
> (interactive)
> (insert "std::cin"))
> :help "Standard input stream.")
> (cout menu-item "std::cout"
> '(lambda nil
> (interactive)
> (insert "std::cout"))
> :help "Standard output stream.")
> (cerr menu-item "std::cerr"
> '(lambda nil
> (interactive)
> (insert "std::cerr"))
> :help "Standard output stream for errors.")
> (clog menu-item "std::clog"
> '(lambda nil
> (interactive)
> (insert "std::clog"))
> :help "Standard output stream for logging.")
> "IOstream Objects")
>
> and the sub-menu elements gets created but when I press on one of them
> I get the error:
>
> Debugger entered--Lisp error: (wrong-type-argument commandp (quote
> (lambda nil (interactive) (insert "std::cin"))))
> call-interactively((quote (lambda nil (interactive) (insert
> "std::cin"))) nil nil)
>
> This is really strange since the evaluation of
>
> (call-interactively (quote (lambda nil (interactive) (insert
> "std::cin"))))
>
> works correctly and
>
> (commandp (quote (lambda nil (interactive) (insert "std::cin"))))
>
> evaluates to t.
>
> What on earth have I missed? This nut is really hard to crack!
>
> Many thanks in advance,
> Nordlöw
First Note: All of the above code snippets can be evaluated in Vanilla
Emacs if you want to test or integrate these concepts into other Emacs
add-ons.
Second Note: The fourth element 'object is currently not used for
anything.
/Nordlöw
prev parent reply other threads:[~2008-09-17 11:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-17 10:41 Auto-Generation of Sub-Menu Items (Keys) from a list of lists Nordlöw
2008-09-17 11:21 ` Nordlöw [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=419677f0-d39b-41b0-86a7-758397be5385@m3g2000hsc.googlegroups.com \
--to=per.nordlow@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.
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).