Subject: Re: bug#3862: 23.1.50; error calling `documentation' on calendar-mode

From: Stefan Monnier <[email-masked]>
Date: Wed, 15 Jul 2009 21:40:18 -0400

>     (progn
>       (require 'calendar)
>       (documentation 'calendar-mode))

> gets the error and backtrace below.

The docstring gets passed through substitute-command-keys which can run
arbitrary code via menu-item :filters (as well as via autoloaded
keymaps, actually).

> For what it's worth it works fine from the actual calendar buffer, but I
> was trying in some program code where that wasn't the case.  I hoped I
> could generally get the docs for any function from anywhere.

In the present case, there's a subtle bug in the :filter of the
calendar-mode-map (more specially in the menu-bar part of the map).

> Also incidentally I tried a condition-case around it like

>     (condition-case nil
>         (documentation 'calendar-mode)
>       (error nil))

> and was surprised it still went to the debugger.  But maybe that's a
> separate problem.

Indeed it's a separate problem: when the filter is run, it is presumed
it is "at top level" and so the error gets turned into a backtrace
without paying attention to surrounding condition-cases.  It's clearly
a bug, but it might be delicate to fix without introducing risks of
nasty crashes.

        Stefan