Skip to content

Commit 23650ba

Browse files
authored
Merge pull request #977 from rswgnu/rsw
hsys-org-link-at-p - Recognize non-delimited Org links
2 parents 46b4e3d + d80d205 commit 23650ba

3 files changed

Lines changed: 48 additions & 23 deletions

File tree

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
2026-06-16 Bob Weiner <rsw@gnu.org>
22

3+
* hsys-org.el (hsys-org-link-at-p): Rewrite to handle non-delimited Org links,
4+
such as: file:my-file::my-text. Leave file:// links for www-url ibtype
5+
by using 'hpath:www-at-p' test as Org url test will match to this:
6+
[[Link]] rather than requiring a true url.
7+
38
* hasht.el (hash-merge): Fix call to hash-map which was not treating its
49
input as string-keys. This led to HyWiki hash tables having string keys
510
rather than symbol keys whenever a non-page referent HyWiki word was read

hsys-org.el

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
;;
@@ -40,6 +40,7 @@
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.
530532
Start 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
538540
Assume 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.

kotl/EXAMPLE.kotl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@
427427
4f. Flexible view handling has been only partially implemented.
428428

429429

430-
"ben" ;; kvspec:current
430+
"c2en" ;; kvspec:current
431431
69 ;; id-counter
432432
alpha ;; label-type
433433
4 ;; label-min-width

0 commit comments

Comments
 (0)