Function try-completion
tests whether a given string can be completed against a given set of completions (e.g. strings).
Function buffer-list
provides the list of buffers.
Function buffer-name
returns the name of a given buffer.
(defun matches-a-buffer-name? (name)
"Return non-nil if NAME matches the name of an existing buffer."
(try-completion name (mapcar #'buffer-name (buffer-list))))
try-completion
also accepts an optional PREDICATE
argument, which you can use to impose a particular kind of testing, e.g., a particular kind of matching.
C-h f try-completion
tells you, part:
Return common substring of all completions of STRING
in COLLECTION
.
Test each possible completion specified by COLLECTION
to see if it begins with STRING
. The possible completions may be
strings or symbols. Symbols are converted to strings before testing,
see symbol-name
.
All that match STRING
are compared together; the longest initial sequence
common to all these matches is the return value.
If there is no match at all, the return value is nil
.
For a unique match which is exact, the return value is t
.