From 6f31217c313f9a1160418f6873ba9090af40979d Mon Sep 17 00:00:00 2001 From: bw Date: Sun, 29 Mar 2026 23:00:12 -0400 Subject: [PATCH] hywiki-delimited-p - Eliminate nil sent as arg to 'matching-paren' hypb:in-string-p - Temporarily widen each non-kotl-mode buffer to ensure can see entire string. org-id-find - Declare as external to quiet byte-compiler. hypb:in-string-cache - Move Private Variable definitions to precede code so they are not referenced before they are defined. --- ChangeLog | 11 +++++ hsys-org.el | 3 +- hypb.el | 127 +++++++++++++++++++++++++++------------------------- hywiki.el | 21 +++++---- 4 files changed, 91 insertions(+), 71 deletions(-) diff --git a/ChangeLog b/ChangeLog index dcdc5c8a..392caccc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2026-03-29 Bob Weiner +* hypb.el (hypb:in-string-cache): Move Private Variable definitions to precede + code so they are not referenced before they are defined. + +* hsys-org.el (org-id-find): Declare as external to quiet byte-compiler. + +* hywiki.el (hywiki-delimited-p): Fix to eliminate nil sent as arg to + 'matching-paren'. + +* hypb.el (hypb:in-string-p): Temporarily widen each non-kotl-mode buffer to + ensure can see entire string. + * hywiki.el (consult--async-*): Silence byte-compiler warnings with function declarations. diff --git a/hsys-org.el b/hsys-org.el index dac34566..605d15c2 100644 --- a/hsys-org.el +++ b/hsys-org.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 2-Jul-16 at 14:54:14 -;; Last-Mod: 28-Mar-26 at 13:22:56 by Bob Weiner +;; Last-Mod: 29-Mar-26 at 22:57:14 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -70,6 +70,7 @@ (declare-function org-babel-get-src-block-info "org-babel") (declare-function org-fold-show-context "org-fold") +(declare-function org-id-find "org-id") (declare-function org-link-open-from-string "ol") (declare-function outline-on-heading-p "outline") diff --git a/hypb.el b/hypb.el index 834e9a1b..825ed052 100644 --- a/hypb.el +++ b/hypb.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 6-Oct-91 at 03:42:38 -;; Last-Mod: 29-Mar-26 at 19:02:41 by Bob Weiner +;; Last-Mod: 29-Mar-26 at 22:47:54 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -125,6 +125,16 @@ Also active in any Decendent modes of those listed.") "\\([_a-zA-Z0-9][-_a-zA-Z0-9.!@+%]*@[-_a-zA-Z0-9.!@+%]+\\.[a-zA-Z0-9][-_a-zA-Z0-9]+\\)\\($\\|[^a-zA-Z0-9@%]\\)" "Regexp with group 1 matching an Internet email address.") +;;; ************************************************************************ +;;; Private variables +;;; ************************************************************************ + +(defvar hypb:in-string-cache (make-hash-table :test 'eq) + "Key: buffer, Value: (tick (range1) (range2) ...) +Where each range is ((start . end) . is-in-string).") + +(define-button-type 'hyperbole-banner) + ;;; ************************************************************************ ;;; Public functions ;;; ************************************************************************ @@ -771,56 +781,61 @@ Quoting conventions recognized are: ;; Cache match (setq cache-match match)) - ;; When no matching cache entry, search for a string match - (let* ((entry (or cache-match - ;; This ignores max-lines, so final result of - ;; whether in a string with max-lines may differ - ;; from what this returns. This allows its result - ;; to be used in the cache. - ;; To call it with the buffer narrowed to - ;; according to `max-lines', use: - ;; (hypb:narrow-to-max-lines max-lines #'hypb:in-string-check t) - (hypb:in-string-check t))) - (in-str (nth 0 entry)) - (str-start (nth 1 entry)) - (str-end (nth 2 entry))) - (cond ((and (not match) (not hypb:in-string-cache-disable)) - ;; Add the new range into the buffer's cache - (setcdr cache-entry (cons entry (cdr cache-entry)))) - (match) - ((not entry) - (setq hypb:in-string-cache-disable t) - (error "(hypb:in-string-p): buffer = %s; cache-match = %S; entry = %s; point = %d" - (current-buffer) cache-match entry (point)))) - ;; Ignore if more than `max-lines' matched - (when (and in-str str-start str-end - (or (null max-lines) - (and (integerp max-lines) - ;; When computing the number of lines in - ;; the string match, ignore any leading and - ;; trailing newlines. This allows for - ;; opening and closing quotes to be on - ;; separate lines, useful with multi-line - ;; strings. - (let (newlines) - (or (< (setq newlines (count-matches "\n" str-start str-end)) - max-lines) - (< (save-excursion - (- newlines - (progn (goto-char str-start) - (if (looking-at "[\n\r\f\t ]+") - (count-matches "\n" (match-beginning 0) (match-end 0)) - 0)) - (progn (goto-char str-end) - (if (zerop (skip-chars-backward "\n\r\f\t ")) - 0 - (count-matches "\n" (point) str-end))))) - max-lines)))))) - (if range-flag - (cond ((zerop str-start) - (list nil (point) (point))) - (in-str (list (buffer-substring-no-properties str-start str-end) str-start str-end))) - in-str))))))) + ;; Buffer might be narrowed in which case full string would not be + ;; seen. If not `kotl-mode', temporarily widen the buffer. + (save-restriction + (unless (derived-mode-p 'kotl-mode) + (widen)) + ;; When no matching cache entry, search for a string match + (let* ((entry (or cache-match + ;; This ignores max-lines, so final result of + ;; whether in a string with max-lines may differ + ;; from what this returns. This allows its result + ;; to be used in the cache. + ;; To call it with the buffer narrowed to + ;; according to `max-lines', use: + ;; (hypb:narrow-to-max-lines max-lines #'hypb:in-string-check t) + (hypb:in-string-check t))) + (in-str (nth 0 entry)) + (str-start (nth 1 entry)) + (str-end (nth 2 entry))) + (cond ((and (not match) (not hypb:in-string-cache-disable)) + ;; Add the new range into the buffer's cache + (setcdr cache-entry (cons entry (cdr cache-entry)))) + (match) + ((not entry) + (setq hypb:in-string-cache-disable t) + (error "(hypb:in-string-p): buffer = %s; cache-match = %S; entry = %s; point = %d" + (current-buffer) cache-match entry (point)))) + ;; Ignore if more than `max-lines' matched + (when (and in-str str-start str-end + (or (null max-lines) + (and (integerp max-lines) + ;; When computing the number of lines in + ;; the string match, ignore any leading and + ;; trailing newlines. This allows for + ;; opening and closing quotes to be on + ;; separate lines, useful with multi-line + ;; strings. + (let (newlines) + (or (< (setq newlines (count-matches "\n" str-start str-end)) + max-lines) + (< (save-excursion + (- newlines + (progn (goto-char str-start) + (if (looking-at "[\n\r\f\t ]+") + (count-matches "\n" (match-beginning 0) (match-end 0)) + 0)) + (progn (goto-char str-end) + (if (zerop (skip-chars-backward "\n\r\f\t ")) + 0 + (count-matches "\n" (point) str-end))))) + max-lines)))))) + (if range-flag + (cond ((zerop str-start) + (list nil (point) (point))) + (in-str (list (buffer-substring-no-properties str-start str-end) str-start str-end))) + in-str)))))))) (defun hypb:narrow-to-max-lines (max-lines func &rest args) "Narrow buffer to +/- (+ 1 MAX-LINES) including current line. @@ -1522,16 +1537,6 @@ Without file, the banner is prepended to the current buffer." oct-str) dec-num)) -;;; ************************************************************************ -;;; Private variables -;;; ************************************************************************ - -(defvar hypb:in-string-cache (make-hash-table :test 'eq) - "Key: buffer, Value: (tick (range1) (range2) ...) -Where each range is ((start . end) . is-in-string).") - -(define-button-type 'hyperbole-banner) - (provide 'hypb) ;;; hypb.el ends here diff --git a/hywiki.el b/hywiki.el index f1537ded..baba69f5 100644 --- a/hywiki.el +++ b/hywiki.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 21-Apr-24 at 22:41:13 -;; Last-Mod: 29-Mar-26 at 19:15:13 by Bob Weiner +;; Last-Mod: 29-Mar-26 at 22:28:44 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -4088,24 +4088,27 @@ a HyWikiWord at point." (let* ((range (or (hypb:in-string-p nil t) (hargs:delimited "[\[<\(\{]" "[\]\}\)\>]" t t t))) (wikiword (car range)) + (str-start (nth 1 range)) + (str-end (nth 2 range)) range-trimmed wikiword-trimmed) (if (and wikiword (string-match "[ \t\n\r\f]+\\'" wikiword)) ;; Strip any trailing whitespace (setq wikiword-trimmed (substring wikiword 0 (match-beginning 0)) range-trimmed (when (car range) - (list wikiword-trimmed (nth 1 range) - (- (nth 2 range) (length (match-string + (list wikiword-trimmed str-start + (- str-end (length (match-string 0 wikiword)))))) (setq range-trimmed (when (car range) range))) - (and range-trimmed + (and range-trimmed str-start str-end ;; Ensure closing delimiter is a match for the opening one - (or (eq (matching-paren (char-before (nth 1 range))) - (char-after (nth 2 range))) + (or (eq (matching-paren (or (char-before str-start) + 0)) + (char-after str-end)) ;; May be string quotes where matching-paren returns nil. - (and (eq (char-before (nth 1 range)) - (char-after (nth 2 range))) - (eq (char-syntax (char-before (nth 1 range))) ?\"))) + (and (eq (char-before str-start) + (char-after str-end )) + (eq (char-syntax (char-before str-start)) ?\"))) range-trimmed))))) (defun hywiki-word-face-at-p (&optional pos)