emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Stephan Schmitt <drmabuse@cs.tu-berlin.de>
To: Nathan Neff <nathan.neff@gmail.com>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>,
	"Štěpán Němec" <stepnem@gmail.com>
Subject: Re: Re: Frequently used files/headings
Date: Mon, 10 May 2010 23:08:28 +0200	[thread overview]
Message-ID: <4BE875CC.20208@cs.tu-berlin.de> (raw)
In-Reply-To: <AANLkTikfIyYov5dknGFSFGjE7YemRAILBqHIltFtvcKr@mail.gmail.com>

Hi Nathan,

when the lambda form is evaluated (when you press f6) the variable
shortcut-def doesn't exist any more.

The problem is that elisp doesn't support closures.  See
this info page:
(elisp) Top > Variables > Variable Scoping > Extent

As a workaraound you can save the table in a global variable with setq
and access that variable in the lambda form.

Hth,
	Stephan

Also sprach Nathan Neff:
> On Mon, May 10, 2010 at 6:35 AM, Štěpán Němec<stepnem@gmail.com>  wrote:
>> Nathan Neff<nathan.neff@gmail.com>  writes:
>>> I tried something like this, but all I get is "Wrong type argument:
>>> integer-or-marker-p, (quote (second shortcut-def))"
>>>
>>> #+srcname: map-nav(navigation-shortcuts=navigation-shortcuts)
>>> #+begin_src emacs-lisp
>>>   (defun map-navigation-shortcuts (shortcut-def)
>>> (global-set-key (kbd (second shortcut-def)) (lambda () "Goto Foo Org File"
>>>      (interactive)
>>>      (org-id-goto '(third shortcut-def)))))
>>>
>>> (mapcar #'map-navigation-shortcuts navigation-shortcuts)
>>>
>>> #+end_src
>>>
>>> Can anyone point out where I'm going wrong?
>>
>> I haven't tried your code, but the way you call `kbd' is obviously
>> wrong.
>>
>> `kbd' is a macro and does not evaluate its arguments; try
>> using `read-kbd-macro' instead.
>
> Stepan,
>
> Thanks for your help -- The keyboard shortcut is now being mapped
> correctly, but
> whenever I press<f6>  a, I get "Symbol's value as a variable is void:
> shortcut-def"
>
> I suspect that (lambda()) is not evaluating (org-id-goto (third
> shortcut-def)).  I need some way to do that.
>
> I would really like to know an "acceptable" or "standard" way to
> implement this feature -- I think it would help me a lot with learning
> Lisp&  functional languages.  Any help is appreciated!
>
> Here's my new code:
>
> #+tblname:navigation-shortcuts
> | Vim                 |<f6>  a   | 733BD03F-0938-432F-B59A-BE235A2DE7E2 |
>
> #+srcname: map-nav(navigation-shortcuts=navigation-shortcuts)
> #+begin_src emacs-lisp
> (defun map-navigation-shortcuts (shortcut-def)
>      (global-set-key (read-kbd-macro (second shortcut-def))
>        (lambda ()
>          (interactive)
>          (org-id-goto (third shortcut-def)))) ;; this line is not
> evaluated inside lambda()
> )
>
> Thanks,
> --Nate
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  reply	other threads:[~2010-05-10 21:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-29 15:47 Frequently used files/headings Nathan Neff
2010-05-06  7:06 ` Nathan Neff
2010-05-10 11:35   ` Štěpán Němec
2010-05-10 20:48     ` Nathan Neff
2010-05-10 21:08       ` Stephan Schmitt [this message]
2010-05-10 21:35         ` Štěpán Němec
2010-05-11 15:42           ` Nathan Neff

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.orgmode.org/

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

  git send-email \
    --in-reply-to=4BE875CC.20208@cs.tu-berlin.de \
    --to=drmabuse@cs.tu-berlin.de \
    --cc=emacs-orgmode@gnu.org \
    --cc=nathan.neff@gmail.com \
    --cc=stepnem@gmail.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).