From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Loading when viewing docstring of autoloaded function Date: Sat, 23 Jun 2012 17:44:10 +0800 Message-ID: <87395mgy6t.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1340444663 17365 80.91.229.3 (23 Jun 2012 09:44:23 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 23 Jun 2012 09:44:23 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 23 11:44:23 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SiMtD-0005xc-34 for ged-emacs-devel@m.gmane.org; Sat, 23 Jun 2012 11:44:23 +0200 Original-Received: from localhost ([::1]:52721 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SiMtD-0004WR-4O for ged-emacs-devel@m.gmane.org; Sat, 23 Jun 2012 05:44:23 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:39554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SiMtA-0004WD-BU for emacs-devel@gnu.org; Sat, 23 Jun 2012 05:44:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SiMt8-0005Xu-Ku for emacs-devel@gnu.org; Sat, 23 Jun 2012 05:44:19 -0400 Original-Received: from fencepost.gnu.org ([208.118.235.10]:50069) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SiMt8-0005Xq-HU for emacs-devel@gnu.org; Sat, 23 Jun 2012 05:44:18 -0400 Original-Received: from cm162.gamma80.maxonline.com.sg ([202.156.80.162]:45747 helo=ulysses) by fencepost.gnu.org with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1SiMt6-0007bj-VA for emacs-devel@gnu.org; Sat, 23 Jun 2012 05:44:17 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 208.118.235.10 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:151106 Archived-At: 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.