emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Frequently used files/headings
@ 2010-04-29 15:47 Nathan Neff
  2010-05-06  7:06 ` Nathan Neff
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Neff @ 2010-04-29 15:47 UTC (permalink / raw)
  To: emacs-orgmode

Currently, I'm using org-id-get-create to generate a unique ID
for headings that I frequently go to in org-mode.

* Foo
:PROPERTIES:
:ID: F3B14102-A66D-408C-8833-1F9CF7E5047C
:END:

Then, I copy the newly created ID to the kill-ring,
and paste it into a block like this:

(global-set-key (kbd "<f6> f") (lambda () "Goto Foo Org File"
    (interactive)
    (org-id-goto "F3B14102-A66D-408C-8833-1F9CF7E5047C")))

This will map F6-f to jump to Foo.

I know that there are many ways to navigate org-files, but using the
ID is great because it requires only two keystrokes.

This works pretty good, except I'd like to improve three things:

1)  I'd like to be able to see a menu of where I've mapped my shortcuts
2)  I'd like to simplify the creation of these IDs and shortcut keys.
3)  I have about 10 quick-keys now, so I have 30 lines of very similar code

I'm sensing an org-babel type approach where I could define an org-mode
table like this:

| Name | Key       | ID |
| Foo    | "<f6> f"  | 123456779 |

Then, I could loop through the table, and for each row, I could
run this code:

(global-set-key (kbd <COLUMN 2>) (lambda () <COLUMN 1>
    (interactive)
    (org-id-goto <COLUMN 3>)))

Before I do something like this, I'd like to know if anyone's done something
similar or if anyone wants to chime in.

Thanks!

--Nate

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Frequently used files/headings
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Neff @ 2010-05-06  7:06 UTC (permalink / raw)
  To: emacs-orgmode

On Thu, Apr 29, 2010 at 10:47 AM, Nathan Neff <nathan.neff@gmail.com> wrote:
> Currently, I'm using org-id-get-create to generate a unique ID
> for headings that I frequently go to in org-mode.
>
> * Foo
> :PROPERTIES:
> :ID: F3B14102-A66D-408C-8833-1F9CF7E5047C
> :END:
>
> Then, I copy the newly created ID to the kill-ring,
> and paste it into a block like this:
>
> (global-set-key (kbd "<f6> f") (lambda () "Goto Foo Org File"
>    (interactive)
>    (org-id-goto "F3B14102-A66D-408C-8833-1F9CF7E5047C")))
>
> This will map F6-f to jump to Foo.
>
> I know that there are many ways to navigate org-files, but using the
> ID is great because it requires only two keystrokes.
>
> This works pretty good, except I'd like to improve three things:
>
> 1)  I'd like to be able to see a menu of where I've mapped my shortcuts
> 2)  I'd like to simplify the creation of these IDs and shortcut keys.
> 3)  I have about 10 quick-keys now, so I have 30 lines of very similar code
>
> I'm sensing an org-babel type approach where I could define an org-mode
> table like this:
>
> | Name | Key       | ID |
> | Foo    | "<f6> f"  | 123456779 |
>
> Then, I could loop through the table, and for each row, I could
> run this code:
>
> (global-set-key (kbd <COLUMN 2>) (lambda () <COLUMN 1>
>    (interactive)
>    (org-id-goto <COLUMN 3>)))
>

I've made some progress on this, and I've defined a table like this:

#+tblname:navigation-shortcuts
| Foo Org File        | <f6 v>   | 733BD03F-0938-432F-B59A-BE235A2DE7E2 |
| Bar Org File        |  <f6 b>  |  123456 |

I would like to map a function that iterates over the items in the
table, and maps
the keyboard string in column 2 to the ID in column 3.

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?

Thanks,
--Nate

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Frequently used files/headings
  2010-05-06  7:06 ` Nathan Neff
@ 2010-05-10 11:35   ` Štěpán Němec
  2010-05-10 20:48     ` Nathan Neff
  0 siblings, 1 reply; 7+ messages in thread
From: Štěpán Němec @ 2010-05-10 11:35 UTC (permalink / raw)
  To: Nathan Neff; +Cc: emacs-orgmode

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.

