2

I am fairly new to emacs and I want to learn emacs Lisp. In particular, is it possible to write elisp functions in, say, the scratch buffer to do some complex text-processing on my program file example.cpp whose buffer I would have open in another frame.

Indeed if I could write some elisp code to do text-processing across all the files in the project folder that would be even better!

I am using Spacemacs

closed as too broad by lawlist, Drew, Dan Feb 9 '16 at 12:28

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Elisp is perfect for performing text operations on the content of a buffers, you can define your functions in `*scratch*' or, even better, in a separate file. However, there is no concept of "project" in Emacs (even though some packages provides project-like support). – Lindydancer Feb 9 '16 at 6:10
  • @lawlist I do agree with your comment. But, I was also in the same situation as him until I discovered with-current-buffer. Once you know how to act on a desired buffer, you feel you passed the hardest cliff of leaning elisp and see the huge possibilities. – Yasushi Shoji Feb 9 '16 at 6:18
5

Yes you can! (If you mean frame what Emacs think it is.)

To demonstrate, do the following steps:

Run Emacs

This will put you into the *scratch* buffer.

Create a new frame

M-x make-frame-command to create a new frame, which is also in *scratch*.

Open example.cpp

So that you can now see both *scratch* buffer in the first frame and example.cpp in the newly created frame, side by side.

Write lisp

Copy the following code and past it into the *scratch* buffer.

(with-current-buffer "example.cpp"
  (insert "Hello, Emacs!\n"))

Evaluate it

Put your cursor after the last ) and do M-x eval-last-sexp. If you see "Hello, Emacs!" in the other frame, you got the first step right. You can now customize the code to suite your needs.

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