You can make characters invisible, so that they do not appear on
the screen, with the invisible property. This can be either a
text property (see Text Properties) or a property of an overlay
(see Overlays). Cursor motion also partly ignores these
characters; if the command loop finds point within them, it moves
point to the other side of them.
In the simplest case, any non-nil invisible property makes
a character invisible. This is the default case—if you don't alter
the default value of buffer-invisibility-spec, this is how the
invisible property works. You should normally use t
as the value of the invisible property if you don't plan
to set buffer-invisibility-spec yourself.
More generally, you can use the variable buffer-invisibility-spec
to control which values of the invisible property make text
invisible. This permits you to classify the text into different subsets
in advance, by giving them different invisible values, and
subsequently make various subsets visible or invisible by changing the
value of buffer-invisibility-spec.
Controlling visibility with buffer-invisibility-spec is
especially useful in a program to display the list of entries in a
database. It permits the implementation of convenient filtering
commands to view just a part of the entries in the database. Setting
this variable is very fast, much faster than scanning all the text in
the buffer looking for properties to change.
This variable specifies which kinds of
invisibleproperties actually make a character invisible. Setting this variable makes it buffer-local.
t- A character is invisible if its
invisibleproperty is non-nil. This is the default.- a list
- Each element of the list specifies a criterion for invisibility; if a character's
invisibleproperty fits any one of these criteria, the character is invisible. The list can have two kinds of elements:
- atom
- A character is invisible if its
invisibleproperty value is atom or if it is a list with atom as a member.(atom. t)- A character is invisible if its
invisibleproperty value is atom or if it is a list with atom as a member. Moreover, a sequence of such characters displays as an ellipsis.
Two functions are specifically provided for adding elements to
buffer-invisibility-spec and removing elements from it.
This function adds the element element to
buffer-invisibility-spec. Ifbuffer-invisibility-specwast, it changes to a list,(t), so that text whoseinvisibleproperty istremains invisible.
This removes the element element from
buffer-invisibility-spec. This does nothing if element is not in the list.
A convention for use of buffer-invisibility-spec is that a
major mode should use the mode's own name as an element of
buffer-invisibility-spec and as the value of the
invisible property:
;; If you want to display an ellipsis: (add-to-invisibility-spec '(my-symbol . t)) ;; If you don't want ellipsis: (add-to-invisibility-spec 'my-symbol) (overlay-put (make-overlay beginning end) 'invisible 'my-symbol) ;; When done with the overlays: (remove-from-invisibility-spec '(my-symbol . t)) ;; Or respectively: (remove-from-invisibility-spec 'my-symbol)
You can check for invisibility using the following function:
If pos-or-prop is a marker or number, this function returns a non-
nilvalue if the text at that position is invisible.If pos-or-prop is any other kind of Lisp object, that is taken to mean a possible value of the
invisibletext or overlay property. In that case, this function returns a non-nilvalue if that value would cause text to become invisible, based on the current value ofbuffer-invisibility-spec.
Ordinarily, functions that operate on text or move point do not care
whether the text is invisible. The user-level line motion commands
ignore invisible newlines if line-move-ignore-invisible is
non-nil (the default), but only because they are explicitly
programmed to do so.
However, if a command ends with point inside or immediately before invisible text, the main editing loop moves point further forward or further backward (in the same direction that the command already moved it) until that condition is no longer true. Thus, if the command moved point back into an invisible range, Emacs moves point back to the beginning of that range, and then back one more character. If the command moved point forward into an invisible range, Emacs moves point forward up to the first visible character that follows the invisible text.
Incremental search can make invisible overlays visible temporarily
and/or permanently when a match includes invisible text. To enable
this, the overlay should have a non-nil
isearch-open-invisible property. The property value should be a
function to be called with the overlay as an argument. This function
should make the overlay visible permanently; it is used when the match
overlaps the overlay on exit from the search.
During the search, such overlays are made temporarily visible by
temporarily modifying their invisible and intangible properties. If you
want this to be done differently for a certain overlay, give it an
isearch-open-invisible-temporary property which is a function.
The function is called with two arguments: the first is the overlay, and
the second is nil to make the overlay visible, or t to
make it invisible again.