Emacs C IDE / Gnu Global helm-gtags - Ask Ubuntu


hello ubuntu community,

so first of i'd quite new ubuntu (16.10) , linux. decided use windows little possible , wanted start learning programming language c. however, thought nice in emacs started learning emacs , did tutorials on emacs. basics , learning doing. found tutorial https://tuhdo.github.io/c-ide.html before installed lot of packages including helm , gtags , helm-gtags. installed ncurses libary in order install gnu global.

so problem / question. first of if honest don't gtags is, thought gonna figure out when install (something navigation guess). under section 'source code navigation' talks about:

"before using ggtags or helm-gtags, remember create gtags database running gtags @ project root in terminal: ".. , commands

i think somehow have connect libary emacs. gnu_global faq written create link project folder reffering to: /usr/src/lib

but in /usr/src directory no lib folder. guess , because ubuntu has different structures other linux distros libary somewhere else ? or wrong ? couldn't find answers google maybe can enlighten me.

thanks in advance, andi

gtags linux tool generates symbol database source code , allows searching of symbols usage , definition. ggtags "plugin" emacs provides automated frontend tool. alternatives have similar functionality gtags ctags, etags, , cscope, of have own emacs plugins.
notably, many of these tools not @ handling large codebases (linux kernel size , larger) because of way store databases. linux kernel example generate 2gb text file when using gtags, , file has loaded , searched whenever try symbol lookup. workarounds exist resolve problem (below).

simple solution

1.install gtags on system.

sudo apt-get install global 

on command line should able run command , see it's installed:

which gtags 

2.tell emacs ggtags plugin find gtags tool.

using path returned which gtags command, add following line ~/.emacs file:

(setq ggtags-executable-directory "/path/to/gtags/parent/dir") 

3.create gtags database code project.

by default ggtags search upward through directory tree file in performed symbol lookup trying find gtags file. gtags file (and possibly associated ones) symbol database. if doesn't find match symbol in first database file, continue searching directory tree additional databases. matches prioritized based on file proximity of symbol usage/definition file you're doing lookup in. generation of database called "tagging", , it's located @ root of source tree want tag. gtags tool not continuation search since it's passed path specific database, , native emacs provided gtags plugin maintains single-database behavior.

create gtags database source folder out of emacs when you're using ggtags plugin (recommended on native emacs gtags plugin), need run command ggtags-create-tags. default key-binding running arbitrary commands in emacs m-x, press , type ggtags-create-tags. prompt folder should tagged , database should placed, point top directory of source folder want tag. run while, possibly quite while if have large source tree, blocking entire emacs gui while generates tag database. once completes used automatically ggtags when relevant.

much better solution

one of problems gtags, ctags, etags, , cscope size of databases produced. since they're tagging symbols defined they're used, can end database larger actual source tree. large databases present problem of searching them in reasonable time. using ggtags default ubuntu gnu-global tool installed produces inefficient database format gets exponentially worse larger grows. because ubuntu still providing gnu-global tool 2008 rather modern version, , it's not built use more efficient ctags tools underlying framework.

avoid problems gtags , use more efficient ctags, need global-6.4 or later, , needs built point ctags installations. way i've found build source , provide proper options necessary dependent package installations. ended writing shell script installation , setup me, , keep in github rest of emacs configuration , installation scripts. can https://github.com/mtalexan/emacs-settings/blob/master/global_install.sh.

you'll need set few things in ~/.emacs make full use of this:

(setq ggtags-use-idutils t) (setq ggtags-use-project-gtagsconf nil) 

this enables use of efficient idutils sub-package, , makes sure gtags calls use global settings gtags you've compiled in.

how use gtags/ggtags/helm-gtags

i use ggtags , not helm-gtags or gtags. emacs provides default gtags "plugin", has worse interface ggtags , search single database. use helm regularly things, ggtags interface separated helm interface when i'm parsing matches don't use helm-gtags. helm-gtags pretty slow if gtags database large.

ggtags need set ggtags-mode useful. can done adding automatically trigger on c-mode adding following .emacs file

(add-hook 'c-mode-common-hook   (lambda ()     (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)      (ggtags-mode 1)))) 

alternatively can set enabled instead using line this:

(setq ggtags-global-mode 1) 



settings recommend if you're going using large codebase require following lines in ~/.emacs file:

; allow large database files (setq ggtags-oversize-limit 104857600) (setq ggtags-sort-by-nearness t) 



when browsing code, common things follow symbol underneath cursor, find uses of symbol underneath cursor, , symbol lookup unrelated cursor is. these correspond commands: ggtags-find-tag-dwim , ggtags-find-reference. these commands operate on point (your emacs cursor position) open prompt enter symbol when there no symbol under point or when they're called m-x.
when run ggtags-find-tag-dwim can number of things best understood playing it, jump match when there's 1 match (equivalent doesn't auto-jump ggtags-find-tag) or open side windows ggtags-find-reference list of possible matches includes file, line number, , context each entry clickable jump directly there.
careful when window open, puts in special minor mode means , down keys switch between matches until press enter officially select match.
conveniently when select match tag-mark left behind. means can use command pop-tag-mark jump last place at. tag-mark stack of tag-marks, can repeatedly symbols , able go each location prior following lookup. if want manual lookup rather 1 based on symbol @ point, there ggtags functions operate ggtags-find-tag-dwim, prompt symbol in minibuffer. ggtags-find-tag-dwim if there no symbol under point.


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User