]> code.delx.au - gnu-emacs-elpa/blob - README.rst
New command ggtags-find-definition for #57
[gnu-emacs-elpa] / README.rst
1 =========================================================
2 Emacs frontend to GNU Global source code tagging system
3 =========================================================
4
5 This package is part of `GNU ELPA <http://elpa.gnu.org>`_ (``M-x
6 list-packages``) and is also available on `MELPA
7 <http://melpa.milkbox.net/#/ggtags>`_.
8
9 The goal is to make working with GNU Global in Emacs as effortlessly
10 and intuitively as possible and to integrate tightly with standard
11 emacs packages. ``ggtags.el`` is tested in emacs 24.1, 24.2, 24.3 and
12 trunk. Patches, feature requests and bug reports are welcome. Thanks.
13
14 Features
15 ~~~~~~~~
16
17 #. Build on ``compile.el`` for asynchronicity and its large
18 feature-set.
19 #. Automatically update Global's tag files when needed with tuning for
20 large source trees.
21 #. Intuitive navigation among multiple matches with mode-line display
22 of current match, total matches and exit status.
23 #. Read tag with completion.
24 #. Show definition at point.
25 #. Jump to #include files.
26 #. Support search history and saving a search to register/bookmark.
27 #. Query replace.
28 #. Manage Global's environment variables on a per-project basis.
29 #. Highlight (definition) tag at point.
30 #. Abbreviated display of file names.
31 #. Support all Global search backends: ``grep``, ``idutils`` etc.
32 #. Support `exuberant ctags <http://ctags.sourceforge.net/>`_ backend.
33 #. Support all Global's output formats: ``grep``, ``ctags-x``,
34 ``cscope`` etc.
35 #. Support projects on remote hosts (e.g. via ``tramp``).
36 #. Support eldoc.
37 #. Search ``GTAGSLIBPATH`` for references and symbols.
38
39 Screenshot
40 ~~~~~~~~~~
41
42 .. figure:: http://i.imgur.com/LX7PVc3.png
43 :width: 500px
44 :target: http://i.imgur.com/LX7PVc3.png
45 :alt: ggtags.png
46
47 Why GNU Global
48 ~~~~~~~~~~~~~~
49
50 The opengrok project composed a feature comparison `table
51 <https://github.com/OpenGrok/OpenGrok/wiki/Comparison-with-Similar-Tools>`_
52 between a few tools.
53
54 Install Global and plugins
55 ~~~~~~~~~~~~~~~~~~~~~~~~~~
56
57 1. Compile and install Global with ``exuberant-ctags``
58 ::
59
60 ./configure --prefix=<PREFIX> --with-exuberant-ctags=/usr/local/bin/ctags
61 make && make install
62
63 The executable ``ctags`` is unfortunately named because ``emacs`` also
64 includes a command of the same name. So make sure it is from
65 http://ctags.sourceforge.net. See ``plugin-factory/README`` in GNU
66 Global source for further information.
67
68 2. Install ``pygments`` plugin
69 ::
70
71 pip install pygments
72 git clone https://github.com/yoshizow/global-pygments-plugin.git
73 sh reconf.sh
74 ./configure --prefix=<PREFIX> --with-exuberant-ctags=/usr/local/bin/ctags
75 make && make install
76 cp sample.globalrc $HOME/.globalrc
77
78 Make sure the value of ``<PREFIX>`` agree with step 1.
79
80 Config
81 ~~~~~~
82
83 Global with ``exuberant-ctags`` and ``pygments`` plugins can support
84 dozens of programming languages. For example, to enable
85 ``ggtags-mode`` for C/C++/Java modes::
86
87 (add-hook 'c-mode-common-hook
88 (lambda ()
89 (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
90 (ggtags-mode 1))))
91
92 Also see https://github.com/leoliu/ggtags/wiki for more examples.
93
94 Usage
95 ~~~~~
96
97 Open any file in a project and type ``M-x ggtags-mode``. Use ``M-.``
98 (``ggtags-find-tag-dwim``) to find the tag at point. If the project
99 has not been indexed (i.e. no ``GTAGS`` file exists), ``ggtags`` will
100 ask for the project root directory and index it recursively.
101 Alternatively one can invoke ``ggtags-create-tags`` to index a
102 directory. The mode line will display the directory name next to the
103 buffer name. If point is at a valid definition tag, it is underlined.
104
105 ``ggtags`` is similar to the standard ``etags`` package. For example
106 these keys ``M-.``, ``M-,``, ``M-*`` and ``C-M-.`` should work as
107 expected in ``ggtags-mode``.
108
109 The following search commands are available:
110
111 ggtags-find-tag-dwim
112
113 Find a tag by context.
114
115 If point is at a definition tag, find references, and vice versa.
116 If point is at a line that matches ``ggtags-include-pattern``, find
117 the include file instead.
118
119 To force finding a definition tag, call it with a prefix (``C-u``).
120
121 ggtags-find-tag-mouse
122
123 Like ``ggtags-find-tag-dwim`` but suitable for binding to mouse
124 events.
125
126 ggtags-find-definition
127
128 Find definition tags. With ``C-u`` ask for the tag name with
129 completion.
130
131 ggtags-find-reference
132
133 Find reference tags. With ``C-u`` ask for the tag name with completion.
134
135 ggtags-find-other-symbol
136
137 Find tags that have no definitions. With ``C-u`` ask for the tag
138 name with completion.
139
140 ggtags-find-tag-regexp
141
142 Find definition tags matching a regexp. By default it lists all
143 matching tags in the project. With ``C-u`` restrict the lists to a
144 directory of choice.
145
146 ggtags-idutils-query
147
148 Use idutils to find matches.
149
150 ggtags-grep
151
152 Grep for lines matching a regexp. This is usually the slowest.
153
154 ggtags-find-file
155
156 Find a file from all the files indexed by ``gtags``.
157
158 ggtags-query-replace
159
160 Do a query replace in all files found in a search.
161
162 Handling multiple matches
163 +++++++++++++++++++++++++
164
165 When a search finds multiple matches, a buffer named
166 ``*ggtags-global*`` is popped up and ``ggtags-navigation-mode`` is
167 turned on to facilitate locating the right match.
168 ``ggtags-navigation-mode`` makes a few commands in the
169 ``*ggtags-global*`` buffer globally accessible:
170
171 ``M-n``
172
173 Move to the next match.
174
175 ``M-p``
176
177 Move to the previous match.
178
179 ``M-}``
180
181 Move to next file.
182
183 ``M-{``
184
185 Move to previous file.
186
187 ``M-<``
188
189 Move to the first match.
190
191 ``M->``
192
193 Move to the last match.
194
195 ``C-M-s``
196
197 Use ``isearch`` to find the match.
198
199 ``RET``
200
201 Found the right match so exit navigation mode. Resumable by ``M-,``
202 (``tags-loop-continue``).
203
204 ``M-*``
205
206 Abort and go back to the location where the search was started.
207
208 Miscellaneous commands
209 ++++++++++++++++++++++
210
211 Commands are avaiable from the ``Ggtags`` menu in ``ggtags-mode``.
212
213 ggtags-prev-mark
214
215 Move to the previously (older) visited location. Unlike ``M-*``
216 this doesn't delete the location from the tag ring.
217
218 ggtags-next-mark
219
220 Move to the next (newer) visited location.
221
222 ggtags-view-tag-history
223
224 Pop to a buffer listing all visited locations from newest to
225 oldest. The buffer is a next error buffer and works with standard
226 commands ``next-error`` and ``previous-error``. In addition ``TAB``
227 and ``S-TAB`` move to next/prev entry, and ``RET`` visits the
228 location. ``M-n`` and ``M-p`` move to and display the next/previous
229 entry.
230
231 ggtags-global-rerun-search
232
233 Re-run a search from search history as kept in
234 ``ggtags-global-search-history``.
235
236 ggtags-kill-file-buffers
237
238 Kill all file-visiting buffers of current project.
239
240 ggtags-toggle-project-read-only
241
242 Toggle opening files in ``read-only`` mode. Handy if the main
243 purpose of source navigation is to read code.
244
245 ggtags-visit-project-root
246
247 Open the project root directory in ``dired``.
248
249 ggtags-delete-tags
250
251 Delete the GTAGS, GRTAGS, GPATH and ID files of current project.
252
253 ggtags-browse-file-as-hypertext
254
255 Use ``htags`` to generate HTML of the source tree. This allows
256 browsing the porject in a browser with cross-references.
257
258 Integration with other packages
259 +++++++++++++++++++++++++++++++
260
261 * eldoc
262
263 ``Eldoc`` support can be enabled by, for example, setting this in
264 the desired major mode with:
265
266 ::
267
268 (setq-local eldoc-documentation-function #'ggtags-eldoc-function)
269
270 * imenu
271
272 Emacs major modes usually have excellent support for ``imenu`` so
273 this is not enabled by default. To use:
274 ::
275
276 (setq-local imenu-create-index-function #'ggtags-build-imenu-index)
277
278 * hippie-exp
279 ::
280
281 (setq-local hippie-expand-try-functions-list
282 (cons 'ggtags-try-complete-tag hippie-expand-try-functions-list))
283
284 * company
285
286 ``company`` can use ``ggtags`` as completion source via
287 ``company-capf`` which is enabled by default.
288
289 * helm
290
291 If ``helm-mode`` is enabled ``ggtags`` will use it for completion if
292 ``ggtags-completing-read-function`` is nil.
293
294 NEWS
295 ~~~~
296
297 [devel] 0.8.5
298 +++++++++++++
299
300 #. New command ``ggtags-find-tag-mouse`` for mouse support.
301 #. New command ``ggtags-find-definition``.
302 #. Variable ``ggtags-completing-read-function`` restored.
303
304 [2014-05-06 Tue] 0.8.4
305 ++++++++++++++++++++++
306
307 #. ``M-.`` (``ggtags-find-tag-dwim``) is smarter on new files.
308 #. Always update tags for current file on save.
309 #. Can continue search ``GTAGSLIBPATH`` if search turns up 0 matches.
310 Customisable via ``ggtags-global-search-libpath-for-reference``.
311
312 [2014-04-12 Sat] 0.8.3
313 ++++++++++++++++++++++
314
315 #. Tweak mode-line ligter in ``ggtags-navigation-mode``.
316
317 [2014-04-05 Sat] 0.8.2
318 ++++++++++++++++++++++
319
320 #. Default ``ggtags-auto-jump-to-match`` to ``history``.
321 #. Add eldoc support; see ``ggtags-eldoc-function``.
322 #. Improved support for tramp.
323
324 [2014-03-30 Sun] 0.8.1
325 ++++++++++++++++++++++
326
327 #. Improve ``ggtags-view-tag-history`` and tag history navigation.
328 #. New customsable variable ``ggtags-global-use-color``.
329 #. Automatically jump to match from location stored in search history.
330 See ``ggtags-auto-jump-to-match``.
331 #. Rename ``ggtags-supress-navigation-keys`` to
332 ``ggtags-enable-navigation-keys`` with a better way to suppress
333 navigation key bindings in some buffers including
334 ``*ggtags-global*`` buffer.
335
336 [2014-03-24 Mon] 0.8.0
337 ++++++++++++++++++++++
338
339 #. Record search history and re-run past searches.
340 #. Bookmark or save search to register.
341 #. New command ``ggtags-show-definition``.
342 #. Project name on mode line.
343 #. Automatically use ``.globalrc`` or ``gtags.conf`` file at project
344 root.
345 #. Better completion based on tag types.
346 #. Use colored output to get column number for jumping to tag.
347 #. Improve detection of stale GTAGS file based on file modification
348 time.
349 #. New customisable variables ``ggtags-executable-directory``,
350 ``ggtags-global-always-update``, ``ggtags-mode-sticky`` and
351 ``ggtags-supress-navigation-keys``.
352 #. Other bug fixes.
353
354 Bugs
355 ~~~~
356
357 https://github.com/leoliu/ggtags/issues