From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sriram Thaiyar Subject: Re: Dynamic links Date: Mon, 11 Jul 2016 00:42:45 -0700 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a114901c04eb7050537574ccf Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMVri-0001Ri-Jz for emacs-orgmode@gnu.org; Mon, 11 Jul 2016 03:42:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMVrc-0003t4-Fa for emacs-orgmode@gnu.org; Mon, 11 Jul 2016 03:42:50 -0400 Received: from mail-yw0-x230.google.com ([2607:f8b0:4002:c05::230]:36650) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMVrc-0003sW-A2 for emacs-orgmode@gnu.org; Mon, 11 Jul 2016 03:42:48 -0400 Received: by mail-yw0-x230.google.com with SMTP id b72so85544154ywa.3 for ; Mon, 11 Jul 2016 00:42:45 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: John Kitchin Cc: emacs-orgmode@gnu.org --001a114901c04eb7050537574ccf Content-Type: text/plain; charset=UTF-8 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 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 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 > --001a114901c04eb7050537574ccf Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
That is exactly what I want!! Thank you!
Added bonus: = it seems I can use this with any other mode.

I'v= e updated the code:

<= /div>
And I'm invoking it like so:

(a= dd-hook 'org-mode-hook
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (la= mbda ()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (my-org-create-= dynamic-link
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&quo= t;\\([[:alpha:]]\\{2,5\\}-[[:digit:]]+\\)"
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"https://www.some-ticket-system/%s")))

=
-Sriram


On Sun, Jul 10, 2016 at 2:19 PM, John Kit= chin <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-ha= ndles-in-Emacs/
for example (and search "clickable text" on my blog for other exa= mples).

Maybe something like:

#+BEGIN_SRC emacs-lisp
(require 'button-lock)
(global-button-lock-mode)

(defvar ticket-regexp "\\([[:alpha:]]\\{2,5\\}-[[:digit:]]+\\)")<= br>
(button-lock-set-button
=C2=A0ticket-regexp
=C2=A0(lambda ()
=C2=A0 =C2=A0(interactive)
=C2=A0 =C2=A0(save-excursion
=C2=A0 =C2=A0 =C2=A0(goto-char (previous-single-property-change (point) = 9;button-lock))
=C2=A0 =C2=A0 =C2=A0(looking-at ticket-regexp)
=C2=A0 =C2=A0 =C2=A0(browse-url (format "http://www.some-ticket= -system/%s" (match-string 0)))))
=C2=A0: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 li= nks 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.c= om/sri/dotfiles/commit/cd3429ce0c8e637c803835299c2ed4653d19a5fb
>
> (This works with Org-mode version: 8.3.4 - 8.3.4-88-g792bb9-elpa.)
>
> With this config:
>
>=C2=A0 =C2=A0 =C2=A0(add-to-list 'my-org-dynamic-links-matcher
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 '(&q= uot;\\([[:alpha:]]\\{2,5\\}-[[:digit:]]+\\)"
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &= quot;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
>=C2=A0 =C2=A0like I would need to advice the `org-return' function.=
>
> - Despite the fact that the `TEST-123' has a `htmlize-link' te= xt property,
>=C2=A0 =C2=A0it errors out with "No link found". To fix that,= I needed to add a hook to
>=C2=A0 =C2=A0`org-open-at-point-functions'.
>
> - I had to copy a bunch of code from `org-activate-plain-links' to= get
>=C2=A0 =C2=A0this 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

--001a114901c04eb7050537574ccf--