* Dynamic links
@ 2016-07-08 22:00 Sriram Thaiyar
2016-07-10 21:19 ` John Kitchin
0 siblings, 1 reply; 3+ messages in thread
From: Sriram Thaiyar @ 2016-07-08 22:00 UTC (permalink / raw
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1165 bytes --]
Hi-
I've implemented "dynamic links" which are like plain links but for
arbitrary regular expressions.
I was wondering if there was a better way to do this?
You can see the implementation here:
https://github.com/sri/dotfiles/commit/cd3429ce0c8e637c803835299c2ed4653d19a5fb
(This works with Org-mode version: 8.3.4 - 8.3.4-88-g792bb9-elpa.)
With this config:
(add-to-list 'my-org-dynamic-links-matcher
'("\\([[:alpha:]]\\{2,5\\}-[[:digit:]]+\\)"
"https://some-ticketing-system.org/%s"))
a string like `TEST-122' is turned into a link, as you type it in.
And when you click on that link, it'll visit this URL:
https://some-ticketing-system.org/TEST-122
There are some things that gave me problems:
- I can't hit <return> and have it follow the link. For this, it seems
like I would need to advice the `org-return' function.
- Despite the fact that the `TEST-123' has a `htmlize-link' text property,
it errors out with "No link found". To fix that, I needed to add a hook to
`org-open-at-point-functions'.
- I had to copy a bunch of code from `org-activate-plain-links' to get
this to work.
Thanks,
-Sriram
[-- Attachment #2: Type: text/html, Size: 1945 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Dynamic links
2016-07-08 22:00 Dynamic links Sriram Thaiyar
@ 2016-07-10 21:19 ` John Kitchin
2016-07-11 7:42 ` Sriram Thaiyar
0 siblings, 1 reply; 3+ messages in thread
From: John Kitchin @ 2016-07-10 21:19 UTC (permalink / raw
To: Sriram Thaiyar; +Cc: emacs-orgmode
It kind of sounds like you want the button-lock package. See
http://kitchingroup.cheme.cmu.edu/blog/2015/03/18/Clickable-links-for-Twitter-handles-in-Emacs/
for example (and search "clickable text" on my blog for other examples).
Maybe something like:
#+BEGIN_SRC emacs-lisp
(require 'button-lock)
(global-button-lock-mode)
(defvar ticket-regexp "\\([[:alpha:]]\\{2,5\\}-[[:digit:]]+\\)")
(button-lock-set-button
ticket-regexp
(lambda ()
(interactive)
(save-excursion
(goto-char (previous-single-property-change (point) 'button-lock))
(looking-at ticket-regexp)
(browse-url (format "http://www.some-ticket-system/%s" (match-string 0)))))
:face 'org-link)
#+END_SRC
You get no export with this, but it has the functionality you want I
think.
Sriram Thaiyar writes:
> Hi-
>
> I've implemented "dynamic links" which are like plain links but for
> arbitrary regular expressions.
>
> I was wondering if there was a better way to do this?
>
> You can see the implementation here:
> https://github.com/sri/dotfiles/commit/cd3429ce0c8e637c803835299c2ed4653d19a5fb
>
> (This works with Org-mode version: 8.3.4 - 8.3.4-88-g792bb9-elpa.)
>
> With this config:
>
> (add-to-list 'my-org-dynamic-links-matcher
> '("\\([[:alpha:]]\\{2,5\\}-[[:digit:]]+\\)"
> "https://some-ticketing-system.org/%s"))
>
> a string like `TEST-122' is turned into a link, as you type it in.
> And when you click on that link, it'll visit this URL:
> https://some-ticketing-system.org/TEST-122
>
> There are some things that gave me problems:
>
> - I can't hit <return> and have it follow the link. For this, it seems
> like I would need to advice the `org-return' function.
>
> - Despite the fact that the `TEST-123' has a `htmlize-link' text property,
> it errors out with "No link found". To fix that, I needed to add a hook to
> `org-open-at-point-functions'.
>
> - I had to copy a bunch of code from `org-activate-plain-links' to get
> this to work.
>
> Thanks,
> -Sriram
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Dynamic links
2016-07-10 21:19 ` John Kitchin
@ 2016-07-11 7:42 ` Sriram Thaiyar
0 siblings, 0 replies; 3+ messages in thread
From: Sriram Thaiyar @ 2016-07-11 7:42 UTC (permalink / raw
To: John Kitchin; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 2881 bytes --]
That is exactly what I want!! Thank you!
Added bonus: it seems I can use this with any other mode.
I've updated the code:
https://github.com/sri/dotfiles/commit/3b2e42f488393dfc0f7fa91887877af5b195a20c
And I'm invoking it like so:
(add-hook 'org-mode-hook
(lambda ()
(my-org-create-dynamic-link
"\\([[:alpha:]]\\{2,5\\}-[[:digit:]]+\\)"
"https://www.some-ticket-system/%s")))
-Sriram
On Sun, Jul 10, 2016 at 2:19 PM, John Kitchin <jkitchin@andrew.cmu.edu>
wrote:
> It kind of sounds like you want the button-lock package. See
>
> http://kitchingroup.cheme.cmu.edu/blog/2015/03/18/Clickable-links-for-Twitter-handles-in-Emacs/
> for example (and search "clickable text" on my blog for other examples).
>
> Maybe something like:
>
> #+BEGIN_SRC emacs-lisp
> (require 'button-lock)
> (global-button-lock-mode)
>
> (defvar ticket-regexp "\\([[:alpha:]]\\{2,5\\}-[[:digit:]]+\\)")
>
> (button-lock-set-button
> ticket-regexp
> (lambda ()
> (interactive)
> (save-excursion
> (goto-char (previous-single-property-change (point) 'button-lock))
> (looking-at ticket-regexp)
> (browse-url (format "http://www.some-ticket-system/%s" (match-string
> 0)))))
> :face 'org-link)
> #+END_SRC
>
> You get no export with this, but it has the functionality you want I
> think.
>
> Sriram Thaiyar writes:
>
> > Hi-
> >
> > I've implemented "dynamic links" which are like plain links but for
> > arbitrary regular expressions.
> >
> > I was wondering if there was a better way to do this?
> >
> > You can see the implementation here:
> >
> https://github.com/sri/dotfiles/commit/cd3429ce0c8e637c803835299c2ed4653d19a5fb
> >
> > (This works with Org-mode version: 8.3.4 - 8.3.4-88-g792bb9-elpa.)
> >
> > With this config:
> >
> > (add-to-list 'my-org-dynamic-links-matcher
> > '("\\([[:alpha:]]\\{2,5\\}-[[:digit:]]+\\)"
> > "https://some-ticketing-system.org/%s"))
> >
> > a string like `TEST-122' is turned into a link, as you type it in.
> > And when you click on that link, it'll visit this URL:
> > https://some-ticketing-system.org/TEST-122
> >
> > There are some things that gave me problems:
> >
> > - I can't hit <return> and have it follow the link. For this, it seems
> > like I would need to advice the `org-return' function.
> >
> > - Despite the fact that the `TEST-123' has a `htmlize-link' text
> property,
> > it errors out with "No link found". To fix that, I needed to add a
> hook to
> > `org-open-at-point-functions'.
> >
> > - I had to copy a bunch of code from `org-activate-plain-links' to get
> > this to work.
> >
> > Thanks,
> > -Sriram
>
>
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>
[-- Attachment #2: Type: text/html, Size: 4837 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-07-11 7:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-08 22:00 Dynamic links Sriram Thaiyar
2016-07-10 21:19 ` John Kitchin
2016-07-11 7:42 ` Sriram Thaiyar
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.