It's not enough to test for properties beginning-op
, end-op
, bounds-of-thing-at-point
, and thing-at-point
. A thing can instead be defined by property forward-op
or by a forward-
THING function. (And some uses of things require the existence of a forward-op
or a forward-
THING function.)
Library thing-cmds.el
(code) defines these functions:
thgcmd-things-alist
is a compiled Lisp function in thing-cmds.el.
(thgcmd-things-alist &optional REQUIRE-FWD-P)
List of most thing types currently defined.
Each is a string that names a type of text entity for which there is a
either a corresponding forward-
thing operation, or corresponding
beginning-of-
thing and end-of-
thing operations. The list
includes the names of the symbols that satisfy
thgcmd-defined-thing-p
, but with these excluded: thing
, buffer
,
point
.
Non-nil arg REQUIRE-FWD-P
means exclude THING
s that do not have an
associated forward-THING
function.
This is the definition of thgcmd-defined-thing-p
, which sounds like what you're looking for:
(defun thgcmd-defined-thing-p (thing)
"Return non-nil if THING (type) is defined as a thing-at-point type.
THING is a symbol."
(let ((forward-op (or (get thing 'forward-op)
(intern-soft (format "forward-%s" thing))))
(beginning-op (get thing 'beginning-op))
(end-op (get thing 'end-op))
(bounds-fn (get thing 'bounds-of-thing-at-point))
(thing-fn (get thing 'thing-at-point)))
(or (functionp forward-op)
(and (functionp beginning-op) (functionp end-op))
(functionp bounds-fn)
(functionp thing-fn))))
There is also user option thing-types
:
thing-types
is a variable defined in thing-cmds.el
.
Its value is
("sexp" "button" "char" "char-same-line" "color" "comment"
"decimal-number" "defun" "email" "filename" "hex-number" "line" "list"
"list-contents" "non-nil-symbol-name" "number" "overlay" "page"
"paragraph" "region-or-word" "sentence" "string" "string-contents"
"symbol" "symbol-name" "unquoted-list" "url" "whitespace"
"whitespace-&-newlines" "word")
Documentation:
List of thing types.
Each is a string that names a type of text entity for which there is a
either a corresponding forward-
thing operation, or corresponding
beginning-of-
thing and end-of-
thing operations.
The default value includes the names of most symbols that satisfy
thgcmd-defined-thing-p
at the time the defcustom
is evaluated.
These types are excluded: thing
, buffer
, point
.
M-@
cycles through this list, in order.
You can customize this variable.
The actual default value depends on your setup. This is the sexp that is evaluated at defcustom
time to produce the default value:
(let ((types ()))
(mapatoms
(lambda (tt)
(when (thgcmd-defined-thing-p tt) (push (symbol-name tt) types))))
(setq types (sort types #'string-lessp))
;; Remove types that do not make sense.
(dolist (typ '("sexp" "thing" "buffer" "point"))
(setq types (delete typ types)))
(setq types (cons "sexp" types))) ; Put `sexp' first.
The option is used in command cycle-select-something
, and it could also be useful in other contexts:
cycle-select-something
is an interactive compiled Lisp function in
thing-cmds.el
.
It is bound to M-@
.
(cycle-select-something)
Select something at or near point. Successively select different things.
The default thing type is the first element of option thing-types
.
In Transient Mark mode, you can follow this with C-M-SPC
to select
successive things of the same type, but to do that you must first use
C-x C-x
: M-@ C-x C-x C-M-SPC
.
If option thgcmd-use-nearest-thing-flag
and non-nil
then use a thing
that is near, not necessarily at, point.