Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: counsel-gtags-dwim also find include files #27

Open
kha-dinh opened this issue Feb 11, 2021 · 4 comments
Open

Feature request: counsel-gtags-dwim also find include files #27

kha-dinh opened this issue Feb 11, 2021 · 4 comments

Comments

@kha-dinh
Copy link

Right now it only finds either definition or reference.
In ggtags, dwim also finds header files when pointing to the include section.
It would be nice to have something similar.

@FelipeLema
Copy link
Owner

acknowledged, although this might take me a bit since this package is scoring very low among my priorities

@FelipeLema
Copy link
Owner

Is there a ggtags command that does this? something like ggtags-find-header-file?

@kha-dinh
Copy link
Author

Here is the function ggtags-find-tag-dwim from ggtags

(defun ggtags-find-tag-dwim (name &optional what)
  "Find NAME by context.
If point is at a definition tag, find references, and vice versa.
If point is at a line that matches `ggtags-include-pattern', find
the include file instead.

When called interactively with a prefix arg, always find
definition tags."
  (interactive
   (let ((include (and (not current-prefix-arg) (ggtags-include-file))))
     (ggtags-ensure-project)
     (if include (list include 'include)
       (list (ggtags-read-tag 'definition current-prefix-arg)
             (and current-prefix-arg 'definition)))))
  (ggtags-check-project)    ; For `ggtags-current-project-root' below.
  (cond
   ((eq what 'include)
    (ggtags-find-file name))
   ((or (eq what 'definition)
        (not buffer-file-name)
        (not (ggtags-project-has-refs (ggtags-find-project)))
        (not (ggtags-project-file-p buffer-file-name)))
    (ggtags-find-definition name))
   (t (ggtags-find-tag
       (format "--from-here=%d:%s"
               (line-number-at-pos)
               ;; Note `ggtags-find-tag' binds `default-directory' to
               ;; project root.
               (shell-quote-argument
                (ggtags-project-relative-file buffer-file-name)))
       "--" (shell-quote-argument name)))))

@FelipeLema
Copy link
Owner

FelipeLema commented Feb 22, 2021

this was implemented recently in global-tags.el, so now I'm clear on what to do here

Feel free to use global-tags.el in the meantime.

I hardly advice you switch to global-tags.el and ivy-xref

EDIT: AY CHIHUAHUA... counsel-gtags--read-tag is a macro! I'm definitely not touching that (most likely that things will break

Leaving open in case someone else will do a PR (or if @kha-dinh has solved by other means)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants