33; ; Author: Bob Weiner
44; ;
55; ; Orig-Date: 2-Jul-16 at 14:54:14
6- ; ; Last-Mod: 29-Mar -26 at 22:57:14 by Bob Weiner
6+ ; ; Last-Mod: 16-Jun -26 at 15:48:04 by Bob Weiner
77; ;
88; ; SPDX-License-Identifier: GPL-3.0-or-later
99; ;
4040(require 'org-element )
4141(require 'org-fold nil t )
4242(require 'org-macs )
43+ (require 'thingatpt )
4344(require 'warnings )
4445(require 'find-func )
4546; ; Avoid any potential library name conflict by giving the load directory.
@@ -525,6 +526,7 @@ Match to all todos if `keyword' is nil or the empty string."
525526 (let ((case-fold-search t ))
526527 (looking-at org-babel-src-block-regexp))))
527528
529+ ; ; Derived in part from `org-open-at-point-global' in "org.el"
528530(defun hsys-org-link-at-p ()
529531 " Return (start . end) iff point is on a delimited Org mode link, else nil.
530532Start and end are the buffer positions of the label of the link. This
@@ -537,27 +539,45 @@ link (return nil); instead activate it as HyWikiWord reference.
537539
538540Assume caller has already checked that the current buffer is in
539541`org-mode' or is looking for an Org link in a non-Org buffer type."
540- (unless (or (smart-eolp) (smart-eobp))
541- (let (label-start-end)
542- (if (derived-mode-p 'org-mode )
543- ; ; Must be in `org-mode' to use `org-element-property'
544- (when (org-element-property :raw-link (org-element-context ))
545- ; ; At an Org link
546- (save-match-data
547- ; ; If this Org link matches a potential HyWikiWord, ignore it.
548- (when (and (not (and (fboundp 'hywiki-word-at ) (hywiki-word-at)))
549- (setq label-start-end (hsys-org-link-label-start-end)))
550- (cons (nth 1 label-start-end) (nth 2 label-start-end)))))
551- ; ; Non-Org mode (can't call org-element (which
552- ; ; hsys-org-thing-at-p calls) outside of Org mode.
553- ; ; Check if point is inside a link.
554- (save-match-data
555- ; ; If any Org link matches a potential HyWikiWord, ignore it.
556- (when (and (not (and (fboundp 'hywiki-word-at ) (hywiki-word-at)))
557- (setq label-start-end (hargs:delimited " [[" " ]]" nil nil t )))
558- (let* ((start (nth 1 label-start-end))
559- (end (nth 2 label-start-end)))
560- (cons start end))))))))
542+ (unless (or (smart-eolp) (smart-eobp)
543+ ; ; The types below are handled by Hyperbole ibtypes
544+ (let ((str (hpath:www-at-p)))
545+ (and str
546+ ; ; If a file link, don't consider a url unless has at
547+ ; ; least 2 forward slashes after the :.
548+ (if (string-prefix-p " file:/" str)
549+ (string-prefix-p " file://" str)
550+ t )))
551+ (thing-at-point 'email ))
552+ (and
553+ ; ; If this Org link matches a potential HyWikiWord, ignore it.
554+ (not (and (fboundp 'hywiki-word-at ) (hywiki-word-at)))
555+ ; ; Org will throw a warning that `org-element-property' must be
556+ ; ; used only within an `org-mode' buffer, but it works in buffers
557+ ; ; outside of `org-mode' when on an Org link, so just suppress any
558+ ; ; warning. Using this allows recognition of Org links that are
559+ ; ; not surrounded by double sqare brackets,
560+ ; ; e.g. file:my-file::my-text.
561+ (with-suppressed-warnings
562+ ((org-element))
563+ (or
564+ (org-in-regexp
565+ org-link-any-re
566+ (let
567+ ((origin
568+ (point )))
569+ (max
570+ (save-excursion
571+ (backward-paragraph )
572+ (count-lines
573+ (point )
574+ origin))
575+ (save-excursion
576+ (forward-paragraph )
577+ (count-lines origin
578+ (point ))))))
579+ (org-in-regexp org-ts-regexp-both nil t )
580+ (org-in-regexp org-tsr-regexp-both nil t ))))))
561581
562582(defun hsys-org-link-label-start-end ()
563583 " With point on an Org link, return the list of (<label> <start> <end>), else nil.
0 commit comments