Shop OBEX P1 Docs P2 Docs Learn Events
Gnu Emacs, a useful IDE tool, available now (and for over 30 years) — Parallax Forums

Gnu Emacs, a useful IDE tool, available now (and for over 30 years)

denominatordenominator Posts: 242
edited 2012-02-15 04:07 in Propeller 1
I just came across this forum yesterday, and I noticed that folks are waiting for a GUI IDE. I also saw another post titled "What editors are being used?".

I thought I'd take a moment to point out Emacs to folks who aren't familiar with it. Emacs was the original piece of the Gnu project (as in the Gnu C Compiler that propgcc is based on). Emacs was invented by Richard Stallman, who basically does *all* his work in it - it supports code editing, compiling, debugging, and a bunch more stuff.

Personally, I love Emacs, and it's been my goto text editor since 1977. If an Eclipse GUI for propgcc came out tomorrow, I'd say "that's nice", and keep using Emacs. I've used pretty much every IDE there is. When a particular IDE provides integrated features I can't live without, I still tend to do the bulk of my editing (and especially all the complicated editing) in Emacs (the macro facility is really quite useful) and just use the IDE for its unique features.

The most important features of an IDE for me are: (1) Electric editing (i.e. highlighting, indentation, paren/quote/brace matching, etc.), (2) One-touch compilation, (3) Quickly navigating from errors back to the source, (4) Symbol look up, and (5) Debugger integration. Emacs supports all of these, perhaps in a bit rougher form than "modern" IDEs, but still quite usable.

Emacs is extensive (it supports practically every language, even spin) - there's too much to even try to cover here, but there's tons of stuff on the web. Two good places to start are:

http://www.linuxjournal.com/article/5765?page=0,0
http://deep.syminet.com/emacside.html

A few details about using emacs with propgcc:

The fact that propgcc is a command line compiler makes it ideal to use with Emacs. Yes, you have to fiddle with the makefiles a bit or else write .bat command files to get automatic compiling, but IMHO (A) it's not that difficult and (B) every programmer should probably know about (or at least want to learn about) make systems.

Setting up Emacs to use propgcc is trivial. If your development system is Windows like mine is, just google for "gnu emacs windows download", then download and unzip the latest version and run it's "addpm" program to get it "installed" in Windows. There are prepackaged version for Mac and Linux too, just search for them.

I put the following into a file named "m.bat" in the same directory with my code:

****** Start of m.bat ******
@echo off
set path=c:\users\ted\propgcc\propgcc-0.2.2\bin;%PATH%

echo Running make all
make all
if errorlevel 1 goto end

echo Running make run (download to the prop) in a separate window
set keepWin=
if "%1%" == "" goto noarg
set keepWin=cmd /k
:noarg
start %keepWin% make run

:end
****** End of m.bat ******

Of course, I also had to set up a makefile. The demo programs all have makefiles, so I just copy them and customize as needed. I could have just thrown compilation commands into the batch file instead of running make.

To get one-touch compiling, I threw the following line into my .emacs file:

