What you want is called folding, and there are 2 ways you can do that.
This is a built-in minor mode that is exactly what org-mode uses to
hide and display it's headlines. You can make sure it's always turned
on in latex-mode with
(add-hook 'LaTeX-mode-hook #'outline-minor-mode)
The keybinds it defines are a little hard to use, so you ...
Try out vimish-fold.
batteries included: activate minor mode, bind a couple of commands and
everything will just work;
it works on regions you select;
it's persistent: when you close file your folds don't disappear;
in addition to being persistent, it scales well, you can work on hundreds
of files with lots of folds without adverse effects;
Hideshowvis adds clickable icons to the fringe, but for some strange reason it's not included in elpa or melpa. By default it shows a - in the fringe for code that can be folded, and then elides the content with a .... By also enabling hideshowvis-symbols it adds a + and makes the hinting for folded content a little louder.
Hideshow itself also allows mouse ...
NB: much of this text came from an answer to a question that turned out to be a duplicate of this question. Some of the material is sufficiently different that it seemed worthwhile to add it to this question.
Outline mode and the AUCTeX folding facilities are two different beasts that are meant to do broadly the same thing: hide and show selected parts of ...
There are more folding options for Emacs: http://wikemacs.org/wiki/Folding#Yafolding
and Yafolding looks like the best for your case since it is based on indentation. It also includes a nice interface à-la Magit to discover the commands.
However, that doesn't fully answer your question since it won't show the range of the fields out of the box.
You can use TeX-fold-comment (C-c C-o C-c) to hide the comment. You need to enable TeX-fold-mode to make use of this functionality.
See the AUCTeX manual on folding macros and environments for more information.
C-hig (emacs)Line Truncation
As an alternative to continuation (*note Continuation Lines::), Emacs
can display long lines by “truncation”. This means that all the
characters that do not fit in the width of the screen or window do not
appear at all. On graphical displays, a small straight arrow in the
fringe indicates truncation at either end of ...
hs-minor-mode is a minor mode. Like most minor modes, it is buffer-specific and should be activated in each buffer where you want it. The error message you have is because the code you added to your init file activates (or tries to activate) hideshow when your init file loads, which is way too early : at that moment, the current buffer is most certainly some ...
(setq-local orgstruct-heading-prefix-regexp "\\s-*/// ")
Replace ??? with the name of the mode, where you want this to happen.
This will use /// as an indication of the beginning of the sub-tree, which can be folded. The number of * characters following the /// will ...
I tried yafolding, seems to work (theres room for improvement on this, though)
(add-hook 'ruby-mode-hook 'yafolding-mode)
(global-set-key (kbd "M-RET") 'yafolding-toggle-element)
"yafolding", "hideshow", "folding.el", "imenu.el","vimish-fold"
It's not documented well enough, and possibly poorly named, but the hideshow function hs-hide-level will collapse all the blocks within the current block. That is, if your cursor is on the class ... line (or below it) in your example input, it will give you something very similar to your desired output. Since hideshow works with indentation I've found that ...
While I don't think the fringe items can directly receive clicks (I might be wrong though), a possible hack would be to bind (kbd "<left-fringe> <double-mouse-1>")
Since the first click would move the point to the beginning of the line that corresponds to the fringe icon, testing the value of (point) in your hypothetical (un)folding function ...
If you are asking about "absolute fold levels" then I can only guess that you want Org-mode like packages for the hierarchical tree-like structuring of files:
It’s an extension library for outline-minor-mode that gives buffers in different major-modes the 'look-and-feel' of Org-mode buffers and enables the use of outorg and navi-mode on them.
I've tried Vimish fold, and it seems to do what you ask. Below is my setup for the keybindings:
;; this registers a region for future folding/unfolding
(global-set-key (kbd "C-c v") #'vimish-fold)
;; this unregisters the region under point from folding/unfolding
(global-set-key (kbd "C-c d") #'vimish-fold-...
Here is one approach to hide tags in folded view, and show them in any expanded view.
(defun org-toggle-tag-visibility (state)
"Run in `org-cycle-hook'."
(message "%s" state)
;; global cycling
((memq state '(overview contents showall))
(let ((tagstring (nth 5 (org-heading-components)))
There are a lot of different implementations of folding for emacs. Some are specific to a particular programming language or syntax, others are more generic. Of the generic ones, it sounds like yafolding is exactly what you're asking for. I tried it out, and while it feels somewhat slow, it does work.
Another I tried is called origami, and I liked the ...
The preview.el library of auctex shows how something like that can be done with overlays.
Font-lock based solution
Another state-of-the-art package is hi-lock.el.
It does not support setting and filtering text properties out of the box.
Paintover is a modified reduced copy of hi-lock.el.
It serves as concept study for solving this ...
The Org manual section 2.4 Motion describes the key bindings to be used for navigation.
For your case I think
C-c C-p (outline-previous-visible-heading)
would cater the requirement. When you are within a sub heading with lots of lines just use C-c C-p to navigate to the heading and press the Tab key to ...
A quick answer. If I get time I'll try to add a bit more later.
Download isearch-prop.el, and load it.
Use this command to make (...) invisible:
(defun hide/show-parenthetical-text (&optional show)
"Remove parentheses and text between them.
With a prefix arg, show all invisible text."
Folding-mode will automatically fold files when opened if you call (folding-mode-add-find-file-hook) in your init file.
The documentation, however, seems wrong. It says that you need to specify a file-local variable, but testing suggests that this is not needed.
Sorry, my documentation - if you can even call it that - is terrible. I imagine this is intimidating even if you're not new to elisp.
->> is a threading macro from the dash library, as wvxvw correctly points out. The easiest way to explore elisp is to use C-h f to read about functions you aren't familiar with. There should be a link to the source code ...
You, sir, are looking for mode hooks: a set of functions that run every time you enter a buffer in a given mode.
Note that mode hooks will not persist state between sessions, but your question really appears to be about running the same command every time you enter a buffer in a given mode.
Now: for hideshow, the default binding C-c @ C-l is for hs-hide-...
I believe the method given in the question, although not efficient, is sufficient. Let me explain it in greater detail. Assuming you have evil-mode enabled:
Toggle hs-minor-mode to enable folding
Place your cursor at the first column of a def statement line. This can be done by pressing 0
Record a macro which folds the current section and then moves to ...
Use emacs' hideshow. You can keep your cursor anywhere & to hide blocks 'n' level below it, use the command
C-c @ C-l
Here, n is a numeric prefix argument that gets set by pressing
C-u 1 RET
Read more about hsmode here,
More about prefix arguments here,
hs mode doesn't work on Default mode. You need to have js2-mode (or) js-mode ...
C-u <tab> (#'org-cycle) will collapse all top-level trees. This might or might not be what you want.
Alternately, you can move up to the parent heading (repeating it to go more than one level up) with C-c C-u (#'outline-up-heading), and then press tab to collapse it.
This answer does not address evil-vimish-mode. Instead, if
you're agnostic about which particular package does the folding
for you, you can try the built-in Hideshow mode
From the manual:
Hideshow mode is a buffer-local minor mode that allows you to
selectively display portions of a program, which are referred to
as blocks. ...
The following code (lightly tested) takes advantage of the fact
that org-mode is derived from outline-mode, which allows you
to use the latter's functions. It simply jumps up headlines
until it can't go any further, and then hides the subtree.
(defun foldup ()
"Hide the entire subtree from root headline at point."
(while (ignore-errors (...