Coder Social home page Coder Social logo

hide-region's Introduction

hide-region.el

About

“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.

Improvement

  1. Add hide-region-folded-face for the overlay, and remove hide-region-before-string, hide-region-after-string and hide-region-propertize-markers.
  2. Add hide-region-set-up-overlay-fn to allow customize the overaly.
  3. Add keymap hide-region-overlay-map for the overlay.
    By default, “<tab>” is binding to hide-region-unhide.
  4. Re-implement hide-region-hide, hide-region-unhide, and hide-region-unhide-all.
  5. Remove hide-region-unhide-below and hide-region-toggle.
  6. Add hide-region-toggle-hide.
  7. Support to navigate over all the hide regions.

Usage

Install

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")))
  )

Usage

Commands

  1. hide-region-hide
    Hide the selected region.
  2. hide-region-unhide
    Unhide the hide region.
  3. hide-region-toggle-hide
    If the selected region is active, run hide-region-hide to hide the region; otherwise, get the overlays of current point, and unhide the region.
  4. hide-region-unhide-all
    Unhide all the region in the buffer.

Customize variable

  1. hide-region-set-up-overlay-fn
    Customize the overlay.
  2. hide-region-overlay-map
    Set new keybindings to the overlay keymap. \ By default,
    keyCommand
    “<tab>”hide-region-unhide
    “n”hide-region-next-ov
    “p”hide-region-pre-ov

Snapshot

  1. Default behavior

    ./image/image1.png

  2. 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))))
      )
        

    ./image/image2.png

hide-region's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.