|
3 | 3 | ;; Author: Bob Weiner
|
4 | 4 | ;;
|
5 | 5 | ;; Orig-Date: 21-Apr-24 at 22:41:13
|
6 |
| -;; Last-Mod: 26-Dec-24 at 22:52:28 by Bob Weiner |
| 6 | +;; Last-Mod: 27-Dec-24 at 11:10:28 by Bob Weiner |
7 | 7 | ;;
|
8 | 8 | ;; SPDX-License-Identifier: GPL-3.0-or-later
|
9 | 9 | ;;
|
@@ -640,21 +640,23 @@ After successfully finding a page and reading it into a buffer, run
|
640 | 640 | (unless buffer-file-name
|
641 | 641 | (error "(hywiki-display-referent): No `wikiword' given; buffer must have an attached file"))
|
642 | 642 | (setq wikiword (file-name-sans-extension (file-name-nondirectory buffer-file-name))))
|
643 |
| - (when (string-match "#[^#]+$" wikiword) |
644 |
| - (setq wikiword (substring wikiword 0 (match-beginning 0)))) |
645 |
| - (let* ((referent (cond (prompt-flag |
646 |
| - (hywiki-add-prompted-referent wikiword)) |
647 |
| - ((hywiki-get-referent wikiword)) |
648 |
| - (t (hywiki-add-page wikiword)))) |
649 |
| - (referent-value (cdr referent))) |
650 |
| - (when referent |
651 |
| - ;; Ensure highlight any page name at point in case called as a |
| 643 | + (let* ((section (when (string-match "#[^#]+$" wikiword) |
| 644 | + (substring wikiword (1+ (match-beginning 0))))) |
| 645 | + (htable-referent (cond (prompt-flag |
| 646 | + (hywiki-add-prompted-referent wikiword)) |
| 647 | + ((hywiki-get-referent wikiword)) |
| 648 | + (t (hywiki-add-page wikiword)))) |
| 649 | + referent) |
| 650 | + ;; HyWikiWord instance may contain a section that must be |
| 651 | + ;; added to the referent value. |
| 652 | + (if (not (setq referent (hywiki--add-section-to-referent |
| 653 | + section htable-referent))) |
| 654 | + (error "(hywiki-display-referent): Invalid `%s' referent: %s" |
| 655 | + wikiword htable-referent) |
| 656 | + ;; Ensure highlight any page name at point in case called as a |
652 | 657 | ;; Hyperbole action type
|
653 | 658 | (hywiki-maybe-highlight-page-name t)
|
654 |
| - (if (and (consp referent) (not (listp referent-value))) |
655 |
| - (hywiki-display-referent-type wikiword referent) |
656 |
| - (error "(hywiki-display-referent): Invalid `%s' referent: %s" |
657 |
| - wikiword referent)) |
| 659 | + (hywiki-display-referent-type wikiword referent) |
658 | 660 | (hywiki-maybe-highlight-page-names)
|
659 | 661 | (run-hooks 'hywiki-display-referent-hook)
|
660 | 662 | referent)))
|
@@ -728,14 +730,16 @@ After successfully finding a page and reading it into a buffer, run
|
728 | 730 | (hui:menu-act 'hywiki-referent-menu
|
729 | 731 | (list (cons 'hywiki-referent-menu
|
730 | 732 | (cons (list (format "%s RefType>"
|
731 |
| - wikiword)) |
| 733 | + (if (string-match "#[^#]+$" wikiword) |
| 734 | + (substring wikiword 0 (match-beginning 0)) |
| 735 | + wikiword))) |
732 | 736 | (cdr hywiki-referent-menu)))))))
|
733 | 737 | (or referent
|
734 | 738 | (when (called-interactively-p 'interactive)
|
735 | 739 | (user-error "(hywiki-add-prompted-referent): Invalid HyWikiWord: '%s'; must be capitalized, all alpha" wikiword)))))
|
736 | 740 |
|
737 | 741 | (defun hywiki-add-referent (wikiword referent)
|
738 |
| - "Add WIKIWORD that displays REFERENT to HyWiki. |
| 742 | + "Add WIKIWORD (sans any #section) that displays REFERENT to HyWiki. |
739 | 743 | Return REFERENT if WIKIWORD is of valid format, otherwise return nil.
|
740 | 744 | REFERENT must be a cons of (<referent-type) . <referent-value>) or
|
741 | 745 | an error is triggered."
|
@@ -1098,7 +1102,8 @@ Use `hywiki-get-referent' to determine whether a HyWiki page exists."
|
1098 | 1102 | "Display an optional WIKIWORD page and return the page file.
|
1099 | 1103 | Use `hywiki-display-page-function' to display the page.
|
1100 | 1104 |
|
1101 |
| -If REFERENT is provided, the page file is its `cdr'. |
| 1105 | +If REFERENT is provided, its `cdr' is the page file with any #section |
| 1106 | +from the WIKIWORD included. |
1102 | 1107 |
|
1103 | 1108 | If WIKIWORD is omitted or nil and `hywiki-display-page-function'
|
1104 | 1109 | is an interactive function, it is called interactively and prompts for
|
@@ -2021,18 +2026,13 @@ value returns nil."
|
2021 | 2026 | If it is a pathname, expand it relative to `hywiki-directory'."
|
2022 | 2027 | (when (and (stringp wikiword) (not (string-empty-p wikiword))
|
2023 | 2028 | (string-match hywiki-word-with-optional-section-exact-regexp wikiword))
|
2024 |
| - (let* ((_section (when (match-string-no-properties 2 wikiword) |
2025 |
| - (prog1 (substring wikiword (match-beginning 2)) |
2026 |
| - ;; Remove any #section suffix in `wikiword'. |
2027 |
| - (setq wikiword (match-string-no-properties 1 wikiword))))) |
| 2029 | + (let* ((section (when (match-string-no-properties 2 wikiword) |
| 2030 | + (prog1 (substring wikiword (1+ (match-beginning 2))) |
| 2031 | + ;; Remove any #section suffix in `wikiword'. |
| 2032 | + (setq wikiword (match-string-no-properties 1 wikiword))))) |
2028 | 2033 | (referent (hash-get (hywiki-get-singular-wikiword wikiword)
|
2029 |
| - (hywiki-get-referent-hasht))) |
2030 |
| - (referent-type (car referent)) |
2031 |
| - (referent-value (cdr referent))) |
2032 |
| - (when (and (consp referent) |
2033 |
| - (symbolp referent-type) |
2034 |
| - (not (listp referent-value))) |
2035 |
| - referent)))) |
| 2034 | + (hywiki-get-referent-hasht)))) |
| 2035 | + (hywiki--add-section-to-referent section referent)))) |
2036 | 2036 |
|
2037 | 2037 | (defun hywiki-get-page-files ()
|
2038 | 2038 | "Return the list of existing HyWiki page file names.
|
@@ -2586,6 +2586,29 @@ Highlight/dehighlight HyWiki page names across all frames on change."
|
2586 | 2586 | ;;; Private functions
|
2587 | 2587 | ;;; ************************************************************************
|
2588 | 2588 |
|
| 2589 | +(defun hywiki--add-section-to-referent (section referent) |
| 2590 | + "Add #SECTION to REFERENT's value and return REFERENT. |
| 2591 | +SECTION excludes # prefix Return nil if any input is invalid." |
| 2592 | + (if (or (null section) (and (stringp section) (string-empty-p section))) |
| 2593 | + referent |
| 2594 | + (when (consp referent) |
| 2595 | + (let ((referent-type (car referent)) |
| 2596 | + (referent-value (cdr referent))) |
| 2597 | + (when (and (symbolp referent-type) referent-value) |
| 2598 | + (if (and (stringp section) |
| 2599 | + (stringp referent-value) |
| 2600 | + (memq referent-type '(page path-link)) |
| 2601 | + (not (seq-contains-p referent-value ?# #'=))) |
| 2602 | + ;; Need to insert #section into referent's value |
| 2603 | + (progn |
| 2604 | + (if (string-match hpath:line-and-column-regexp referent-value) |
| 2605 | + (setq referent-value (concat (substring 0 (match-beginning 0)) |
| 2606 | + "#" section |
| 2607 | + (match-string 0 referent-value))) |
| 2608 | + (setq referent-value (concat referent-value "#" section))) |
| 2609 | + (cons referent-type referent-value)) |
| 2610 | + referent)))))) |
| 2611 | + |
2589 | 2612 | (defun hywiki--get-delimited-range-backward ()
|
2590 | 2613 | "Return a list of (start end) if not between/after end ]] or >>.
|
2591 | 2614 | Otherwise, return nil."
|
|
0 commit comments