July 26, 2008

Things I can do to make progress on my book

July 26, 2008 - Categories: emacs, wickedcoolemacs, writing

Yet another snippet mode for Emacs

July 26, 2008 - Categories: emacs

While reading gnu.emacs.help, I came across yasnippet (yet another snippet extension for Emacs). It provides interactive templates for text or code entry. It’s similar to SkeletonMode, but with TextMate-type syntax, simpler prompting for information, and more focus on expanding mode-sensitive text in the buffer.

Here’s what I did to get started with it on my system:

  1. Download http://yasnippet.googlecode.com/files/yasnippet-0.5.5.tar.bz2 and unpack it as ~/elisp/snippets.
  2. Download http://yasnippet.googlecode.com/files/yasnippet-bundle-0.5.5.el.tgz and unpack it as ~/elisp/yasnippet-bundle.el .
  3. Symlink lisp-interaction-mode to emacs-lisp-mode with the command
    ln -s ~/elisp/snippets/emacs-lisp-mode ~/elisp/snippets/lisp-interaction-mode
    
  4. Add the following lines to ~/.emacs
    (require 'yasnippet-bundle)
    (yas/initialize)
    (yas/load-directory "~/elisp/snippets")
    ;; I don't like using partial words for completion
    (setq yas/key-syntaxes '("w_" "w_." "^ "))
    

So far, so good. M-x yas/minor-mode lets me use TAB as the completion key, and I can use TAB and S-TAB to navigate between the fields of a snippet as well. I think it’s a decent snippets mode if you don’t need the complexity of skeleton.el.

After some experimentation, I see how this might make me even happier working on Drupal. I’ve put together this first try at a template for Drupal modules. Drupal code has a lot of repetitive typing and/or search-and-replacing because all the hook functions need to start with the module name. With yasnippet, I can type in the module name once, and all the other functions will be updated. I often find myself looking up the argument lists for the hook functions, too, and the template includes the hooks I tend to use. I think this snippet will save me a lot of start-up time.

You know what would be even cooler? If I could create snippets that dynamically calculate values using Emacs Lisp. Then I could create, for example, a hook_user abbreviation that automatically picked up the module name from the filename or from the other functions. Wouldn’t that be cool?

UPDATE: Putting Emacs Lisp in templates is awesome. With this function in my ~/.emacs:

(defun sacha/drupal-module-name ()
  "Return the Drupal module name for .module and .install files."
  (file-name-sans-extension (file-name-nondirectory (buffer-file-name))))

I can make templates like this one for hook_user. Sweet!

Want to subscribe to a subset of my blog?

July 26, 2008 - Categories: blogging

I write a lot about Emacs. I also write a fair bit about Drupal. Both are rather geeky topics that may not interest you, or they might be the only things you want to read about. If all the posts you want to read fall into a specific category (example: emacs, drupal, sketches), you go to the category page and subscribe to just that category in your feed reader. If you want to exclude posts in a specific category, here are six ways to filter RSS feeds. Try out http://www.feedrinse.com.

I might occasionally go into firehose-mode, but at least you’ve got a way to control it! =)

Emacs is not just for computer geeks; also, these are the things that keep me going

July 26, 2008 - Categories: emacs, goodkarma

Reposted with permission because (a) it shows that people who aren’t computer geeks can also love Emacs, and (b) it gave me a warm and fuzzy feeling and encouraged me to keep writing, so I want to keep it around just in case I get in a rut again.

Sacha,

I’m an emacs newbie who’s trying to both simplify and empower my computing life, and I’ve chosen emacs as the tool to do that. I’m pretty excited about that, and overwhelmed, too.

Actually, a little background might help: I’m a PhD student in early modern (read: renaissance) English literature. Yeah, I’m a Shakespeare guy. I work in a field in which computers are, to most folks, MS Word, MS Entourage, and MS Explorer. I’m a nut who actually plays with stuff. (Actually, I don’t tell my colleagues about it. It could honestly damage my career. I know, it’s disturbing.) I also have some tech chops, being a refugee from the heady late 1990s tech boom where I co-founded a small company that made some money before it collapsed. I’ve been able to do the basics in emacs for years. The basics, but nothing more.

My introduction this time was a rather circuitous route: I moved from Mellel (on the Mac), to Scrivener where I discovered the wonders of MultiMarkdown. Happily I discovered that I could use MMD and TextMate to create LaTeX files without having to look at a bunch of distracting LaTeX markup. I could write plain text and, with a couple of handy keystrokes, create beautiful PDF files that my committee would appreciate. The plain text files took up no space and could be edited anywhere. I could fit a bazillion of them on my USB drive and carry loads of research with me to my office on campus (where I got a hand-me-down Dell running XP v.e.r.y.s.l.o.w.l.y) and on my much speedier Mac at home and even in Linux. Neat. Still, MMD felt hack-y and was only supported by one guy and I wondered if there was anything else like it out there.

Which lead me to muse-mode. From there you can guess my path of discovery: org-mode, planner-mode, remember: oh my!

For a prose writer like myself, the ability to have the cursor jump forward and backward by letter, word, line, and paragraph was nothing new, but M-a and M-e have changed my life. Why don’t all word/text processors understand that the sentence is the fundamental unit of prose writing? Why don’t they all allow me to navigate using units that make logical sense?

Whoever said that emacs was for programmers only surely isn’t a writer.

(This is becoming much longer than I had anticipated, sorry.) My point in writing is to tell you how invaluable I have found your two public chapters (I think they’re 7 and 8) have been for me. The whole idea of writing a book about emacs as cool (as opposed to just highly functional) is both obvious and revolutionary. Know that I would buy a copy today if only it were available.

I noticed in your blog that you felt you had lost some steam on the book. Please don’t. My life is better, my writing is better, my research is better, and, much to the joy of my wife, my progress toward a completed PhD is better, all thanks to emacs which, based on the tools I’m using, is also in thanks to you.

So thank you, and keep writing. I, for one, and hungry for more. I’m sure others are, too.

Jeffrey Windsor