Git Product home page Git Product logo

gtags-mode's Introduction

Readme

This package provides GNU Global integration with xref, project, completion-at-point (capf) and imenu in emacs.

There are some other packages with their own approach and set of more complete/complex features, maps and functionalities; like ggtags, gtags.el, gxref, agtags and some others. They are listed with a brief description in: related sites.

This package let all the work to the EMACS tools available for such functionalities and avoids external dependencies. Unlike other packages; this module does not create extra special maps, bindings or menus, but just adds support to the mentioned features to use gtags/global as a backend when possible. We do special emphasis on minimalism, simplicity, efficiency and tramp support.

This package may be extended in the future with new features and to support other tools, but only if they are required and included in an emacs distribution and don't need external dependencies.

Usage

Just load and enable the mode: gtags-mode or call it in a hook as usual. The mode is a global-minor-mode.

With use-packages

(use-package gtags-mode
  :hook ((emacs-startup . gtags-mode)))

or simply

(unless (fboundp 'gtags-mode)
	(autoload #'gtags-mode "gtags-mode" nil t))
(add-hook 'emacs-startup-hook #'gtags-mode)

There are only 3 extra commands that the user may need to know:

  • gtags-mode : To enable the global minor mode.
  • gtags-mode-create : To create a gtags database in case it doesn't exist for the current project.
  • gtags-mode-update : To manually update an existent database; specially useful if the project has been modified outside emacs.

Configuration

This packages tries to do its best to not require user configuration. The package provides a minimal set of configuration options in case the global/gtags executable are not in the usual locations, so the user can set them. gtags-mode-global-executable gtags-mode-gtags-executable are buffer local configuration options to set the path or names in case the user needs it or the user setup is do special that the command executable-find fails searching.

TRAMP users can use connection-local-variables to set these values per individual hosts or users if needed.

gtags-mode-features is the list of enabled features in gtags-mode. By default all the features: (project xref completion imenu hooks) are enabled. The user only needs to remove one of these entries and restart gtags-mode to disable it. TODO: Improve the custom type for this variable in order to restrict possible values.

The custom variable gtags-mode-lighter can be used to change the default mode-line message to use when the mode is enabled.

The verbosity of messages printed can be controlled with gtags-mode-verbose-level higher verbose level implies more messages and 0 prints no messages at all (not recommended!!). The most verbose messages are not printed in the echo area, but only in the \*Messages\* buffer.

It is possible to pass extra arguments to update commands using the variable gtags-mode-update-args. Usually these can be used to use different global backends. For example, to use exuberant-gtags instead of the default backend, the Arch Linux configuration is:

(setq gtags-mode-update-args "--gtagsconf=/usr/share/gtags/gtags.conf --gtagslabel=universal-ctags")

This variable can be set in the .dir-locals or as a connection-local-variable

gtags-mode's People

Contributors

ergus avatar jangid avatar magielbruntink avatar phikal avatar whatacold avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gtags-mode's Issues

gtags-mode is kinda spammy in the echo area

It might be a difference in tastes, but it gtags-mode is really liberal in what it outputs to the echo area. Create a new structure in a file and save it, and gtags will immediately tell you that it ran global --single-update. This feels more like a debug message than something for the user. Could a customizable variable be added to turn these messages off?

gtags-mode--after-save-hook should check whether we are in GLOBAL project

Whenever gtags-mode is enabled, gtags-mode--after-save-hook is added to after-save-hook, and runs every time a buffer is saved. This results in spurious error messages like

process-file: Setting current directory: Not a directory

when I am editing files that are not part of any project tagged with GNU global.

Please consider whether it would be a good idea to replace the following condition at the beginning of gtags-mode--after-save-hook

(when (and buffer-file-name

with something like

(when (and (gtags-root-dir) buffer-file-name

http://www.emacswiki.org/emacs/GnuGlobal contains the gtags-root-dir function.

  (defun gtags-root-dir ()
  "Returns GTAGS root directory or nil if doesn't exist."
  (with-temp-buffer
    (if (zerop (call-process "global" nil t nil "-pr"))
        (buffer-substring (point-min) (1- (point-max)))
      nil)))

Switching between a non gtags project into a gtags project results in an error message (wrong-type-argument stringp nil)

Steps to reproduce:

  • Start emacs (29.1 with gtags-mode 1.0 from gnu's elpa https://elpa.gnu.org/packages/gtags-mode.html)
  • Open a gtags project
  • Switch project (project-switch-project) into a non gtags project (vc Git project for example)
  • Try to switch back into the gtags project by executing project-switch-project and pressing f
  • The error message "wrong-type-argument stringp nil" appears

After the error occurs, switching to the *Messages* buffer reveals a "GTAGS not found" error message.
I believe the issue comes from calling the global executable not in the project directory.

When calling project-switch-project and choosing the f option it calls project-find-file-in
https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/progmodes/project.el?h=emacs-29.1#n1731
https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/progmodes/project.el?h=emacs-29.1#n1084

This calls to the override of project-files, which executes global --path-style=through --path
https://github.com/Ergus/gtags-mode/blob/681f210eeedb11234ceea206509185051ea0a5c0/gtags-mode.el#L314C15-L326

If I'm correct, setting default-directory with a let to (project-root) before executing could fix the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.