all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Find tags with dot character
@ 2019-07-22 13:51 Pascal Quesseveur
  2019-07-22 15:36 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Pascal Quesseveur @ 2019-07-22 13:51 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

In Delphi methods are defined using notation ClassName.Method. Very
often I find it more interesting to look for tags using the name
ClassName.Method instead of the name Method. For example on a line

var x := MyClass.Create;

when the point is inside Create, by default the find-tag function
looks for a tag named Create. This tag is found and it corresponds to
the declaration of Create method in class MyClass. Instead I would
prefer to look for the definition of MyClass.Create. In addition,
there are inevitably several classes with the Create method in the
project with leads to ambiguities.

I can edit the tag name in the minibuffer before validating, but in
that case i have to type MyClass.Create in the minibuffer what I find
quite painful.

So I decided to change the way the dot character is taken into account
to build the expression around point. The most obvious thing for me
was to change the syntax entry for words. So I defined a function
which changes the word syntax entry before calling find-tag-default
and then restores the syntax:

(defun my-find-tag-default-opascal ()
  (let (tag)
    (modify-syntax-entry ?. "w")
    (setq tag (find-tag-default))
    (modify-syntax-entry ?. ".")
    tag))

And in Delphi mode hook, I added:

(setq find-tag-default-function 'my-find-tag-default-opascal)

This works fine, but I am wondering if i'm not reinventing the wheel
because I missed something.


-- 
Pascal Quesseveur
pquessev@gmail.com




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

* Re: Find tags with dot character
  2019-07-22 13:51 Find tags with dot character Pascal Quesseveur
@ 2019-07-22 15:36 ` Stefan Monnier
  2019-07-22 17:32   ` Eli Zaretskii
  2019-07-23  7:05   ` Pascal Quesseveur
  0 siblings, 2 replies; 4+ messages in thread
From: Stefan Monnier @ 2019-07-22 15:36 UTC (permalink / raw)
  To: help-gnu-emacs

> (defun my-find-tag-default-opascal ()
>   (let (tag)
>     (modify-syntax-entry ?. "w")
>     (setq tag (find-tag-default))
>     (modify-syntax-entry ?. ".")
>     tag))

In case of an error (or a C-g) during the execution of find-tag-default,
this will fail to restore the syntax-table to its original state, so
I recommend:

    (defun my-find-tag-default-opascal ()
      (unwind-protect
          (progn (modify-syntax-entry ?. "w")
                 (find-tag-default))
        (modify-syntax-entry ?. ".")))

> And in Delphi mode hook, I added:
>
> (setq find-tag-default-function 'my-find-tag-default-opascal)

This likely affects the variable globally, so maybe you'd want to use
`setq-local` instead.

> This works fine, but I am wondering if i'm not reinventing the wheel
> because I missed something.

I know the general issue of namespaces is not handled very well by the
etags support.  Your approach above will make thing worse in several
important use cases (e.g. when point is on "<var>.<method>" where we
won't find that tag anywhere (we'd have to lookup something like
"<class>.<method>" instead)), so it's not really something we can use as
is by default, but I think we'd welcome patches which try to improve on
this (e.g. by first trying with the dots and if that fails try again
without them).


        Stefan




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

* Re: Find tags with dot character
  2019-07-22 15:36 ` Stefan Monnier
@ 2019-07-22 17:32   ` Eli Zaretskii
  2019-07-23  7:05   ` Pascal Quesseveur
  1 sibling, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2019-07-22 17:32 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Mon, 22 Jul 2019 11:36:39 -0400
> 
> I know the general issue of namespaces is not handled very well by the
> etags support.

In general, this support requires something in etags the program: it
should know about class-qualified identifiers and put in TAGS both the
qualified and the unqualified forms.  Then M-. will suggest both as
possible candidates.



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

* Re: Find tags with dot character
  2019-07-22 15:36 ` Stefan Monnier
  2019-07-22 17:32   ` Eli Zaretskii
@ 2019-07-23  7:05   ` Pascal Quesseveur
  1 sibling, 0 replies; 4+ messages in thread
From: Pascal Quesseveur @ 2019-07-23  7:05 UTC (permalink / raw)
  To: help-gnu-emacs

>"SM" == Stefan Monnier <monnier@iro.umontreal.ca> writes:

  SM> In case of an error (or a C-g) during the execution of find-tag-default,
  SM> this will fail to restore the syntax-table to its original state, so
  SM> I recommend:

  SM>     (defun my-find-tag-default-opascal ()
  SM>       (unwind-protect
  SM>           (progn (modify-syntax-entry ?. "w")
  SM>                  (find-tag-default))
  SM>         (modify-syntax-entry ?. ".")))

OK.

> And in Delphi mode hook, I added:
>
> (setq find-tag-default-function 'my-find-tag-default-opascal)

  SM> This likely affects the variable globally, so maybe you'd want
  SM> to use `setq-local` instead.

Yes, thank you.

  SM> Your approach above will make thing worse in several important
  SM> use cases (e.g. when point is on "<var>.<method>" where we won't
  SM> find that tag anywhere (we'd have to lookup something like
  SM> "<class>.<method>" instead))

Yes, we need both.

  SM> is by default, but I think we'd welcome patches which try to
  SM> improve on this (e.g. by first trying with the dots and if that
  SM> fails try again without them).

I'm afraid I'm not expert enough to propose a modification of etags,
either etags the program or the etags handling in emacs. In addition i
use an old version of emacs (24.3) for delphi devlopment, where I
don't have the new opascal mode, only delphi-mode. I still tried and
produced those functions:

(defun my-find-tag-opascal-helper (prompt)
  "Helper to call find-tag and catch errors. I was unable to call
find-tag-interactive, so I used find-tag-tag without any
options."
  (condition-case err
      (let ((tagname (find-tag-tag prompt)))
        (find-tag tagname)
        t)
    (error (message "%s" (error-message-string err))
           nil)))

(defun my-find-tag-opascal()
  "First call find-tag using current find-tag-default-function,
and when no tags are found call find-tag again with
find-tag-default-function set to nil."
  (interactive)
  (let ((xp (point))
        (xb (current-buffer))
        tfunc)
    (unless (my-find-tag-opascal-helper "Find tag: ")
      (set-buffer xb)
      (goto-char xp)
      (setq tfunc find-tag-default-function)
      (setq-local find-tag-default-function nil)
      (unwind-protect
          (my-find-tag-opascal-helper "Tag not found. Retry with: ")
        (set-buffer xb)
        (setq-local find-tag-default-function tfunc)))))


-- 
Pascal Quesseveur
pquessev@gmail.com




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

end of thread, other threads:[~2019-07-23  7:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-22 13:51 Find tags with dot character Pascal Quesseveur
2019-07-22 15:36 ` Stefan Monnier
2019-07-22 17:32   ` Eli Zaretskii
2019-07-23  7:05   ` Pascal Quesseveur

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.