Keeping what I need to know at finger’s length

I’ve been trying to cram in so much information so quickly, I’m starting (hah!) to realize that it’s not all sticking.

So, what better tool to use than Emacs to solve my problem with not remembering Emacs commands?

My solution is simple—create a cheat-sheet. The great thing about Emacs is that this doesn’t have to be a piece of paper, it can be a file that I can maintain in org-mode, just like this blog. In fact, I can also maintain it as a page on the blog. And with the most trivial bit of elisp, I can make sure that I can get to it with no more than two easy-to-remember keystrokes:

(define-key global-map [?\C-h ?\C-h]
  '(lambda ()
     (interactive)
     (view-file "~/org/doyouevenlisp.com/cheatsheet.org")))

The joy of an integrated environment

Most of my GNU Emacs learning time has continued to be spent writing elisp. I am very slowly starting to retrain myself on a couple of basic keystrokes: M-g M-g (goto-line) and M-% (query-replace) are two biggies, because my use of ido-ubquitous mode actually means that my default use of M-x to get to both of those is disrupted—the minibuffer no longer autocompletes in the same way, so if I’m going to have to relearn how to get to them, I should really re-learn the short versions.

Anyway, I did want to take a moment to sing the praises of the GNU Emacs Help facility, because it has been invaluable. Specifically C-h f (describe-function) and C-h v (describe-variable). While the help they give is necessarily brief, it’s often enough for someone like me, who just needs a gentle prod about something now and again. I even used C-h f to look up the documentation for if a few minutes ago, because I couldn’t remember if you had to do progn to do a multi-statement else block.

So that’s it for today. Learn the rich set of commands that let you get right to what you need in the documentation—it will be invaluable for exploring emacs.

Weekly Wrap-Up #3

So this is the two-days-late Weekly Wrap-Up #3. I spent the last two days doing my first real batch of elisp hacking of any significance, so I don’t feel too bad about missing the normal rhythm of things.

My big winner for this week is C-M-@ (mark-sexp), which made several moments in elisp hacking bearable—there’s inevitably a moment in any lisp code where the right parens start to pile up, and good luck with trying to figure out what to mark by hand.

I’m still not habituated to using TRAMP for editing files using sudo or ssh, which is unfortunate since I do that a lot. And the mark ring stuff still eludes me.

I think this week I’m going to take on registers and rectangles, and perhaps start building up a cheat-sheet I can use to keep the things I’ve discovered a little more present.

Refining org2blog

No updates to be made, because I spent the entire day working on org2blog. I actually kinda liked it. A lot.

I’ve now rewritten the XML-RPC back-end to use the new, documented, WordPress API. Right at the moment, this is just running-in-place, but I hope to use the new code to simplifying things more.

No Weekly Wrapup today

Instead, I spent the time I would normally allocate to writing something for “Do you even lisp?” to enhancing org2blog, the software I’m using to manage this blog.

Well, enhancing might be saying a lot—since I’ve been doing a little WordPress hacking in other contexts, I’ve become aware of WordPress’ new (released with 3.4, so only six months old at this time) “native” XML-RPC API, and I chose to start moving org2blog to use that, and move it away from the hodge-podge of Blogger and MoveableType and metaWeblog APIs that are currently in use.

I hope that over time this will simplify the API, and perhaps result in even better possibilities for interaction—it would, of course, also be great if we could start to abstract away the specifics of a blog’s back-end requirements into a well-defined API so we could easily use whatever is the most featureful back-end for a given blog.

Others might see if differently; we’ll know when I start sending in merge requests.

I also want to automate the process of storing local copies of articles in a hierarchy that mirrors their permalinks and a couple of other things. That I’m also effectively learning elisp at the same time will make all of that very interesting.

One ring to rule them all

I suppose I might have once read that GNU Emacs had a mark ring—that is, a capped collection of marked locations in the current buffer. But I’ve never really thought about it.

I can see a lot of possibilities in the idea, though—it’s implicitly a list of nominally important spots in the buffer, so of course it has the possibility of being useful.

There are two commands that have a lot of potential. Both are variations on C-SPC (set-mark-command).

The first is simply C-SPC C-SPC—that is, set-mark-command applied twice. The first time sets mark and activates it, the second deactivates it so any further motion won’t start establishing a region.

Having set the mark, you can next use C-u C-SPC, which is simply applying the universal argument to set-mark-command. This will start cycling back through the mark ring, with each invocation moving further back.