HTH,

Štěpán

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Frequently used files/headings
  2010-05-10 11:35   ` Štěpán Němec
@ 2010-05-10 20:48     ` Nathan Neff
  2010-05-10 21:08       ` Stephan Schmitt
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Neff @ 2010-05-10 20:48 UTC (permalink / raw)
  To: Štěpán Němec; +Cc: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Re: Frequently used files/headings
  2010-05-10 20:48     ` Nathan Neff
@ 2010-05-10 21:08       ` Stephan Schmitt
  2010-05-10 21:35         ` Štěpán Němec
  0 siblings, 1 reply; 7+ messages in thread
From: Stephan Schmitt @ 2010-05-10 21:08 UTC (permalink / raw)
  To: Nathan Neff; +Cc: emacs-orgmode, Štěpán Němec

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Frequently used files/headings
  2010-05-10 21:08       ` Stephan Schmitt
@ 2010-05-10 21:35         ` Štěpán Němec
  2010-05-11 15:42           ` Nathan Neff
  0 siblings, 1 reply; 7+ messages in thread
From: Štěpán Němec @ 2010-05-10 21:35 UTC (permalink / raw)
  To: Stephan Schmitt; +Cc: emacs-orgmode

Stephan Schmitt <drmabuse@cs.tu-berlin.de> writes:
> 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.

Another way would be to use `lexical-let' from the CL package, i.e.:

  (global-set-key (read-kbd-macro (second shortcut-def))
                  (lexical-let ((shortcut-def shortcut-def))
                    (lambda ()
                      (interactive)
                      (org-id-goto (third shortcut-def)))))

should do what you want.

  Štěpán

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Frequently used files/headings
  2010-05-10 21:35         ` Štěpán Němec
@ 2010-05-11 15:42           ` Nathan Neff
  0 siblings, 0 replies; 7+ messages in thread
From: Nathan Neff @ 2010-05-11 15:42 UTC (permalink / raw)
  To: Štěpán Němec; +Cc: emacs-orgmode

> Another way would be to use `lexical-let' from the CL package, i.e.:
>
>  (global-set-key (read-kbd-macro (second shortcut-def))
>                  (lexical-let ((shortcut-def shortcut-def))
>                    (lambda ()
>                      (interactive)
>                      (org-id-goto (third shortcut-def)))))
>
> should do what you want.
>
>  Štěpán
>

This is very cool!

Here's the final source code for defining shortcuts to headings in
org-mode files, if anyone's interested:

* Fast Navigation to Files
  :PROPERTIES:
  :ID:       FC8A103B-5959-4A13-9735-F175C36CDC01
  :END:
  - Create an ID using org-id-get-create (See the :ID: in
    the :PROPERTIES: for this heading)
  - Put that ID in the table below, along with your favorite shortcut
    sequence and a description
  - See "Nav Shortcuts" below for an example
  - Save oodles of time with your shortcuts, but waste the time
    writing lisp code to implement the shortcut list :-)


#+tblname:shortcut-definition-list
| Appointments       | <f6> a    | A33F7A0C-F974-4C7F-A4FD-1AAA6CF9C60E |
| Foo Org File       | <f6> f    | F3B14102-A66D-408C-8833-1F9CF7E5047C |
| Home               | <f6> h    | 772DFBDD-38A3-4E92-8860-6904CC9D4F49 |
| Nav Shortcuts      | <f6> <f6> | FC8A103B-5959-4A13-9735-F175C36CDC01 |


#+srcname: map-nav(shortcut-definition-list=shortcut-definition-list)
#+begin_src emacs-lisp
(defun map-navigation-shortcuts(shortcut-def)
(global-set-key (read-kbd-macro (second shortcut-def))
                 (lexical-let ((shortcut-def shortcut-def))
                   (lambda ()
                     (interactive)
                     (org-id-goto (third shortcut-def))))))
(mapcar #'map-navigation-shortcuts shortcut-definition-list)
#+end_src

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-05-11 15:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2010-05-10 21:35         ` Štěpán Němec
2010-05-11 15:42           ` Nathan Neff

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).