1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-05 22:20:24 -08:00

hideshow: Fix regressions. (Bug#79857)

* lisp/progmodes/hideshow.el (hs-block-positions): Exit the
function if 'hs-forward-sexp' fails.
(hs-hide-level-recursive): Fix infloop.
* test/lisp/progmodes/hideshow-tests.el (hideshow-hide-level-1):
(hideshow-hide-level-2): Update tests.
This commit is contained in:
Elías Gabriel Pérez 2025-11-18 11:02:24 -06:00 committed by Juri Linkov
parent 4532f5ae8f
commit bfa0cb81dd
2 changed files with 45 additions and 29 deletions

View file

@ -794,34 +794,39 @@ to call with the newly initialized overlay."
This returns a list with the current code block beginning and end This returns a list with the current code block beginning and end
positions. This does nothing if there is not a code block at current positions. This does nothing if there is not a code block at current
point." point."
(save-match-data ;; `catch' is used here if the search fails due unbalanced parentheses
(save-excursion ;; or any other unknown error caused in `hs-forward-sexp'.
(when (funcall hs-looking-at-block-start-predicate) (catch 'hs-sexp-error
(let ((mdata (match-data t)) (save-match-data
(header-end (match-end 0)) (save-excursion
block-beg block-end) (when (funcall hs-looking-at-block-start-predicate)
;; `block-start' is the point at the end of the block (let ((mdata (match-data t))
;; beginning, which may need to be adjusted (header-end (match-end 0))
(save-excursion block-beg block-end)
(when hs-adjust-block-beginning-function ;; `block-start' is the point at the end of the block
(goto-char (funcall hs-adjust-block-beginning-function header-end))) ;; beginning, which may need to be adjusted
(setq block-beg (line-end-position))) (save-excursion
;; `block-end' is the point at the end of the block (when hs-adjust-block-beginning-function
(hs-forward-sexp mdata 1) (goto-char (funcall hs-adjust-block-beginning-function header-end)))
(setq block-end (setq block-beg (line-end-position)))
(cond ((and (stringp hs-block-end-regexp) ;; `block-end' is the point at the end of the block
(looking-back hs-block-end-regexp nil)) (condition-case _
(match-beginning 0)) (hs-forward-sexp mdata 1)
((functionp hs-block-end-regexp) (scan-error (throw 'hs-sexp-error nil)))
(funcall hs-block-end-regexp)
(match-beginning 0))
(t (point))))
;; adjust block end (if needed)
(when hs-adjust-block-end-function
(setq block-end (setq block-end
(or (funcall hs-adjust-block-end-function block-beg) (cond ((and (stringp hs-block-end-regexp)
block-end))) (looking-back hs-block-end-regexp nil))
(list block-beg block-end)))))) (match-beginning 0))
((functionp hs-block-end-regexp)
(funcall hs-block-end-regexp)
(match-beginning 0))
(t (point))))
;; adjust block end (if needed)
(when hs-adjust-block-end-function
(setq block-end
(or (funcall hs-adjust-block-end-function block-beg)
block-end)))
(list block-beg block-end)))))))
(defun hs--make-indicators-overlays (beg) (defun hs--make-indicators-overlays (beg)
"Helper function to make the indicators overlays." "Helper function to make the indicators overlays."
@ -1177,8 +1182,11 @@ region (point MAXP)."
(not (nth 8 (syntax-ppss)))) ; not inside comments or strings (not (nth 8 (syntax-ppss)))) ; not inside comments or strings
(if (> arg 1) (if (> arg 1)
(hs-hide-level-recursive (1- arg) minp maxp) (hs-hide-level-recursive (1- arg) minp maxp)
(goto-char (match-beginning hs-block-start-mdata-select)) ;; `hs-hide-block-at-point' already moves the cursor, but if it
(hs-hide-block-at-point t)))) ;; fails, return to the previous position where we were.
(unless (and (goto-char (match-beginning hs-block-start-mdata-select))
(hs-hide-block-at-point t))
(goto-char (match-end hs-block-start-mdata-select))))))
(goto-char maxp)) (goto-char maxp))
(defmacro hs-life-goes-on (&rest body) (defmacro hs-life-goes-on (&rest body)

View file

@ -254,6 +254,8 @@ sub()
Comments Comments
*/ */
\"String\"
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
@ -270,6 +272,8 @@ main(int argc, char **argv)
Comments Comments
*/ */
\"String\"
int int
main(int argc, char **argv) main(int argc, char **argv)
{} {}
@ -284,6 +288,8 @@ main(int argc, char **argv)
Comments Comments
*/ */
\"String\"
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
@ -300,6 +306,8 @@ main(int argc, char **argv)
Comments Comments
*/ */
\"String\"
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {