From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Liu Newsgroups: gmane.emacs.bugs Subject: bug#15641: 24.3; [PATCH] Add find-definition for M-. Date: Fri, 18 Oct 2013 15:33:41 +0800 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1382081721 13311 80.91.229.3 (18 Oct 2013 07:35:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 18 Oct 2013 07:35:21 +0000 (UTC) To: 15641@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Oct 18 09:35:24 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1VX4ai-0004YB-2i for geb-bug-gnu-emacs@m.gmane.org; Fri, 18 Oct 2013 09:35:24 +0200 Original-Received: from localhost ([::1]:56132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VX4ah-0007Nw-Bv for geb-bug-gnu-emacs@m.gmane.org; Fri, 18 Oct 2013 03:35:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VX4aW-0007Nh-MZ for bug-gnu-emacs@gnu.org; Fri, 18 Oct 2013 03:35:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VX4aO-000131-8s for bug-gnu-emacs@gnu.org; Fri, 18 Oct 2013 03:35:12 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:42356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VX4aO-00012M-5y for bug-gnu-emacs@gnu.org; Fri, 18 Oct 2013 03:35:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VX4aN-000375-8J; Fri, 18 Oct 2013 03:35:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Leo Liu Original-Sender: "Debbugs-submit" Resent-CC: monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Fri, 18 Oct 2013 07:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 15641 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Stefan Monnier Original-Received: via spool by submit@debbugs.gnu.org id=B.138208166511908 (code B ref -1); Fri, 18 Oct 2013 07:35:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Oct 2013 07:34:25 +0000 Original-Received: from localhost ([127.0.0.1]:56375 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VX4Zj-00035z-UI for submit@debbugs.gnu.org; Fri, 18 Oct 2013 03:34:24 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36322) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VX4Zg-00035i-KM for submit@debbugs.gnu.org; Fri, 18 Oct 2013 03:34:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VX4ZS-0000jm-R1 for submit@debbugs.gnu.org; Fri, 18 Oct 2013 03:34:15 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:35356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VX4ZS-0000jf-Nd for submit@debbugs.gnu.org; Fri, 18 Oct 2013 03:34:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VX4ZK-0007Ez-87 for bug-gnu-emacs@gnu.org; Fri, 18 Oct 2013 03:34:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VX4ZB-0000f7-RD for bug-gnu-emacs@gnu.org; Fri, 18 Oct 2013 03:33:58 -0400 Original-Received: from mail-pb0-x232.google.com ([2607:f8b0:400e:c01::232]:48713) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VX4ZB-0000ez-GD for bug-gnu-emacs@gnu.org; Fri, 18 Oct 2013 03:33:49 -0400 Original-Received: by mail-pb0-f50.google.com with SMTP id uo15so2025145pbc.23 for ; Fri, 18 Oct 2013 00:33:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:mime-version:content-type; bh=QBOgVIZkMu8SXnt72D8qCFMhz2PTPg2XZf7KAA0voc0=; b=VSQEz4GdFrZHEIjQgWKO2cxSwWMe6Xu7STb+gHW8nPBY/NfukA43eFkC1/kuXdDe95 B9tz+S3jR84rBlQhfG+uL5Tge4L3PTUoI9n4CYtaym7KFuW4fuunscxsRrtk2ZHM6gqP wlDNL+yP6v1yKIfKadH7xkVJODQVRxDYEyz7FcvlGIXXuEd1MGaON4ZyPnmzHTtqLBwl G6K7KiUT/urLNLpbE7PJfl822T8qSkeUrq/+A601upHz0Cl8XC+WxCA743Rm5a8eCtG+ yAej1GaUAaO3sK7jcq3FKxwcs/dj3VV0VviENb3KOKGGrcE/Ieghjvkq0UkqbyFr3teY m5cg== X-Received: by 10.68.135.132 with SMTP id ps4mr1576479pbb.171.1382081627513; Fri, 18 Oct 2013 00:33:47 -0700 (PDT) Original-Received: from localhost ([61.149.217.126]) by mx.google.com with ESMTPSA id pu5sm2176067pac.21.2013.10.18.00.33.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Oct 2013 00:33:46 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:79356 Archived-At: --=-=-= Content-Type: text/plain I think we should just make M-. work on elisp-related places such as lisp-interaction-mode, emacs-lisp-mode, eval-expression and even help-mode. I haven't added the key binding but the function is as in the patch. Comments? --=-=-= Content-Type: text/x-patch Content-Disposition: inline Content-Description: find-func.diff === modified file 'lisp/emacs-lisp/find-func.el' --- lisp/emacs-lisp/find-func.el 2013-01-01 09:11:05 +0000 +++ lisp/emacs-lisp/find-func.el 2013-10-18 07:26:27 +0000 @@ -1,4 +1,4 @@ -;;; find-func.el --- find the definition of the Emacs Lisp function near point +;;; find-func.el --- find the definition of the Emacs Lisp function near point -*- lexical-binding: t; -*- ;; Copyright (C) 1997, 1999, 2001-2013 Free Software Foundation, Inc. @@ -138,8 +138,10 @@ (defun find-library-suffixes () (let ((suffixes nil)) - (dolist (suffix (get-load-suffixes) (nreverse suffixes)) - (unless (string-match "elc" suffix) (push suffix suffixes))))) + (dolist (suffix (get-load-suffixes) ) + (unless (string-match "elc" suffix) + (push suffix suffixes))) + (nreverse suffixes))) (defun find-library--load-name (library) (let ((name library)) @@ -392,12 +394,11 @@ Set mark before moving, if the buffer already existed." (let* ((orig-point (point)) - (orig-buf (window-buffer)) - (orig-buffers (buffer-list)) - (buffer-point (save-excursion - (find-definition-noselect symbol type))) - (new-buf (car buffer-point)) - (new-point (cdr buffer-point))) + (orig-buffers (buffer-list)) + (buffer-point (save-excursion + (find-definition-noselect symbol type))) + (new-buf (car buffer-point)) + (new-point (cdr buffer-point))) (when buffer-point (when (memq new-buf orig-buffers) (push-mark orig-point)) @@ -490,16 +491,16 @@ (defun find-definition-noselect (symbol type &optional file) "Return a pair `(BUFFER . POINT)' pointing to the definition of SYMBOL. If the definition can't be found in the buffer, return (BUFFER). -TYPE says what type of definition: nil for a function, `defvar' for a -variable, `defface' for a face. This function does not switch to the -buffer nor display it. +TYPE says what type of definition: nil or `defun' for a function, +`defvar' for a variable, `defface' for a face. This function +does not switch to the buffer nor display it. The library where SYMBOL is defined is searched for in FILE or `find-function-source-path', if non-nil, otherwise in `load-path'." (cond ((not symbol) (error "You didn't specify a symbol")) - ((null type) + ((memq type '(nil defun)) (find-function-noselect symbol)) ((eq type 'defvar) (find-variable-noselect symbol file)) @@ -579,6 +580,44 @@ (define-key ctl-x-4-map "V" 'find-variable-other-window) (define-key ctl-x-5-map "V" 'find-variable-other-frame)) +;;;###autoload +(defun find-definition (symbol &optional type) + (interactive + (let* ((default (or (intern-soft (thing-at-point 'symbol)) + (function-called-at-point))) + (symbol (intern-soft + (completing-read + (format (if default "Find symbol (default %s): " + "Find symbol: ") default) + obarray + (lambda (s) (or (fboundp s) (boundp s) (facep s))) + t nil nil default))) + (types (delq nil (list (and (fboundp symbol) 'defun) + (and (boundp symbol) 'defvar) + (and (facep symbol) 'defface))))) + (list symbol (if (<= (length types) 1) + (car types) + (intern-soft + (completing-read "Type: " + (mapcar #'symbol-name types) nil t)))))) + (eval-and-compile (require 'etags)) + (let ((def (save-excursion (find-definition-noselect symbol type)))) + (cond + ((not (car def)) + (user-error "No definition found for `%s'" symbol)) + ((and (not (numberp (cdr def))) + (with-current-buffer (car def) + (buffer-narrowed-p)) + (yes-or-no-p + (format "Definition not in accessible portion of buffer %s. Widen? " + (buffer-name (car def))))) + (with-current-buffer (car def) + (widen)) + (find-definition symbol type)) + (t (ring-insert find-tag-marker-ring (point-marker)) + (switch-to-buffer (car def)) + (and (cdr def) (goto-char (cdr def))))))) + (provide 'find-func) ;;; find-func.el ends here --=-=-=--