diff options
author | Bastien Guerry <bzg@altern.org> | 2012-07-13 18:22:45 +0200 |
---|---|---|
committer | Bastien Guerry <bzg@altern.org> | 2012-07-13 18:22:45 +0200 |
commit | ef3d4b5965b828e85a535ef3f32999473c6a2a7a (patch) | |
tree | e0936ef1ec87170de06ec0e12e8e9b63a0dcd5a7 | |
parent | 3ecd7a9ad03323feebad7dd1705302dab9c62372 (diff) | |
download | org-mode-ef3d4b5965b828e85a535ef3f32999473c6a2a7a.tar.gz |
org.el: Allow %(my-function) as a specifier in abbreviated links.
* org.el (org-link-expand-abbrev): Implement "%(my-function)"
as a new specifier. Update the docstring.
* org.texi (Link abbreviations): Illustrate the use of the
"%h" specifier. Document the new "%(my-function)" specifier.
Thanks to Takaaki ISHIKAWA who came all the way down from Tokyo
to Paris and raised a not-so-distant issue: "could we translate
emails from the mailing list and have a URI for each translated
email?" See the update in the manual for an answer.
-rw-r--r-- | doc/org.texi | 24 | ||||
-rw-r--r-- | lisp/org.el | 11 |
2 files changed, 24 insertions, 11 deletions
diff --git a/doc/org.texi b/doc/org.texi index 90844d8..9e910fc 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -3570,18 +3570,26 @@ that relates the linkwords to replacement text. Here is an example: @smalllisp @group (setq org-link-abbrev-alist - '(("bugzilla" . "http://10.1.2.9/bugzilla/show_bug.cgi?id=") - ("google" . "http://www.google.com/search?q=") - ("gmap" . "http://maps.google.com/maps?q=%s") - ("omap" . "http://nominatim.openstreetmap.org/search?q=%s&polygon=1") - ("ads" . "http://adsabs.harvard.edu/cgi-bin/nph-abs_connect?author=%s&db_key=AST"))) + '(("bugzilla" . "http://10.1.2.9/bugzilla/show_bug.cgi?id=") + ("url-to-ja" . "http://translate.google.fr/translate?sl=en&tl=ja&u=%h") + ("google" . "http://www.google.com/search?q=") + ("gmap" . "http://maps.google.com/maps?q=%s") + ("omap" . "http://nominatim.openstreetmap.org/search?q=%s&polygon=1") + ("ads" . "http://adsabs.harvard.edu/cgi-bin/nph-abs_connect?author=%s&db_key=AST"))) @end group @end smalllisp If the replacement text contains the string @samp{%s}, it will be -replaced with the tag. Otherwise the tag will be appended to the string -in order to create the link. You may also specify a function that will -be called with the tag as the only argument to create the link. +replaced with the tag. Using @samp{%h} instead of @samp{%s} will +url-encode the tag (see the example above, where we need to encode +the URL parameter.) Using @samp{%(my-function)} will pass the tag +to a custom function, and replace it by the resulting string. + +If the replacement text don't contain any specifier, it will simply +be appended to the string in order to create the link. + +Instead of a string, you may also specify a function that will be +called with the tag as the only argument to create the link. With the above setting, you could link to a specific bug with @code{[[bugzilla:129]]}, search the web for @samp{OrgMode} with diff --git a/lisp/org.el b/lisp/org.el index 90eee63..e728303 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -1319,9 +1319,12 @@ The 'linkkey' must be a word word, starting with a letter, followed by letters, numbers, '-' or '_'. If REPLACE is a string, the tag will simply be appended to create the link. -If the string contains \"%s\", the tag will be inserted there. Alternatively, -the placeholder \"%h\" will cause a url-encoded version of the tag to -be inserted at that point (see the function `url-hexify-string'). +If the string contains \"%s\", the tag will be inserted there. If the string +contains \"%h\", it will cause a url-encoded version of the tag to be inserted +at that point (see the function `url-hexify-string'). If the string contains +the specifier \"%(my-function)\", then the custom function `my-function' will +be invoked: this function takes the tag as its only argument and must return +a string. REPLACE may also be a function that will be called with the tag as the only argument to create the link, which should be returned as a string. @@ -8668,6 +8671,8 @@ call CMD." (setq rpl (cdr as)) (cond ((symbolp rpl) (funcall rpl tag)) + ((string-match "%(\\([^)]+\\))" rpl) + (replace-match (funcall (intern-soft (match-string 1 rpl)) tag) t t rpl)) ((string-match "%s" rpl) (replace-match (or tag "") t t rpl)) ((string-match "%h" rpl) (replace-match (url-hexify-string (or tag "")) t t rpl)) |