“hide-region” is Emacs package to hide the selected region in the buffer.
The original version was copied from https://gist.github.com/mplscorwin/7832d7de7530ff355bff5778e46f477d/, and I adapt the code and made some improvement.
The old library introduction can be found in https://www.emacswiki.org/emacs/HideRegion.
- Add
hide-region-folded-face
for the overlay, and removehide-region-before-string
,hide-region-after-string
andhide-region-propertize-markers
. - Add
hide-region-set-up-overlay-fn
to allow customize the overaly. - Add keymap
hide-region-overlay-map
for the overlay.
By default, “<tab>” is binding tohide-region-unhide
. - Re-implement
hide-region-hide
,hide-region-unhide
, andhide-region-unhide-all
. - Remove
hide-region-unhide-below
andhide-region-toggle
. - Add
hide-region-toggle-hide
. - Support to navigate over all the hide regions.
Firstly clone this git repo to “${user-emacs-directory}/packages/hide-region”, and add folowing lines to Emacs config file:
(use-package hide-region
:defer t
:ensure nil ; it is github package
;; If the path is relative, it is expanded within `user-emacs-directory'
:load-path "packages/hide-region"
:bind (("C-<f9>" . hide-region-toggle-hide)
("C-M-<f9>" . hide-region-unhide-all)
;; :map hide-region-overlay-map
;; ("<tab>" . hide-region-unhide)
;; ("n" . hide-region-next-ov)
;; ("p" . hide-region-pre-ov)
)
:init
(let ((pkg-name "hide-region"))
(ignore-errors
(package-generate-autoloads pkg-name
(expand-file-name (concat "packages/" pkg-name)
user-emacs-directory)))
(load (concat pkg-name "-autoloads.el")))
)
hide-region-hide
Hide the selected region.hide-region-unhide
Unhide the hide region.hide-region-toggle-hide
If the selected region is active, runhide-region-hide
to hide the region; otherwise, get the overlays of current point, and unhide the region.hide-region-unhide-all
Unhide all the region in the buffer.
hide-region-set-up-overlay-fn
Customize the overlay.hide-region-overlay-map
Set new keybindings to the overlay keymap. \ By default,key Command “<tab>” hide-region-unhide
“n” hide-region-next-ov
“p” hide-region-pre-ov
- Default behavior
- Customize
hide-region-set-up-overlay-fn
by adding the info of number of lines(use-package hide-region :custom (hide-region-set-up-overlay-fn #'my-hide-region-folded-overlay) :init (defun my-hide-region-folded-overlay (ov) (let* ((nlines (count-lines (overlay-start ov) (overlay-end ov))) (info (format " ... #%d " nlines))) (overlay-put ov 'display (propertize info 'face hide-region-folded-face)))) )