2

For example, I want to create a link pointing to line 16 or the start of the first found keyword "binding" in the projectile mode help page ([[help:projectile-mode]]). I tried the double colon format dealing with normal files such as [[help:projectile-mode::16]] and [[help:projectile-mode::binding]] but it doesn't work.

2 Answers 2

1

Only file-type links are allowed to use the search option ::<N> currently.

The code in org-link-open is a bit strange to my eyes: it gets the type of the link and the path of the link. In the file case, the path does not contain the search option, but in all other cases it does. But then the file case concatenates the search option onto the path and calls org-link-open-file with the result (which must take it apart again and do the search). In all other cases, the path is passed as-is (including the search option), but the helper functions (e.g. org-link-open-help) just use the thing literally (and presumably fail: there is no help node org-mode::14).

I'd imagine that the more uniform solution would be to keep the option separate in all cases, and pass it to the helper function explicitly which could use it or throw it away as it saw fit. But that's not the way it's currently done.

2
  • Is it possible to modify the behavior of existing link types? Say, to change the help: type so it supports search options. Apr 28, 2020 at 2:05
  • I think so: you'd have to modify the function org-link-open-help in ol.el.
    – NickD
    Apr 28, 2020 at 13:05
0

You can advice org-link--open-help to move the cursor to the specified line number or search string. The last line highlights the matched line.

(advice-add 'org-link--open-help :around
            (lambda (oldfun path _)
              (let* ((option (and (string-match "::\\(.*\\)\\'" path)
                                  (match-string 1 path)))
                     (path (if (not option) path
                             (substring path 0 (match-beginning 0)))))
                (apply oldfun (list path nil))
                (when-let (help-window (and option
                                            (get-buffer-window (help-buffer))))
                  (save-selected-window
                    (select-window help-window)
                    (if (zerop (string-to-number option))
                        (re-search-forward option nil t)
                      (forward-line (1- (string-to-number option))))
                    (org-highlight-new-match (line-beginning-position)
                                             (line-end-position)))))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.