I would like to be able to store text between 2 positions (the string in between), but I don’t know where to conveniently store it, perhaps just locally, or even globally (let or setq). The answer is probably out there, but I couldn’t find it.
Example:
I would like to store text in a symbol in order to search for it backwards. Let’s say the region from (point) until the first whitespace character.
My previous way of doing this was using (kill-ring-save), but I know this is a bad practice.
From (here) (message "hello")(point)
I would be interested in both better techniques for doing this, as well as the best way to store a string which is somehwere around (point).
If a temporary local scope is all you require, then you definitely want to use
let.Otherwise you would usually define a variable (keeping in mind when you name it that elisp has no name spaces, so best practice is to use as reliably unique a prefix for all symbol names in a given library as practical).
If you omit the INITVALUE argument, the variable will not be bound initially, but ensures that your variable will use dynamic binding once used.
Then you just
setqthe variable as required.Edit:
To obtain a buffer’s contents between two points, use either of
(buffer-substring START END)(buffer-substring-no-properties START END)depending on whether or not you wish to preserve text properties.