unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#15641: 24.3; [PATCH] Add find-definition for M-.
@ 2013-10-18  7:33 Leo Liu
  2013-10-18 12:58 ` Stefan Monnier
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Leo Liu @ 2013-10-18  7:33 UTC (permalink / raw)
  To: 15641

[-- Attachment #1: Type: text/plain, Size: 226 bytes --]

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?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: find-func.diff --]
[-- Type: text/x-patch, Size: 3957 bytes --]

=== 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#15641: 24.3; [PATCH] Add find-definition for M-.
  2013-10-18  7:33 bug#15641: 24.3; [PATCH] Add find-definition for M- Leo Liu
@ 2013-10-18 12:58 ` Stefan Monnier
  2013-10-18 19:01   ` Josh
  2013-10-18 20:02   ` Dmitry Gutov
  2013-10-18 22:49 ` Barry OReilly
  2017-11-07  0:53 ` Noam Postavsky
  2 siblings, 2 replies; 7+ messages in thread
From: Stefan Monnier @ 2013-10-18 12:58 UTC (permalink / raw)
  To: Leo Liu; +Cc: 15641

> 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





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#15641: 24.3; [PATCH] Add find-definition for M-.
  2013-10-18 12:58 ` Stefan Monnier
@ 2013-10-18 19:01   ` Josh
  2013-10-18 20:02   ` Dmitry Gutov
  1 sibling, 0 replies; 7+ messages in thread
From: Josh @ 2013-10-18 19:01 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Leo Liu, 15641

On Fri, Oct 18, 2013 at 5:58 AM, Stefan Monnier
<monnier@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





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#15641: 24.3; [PATCH] Add find-definition for M-.
  2013-10-18 12:58 ` Stefan Monnier
  2013-10-18 19:01   ` Josh
@ 2013-10-18 20:02   ` Dmitry Gutov
  2013-10-19  1:21     ` Stefan Monnier
  1 sibling, 1 reply; 7+ messages in thread
From: Dmitry Gutov @ 2013-10-18 20:02 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Leo Liu, 15641

Stefan Monnier <monnier@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.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#15641: 24.3; [PATCH] Add find-definition for M-.
  2013-10-18  7:33 bug#15641: 24.3; [PATCH] Add find-definition for M- Leo Liu
  2013-10-18 12:58 ` Stefan Monnier
@ 2013-10-18 22:49 ` Barry OReilly
  2017-11-07  0:53 ` Noam Postavsky
  2 siblings, 0 replies; 7+ messages in thread
From: Barry OReilly @ 2013-10-18 22:49 UTC (permalink / raw)
  To: 15641

[-- Attachment #1: Type: text/plain, Size: 903 bytes --]

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.

[-- Attachment #2: Type: text/html, Size: 1016 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#15641: 24.3; [PATCH] Add find-definition for M-.
  2013-10-18 20:02   ` Dmitry Gutov
@ 2013-10-19  1:21     ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2013-10-19  1:21 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Leo Liu, 15641

> 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





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#15641: 24.3; [PATCH] Add find-definition for M-.
  2013-10-18  7:33 bug#15641: 24.3; [PATCH] Add find-definition for M- Leo Liu
  2013-10-18 12:58 ` Stefan Monnier
  2013-10-18 22:49 ` Barry OReilly
@ 2017-11-07  0:53 ` Noam Postavsky
  2 siblings, 0 replies; 7+ messages in thread
From: Noam Postavsky @ 2017-11-07  0:53 UTC (permalink / raw)
  To: Leo Liu; +Cc: Stefan Monnier, 15641

close 15641 25.1
quit

Leo Liu <sdl.web@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.







^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-11-07  0:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-18  7:33 bug#15641: 24.3; [PATCH] Add find-definition for M- Leo Liu
2013-10-18 12:58 ` Stefan Monnier
2013-10-18 19:01   ` Josh
2013-10-18 20:02   ` Dmitry Gutov
2013-10-19  1:21     ` Stefan Monnier
2013-10-18 22:49 ` Barry OReilly
2017-11-07  0:53 ` Noam Postavsky

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).