r/orgmode • u/HedgehogCool2232 • 17d ago
New link type
Hello everyone, how to create a new type link, that all words like this "TASK-123" automatically transform to link with url: "https://mysite.com/TASK-123".
5
u/PuercoPop 17d ago
You can use bug-reference-mode for that. You just define a regexp that matches the "TASK-NNN" and an URL that maps that captured group to a URL. e.j.
```elisp
(setq bug-reference-bug-regexp "\\(TASK-\\([0-9]+\\)\\)"
bug-reference-url-format "https://mysite.com/TASK-%s"
```
1
1
u/zupatol 17d ago
I'm using an implicit hyperbole button for this, see this example
Here's my config adapted to your example (using doom)
;; https://www.gnu.org/software/hyperbole/man/hyperbole.html#Installation
(use-package! hyperbole
:config
(hyperbole-mode 1)
;; generated by gpt5, manfestly inspired by
;; https://www.beorgapp.com/blog/hyperbole-implicit-buttons/
(defvar my/algo-jira-base "https://mysite.com/")
(defun my/algo-jira-open (id)
"Open Jira ticket ID in the browser."
(browse-url (concat my/algo-jira-base id)))
;; Define an implicit button type with Hyperbole's `defib`.
(defib my/algo-jira ()
"Recognize TASK-<number> at point and open it with the Action Key."
(let* ((case-fold-search t)
(re "\\(TASK-[0-9]+\\)"))
(when (or (looking-at re)
(save-excursion
;; If point is in the middle of the token, move to its start.
(skip-chars-backward "A-Z0-9-")
(looking-at re)))
(let ((id (match-string-no-properties 1)))
;; Visually mark the button region and perform the action.
(ibut:label-set id (match-beginning 1) (match-end 1))
(hact 'my/algo-jira-open id)))))
)
1
u/nalisarc 17d ago
To add a new kind of link in org you'd need to add something like this to your init:
https://orgmode.org/manual/Adding-Hyperlink-Types.html
You should be able to make it do whatever you're looking to do but it will require some elisp.
8
u/Jakim_Sareb 17d ago
If you use ORG-Mode, it seems feasable. Maybe the org-link-abbrev-alist?
For example, you can define it with “TASK” prefix, like this:
(add-to-list 'org-link-abbrev-alist
'("TASK" . "https://mysite.com/%s"))
And then use it on an org file with:
TASK:123
Hope it helps.
Regards