1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-30 12:21:25 -08:00

hideshow: Rework previous changes

* lisp/progmodes/hideshow.el: Set default values of buffer-local variables.
(hs-inside-comment-p): Restore.
(hs--set-variable): Rename from 'hs--get-mode-value'.
(hs-grok-mode-type): Rework.
* lisp/nxml/nxml-mode.el:
* lisp/progmodes/f90.el:
* lisp/progmodes/fortran.el:
* lisp/progmodes/icon.el:
* lisp/progmodes/lua-mode.el:
* lisp/progmodes/python.el:
* lisp/progmodes/verilog-mode.el:
* lisp/progmodes/vhdl-mode.el:
* lisp/textmodes/mhtml-mode.el:
* lisp/textmodes/sgml-mode.el:
* lisp/treesit.el (treesit-major-mode-setup): Rename
'hs-forward-sexp-func' to 'hs-forward-sexp-function',
'hs-adjust-block-beginning' to 'hs-adjust-block-beginning-function',
'hs-find-block-beginning-func' to 'hs-find-block-beginning-function',
'hs-find-next-block-func' to 'hs-find-next-block-function',
'hs-looking-at-block-start-p-func' to 'hs-looking-at-block-start-predicate',
'hs-inside-comment-p-func' to 'hs-inside-comment-predicate'.
This commit is contained in:
Elías Gabriel Pérez 2025-11-08 20:04:30 +02:00 committed by Juri Linkov
parent 5d11ee9f54
commit ef2584585b
12 changed files with 148 additions and 188 deletions

View file

