I want to do two things.
- Starting at point, get the next
N
words and store them in a list. - Starting at point, get the next
N
elements (any isolated text sequence) and store them in a list.
For question 1. only:
(defun my/word-list (n)
(save-excursion
(let ((s (buffer-substring (point) (progn (forward-word n) (point)))))
(s-split-words s))))
This requires that the package s.el be installed. It is available on MELPA.
With the following text and the cursor at the `|' below:
This is a test of the |emergency broadcasting system.
calling the function with M-: (my/word-list 3)
returns ("emergency" "broadcasting" "system")
.
The function does no error checking (e.g. if there aren't n
words after point
, you get a list of the remaining words and no indication that something is wrong).
Isolated Text Sequence
is any continuous sequence of characters with the ends being either whitespace, beginning of line, end of line, or control characters.