Emacs for programming


#1

I’ve been using emacs to write my code and send it to the board using the emacs built in serial terminal. Emacs being lisp smart (among many other things) gives code color high lighting and parenthesis matching.
The terminal has cut and pasting as well as all the other editing features (in line mode). It takes a bit to get use too but once you establish a work flow its far supperior to the arduino serial terminal.


#2

That sounds like a great way of working with uLisp. Would you consider writing up a bit more detail? How to get and install emacs, set it up, and what platforms it supports?


#3

Is there a way to copy the lisp expression from the source file to the serial-term? (I mean by not using M-c, C-x o, C-y)?
I think it exists a emacs-mode which uses C-c e or something like this to evaluate the expression where the cursor is.
Do you know if it is possible to use something like this?


#4

Emacs is an extensible (you can add to it) text editor that has been around since the dark ages of unix.
Its written in C and a dialect of lisp (elisp).

I believe emacs is cross platform, but I have no understanding of windoze or mackos so you’re on you’re own on how to install it here. On Linux its available either already installed or available in your distros repository.

Once installed I recommend doing the tutorial which is available holding down the control and h key then pressing t. Also, the resource that got me over the hump and on the road to using emacs for everything was the excellent podcasts done by Klaatu for hackerpublicradio, the links are as follows:

http://hackerpublicradio.org/eps.php?id=0852
https://hackerpublicradio.org/eps.php?id=0856
https://hackerpublicradio.org/eps.php?id=0861

listen to those and you’ll be well on your way to using emacs for all of your computing needs.

As far as using emacs for ulisp, I usually split the screen and have the serial terminal in one buffer (meta-x serial-term) and the scratch buffer in the other. I compose my code in the scratch buffer then cut and paste to the terminal there. You must be in line mode (C-c C-j) for this to work, and char mode (C-c C-k) sends the text to the device. If that doesn’t make sense, you haven’t listened to the podcasts ;) Anyway, I haven’t yet explored all the serial terminal can do or customized it in anyway but it is much more functional than the arduino terminal. Hope this helps.

In response to Kaef:

I don’t know of a way to push the code to the buffer with the the serial terminal in it, but that doesn’t mean its not possible.


#5

Thanks for the information! There are several Mac versions of Emacs; for a good review see:


#6

I’m use emacs serial-term too. But instead of copy the code by hand,
i have the following snippet in my init.el (emac’s config file):

(setq ulisp-term-buffer-name "/dev/ttyUSB0")

(defun ulisp-eval-last-expression-in-term ()
  (interactive)
  (let ((expr (buffer-substring-no-properties  
                     (save-excursion (backward-sexp) (point))
                     (point))))
      (with-current-buffer ulisp-term-buffer-name
          (insert expr)
          (term-send-input))))

(global-set-key (kbd "C-x e") 'ulisp-eval-last-expression-in-term)

With this snippet, i can place my cursor at the end of a expression (after the last closing “)”)
and hit Ctrl-x e to evaluate it (copy it in the serial-term buffer and send it to the esp).

To test it yourself, you can copy this snippet in your *scratch* buffer, evaluate each
expression per Ctrl-x Ctrl-e or type M-x eval-buffer to evaluate the whole buffer.

Maybe you need to adjust the variable ulisp-term-buffer-name. Use the name
of your serial-term buffer. I use Linux (so it’s /dev/ttyUSB0) and FreeBSD (so it’s /dev/ttyU0).
For other platforms, i have no idea.

If something is unclear, feel free to ask.


#7

That’s great! I was playing around last night to try to do just that. Awesome!


#8

Great, that’s what I was looking for – thank you very much!