[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/hyperbole b99370079d 2/3: Fix hyrolo hanging issue when
From: |
ELPA Syncer |
Subject: |
[elpa] externals/hyperbole b99370079d 2/3: Fix hyrolo hanging issue when encounter *word* at bol |
Date: |
Sat, 11 Mar 2023 03:58:18 -0500 (EST) |
branch: externals/hyperbole
commit b99370079d66c5c66a1d1d4ae97ac3c3e54871d2
Author: Bob Weiner <rsw@gnu.org>
Commit: Bob Weiner <rsw@gnu.org>
Fix hyrolo hanging issue when encounter *word* at bol
---
ChangeLog | 8 +++++
hyrolo.el | 117 +++++++++++++++++++++++++++++++++++++-------------------------
2 files changed, 78 insertions(+), 47 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 63bf742b88..eca194a9c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-03-10 Bob Weiner <rsw@gnu.org>
+
+* hyrolo.el (hyrolo-find-file): Prevent 'outline-regexp' getting stuck
+ matching to *word* at the beginning of lines and hanging hyrolo-fgrep
+ because keeps moving to within an entry rather than past it.
+ (hyrolo-grep-file): If above happens, trigger an error and
+ display the problematic file with point at the errant entry.
+
2023-03-08 Bob Weiner <rsw@gnu.org>
* hibtypes.el (grep-msg): Trigger only if filename exists. Prevents matching
diff --git a/hyrolo.el b/hyrolo.el
index 58d07e039c..36d84d0633 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: 8-Mar-23 at 01:15:53 by Bob Weiner
+;; Last-Mod: 11-Mar-23 at 01:33:01 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -486,8 +486,10 @@ the logical sexpression matching."
;;;###autoload
(defun hyrolo-find-file (&optional file find-function &rest args)
- "Select and edit a FILE in `hyrolo-file-list' with FIND-FUNCTION.
-Default to the first listed file when not given a prefix arg."
+ "Find an optional FILE in `hyrolo-file-list' with FIND-FUNCTION.
+Default to the first listed file when not given a prefix arg.
+FIND-FUNCTION must return the buffer of the file found but need not
+select it."
(interactive "P")
(when (or (called-interactively-p 'interactive)
(null file))
@@ -497,8 +499,14 @@ Default to the first listed file when not given a prefix
arg."
(setq file (completing-read "Edit HyRolo file: "
(mapcar #'list hyrolo-file-list)))))
(when (stringp file)
- (prog1 (apply (or find-function hyrolo-find-file-function) file args)
- (setq buffer-read-only nil))))
+ (let (buf)
+ (prog1 (setq buf (apply (or find-function hyrolo-find-file-function)
file args))
+ (when buf
+ (with-current-buffer buf
+ (when (equal outline-regexp "[*]+")
+ ;; Prevent matching to *word* at the beginning of lines
+ (setq-local outline-regexp "\\*+[ \t]\\|+"))
+ (setq buffer-read-only nil)))))))
;;;###autoload
(defun hyrolo-find-file-noselect (&optional file)
@@ -1419,7 +1427,9 @@ Return number of matching entries found."
(setq actual-buf (hyrolo-find-file-noselect
hyrolo-file-or-buf)
new-buf-p t))))
(let ((hdr-pos) (num-found 0) (curr-entry-level-len)
- (incl-hdr t) start)
+ (incl-hdr t)
+ (stuck-negative-point 0)
+ start)
(when max-matches
(cond ((eq max-matches t)
(setq incl-hdr nil max-matches nil))
@@ -1429,47 +1439,60 @@ Return number of matching entries found."
(set-buffer actual-buf)
(when new-buf-p
(setq buffer-read-only t))
- (save-excursion
- (save-restriction
- (hyrolo-widen)
- ;; Ensure no entries in outline mode are hidden.
- (outline-show-all)
- (goto-char (point-min))
- (when (re-search-forward hyrolo-hdr-regexp nil t 2)
- (forward-line)
- (setq hdr-pos (cons (point-min) (point))))
- (let (case-fold-search)
- (re-search-forward hyrolo-entry-regexp nil t)
- (while (and (or (null max-matches) (< num-found max-matches))
- (funcall hyrolo-next-match-function pattern
headline-only))
- (re-search-backward hyrolo-entry-regexp nil t)
- (setq start (point))
- (re-search-forward hyrolo-entry-regexp nil t)
- (setq curr-entry-level-len (length
(buffer-substring-no-properties start (point))))
- (hyrolo-to-entry-end t curr-entry-level-len)
- (or count-only
- (when (and (zerop num-found) incl-hdr)
- (let* ((src (or (buffer-file-name actual-buf)
- actual-buf))
- (src-line
- (format
- (concat (if (boundp 'hbut:source-prefix)
- hbut:source-prefix
- "@loc> ")
- "%s")
- (prin1-to-string src))))
- (set-buffer hyrolo-display-buffer)
- (goto-char (point-max))
- (if hdr-pos
- (progn
- (insert-buffer-substring-no-properties
- actual-buf (car hdr-pos) (cdr hdr-pos))
- (insert src-line "\n\n"))
- (insert (format hyrolo-hdr-format src-line)))
- (set-buffer actual-buf))))
- (setq num-found (1+ num-found))
- (or count-only
- (hyrolo-add-match hyrolo-display-buffer pattern start
(point)))))))
+ (setq stuck-negative-point
+ (catch 'stuck
+ (save-excursion
+ (save-restriction
+ (hyrolo-widen)
+ ;; Ensure no entries in outline mode are hidden.
+ (outline-show-all)
+ (goto-char (point-min))
+ (when (re-search-forward hyrolo-hdr-regexp nil t 2)
+ (forward-line)
+ (setq hdr-pos (cons (point-min) (point))))
+ (let (case-fold-search
+ opoint)
+ (re-search-forward hyrolo-entry-regexp nil t)
+ (while (and (or (null max-matches) (< num-found
max-matches))
+ (funcall hyrolo-next-match-function pattern
headline-only))
+ (setq opoint (point))
+ (re-search-backward hyrolo-entry-regexp nil t)
+ (setq start (point))
+ (re-search-forward hyrolo-entry-regexp nil t)
+ (setq curr-entry-level-len (length
(buffer-substring-no-properties start (point))))
+ (hyrolo-to-entry-end t curr-entry-level-len)
+ (when (<= (point) opoint)
+ ;; Stuck looping without moving to next entry,
+ ;; probably *word* at beginning of a line.
+ (throw 'stuck (- (point))))
+ (or count-only
+ (when (and (zerop num-found) incl-hdr)
+ (let* ((src (or (buffer-file-name actual-buf)
+ actual-buf))
+ (src-line
+ (format
+ (concat (if (boundp
'hbut:source-prefix)
+ hbut:source-prefix
+ "@loc> ")
+ "%s")
+ (prin1-to-string src))))
+ (set-buffer hyrolo-display-buffer)
+ (goto-char (point-max))
+ (if hdr-pos
+ (progn
+ (insert-buffer-substring-no-properties
+ actual-buf (car hdr-pos) (cdr hdr-pos))
+ (insert src-line "\n\n"))
+ (insert (format hyrolo-hdr-format
src-line)))
+ (set-buffer actual-buf))))
+ (setq num-found (1+ num-found))
+ (or count-only
+ (hyrolo-add-match hyrolo-display-buffer pattern
start (point)))))))
+ num-found))
+ (when (< stuck-negative-point 0)
+ (pop-to-buffer (current-buffer))
+ (goto-char (- stuck-negative-point))
+ (error "(hyrolo-grep-file): Stuck looping at position %d in buffer
\"%s\"" (point) (buffer-name)))
(hyrolo-kill-buffer actual-buf)
num-found)
0)))