Related Question

I want to interactively invoke Elisp code which extracts the words between two arbitrary symbols. So could someone kindly guide me to a modest document which explains how to invoke Elisp code in Emacs?

This is the code I want to execute on a txt file:

(when (string-match "<br>\\(.*?\\)<" STR)
(match-string 1 STR))
  • Type M-: then paste your code (both lines at once) into the prompt and press enter. – jue Apr 9 at 8:08
  • you could google for a tutorial to eval-expression. Maybe this page is ok for you: emacslife.com/read-lisp-tweak-emacs/… – jue Apr 9 at 8:13
  • @jue Thanks, Can you tell where I can go to understand what it means? I copy and pasted the text in that question and then copied the command and using M-: but it said: Symbol's value as variable is void: STR. – nima Apr 9 at 8:58
  • @nima Well STR is from your own code, so you probably have an entirely different question (which you should post separately) about how to achieve your actual goal. Knowing how to evaluate some elisp doesn't help you come up with the right elisp to evaluate. – phils Apr 9 at 9:28
  • From your question it is not clear what you are operating on and what do you want to do. Lets assume, you want to search the first occurance in a whole buffer. Then you can evaluate the following code as I described earlier: (let ((STR (buffer-substring-no-properties (point-min) (point-max)))) (when (string-match "<br>\\(.*?\\)<" STR) (match-string 1 STR))) – jue Apr 9 at 10:59

could someoone kindly guide me to a modest document which explains how to give an elisp command in emacs?

Yes, https://masteringemacs.org/article/evaluating-elisp-emacs is an excellent article specifically on that subject.

For Emacs.SE purposes I'll list the options covered, but you'll want to read the full article.

  • C-xC-e which is bound to eval-last-sexp
  • C-M-x which is bound to eval-defun
  • M-: which is bound to eval-expression
  • C-j in the *scratch* buffer
  • M-x eval-region
  • M-x eval-buffer
  • M-x ielm to run the elisp REPL

and of course M-x itself (which is bound to execute-extended-command) is a way to "give an elisp command" in the sense that most commands are implemented in elisp and named. e.g. eval-region in the previous list is the name of a command.

  • Thank you phils. – nima Apr 11 at 10:40
  • 1
    A kind reminder that if you found the response helpful and that it answered your question to please mark it as accepted. – Lorem Ipsum Apr 12 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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