The commands select various Lisp objects and text entities that are at or near point (cursor position), or they move point to such an object or text entity. The commands are described individually below.
Completion or cycling is available to choose the type of thing to use. Pretty much all thing types are completion candidates. User option
‘thing-types’ determines the types that are available for cycling.
‘C-M-SPC’– `mark-thing’ (overwrites the standard binding for
‘mark-sexp’; `sexp’ is the default thing type)
M-@’ – `cycle-thing-region’ (overwrites the standard binding for
‘C-M-S-u’) – `mark-enclosing-sexp’
‘C-M-S-f’) – `mark-enclosing-sexp-forward’
‘C-M-S-b’) – `mark-enclosing-sexp-backward’
‘C-x down’– `next-visible-thing-repeat’ (Emacs 22 and later)
‘C-x up’– `previous-visible-thing-repeat’ (Emacs 22 and later)
‘mark-thing’ marks, that is selects, successive things, starting at point. Point is moved to the beginning of the enclosing thing (or to the end, if you use a negative prefix argument). Mark is put at the same place that command
‘forward-’thing would put it using the same prefix argument.
If the region is not active, you are prompted for the type of thing to use – completion is available. The default type for completion is the first element in user option
‘thing-types’ (which, by default, is `sexp’).
If the region is active, you are not prompted, and the last-used type of thing is used again. On consecutive uses of
‘mark-thing’, the region is active, so you are not prompted, and the region is extended to successive things of the same type.
This is true even if the region is empty – as long as it is active, it is extended using the last-used type of thing, without any prompting. You can thus just hit
‘C-SPC’ to set mark and activate an empty region, then use
‘mark-thing’ to select successive things of the last type used.
‘cycle-thing-region’ selects a single thing near the cursor. You are not prompted for the type of thing. Instead, successive uses of the command select a different type of thing. The first type of thing selected is determined by the first element in option
‘thing-types’ (which, by default, is `sexp’).
In TransientMarkMode, you can follow this with
‘mark-thing’ to select successive things of the same type, but to do that you must first use
‘C-x C-x’ (
‘exchange-point-and-mark’): Using the bindings created by command
‘thgcmd-bind-keys’, this becomes `
M-@ C-x C-x C-M-SPC’. This command has an alias:
‘thing-region’ selects a single thing near the cursor. Unlike
‘cycle-thing-region’, you are prompted for the type of thing – completion is available. The cursor is placed at the end of the region. You can return it to the original location by using
‘C-u C-SPC’ (once or twice, depending on the thing type).
‘mark-enclosing-sexp’ selects a sexp that surrounds the cursor. If you repeat the command it selects a wider enclosing sexp each time you repeat it.
If you use a numeric prefix argument then the selection is that many sexps up, surrounding point. 1 means select the immediately enclosing sexp. 2 means select the sexp immediately enclosing that first enclosing sexp, and so on. A negative prefix argument puts point at the beginning of the new region instead of the end.
This command moves point, and the starting position is added to the mark ring before doing anything else, so you can easily return to that position (e.g. using
‘mark-enclosing-sexp-forward’ are the same, but they specifically put point at the end and beginning of the region, respectively.
‘next-visible-thing’ moves point to the start of the next visible thing of a given type. Things that are currently invisible (using text property
‘invisible’) are ignored.
If user option
‘ignore-comments-flag’ is non-
‘nil’ then things that are commented out are also ignored. They are, in effect, temporarily hidden while scanning for the next thing. If you also use library Icicles then you can use `
C-M-;’ in the minibuffer to toggle this option.
‘previous-visible-thing’ is the same, except that it moves backward, to the first visible thing before point.
These commands prompt you for the type of thing to use, but only the first time they are invoked in succession. So if you bind them to simple repeatable keys, such as
‘f12’, then you can hit those keys over and over to move forward and back successive things.
thing-cmds.el does not bind these two commands, because simple repeatable keys are rare (mostly taken already).
However, if you invoke command thgcmd-bind-keys (e.g. in your init file) then similar commands,
‘previous-visible-thing’, are bound to keys
‘C-x up’ and
‘C-x down’, respectively.
You can repeat movement in either direction without being prompted for the thing type after the first invocation: `
C-x up up up up...’. However, unlike bindings for
‘previous-visible-thing’, if you change direction you are prompted again for the thing type. That’s simply due to definition of command
‘repeat’, which is used for the implementation.
Libraries referenced here: Lisp:thing-cmds.el