(global-set-key [f9] 'compile)

To compile, I just hit the <F9> key, then hit <enter> (the first time I run it, I change the default command "make -k" to my batch file "m" before hitting <enter>). The compile output appears in a window, and I can click on errors that come up to go right to the line with the error.

As you can see from the above batch file, if the compilation ran without error, the m.bat brings up a separate window to download the program to the prop and run it. I put the commands for downloading/running in the makefile, but again, you could just include the propeller-load command in the batch file. Here's my makefile's "run" rule:

BOARDFLAG = -b spinstamp
RUNFLAGS = -r -t19200 # Load ram and run, then open terminal

#
# how to run
#
run: $(NAME).elf
$(LOADER) $(BOARDFLAG) $(NAME).elf $(RUNFLAGS)

To get symbol lookup and symbol completion, I threw the following into my makefile:

TAGS: *.c *.h
etags $^

and I added TAGS to the default "all" rule, so I get new symbols with each compilation:

# default build target
all: $(NAME).elf TAGS

Of course, you have to know the proper Emacs commands to use symbol search and completion.

All this covers IDE features 1-4. Feature 5, debugging, is also supported in Emacs via GDB. If/when propgcc supports GDB, hopefully this will just work too!

This is all FYI, in case anybody is interested. I did a search on "Emacs" across all the forums, and it only generated 42 hits. This is comparitively uncommon (search for words like "blink" and the search will stop at 500). So with apologies to those folks who already know and use Emacs (or the vi, etc., users who don't want to), I figured Emacs could use a proper introduction to the forums.

- Ted

Comments

  • RossHRossH Posts: 5,512
    edited 2012-02-01 01:10
    I love Emacs! Watching someone who knows how to use it is like watching one of those amazing people who can solve a Rubik's cube in 6 seconds. But whenever you try, every command you enter just serves to embed you deeper in some bizarre and torturous sub-mode from which the exit code is a closely guarded secret!

    I'm sure it was the inspiration for the original game of Zork - "You are in a maze of twisty little passages, all alike ..."

    Ross.
  • LeonLeon Posts: 7,620
    edited 2012-02-01 04:21
    I've always liked Emacs, it's my preferred Linux editor.
  • jazzedjazzed Posts: 11,803
    edited 2012-02-01 10:05
    Hi Ted,

    Welcome to these forums!

    Thanks for contributing this information for the widely used EMACS code tools.

    --Steve
  • Martin_HMartin_H Posts: 4,051
    edited 2012-02-01 10:22
    Emacs is great, free, and everywhere, and I've been a user for decades.
  • shimniokshimniok Posts: 177
    edited 2012-02-01 15:41
    Yay GNU emacs! Started using it back in college (erm, that was about 20+ years ago eek). It's extremely extensible (just learn elisp heheh) so would imagine it could be set up to very cleanly and nicely support various mcu development.
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2012-02-04 22:08
    Can't have a thread about Emacs and not link to a relevant xkcd... https://www.xkcd.com/378/

    :)
  • shimniokshimniok Posts: 177
    edited 2012-02-05 07:52
    Pure awesomeness :D
  • 4x5n4x5n Posts: 745
    edited 2012-02-05 09:19
    VI forever!!!!!!!





    (sorry couldn't resist)
  • Heater.Heater. Posts: 21,230
    edited 2012-02-05 09:38
    Oh dear. Here we go...
    As it happens there is a Spin mode for vi/vim which looks very good. Sorry I don't have a link for it to hand but it was posted to the Propeller forum.
  • LeonLeon Posts: 7,620
    edited 2012-02-05 09:45
    We used vi on our Silicon Graphics machines when I worked for British Aerospace, many years ago. I've been using it again on the BeagleBone recently, it's just as awkward.
  • jazzedjazzed Posts: 11,803
    edited 2012-02-05 10:15
    I don't believe this is a vim-vs-emacs thread.
    The cartoon strip was very funny though.

    The old vi program is horrible; vim is much better.

    heater, there is a spin syntax highlighter for emacs too.
  • TorTor Posts: 2,010
    edited 2012-02-15 04:07
    Instead of using tags/etags and having to edit the Makefile I prefer to use 'idutils'.

    You run 'mkid' (initially, and whenever you feel you need to) in the command line, which creates an ID file (valid for that directory and all its subdirectories. The way it works is that when referencing a symbol the tool will walk 'up' until it finds the first ID file, so you can distribute them as you like). Then I have id-utils.el loaded from my site-lisp (or could have used my $HOME/.emacs or $HOME/.xemacs directories). From then on Emacs or XEmacs will know about symbols and it's easy to hover over e.g. a function name and find all references to it. There's not need for any 'make tags' or anything in the Makefile, and it'll know about symbols in other directories too, as you wish (you decide by running 'mkid' up or down subdirectories to the appropriate level). So it's easy to work with setups where e.g. library code is elsewhere.

    -Tor
Sign In or Register to comment.