-
Notifications
You must be signed in to change notification settings - Fork 139
/
c-ide.html
3173 lines (2673 loc) · 127 KB
/
c-ide.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2016-11-04 Fri 22:29 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>C/C++ Development Environment for Emacs</title>
<meta name="generator" content="Org-mode" />
<meta name="author" content="Tu Do" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
pre.src-sh:before { content: 'sh'; }
pre.src-bash:before { content: 'sh'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-R:before { content: 'R'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-java:before { content: 'Java'; }
pre.src-sql:before { content: 'SQL'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
/*]]>*/-->
</style>
<link rel="stylesheet" href="./static/worg.css">
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2013 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
</head>
<body>
<div id="preamble" class="status">
<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
var sc_project=9874755;
var sc_invisible=1;
var sc_security="c2028bb7";
var scJsHost = (("https:" == document.location.protocol) ?
"https://secure." : "http://www.");
document.write("<sc"+"ript type='text/javascript' src='" + scJsHost+
"statcounter.com/counter/counter.js'></"+"script>");
</script>
<noscript><div class="statcounter"><a title="hit counter"
href="http://statcounter.com/free-hit-counter/" target="_blank"><img
class="statcounter" src="http://c.statcounter.com/9874755/0/c2028bb7/1/"
alt="hit counter"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->
<h2><a href="index.html">Back to Table of Contents</a></h2>
</div>
<div id="content">
<h1 class="title">C/C++ Development Environment for Emacs</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#orgheadline0">Introductory demos</a>
<li><a href="#orgheadline0a">Quick setup</a>
<li><a href="#orgheadline1">Source code navigation</a>
<ul>
<li><a href="#orgheadline2">Prerequisite:</a></li>
<li><a href="#orgheadline3">Basic movements</a></li>
<li><a href="#orgheadline4">Basic concepts of tag</a></li>
<li><a href="#orgheadline5">Find definitions in current buffer</a></li>
<li><a href="#orgheadline6">Find definitions in project</a></li>
<li><a href="#orgheadline7">Find references in project</a></li>
<li><a href="#orgheadline8">Find functions that current functions call</a></li>
<li><a href="#orgheadline9">Find files in project</a></li>
<li><a href="#orgheadline10">View visited tags with tag stack</a></li>
</ul>
</li>
<li><a href="#orgheadline11">Browse source tree with <code>Speedbar</code> file browser</a>
<ul>
<li><a href="#orgheadline12">Package: <code>sr-speedbar</code></a></li>
</ul>
</li>
<li><a href="#orgheadline13">General completion with <code>company-mode</code></a></li>
<li><a href="#orgheadline14">Demo project</a></li>
<li><a href="#orgheadline15">Source code completion using Clang</a></li>
<li><a href="#orgheadline16">Header file completion with <code>company-c-headers</code> package</a></li>
<li><a href="#orgheadline17">CEDET</a>
<ul>
<li><a href="#orgheadline18">What is CEDET?</a></li>
<li><a href="#orgheadline19">Why use CEDET?</a></li>
<li><a href="#orgheadline20">Installation</a></li>
<li><a href="#orgheadline21">Semantic minor modes</a></li>
<li><a href="#orgheadline28">CEDET can do more</a></li>
<li><a href="#orgheadline29">Source code navigation using Senator</a>
<ul>
<li><a href="#orgheadline30">Navigation</a></li>
<li><a href="#orgheadline31">Copy/Paste</a></li>
<li><a href="#orgheadline32">Obsolete commands</a></li>
</ul>
</li>
<li><a href="#orgheadline33"><b>(Optional)</b> Project management with EDE</a></li>
</ul>
</li>
<li><a href="#orgheadline34">Code refactoring</a></li>
<li><a href="#orgheadline35">Navigate system include path</a>
<ul>
<li><a href="#orgheadline36">Using <code>Semantic</code> with <code>semantic-ia-fast-jump</code> command</a></li>
<li><a href="#orgheadline37">Using generated database from <code>GNU Global</code></a></li>
</ul>
</li>
<li><a href="#orgheadline38">Project management with Projectile</a></li>
<li><a href="#orgheadline39">Source code information</a>
<ul>
<li><a href="#orgheadline40">Command: <code>global-semantic-idle-summary-mode</code></a></li>
<li><a href="#orgheadline41">Command: <code>global-semantic-stickyfunc-mode</code></a></li>
<li><a href="#orgheadline42">Using <code>ggtags</code> + <code>eldoc</code></a></li>
</ul>
</li>
<li><a href="#orgheadline43">Source code documentation</a>
<ul>
<li><a href="#orgheadline44">Command: <code>man</code></a></li>
<li><a href="#orgheadline45">Command: <code>helm-man-woman</code></a></li>
</ul>
</li>
<li><a href="#orgheadline46">Source code editing</a>
<ul>
<li><a href="#orgheadline47">Folding</a></li>
<li><a href="#orgheadline48">Narrowing</a></li>
<li><a href="#orgheadline49">Identation</a>
<ul>
<li><a href="#orgheadline50">Setup default C style</a></li>
<li><a href="#orgheadline51">Setup indentation</a></li>
<li><a href="#orgheadline52">Package: <code>clean-aindent-mode</code></a></li>
<li><a href="#orgheadline53">Package: <code>dtrt-indent</code></a></li>
<li><a href="#orgheadline54">Package: <code>ws-butler</code></a></li>
</ul>
</li>
<li><a href="#orgheadline55">Code template using <code>yasnippet</code></a></li>
<li><a href="#orgheadline56">Package: <code>smartparens</code></a></li>
</ul>
</li>
<li><a href="#orgheadline57">Compilation Support</a></li>
<li><a href="#orgheadline58">Debugging</a>
<ul>
<li><a href="#orgheadline59">With GDB Many Windows</a></li>
<li><a href="#orgheadline60">With Grand Unified Debugger - GUD</a></li>
</ul>
</li>
</ul>
</div>
</div>
<p>
In this guide, I will help you to setup an efficient working C/C++
environment. Despite looking long, the setup is short and easy (mostly
copy/paste Emacs Lisp code into your <code>init.el</code>); most of the guide are
explanations and demonstrations of many useful features. Following
this guide, you should be able to browse the Linux kernel source tree
inside Emacs effortlessly, such as jump to definition/references at
cursor, go back and forth between jumping points, finding any file
instantly, switching between .h and .c/.cpp.
</p>
<p>
Please remember that there's a table of content on the top right
corner and you can use it to navigate this guide. If you feel your
internet connection is too slow for my guide, you can always clone and
read it offline: <a href="https://github.com/tuhdo/tuhdo.github.io">https://github.com/tuhdo/tuhdo.github.io</a>
</p>
<div id="outline-container-orgheadline0" class="outline-2">
<h2 id="orgheadline0"><a id="introductory-demos"></a>Introductory demos</h2>
<div class="outline-text-2" id="text-orgheadline0">
</div>
<ul class="org-ul">
<li>Switching between .h and .c/.cpp anywhere in the project like Linux
kernel. If more than one file exists, it displays a list of
possible candidates. The command collects files of the same names
but different across the project:</li>
</ul>
<div class="figure">
<p><a href="static/c-ide/projectile-find-other-file.gif"><img src="static/c-ide/projectile-find-other-file.gif" alt="projectile-find-other-file.gif" /></a>
</p>
</div>
<ul class="org-ul">
<li>Jump around Linux kernel source with ease using <code>helm-gtags</code>. The
demo begins when "START" appears at the bottom:</li>
</ul>
<div class="figure">
<p><a href="static/c-ide/helm-gtags-jump-dwim.gif"><img src="static/c-ide/helm-gtags-jump-dwim.gif" alt="helm-gtags-jump-dwim.gif" /></a>
</p>
</div>
<ul class="org-ul">
<li><p>
Interactive outline tree using <code>moo-jump-local</code> from <a href="https://github.com/abo-abo/function-args">function-args</a>
package:
</p>
<div class="figure">
<p><a href="static/c-ide/moo-jump-local.gif"><img src="static/c-ide/moo-jump-local.gif" alt="moo-jump-local.gif" /></a>
</p>
</div></li>
<li>Static outline tree as a file browser:</li>
</ul>
<div class="figure">
<p><a href="static/c-ide/sr-speedbar.gif"><img src="static/c-ide/sr-speedbar.gif" alt="sr-speedbar.gif" /></a>
</p>
</div>
<ul class="org-ul">
<li>Symbol references:</li>
</ul>
<div class="figure">
<p><a href="static/c-ide/semantic-symref.gif"><img src="static/c-ide/semantic-symref.gif" alt="semantic-symref.gif" /></a>
</p>
</div>
<ul class="org-ul">
<li>Code completion 1:</li>
</ul>
<div class="figure">
<p><a href="static/c-ide/semantic-boost-demo.gif"><img src="static/c-ide/semantic-boost-demo.gif" alt="semantic-boost-demo.gif" /></a>
</p>
</div>
<ul class="org-ul">
<li>Code completion 2:</li>
</ul>
<div class="figure">
<p><a href="static/auto_complete.gif"><img src="static/auto_complete.gif" alt="auto_complete.gif" /></a>
</p>
</div>
<ul class="org-ul">
<li>Header completion:</li>
</ul>
<div class="figure">
<p><a href="static/c-ide/company-c-header.png"><img src="static/c-ide/company-c-header.png" alt="company-c-header.png" /></a>
</p>
</div>
<ul class="org-ul">
<li>Show function interface and variable definition at the bottom:</li>
</ul>
<div class="figure">
<p><a href="static/func_args.jpg"><img src="static/func_args.jpg" alt="func_args.jpg" /></a>
</p>
</div>
<div class="figure">
<p><a href="static/c-ide/semantic-idle-summary-lambda.gif"><img src="static/c-ide/semantic-idle-summary-lambda.gif" alt="semantic-idle-summary-lambda.gif" /></a>
</p>
</div>
<div class="figure">
<p><a href="static/c-ide/semantic-idle-summary-variable.gif"><img src="static/c-ide/semantic-idle-summary-variable.gif" alt="semantic-idle-summary-variable.gif" /></a>
</p>
</div>
<ul class="org-ul">
<li>Show current function your cursor is inside at the top:</li>
</ul>
<div class="figure">
<p><a href="static/c-ide/semantic-sticky-func.gif"><img src="static/c-ide/semantic-sticky-func.gif" alt="semantic-sticky-func.gif" /></a>
</p>
</div>
<ul class="org-ul">
<li>Compilation support:</li>
</ul>
<div class="figure">
<p><a href="static/c-ide/compilation-mode.gif"><img src="static/c-ide/compilation-mode.gif" alt="compilation-mode.gif" /></a>
</p>
</div>
<ul class="org-ul">
<li>Beautiful compile output:</li>
</ul>
<div class="figure">
<p><a href="static/c-ide/compilation-compile.gif"><img src="static/c-ide/compilation-compile.gif" alt="compilation-compile.gif" /></a>
</p>
</div>
<ul class="org-ul">
<li>Fancy GDB debugging:</li>
</ul>
<div class="figure">
<p><a href="static/c-ide/gdb-many-windows.gif"><img src="static/c-ide/gdb-many-windows.gif" alt="gdb-many-windows.gif" /></a>
</p>
</div>
<ul class="org-ul">
<li>Getting man pages for symbol at cursor:</li>
</ul>
<div class="figure">
<p><a href="static/part3/helm-man-woman.gif"><img src="static/part3/helm-man-woman.gif" alt="helm-man-woman.gif" /></a>
</p>
</div>
<div id="outline-container-orgheadline0a" class="outline-2">
<h2 id="orgheadline0a"><a id="quick-setup"></a>Quick setup</h2>
<div class="outline-text-2" id="text-orgheadline0a">
</div>
<p>
I've prepared an Emacs repository that is properly configured for
demonstration purposes. You can clone it and play with it without having to
manually copy and paste all the setup Elisp code
throughout the guide. When installed and run <u>the first time</u>, the demo
repository will download from melpa, install, and compile all the packages
it needs. Note that depending on your internet connection and processor speeds,
this may take a while.
</p>
<ol>
<li><p>Install <a href="http://www.gnu.org/software/global/">GNU Global</a> from your distribution's package manager (Linux / Mac) or from the <a href="http://adoxa.altervista.org/global/">Win32 port</a> (Windows). If none is available, download the sources <a href="http://www.gnu.org/software/global/download.html">here</a> and manually build the package.</p>
<li><p>Backup your <code>~/.emacs.d</code> elsewhere.</p></li>
<li><p>If emacs is not already running, start it.</p></li>
<li><p>Update your melpa database: <code>M-x package-list-packages</code></p></li>
<li><p>Clone the repository into your ~/.emacs.d folder.
<div class="org-src-container">
<pre class="src src-sh">git clone https://github.com/tuhdo/emacs-c-ide-demo.git ~/.emacs.d
</pre>
</div></p></li>
<li><p>You may possibly want to edit your new <code>~/.emacs.d/init.el</code> file for two options.
<ol>
<li><p>The demo repository can use either <code>helm-gtags</code> (the default), or <code>ggtags</code>.
If you want to use <code>ggtags</code>, comment this line in <code>init.el</code>:
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #707183;">(</span><span style="color: #a020f0;">require</span> '<span style="color: #008b8b;">setup-helm-gtags</span><span style="color: #707183;">)</span>
</pre>
</div>
And uncomment this line:
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #b22222;">;; </span><span style="color: #b22222;">(require 'setup-ggtags)</span>
</pre>
</div>
</p></li>
<li><p>The demo uses Helm. If you're not already familiar with Helm, read
<a href="http://tuhdo.github.io/helm-intro.html">my guide</a>.
If you don't want to use Helm, also comment this line in <code>init.el</code>:
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #707183;">(</span><span style="color: #a020f0;">require</span> '<span style="color: #008b8b;">setup-helm</span><span style="color: #707183;">)</span>
</pre>
</div>
</p></li>
</ol>
</ol>
<p>That does it! To start using the demo, just type <code>M-x load-file RET init.el</code>. Continue reading this guide for its operational directions, without needing to bother to perform any more installations or elisp evaluations.</p>
<div id="outline-container-orgheadline1" class="outline-2">
<h2 id="orgheadline1"><a id="source-navigation"></a>Source code navigation</h2>
<div class="outline-text-2" id="text-orgheadline1">
</div>
<div id="outline-container-orgheadline2" class="outline-3">
<h3 id="orgheadline2"><a id="ID-b1292347-d0ed-4421-9905-33f1050883b2"></a>Prerequisite:</h3>
<div class="outline-text-3" id="text-orgheadline2">
<ul class="org-ul">
<li>Know how to use <code>package.el</code> and MELPA. If you don't know how to
use, read the guide <a href="emacs-tutor3.html#MissingReference">How to use Emacs package manager</a>.</li>
<li><p>Install <a href="http://www.gnu.org/software/global/">GNU Global</a> from your distribution's package manager (Linux / Mac) or from the <a href="http://adoxa.altervista.org/global/">Win32 port</a> (Windows). If none is available, download the sources <a href="http://www.gnu.org/software/global/download.html">here</a> and manually build the package. Do be aware that it is remotely possible that your package manager might install an
outdated version that might impair some functionality of helm-gtags.
</p></li>
<li>Install <a href="https://github.com/leoliu/ggtags">ggtags</a>. After installing <code>ggtags</code> from MELPA, add this code
snippet to setup <code>ggtags</code> and key bindings:</li>
</ul>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #707183;">(</span><span style="color: #a020f0;">require</span> '<span style="color: #008b8b;">ggtags</span><span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>add-hook 'c-mode-common-hook
<span style="color: #7388d6;">(</span><span style="color: #a020f0;">lambda</span> <span style="color: #909183;">()</span>
<span style="color: #909183;">(</span><span style="color: #a020f0;">when</span> <span style="color: #709870;">(</span>derived-mode-p 'c-mode 'c++-mode 'java-mode 'asm-mode<span style="color: #709870;">)</span>
<span style="color: #709870;">(</span>ggtags-mode <span style="color: #008b8b;">1</span><span style="color: #709870;">)</span><span style="color: #909183;">)</span><span style="color: #7388d6;">)</span><span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>define-key ggtags-mode-map <span style="color: #7388d6;">(</span>kbd <span style="color: #8b2252;">"C-c g s"</span><span style="color: #7388d6;">)</span> 'ggtags-find-other-symbol<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>define-key ggtags-mode-map <span style="color: #7388d6;">(</span>kbd <span style="color: #8b2252;">"C-c g h"</span><span style="color: #7388d6;">)</span> 'ggtags-view-tag-history<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>define-key ggtags-mode-map <span style="color: #7388d6;">(</span>kbd <span style="color: #8b2252;">"C-c g r"</span><span style="color: #7388d6;">)</span> 'ggtags-find-reference<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>define-key ggtags-mode-map <span style="color: #7388d6;">(</span>kbd <span style="color: #8b2252;">"C-c g f"</span><span style="color: #7388d6;">)</span> 'ggtags-find-file<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>define-key ggtags-mode-map <span style="color: #7388d6;">(</span>kbd <span style="color: #8b2252;">"C-c g c"</span><span style="color: #7388d6;">)</span> 'ggtags-create-tags<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>define-key ggtags-mode-map <span style="color: #7388d6;">(</span>kbd <span style="color: #8b2252;">"C-c g u"</span><span style="color: #7388d6;">)</span> 'ggtags-update-tags<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>define-key ggtags-mode-map <span style="color: #7388d6;">(</span>kbd <span style="color: #8b2252;">"M-,"</span><span style="color: #7388d6;">)</span> 'pop-tag-mark<span style="color: #707183;">)</span>
</pre>
</div>
<ul class="org-ul">
<li>Or, <a href="https://github.com/emacs-helm/helm">helm</a> + <a href="https://github.com/syohex/emacs-helm-gtags">helm-gtags</a>. Helm is awesome and if you are going to use
Helm, please read the <a href="http://tuhdo.github.io/helm-intro.html">Helm guide</a>. Remember to setup <code>Helm</code> before
using <code>helm-gtags</code>. You can use this <a href="https://github.com/tuhdo/emacs-c-ide-demo/blob/master/custom/setup-helm.el">sample configuration</a>. When
includes the above file in your <code>~/.emacs.d</code>, remember to add
<code>(require 'setup-helm)</code> to your <code>init.el</code>.</li>
</ul>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #707183;">(</span><span style="color: #a020f0;">setq</span>
helm-gtags-ignore-case t
helm-gtags-auto-update t
helm-gtags-use-input-at-cursor t
helm-gtags-pulse-at-cursor t
helm-gtags-prefix-key <span style="color: #8b2252;">"\C-cg"</span>
helm-gtags-suggested-key-mapping t
<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span><span style="color: #a020f0;">require</span> '<span style="color: #008b8b;">helm-gtags</span><span style="color: #707183;">)</span>
<span style="color: #b22222;">;; </span><span style="color: #b22222;">Enable helm-gtags-mode</span>
<span style="color: #707183;">(</span>add-hook 'dired-mode-hook 'helm-gtags-mode<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>add-hook 'eshell-mode-hook 'helm-gtags-mode<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>add-hook 'c-mode-hook 'helm-gtags-mode<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>add-hook 'c++-mode-hook 'helm-gtags-mode<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>add-hook 'asm-mode-hook 'helm-gtags-mode<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>define-key helm-gtags-mode-map <span style="color: #7388d6;">(</span>kbd <span style="color: #8b2252;">"C-c g a"</span><span style="color: #7388d6;">)</span> 'helm-gtags-tags-in-this-function<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>define-key helm-gtags-mode-map <span style="color: #7388d6;">(</span>kbd <span style="color: #8b2252;">"C-j"</span><span style="color: #7388d6;">)</span> 'helm-gtags-select<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>define-key helm-gtags-mode-map <span style="color: #7388d6;">(</span>kbd <span style="color: #8b2252;">"M-."</span><span style="color: #7388d6;">)</span> 'helm-gtags-dwim<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>define-key helm-gtags-mode-map <span style="color: #7388d6;">(</span>kbd <span style="color: #8b2252;">"M-,"</span><span style="color: #7388d6;">)</span> 'helm-gtags-pop-stack<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>define-key helm-gtags-mode-map <span style="color: #7388d6;">(</span>kbd <span style="color: #8b2252;">"C-c <"</span><span style="color: #7388d6;">)</span> 'helm-gtags-previous-history<span style="color: #707183;">)</span>
<span style="color: #707183;">(</span>define-key helm-gtags-mode-map <span style="color: #7388d6;">(</span>kbd <span style="color: #8b2252;">"C-c >"</span><span style="color: #7388d6;">)</span> 'helm-gtags-next-history<span style="color: #707183;">)</span>
</pre>
</div>
<p>
Before using the <code>ggtags</code> or <code>helm-gtags</code>, remember to create a GTAGS
database by running <code>gtags</code> at your project root in terminal:
</p>
<div class="org-src-container">
<pre class="src src-shell-script">$ cd /path/to/project/root
$ gtags
</pre>
</div>
<p>
After this, a few files are created:
</p>
<div class="org-src-container">
<pre class="src src-shell-script">$ ls G*
GPATH GRTAGS GTAGS
</pre>
</div>
<ul class="org-ul">
<li><b>GTAGS</b>: definition database</li>
<li><b>GRTAGS</b>: reference database</li>
<li><b>GPATH</b>: path name database</li>
</ul>
<p>
If you use <code>ggtags</code>, you have a command for creating GTAGS database,
that is <code>ggtags-create-tags</code>; this is recommended way when using
<code>ggtags</code>, to let it know where the project root is.
</p>
</div>
</div>
<div id="outline-container-orgheadline3" class="outline-3">
<h3 id="orgheadline3"><a id="ID-45f1bb42-08e5-43b9-8ea9-7b5e1124f89e"></a>Basic movements</h3>
<div class="outline-text-3" id="text-orgheadline3">
<ul class="org-ul">
<li><p>
<b>C-M-f</b> runs <code>forward-sexp</code>, move forward over a balanced
expression that can be a pair or a symbol. Demo:
</p>
<div class="figure">
<p><a href="static/c-ide/forward-func.gif"><img src="static/c-ide/forward-func.gif" alt="forward-func.gif" /></a>
</p>
</div></li>
<li><p>
<b>C-M-b</b> runs <code>backward-sexp</code>, move backward over a balanced
expression that can be a pair or a symbol. Demo:
</p>
<div class="figure">
<p><a href="static/c-ide/backward-func.gif"><img src="static/c-ide/backward-func.gif" alt="backward-func.gif" /></a>
</p>
</div></li>
<li><p>
<b>C-M-k</b> runs <code>kill-sexp</code>, kill balanced expression
forward that can be a pair or a symbol. Demo:
</p>
<div class="figure">
<p><a href="static/c-ide/kill-func-body.gif"><img src="static/c-ide/kill-func-body.gif" alt="kill-func-body.gif" /></a>
</p>
</div></li>
<li><p>
<b>C-M-<SPC></b> or <b>C-M-@</b> runs <code>mark-sexp</code>, put mark after
following expression that can be a pair or a symbol. Demo:
</p>
<div class="figure">
<p><a href="static/c-ide/mark-func-body.gif"><img src="static/c-ide/mark-func-body.gif" alt="mark-func-body.gif" /></a>
</p>
</div></li>
<li><p>
<b>C-M-a</b> runs <code>beginning-of-defun</code>, which moves point to beginning of
a function. Demo:
</p>
<div class="figure">
<p><a href="static/c-ide/beginning-of-defun.gif"><img src="static/c-ide/beginning-of-defun.gif" alt="beginning-of-defun.gif" /></a>
</p>
</div></li>
<li><p>
<b>C-M-e</b> runs <code>end-of-defun</code>, which moves point to end of a
function. Demo:
</p>
<div class="figure">
<p><a href="static/c-ide/end-of-defun.gif"><img src="static/c-ide/end-of-defun.gif" alt="end-of-defun.gif" /></a>
</p>
</div></li>
<li><p>
<b>C-M-h</b> runs <code>mark-defun</code>, which put a region around whole current
or following function. Demo:
</p>
<div class="figure">
<p><a href="static/c-ide/mark-defun.gif"><img src="static/c-ide/mark-defun.gif" alt="mark-defun.gif" /></a>
</p>
</div></li>
</ul>
</div>
</div>
<div id="outline-container-orgheadline4" class="outline-3">
<h3 id="orgheadline4"><a id="ID-b4902a85-f303-4f5f-8c13-1eb3d2d2de73"></a>Basic concepts of tag</h3>
<div class="outline-text-3" id="text-orgheadline4">
<p>
A tag is a name of an entity in source code. An entity can be a
variable, a method definition, an include-operator… A tag contains
information such as name of the tag (the name of the variable,
class, method), location of this tag in source code and which file it
belongs to. As an example, GNU Global generates three tag databases:
</p>
<ul class="org-ul">
<li><b>GTAGS</b>: definition database</li>
<li><b>GRTAGS</b>: reference database</li>
<li><b>GPATH</b>: path name database</li>
</ul>
<p>
A definition of a tag is where a tag is implemented. For example, a
function definition is the body where it is actually implemented, or a
variable definition is where the type and its property (i.e static) is
specified.
</p>
<p>
A reference of a tag is where a tag is used in a source tree, but not
where it is defined.
</p>
</div>
</div>
<div id="outline-container-orgheadline5" class="outline-3">
<h3 id="orgheadline5"><a id="ID-3a64c7a4-e8a5-42b9-9476-28dff9e5cb96"></a>Find definitions in current buffer</h3>
<div class="outline-text-3" id="text-orgheadline5">
<p>
The Imenu facility offers a way to find the major definitions, such as
function definitions, variable definitions in a file by name. <code>ggtags</code>
can integrate Imenu:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #707183;">(</span><span style="color: #a020f0;">setq-local</span> imenu-create-index-function #'ggtags-build-imenu-index<span style="color: #707183;">)</span>
</pre>
</div>
<p>
If you use Helm, use <code>moo-jump-local</code> from <a href="https://github.com/abo-abo/function-args">function-args</a> package. You
can use it as an outline tree like in other IDEs. Here is a demo:
</p>
<div class="figure">
<p><a href="static/c-ide/moo-jump-local.gif"><img src="static/c-ide/moo-jump-local.gif" alt="moo-jump-local.gif" /></a>
</p>
</div>
</div>
</div>
<div id="outline-container-orgheadline6" class="outline-3">
<h3 id="orgheadline6"><a id="ID-0331265b-7c3f-457e-ba1d-ef6c3cd24208"></a>Find definitions in project</h3>
<div class="outline-text-3" id="text-orgheadline6">
<ul class="org-ul">
<li>Using <code>gtags</code>: by default, <code>M-.</code> runs <code>ggtags-find-tag-dwim</code> when
<code>ggtags-mode</code> is enabled. The command <code>ggtags-find-tag-dwim</code> jump to
tag base on context:
<ul class="org-ul">
<li>If the tag at point is a definition, <code>ggtags</code> jumps to a
reference. If there is more than one reference, it displays a list
of references.</li>
<li>If the tag at point is a reference, <code>ggtags</code> jumps to tag
definition.</li>
<li>If the tag at point is an include header, it jumps to that header.</li>
</ul></li>
</ul>
<p>
You can jump back to original location where you invoked
<code>ggtags-find-tag-dwim</code> by <code>M-,</code>, which runs <code>pop-tag-mark</code> (if you
follow my key bindings).
</p>
<p>
You can also find arbitrary tag definition when invoking <code>M-.</code> on
blank space. A prompt asks you for tag pattern, which is a regexp.
</p>
<p>
If <code>ggtags</code> gives you a list of candidates, you can use <code>M-n</code> to move
to next candidate and <code>M-p</code> to move back previous candidate. Use <code>M-g
s</code> to invoke Isearch on candidate buffer list.
</p>
<div class="org-center">
<div class="figure">
<p><a href="static/c-ide/ggtags-definitions.png"><img src="static/c-ide/ggtags-definitions.png" alt="ggtags-definitions.png" /></a>
</p>
</div>
<p>
(screenshot taken from <a href="https://github.com/leoliu/ggtags">ggtags</a>)
</p>
</div>
<ul class="org-ul">
<li>Using <code>helm-gtags</code>: If key bindings are properly setup as above,
<code>M-.</code> runs <code>helm-gtags-dwim</code>, which behaves the same as
<code>ggtags-find-tag-dwim</code>. Similarly, you jump back to original
location by using <code>M-,</code>, which runs <code>tags-loop-continue</code> (Emacs
default).</li>
</ul>
<div class="org-center">
<div class="figure">
<p><a href="static/c-ide/helm-gtags-definitions.png"><img src="static/c-ide/helm-gtags-definitions.png" alt="helm-gtags-definitions.png" /></a>
</p>
</div>
<p>
(screenshot taken from <a href="https://github.com/syohex/emacs-helm-gtags">helm-gtags</a>)
</p>
</div>
<p>
You can also find arbitrary tag definition when invoking <code>M-.</code> on
blank space. A prompt asks you for tag pattern, which is a
regexp.
</p>
<p>
<code>helm-gtags</code> provides a really nice feature that uses Helm to display
all available tags in a project and incrementally filtering, and is really
fast using <code>helm-gtags-select</code>, which is bound to <code>C-j</code> in my setup
above. This is useful when you want to explore tags in unfamiliar
project. Demo:
</p>
<div class="figure">
<p><a href="static/c-ide/helm-gtags-select.gif"><img src="static/c-ide/helm-gtags-select.gif" alt="helm-gtags-select.gif" /></a>
</p>
</div>
</div>
</div>
<div id="outline-container-orgheadline7" class="outline-3">
<h3 id="orgheadline7"><a id="ID-410cfad4-a08d-4139-8c37-cb1bff5bd44e"></a>Find references in project</h3>
<div class="outline-text-3" id="text-orgheadline7">
<ul class="org-ul">
<li>Using <code>ggtags</code>: Either run <code>ggtags-find-tag-dwim</code> or
<code>ggtags-find-reference</code>, which only finds references.</li>
<li>Using <code>helm-gtags</code>: Either run <code>helm-gtags-dwim</code> or
<code>helm-gtags-find-rtags</code>, bound to <b>C-c g r</b>, which only finds
references. Note that for <code>helm-gtags-find-rtags</code>:
<ul class="org-ul">
<li>if point is inside a function, the prompt will be default to the
function name.</li>
<li>If point is on a function, it lists references of that functions
immediately.</li>
<li>If point is on a variable, <code>helm-gtags-find-rtags</code> won't have any
effect. You should use <code>helm-gtags-find-symbol</code>, which is bound to
<b>C-c g s</b>.</li>
</ul></li>
</ul>
<p>
Find functions that calls function is actually a special case of
finding references. That is, you gather references for a function.
</p>
</div>
</div>
<div id="outline-container-orgheadline8" class="outline-3">
<h3 id="orgheadline8"><a id="ID-793aa930-0586-4dbe-9a10-55407be888f3"></a>Find functions that current functions call</h3>
<div class="outline-text-3" id="text-orgheadline8">
<p>
If you want to list all the functions that the current function - the
function that point is inside - calls, you can do that with
<code>helm-gtags-tags-in-this-function</code>, which is bound to <b>C-c g a</b> in my
setup.
</p>
</div>
</div>
<div id="outline-container-orgheadline9" class="outline-3">
<h3 id="orgheadline9"><a id="ID-b6c7d5a9-2fce-4488-a7d5-3eb301b6b89a"></a>Find files in project</h3>
<div class="outline-text-3" id="text-orgheadline9">
<ul class="org-ul">
<li>Using <code>ggtags</code>: Run <code>ggtags-find-file</code> to find a file from all the
files indexed. If point is on an included header file,
<code>ggtags-find-tag-dwim</code> automatically jumps to the file.</li>
<li>Using <code>helm-gtags</code>: Run <code>helm-gtags-find-files</code> to find files
matching regexp. If point is on an included header file,
<code>helm-gtags-dwim</code> automatically jumps to the file.</li>
</ul>
<p>
Alternatively, you have a more generic solution, that is using
Projectile. Projectile is a generic project management tool that you
learn later. With Projectile, jumping around version controlled
project like Linux kernel is a breeze, since you can jump to any file
regardless of where you are standing in the project.
</p>
</div>
</div>
<div id="outline-container-orgheadline10" class="outline-3">
<h3 id="orgheadline10"><a id="ID-db6bf87e-969d-42b8-ae60-b0b58f13e073"></a>View visited tags with tag stack</h3>
<div class="outline-text-3" id="text-orgheadline10">
<ul class="org-ul">
<li>Using <code>ggtags</code>: As you know that you can jump back with
<code>pop-tag-mark</code> (bound to <code>M-,</code>), you can also view a list of visited
tags using <code>ggtags-view-tag-history</code>, which is bound to <code>C-c g
h</code>. It displays visited tags from newest to oldest, that is from top
to bottom.</li>
<li>Using <code>helm-gtags</code>: Similarly, <code>helm-gtags</code> also has the command
<code>helm-gtags-show-stack</code> that shows visited tags from newest to
oldest, from top to bottom.</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-orgheadline11" class="outline-2">
<h2 id="orgheadline11"><a id="speedbar"></a>Browse source tree with <code>Speedbar</code> file browser</h2>
<div class="outline-text-2" id="text-orgheadline11">
<p>
If you want a static outline tree, Emacs also has a more one:
<code>Speedbar</code>. To use Speed bar, <code>M-x speedbar</code> and a frame that contains
a directory tree appear. In this directory, to the left of a file or
directory name is an icon with <code>+</code> sign in it. You can click the icon
to open the content of a node. If the node is a file, the children of
the files are tags (variable and function definitions) of the file; if
the node is a directory, the children of the node are files in that
directory. One important thing to remember, Speedbar only lists files
that match <code>speedbar-file-regexp</code>, that contains the extensions for
common programming languages. If you don't see files in your
programming languages listed, consider adding it the regexp list.
</p>
<p>
<b>Basic usage</b>:
</p>
<ul class="org-ul">
<li>Use <b>SPC</b> to open the children of a node.</li>
<li><b>RET</b> to open the node in another window. If node is a file, open
that file; if node is a directory, enter that directory; if node is
a tag in a file, jump to the location of that tag in the file.</li>
<li><b>U</b> to go up parent directory.</li>
<li><b>n</b> or <b>p</b> moves to next or previous node.</li>
<li><b>M-n</b> or <b>M-p</b> moves to next or previous node at the current level.</li>
<li><b>b</b> switches to buffer list using Speedbar presentation. You can
also open children of each buffer.</li>
<li><b>f</b> switches back to file list.</li>
</ul>
<p>
To enable <code>speedbar</code> to show all files:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #707183;">(</span><span style="color: #a020f0;">setq</span> speedbar-show-unknown-files t<span style="color: #707183;">)</span>
</pre>
</div>
</div>
<div id="outline-container-orgheadline12" class="outline-3">
<h3 id="orgheadline12"><a id="ID-1824d791-2592-4efa-90b7-845e6a68681d"></a>Package: <code>sr-speedbar</code></h3>
<div class="outline-text-3" id="text-orgheadline12">
<p>
However, you may feel that a frame is difficult to use. To solve this
issue, you need <code>sr-speedbar</code>, which can be installed via
MELPA.
</p>
<ul class="org-ul">
<li>To open <code>sr-speedbar</code>, execute the command <code>sr-speedbar-open</code> or
<code>sr-speedbar-toggle</code>.</li>
<li>To close <code>sr-speedbar</code>, execute the command <code>sr-speedbar-close</code> or
<code>sr-speedbar-toggle</code> again.</li>
</ul>
<p>
Best is to use <code>sr-speedbar-toggle</code> only, for simplicity.
</p>
<p>
<code>sr-speedbar</code> gives the following improvements:
</p>
<ul class="org-ul">
<li>Automatically switches directory tree - when you switch buffer - to
the <code>default-directory</code> of current buffer.</li>
<li>Use an Emacs window instead of frame, make it easier to use.</li>