Sunday 18 November 2012

A Journey into Emacs is a Long One.


I never really intended to get pulled into emacs  I admit I have at points in the past liked it and at other points found it frustrating  My return to it from vim for simple editing and lots of eclipse for Java was initiated when I wanted to play with Clojure. Doing lisp and not using emacs just did not seem right :)

My adventures with Clojure did not last long and I move on to revisiting JavaScript. However I stuck with emacs and use the official js-mode along with the js2-mode thing originating from Steve Yeggie. I think I prefer the Steve Yeggie one at the moment. As there does not seem to be much development on either of these two modes I doubt my opinion will change in the next year of so.

I have written a couple of noob elisp functions but not anything that I use daily. Usually I myself coming up with an idea fiddling a bit and then realising that core emacs has it build in or someone else has already added the idea to some extension. This is good as it is not really a goal to become really good at hammering out elisp. I will just learn as I go.

Some things that I have found useful are:

Book Marking
This is basically a list of places on your drive that you want to jump to. Say different project directories and so on.

The main keys are

  •  C-x r m                     - Make bookmark, you will be prompted for a name
  •  C-x r l                       - To list them
  • M-x bookmark-save  - To save them so they persist past the session

When in a book mark list buffer

  •  D - delete a bookmark
  •  r  - to rename it

I use this everyday.

Register Bookmarks
This one is more for jumping around a file. It lets you drop bookmarks and return to them. The keys for this are

  • C-x r SPACE [a-z]  - Store a position
  • C-x r j [a-z]      - Jump to position


I am guilty of not using these enough. They have not made it into my muscle memory just yet. I am using them more and more so they will be soon.

Navigation Stack
Again another one I am just getting used to and am not 100% on how exactly they work. But they let you go back to position in a buffer or between buffers


  • C-u C-SPACE - Back to a previous position in a buffer.
  • C-x C-SPC      - Back to a previous buffer.


Alignment
I really like this one and nearly wrote some elisp to do this before I found out it existed.

Say you have some code
x = 90
myvar = "the"
thisIsAReallyLongVariableName = 1

and you want to line up all the equal signs to make them a little clearer. It is simple, you just highlight the region and then do

M-x align-regex press return;
then type = and press return
Hey presto we have

x                             = 90
myvar                         = "the"
thisIsAReallyLongVariableName = 1

I really like this as I mentioned before.


Other stuff,
I followed some tutorial when I was first setting up emacs to get things like ido mode working and using them makes the whole experience a lot better. There is an lot of setting up emacs articles on the web.

I will not be doing any proper Java coding in emacs, it would be significantly slower but perhaps on cold winter evening I might give it a go. I also suspect there are better editors for JavaScript but for now I am quite happy.

I think I am over the hardest part of the learning curve and emacs is starting to become enjoyable to use. If I learn elisp it will be a gradual thing done on an as needed basis and I feel like I am now into the slow customisation phase that will slowly boost my productivity.

Do I code faster in emacs? Saying yes would be nice but I don't honestly know. I suspect coding JavaScript in eclipse or some other ide would be just as fast but I can't be sure as a lot of productivity is subjective. At the moment nothing gets in my way when using emacs and it is fun to use, I don't mind firing it up late at night when I am tired and that helps.

Coding using emacs and JavaScript is so distant from what I do at work it just feels like fun. Hopefully as my JavaScript code grows in size my skills in emacs will also grow to accommodate the added complexity.

No comments:

Post a Comment