mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-05 22:20:24 -08:00
hideshow: Rework previous changes
* doc/emacs/programs.texi (Hideshow): * etc/NEWS: Fix doc. * lisp/progmodes/hideshow.el: Update Commentary Header. (hs-modes-alist): Remove. (hs--get-mode-value, hs-grok-mode-type): Rework. * lisp/treesit.el (treesit-major-mode-setup): * lisp/emacs-lisp/lisp-mode.el: * lisp/nxml/nxml-mode.el: * lisp/progmodes/cc-mode.el: * lisp/progmodes/f90.el: * lisp/progmodes/fortran.el: * lisp/progmodes/hideshow.el: * lisp/progmodes/icon.el: * lisp/progmodes/js.el: * lisp/progmodes/lua-mode.el: * lisp/progmodes/python.el: * lisp/progmodes/verilog-mode.el: * lisp/progmodes/vhdl-mode.el: * lisp/textmodes/bibtex.el: * lisp/textmodes/mhtml-mode.el: * lisp/textmodes/sgml-mode.el: * lisp/treesit.el: Fix and rework previous changes.
This commit is contained in:
parent
2c41bfabbc
commit
cc589d7003
18 changed files with 228 additions and 243 deletions
|
|
@ -1688,8 +1688,9 @@ row). Just what constitutes a block depends on the major mode. In C
|
|||
mode and related modes, blocks are delimited by braces, while in Lisp
|
||||
mode they are delimited by parentheses. Multi-line comments also
|
||||
count as blocks.
|
||||
@vindex hs-prefix-map
|
||||
|
||||
Hideshow mode provides the following commands:
|
||||
Hideshow mode provides the following commands (defined in @code{hs-prefix-map}):
|
||||
|
||||
@findex hs-hide-all
|
||||
@findex hs-hide-block
|
||||
|
|
@ -1735,7 +1736,6 @@ Hide all blocks @var{n} levels below this block
|
|||
@vindex hs-indicator-maximum-buffer-size
|
||||
@vindex hs-isearch-open
|
||||
@vindex hs-hide-block-behavior
|
||||
@vindex hs-modes-alist
|
||||
These variables can be used to customize Hideshow mode:
|
||||
|
||||
@table @code
|
||||
|
|
@ -1782,9 +1782,6 @@ code blocks and comments), or @code{nil} (unhide neither code blocks
|
|||
nor comments). The default value is @code{code}.
|
||||
@end table
|
||||
|
||||
All necessary settings for each mode can be found in the variable
|
||||
@code{hs-modes-alist}.
|
||||
|
||||
@node Symbol Completion
|
||||
@section Completion for Symbol Names
|
||||
@cindex completion (symbol names)
|
||||
|
|
|
|||
3
etc/NEWS
3
etc/NEWS
|
|
@ -1108,9 +1108,6 @@ after cursor position. By default this is set to 'after-bol'.
|
|||
|
||||
+++
|
||||
*** The variable 'hs-special-modes-alist' is now obsolete.
|
||||
Use the new variable 'hs-modes-alist' instead, which supports mode
|
||||
hierarchy for each value.
|
||||
|
||||
|
||||
** C-ts mode
|
||||
|
||||
|
|
|
|||
|
|
@ -729,7 +729,9 @@ font-lock keywords will not be case sensitive."
|
|||
:group 'lisp
|
||||
(lisp-mode-variables nil t nil)
|
||||
(setq-local electric-quote-string t)
|
||||
(setq imenu-case-fold-search nil))
|
||||
(setq imenu-case-fold-search nil)
|
||||
(setq-local hs-block-start-regexp "\\s(\\|\"")
|
||||
(setq-local hs-block-end-regexp "\\s)\\|\""))
|
||||
|
||||
(defun lisp-outline-level ()
|
||||
"Lisp mode `outline-level' function."
|
||||
|
|
|
|||
|
|
@ -532,6 +532,10 @@ Many aspects this mode can be customized using
|
|||
(setq-local comment-line-break-function #'nxml-newline-and-indent)
|
||||
(setq-local comment-quote-nested-function #'nxml-comment-quote-nested)
|
||||
(setq-local comment-continue "") ; avoid double-hyphens as a padding
|
||||
(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)
|
||||
(save-excursion
|
||||
(save-restriction
|
||||
(widen)
|
||||
|
|
|
|||
|
|
@ -252,7 +252,11 @@ control). See \"cc-mode.el\" for more info."
|
|||
(when (fboundp 'electric-indent-local-mode)
|
||||
(add-hook 'electric-indent-mode-hook 'c-electric-indent-mode-hook)
|
||||
(add-hook 'electric-indent-local-mode-hook
|
||||
'c-electric-indent-local-mode-hook)))
|
||||
'c-electric-indent-local-mode-hook))
|
||||
;; Setup hideshow variables
|
||||
(setq-local hs-block-start-regexp "\\s(\\|{\\|\"")
|
||||
(setq-local hs-block-end-regexp "\\s)\\|}\\|\"")
|
||||
(setq-local hs-c-start-regexp "/[*/]"))
|
||||
;; Will try initialization hooks again if they failed.
|
||||
(put 'c-initialize-cc-mode initprop c-initialization-ok))))
|
||||
|
||||
|
|
|
|||
|
|
@ -930,7 +930,7 @@ allowed. This minor issue currently only affects \"(/\" and \"/)\".")
|
|||
"block" "critical") t)
|
||||
"\\_>")
|
||||
"Regexp matching the end of an F90 \"block\", from the line start.
|
||||
Used in the F90 entry in `hs-modes-alist'.")
|
||||
Used in the F90 entry in `hs-block-end-regexp'.")
|
||||
|
||||
;; Ignore the fact that FUNCTION, SUBROUTINE, WHERE, FORALL have a
|
||||
;; following "(". DO, CASE, IF can have labels.
|
||||
|
|
@ -966,12 +966,7 @@ Used in the F90 entry in `hs-modes-alist'.")
|
|||
"Regexp matching the start of an F90 \"block\", from the line start.
|
||||
A simple regexp cannot do this in fully correct fashion, so this
|
||||
tries to strike a compromise between complexity and flexibility.
|
||||
Used in the F90 entry in `hs-modes-alist'.")
|
||||
|
||||
;; hs-modes-alist is autoloaded.
|
||||
(add-to-list 'hs-modes-alist
|
||||
`(f90-mode (start . ,f90-start-block-re) (end . ,f90-end-block-re)
|
||||
(c-start . "!") (forward-fn . f90-end-of-block)))
|
||||
Used in the F90 entry in `hs-block-start-regexp'.")
|
||||
|
||||
|
||||
;; Imenu support.
|
||||
|
|
@ -1188,7 +1183,11 @@ with no args, if that value is non-nil."
|
|||
(setq-local imenu-generic-expression f90-imenu-generic-expression)
|
||||
(setq-local beginning-of-defun-function #'f90-beginning-of-subprogram)
|
||||
(setq-local end-of-defun-function #'f90-end-of-subprogram)
|
||||
(setq-local add-log-current-defun-function #'f90-current-defun))
|
||||
(setq-local add-log-current-defun-function #'f90-current-defun)
|
||||
(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))
|
||||
|
||||
|
||||
;; Inline-functions.
|
||||
|
|
|
|||
|
|
@ -549,7 +549,7 @@ than ENDDO.")
|
|||
"\\|!\\|$\\)")
|
||||
"Regexp matching the end of a Fortran \"block\", from the line start.
|
||||
Note that only ENDDO is handled for the end of a DO-loop. Used
|
||||
in the Fortran entry in `hs-modes-alist'.")
|
||||
in the Fortran entry in `hs-block-end-regexp'.")
|
||||
|
||||
(defconst fortran-start-block-re
|
||||
(concat
|
||||
|
|
@ -582,11 +582,7 @@ in the Fortran entry in `hs-modes-alist'.")
|
|||
"Regexp matching the start of a Fortran \"block\", from the line start.
|
||||
A simple regexp cannot do this in fully correct fashion, so this
|
||||
tries to strike a compromise between complexity and flexibility.
|
||||
Used in the Fortran entry in `hs-modes-alist'.")
|
||||
|
||||
(add-to-list 'hs-modes-alist
|
||||
`(fortran-mode (start . ,fortran-start-block-re) (end . ,fortran-end-block-re)
|
||||
(c-start . "^[cC*!]") (forward-fn . fortran-end-of-block)))
|
||||
Used in the Fortran entry in `hs-block-start-regexp'.")
|
||||
|
||||
|
||||
(defvar fortran-mode-syntax-table
|
||||
|
|
@ -837,7 +833,11 @@ with no args, if that value is non-nil."
|
|||
#'fortran-current-defun)
|
||||
(setq-local dabbrev-case-fold-search 'case-fold-search)
|
||||
(setq-local gud-find-expr-function 'fortran-gud-find-expr)
|
||||
(add-hook 'hack-local-variables-hook 'fortran-hack-local-variables nil t))
|
||||
(add-hook 'hack-local-variables-hook 'fortran-hack-local-variables nil t)
|
||||
(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))
|
||||
|
||||
|
||||
(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-modes-alist.
|
||||
;; Used in hs-forward-sexp-func.
|
||||
(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.
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@
|
|||
;; `hs-toggle-hiding' S-<mouse-2>
|
||||
;; `hs-hide-initial-comment-block'
|
||||
;;
|
||||
;; All these commands are defined in `hs-prefix-map',
|
||||
;; `hs-minor-mode-map' and `hs-indicators-map'.
|
||||
;;
|
||||
;; Blocks are defined per mode. In c-mode, c++-mode and java-mode, they
|
||||
;; are simply text between curly braces, while in Lisp-ish modes parens
|
||||
;; are used. Multi-line comment blocks can also be hidden. Read-only
|
||||
|
|
@ -86,6 +89,14 @@
|
|||
;; is called with no arguments
|
||||
;; - `hs-isearch-open' -- what kind of hidden blocks to
|
||||
;; open when doing isearch
|
||||
;; - `hs-display-lines-hidden' -- displays the number of hidden
|
||||
;; lines next to the ellipsis.
|
||||
;; - `hs-show-indicators' -- display indicators to show
|
||||
;; and toggle the block hiding.
|
||||
;; - `hs-indicator-type' -- which indicator type should be
|
||||
;; used for the block indicators.
|
||||
;; - `hs-indicator-maximum-buffer-size' -- max buffer size in bytes where
|
||||
;; the indicators should be enabled.
|
||||
;;
|
||||
;; Some languages (e.g., Java) are deeply nested, so the normal behavior
|
||||
;; of `hs-hide-all' (hiding all but top-level blocks) results in very
|
||||
|
|
@ -122,19 +133,6 @@
|
|||
;; respectively. All hooks are run with `run-hooks'. See the
|
||||
;; documentation for each variable or hook for more information.
|
||||
;;
|
||||
;; Normally, hideshow tries to determine appropriate values for block
|
||||
;; and comment definitions by examining the buffer's major mode. If
|
||||
;; there are problems, hideshow will not activate and in that case you
|
||||
;; may wish to override hideshow's heuristics by adding an entry to
|
||||
;; variable `hs-special-modes-alist'. Packages that use hideshow should
|
||||
;; do something like:
|
||||
;;
|
||||
;; (add-to-list 'hs-special-modes-alist '(my-mode "{{" "}}" ...))
|
||||
;;
|
||||
;; If you have an entry that works particularly well, consider
|
||||
;; submitting it for inclusion in hideshow.el. See docstring for
|
||||
;; `hs-special-modes-alist' for more info on the entry format.
|
||||
;;
|
||||
;; See also variable `hs-set-up-overlay' for per-block customization of
|
||||
;; appearance or other effects associated with overlays. For example:
|
||||
;;
|
||||
|
|
@ -148,6 +146,41 @@
|
|||
;; (overlay-end ov)))
|
||||
;; 'face 'font-lock-type-face)))))
|
||||
|
||||
;; * Adding support for a major mode
|
||||
;;
|
||||
;; Normally, hideshow tries to determine appropriate values for block
|
||||
;; and comment definitions by examining the major mode settings. If the
|
||||
;; major mode is not derived from `prog-mode', hideshow will not
|
||||
;; 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-treesit-things'.
|
||||
;;
|
||||
;; These variables help hideshow know what is considered a block, which
|
||||
;; function to use to get the block positions, etc.
|
||||
;;
|
||||
;; A block is defined as text surrounded by `hs-block-start-regexp' and
|
||||
;; `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
|
||||
;; instead.
|
||||
|
||||
;; ** Tree-sitter support
|
||||
;;
|
||||
;; All the treesit based modes already have support for hidding/showing
|
||||
;; using the treesit thing `list' (see `treesit-major-mode-setup').
|
||||
;;
|
||||
;; 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
|
||||
;; properly hide the code block.
|
||||
|
||||
;; * Bugs
|
||||
;;
|
||||
;; (1) Sometimes `hs-headline' can become out of sync. To reset, type
|
||||
|
|
@ -371,83 +404,9 @@ This is only used if `hs-indicator-type' is set to `margin' or nil."
|
|||
|
||||
;;;###autoload
|
||||
(defvar hs-special-modes-alist nil)
|
||||
(make-obsolete-variable 'hs-special-modes-alist 'hs-modes-alist "31.1")
|
||||
|
||||
;;;###autoload
|
||||
(defvar hs-modes-alist
|
||||
'((c-mode (start . "\\s(\\|{\\|\"")
|
||||
(end . "\\s)\\|}\\|\"")
|
||||
(c-start . "/[*/]"))
|
||||
(c++-mode (start . "\\s(\\|{\\|\"")
|
||||
(end . "\\s)\\|}\\|\"")
|
||||
(c-start . "/[*/]"))
|
||||
(java-mode (start . "\\s(\\|{\\|\"")
|
||||
(end . "\\s)\\|}\\|\"")
|
||||
(c-start . "/[*/]"))
|
||||
(js-base-mode (start . "\\s(\\|{\\|\"")
|
||||
(end . "\\s)\\|}\\|\"")
|
||||
(c-start . "/[*/]"))
|
||||
(bibtex-mode (start . ("@\\S(*\\(\\s(\\)" 1)))
|
||||
(sgml-mode (start . "<[^/>]*?") (end . "</[^/>]*[^/]>")
|
||||
(c-start . "<!--") (forward-fn . sgml-skip-tag-forward))
|
||||
(mhtml-mode (start . "{\\|<[^/>]*?") (end . "}\\|</[^/>]*[^/]>")
|
||||
(forward-fn . mhtml-forward))
|
||||
(lisp-data-mode (start . "\\s(\\|\"") (end . "\\s)\\|\""))
|
||||
;; Add more support here.
|
||||
)
|
||||
"Alist for initializing the hideshow variables for different modes.
|
||||
Each element is an alist with any of the cons-cells forms:
|
||||
(MODE &optional
|
||||
(start . START)
|
||||
(end . END)
|
||||
(c-start . COMMENT-START)
|
||||
(forward-fn . FORWARD-SEXP-FUNC)
|
||||
(adjust-beg-fn . ADJUST-BEG-FUNC)
|
||||
(adjust-end-fn . ADJUST-END-FUNC)
|
||||
(find-beg-fn . FIND-BLOCK-BEGINNING-FUNC)
|
||||
(find-next-fn . FIND-NEXT-BLOCK-FUNC)
|
||||
(look-start-fn . LOOKING-AT-BLOCK-START-P-FUNC)
|
||||
(commentp . INSIDE-COMMENT-P-FUNC)
|
||||
(treesit-things . TREESIT-THINGS))
|
||||
|
||||
If non-nil, hideshow will use these values as regexps to define blocks
|
||||
and comments, respectively for major mode MODE and its derivatives.
|
||||
|
||||
START, END and COMMENT-START are regular expressions. A block is
|
||||
defined as text surrounded by START and END.
|
||||
|
||||
As a special case, START may be a list of the form (COMPLEX-START
|
||||
MDATA-SELECTOR), where COMPLEX-START is a regexp with multiple parts and
|
||||
MDATA-SELECTOR an integer that specifies which sub-match is the proper
|
||||
place to adjust point, before calling `hs-forward-sexp-func'. Point
|
||||
is adjusted to the beginning of the specified match. For example,
|
||||
see the `hs-modes-alist' entry for `bibtex-mode'.
|
||||
|
||||
For some major modes, `forward-sexp' does not work properly. In those
|
||||
cases, FORWARD-SEXP-FUNC specifies another function to use instead.
|
||||
|
||||
See `hs-adjust-block-beginning' for how to use ADJUST-BEG-FUNC,
|
||||
and `hs-adjust-block-end' for how to use ADJUST-END-FUNC.
|
||||
|
||||
See `hs-find-block-beginning-func' for how to use FIND-BLOCK-BEGINNING-FUNC
|
||||
and `hs-find-next-block-func' for how to use FIND-NEXT-BLOCK-FUNC.
|
||||
|
||||
See `hs-looking-at-block-start-p-func' for how to use
|
||||
LOOKING-AT-BLOCK-START-P-FUNC and `hs-inside-comment-p-func' for how to
|
||||
use INSIDE-COMMENT-P-FUNC.
|
||||
|
||||
TREESIT-THINGS is a thing defined in `treesit-thing-settings' to
|
||||
determine if the block at point is valid, see `treesit-thing-settings'
|
||||
for more information.
|
||||
|
||||
All the elements support mode hierarchy. If any of the elements is left
|
||||
nil or omitted, hideshow searches for a value defined in some parent
|
||||
mode in this alist; if no value is found, it tries to guess the
|
||||
appropriate value. The regexps should not contain leading or trailing
|
||||
whitespace. Letter-case does not matter.")
|
||||
|
||||
(defvar hs-hide-all-non-comment-function nil
|
||||
"Function called if non-nil when doing `hs-hide-all' for non-comments.")
|
||||
(make-obsolete-variable 'hs-special-modes-alist
|
||||
"use the buffer-local variables instead"
|
||||
"31.1")
|
||||
|
||||
(defcustom hs-allow-nesting nil
|
||||
"If non-nil, hiding remembers internal blocks.
|
||||
|
|
@ -554,21 +513,53 @@ Use the command `hs-minor-mode' to toggle or set this variable.")
|
|||
:help "Do not hidden code or comment blocks when isearch matches inside them"
|
||||
:active t :style radio :selected (eq hs-isearch-open nil)])))
|
||||
|
||||
(defvar-local hs-c-start-regexp nil
|
||||
"Regexp for beginning of comments.
|
||||
Differs from mode-specific comment regexps in that
|
||||
surrounding whitespace is stripped.")
|
||||
(defvar hs-hide-all-non-comment-function nil
|
||||
"Function called if non-nil when doing `hs-hide-all' for non-comments.")
|
||||
|
||||
(defvar hs-headline nil
|
||||
"Text of the line where a hidden block begins, set during isearch.
|
||||
You can display this in the mode line by adding the symbol `hs-headline'
|
||||
to the variable `mode-line-format'. For example,
|
||||
|
||||
(unless (memq \\='hs-headline mode-line-format)
|
||||
(setq mode-line-format
|
||||
(append \\='(\"-\" hs-headline) mode-line-format)))
|
||||
|
||||
Note that `mode-line-format' is buffer-local.")
|
||||
|
||||
;;---------------------------------------------------------------------------
|
||||
;; API variables
|
||||
|
||||
(defvar-local hs-block-start-regexp nil
|
||||
"Regexp for beginning of block.")
|
||||
"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
|
||||
"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-func'.
|
||||
|
||||
If not bound, this will be set to 0")
|
||||
|
||||
(defvar-local hs-block-end-regexp nil
|
||||
"Regexp for end of block.")
|
||||
"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-c-start-regexp nil
|
||||
"Regexp for beginning of comments.
|
||||
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.")
|
||||
|
||||
(defvar-local hs-forward-sexp-func nil
|
||||
"Function used to do a `forward-sexp'.
|
||||
|
|
@ -576,7 +567,9 @@ 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
|
||||
`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'.")
|
||||
|
||||
(defvar-local hs-adjust-block-beginning nil
|
||||
"Function used to tweak the block beginning.
|
||||
|
|
@ -596,7 +589,9 @@ 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
|
||||
"Function used to tweak the block end.
|
||||
|
|
@ -605,7 +600,9 @@ 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.")
|
||||
|
||||
(defvar-local hs-find-block-beginning-func nil
|
||||
"Function used to do `hs-find-block-beginning'.
|
||||
|
|
@ -614,7 +611,9 @@ 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'.")
|
||||
|
||||
(defvar-local hs-find-next-block-func nil
|
||||
"Function used to do `hs-find-next-block'.
|
||||
|
|
@ -630,7 +629,9 @@ 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'.")
|
||||
|
||||
(defvar-local hs-looking-at-block-start-p-func nil
|
||||
"Function used to do `hs-looking-at-block-start-p'.
|
||||
|
|
@ -638,7 +639,9 @@ 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
|
||||
"Function used to check if point is inside a comment.
|
||||
|
|
@ -649,23 +652,16 @@ 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
|
||||
"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.")
|
||||
current buffer's major mode.
|
||||
|
||||
(defvar hs-headline nil
|
||||
"Text of the line where a hidden block begins, set during isearch.
|
||||
You can display this in the mode line by adding the symbol `hs-headline'
|
||||
to the variable `mode-line-format'. For example,
|
||||
|
||||
(unless (memq \\='hs-headline mode-line-format)
|
||||
(setq mode-line-format
|
||||
(append \\='(\"-\" hs-headline) mode-line-format)))
|
||||
|
||||
Note that `mode-line-format' is buffer-local.")
|
||||
If not bound, this will be set to \\='list.")
|
||||
|
||||
;;---------------------------------------------------------------------------
|
||||
;; support functions
|
||||
|
|
@ -747,7 +743,8 @@ point."
|
|||
;; `block-start' is the point at the end of the block
|
||||
;; beginning, which may need to be adjusted
|
||||
(save-excursion
|
||||
(goto-char (funcall hs-adjust-block-beginning header-end))
|
||||
(when hs-adjust-block-beginning
|
||||
(goto-char (funcall hs-adjust-block-beginning header-end)))
|
||||
(setq block-beg (line-end-position)))
|
||||
;; `block-end' is the point at the end of the block
|
||||
(hs-forward-sexp mdata 1)
|
||||
|
|
@ -759,8 +756,12 @@ point."
|
|||
(funcall hs-block-end-regexp)
|
||||
(match-beginning 0))
|
||||
(t (point))))
|
||||
(cons block-beg
|
||||
(or (funcall hs-adjust-block-end block-beg) block-end)))))))
|
||||
;; adjust block end (if needed)
|
||||
(when hs-adjust-block-end
|
||||
(setq block-end
|
||||
(or (funcall hs-adjust-block-end block-beg)
|
||||
block-end)))
|
||||
(cons block-beg block-end))))))
|
||||
|
||||
(defun hs--make-indicators-overlays (beg)
|
||||
"Helper function to make the indicators overlays."
|
||||
|
|
@ -1019,33 +1020,32 @@ Otherwise, return nil."
|
|||
(when (>= (point) q)
|
||||
(list (and hideable p) (point))))))))
|
||||
|
||||
(defun hs--get-mode-value (value &optional old-nth)
|
||||
"Get VALUE for current major mode in `hs-modes-alist'.
|
||||
(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)
|
||||
(if-let* (old-nth
|
||||
(old-lookup (assoc major-mode hs-special-modes-alist)))
|
||||
(nth old-nth old-lookup)
|
||||
(catch 'hs-grok-exit
|
||||
(dolist (modes (get major-mode 'derived-mode--all-parents))
|
||||
;; If we cannot find VALUE in current MODES, try to find it in
|
||||
;; the next mode in MODES
|
||||
(if-let* ((list (assoc modes hs-modes-alist))
|
||||
(elm (alist-get value list)))
|
||||
(throw 'hs-grok-exit elm))))))
|
||||
default)))
|
||||
|
||||
(defun hs-grok-mode-type ()
|
||||
"Set up hideshow variables for new buffers.
|
||||
If `hs-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 `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 (ensure-list (hs--get-mode-value 'start 1))))
|
||||
(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
|
||||
|
|
@ -1057,59 +1057,49 @@ function; and adjust-block-beginning function."
|
|||
(or (cadr start-elem) 0))
|
||||
|
||||
hs-block-end-regexp
|
||||
(if (local-variable-p 'hs-block-end-regexp)
|
||||
hs-block-end-regexp
|
||||
(or (hs--get-mode-value 'end 2) "\\s)"))
|
||||
(hs--get-mode-value 'hs-block-end-regexp "\\s)" 2)
|
||||
|
||||
hs-c-start-regexp
|
||||
(if (local-variable-p 'hs-c-start-regexp)
|
||||
hs-c-start-regexp
|
||||
(or (hs--get-mode-value 'c-start 3)
|
||||
(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))))
|
||||
c-start-regexp))
|
||||
3)
|
||||
|
||||
hs-forward-sexp-func
|
||||
(if (local-variable-p 'hs-forward-sexp-func)
|
||||
hs-forward-sexp-func
|
||||
(or (hs--get-mode-value 'forward-fn 4)
|
||||
#'forward-sexp))
|
||||
(hs--get-mode-value 'hs-forward-sexp-func #'forward-sexp 4)
|
||||
|
||||
hs-adjust-block-beginning
|
||||
(or (hs--get-mode-value 'adjust-fn 5) #'identity)
|
||||
(hs--get-mode-value 'hs-adjust-block-beginning nil 5)
|
||||
|
||||
hs-adjust-block-end
|
||||
(or (hs--get-mode-value 'adjust-end-fn) #'ignore)
|
||||
(hs--get-mode-value 'hs-adjust-block-end nil)
|
||||
|
||||
hs-find-block-beginning-func
|
||||
(if (local-variable-p 'hs-find-block-beginning-func)
|
||||
hs-find-block-beginning-func
|
||||
(or (hs--get-mode-value 'find-beg-fn 6)
|
||||
#'hs-find-block-beginning))
|
||||
(hs--get-mode-value 'hs-find-block-beginning-func
|
||||
#'hs-find-block-beginning
|
||||
6)
|
||||
|
||||
hs-find-next-block-func
|
||||
(if (local-variable-p 'hs-find-next-block-func)
|
||||
hs-find-next-block-func
|
||||
(or (hs--get-mode-value 'find-next-fn 7)
|
||||
#'hs-find-next-block))
|
||||
(hs--get-mode-value 'hs-find-next-block-func
|
||||
#'hs-find-next-block
|
||||
7)
|
||||
|
||||
hs-looking-at-block-start-p-func
|
||||
(if (local-variable-p 'hs-looking-at-block-start-p-func)
|
||||
hs-looking-at-block-start-p-func
|
||||
(or (hs--get-mode-value 'look-start-fn 8)
|
||||
#'hs-looking-at-block-start-p))
|
||||
(hs--get-mode-value 'hs-looking-at-block-start-p-func
|
||||
#'hs-looking-at-block-start-p
|
||||
8)
|
||||
|
||||
hs-inside-comment-p-func
|
||||
(if (local-variable-p 'hs-inside-comment-p-func)
|
||||
hs-inside-comment-p-func
|
||||
(or (hs--get-mode-value 'commentp)
|
||||
#'hs-inside-comment-p--default))
|
||||
(hs--get-mode-value 'hs-inside-comment-p-func
|
||||
#'hs-inside-comment-p--default)
|
||||
|
||||
hs-treesit-things
|
||||
(or (hs--get-mode-value 'treesit-things) 'list)))
|
||||
(hs--get-mode-value 'hs-treesit-things 'list)))
|
||||
|
||||
(setq hs-minor-mode nil)
|
||||
(error "%S doesn't support Hideshow Minor Mode" major-mode)))
|
||||
|
|
@ -1431,7 +1421,7 @@ Key bindings:
|
|||
(setq hs-headline nil)
|
||||
(if hs-minor-mode
|
||||
(progn
|
||||
;; Set the variables according to `hs-modes-alist'.
|
||||
;; Set the variables
|
||||
(hs-grok-mode-type)
|
||||
;; Turn off this mode if we change major modes.
|
||||
(add-hook 'change-major-mode-hook
|
||||
|
|
|
|||
|
|
@ -167,12 +167,9 @@ with no args, if that value is non-nil."
|
|||
;; imenu support
|
||||
(setq-local imenu-generic-expression icon-imenu-generic-expression)
|
||||
;; hideshow support
|
||||
;; we start from the assertion that `hs-modes-alist' is autoloaded.
|
||||
(unless (assq 'icon-mode hs-modes-alist)
|
||||
(setq hs-modes-alist
|
||||
(cons '(icon-mode (start . "\\<procedure\\>") (end . "\\<end\\>")
|
||||
(forward-fn . icon-forward-sexp-function))
|
||||
hs-modes-alist))))
|
||||
(setq-local hs-block-start-regexp "\\<procedure\\>")
|
||||
(setq-local hs-block-end-regexp "\\<end\\>")
|
||||
(setq-local hs-forward-sexp-func #'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.
|
||||
|
|
|
|||
|
|
@ -3832,7 +3832,9 @@ Return nil if there is no name or if NODE is not a defun node."
|
|||
This mode is intended to be inherited by concrete major modes.
|
||||
Currently there are `js-mode' and `js-ts-mode'."
|
||||
:group 'js
|
||||
nil)
|
||||
(setq-local hs-block-start-regexp "\\s(\\|{\\|\"")
|
||||
(setq-local hs-block-end-regexp "\\s)\\|}\\|\"")
|
||||
(setq-local hs-c-start-regexp "/[*/]"))
|
||||
|
||||
;;;###autoload
|
||||
(define-derived-mode js-mode js-base-mode "JavaScript"
|
||||
|
|
|
|||
|
|
@ -553,12 +553,9 @@ See `imenu-generic-expression'.")
|
|||
(add-hook 'flymake-diagnostic-functions #'lua-flymake nil t)
|
||||
|
||||
;; Hide-show setup
|
||||
(unless (assq 'lua-mode hs-modes-alist)
|
||||
(add-to-list 'hs-modes-alist
|
||||
`(lua-mode
|
||||
(start . ,(regexp-opt (mapcar 'car lua-sexp-alist) 'words)) ; Start
|
||||
(end . ,(regexp-opt (mapcar 'cdr lua-sexp-alist) 'words)) ; End
|
||||
(forward-fn . lua-forward-sexp)))))
|
||||
(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))
|
||||
|
||||
;;;###autoload
|
||||
(add-to-list 'auto-mode-alist '("\\.lua\\'" . lua-mode))
|
||||
|
|
|
|||
|
|
@ -7355,24 +7355,15 @@ implementations: `python-mode' and `python-ts-mode'."
|
|||
#'python-eldoc-function))))
|
||||
(eldoc-add-command-completions "python-indent-dedent-line-backspace")
|
||||
|
||||
(add-to-list
|
||||
'hs-modes-alist
|
||||
`(python-mode
|
||||
(start . ,python-nav-beginning-of-block-regexp)
|
||||
(setq-local hs-block-start-regexp python-nav-beginning-of-block-regexp)
|
||||
;; Use the empty string as end regexp so it doesn't default to
|
||||
;; "\\s)". This way parens at end of defun are properly hidden.
|
||||
(end . "")
|
||||
(c-start . "#")
|
||||
(forward-fn . python-hideshow-forward-sexp-function)
|
||||
(find-beg-fn . python-nav-beginning-of-block)
|
||||
(find-next-fn . python-hideshow-find-next-block)
|
||||
(look-start-fn . python-info-looking-at-beginning-of-block)))
|
||||
|
||||
(add-to-list
|
||||
'hs-modes-alist
|
||||
'(python-ts-mode
|
||||
(treesit-things . (or defun sexp))
|
||||
(adjust-end-fn . python-ts-hs-adjust-block-end-fn)))
|
||||
(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 outline-regexp (python-rx (* space) block-start))
|
||||
(setq-local outline-level
|
||||
|
|
@ -7446,6 +7437,9 @@ implementations: `python-mode' and `python-ts-mode'."
|
|||
(setq-local forward-sexp-function #'treesit-forward-sexp
|
||||
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 syntax-propertize-function #'python--treesit-syntax-propertize)
|
||||
|
||||
(python-skeleton-add-menu-items)
|
||||
|
|
|
|||
|
|
@ -4363,12 +4363,9 @@ Key bindings specific to `verilog-mode-map' are:
|
|||
(when (and (boundp 'which-func-modes) (listp which-func-modes))
|
||||
(add-to-list 'which-func-modes 'verilog-mode))
|
||||
;; hideshow support
|
||||
(when (boundp 'hs-modes-alist)
|
||||
(unless (assq 'verilog-mode hs-modes-alist)
|
||||
(setq hs-modes-alist
|
||||
(cons '(verilog-mode (beg . "\\<begin\\>") (end . "\\<end\\>")
|
||||
(forward-fn . verilog-forward-sexp-function))
|
||||
hs-modes-alist))))
|
||||
(setq-local hs-block-start-regexp "\\<begin\\>")
|
||||
(setq-local hs-block-end-regexp "\\<end\\>")
|
||||
(setq-local hs-forward-sexp-func #'verilog-forward-sexp-function)
|
||||
|
||||
(add-hook 'completion-at-point-functions
|
||||
#'verilog-completion-at-point nil 'local)
|
||||
|
|
|
|||
|
|
@ -13282,11 +13282,9 @@ File statistics: \"%s\"\n\
|
|||
(if (not (boundp 'hs-block-start-mdata-select))
|
||||
(vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
|
||||
;; initialize hideshow
|
||||
(unless (assoc 'vhdl-mode hs-modes-alist)
|
||||
(setq hs-modes-alist
|
||||
(cons `(vhdl-mode (start . ,vhdl-hs-start-regexp) (c-start . "--\\( \\|$\\)")
|
||||
(forward-fn . vhdl-hs-forward-sexp-func))
|
||||
hs-modes-alist)))
|
||||
(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)
|
||||
(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)
|
||||
|
|
|
|||
|
|
@ -3661,6 +3661,8 @@ if that value is non-nil.
|
|||
(setq-local comment-column 0)
|
||||
(setq-local defun-prompt-regexp "^[ \t]*@[[:alnum:]]+[ \t]*")
|
||||
(setq-local outline-regexp "[ \t]*@")
|
||||
(setq-local hs-block-start-regexp "@\\S(*\\(\\s(\\)")
|
||||
(setq-local hs-block-end-regexp 1)
|
||||
(setq-local fill-paragraph-function #'bibtex-fill-field)
|
||||
(setq-local font-lock-defaults
|
||||
'(bibtex-font-lock-keywords
|
||||
|
|
|
|||
|
|
@ -306,7 +306,7 @@ This is used by `mhtml--pre-command'.")
|
|||
(flyspell-generic-progmode-verify)
|
||||
t)))
|
||||
|
||||
;; Support for hideshow.el (see `hs-modes-alist').
|
||||
;; Support for hideshow.el (see `hs-forward-sexp-func').
|
||||
(defun mhtml-forward (arg)
|
||||
"Move point forward past a structured expression.
|
||||
If point is on a tag, move to the end of the tag.
|
||||
|
|
@ -329,6 +329,9 @@ the rules from `css-mode'."
|
|||
(setq-local syntax-propertize-function #'mhtml-syntax-propertize)
|
||||
(setq-local font-lock-fontify-region-function
|
||||
#'mhtml--submode-fontify-region)
|
||||
(setq-local hs-block-start-regexp "{\\|<[^/>]*?")
|
||||
(setq-local hs-block-end-regexp "}\\|</[^/>]*[^/]>")
|
||||
(setq-local hs-forward-sexp-func #'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.
|
||||
|
|
|
|||
|
|
@ -667,7 +667,11 @@ Do \\[describe-key] on the following bindings to discover what they do.
|
|||
,(concat "<[^>]+[ \t\n]+[Nn][Aa][Mm][Ee]=\\(['\"]"
|
||||
(if sgml-xml-mode "" "?")
|
||||
"\\)\\(" sgml-name-re "\\)\\1")
|
||||
2))))
|
||||
2)))
|
||||
(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))
|
||||
|
||||
(defun sgml-comment-indent ()
|
||||
(if (looking-at "--") comment-column 0))
|
||||
|
|
|
|||
|
|
@ -4514,10 +4514,8 @@ before calling this function."
|
|||
(setq-local show-paren-data-function #'treesit-show-paren-data)
|
||||
(setq-local hs-c-start-regexp nil
|
||||
hs-block-start-regexp nil
|
||||
hs-block-start-mdata-select 0
|
||||
hs-block-end-regexp #'treesit-hs-block-end
|
||||
hs-forward-sexp-func #'forward-list
|
||||
hs-adjust-block-beginning nil
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue