Saturday, July 06, 2002


Jarno blogged a vintage Tim Peters quote about functional languages (oh well, apparently his archives are broken, as per Blogger usual — the article I'm talking about isn't there.) This reminded me of a post in comp.lang.lisp I saw last year, I believe. However, I was unable to find it with Google Groups, so I'll have to resort to paraphrasing. Someone was asking what are functional languages, or something like that, and the reply was:

"There are two kinds of languages, just like relationships: functional and non-functional."

And while I don't do Haskell and I'm no big fan of functional purity, I have to admit I believe there's truth in that. I'm sure (or at least I hope) timbot would agree that popularity contests aren't the best way to measure the usefulness of language features.

Friday, July 05, 2002

More Emacs

As a follow-up to my note about using manual indentation in sgml buffers, here's how to make backspace behave the way it should: delete backward if there's a character to delete, unindent otherwise. This time in a code element, too :-)

(defun delete-backward-or-unindent-tab-stop ()
(let ((saved-pos (point)))
(if (save-excursion
(block 'look-for-ws
(let ((tmp-pos (point)))
(when (= saved-pos tmp-pos)
(return-from 'look-for-ws t))
(while (< tmp-pos saved-pos)
(when (not (memq (char-after tmp-pos) '(?\t ?\ )))
(return-from 'look-for-ws t))
(incf tmp-pos)))
(delete-region (point) saved-pos))))

(define-key sgml-mode-map [backspace] 'delete-backward-or-unindent-tab-stop)

This has been tested only minimally.

Makes me wonder, though, how much of this could have been done without coding elisp — I wouldn't be surprised if I found out there was, after all, already support for all this, somewhere.

Whee - putting the code in a pre totally overflows it out of my layout. Oh well.


So the first version was broken. I warned you. Minimal testing still applies :-)

Wednesday, July 03, 2002

Respect and a me2

John Wiseman has discovered Automator's hip-hop too. The strange, futuristic albums Dan the Automator has done with a cohort of other people absolutely rock and are definitely worth checking out — they aren't quite mainstream hip-hop (although Gorillaz is, by definition, mainstream something, being as popular as it is) and are all the more interesting because of that.

Tuesday, July 02, 2002

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.

Monday, July 01, 2002

Hot launchers in drag

I've been bitten a few times by this: I have in my GNOME panel a bunch of launchers. I open a directory in Nautilus, try to drag and drop a file on a launcher, get the application started without any files open. Duh.

I finally got annoyed, tried to edit the properties of a launcher, hit Help, didn't find any mention of this, tried Google, no luck, tried GNOME Bugzilla, and finally got lucky: via #75470, List of valid Exec parameter variables. Hooray.