From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: master f995fbd: * lisp/server.el (server-name): Add autoload cookie. (Bug#23576) Date: Wed, 25 May 2016 23:01:51 -0400 Message-ID: References: <20160518194708.27363.47377@vcs.savannah.gnu.org> <20160518194708.86FE0220157@vcs.savannah.gnu.org> <834m9u9dis.fsf@gnu.org> <83r3cx8eg2.fsf@gnu.org> <83mvnl894y.fsf@gnu.org> <83lh3583tb.fsf@gnu.org> <83eg8w97kf.fsf@gnu.org> <8337pc8sjc.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1464231742 7876 80.91.229.3 (26 May 2016 03:02:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 26 May 2016 03:02:22 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu May 26 05:02:13 2016 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 1b5lYq-00079l-RV for ged-emacs-devel@m.gmane.org; Thu, 26 May 2016 05:02:13 +0200 Original-Received: from localhost ([::1]:36174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5lYm-00086u-LM for ged-emacs-devel@m.gmane.org; Wed, 25 May 2016 23:02:08 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5lYe-00085S-HF for emacs-devel@gnu.org; Wed, 25 May 2016 23:02:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5lYc-0002Su-1W for emacs-devel@gnu.org; Wed, 25 May 2016 23:01:59 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:24155) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5lYX-0002R2-6K; Wed, 25 May 2016 23:01:53 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0A6FgA731xV/472SC1cgxCEAoVVwD6CTQQCAoE8PBEBAQEBAQEBgQpBBYNdAQEDAVYjBQsLNBIUGA0kiDcIzyMBAQEBAQUBAQEBHos6hDpLB4QtBYtEk1ODa4J+hGGKIyOBZiMBHBWBWSKBNCSBIAEBAQ X-IPAS-Result: A0A6FgA731xV/472SC1cgxCEAoVVwD6CTQQCAoE8PBEBAQEBAQEBgQpBBYNdAQEDAVYjBQsLNBIUGA0kiDcIzyMBAQEBAQUBAQEBHos6hDpLB4QtBYtEk1ODa4J+hGGKIyOBZiMBHBWBWSKBNCSBIAEBAQ X-IronPort-AV: E=Sophos;i="5.13,465,1427774400"; d="scan'208";a="239492061" Original-Received: from 45-72-246-142.cpe.teksavvy.com (HELO pastel.home) ([45.72.246.142]) by ironport2-out.teksavvy.com with ESMTP; 25 May 2016 23:01:51 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 3C24362202; Wed, 25 May 2016 23:01:51 -0400 (EDT) In-Reply-To: <8337pc8sjc.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 20 May 2016 21:59:19 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:204023 Archived-At: > Is that available on master? I just pushed it, yes. > If not, please push, and let's start using this. The code I pushed just populates a new hash table `definition-prefixes'. We still need to change help-fns.el (and various other places) to make use of it. I've used the patch below (which makes `C-h f' use that table during completion), but it's just the temporary result of my experimentation with it: it's fundamentally incorrect and hence needs to be rewritten. Stefan diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 040152a..0f9ab0e 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -43,6 +43,43 @@ help-fns-describe-function-functions ;; Functions +(defun help--load-files (files) + (dolist (file files) + ;; FIXME: this regexp business is not good enough: for file + ;; `toto', it will say `toto' is loaded when in reality it was + ;; just cedet/semantic/toto that has been loaded. + (let ((re (load-history-regexp file)) + (done nil)) + (dolist (x load-history) + (if (string-match re (car x)) (setq done t))) + (maphash (lambda (prefix files) + (when (member file files) + (if (not (cdr files)) + (remhash prefix definition-prefixes) + (puthash prefix (remove file files) + definition-prefixes)))) + definition-prefixes) + (unless done + (load file 'noerror))))) + +(defun help--symbol-completion-table (string pred action) + ;; FIXME: To minimize the size of the definition-prefixes table, + ;; we should/could use the rule that "foo-bar" can likely be found in file + ;; foo.el (or foo-mode.el). + (unless (eq 'lambda action) + (string-match "\\`[^-:/_]*[-:/_]*" string) + (let* ((prefix1 (match-string 0 string)) + (prefixes (all-completions prefix1 definition-prefixes))) + (dolist (prefix (prog1 prefixes (setq prefixes nil))) + (when (string-prefix-p prefix string) + (help--load-files (gethash prefix definition-prefixes)))))) + (let ((prefix-completions + (mapcar #'intern (all-completions string definition-prefixes)))) + (complete-with-action action obarray string + (if pred (lambda (sym) + (or (funcall pred sym) + (memq sym prefix-completions))))))) + (defvar describe-function-orig-buffer nil "Buffer that was current when `describe-function' was invoked. Functions on `help-fns-describe-function-functions' can use this @@ -58,13 +95,14 @@ describe-function (setq val (completing-read (if fn (format "Describe function (default %s): " fn) "Describe function: ") - obarray 'fboundp t nil nil - (and fn (symbol-name fn)))) + #'help--symbol-completion-table + #'fboundp + 'confirm nil nil (and fn (symbol-name fn)))) (list (if (equal val "") fn (intern val))))) (or (and function (symbolp function)) (user-error "You didn't specify a function symbol")) - (or (fboundp function) + (or (help--symbol-function function) (user-error "Symbol's function definition is void: %s" function)) ;; We save describe-function-orig-buffer on the help xref stack, so @@ -299,6 +337,32 @@ find-lisp-object-file-name (src-file (locate-library file-name t nil 'readable))) (and src-file (file-readable-p src-file) src-file)))))) +(defun help--try-load-symbol (sym) + ;; FIXME: Here we use the rule that "foo-bar" can be found in "foo.el", but + ;; we should extend it to include "foo-mode.el", and we should additionally + ;; use `definition-prefixes'. + (let ((name (symbol-name sym))) + (while (not (zerop (length name))) + (let ((file (locate-file name load-path (get-load-suffixes)))) + (if (and file (not (assoc (file-truename file) load-history))) + (progn (load file) (setq name "")) + (setq name + (if (string-match "[-:/][^-:/]*\\'" name) + (substring name 0 (match-beginning 0)) + (message "Cannot find file for symbol %s" sym) + ""))))))) + +(defun help--symbol-function (sym) + "Like `symbol-function' except it may try to load files to find the function." + (or (symbol-function sym) + (progn + ;; The function either doesn't exist or is not loaded yet. + ;; Try to find it. + (help--try-load-symbol sym) + ;; We did find some file to load, but we don't know if it did provide + ;; the function we're looking for. + (symbol-function sym)))) + (defun help-fns--key-bindings (function) (when (commandp function) (let ((pt2 (with-current-buffer standard-output (point))) @@ -329,12 +393,12 @@ help-fns--key-bindings ;; If lots of ordinary text characters run this command, ;; don't mention them one by one. (if (< (length non-modified-keys) 10) - (princ (mapconcat 'key-description keys ", ")) + (princ (mapconcat #'key-description keys ", ")) (dolist (key non-modified-keys) (setq keys (delq key keys))) (if keys (progn - (princ (mapconcat 'key-description keys ", ")) + (princ (mapconcat #'key-description keys ", ")) (princ ", and many ordinary text characters")) (princ "many ordinary text characters")))) (when (or remapped keys non-modified-keys) @@ -509,17 +573,16 @@ describe-function-1 function)) ;; Get the real definition. (def (if (symbolp real-function) - (or (symbol-function real-function) - (signal 'void-function (list real-function))) + (help--symbol-function real-function) real-function)) (aliased (or (symbolp def) ;; Advised & aliased function. (and advised (symbolp real-function)))) (real-def (cond (aliased (let ((f real-function)) - (while (and (fboundp f) - (symbolp (symbol-function f))) - (setq f (symbol-function f))) + (while (and (fboundp f) + (symbolp (symbol-function f))) + (setq f (symbol-function f))) f)) ((subrp def) (intern (subr-name def))) (t def))) @@ -706,7 +769,7 @@ describe-variable (format "Describe variable (default %s): " v) "Describe variable: ") - obarray + #'help--symbol-completion-table (lambda (vv) ;; In case the variable only exists in the buffer ;; the command we switch back to that buffer before