@ -535,7 +535,7 @@ Many aspects this mode can be customized using
(setq-local hs-block-start-regexp "<[^/>]*?")
(setq-local hs-block-end-regexp "</[^/>]*[^/]>")
(setq-local hs-c-start-regexp "<!--")
(setq-local hs-forward-sexp-func #'sgml-skip-tag-forward)
(setq-local hs-forward-sexp-function #'sgml-skip-tag-forward)
(save-excursion
(save-restriction
(widen)

View file

@ -1187,7 +1187,7 @@ with no args, if that value is non-nil."
(setq-local hs-block-start-regexp f90-start-block-re)
(setq-local hs-block-end-regexp f90-end-block-re)
(setq-local hs-c-start-regexp "!")
(setq-local hs-forward-sexp-func #'f90-end-of-block))
(setq-local hs-forward-sexp-function #'f90-end-of-block))
;; Inline-functions.

View file

@ -837,7 +837,7 @@ with no args, if that value is non-nil."
(setq-local hs-block-start-regexp fortran-start-block-re)
(setq-local hs-block-end-regexp fortran-end-block-re)
(setq-local hs-c-start-regexp "^[cC*!]")
(setq-local hs-forward-sexp-func #' fortran-end-of-block))
(setq-local hs-forward-sexp-function #' fortran-end-of-block))
(defun fortran-line-length (nchars &optional global)
@ -1247,7 +1247,7 @@ Directive lines are treated as comments."
(goto-char i)
(= (line-beginning-position) p)))))
;; Used in hs-forward-sexp-func.
;; Used in hs-forward-sexp-function.
(defun fortran-end-of-block (&optional num)
"Move point forward to the end of the current code block.
With optional argument NUM, go forward that many balanced blocks.

View file

@ -106,7 +106,7 @@
;; nested level in addition to the top-level:
;;
;; (defun ttn-hs-hide-level-1 ()
;; (when (funcall hs-looking-at-block-start-p-func)
;; (when (funcall hs-looking-at-block-start-predicate)
;; (hs-hide-level 1))
;; (forward-sexp 1))
;; (setq hs-hide-all-non-comment-function 'ttn-hs-hide-level-1)
@ -154,10 +154,10 @@
;; activate. If you want to override this, you can set any of the
;; following variables: `hs-block-start-regexp',
;; `hs-block-start-mdata-select', `hs-block-end-regexp',
;; `hs-c-start-regexp', `hs-forward-sexp-func',
;; `hs-adjust-block-beginning', `hs-adjust-block-end',
;; `hs-find-block-beginning-func', `hs-find-next-block-func',
;; `hs-looking-at-block-start-p-func', `hs-inside-comment-p-func',
;; `hs-c-start-regexp', `hs-forward-sexp-function',
;; `hs-adjust-block-beginning-function', `hs-adjust-block-end-function',
;; `hs-find-block-beginning-function', `hs-find-next-block-function',
;; `hs-looking-at-block-start-predicate', `hs-inside-comment-predicate',
;; `hs-treesit-things'.
;;
;; These variables help hideshow know what is considered a block, which
@ -167,7 +167,7 @@
;; `hs-block-end-regexp'.
;;
;; For some major modes, forward-sexp does not work properly. In those
;; cases, `hs-forward-sexp-func' specifies another function to use
;; cases, `hs-forward-sexp-function' specifies another function to use
;; instead.
;; ** Tree-sitter support
@ -178,7 +178,7 @@
;; However, for some modes the `list' thing is not enough for detecting
;; the proper code block and the range to hide, you can set the variable
;; `hs-treesit-things' to override this, but ensure you have the proper
;; values in `hs-adjust-block-end' and `hs-adjust-block-beginning' to
;; values in `hs-adjust-block-end-function' and `hs-adjust-block-beginning-function' to
;; properly hide the code block.
;; * Bugs
@ -530,28 +530,16 @@ Note that `mode-line-format' is buffer-local.")
;;---------------------------------------------------------------------------
;; API variables
(defvar-local hs-block-start-regexp nil
"Regexp for beginning of block.
(defvar-local hs-block-start-regexp "\\s("
"Regexp for beginning of block.")
It should not contain leading or trailing whitespace.
Letter-case does not matter.
If not bound, this will be set to \"\\s(\".")
(defvar-local hs-block-start-mdata-select nil
(defvar-local hs-block-start-mdata-select 0
"Element in `hs-block-start-regexp' match data to consider as block start.
The internal function `hs-forward-sexp' moves point to the beginning of this
element (using `match-beginning') before calling `hs-forward-sexp-func'.
element (using `match-beginning') before calling `hs-forward-sexp-function'.")
If not bound, this will be set to 0")
(defvar-local hs-block-end-regexp nil
"Regexp for end of block.
It should not contain leading or trailing whitespace.
Letter-case does not matter.
If not bound, this will be set to \"\\s)\"")
(defvar-local hs-block-end-regexp "\\s)"
"Regexp for end of block.")
(defvar-local hs-c-start-regexp nil
"Regexp for beginning of comments.
@ -559,19 +547,27 @@ Differs from mode-specific comment regexps in that surrounding
whitespace is stripped.
If not bound, hideshow will use current `comment-start' value without
any surrounding whitespace.")
any trailing whitespace.")
(defvar-local hs-forward-sexp-func nil
(define-obsolete-variable-alias
'hs-forward-sexp-func
'hs-forward-sexp-function
"31.1")
(defvar-local hs-forward-sexp-function #'forward-sexp
"Function used to do a `forward-sexp'.
Should change for Algol-ish modes. For single-character block
delimiters -- ie, the syntax table regexp for the character is
either `(' or `)' -- `hs-forward-sexp-func' would just be
either `(' or `)' -- `hs-forward-sexp-function' would just be
`forward-sexp'. For other modes such as simula, a more specialized
function is necessary.
function is necessary.")
If not bound, this will be set to `forward-sexp'.")
(define-obsolete-variable-alias
'hs-adjust-block-beginning
'hs-adjust-block-beginning-function
"31.1")
(defvar-local hs-adjust-block-beginning nil
(defvar-local hs-adjust-block-beginning-function nil
"Function used to tweak the block beginning.
The block is hidden from the position returned by this function,
as opposed to hiding it from the position returned when searching
@ -589,33 +585,37 @@ It should return the position from where we should start hiding.
It should not move the point.
See `hs-c-like-adjust-block-beginning' for an example of using this.
See `hs-c-like-adjust-block-beginning' for an example of using this.")
If not bound, this will be set to nil.")
(defvar-local hs-adjust-block-end nil
(defvar-local hs-adjust-block-end-function nil
"Function used to tweak the block end.
This is useful to ensure some characters such as parenthesis or curly
braces get properly hidden in python-like modes.
It is called with one argument, which is the start position where the
overlay will be created, and should return either the last position to
hide or nil. If it returns nil, hideshow will guess the end position.
hide or nil. If it returns nil, hideshow will guess the end position.")
If not bound, this will be set to nil.")
(define-obsolete-variable-alias
'hs-find-block-beginning-func
'hs-find-block-beginning-function
"31.1")
(defvar-local hs-find-block-beginning-func nil
(defvar-local hs-find-block-beginning-function #'hs-find-block-beginning
"Function used to do `hs-find-block-beginning'.
It should reposition point at the beginning of the current block
and return point, or nil if original point was not in a block.
Specifying this function is necessary for languages such as
Python, where regexp search and `syntax-ppss' check is not enough
to find the beginning of the current block.
to find the beginning of the current block.")
If not bound, this will be set to `hs-find-block-beginning'.")
(define-obsolete-variable-alias
'hs-find-next-block-func
'hs-find-next-block-function
"31.1")
(defvar-local hs-find-next-block-func nil
(defvar-local hs-find-next-block-function #'hs-find-next-block
"Function used to do `hs-find-next-block'.
It should reposition point at next block start.
@ -629,21 +629,22 @@ this case, the function should find nearest block or comment.
Specifying this function is necessary for languages such as
Python, where regexp search is not enough to find the beginning
of the next block.
of the next block.")
If not bound, this will be set to `hs-find-next-block'.")
(define-obsolete-variable-alias
'hs-looking-at-block-start-p-func
'hs-looking-at-block-start-predicate
"31.1")
(defvar-local hs-looking-at-block-start-p-func nil
(defvar-local hs-looking-at-block-start-predicate #'hs-looking-at-block-start-p
"Function used to do `hs-looking-at-block-start-p'.
It should return non-nil if the point is at the block start.
Specifying this function is necessary for languages such as
Python, where `looking-at' and `syntax-ppss' check is not enough
to check if the point is at the block start.
to check if the point is at the block start.")
If not bound, this will be set to `hs-looking-at-block-start-p'.")
(defvar-local hs-inside-comment-p-func nil
(defvar-local hs-inside-comment-predicate #'hs-inside-comment-p--default
"Function used to check if point is inside a comment.
If point is inside a comment, the function should return a list
containing the buffer position of the start and the end of the
@ -652,16 +653,12 @@ comment, otherwise it should return nil.
A comment block can be hidden only if on its starting line there is only
whitespace preceding the actual comment beginning. If point is inside
a comment but this condition is not met, the function can return a list
having nil as its `car' and the end of comment position as its `cdr'.
having nil as its `car' and the end of comment position as its `cdr'.")
If not bound, this will be set to `hs-inside-comment-p--default'.")
(defvar-local hs-treesit-things nil
(defvar-local hs-treesit-things 'list
"Treesit things to check if point is at a valid block.
The value should be a thing defined in `treesit-thing-settings' for the
current buffer's major mode.
If not bound, this will be set to \\='list.")
current buffer's major mode.")
;;---------------------------------------------------------------------------
;; support functions
@ -686,9 +683,7 @@ Skip \"internal\" overlays if `hs-allow-nesting' is non-nil."
"Return t if region in BEG and END can be hidden."
;; Check if BEG and END are not in the same line number,
;; since using `count-lines' is slow.
(save-excursion
(let ((pos2 (progn (goto-char end) (line-beginning-position))))
(< beg pos2))))
(< beg (save-excursion (goto-char end) (line-beginning-position))))
(defun hs-make-overlay (b e kind &optional b-offset e-offset)
"Return a new overlay in region defined by B and E with type KIND.
@ -736,15 +731,15 @@ positions. This does nothing if there is not a code block at current
point."
(save-match-data
(save-excursion
(when (funcall hs-looking-at-block-start-p-func)
(when (funcall hs-looking-at-block-start-predicate)
(let ((mdata (match-data t))
(header-end (match-end 0))
block-beg block-end)
;; `block-start' is the point at the end of the block
;; beginning, which may need to be adjusted
(save-excursion
(when hs-adjust-block-beginning
(goto-char (funcall hs-adjust-block-beginning header-end)))
(when hs-adjust-block-beginning-function
(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
(hs-forward-sexp mdata 1)
@ -757,9 +752,9 @@ point."
(match-beginning 0))
(t (point))))
;; adjust block end (if needed)
(when hs-adjust-block-end
(when hs-adjust-block-end-function
(setq block-end
(or (funcall hs-adjust-block-end block-beg)
(or (funcall hs-adjust-block-end-function block-beg)
block-end)))
(cons block-beg block-end))))))
@ -815,11 +810,11 @@ point."
(goto-char beg)
(remove-overlays beg end 'hs-indicator t)
(while (funcall hs-find-next-block-func hs-block-start-regexp end nil)
(while (funcall hs-find-next-block-function hs-block-start-regexp end nil)
(when-let* ((b-beg (match-beginning 0))
(_ (save-excursion
(goto-char b-beg)
(funcall hs-looking-at-block-start-p-func)))
(funcall hs-looking-at-block-start-predicate)))
;; `catch' is used here if the search fail due
;; unbalanced parenthesis or any other unknown error
;; caused in `hs-forward-sexp'.
@ -827,7 +822,7 @@ point."
(save-excursion
(goto-char b-beg)
(condition-case _
(funcall hs-forward-sexp-func 1)
(funcall hs-forward-sexp-function 1)
(scan-error (throw 'hs-indicator-error nil)))
(point))))
;; Check if block is longer than 1 line.
@ -922,12 +917,12 @@ property of an overlay."
(save-match-data (not (nth 8 (syntax-ppss))))))
(defun hs-forward-sexp (match-data arg)
"Adjust point based on MATCH-DATA and call `hs-forward-sexp-func' with ARG.
"Adjust point based on MATCH-DATA and call `hs-forward-sexp-function' with ARG.
Original match data is restored upon return."
(save-match-data
(set-match-data match-data)
(goto-char (match-beginning hs-block-start-mdata-select))
(funcall hs-forward-sexp-func arg)))
(funcall hs-forward-sexp-function arg)))
(defun hs-hide-comment-region (beg end &optional repos-end)
"Hide a region from BEG to END, marking it as a comment.
@ -947,7 +942,7 @@ Optional arg COMMENT-REG is a list of the form (BEGIN END) and
specifies the limits of the comment, or nil if the block is not
a comment.
The block beginning is adjusted by `hs-adjust-block-beginning'
The block beginning is adjusted by `hs-adjust-block-beginning-function'
and then further adjusted to be at the end of the line.
If hidding the block is successful, return non-nil.
@ -969,6 +964,10 @@ Otherwise, return nil."
(goto-char (if end q (min p (match-end 0))))
nil)))))
(defun hs-inside-comment-p ()
(declare (obsolete "Call `hs-inside-comment-predicate' instead." "31.1"))
(funcall hs-inside-comment-predicate))
(defun hs-inside-comment-p--default ()
(save-excursion
;; the idea is to look backwards for a comment start regexp, do a
@ -1020,17 +1019,28 @@ Otherwise, return nil."
(when (>= (point) q)
(list (and hideable p) (point))))))))
(defun hs--get-mode-value (var default &optional old-nth)
"Get VAR value for current major mode in `hs-special-modes-alist'.
DEFAULT is a value to use as fallback.
OLD-NTH is only used for backward compatibility with
`hs-special-modes-alist'."
(if (local-variable-p var)
(symbol-value var)
(defun hs--set-variable (var old-nth &optional default)
"Set Hideshow VAR if already not set.
This function is meant to be used for backward compatibility with
`hs-special-modes-alist'.
OLD-NTH is a number indicating NTH element of `hs-special-modes-alist'.
DEFAULT is a value to use as fallback."
(unless (local-variable-p var) ; Already set, nothing to do.
(if-let* (old-nth
(old-lookup (assoc major-mode hs-special-modes-alist)))
(nth old-nth old-lookup)
default)))
(set (make-local-variable var)
(if (integerp old-nth)
(nth old-nth old-lookup)
(funcall old-nth old-lookup)))
(when default
(set (make-local-variable var) default)))))
;; TODO: When `hs-special-modes-alist' is removed, `hs-grok-mode-type'
;; and `hs--set-variable' will no longer be necessary, but
;; `hs-c-start-regexp' will still have to be set manually after enabling
;; `hs-minor-mode'.
(defun hs-grok-mode-type ()
"Set up hideshow variables for new buffers.
@ -1038,71 +1048,16 @@ If `hs-special-modes-alist' has information associated with the current
buffer's major mode, use that. Otherwise, guess start, end and
`comment-start' regexps; `forward-sexp' function; and
adjust-block-beginning function."
(if (and (bound-and-true-p comment-start)
(bound-and-true-p comment-end))
(let ((start-elem (cadr (assoc major-mode hs-special-modes-alist))))
;; If some these variables are already set, use them instead.
(setq
;; handle (START-REGEXP MDATA-SELECT) and simple START-REGEXP
;; TEMP: At the moment, we cannot use `hs--get-mode-value'
;; here.
hs-block-start-regexp
(if (local-variable-p 'hs-block-start-regexp)
hs-block-start-regexp
(or (car start-elem) "\\s("))
hs-block-start-mdata-select
(if (local-variable-p 'hs-block-start-mdata-select)
hs-block-start-mdata-select
(or (cadr start-elem) 0))
hs-block-end-regexp
(hs--get-mode-value 'hs-block-end-regexp "\\s)" 2)
hs-c-start-regexp
(hs--get-mode-value
'hs-c-start-regexp
(let ((c-start-regexp
(regexp-quote comment-start)))
(if (string-match " +$" c-start-regexp)
(substring c-start-regexp
0 (1- (match-end 0)))
c-start-regexp))
3)
hs-forward-sexp-func
(hs--get-mode-value 'hs-forward-sexp-func #'forward-sexp 4)
hs-adjust-block-beginning
(hs--get-mode-value 'hs-adjust-block-beginning nil 5)
hs-adjust-block-end
(hs--get-mode-value 'hs-adjust-block-end nil)
hs-find-block-beginning-func
(hs--get-mode-value 'hs-find-block-beginning-func
#'hs-find-block-beginning
6)
hs-find-next-block-func
(hs--get-mode-value 'hs-find-next-block-func
#'hs-find-next-block
7)
hs-looking-at-block-start-p-func
(hs--get-mode-value 'hs-looking-at-block-start-p-func
#'hs-looking-at-block-start-p
8)
hs-inside-comment-p-func
(hs--get-mode-value 'hs-inside-comment-p-func
#'hs-inside-comment-p--default)
hs-treesit-things
(hs--get-mode-value 'hs-treesit-things 'list)))
(setq hs-minor-mode nil)
(error "%S doesn't support Hideshow Minor Mode" major-mode)))
(hs--set-variable 'hs-block-start-regexp #'caadr)
(hs--set-variable 'hs-block-start-mdata-select #'cadadr)
(hs--set-variable 'hs-block-end-regexp 2)
(hs--set-variable 'hs-c-start-regexp 3
(string-trim-right (regexp-quote comment-start)))
(hs--set-variable 'hs-forward-sexp-function 4)
(hs--set-variable 'hs-adjust-block-beginning-function 5)
(hs--set-variable 'hs-find-block-beginning-function 6)
(hs--set-variable 'hs-find-next-block-function 7)
(hs--set-variable 'hs-looking-at-block-start-predicate 8))
(defun hs-find-block-beginning ()
"Reposition point at block-start.
@ -1110,7 +1065,7 @@ Return point, or nil if original point was not in a block."
(let ((done nil)
(here (point)))
;; look if current line is block start
(if (funcall hs-looking-at-block-start-p-func)
(if (funcall hs-looking-at-block-start-predicate)
(point)
;; look backward for the start of a block that contains the cursor
(while (and (re-search-backward hs-block-start-regexp nil t)
@ -1136,14 +1091,14 @@ region (point MAXP)."
(defun hs-hide-level-recursive (arg minp maxp)
"Recursively hide blocks ARG levels below point in region (MINP MAXP)."
(when (funcall hs-find-block-beginning-func)
(when (funcall hs-find-block-beginning-function)
(setq minp (1+ (point)))
(funcall hs-forward-sexp-func 1)
(funcall hs-forward-sexp-function 1)
(setq maxp (1- (point))))
(unless hs-allow-nesting
(hs-discard-overlays minp maxp))
(goto-char minp)
(while (funcall hs-find-next-block-func hs-block-start-regexp maxp nil)
(while (funcall hs-find-next-block-function hs-block-start-regexp maxp nil)
(when (save-match-data
(not (nth 8 (syntax-ppss)))) ; not inside comments or strings
(if (> arg 1)
@ -1164,8 +1119,8 @@ In the dynamic context of this macro, `case-fold-search' is t."
(defun hs-find-block-beginning-match ()
"Reposition point at the end of match of the block-start regexp.
Return point, or nil if original point was not in a block."
(when (and (funcall hs-find-block-beginning-func)
(funcall hs-looking-at-block-start-p-func))
(when (and (funcall hs-find-block-beginning-function)
(funcall hs-looking-at-block-start-predicate))
;; point is inside a block
(goto-char (match-end 0))))
@ -1181,7 +1136,7 @@ Return point, or nil if original point was not in a block."
(defun hs-already-hidden-p ()
"Return non-nil if point is in an already-hidden block, otherwise nil."
(save-excursion
(let ((c-reg (funcall hs-inside-comment-p-func)))
(let ((c-reg (funcall hs-inside-comment-predicate)))
(if (and c-reg (nth 0 c-reg))
;; point is inside a comment, and that comment is hideable
(goto-char (nth 0 c-reg))
@ -1200,7 +1155,7 @@ Return point, or nil if original point was not in a block."
"Adjust INITIAL, the buffer position after `hs-block-start-regexp'.
Actually, point is never moved; a new position is returned that is
the end of the C-function header. This adjustment function is meant
to be assigned to `hs-adjust-block-beginning' for C-like modes."
to be assigned to `hs-adjust-block-beginning-function' for C-like modes."
(save-excursion
(goto-char (1- initial))
(forward-comment (- (buffer-size)))
@ -1233,7 +1188,7 @@ If `hs-hide-comments-when-hiding-all' is non-nil, also hide the comments."
hs-c-start-regexp
"\\)")
"")))))
(while (funcall hs-find-next-block-func re (point-max)
(while (funcall hs-find-next-block-function re (point-max)
hs-hide-comments-when-hiding-all)
(if (match-beginning 1)
;; We have found a block beginning.
@ -1249,7 +1204,7 @@ If `hs-hide-comments-when-hiding-all' is non-nil, also hide the comments."
(eq (point) (match-beginning 0)))
(goto-char (match-end 0)))))
;; found a comment, probably
(let ((c-reg (funcall hs-inside-comment-p-func)))
(let ((c-reg (funcall hs-inside-comment-predicate)))
(when (and c-reg (car c-reg))
(if (hs-hideable-region-p (car c-reg) (nth 1 c-reg))
(hs-hide-block-at-point t c-reg)
@ -1275,7 +1230,7 @@ Upon completion, point is repositioned and the normal hook
`hs-hide-hook' is run. See documentation for `run-hooks'."
(interactive "P")
(hs-life-goes-on
(let ((c-reg (funcall hs-inside-comment-p-func)))
(let ((c-reg (funcall hs-inside-comment-predicate)))
(cond
((and c-reg (or (null (nth 0 c-reg))
(not (hs-hideable-region-p (car c-reg) (nth 1 c-reg)))))
@ -1286,18 +1241,18 @@ Upon completion, point is repositioned and the normal hook
((or (and (eq hs-hide-block-behavior 'after-bol)
(save-excursion
(goto-char (line-beginning-position))
(funcall hs-find-next-block-func hs-block-start-regexp
(funcall hs-find-next-block-function hs-block-start-regexp
(line-end-position) nil))
(goto-char (match-beginning 0)))
(funcall hs-looking-at-block-start-p-func))
(funcall hs-looking-at-block-start-predicate))
;; If hidding the block fails (due the block is not hideable)
;; Then just hide the parent block (if possible)
(unless (save-excursion (hs-hide-block-at-point end))
(goto-char (1- (point)))
(funcall hs-find-block-beginning-func)
(funcall hs-find-block-beginning-function)
(hs-hide-block-at-point end)))
((funcall hs-find-block-beginning-func)
((funcall hs-find-block-beginning-function)
(hs-hide-block-at-point end)))
(run-hooks 'hs-hide-hook))))
@ -1325,15 +1280,15 @@ See documentation for functions `hs-hide-block' and `run-hooks'."
(hs--refresh-indicators ov-start ov-end)
t))
;; not immediately obvious, look for a suitable block
(let ((c-reg (funcall hs-inside-comment-p-func))
(let ((c-reg (funcall hs-inside-comment-predicate))
p q)
(cond (c-reg
(when (car c-reg)
(setq p (car c-reg)
q (cadr c-reg))))
((and (funcall hs-find-block-beginning-func)
((and (funcall hs-find-block-beginning-function)
;; ugh, fresh match-data
(funcall hs-looking-at-block-start-p-func))
(funcall hs-looking-at-block-start-predicate))
(setq p (point)
q (progn (hs-forward-sexp (match-data t) 1) (point)))))
(when (and p q)
@ -1389,7 +1344,7 @@ This can be useful if you have huge RCS logs in those comments."
(let ((c-reg (save-excursion
(goto-char (point-min))
(skip-chars-forward " \t\n\f")
(funcall hs-inside-comment-p-func))))
(funcall hs-inside-comment-predicate))))
(when c-reg
(let ((beg (car c-reg)) (end (cadr c-reg)))
;; see if we have enough comment lines to hide
@ -1419,6 +1374,11 @@ Key bindings:
:lighter " hs"
:keymap hs-minor-mode-map
(setq hs-headline nil)
(unless (and comment-start comment-end)
(setq hs-minor-mode nil)
(user-error "%S doesn't support Hideshow Minor Mode" major-mode))
(if hs-minor-mode
(progn
;; Set the variables

View file

@ -169,7 +169,7 @@ with no args, if that value is non-nil."
;; hideshow support
(setq-local hs-block-start-regexp "\\<procedure\\>")
(setq-local hs-block-end-regexp "\\<end\\>")
(setq-local hs-forward-sexp-func #'icon-forward-sexp-function))
(setq-local hs-forward-sexp-function #'icon-forward-sexp-function))
;; This is used by indent-for-comment to decide how much to
;; indent a comment in Icon code based on its context.

View file

@ -555,7 +555,7 @@ See `imenu-generic-expression'.")
;; Hide-show setup
(setq-local hs-block-start-regexp (regexp-opt (mapcar 'car lua-sexp-alist) 'words))
(setq-local hs-block-end-regexp (regexp-opt (mapcar 'cdr lua-sexp-alist) 'words))
(setq-local hs-forward-sexp-func #'lua-forward-sexp))
(setq-local hs-forward-sexp-function #'lua-forward-sexp))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.lua\\'" . lua-mode))

View file

@ -5913,7 +5913,7 @@ are also searched. REGEXP is passed to `looking-at' to set
(looking-at regexp)))))
(defun python-ts-hs-adjust-block-end-fn (block-beg)
"Python-ts-mode specific `hs-adjust-block-end' function for `hs-minor-mode'.
"Python-ts-mode specific `hs-adjust-block-end-function' function.
BLOCK-BEG is the beginning position where the hiding will be performed.
@ -7360,10 +7360,10 @@ implementations: `python-mode' and `python-ts-mode'."
;; "\\s)". This way parens at end of defun are properly hidden.
(setq-local hs-block-end-regexp "")
(setq-local hs-c-start-regexp "#")
(setq-local hs-forward-sexp-func #'python-hideshow-forward-sexp-function)
(setq-local hs-find-block-beginning-func #'python-nav-beginning-of-block)
(setq-local hs-find-next-block-func #'python-hideshow-find-next-block)
(setq-local hs-looking-at-block-start-p-func #'python-info-looking-at-beginning-of-block)
(setq-local hs-forward-sexp-function #'python-hideshow-forward-sexp-function)
(setq-local hs-find-block-beginning-function #'python-nav-beginning-of-block)
(setq-local hs-find-next-block-function #'python-hideshow-find-next-block)
(setq-local hs-looking-at-block-start-predicate #'python-info-looking-at-beginning-of-block)
(setq-local outline-regexp (python-rx (* space) block-start))
(setq-local outline-level
@ -7438,7 +7438,7 @@ implementations: `python-mode' and `python-ts-mode'."
treesit-sexp-thing 'sexp)
(setq-local hs-treesit-things '(or defun sexp))
(setq-local hs-adjust-block-end #'python-ts-hs-adjust-block-end-fn)
(setq-local hs-adjust-block-end-function #'python-ts-hs-adjust-block-end-fn)
(setq-local syntax-propertize-function #'python--treesit-syntax-propertize)

View file

@ -4365,7 +4365,7 @@ Key bindings specific to `verilog-mode-map' are:
;; hideshow support
(setq-local hs-block-start-regexp "\\<begin\\>")
(setq-local hs-block-end-regexp "\\<end\\>")
(setq-local hs-forward-sexp-func #'verilog-forward-sexp-function)
(setq-local hs-forward-sexp-function #'verilog-forward-sexp-function)
(add-hook 'completion-at-point-functions
#'verilog-completion-at-point nil 'local)

View file

@ -13284,7 +13284,7 @@ File statistics: \"%s\"\n\
;; initialize hideshow
(setq-local hs-block-start-regexp vhdl-hs-start-regexp)
(setq-local hs-c-start-regexp "--\\( \\|$\\)")
(setq-local hs-forward-sexp-func #'vhdl-hs-forward-sexp-func)
(setq-local hs-forward-sexp-function #'vhdl-hs-forward-sexp-func)
(if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
(if vhdl-hide-all-init
(add-hook 'hs-minor-mode-hook #'hs-hide-all nil t)

View file

@ -306,7 +306,7 @@ This is used by `mhtml--pre-command'.")
(flyspell-generic-progmode-verify)
t)))
;; Support for hideshow.el (see `hs-forward-sexp-func').
;; Support for hideshow.el (see `hs-forward-sexp-function').
(defun mhtml-forward (arg)
"Move point forward past a structured expression.
If point is on a tag, move to the end of the tag.
@ -331,7 +331,7 @@ the rules from `css-mode'."
#'mhtml--submode-fontify-region)
(setq-local hs-block-start-regexp "{\\|<[^/>]*?")
(setq-local hs-block-end-regexp "}\\|</[^/>]*[^/]>")
(setq-local hs-forward-sexp-func #'mhtml-forward)
(setq-local hs-forward-sexp-function #'mhtml-forward)
;; Attach this to both pre- and post- hooks just in case it ever
;; changes a key binding that might be accessed from the menu bar.

View file

@ -671,7 +671,7 @@ Do \\[describe-key] on the following bindings to discover what they do.
(setq-local hs-block-start-regexp "<[^/>]*?")
(setq-local hs-block-end-regexp "</[^/>]*[^/]>")
(setq-local hs-c-start-regexp "<!--")
(setq-local hs-forward-sexp-func #'sgml-skip-tag-forward))
(setq-local hs-forward-sexp-function #'sgml-skip-tag-forward))
(defun sgml-comment-indent ()
(if (looking-at "--") comment-column 0))

View file

@ -4261,7 +4261,7 @@ For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in
t)))
(defun treesit-hs-find-block-beginning ()
"Tree-sitter implementation of `hs-find-block-beginning-func'."
"Tree-sitter implementation of `hs-find-block-beginning-function'."
(let* ((pred (bound-and-true-p hs-treesit-things))
(thing (treesit-thing-at (point) pred))
(beg (when thing (treesit-node-start thing)))
@ -4272,7 +4272,7 @@ For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in
t)))
(defun treesit-hs-find-next-block (_regexp maxp comments)
"Tree-sitter implementation of `hs-find-next-block-func'."
"Tree-sitter implementation of `hs-find-next-block-function'."
(when (not comments)
(forward-comment (point-max)))
(let* ((comment-pred
@ -4301,7 +4301,7 @@ For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in
t)))
(defun treesit-hs-looking-at-block-start-p ()
"Tree-sitter implementation of `hs-looking-at-block-start-p-func'."
"Tree-sitter implementation of `hs-looking-at-block-start-predicate'."
(let* ((pred (bound-and-true-p hs-treesit-things))
(thing (treesit-thing-at (point) pred))
(beg (when thing (treesit-node-start thing)))
@ -4311,7 +4311,7 @@ For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in
t)))
(defun treesit-hs-inside-comment-p ()
"Tree-sitter implementation of `hs-inside-comment-p-func'."
"Tree-sitter implementation of `hs-inside-comment-predicate'."
(let* ((comment-pred
(if (treesit-thing-defined-p 'comment (treesit-language-at (point)))
'comment "\\`comment\\'"))
@ -4515,11 +4515,11 @@ before calling this function."
(setq-local hs-c-start-regexp nil
hs-block-start-regexp nil
hs-block-end-regexp #'treesit-hs-block-end
hs-forward-sexp-func #'forward-list
hs-find-block-beginning-func #'treesit-hs-find-block-beginning
hs-find-next-block-func #'treesit-hs-find-next-block
hs-looking-at-block-start-p-func #'treesit-hs-looking-at-block-start-p
hs-inside-comment-p-func #'treesit-hs-inside-comment-p))
hs-forward-sexp-function #'forward-list
hs-find-block-beginning-function #'treesit-hs-find-block-beginning
hs-find-next-block-function #'treesit-hs-find-next-block
hs-looking-at-block-start-predicate #'treesit-hs-looking-at-block-start-p
hs-inside-comment-predicate #'treesit-hs-inside-comment-p))
(when (treesit-thing-defined-p 'sentence nil)
(setq-local forward-sentence-function #'treesit-forward-sentence))