This may just be something I have to use repeatedly even when I don’t need to, to start finding situations where it will truly be helpful.

Building blocks

The two tasks I do most in Emacs (which are two of the three tasks I do most at the computer) are read email and write programs.

I probably spend far more of my time in those tasks editing than I ever do writing—that is, I may write a first draft of a paragraph in an email, or a function in a program, in five minutes, and then spend fifteen getting it right.

A large part of that process will involve moving stuff around, sometimes in large chunks—because the flow of a program or a document isn’t just about one sentence coming after the other, but about how the ideas embodied in whatever you’re writing flow through the entire construct. If you don’t edit your emails and programs a lot, if you don’t spend more time in the refinement than the first draft then, well…I don’t know if I want to read your emails or source code.

Anyway, it’s important to me to be able to cut and paste stuff efficiently, and, again, this is one of those things where my knowledge isn’t as comprehensive as I would like. I’ve known about C-x h (mark-whole-buffer) for roughly forever, but that’s about it besides the normal set-mark-and-move behavior. I’ve got a bunch of new things to work with now.

M-@ (mark-word) is one I hope to get down pretty quickly. To have the cursor stay where it is, but have the region extend itself quickly should make a lot of email-y sorts of tasks much simpler.

Similarly, M-h (mark-paragraph) will be a nice addition to the toolbox when writing emails, or when writing things like blog posts—I often decide to reorder stuff on a paragraph-by-paragraph basis to help the flow of my ideas.

I don’t know how much use I’ll get out of C-M-@ (mark-sexp) in the short term. I will try to remember it when I’m working with lisp, but honestly, I don’t do so much of that, at least not yet—I have ambitions. So perhaps it will come in handy.

C-x C-p (mark-page) probably isn’t going to see a lot of use from me—I don’t use the whole ^L-delimited pages thing at all, really.

C-M-h (mark-defun) has some potential. As long as its implementation is up to snuff with regards to CPerl or Haskell modes—that is, in those modes, it has a sensible idea of what constitutes a function definition—I could see myself finding a lot of use for these things.

Do it again (again)

Q: How did I not know about this? A: You never read the manual.

(A close friend of mine from college with whom I’ve worked professionally now and again, once suggested that the secret to our individual successes was that we were the ones willing to read the manuals. Obviously in this instance I failed.)

Oh, good lord, the number of times I’ve done M-x UP RETURN RETURN to re-do query-replace on a new buffer, when I could have just done C-x ESC ESC (repeat-complex-command).

Yeah, I realize that it’s really only one fewer keystroke, but I can do that set of keys more efficiently. And I suspect that if I’m paying attention, I will find that I have far more opportunities to use it than just speeding up search and replace operations.

Of course, M-x list-command-history is a great complement to it, to see what you have done recently. It will be interesting to play with—I was honestly surprised at the contents when I tried it just now.

Banging out the HTML

I suspect I heard about the Emacs zencoding mode from its (I believe) original author, Chris Done—he did a screencast about using Emacs for Haskell development that I found interesting, and I imagine that I found a reference while looking at his material about that.

Anyway, I created a Debian package for it, and installed it…and didn’t use it for squat. Although the idea makes great sense—use a CSS-selector like language to create HTML (an idea I was first exposed to with Kris Zyp’s put-selector JavaScript library)—I never even bothered to learn the keystroke to activate it.

Now, however, is the time—I’m doing some HTML writing these days, so I thought I’d go back and start learning it.

So, the magic keystroke is C-j (zencoding-expand-line) or C-RETURN. The language…well, I will probably have to refer back to the cheat-sheet on the github page now and again—it’s like CSS, without entirely being CSS—but I expect it will take a lot of the really repetitive boilerplate out of writing HTML for me.

In which I humble myself terribly…

This is how poor a user of Emacs I am: I still habitually use C-@ (set-mark-command) to set the mark. I mean, on what planet is that easier or more ergonomic than C-SPC (set-mark-command)?

I actually started retraining myself to use C-SPC a while ago, and it’s mostly taken—but I still occasionally catch myself going for that awkward pinky-thumb-middle-finger chord that fires C-@.

More interesting for me to learn how to use effectively is C-x C-x (exchange-point-and-mark). I know I spend a lot of unnecessary time scrolling around the screen rather than targetting where I want to go. Internalizing C-x C-x is, I think, the first step in moving a little faster.

But there are other tools, as well.