* Smart processing of http(s) links
@ 2020-06-28 20:43 Ag Ibragimov
2020-06-28 21:02 ` Kyle Meyer
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Ag Ibragimov @ 2020-06-28 20:43 UTC (permalink / raw)
To: emacs-orgmode
I want to make something like this:
Whenever I I use org-insert-link and it turns out to be a URI that starts with "https://github.com" I would like it to be processed differently than any other link, one example - if it is a PR or a Github Issue, I'd like it to fetch summary(title) of it and create a link that looks like this:
[[https://github.com/user/repo/issues/3899][This issue needs to be fixed #3899]]
Do we have any "built-in" mechanism for doing something like this? Can someone suggest how I can make it. Thank you!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Smart processing of http(s) links
2020-06-28 20:43 Smart processing of http(s) links Ag Ibragimov
@ 2020-06-28 21:02 ` Kyle Meyer
2020-06-28 23:59 ` Ag Ibragimov
2020-06-29 0:44 ` Tim Cross
2020-06-29 10:51 ` Christian Heinrich
2 siblings, 1 reply; 7+ messages in thread
From: Kyle Meyer @ 2020-06-28 21:02 UTC (permalink / raw)
To: Ag Ibragimov; +Cc: emacs-orgmode
Ag Ibragimov writes:
> Whenever I I use org-insert-link and it turns out to be a URI that
> starts with "https://github.com" I would like it to be processed
> differently than any other link, one example - if it is a PR or a
> Github Issue, I'd like it to fetch summary(title) of it and create a
> link that looks like this:
>
> [[https://github.com/user/repo/issues/3899][This issue needs to be fixed #3899]]
>
> Do we have any "built-in" mechanism for doing something like this? Can
> someone suggest how I can make it. Thank you!
You can set org-link-make-description-function to a function that
detects links of interest and generates a custom description.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Smart processing of http(s) links
2020-06-28 21:02 ` Kyle Meyer
@ 2020-06-28 23:59 ` Ag Ibragimov
2020-06-29 9:35 ` Bonface M. K.
0 siblings, 1 reply; 7+ messages in thread
From: Ag Ibragimov @ 2020-06-28 23:59 UTC (permalink / raw)
To: Kyle Meyer; +Cc: emacs-orgmode
Oh cool. This is exactly what I needed:
I was able to build this:
#+begin_src emacs-lisp
(defun get-gh-item-title (uri &optional include-number?)
"Based on given github URI for (pull request or an issue),
returns its title"
(when (string-match "\\(github.com\\).*\\(issues\\|pull\\)" uri) ; either PR or issue
(pcase-let* ((`(_ _ ,owner ,repo ,type ,number) (remove "" (split-string uri "/")))
(gh-resource (format "/repos/%s/%s/%s/%s"
owner
repo
(if (string= type "pull") "pulls" type)
number))
(resp (ghub-get gh-resource nil :auth 'forge)))
(when resp
(format "%s%s" (alist-get 'title resp)
(when include-number? (format " #%s" number)))))))
(defun org-link-make-description-function* (link desc)
(cond ((string-match "\\(github.com\\).*\\(issues\\|pull\\)" link)
(get-gh-item-title link :with-number))
(t desc)))
(setq org-link-make-description-function 'org-link-make-description-function*)
#+end_src
https://gist.github.com/agzam/b2f2d441acb96e1d693a2c81e9c4518f
On Sun 28 Jun 2020 at 14:02, Kyle Meyer <kyle@kyleam.com> wrote:
> Ag Ibragimov writes:
>
>> Whenever I I use org-insert-link and it turns out to be a URI that
>> starts with "https://github.com" I would like it to be processed
>> differently than any other link, one example - if it is a PR or a
>> Github Issue, I'd like it to fetch summary(title) of it and create a
>> link that looks like this:
>>
>> [[https://github.com/user/repo/issues/3899][This issue needs to be fixed #3899]]
>>
>> Do we have any "built-in" mechanism for doing something like this? Can
>> someone suggest how I can make it. Thank you!
>
> You can set org-link-make-description-function to a function that
> detects links of interest and generates a custom description.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Smart processing of http(s) links
2020-06-28 20:43 Smart processing of http(s) links Ag Ibragimov
2020-06-28 21:02 ` Kyle Meyer
@ 2020-06-29 0:44 ` Tim Cross
2020-06-29 1:13 ` Ag Ibragimov
2020-06-29 10:51 ` Christian Heinrich
2 siblings, 1 reply; 7+ messages in thread
From: Tim Cross @ 2020-06-29 0:44 UTC (permalink / raw)
To: emacs-orgmode
Ag Ibragimov <agzam.ibragimov@gmail.com> writes:
> I want to make something like this:
>
> Whenever I I use org-insert-link and it turns out to be a URI that starts with "https://github.com" I would like it to be processed differently than any other link, one example - if it is a PR or a Github Issue, I'd like it to fetch summary(title) of it and create a link that looks like this:
>
> [[https://github.com/user/repo/issues/3899][This issue needs to be fixed #3899]]
>
> Do we have any "built-in" mechanism for doing something like this? Can someone suggest how I can make it. Thank you!
I suspect you could do something with browse-url. The issue I see here
is why you would want the contents fetched whenever you insert a link or
where this summary(title). I guess I don't really understand what
exactly is your use case here - everything I can think of seems more
complicated and requiring more maintenance than just typing the
appropriate description when you insert the link.
--
Tim Cross
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Smart processing of http(s) links
2020-06-29 0:44 ` Tim Cross
@ 2020-06-29 1:13 ` Ag Ibragimov
0 siblings, 0 replies; 7+ messages in thread
From: Ag Ibragimov @ 2020-06-29 1:13 UTC (permalink / raw)
To: Tim Cross; +Cc: emacs-orgmode
> seems more
> complicated and requiring more maintenance than just typing the
> appropriate description when you insert the link.
Actually, it is not. See my reply to Kyle. You still can modify the link description, it just gives you an option to make it as the title of the GitHub issue or PR.
https://gist.github.com/agzam/b2f2d441acb96e1d693a2c81e9c4518f
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Smart processing of http(s) links
2020-06-28 23:59 ` Ag Ibragimov
@ 2020-06-29 9:35 ` Bonface M. K.
0 siblings, 0 replies; 7+ messages in thread
From: Bonface M. K. @ 2020-06-29 9:35 UTC (permalink / raw)
To: Ag Ibragimov; +Cc: emacs-orgmode
Ag Ibragimov <agzam.ibragimov@gmail.com> writes:
> Oh cool. This is exactly what I needed:
>
> I was able to build this:
>
> #+begin_src emacs-lisp
> (defun get-gh-item-title (uri &optional include-number?)
> "Based on given github URI for (pull request or an issue),
> returns its title"
> (when (string-match "\\(github.com\\).*\\(issues\\|pull\\)" uri) ; either PR or issue
> (pcase-let* ((`(_ _ ,owner ,repo ,type ,number) (remove "" (split-string uri "/")))
> (gh-resource (format "/repos/%s/%s/%s/%s"
> owner
> repo
> (if (string= type "pull") "pulls" type)
> number))
> (resp (ghub-get gh-resource nil :auth 'forge)))
> (when resp
> (format "%s%s" (alist-get 'title resp)
> (when include-number? (format " #%s" number)))))))
>
> (defun org-link-make-description-function* (link desc)
> (cond ((string-match "\\(github.com\\).*\\(issues\\|pull\\)" link)
> (get-gh-item-title link :with-number))
> (t desc)))
>
> (setq org-link-make-description-function 'org-link-make-description-function*)
> #+end_src
>
Thanks for this!
> https://gist.github.com/agzam/b2f2d441acb96e1d693a2c81e9c4518f
> On Sun 28 Jun 2020 at 14:02, Kyle Meyer <kyle@kyleam.com> wrote:
>
>> Ag Ibragimov writes:
>>
>>> Whenever I I use org-insert-link and it turns out to be a URI that
>>> starts with "https://github.com" I would like it to be processed
>>> differently than any other link, one example - if it is a PR or a
>>> Github Issue, I'd like it to fetch summary(title) of it and create a
>>> link that looks like this:
>>>
>>> [[https://github.com/user/repo/issues/3899][This issue needs to be fixed #3899]]
>>>
>>> Do we have any "built-in" mechanism for doing something like this? Can
>>> someone suggest how I can make it. Thank you!
>>
>> You can set org-link-make-description-function to a function that
>> detects links of interest and generates a custom description.
>
>
--
Bonface M. K. (https://www.bonfacemunyoki.com)
One Divine Emacs To Rule Them All
GPG key = D4F09EB110177E03C28E2FE1F5BBAE1E0392253F
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Smart processing of http(s) links
2020-06-28 20:43 Smart processing of http(s) links Ag Ibragimov
2020-06-28 21:02 ` Kyle Meyer
2020-06-29 0:44 ` Tim Cross
@ 2020-06-29 10:51 ` Christian Heinrich
2 siblings, 0 replies; 7+ messages in thread
From: Christian Heinrich @ 2020-06-29 10:51 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 810 bytes --]
I'm not sure if this is of interest to you, but I like org-cliplink to insert links with their
titles. Maybe you can look at their source to build your own if it doesn't work for you?
On Sun, 2020-06-28 at 13:43 -0700, Ag Ibragimov wrote:
> I want to make something like this:
>
> Whenever I I use org-insert-link and it turns out to be a URI that starts with "https://github.com
> " I would like it to be processed differently than any other link, one example - if it is a PR or
> a Github Issue, I'd like it to fetch summary(title) of it and create a link that looks like this:
>
> [[https://github.com/user/repo/issues/3899][This issue needs to be fixed #3899]]
>
> Do we have any "built-in" mechanism for doing something like this? Can someone suggest how I can
> make it. Thank you!
>
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-06-29 10:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-28 20:43 Smart processing of http(s) links Ag Ibragimov
2020-06-28 21:02 ` Kyle Meyer
2020-06-28 23:59 ` Ag Ibragimov
2020-06-29 9:35 ` Bonface M. K.
2020-06-29 0:44 ` Tim Cross
2020-06-29 1:13 ` Ag Ibragimov
2020-06-29 10:51 ` Christian Heinrich
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).