help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: bounds-of-thing-at-point for paragraphs


From: Drew Adams
Subject: RE: bounds-of-thing-at-point for paragraphs
Date: Sun, 1 Nov 2020 14:10:28 -0800 (PST)

> > I think for discoverability for non-Elisp-programmer Emacs users it
> > would be nice at least if there was something that would dynamically
> > generate a list for you.
> 
> Fully agree.  A list is a beautiful thing.

I use this, which is a straightforward definition
from the thingatpt.el Commentary.

(defun icicle-defined-thing-p (thing)
  "Return non-nil if THING is defined as a thing-at-point type.
THING is normally a symbol, but it can also be a string that names a
symbol or a cons whose car is such a string.  This is so that the
function can be used to filter completion candidates."
  (when (consp thing) (setq thing  (car thing)))
  (when (stringp thing) (setq thing  (intern thing)))
  (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))))

(defun icicle-things-alist ()
  "Alist of most thing types currently defined.
Each is a cons (STRING), where STRING 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
`icicle-defined-thing-p', but with these excluded: `thing', `buffer',
`point'."
  (let ((types  ()))
    (mapatoms
     (lambda (tt)
       (when (icicle-defined-thing-p tt)
         (push (symbol-name tt) types))))
    ;; Remove types that don't make sense.
    (dolist (typ  '("thing" "buffer" "point"))
      (setq types (delete typ types)))
    (setq types  (sort types #'string-lessp))
    (mapcar #'list types)))

Remove the mapcar sexp in the latter definition, if you
want just a list, not an alist, of names.  Map `intern'
over the list if you want symbols instead of strings.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]