Wednesday, April 13, 2011

11 Concepts The Emacs Newbie Should Master

A friend of mine asked me for some links/suggestions for learning Emacs. While, I was naturally excited that another soul was interested in the emacs religion, I do appreciate the awfully high learning curve involved. It's been years since I sat in a University at Buffalo CS113 class getting schooled on how emacs worked.

To help him get started, though, I've compiled the following 10 links into emacswiki.org - a site that consistently shows up first when I search for all things emacs. I've tried to focus this list on some core concepts that I absolutely rely on. Many of these aren't sexy topics, but emacs has never been about flashiness - it's about editing text quickly and never having to take your hands off the keyboard.*

  1. Killing & Yanking - emacs doesn't do copy and paste. Emacs does killing and yanking. While there may not appear to be much difference when you start learning emacs at first, you soon appreciate the value of the kill-ring - which allows you to get back to previously copied text. Once you get hooked on it, you're hooked for life.
  2. Buffer switching - First rule of emacs: don't quit. Or, more specifically, don't shut it down. That is, you should have hundreds of files open (each in their own buffer) and using the various buffer switching techniques should be able to get to any of them within a few keystrokes.
  3. Dynamic Abbreviations - Emacs is all about saving keystrokes with various forms of completion. Dynamic abbreviations are one especially cool technique because they allow you to auto complete on any text you've written in the past and have currently open. It makes writing variables, function names and other repeated text a breeze.
  4. Parenthese Modes - Emacs is programmable via lisp, and lisp is all about parenthesis. So, it's no surprise emacs has a number of packages for dealing with them. Pick one, use it, and never get confused about which (, { or [ you're matching up against.
  5. Spell Checking - one of the features I miss most when I'm not using emacs is spell checking capability. Besides making your comments more understandable to the world, spell checking means that your variables will actually match up to the word you intended.
  6. Undo - like the Killing and Yanking above, the undo capability of emacs is like other editors, but on steroids. Take the time to learn it, and you'll be make and unmaking changes at light speed.
  7. Narrowing - emacs allows you to hide part of a buffer (one form of this known as narrowing) with ease. I find this facility to be essential when I'm trying to wrap my head around new (and very ugly) code.
  8. Incremental Search - once you get used to the speed and convenience of isearch you'll never want to search any other way again. Emacs actually has quite a long list of search and replace tools.
  9. Keyboard Macros - emacs has a built in macro recorder that I find I use all the time to solve thorny problems in a few seconds. For example, need to convert a line of text into an SQL statement? Just record the action on a single line and then run the macro as many times as you'd like. While I could write the lisp code to do this, I find that recording the macro is much faster.
  10. Dired Mode - Manage files and directories from within emacs? Well, of course. Your goal should be to do everything from within emacs. Turns out, dired really is a fast and efficient way to manage files.
  11. Version Control - one of first killer features for me was the way emacs handled version control commands. It made dealing with RCS totally painless. And the same commands I used so many years ago still work quite well with CVS and subversion. There's also a specific mode for subversion that I use daily to stay efficient.

Once you've mastered the basics, it's time to ponder the emacs lisp list - which provides plenty of add on functionality for emacs.

So, if you were learning emacs today - what topics would you focus on?

*Yes, I know your whiz bang IDE can do all this functionality. Congrats. This list isn't meant to be a: "emacs is better than X list" -- I'll leave that to others to duke out.

13 comments:

  1. This pretty much covers my everyday use. I would add AucTeX for mathematicians, and the fact that you can live within emacs (I tried living in emacs for 30 days). Another interesting addition are skeletons (to dynamic abbreviations) and org-mode.

    Cheers,

    Ruben

    ReplyDelete
  2. An emacs feature I love is the regular expression support. In particular the regex search and replace functions (query-replace-regexp). Great for transforming data files.

    ReplyDelete
  3. mpv, the fact that emacs has the built-in regexp builder is also great for non-regex-gurus like I am: when I want to do some fancy in dired mode, or do some hard-core re-search and replace using it to be sure I'm forming a correct expression is pure awesome.

    Skál,

    Ruben

    ReplyDelete
  4. sateesh8:13 AM

    An emacs feature that I found quite is : split-window. Quite useful when I am editing one file and need to look at other file for some related information.

    ReplyDelete
  5. Shell mode. I almost never launch a cmd shell or xterm equivalent.
    The remote file system aspects of dired-mode. Also dired-dwim-target makes dired a great 'mc' alternative.
    M-x calculator or if you're really motivated: calc.
    And I really need to get better at org-mode. It is impressive but came out long after I'd mastered 90% of emacs and elisp.

    ReplyDelete
  6. Guys -

    Thanks for all the additional suggestions, they're great ones.

    I especially like the comment about calc - I find it to be the fastest way to do the the little math I need to do. And it's go tons of slick features.

    I also got a fair amount of mileage out of the M-x calendar, but these days I'm on Google Calendar.

    ReplyDelete
    Replies
    1. Ben you should checkout calfw. This provides access to your Google Calendar from emacs!
      http://emacswiki.org/emacs-en/Calfw
      https://github.com/kiwanami/emacs-calfw

      Enjoy!

      Delete
  7. You've made the same error as every other editor 'things you must know' list has made--- the first thing that is fundamental to all such lists is 'How do I get out of this thing?' Once past that small speed bump, you account is indeed gravy and well thought out...

    ReplyDelete
  8. @hsm: You've made the same error as every other editor 'things you must know' list has made--- the first thing that is fundamental to all such lists is 'How do I get out of this thing?'

    Easy. You don't ;-).

    But, if for some reason you absolutely need to, I run:

    M-x save-buffers-kill-emacs

    One of the first things I do is override the key combination that exits emacs. There's nothing worse than having hundreds of buffers open and losing your state.

    ReplyDelete
  9. really great post

    In my personal opinion org-mode and, magit are missing

    again great post

    ReplyDelete
  10. agree with Scott re: shell-mode. I'm so used to typing M-p to go back in a shell history (vs. C-p) that having Cmd-P bring up a print dialog in Mac Terminal.app is a major source of annoyance. It's incredibly useful to have kill/yank and dabbrevs across shell and other buffers.

    ReplyDelete
  11. Of course I just happened upon this article, and it'd doesn't surprise me that you wrote it - the man that taught me all I forgot about Emacs!

    ReplyDelete
  12. Thanks Larry!!

    (Could this be Larry W. from UB?)

    ReplyDelete

LinkWithin

Related Posts with Thumbnails