emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Loading when viewing docstring of autoloaded function


From: Chong Yidong
Subject: Loading when viewing docstring of autoloaded function
Date: Sat, 23 Jun 2012 17:44:10 +0800

It's a long-standing problem that documentation viewed with C-h * might
not make much sense if it refers to stuff defined in a library that has
not yet been loaded.

The most annoying aspect is that autoloaded functions often have
docstrings containing key substitution constructs, which are expanded
into `M-x FOO' because the relevant keymaps are not yet defined.  I'd
like to suggest a simple workaround: if an autoloaded function contains
key substitution constructs, just outright load the library where it was
defined.  There's not much point in being conservative about loading
libraries, since it is so fast nowadays.  See attached patch.

Alternatively, we could introduce a full-blown solution by adding a new
docstring substitution construct to invoke library loading, but I'm not
sure we need that.

Opinions?


=== modified file 'lisp/help-fns.el'
*** lisp/help-fns.el    2012-06-11 20:35:00 +0000
--- lisp/help-fns.el    2012-06-23 07:15:55 +0000
***************
*** 534,541 ****
        (let* ((advertised (gethash def advertised-signature-table t))
             (arglist (if (listp advertised)
                          advertised (help-function-arglist def)))
!            (doc (condition-case err (documentation function)
!                     (error (format "No Doc! %S" err))))
             (usage (help-split-fundoc doc function)))
        (with-current-buffer standard-output
          ;; If definition is a keymap, skip arglist note.
--- 534,550 ----
        (let* ((advertised (gethash def advertised-signature-table t))
             (arglist (if (listp advertised)
                          advertised (help-function-arglist def)))
!            (doc-raw (condition-case err
!                         (documentation function t)
!                       (error (format "No Doc! %S" err))))
!            ;; If the function is autoloaded, and its docstring has
!            ;; key substitution constructs, load the library.
!            (doc (progn
!                   (and (eq (car-safe def) 'autoload)
!                        (string-match "\\([^\\]=\\|[^=]\\|\\`\\)\\\\[[{<]"
!                                      doc-raw)
!                        (load (cadr def) t))
!                   (substitute-command-keys doc-raw)))
             (usage (help-split-fundoc doc function)))
        (with-current-buffer standard-output
          ;; If definition is a keymap, skip arglist note.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]