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,6 +794,9 @@ to call with the newly initialized overlay."
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
point."
;; `catch' is used here if the search fails due unbalanced parentheses
;; or any other unknown error caused in `hs-forward-sexp'.
(catch 'hs-sexp-error
(save-match-data
(save-excursion
(when (funcall hs-looking-at-block-start-predicate)
@ -807,7 +810,9 @@ point."
(goto-char (funcall hs-adjust-block-beginning-function header-end)))
(setq block-beg (line-end-position)))
;; `block-end' is the point at the end of the block
(condition-case _
(hs-forward-sexp mdata 1)
(scan-error (throw 'hs-sexp-error nil)))
(setq block-end
(cond ((and (stringp hs-block-end-regexp)
(looking-back hs-block-end-regexp nil))
@ -821,7 +826,7 @@ point."
(setq block-end
(or (funcall hs-adjust-block-end-function block-beg)
block-end)))
(list block-beg block-end))))))
(list block-beg block-end)))))))
(defun hs--make-indicators-overlays (beg)
"Helper function to make the indicators overlays."
@ -1177,8 +1182,11 @@ region (point MAXP)."
(not (nth 8 (syntax-ppss)))) ; not inside comments or strings
(if (> arg 1)
(hs-hide-level-recursive (1- arg) minp maxp)
(goto-char (match-beginning hs-block-start-mdata-select))
(hs-hide-block-at-point t))))
;; `hs-hide-block-at-point' already moves the cursor, but if it
;; 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))
(defmacro hs-life-goes-on (&rest body)

View file

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