So yesterday, I was going to do an essentials type post, listing all the software that I couldn’t really function without. First up on my list, of course, is xemacs, but writing that made me feel guilty about the fact that I’ve been neglecting mt.el, choosing instead to go through the web interface for posting to mt. Mostly this was because I hadn’t yet adapted it to set the text filter on posts, and I really like textile 2. So, I figured I’d dig in and get that working. Couple hours, tops.
Well.
First problem: I’d neglected things long enough that my lisp knowledge was once again on the oh-that’s-the-language-with-parens level, so I mucked about for a while getting my bearings. Once things like:
(let ((form `(lambda (limit) (let ((start (point))) (save-restriction (widen)
no longer looked completely bizarre to me, I started digging. First off, some upgrade of xml-rpc.el or xml.el or something had caused blank excerpt and extended entries to be set to 0. Replacing '0 with "" in the appropriate functions fixed this.
Having made this change, I quickly run GNU emacs to see if everything works ok there. It doesn’t, but for what appears to be a completely different reason: (concat "foo" 2) no longer works in emacs 21; you have to do concat "foo" (number-to-string 2)). Making this change breaks mt.el in xemacs.
Time passes…
Ultimately, the problem is that I’ve been storing the weblog-id as a string, but somehow in emacs it’s seen as an integer (or I do something that causes this, I dunno. At this point it’s a bit of a blur, honestly.) The solution: store it as an integer, so I can reliably do number-to-string whenever using weblog-id.
(For those still paying attention, all this work has gotten me to the point where I can start adding the functionality I originally opened the file to work on. I don’t call it Deft Code for nothin’, baby.)
I get setting text filter working without too much trouble, but immediately run into another issue: autofill and textile do not get along too well. For non-emacs users out there: autofill is what wraps lines in a paragraph, it basically takes long lines and breaks them with newlines at the appropriate place. The problem is that textile converts single newlines to <br />. So, I need an unfill function. After a bit of hacking about, I’ve got one that isn’t too cringeworthy (i.e., doesn’t rely on regular expressions). I have things re-autofilled when they’re returned, and all is well: things look right on the website, and things look the way I want them to in an emacs buffer.
But.
In textile, you define lists with successive lines beginning with either # (ordered) or * (unordered). However, when unfilling lines, emacs sees:
# one # two # three
and assumes what you want is:
# one # two #three
This, needless to say, is not what I want. Much manual digging later, I figure out that I can tell emacs that lines beginning with * or # indicate the beginning of a paragraph. This is tantalizingly close to what I want, but now when the content of a post is brought back, this:
# This is a really long line that wraps, so it should be all part of one bullet point .
is being autofilled into:
# This is a really long line that wraps, so it should be all part of # one bullet point
Which just will not do at all. The reason that this is happening is that emacs fill mode is CLEVER, and treats certain characters as a fill-prefix which should be used to begin each line. This is excellent if you’re wanting to quote a long line for an email with >, but not so nifty for me. It is possible, however, to turn this off locally in my fill-paragraph function with the magic incantation of let ((adaptive-fill-mode nil)).
At which point I begin to write this post, whereupon I realize halfway through that a few other things will likely break upon submission. Let’s find out…
Update: not too bad, but I think I still have a lot of work to do on handling block sections. I was hoping I wasn’t going to have to write my own fill-paragraph function, but…
For the time being though, I think it’s good enough for the textile functionality I make use of regularly. The funny part is that the only reason I’m having to do any of this is because I don’t want to turn off auto-fill in emacs.
Posted by Bill Stilwell at May 3, 2004 09:16 PM