Muli Ben-Yehuda's journal

September 15, 2004

todoo.el 1.6

Filed under: Uncategorized — Muli Ben-Yehuda @ 10:19 AM

New todoo.el is up.

One conceptual problem that I’ve been struggling with wrt todoo.el is how to properly save the folding state whenever it changes. The problem is that changing the folding state does not make emacs think the buffer has been modified, so emacs will happily let you close it without saving. What I did at first was hook into todoo’s “save and exit” function, which is fine if you hit ‘todoo-save-and-exit’. But what happens if you just hit ‘kill-buffer’? lossage. So then I hooked into ‘kill-buffer-hook’, which fixed the ‘kill-buffer’ case. But what happens if you hit ‘save-buffers-kill-emacs’? again, lossage.

Last night the correct solution hit me in the face. If the problem is that changing the folding state does not cause the buffer to be modified – fix that. Just call (set-buffer-modified-p t) wherever we change the folding state. Did that, it works. Yay 馃檪

But this is only half of the solution. The second half is saving the metadata whenever you save the data. ‘save-buffer’ has several hooks, including ‘after-save-hook’. Trying to get it to work led to some interesting effects, because my ‘after-save-hook’ called a function that ended up saving a buffer, which called ‘after-save-hook’, which called my function, etc, etc, ad infinitum. Fixing that was pretty simple – just nil the hook in the lexical scope of my function so that it does not get called again.

Then I hit another bug, that apparently existed since the first day. My code to serialize the folding state into the metadata buffer changed the location of the cursor on the screen. I never saw it, because the buffer was always destroyed after saving the metadata previously. Now that I saved the metadata on every save, it was very visible and annoying. I wrapped it in ‘save-excursion’ – no change. I saved and restored the point manually – no change. After some minutes of head scratching and debugging, the culprit ended up being a call to ‘end-of-buffer’, which effects the scrolling status of the buffer. Well, duh! the help for ‘end-of-buffer’ even says “Don’t use this command in Lisp programs! (goto-char (point-max)) is faster and avoids clobbering the mark.” And that works like a charm…

Ergo – todoo.el 1.6.

listening to music with my new headphones is such a joy

Filed under: Uncategorized — Muli Ben-Yehuda @ 9:48 AM

Currently listening to Rage Against The Machine’s “Know Your Enemy”, and the base is just amazing. Thank you for the headphones, ladypine!.

Blog at