emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/hyperbole 7b1cd4a4de 4/5: hpath, hyrolo and hargs wildc


From: ELPA Syncer
Subject: [elpa] externals/hyperbole 7b1cd4a4de 4/5: hpath, hyrolo and hargs wildcard expansion and delimited match fixes
Date: Fri, 1 Dec 2023 09:58:15 -0500 (EST)

branch: externals/hyperbole
commit 7b1cd4a4de4bbbeccc832bf84096266f6f413114
Author: bw <rsw@gnu.org>
Commit: bw <rsw@gnu.org>

    hpath, hyrolo and hargs wildcard expansion and delimited match fixes
---
 ChangeLog |  17 +++++++++
 hargs.el  | 126 +++++++++++++++++++++++++++++---------------------------------
 hpath.el  |  68 +++++++++++++++++++--------------
 hyrolo.el |  38 ++++++-------------
 4 files changed, 128 insertions(+), 121 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 39f7e57ced..ecd08c4d8b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2023-12-01  Bob Weiner  <rsw@gnu.org>
+
+* hargs.el (hargs:delimited): Remove use of 'bounds-of-thing-at-point'
+    and (require 'thingatpt) since it doesn't use the delimiters given
+    and returns wrong results.  This fixes defal tests that were failing.
+
+* hyrolo.el (hyrolo-grep): Fix to ensure 'outline-regexp' setting for all
+    matching file types is set locally in the match buffer only.
+            (hyrolo-mode): Use 'setq-local' instead of 'make-local-variable'.
+           (require 'outline): Add and remove its function declarations.
+
+* hpath.el (hpath:expand): Fix to allow return of paths with file wildcards
+    that are not yet expanded.  Use 'hpath:expand-list' to expand them.
+           (hpath:expand-list): Fix to call 'hpath:expand' before resolving
+    wildcards, so that variables are resolved first.  Also make 'match-regexp'
+    argument optional, in which case all files are matched.  Improve doc 
string.
+
 2023-11-30  Bob Weiner  <rsw@gnu.org>
 
 * hyrolo.el (hyrolo-grep-file): Add 'backward-search-limit' to minimize
diff --git a/hargs.el b/hargs.el
index 8810630769..fb58c616a3 100644
--- a/hargs.el
+++ b/hargs.el
@@ -3,7 +3,7 @@
 ;; Author:       Bob Weiner
 ;;
 ;; Orig-Date:    31-Oct-91 at 23:17:35
-;; Last-Mod:     30-Nov-23 at 23:20:37 by Bob Weiner
+;; Last-Mod:      1-Dec-23 at 11:23:52 by Bob Weiner
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -34,7 +34,6 @@
 (require 'set)
 (require 'info)
 (require 'hmouse-drv) ;; loads hui-mouse and hmouse-key
-(require 'thingatpt)  ;; for `bounds-of-thing-at-point'
 
 ;;; ************************************************************************
 ;;; Public declarations
@@ -129,7 +128,9 @@ START-DELIM is treated as a regular expression.  
END-REGEXP-FLAG
 is similar.  With optional LIST-POSITIONS-FLAG, return list
 of (string-matched start-pos end-pos).  Optional
 EXCLUDE-REGEXP is compared against the match string with its delimiters
-included; any string that matches this regexp is ignored."
+included; any string that matches this regexp is ignored.  Optional
+AS-KEY non-nil means return the string normalized as a Hyperbole
+button key (no spaces)."
   (let* ((opoint (point))
         ;; This initial limit is the forward search limit for start delimiters
         (limit (if start-regexp-flag
@@ -148,75 +149,66 @@ included; any string that matches this regexp is ignored."
         start-with-delim
         end-with-delim)
 
-    (if (and (not (or start-regexp-flag end-regexp-flag))
-            (or (and (equal start-delim "{") (equal end-delim "}"))
-                (and (equal start-delim "<") (equal end-delim ">"))
-                (and (equal start-delim "(") (equal end-delim ")"))
-                (and (equal start-delim "[") (equal end-delim "]"))))
-       (cl-destructuring-bind (start-with-delim . end-with-delim) (or 
(bounds-of-thing-at-point 'list) '(nil . nil))
-         (when (and start-with-delim end-with-delim)
-           (setq start (1+ start-with-delim)
-                 end   (1- end-with-delim))))
-      (if (string-equal start-delim end-delim)
-         (save-excursion
-           (beginning-of-line)
-           (while (and (setq end-pos (funcall start-search-func start-delim 
limit t))
-                       (setq start-with-delim (match-beginning 0))
-                       ;; Prevent infinite loop where regexp match does not
-                       ;; move end-pos forward, e.g. match to bol.
-                       (not (eq first end-pos))
-                       (setq start end-pos)
-                       (setq count (1+ count))
-                       (< (point) opoint)
-                       ;; This is not to find the real end delimiter but to 
find
-                       ;; end delimiters that precede the current argument and 
are
-                       ;; therefore false matches, hence the search is limited 
to
-                       ;; prior to the original point.
-                       (funcall end-search-func end-delim opoint t)
-                       (setq count (1+ count)))
-             (setq first (or first start)
-                   start nil))
-           (when (and (not start) (> count 0) (zerop (% count 2)))
-             ;; Since strings can span lines but this function matches only
-             ;; strings that start on the current line, when start-delim and
-             ;; end-delim are the same and there are an even number of
-             ;; delimiters in the search range, causing the end-delim
-             ;; search to match to what should probably be the start-delim,
-             ;; assume point is within a string and not between two other 
strings.
-             ;; -- RSW, 02-05-2019
-             (setq start (if (string-equal start-delim end-delim)
-                             (point)
-                           first))))
-       ;;
-       ;; Start and end delims are different, so don't have to worry
-       ;; about whether in or outside two of the same delimiters and
-       ;; can match much more simply.
-       ;; Use forward rather than reverse search here to perform greedy
-       ;; searches when optional matches within a regexp.
+    (if (string-equal start-delim end-delim)
        (save-excursion
          (beginning-of-line)
-         (while (and (<= (point) limit)
-                     (setq start-pos (point)
-                           end-pos (funcall start-search-func start-delim 
limit t))
+         (while (and (setq end-pos (funcall start-search-func start-delim 
limit t))
+                     (setq start-with-delim (match-beginning 0))
                      ;; Prevent infinite loop where regexp match does not
                      ;; move end-pos forward, e.g. match to bol.
-                     (not (eq start end-pos)))
-           (setq start-with-delim (match-beginning 0)
-                 start (match-end 0))
-           (when (eq start-pos end-pos)
-             ;; start-delim contains a match for bol, so move point
-             ;; forward a char to prevent loop exit even though start
-             ;; delim matched.
-             (goto-char (min (1+ (point)) (point-max)))))))
+                     (not (eq first end-pos))
+                     (setq start end-pos)
+                     (setq count (1+ count))
+                     (< (point) opoint)
+                     ;; This is not to find the real end delimiter but to find
+                     ;; end delimiters that precede the current argument and 
are
+                     ;; therefore false matches, hence the search is limited to
+                     ;; prior to the original point.
+                     (funcall end-search-func end-delim opoint t)
+                     (setq count (1+ count)))
+           (setq first (or first start)
+                 start nil))
+         (when (and (not start) (> count 0) (zerop (% count 2)))
+           ;; Since strings can span lines but this function matches only
+           ;; strings that start on the current line, when start-delim and
+           ;; end-delim are the same and there are an even number of
+           ;; delimiters in the search range, causing the end-delim
+           ;; search to match to what should probably be the start-delim,
+           ;; assume point is within a string and not between two other 
strings.
+           ;; -- RSW, 02-05-2019
+           (setq start (if (string-equal start-delim end-delim)
+                           (point)
+                         first))))
+      ;;
+      ;; Start and end delims are different, so don't have to worry
+      ;; about whether in or outside two of the same delimiters and
+      ;; can match much more simply.
+      ;; Use forward rather than reverse search here to perform greedy
+      ;; searches when optional matches within a regexp.
+      (save-excursion
+       (beginning-of-line)
+       (while (and (<= (point) limit)
+                   (setq start-pos (point)
+                         end-pos (funcall start-search-func start-delim limit 
t))
+                   ;; Prevent infinite loop where regexp match does not
+                   ;; move end-pos forward, e.g. match to bol.
+                   (not (eq start end-pos)))
+         (setq start-with-delim (match-beginning 0)
+               start (match-end 0))
+         (when (eq start-pos end-pos)
+           ;; start-delim contains a match for bol, so move point
+           ;; forward a char to prevent loop exit even though start
+           ;; delim matched.
+           (goto-char (min (1+ (point)) (point-max)))))))
 
-      (when start
-       (save-excursion
-         (forward-line 2)
-         (setq limit (point))
-         (goto-char opoint)
-         (and (funcall end-search-func end-delim limit t)
-              (setq end (match-beginning 0)
-                    end-with-delim (match-end 0))))))
+    (when start
+      (save-excursion
+       (forward-line 2)
+       (setq limit (point))
+       (goto-char opoint)
+       (and (funcall end-search-func end-delim limit t)
+            (setq end (match-beginning 0)
+                  end-with-delim (match-end 0)))))
 
     (when (and start end)
       (save-excursion
diff --git a/hpath.el b/hpath.el
index 35cd892417..b65538f481 100644
--- a/hpath.el
+++ b/hpath.el
@@ -3,7 +3,7 @@
 ;; Author:       Bob Weiner
 ;;
 ;; Orig-Date:     1-Nov-91 at 00:44:23
-;; Last-Mod:     25-Nov-23 at 16:42:29 by Mats Lidell
+;; Last-Mod:      1-Dec-23 at 01:11:32 by Bob Weiner
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -1209,47 +1209,60 @@ Any single ${variable} within PATH is resolved.  Then 
PATH is
 expanded from the first file matching regexp in
 `hpath:auto-variable-alist'.
 
+Return expanded path if it exists or it contains file wildcards of
+'[]', '*', or '?'.
+
 Return any absolute or invalid PATH unchanged unless optional
 EXISTS-FLAG is non-nil in which case, return the expanded path
 only if it exists, otherwise, return nil."
 
   (when (stringp path)
     (unless (string-match-p hpath:variable-regexp path)
+      ;; Replace any $VAR environment variable references
       (setq path (substitute-in-file-name path)))
     (let (variable-path
          substituted-path
          expanded-path)
-      (setq variable-path (hpath:expand-with-variable path)
-           substituted-path (hpath:substitute-value variable-path)
-           expanded-path
-           (cond ((or (null substituted-path) (string-empty-p 
substituted-path))
-                  path)
-                 ((and (string-match-p hpath:variable-regexp variable-path)
-                       (string-match-p hpath:variable-regexp substituted-path))
-                  ;; If a path is invalid, then a variable may have been 
prepended but
-                  ;; it will remain unresolved in `substituted-path', in which 
case we
-                  ;; want to return `path' without any further changes.
-                  path)
-                 ;; For compressed Elisp libraries, add any found compressed 
suffix to the path.
-                 ((string-match-p "\\.el\\(\\.\\|\\'\\)" substituted-path)
-                  (or (locate-library substituted-path t) path))
-                 ((or (string-match-p 
"\\`\\(#[^#+.]\\|([^\)\\/]+)\\|[^.\\/].*\\.[^.\\/]\\)" substituted-path)
-                      (string-match-p "[\\/~]" substituted-path))
-                  ;; Don't expand if an Info path, URL, #anchor or has a 
directory prefix
-                  substituted-path)
-                 (t (expand-file-name substituted-path))))
-      (if (file-exists-p expanded-path)
+      (setq
+       ;; Expand relative path from appropriate multi-path prefix variables
+       variable-path (hpath:expand-with-variable path)
+       ;; Substitute values for Emacs Lisp variables and environment variables 
in PATH.
+       substituted-path (hpath:substitute-value variable-path)
+       expanded-path
+       (cond ((or (null substituted-path) (string-empty-p substituted-path))
+             path)
+            ((and (string-match-p hpath:variable-regexp variable-path)
+                  (string-match-p hpath:variable-regexp substituted-path))
+             ;; If a path is invalid, then a variable may have been prepended 
but
+             ;; it will remain unresolved in `substituted-path', in which case 
we
+             ;; want to return `path' without any further changes.
+             path)
+            ;; For compressed Elisp libraries, add any found compressed suffix 
to the path.
+            ((string-match-p "\\.el\\(\\.\\|\\'\\)" substituted-path)
+             (or (locate-library substituted-path t) path))
+            ((or (string-match-p 
"\\`\\(#[^#+.]\\|([^\)\\/]+)\\|[^.\\/].*\\.[^.\\/]\\)" substituted-path)
+                 (string-match-p "[\\/~]" substituted-path))
+             ;; Don't expand if an Info path, URL, #anchor or has a directory 
prefix
+             substituted-path)
+            (t (expand-file-name substituted-path))))
+      (if (and (stringp expanded-path)
+              (or (file-exists-p expanded-path)
+                  (string-match "[[*?]" (file-local-name expanded-path))))
          expanded-path
        (unless exists-flag
          path)))))
 
-(defun hpath:expand-list (paths match-regexp &optional exists-flag)
+(defun hpath:expand-list (paths &optional match-regexp exists-flag)
   "Return expansions of PATHS, a list of dirs or wildcarded file patterns.
-PATHS expansion filters out non-strings, expand file wildcards
-when `find-file-wildcards' is non-nil (the default), substitute
-up to one ${variable} per path, and recursively walk directory
-trees for files with MATCH-REGEXP."
+PATHS expansion recursively walks directory trees to include
+files with names matching optional MATCH-REGEXP (otherwise, all
+files), filters out non-strings and non-existent filenames when
+optional EXISTS-FLAG is non-nil, expands file wildcards when
+`find-file-wildcards' is non-nil (the default), substitutes for
+multipled $VAR environment variables, substitutes up to one
+${variable} per path."
   (mapcan (lambda (path)
+           (setq path (hpath:expand path exists-flag))
            (when (setq path (or (when find-file-wildcards
                                   (file-expand-wildcards path))
                                 (list path)))
@@ -1257,9 +1270,8 @@ trees for files with MATCH-REGEXP."
                  (setq path (car path))
                (setq paths (nconc (cdr path) paths)
                      path (car path)))
-             (setq path (hpath:expand path exists-flag))
              (if (file-directory-p path)
-                 (directory-files-recursively path match-regexp)
+                 (directory-files-recursively path (or match-regexp ""))
                (list path))))
          (seq-filter #'stringp paths)))
 
diff --git a/hyrolo.el b/hyrolo.el
index a8bb8d011e..4f795f4487 100644
--- a/hyrolo.el
+++ b/hyrolo.el
@@ -3,7 +3,7 @@
 ;; Author:       Bob Weiner
 ;;
 ;; Orig-Date:     7-Jun-89 at 22:08:29
-;; Last-Mod:     30-Nov-23 at 23:31:44 by Bob Weiner
+;; Last-Mod:      1-Dec-23 at 02:24:49 by Bob Weiner
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -31,6 +31,7 @@
 (require 'hversion)
 (require 'hmail)
 (require 'hypb)  ;; For 'hypb:mail-address-regexp'.
+(require 'outline)
 (require 'package)
 (require 'set)
 (require 'sort)
@@ -83,19 +84,6 @@
 (declare-function hui:hbut-act "hui")
 (declare-function ibut:at-p "hbut")
 (declare-function kcell-view:indent "kotl/kview")
-(declare-function outline-back-to-heading "outline")
-(declare-function outline-backward-same-level "outline")
-(declare-function outline-end-of-subtree "outline")
-(declare-function outline-forward-same-level "outline")
-(declare-function outline-hide-sublevels "outline")
-(declare-function outline-hide-subtree "outline")
-(declare-function outline-level "outline")
-(declare-function outline-next-heading "outline")
-(declare-function outline-next-visible-heading "outline")
-(declare-function outline-previous-heading "outline")
-(declare-function outline-previous-visible-heading "outline")
-(declare-function outline-show-all "outline")
-(declare-function outline-up-heading "outline")
 
 (declare-function hmouse-pulse-line "hui-window")
 (declare-function hpath:find "hpath")
@@ -678,7 +666,7 @@ select it."
            (with-current-buffer buf
              (when (equal outline-regexp (default-value 'outline-regexp))
                ;; Prevent matching to *word* at the beginning of
-               ;; lines and hanging hyrolo search functions but this
+               ;; lines and hanging hyrolo search functions.  Note this
                ;; change adds one to the default `outline-level' function,
                ;; so 'hyrolo-mode' overrides that as well to get the correct
                ;; calculation.  -- rsw, 2023-11-17
@@ -783,9 +771,9 @@ Return number of entries matched.  See also documentation 
for the variable
        (unless (string-prefix-p hyrolo-hdr-regexp hyrolo-entry-regexp)
          (setq hyrolo-entry-regexp (concat hyrolo-hdr-regexp "\\|" 
hyrolo-entry-regexp))))
       (when outline-regexps
-       (setq outline-regexp (string-join outline-regexps "\\|"))
+       (setq-local outline-regexp (string-join outline-regexps "\\|"))
        (unless (string-prefix-p hyrolo-hdr-regexp outline-regexp)
-         (setq outline-regexp (concat hyrolo-hdr-regexp "\\|" 
outline-regexp))))
+         (setq-local outline-regexp (concat hyrolo-hdr-regexp "\\|" 
outline-regexp))))
       (hyrolo-display-matches display-buf))
     (when (called-interactively-p 'interactive)
       (message "%s matching entr%s found in rolo."
@@ -1681,9 +1669,10 @@ Return number of matching entries found."
                        (forward-line)
                        (setq hdr-pos (cons (point-min) (point))))
                      (let* ((case-fold-search t)
-                            (backward-search-limit (if (re-search-forward 
hyrolo-entry-regexp nil t)
-                                                       (match-beginning 0)
-                                                     (point)))
+                            (backward-search-limit (save-excursion
+                                                     (if (re-search-forward 
hyrolo-entry-regexp nil t)
+                                                         (match-beginning 0)
+                                                       (point))))
                             match-end)
                        (re-search-forward hyrolo-entry-regexp nil t)
                        (while (and (or (null max-matches) (< num-found 
max-matches))
@@ -1807,13 +1796,10 @@ Calls the functions given by `hyrolo-mode-hook'.
 \\{hyrolo-mode-map}"
   (interactive)
   (unless (eq major-mode 'hyrolo-mode)
-    (make-local-variable 'outline-regexp)
     ;; This next local value is dynamically overridden in `hyrolo-grep'.
-    (setq outline-regexp (default-value 'outline-regexp))
-    (make-local-variable 'hyrolo-entry-regexp)
-    (setq hyrolo-entry-regexp (default-value 'hyrolo-entry-regexp))
-    (make-local-variable 'outline-level)
-    (setq outline-level #'hyrolo-mode-outline-level)
+    (setq-local outline-regexp (default-value 'outline-regexp)
+               hyrolo-entry-regexp (default-value 'hyrolo-entry-regexp)
+               outline-level #'hyrolo-mode-outline-level)
     (reveal-mode 1)) ;; Expose hidden text as move into it.
   (setq major-mode 'hyrolo-mode
        mode-name "HyRolo")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]