From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Stefan Monnier" Newsgroups: gmane.emacs.devel Subject: Re: building directory Date: Fri, 04 Apr 2003 09:51:06 -0500 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200304041451.h34Ep6QO007292@rum.cs.yale.edu> References: <20030404.171320.107253085.jet@gyve.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1049468694 1795 80.91.224.249 (4 Apr 2003 15:04:54 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 4 Apr 2003 15:04:54 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Fri Apr 04 17:04:52 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 191SkO-0000So-00 for ; Fri, 04 Apr 2003 17:04:52 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 191SmU-0001vs-00 for ; Fri, 04 Apr 2003 17:07:02 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 191Sjx-00033t-08 for emacs-devel@quimby.gnus.org; Fri, 04 Apr 2003 10:04:25 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 191Sim-0002al-00 for emacs-devel@gnu.org; Fri, 04 Apr 2003 10:03:12 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 191Sef-0001cy-00 for emacs-devel@gnu.org; Fri, 04 Apr 2003 09:58:57 -0500 Original-Received: from rum.cs.yale.edu ([128.36.229.169]) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.10.13) id 191SX6-0007zi-00 for emacs-devel@gnu.org; Fri, 04 Apr 2003 09:51:08 -0500 Original-Received: from rum.cs.yale.edu (localhost [127.0.0.1]) by rum.cs.yale.edu (8.12.8/8.12.8) with ESMTP id h34Ep7x6007294; Fri, 4 Apr 2003 09:51:07 -0500 Original-Received: (from monnier@localhost) by rum.cs.yale.edu (8.12.8/8.12.8/Submit) id h34Ep6QO007292; Fri, 4 Apr 2003 09:51:06 -0500 X-Mailer: exmh version 2.4 06/23/2000 with nmh-1.0.4 Original-To: Masatake YAMATO X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:12896 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:12896 > I'd like to prepare an user interface to access emacs C source > files easily. M-x describe-function is very good entry point for > my goal. I'd like that too. And also for built-in variables. I've been using a patch (that I posted to this list a while back) to do what you suggest. There are several different possible approaches to do what you want. You want to be careful about the fact that source files might have been edited since the last build so the source-line info might be off. This means that even if you have the line number, you'll have to search for the right DEFUN, so the line info is not that useful anyway. I think an other approach along the lines of yours would be to simply adjust the initial `load-history'. That would give you the equivalent of `source-file', but using `symbol-file'. It's probably not that different in the end. Although the generalization to built-in variables is more obvious. My patch (see below) simply relies on having TAGS built in the source directory. It's not a bad approach although it's not great either: the main problem is that the etags.el functions make it a bit difficult to locally use a tags table without impacting other uses of tags that might be going on already. Of course the other problem is that it requires TAGS, but I find that it's not a big problem and even has the advantage that it even works in the case where a function is moved from one file to another. Also it does not require any extra information in Emacs, so people who don't use it don't pay anything for it. This is relevant (though maybe not too important) because it is a feature likely to be used only by a small minority of the users. I wanted to fix etags.el so that my patch could be made cleaner, but I haven't gotten to it (mostly because it works well enough for me :-( ). Stefan Index: help-fns.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/help-fns.el,v retrieving revision 1.30 diff -u -r1.30 help-fns.el --- help-fns.el 12 Feb 2003 23:13:43 -0000 1.30 +++ help-fns.el 4 Apr 2003 14:43:23 -0000 @@ -285,9 +286,36 @@ (princ "'") ;; Make a hyperlink to the library. (with-current-buffer standard-output (save-excursion (re-search-backward "`\\([^`']+\\)'" nil t) - (help-xref-button 1 'help-function-def function file-name))))) + (help-xref-button 1 'help-function-def function file-name)))) + ;; If it's a subr, try to make a link to the C source. + ((and (subrp def) (symbolp function) + (file-exists-p (expand-file-name "src/TAGS" source-directory))) + (let ((src-tags-file (expand-file-name "src/TAGS" source-directory)) + (tags-file-name (if (boundp 'tags-file-name) tags-file-name))) + (unless (equal tags-file-name src-tags-file) + (setq tags-file-name nil) + (visit-tags-table src-tags-file)) + (let ((buf (condition-case nil + (save-excursion + (visit-tags-table-buffer) + (find-tag-in-order + (concat "\"" (symbol-name function) "\"") + find-tag-search-function find-tag-tag-order + find-tag-next-line-after-failure-p + "containing" t)) + (error nil)))) + (when buf + (let ((pos (with-current-buffer buf (point)))) + (princ " in `") + (princ (with-current-buffer buf (file-name-nondirectory + buffer-file-name))) + (princ "'") + (with-current-buffer standard-output + (save-excursion + (re-search-backward "`\\([^`']+\\)'" nil t) + (help-xref-button 1 'help-function-def pos buf))))))))) (princ ".") (terpri) (when (commandp function)