I want to write an Elisp command that searches for a specific string in the backward direction, pauses the cursor there for a second, echoes a message about that occurrence, and then returns the cursor back to its original position. The purpose of the command is to examine the contents surrounding the search string. My text is structured like below:
\begin{myverse}
line one of verse
line two of verse ॥ 3.2 ॥ \\
\end{myverse}
\vspace{2mm}
Lots of text
below
over multiple
lines
cursor here
If my cursor is at the last line (cursor here
), I would like the Elisp function to search backwards for the first occurrence of the text ॥
, pause for a bit so that I can read the number (3.2), and then return the cursor back to its previous position. I have the following command:
(defun fn ()
"Retrieve verse number"
(interactive)
(setq test-str "॥")
(save-excursion
(search-backward test-str)
(sit-for 1)))
How can this command be enhanced so that it that prints the verse number in the echo area (i.e. where I type M-x fn
)?