Function: forward-thing
forward-thing is an autoloaded and byte-compiled function defined in
thingatpt.el.gz.
Signature
(forward-thing THING &optional N)
Documentation
Move forward to the end of the Nth next THING.
THING should be a symbol specifying a type of syntactic entity.
Possibilities include symbol, list, sexp, defun, number,
filename, url, email, uuid, word, sentence, whitespace,
line, and page.
Probably introduced at or before Emacs version 30.1.
Source Code
;; Defined in /usr/src/emacs/lisp/thingatpt.el.gz
;; Basic movement
;;;###autoload
(defun forward-thing (thing &optional n)
"Move forward to the end of the Nth next THING.
THING should be a symbol specifying a type of syntactic entity.
Possibilities include `symbol', `list', `sexp', `defun', `number',
`filename', `url', `email', `uuid', `word', `sentence', `whitespace',
`line', and `page'."
(setq n (or n 1))
(if (assq thing forward-thing-provider-alist)
(let* ((backward (< n 0))
(reducer (if backward #'max #'min))
(limit (if backward (point-min) (point-max))))
(catch 'done
(dotimes (_ (abs n))
;; Find the provider that moves point the smallest non-zero
;; amount, and use that to update point.
(let ((new-point (seq-reduce
(lambda (value elt)
(if (eq (car elt) thing)
(save-excursion
(funcall (cdr elt) backward)
(if value
(funcall reducer value (point))
(point)))
value))
forward-thing-provider-alist nil)))
(if (and new-point (/= new-point (point)))
(goto-char new-point)
;; If we didn't move point, move to our limit (min or max
;; point), and terminate.
(goto-char limit)
(throw 'done t))))))
(let ((forward-op (or (get thing 'forward-op)
(intern-soft (format "forward-%s" thing)))))
(if (functionp forward-op)
(funcall forward-op n)
(error "Can't determine how to move over a %s" thing)))))