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.


  1. Maybe you can add your version to:

    Comment by yrk — September 15, 2004 @ 3:17 AM | Reply

    • to be honest, I am somewhat apprehensive about even implying my code is “emacs quality”. But it’s certainly the right thing to do, as well as emailing the author and trying to merge my changes into his version. One of these days…

      Comment by mulix — September 19, 2004 @ 12:15 AM | Reply

  2. One of these days, when I stop my strong dislike of emacs, I’ll try out this script.
    Not today though. If I start using emacs now, I’ll never get any work done.

    Comment by the_p0pe — September 15, 2004 @ 8:07 AM | Reply

  3. hello, friend
    I noticed you friended me… did you mention that to me in my LJ comments, somewhere, possibly a long time ago? because I don’t remember it. 🙂
    Anyway, your journal looked quite interesting as well, so I friended you. I was just wondering how you found me in the first place, and what made you friend me.
    — Zach, aka reverius42

    Comment by reverius42 — September 17, 2004 @ 12:52 AM | Reply

    • Re: hello, friend
      Sorry, I don’t recall. We must have some mutual friend of a friend, or maybe I just found you through google? I no longer recall. Anyway, nice to virtually meet you 🙂

      Comment by mulix — September 19, 2004 @ 12:14 AM | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply to mulix Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: