-;;; hideshow.el --- minor mode cmds to selectively display code/comment blocks
+;;; hideshow.el --- minor mode cmds to selectively display code/comment blocks -*- lexical-binding:t -*-
;; Copyright (C) 1994-2019 Free Software Foundation, Inc.
;; hs-show-all C-c @ C-M-s
;; hs-hide-level C-c @ C-l
;; hs-toggle-hiding C-c @ C-c
-;; hs-mouse-toggle-hiding [(shift mouse-2)]
+;; hs-toggle-hiding [(shift mouse-2)]
;; hs-hide-initial-comment-block
;;
;; Blocks are defined per mode. In c-mode, c++-mode and java-mode, they
;; Then, add the following to your init file:
;;
;; (load-library "hideshow")
-;; (add-hook 'X-mode-hook ; other modes similarly
-;; (lambda () (hs-minor-mode 1)))
+;; (add-hook 'X-mode-hook #'hs-minor-mode) ; other modes similarly
;;
;; where X = {emacs-lisp,c,c++,perl,...}. You can also manually toggle
;; hideshow minor mode by typing `M-x hs-minor-mode'. After hideshow is
;; (5) Hideshow interacts badly with Ediff and `vc-diff'. At the moment, the
;; suggested workaround is to turn off hideshow entirely, for example:
;;
-;; (add-hook 'ediff-prepare-buffer-hook 'turn-off-hideshow)
-;; (add-hook 'vc-before-checkin-hook 'turn-off-hideshow)
+;; (add-hook 'ediff-prepare-buffer-hook #'turn-off-hideshow)
+;; (add-hook 'vc-before-checkin-hook #'turn-off-hideshow)
;;
;; In the case of `vc-diff', here is a less invasive workaround:
;;
These commands include the toggling commands (when the result is to show
a block), `hs-show-all' and `hs-show-block'.")
-(defvar hs-set-up-overlay nil
+(defvar hs-set-up-overlay #'ignore
"Function called with one arg, OV, a newly initialized overlay.
Hideshow puts a unique overlay on each range of text to be hidden
in the buffer. Here is a simple example of how to use this variable:
(count-lines (overlay-start ov)
(overlay-end ov))))))
- (setq hs-set-up-overlay \\='display-code-line-counts)
+ (setq hs-set-up-overlay #\\='display-code-line-counts)
This example shows how to get information from the overlay as well
as how to set its `display' property. See `hs-make-overlay' and
(define-key map "\C-c@\C-t" 'hs-hide-all)
(define-key map "\C-c@\C-d" 'hs-hide-block)
(define-key map "\C-c@\C-e" 'hs-toggle-hiding)
- (define-key map [(shift mouse-2)] 'hs-mouse-toggle-hiding)
+ (define-key map [(shift mouse-2)] 'hs-toggle-hiding)
map)
"Keymap for hideshow minor mode.")
(defvar-local hs-block-end-regexp nil
"Regexp for end of block.")
-(defvar-local hs-forward-sexp-func 'forward-sexp
+(defvar-local hs-forward-sexp-func #'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
`forward-sexp'. For other modes such as simula, a more specialized
function is necessary.")
-(defvar-local hs-adjust-block-beginning nil
+(defvar-local hs-adjust-block-beginning #'identity
"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
;; `p' is the point at the end of the block beginning, which
;; may need to be adjusted
(save-excursion
- (if hs-adjust-block-beginning
- (goto-char (funcall hs-adjust-block-beginning
- header-end))
- (goto-char header-end))
+ (goto-char (funcall (or hs-adjust-block-beginning #'identity)
+ header-end))
(setq p (line-end-position)))
;; `q' is the point at the end of the block
(hs-forward-sexp mdata 1)
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 (boundp 'comment-start)
- (boundp 'comment-end)
- comment-start comment-end)
+ (if (and (bound-and-true-p comment-start)
+ (bound-and-true-p comment-end))
(let* ((lookup (assoc major-mode hs-special-modes-alist))
(start-elem (or (nth 1 lookup) "\\s(")))
(if (listp start-elem)
(substring c-start-regexp
0 (1- (match-end 0)))
c-start-regexp)))
- hs-forward-sexp-func (or (nth 4 lookup) 'forward-sexp)
- hs-adjust-block-beginning (nth 5 lookup)))
+ hs-forward-sexp-func (or (nth 4 lookup) #'forward-sexp)
+ hs-adjust-block-beginning (or (nth 5 lookup) #'identity)))
(setq hs-minor-mode nil)
(error "%s Mode doesn't support Hideshow Minor Mode"
(format-mode-line mode-name))))
"Evaluate BODY forms if variable `hs-minor-mode' is non-nil.
In the dynamic context of this macro, `inhibit-point-motion-hooks'
and `case-fold-search' are both t."
+ (declare (debug t))
`(when hs-minor-mode
(let ((inhibit-point-motion-hooks t)
(case-fold-search t))
,@body)))
-(put 'hs-life-goes-on 'edebug-form-spec '(&rest form))
-
(defun hs-overlay-at (position)
"Return hideshow overlay at POSITION, or nil if none to be found."
(let ((overlays (overlays-at position))
(message "Hiding blocks ... done"))
(run-hooks 'hs-hide-hook)))
-(defun hs-toggle-hiding ()
+(defun hs-toggle-hiding (&optional e)
"Toggle hiding/showing of a block.
-See `hs-hide-block' and `hs-show-block'."
+See `hs-hide-block' and `hs-show-block'.
+Argument E should be the event that triggered this action."
(interactive)
(hs-life-goes-on
+ (posn-set-point (event-end e))
(if (hs-already-hidden-p)
(hs-show-block)
(hs-hide-block))))
-(defun hs-mouse-toggle-hiding (e)
- "Toggle hiding/showing of a block.
-This command should be bound to a mouse key.
-Argument E is a mouse event used by `mouse-set-point'.
-See `hs-hide-block' and `hs-show-block'."
- (interactive "@e")
- (hs-life-goes-on
- (mouse-set-point e)
- (hs-toggle-hiding)))
+(define-obsolete-function-alias 'hs-mouse-toggle-hiding #'hs-toggle-hiding "27.1")
(defun hs-hide-initial-comment-block ()
"Hide the first block of comments in a file.
The main commands are: `hs-hide-all', `hs-show-all', `hs-hide-block',
`hs-show-block', `hs-hide-level' and `hs-toggle-hiding'. There is also
-`hs-hide-initial-comment-block' and `hs-mouse-toggle-hiding'.
+`hs-hide-initial-comment-block'.
Turning hideshow minor mode off reverts the menu bar and the
variables to default values and disables the hideshow commands.
(hs-grok-mode-type)
;; Turn off this mode if we change major modes.
(add-hook 'change-major-mode-hook
- 'turn-off-hideshow
+ #'turn-off-hideshow
nil t)
(easy-menu-add hs-minor-mode-menu)
(set (make-local-variable 'line-move-ignore-invisible) t)