0

I want to do two things.

  1. Starting at point, get the next N words and store them in a list.
  2. Starting at point, get the next N elements (any isolated text sequence) and store them in a list.
5
  • What is an "isolated text sequence" pray? That's almost as clear as "element". Also: one question per question.
    – NickD
    Commented Oct 23, 2022 at 2:52
  • An Isolated Text Sequence is any continuous sequence of characters with the ends being either whitespace, beginning of line, end of line, or control characters.
    – Dilna
    Commented Oct 23, 2022 at 2:59
  • OK - maybe you can ask your second question as a separate question and add this explanation to the question to begin with.
    – NickD
    Commented Oct 23, 2022 at 3:10
  • Isn't this question already included in your other question here: emacs.stackexchange.com/q/74219/105?
    – Drew
    Commented Oct 23, 2022 at 17:39
  • Please pose only one question per post.
    – Drew
    Commented Oct 23, 2022 at 17:39

1 Answer 1

1

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.