Emacs tip for the day
It's nice when your editor does the indenting of code for you. It's definitely not nice when your editor tries to do the indenting, but screws it up. Sometimes it doesn't have much of a chance; html-mode, psgml-mode or whatever in Emacs is nice for editing Zope DTML documents — yeah I know, I should get on the DPT wagon — but, not surprisingly, it fails pretty miserably with indenting.
So it's time to go for manual indenting instead. For editing things consisting of blocks, like code, Vi-like indentation where you stay on the indentation level you have set until you insert/remove indentation is much nicer than having to indent separately every line. Me being an Emacs boy, however, I'm not going to switch to using GVim, even if it is very nice. So we need to make Emacs behave sanely.
First: tab needs to be bound to tab-to-tab-stop. Easy enough. Second: how to de-indent? Um, er, hey, there's no function to move back a tab stop? This seems to be really well thought out. Google groups help here:
Re: tab-to-tab-stop /backwards/. Finally, how to make Emacs stay on the specified indentation level? The functions indent-relatively-maybe and newline-and-indent, plus the variable indent-line-function are your friends here. Something along these lines in .emacs more or less does the job:
(add-hook 'sgml-mode-hook
(function (lambda ()
(setq indent-line-function 'indent-relative-maybe))))
(define-key sgml-mode-map [tab] 'tab-to-tab-stop)
(define-key sgml-mode-map [(shift tab)] 'backward-move-to-tab-stop)
(define-key sgml-mode-map [return] 'newline-and-indent)
This modifies the keyboard mappings in all the sgml-mode buffers, not just those editing DTML. To avoid this, a separate major mode would have to be defined.
Un-indent is bound to shift-tab which is a bit dodgy, too; it really should work with backspace.