GNU bug report logs - #15641
24.3; [PATCH] Add find-definition for M-.

Previous Next

Package: emacs;

Reported by: Leo Liu <sdl.web <at> gmail.com>

Date: Fri, 18 Oct 2013 07:35:02 UTC

Severity: wishlist

Tags: patch

Found in version 24.3

Fixed in version 25.1

Done: Noam Postavsky <npostavs <at> users.sourceforge.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 15641 in the body.
You can then email your comments to 15641 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org:
bug#15641; Package emacs. (Fri, 18 Oct 2013 07:35:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Leo Liu <sdl.web <at> gmail.com>:
New bug report received and forwarded. Copy sent to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org. (Fri, 18 Oct 2013 07:35:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3; [PATCH] Add find-definition for M-.
Date: Fri, 18 Oct 2013 15:33:41 +0800
[Message part 1 (text/plain, inline)]
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?

[Message part 2 (text/x-patch, inline)]
=== 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


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15641; Package emacs. (Fri, 18 Oct 2013 12:59:02 GMT) Full text and rfc822 format available.

Message #8 received at 15641 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 15641 <at> debbugs.gnu.org
Subject: Re: bug#15641: 24.3; [PATCH] Add find-definition for M-.
Date: Fri, 18 Oct 2013 08:58:31 -0400
> 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.

Right: M-. should not be bound to an command specific to etags but to
a command which delegates the work to a find-tag-function (whose
default can then be to use etags).

Of course, find-tag-function should do "as little as possible": find the
corresponding place and return it.  The generic part of the code will
take care of displaying the buffer, selecting it, remembering the
previous position, etc... so we don't need a pop-tag-mark-function.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15641; Package emacs. (Fri, 18 Oct 2013 19:02:02 GMT) Full text and rfc822 format available.

Message #11 received at 15641 <at> debbugs.gnu.org (full text, mbox):

From: Josh <josh <at> foxtail.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Leo Liu <sdl.web <at> gmail.com>, 15641 <at> debbugs.gnu.org
Subject: Re: bug#15641: 24.3; [PATCH] Add find-definition for M-.
Date: Fri, 18 Oct 2013 12:01:21 -0700
On Fri, Oct 18, 2013 at 5:58 AM, Stefan Monnier
<monnier <at> iro.umontreal.ca> wrote:
>> 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.
>
> Right: M-. should not be bound to an command specific to etags but to
> a command which delegates the work to a find-tag-function (whose
> default can then be to use etags).
>
> Of course, find-tag-function should do "as little as possible": find the
> corresponding place and return it.  The generic part of the code will
> take care of displaying the buffer, selecting it, remembering the
> previous position, etc... so we don't need a pop-tag-mark-function.

If you haven't already done so, it might be worth taking a look at
elisp-slime-nav-mode[0], which implements something similar to your
patch in a minor mode.  Its author appears to have signed copyright
papers as well.

I'm in agreement with Stefan's inclination to make the entry points
to this functionality sufficiently generic that they can be tagging
system agnostic.  If we start down that path for M-. it seems wise
to consider and specify user interfaces to all of the related
functionality (e.g. as described here[1]) at the same time in order
to provide a single coherent set of commands and key bindings
for navigating source trees, regardless of whether the navigation
in any particular context is facilitated by etags, GNU Global, nrepl,
or other means.

[0] https://github.com/purcell/elisp-slime-nav
[1] http://www.emacswiki.org/emacs/EmacsTags#toc1

Josh




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15641; Package emacs. (Fri, 18 Oct 2013 20:04:01 GMT) Full text and rfc822 format available.

Message #14 received at 15641 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Leo Liu <sdl.web <at> gmail.com>, 15641 <at> debbugs.gnu.org
Subject: Re: bug#15641: 24.3; [PATCH] Add find-definition for M-.
Date: Sat, 19 Oct 2013 00:02:54 +0400
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

> Of course, find-tag-function should do "as little as possible": find the
> corresponding place and return it.

`lisp--company-location' looks like a decent candidate, for Elisp.

> The generic part of the code will
> take care of displaying the buffer, selecting it, remembering the
> previous position, etc... so we don't need a pop-tag-mark-function.

Should we also have a tags-loop-continue-function (or
next-file-function)? Mostly for consistency, it's not as useful in
Elisp, but it could allow the user to jump between different things with
the same name: functions, variables, faces, features.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15641; Package emacs. (Fri, 18 Oct 2013 22:50:02 GMT) Full text and rfc822 format available.

Message #17 received at 15641 <at> debbugs.gnu.org (full text, mbox):

From: Barry OReilly <gundaetiapo <at> gmail.com>
To: 15641 <at> debbugs.gnu.org
Subject: bug#15641: 24.3; [PATCH] Add find-definition for M-.
Date: Fri, 18 Oct 2013 18:49:29 -0400
[Message part 1 (text/plain, inline)]
This would be very nice improvement. When I'm editing C or C++, I
usually try semantic-ia-fast-jump first, which can fail to find the
tag for a variety of reasions. I use etags as my fallback, sometimes
with a few iterations with prefix-arg because of etags false results.

I've missed the fact that I can't pop positions with Semantic. In
practice I end up using Evil's C-o command for the same buffer or
buffer-menu if Semantic took me to a different buffer.

Currently semantic-ia-fast-jump doesn't prompt for the tag to find, as
etags' find-tag does. This is nicer in Semantic's case, so I think the
minibuffer prompting should be specific to etags and not a part of the
generic interface.

Currently find-tag takes TAGNAME while semantic-ia-fast-jump takes PT,
so their interfaces need to be consolidated. PT is more basic since
the TAGNAME etags offers as default is derived from what's at point.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15641; Package emacs. (Sat, 19 Oct 2013 01:22:01 GMT) Full text and rfc822 format available.

Message #20 received at 15641 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: Leo Liu <sdl.web <at> gmail.com>, 15641 <at> debbugs.gnu.org
Subject: Re: bug#15641: 24.3; [PATCH] Add find-definition for M-.
Date: Fri, 18 Oct 2013 21:21:04 -0400
> Should we also have a tags-loop-continue-function (or
> next-file-function)?

Or some other way to get the same result (e.g. an additional argument to
find-tag-function), yes.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15641; Package emacs. (Tue, 07 Nov 2017 00:54:02 GMT) Full text and rfc822 format available.

Message #23 received at 15641 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> users.sourceforge.net>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 15641 <at> debbugs.gnu.org
Subject: Re: bug#15641: 24.3; [PATCH] Add find-definition for M-.
Date: Mon, 06 Nov 2017 19:53:03 -0500
close 15641 25.1
quit

Leo Liu <sdl.web <at> gmail.com> writes:

> 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 believe we now have xref-find-definitions which does this.






bug marked as fixed in version 25.1, send any further explanations to 15641 <at> debbugs.gnu.org and Leo Liu <sdl.web <at> gmail.com> Request was from Noam Postavsky <npostavs <at> users.sourceforge.net> to control <at> debbugs.gnu.org. (Tue, 07 Nov 2017 00:54:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 05 Dec 2017 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 261 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.