-
Notifications
You must be signed in to change notification settings - Fork 0
/
xcscope.el
3007 lines (2610 loc) · 115 KB
/
xcscope.el
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
;;; xcscope.el --- cscope interface for (X)Emacs
;; Copyright (C) 2000-2002 Darryl Okahata
;; 2001 Triet H. Lai
;; 2001 Steven Elliott
;; 2013 Dima Kogan
;; Author: Darryl Okahata <[email protected]>
;; Dima Kogan <[email protected]>
;; Maintainer: Dima Kogan <[email protected]>
;; Keywords: languages c
;; Homepage: https://github.com/dkogan/xcscope.el
;; Package-Version: 1.0
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
;;
;;; Commentary:
;;
;; This is a cscope interface for (X)Emacs.
;; It currently runs under Unix only.
;;
;; Using cscope, you can easily search for where symbols are used and defined.
;; Cscope is designed to answer questions like:
;;
;; Where is this variable used?
;; What is the value of this preprocessor symbol?
;; Where is this function in the source files?
;; What functions call this function?
;; What functions are called by this function?
;; Where does the message "out of space" come from?
;; Where is this source file in the directory structure?
;; What files include this header file?
;; Where was this variable assigned-to?
;;
;; Send comments to [email protected]
;;
;;
;;
;; ***** INSTALLATION *****
;;
;; * NOTE: this interface currently runs under Unix only.
;;
;; Installation steps:
;;
;; 0. (It is, of course, assumed that cscope is already properly
;; installed on the current system.)
;;
;; 1. Install xcscope.el through your system package manager, MELPA or by
;; loading the file with
;;
;; (require 'xcscope)
;;
;; 2. Call (cscope-setup). This can go into the .emacs to always enable
;; xcscope.el at emacs startup
;;
;; 3. If you intend to use xcscope.el often you can optionally edit your
;; ~/.emacs file to add keybindings that reduce the number of keystrokes
;; required. For example, the following will add "C-f#" keybindings, which
;; are easier to type than the usual "C-c s" prefixed keybindings. Note
;; that specifying "global-map" instead of "cscope-minor-mode-keymap" makes the
;; keybindings available in all buffers:
;;
;;(define-key global-map [(control f3)] 'cscope-set-initial-directory)
;;(define-key global-map [(control f4)] 'cscope-unset-initial-directory)
;;(define-key global-map [(control f5)] 'cscope-find-this-symbol)
;;(define-key global-map [(control f6)] 'cscope-find-global-definition)
;;(define-key global-map [(control f7)]
;; 'cscope-find-global-definition-no-prompting)
;;(define-key global-map [(control f8)] 'cscope-pop-mark)
;;(define-key global-map [(control f9)] 'cscope-history-forward-line)
;;(define-key global-map [(control f10)] 'cscope-history-forward-file)
;;(define-key global-map [(control f11)] 'cscope-history-backward-line)
;;(define-key global-map [(control f12)] 'cscope-history-backward-file)
;; (define-key global-map [(meta f9)] 'cscope-display-buffer)
;; (define-key global-map [(meta f10)] 'cscope-display-buffer-toggle)
;;
;; 6. Restart (X)Emacs. That's it.
;;
;;
;;
;;
;; ***** USING THIS MODULE *****
;;
;; * Basic usage:
;;
;; If all of your C/C++/lex/yacc source files are in the same
;; directory, you can just start using this module. If your files are
;; spread out over multiple directories, see "Advanced usage", below.
;;
;; Just edit a source file, and use the pull-down or pop-up (button 3)
;; menus to select one of:
;;
;; Find symbol
;; Find global definition
;; Find called functions
;; Find functions calling a function
;; Find text string
;; Find egrep pattern
;; Find a file
;; Find files #including a file
;;
;; The cscope database will be automatically created in the same
;; directory as the source files (assuming that you've never used
;; cscope before), and a buffer will pop-up displaying the results.
;; You can then use button 2 (the middle button) on the mouse to edit
;; the selected file, or you can move the text cursor over a selection
;; and press [Enter].
;;
;; The third mouse button is bound to a popup menu for cscope. Shift-mouse
;; button 3 invokes the last find command again. E.g. if you look for the symbol
;; 'main' and afterwards you want to look for another symbol, just press Shift
;; and click the third button.
;;
;; Each cscope search adds its results to the *cscope* buffer. These sets of
;; results can be navigated and manupulated similar to patches in diff-mode.:
;;
;; - n/p navigates over individual results
;; - k kills individual results
;;
;; - N/P or M-n/M-p navigates over file results
;; - M-k kills file results
;;
;; - M-N/M-P navigates over result sets
;; - M-K kills result sets
;;
;; - Navigation from outside the *cscope* buffer (C-c s n/p/N/P) is restricted to
;; the result set at (point)
;;
;; Any result set in the *cscope* buffer can be re-run with the 'r' key.
;;
;;
;; * Locating the cscope databases:
;;
;; This module will first use the variable, `cscope-database-regexps', to search
;; for a suitable database directory. If a database location cannot be found
;; using this variable then a search is begun at the variable,
;; `cscope-initial-directory', if set. If not set and we're running this search
;; from the *cscope* buffer, the search is begun from the directory of the
;; search at point. Otherwise, the current directory is used. If the directory
;; is not a cscope database directory then the directory's parent, parent's
;; parent, etc. is searched until a cscope database directory is found, or the
;; root directory is reached. If the root directory is reached, the current
;; directory will be used.
;;
;; A cscope database directory is one in which EITHER a cscope database
;; file (e.g., "cscope.out") OR a cscope file list (e.g.,
;; "cscope.files") exists. If only "cscope.files" exists, the
;; corresponding "cscope.out" will be automatically created by cscope
;; when a search is done. By default, the cscope database file is called
;; "cscope.out", but this can be changed (on a global basis) via the
;; variable, `cscope-database-file'. There is limited support for cscope
;; databases that are named differently than that given by
;; `cscope-database-file', using the variable, `cscope-database-regexps'.
;;
;; Note that the variable, `cscope-database-regexps', is generally not
;; needed, as the normal hierarchical database search is sufficient
;; for placing and/or locating the cscope databases. However, there
;; may be cases where it makes sense to place the cscope databases
;; away from where the source files are kept; in this case, this
;; variable is used to determine the mapping. One use for this
;; variable is when you want to share the database file with other
;; users; in this case, the database may be located in a directory
;; separate from the source files.
;;
;; Setting the variable, `cscope-initial-directory', is useful when a
;; search is to be expanded by specifying a cscope database directory
;; that is a parent of the directory that this module would otherwise
;; use. For example, consider a project that contains the following
;; cscope database directories:
;;
;; /users/jdoe/sources
;; /users/jdoe/sources/proj1
;; /users/jdoe/sources/proj2
;;
;; If a search is initiated from a .c file in /users/jdoe/sources/proj1
;; then (assuming the variable, `cscope-database-regexps', is not set)
;; /users/jdoe/sources/proj1 will be used as the cscope data base directory.
;; Only matches in files in /users/jdoe/sources/proj1 will be found. This
;; can be remedied by typing "C-c s a" and then "M-del" to remove single
;; path element in order to use a cscope database directory of
;; /users/jdoe/sources. Normal searching can be restored by typing "C-c s A".
;;
;;
;; * Keybindings:
;;
;; All keybindings use the "C-c s" prefix, but are usable only while
;; editing a source file, or in the cscope results buffer:
;;
;; C-c s s Find symbol.
;; C-c s = Find assignments to this symbol
;; C-c s d Find global definition.
;; C-c s g Find global definition (alternate binding).
;; C-c s G Find global definition without prompting.
;; C-c s c Find functions calling a function.
;; C-c s C Find called functions (list functions called
;; from a function).
;; C-c s t Find text string.
;; C-c s e Find egrep pattern.
;; C-c s f Find a file.
;; C-c s i Find files #including a file.
;;
;; These pertain to navigation through the search results:
;;
;; C-c s b Display *cscope* buffer.
;; C-c s B Auto display *cscope* buffer toggle.
;; C-c s n Next symbol.
;; C-c s N Next file.
;; C-c s p Previous symbol.
;; C-c s P Previous file.
;; C-c s u Pop mark.
;;
;; These pertain to setting and unsetting the variable,
;; `cscope-initial-directory', (location searched for the cscope database
;; directory):
;;
;; C-c s a Set initial directory.
;; C-c s A Unset initial directory.
;;
;; These pertain to cscope database maintenance:
;;
;; C-c s L Create list of files to index.
;; C-c s I Create list and index.
;; C-c s E Edit list of files to index.
;; C-c s W Locate this buffer's cscope directory
;; ("W" --> "where").
;; C-c s S Locate this buffer's cscope directory.
;; (alternate binding: "S" --> "show").
;; C-c s T Locate this buffer's cscope directory.
;; (alternate binding: "T" --> "tell").
;; C-c s D Dired this buffer's directory.
;;
;;
;; * Advanced usage:
;;
;; If the source files are spread out over multiple directories,
;; you've got a few choices:
;;
;; 1. If all of the directories exist below a common directory
;; (without any extraneous, unrelated subdirectories), you can tell
;; this module to place the cscope database into the top-level,
;; common directory. This assumes that you do not have any cscope
;; databases in any of the subdirectories. If you do, you should
;; delete them; otherwise, they will take precedence over the
;; top-level database.
;;
;; If you do have cscope databases in any subdirectory, the
;; following instructions may not work right.
;;
;; It's pretty easy to tell this module to use a top-level, common
;; directory:
;;
;; a. Make sure that the menu pick, "Cscope/Index recursively", is
;; checked (the default value).
;;
;; b. Select the menu pick, "Cscope/Create list and index", and
;; specify the top-level directory. This will index the sources
;; in the background, so you can do other things if indexing
;; takes a long time. A list of files to index will be created in
;; "cscope.files", and the cscope database will be created in
;; "cscope.out".
;;
;; Once this has been done, you can then use the menu picks
;; (described in "Basic usage", above) to search for symbols.
;;
;; Note, however, that, if you add or delete source files, you'll
;; have to either rebuild the database using the above procedure,
;; or edit the file, "cscope.files" to add/delete the names of the
;; source files. To edit this file, you can use the menu pick,
;; "Cscope/Edit list of files to index".
;;
;;
;; 2. If most of the files exist below a common directory, but a few
;; are outside, you can use the menu pick, "Cscope/Create list of
;; files to index", and specify the top-level directory. Make sure
;; that "Cscope/Index recursively", is checked before you do so,
;; though. You can then edit the list of files to index using the
;; menu pick, "Cscope/Edit list of files to index". Just edit the
;; list to include any additional source files not already listed.
;;
;; Once you've created, edited, and saved the list, you can then
;; use the menu picks described under "Basic usage", above, to
;; search for symbols. The first time you search, you will have to
;; wait a while for cscope to fully index the source files, though.
;; If you have a lot of source files, you may want to manually run
;; cscope to build the database:
;;
;; cd top-level-directory # or wherever
;; rm -f cscope.out # not always necessary
;; cscope -b
;;
;;
;; 3. If the source files are scattered in many different, unrelated
;; places, you'll have to manually create cscope.files and put a
;; list of all pathnames into it. Then build the database using:
;;
;; cd some-directory # wherever cscope.files exists
;; rm -f cscope.out # not always necessary
;; cscope -b
;;
;; Next, read the documentation for the variable,
;; "cscope-database-regexps", and set it appropriately, such that
;; the above-created cscope database will be referenced when you
;; edit a related source file.
;;
;; Once this has been done, you can then use the menu picks
;; described under "Basic usage", above, to search for symbols.
;;
;;
;; * Interesting configuration variables:
;;
;; "cscope-truncate-lines"
;; This is the value of `truncate-lines' to use in cscope
;; buffers; the default is the current setting of
;; `truncate-lines'. This variable exists because it can be
;; easier to read cscope buffers with truncated lines, while
;; other buffers do not have truncated lines.
;;
;; "cscope-use-relative-paths"
;; If non-nil, use relative paths when creating the list of files
;; to index. The path is relative to the directory in which the
;; cscope database will be created. If nil, absolute paths will
;; be used. Absolute paths are good if you plan on moving the
;; database to some other directory (if you do so, you'll
;; probably also have to modify `cscope-database-regexps').
;; Absolute paths may also be good if you share the database file
;; with other users (you'll probably want to specify some
;; automounted network path for this).
;;
;; "cscope-index-recursively"
;; If non-nil, index files in the current directory and all
;; subdirectories. If nil, only files in the current directory
;; are indexed. This variable is only used when creating the
;; list of files to index, or when creating the list of files and
;; the corresponding cscope database.
;;
;; "cscope-name-line-width"
;; The width of the combined "function name:line number" field in
;; the cscope results buffer. If negative, the field is
;; left-justified.
;;
;; "cscope-option-...." Various options passed to the 'cscope' process. Controls
;; things like include directories, database compression, database type,
;; etc.
;;
;; "cscope-display-cscope-buffer"
;; If non-nil, display the *cscope* buffer after each search
;; (default). This variable can be set in order to reduce the
;; number of keystrokes required to navigate through the matches.
;;
;; "cscope-database-regexps"
;; List to force directory-to-cscope-database mappings.
;; This is a list of `(REGEXP DBLIST [ DBLIST ... ])', where:
;;
;; REGEXP is a regular expression matched against the current buffer's
;; current directory. The current buffer is typically some source file,
;; and you're probably searching for some symbol in or related to this
;; file. Basically, this regexp is used to relate the current directory
;; to a cscope database. You need to start REGEXP with "^" if you want
;; to match from the beginning of the current directory.
;;
;; DBLIST is a list that contains one or more of:
;;
;; ( DBDIR )
;; ( DBDIR ( OPTIONS ) )
;; ( t )
;; t
;;
;; Here, DBDIR is a directory (or a file) that contains a cscope
;; database. If DBDIR is a directory, then it is expected that the
;; cscope database, if present, has the filename given by the variable,
;; `cscope-database-file'; if DBDIR is a file, then DBDIR is the path
;; name to a cscope database file (which does not have to be the same as
;; that given by `cscope-database-file'). If only DBDIR is specified,
;; then that cscope database will be searched without any additional
;; cscope command-line options. If OPTIONS is given, then OPTIONS is a
;; list of strings, where each string is a separate cscope command-line
;; option.
;;
;; In the case of "( t )", this specifies that the search is to use the
;; normal hierarchical database search. This option is used to
;; explicitly search using the hierarchical database search either before
;; or after other cscope database directories.
;;
;; If "t" is specified (not inside a list), this tells the searching
;; mechanism to stop searching if a match has been found (at the point
;; where "t" is encountered). This is useful for those projects that
;; consist of many subprojects. You can specify the most-used
;; subprojects first, followed by a "t", and then followed by a master
;; cscope database directory that covers all subprojects. This will
;; cause the most-used subprojects to be searched first (hopefully
;; quickly), and the search will then stop if a match was found. If not,
;; the search will continue using the master cscope database directory.
;;
;; Here, `cscope-database-regexps' is generally not used, as the normal
;; hierarchical database search is sufficient for placing and/or locating
;; the cscope databases. However, there may be cases where it makes
;; sense to place the cscope databases away from where the source files
;; are kept; in this case, this variable is used to determine the
;; mapping.
;;
;; This module searches for the cscope databases by first using this
;; variable; if a database location cannot be found using this variable,
;; then the current directory is searched, then the parent, then the
;; parent's parent, until a cscope database directory is found, or the
;; root directory is reached. If the root directory is reached, the
;; current directory will be used.
;;
;; A cscope database directory is one in which EITHER a cscope database
;; file (e.g., "cscope.out") OR a cscope file list (e.g.,
;; "cscope.files") exists. If only "cscope.files" exists, the
;; corresponding "cscope.out" will be automatically created by cscope
;; when a search is done. By default, the cscope database file is called
;; "cscope.out", but this can be changed (on a global basis) via the
;; variable, `cscope-database-file'. There is limited support for cscope
;; databases that are named differently than that given by
;; `cscope-database-file', using the variable, `cscope-database-regexps'.
;;
;; Here is an example of `cscope-database-regexps':
;;
;;(setq cscope-database-regexps
;; '(
;;( "^/users/jdoe/sources/proj1"
;; ( t )
;; ( "/users/jdoe/sources/proj2")
;; ( "/users/jdoe/sources/proj3/mycscope.out")
;; ( "/users/jdoe/sources/proj4")
;; t
;; ( "/some/master/directory" ("-d" "-I/usr/local/include") )
;; )
;;( "^/users/jdoe/sources/gnome/"
;; ( "/master/gnome/database" ("-d") )
;; )
;;))
;;
;; If the current buffer's directory matches the regexp,
;; "^/users/jdoe/sources/proj1", then the following search will be
;; done:
;;
;; 1. First, the normal hierarchical database search will be used to
;; locate a cscope database.
;;
;; 2. Next, searches will be done using the cscope database
;; directories, "/users/jdoe/sources/proj2",
;; "/users/jdoe/sources/proj3/mycscope.out", and
;; "/users/jdoe/sources/proj4". Note that, instead of the file,
;; "cscope.out", the file, "mycscope.out", will be used in the
;; directory "/users/jdoe/sources/proj3".
;;
;; 3. If a match was found, searching will stop.
;;
;; 4. If a match was not found, searching will be done using
;; "/some/master/directory", and the command-line options "-d"
;; and "-I/usr/local/include" will be passed to cscope.
;;
;; If the current buffer's directory matches the regexp,
;; "^/users/jdoe/sources/gnome", then the following search will be
;; done:
;;
;; The search will be done only using the directory,
;; "/master/gnome/database". The "-d" option will be passed to
;; cscope.
;;
;; If the current buffer's directory does not match any of the above
;; regexps, then only the normal hierarchical database search will be
;; done.
;;
;;
;; * Other notes:
;;
;; 1. This module is called, "xcscope", because someone else has
;; already written a "cscope.el" (although it's quite old).
;;
;;
;; * KNOWN BUGS:
;;
;; 1. Cannot handle whitespace in directory or file names.
;;
;; 2. The support for cscope databases different from that specified by
;; `cscope-database-file' is quirky. If the file does not exist, it
;; will not be auto-created (unlike files names by
;; `cscope-database-file'). You can manually force the file to be
;; created by using touch(1) to create a zero-length file; the
;; database will be created the next time a search is done.
;;
;;; Code:
(require 'easymenu)
(defgroup cscope nil
"Cscope interface for (X)Emacs.
Using cscope, you can easily search for where symbols are used and defined.
It is designed to answer questions like:
Where is this variable used?
What is the value of this preprocessor symbol?
Where is this function in the source files?
What functions call this function?
What functions are called by this function?
Where does the message \"out of space\" come from?
Where is this source file in the directory structure?
What files include this header file?
"
:prefix "cscope-"
:group 'tools)
(defcustom cscope-option-include-directories nil
"The -I option in cscope: add these directories to the list of
search paths for #include, similar to the -I gcc option"
:type '(repeat directory)
:group 'cscope)
(defcustom cscope-option-disable-compression nil
"The -c option in cscope: use an uncompressed, ASCII database"
:type 'boolean
:group 'cscope)
(defcustom cscope-option-kernel-mode nil
"The -k option in cscope: use no system-wide include paths.
Useful for self-contained codebases, such as a kernel"
:type 'boolean
:group 'cscope)
(defcustom cscope-option-use-inverted-index nil
"The -q option in cscope: use an inverted database index. Takes
longer to build, but results in faster lookups. Useful for very
large codebases"
:type 'boolean
:group 'cscope)
(defcustom cscope-option-do-not-update-database nil
"The -d option in cscope: never check and/or update the cscope
database when searching. Beware of setting this to non-nil, as
this will disable automatic database creation, updating, and
maintenance."
:type 'boolean
:group 'cscope)
(defcustom cscope-option-other nil
"Any indexing/lookup options to pass to cscope. These are used
both when building the database and when searching. Note that the
most common options have specific customization in the
cscope-option-* variables, and it is preferable to use those"
:type '(repeat string)
:group 'cscope)
(defcustom cscope-database-regexps nil
"List to force directory-to-cscope-database mappings.
This is a list of `(REGEXP DBLIST [ DBLIST ... ])', where:
REGEXP is a regular expression matched against the current buffer's
current directory. The current buffer is typically some source file,
and you're probably searching for some symbol in or related to this
file. Basically, this regexp is used to relate the current directory
to a cscope database. You need to start REGEXP with \"^\" if you want
to match from the beginning of the current directory.
DBLIST is a list that contains one or more of:
( DBDIR )
( DBDIR ( OPTIONS ) )
( t )
t
Here, DBDIR is a directory (or a file) that contains a cscope database.
If DBDIR is a directory, then it is expected that the cscope database,
if present, has the filename given by the variable,
`cscope-database-file'; if DBDIR is a file, then DBDIR is the path name
to a cscope database file (which does not have to be the same as that
given by `cscope-database-file'). If only DBDIR is specified, then that
cscope database will be searched without any additional cscope
command-line options. If OPTIONS is given, then OPTIONS is a list of
strings, where each string is a separate cscope command-line option.
In the case of \"( t )\", this specifies that the search is to use the
normal hierarchical database search. This option is used to
explicitly search using the hierarchical database search either before
or after other cscope database directories.
If \"t\" is specified (not inside a list), this tells the searching
mechanism to stop searching if a match has been found (at the point
where \"t\" is encountered). This is useful for those projects that
consist of many subprojects. You can specify the most-used
subprojects first, followed by a \"t\", and then followed by a master
cscope database directory that covers all subprojects. This will
cause the most-used subprojects to be searched first (hopefully
quickly), and the search will then stop if a match was found. If not,
the search will continue using the master cscope database directory.
Here, `cscope-database-regexps' is generally not used, as the normal
hierarchical database search is sufficient for placing and/or locating
the cscope databases. However, there may be cases where it makes
sense to place the cscope databases away from where the source files
are kept; in this case, this variable is used to determine the
mapping.
This module searches for the cscope databases by first using this
variable; if a database location cannot be found using this variable,
then the current directory is searched, then the parent, then the
parent's parent, until a cscope database directory is found, or the
root directory is reached. If the root directory is reached, the
current directory will be used.
A cscope database directory is one in which EITHER a cscope database
file (e.g., \"cscope.out\") OR a cscope file list (e.g.,
\"cscope.files\") exists. If only \"cscope.files\" exists, the
corresponding \"cscope.out\" will be automatically created by cscope
when a search is done. By default, the cscope database file is called
\"cscope.out\", but this can be changed (on a global basis) via the
variable, `cscope-database-file'. There is limited support for cscope
databases that are named differently than that given by
`cscope-database-file', using the variable, `cscope-database-regexps'.
Here is an example of `cscope-database-regexps':
(setq cscope-database-regexps
'(
( \"^/users/jdoe/sources/proj1\"
( t )
( \"/users/jdoe/sources/proj2\")
( \"/users/jdoe/sources/proj3/mycscope.out\")
( \"/users/jdoe/sources/proj4\")
t
( \"/some/master/directory\" (\"-d\" \"-I/usr/local/include\") )
)
( \"^/users/jdoe/sources/gnome/\"
( \"/master/gnome/database\" (\"-d\") )
)
))
If the current buffer's directory matches the regexp,
\"^/users/jdoe/sources/proj1\", then the following search will be
done:
1. First, the normal hierarchical database search will be used to
locate a cscope database.
2. Next, searches will be done using the cscope database
directories, \"/users/jdoe/sources/proj2\",
\"/users/jdoe/sources/proj3/mycscope.out\", and
\"/users/jdoe/sources/proj4\". Note that, instead of the file,
\"cscope.out\", the file, \"mycscope.out\", will be used in the
directory \"/users/jdoe/sources/proj3\".
3. If a match was found, searching will stop.
4. If a match was not found, searching will be done using
\"/some/master/directory\", and the command-line options \"-d\"
and \"-I/usr/local/include\" will be passed to cscope.
If the current buffer's directory matches the regexp,
\"^/users/jdoe/sources/gnome\", then the following search will be
done:
The search will be done only using the directory,
\"/master/gnome/database\". The \"-d\" option will be passed to
cscope.
If the current buffer's directory does not match any of the above
regexps, then only the normal hierarchical database search will be
done.
"
:type '(repeat (list :format "%v"
(choice :value ""
(regexp :tag "Buffer regexp")
string)
(choice :value ""
(directory :tag "Cscope database directory")
string)
(string :value ""
:tag "Optional cscope command-line arguments")
))
:group 'cscope)
(defcustom cscope-name-line-width -30
"The width of the combined \"function name:line number\" field in the
cscope results buffer. If negative, the field is left-justified."
:type 'integer
:group 'cscope)
(defcustom cscope-truncate-lines truncate-lines
"The value of `truncate-lines' to use in cscope buffers.
This variable exists because it can be easier to read cscope buffers
with truncated lines, while other buffers do not have truncated lines."
:type 'boolean
:group 'cscope)
(defcustom cscope-display-times t
"If non-nil, display how long each search took.
The elasped times are in seconds. Floating-point support is required
for this to work."
:type 'boolean
:group 'cscope)
(defcustom cscope-max-cscope-buffer-size 1000000
"If >0, limit the size of the *cscope* buffer. Only the
'cscope-max-cscope-buffer-size' bytes at the end are kept,
rounded up to keep whole sets of cscope output"
:type 'integer
:group 'cscope)
(defcustom cscope-program "cscope"
"The pathname of the cscope executable to use."
:type 'string
:group 'cscope)
(defcustom cscope-index-file "cscope.files"
"The name of the cscope file list file."
:type 'string
:group 'cscope)
(defcustom cscope-database-file "cscope.out"
"The name of the cscope database file."
:type 'string
:group 'cscope)
(defcustom cscope-edit-single-match t
"If non-nil and only one match is output, edit the matched location."
:type 'boolean
:group 'cscope)
(defcustom cscope-display-cscope-buffer t
"If non-nil automatically display the *cscope* buffer after each search."
:type 'boolean
:group 'cscope)
(defcustom cscope-stop-at-first-match-dir nil
"If non-nil, stop searching through multiple databases if a match is found.
This option is useful only if multiple cscope database directories are being
used. When multiple databases are searched, setting this variable to non-nil
will cause searches to stop when a search outputs anything; no databases after
this one will be searched."
:type 'boolean
:group 'cscope)
(defcustom cscope-use-relative-paths t
"If non-nil, use relative paths when creating the list of files to index.
The path is relative to the directory in which the cscope database
will be created. If nil, absolute paths will be used. Absolute paths
are good if you plan on moving the database to some other directory
(if you do so, you'll probably also have to modify
\`cscope-database-regexps\'). Absolute paths may also be good if you
share the database file with other users (you\'ll probably want to
specify some automounted network path for this)."
:type 'boolean
:group 'cscope)
(defcustom cscope-index-recursively t
"If non-nil, index files in the current directory and all subdirectories.
If nil, only files in the current directory are indexed. This
variable is only used when creating the list of files to index, or
when creating the list of files and the corresponding cscope database."
:type 'boolean
:group 'cscope)
(defcustom cscope-indexer-ignored-directories '("CVS"
"RCS"
"SCCS"
".git"
".hg"
".bzr"
".cdv"
".pc"
".svn"
"_MTN"
"_darcs"
"_sgbak"
"debian")
"List of directory names that should be ignored when building a
cscope index. These are mostly version-control directories"
:type '(repeat string)
:group 'cscope)
(defcustom cscope-indexer-suffixes '("*.[chly]"
"*.[ch]xx"
"*.[ch]pp"
"*.cc"
"*.hh")
"List of file suffixes to index. By default these are C, C++,
Lex and Yacc source. These are globs accepted by 'find -iname'"
:type '(repeat string)
:group 'cscope)
(defcustom cscope-symbol-chars "A-Za-z0-9_"
"A string containing legal characters in a symbol.
The current syntax table should really be used for this."
:type 'string
:group 'cscope)
(defcustom cscope-filename-chars "-.,/A-Za-z0-9_~!@#$%&+=\\\\"
"A string containing legal characters in a symbol.
The current syntax table should really be used for this."
:type 'string
:group 'cscope)
(defcustom cscope-allow-arrow-overlays t
"If non-nil, use an arrow overlay to show target lines.
Arrow overlays are only used when the following functions are used:
cscope-show-entry-other-window
cscope-show-next-entry-other-window
cscope-show-prev-entry-other-window
The arrow overlay is removed when other cscope functions are used.
Note that the arrow overlay is not an actual part of the text, and can
be removed by quitting the cscope buffer."
:type 'boolean
:group 'cscope)
(defcustom cscope-overlay-arrow-string "=>"
"The overlay string to use when displaying arrow overlays."
:type 'string
:group 'cscope)
(defcustom cscope-close-window-after-select nil
"If non-nil close the window showing the cscope buffer after an entry has been selected."
:type 'boolean
:group 'cscope)
(defvar cscope-minor-mode-hooks nil
"List of hooks to call when entering cscope-minor-mode.")
(defconst cscope-result-separator
"===============================================================================\n"
"Line of text to use as a visual separator.
Must end with a newline. Must work as a regex without quoting")
(defconst cscope-file-separator-start-regex
"\\*\\*\\* .*:\n"
"Regex to match a file-start separator. This has to match the
'***' that xcscope.el normally outputs. This is assumed to appear
at the start of a line, so the leading ^ must be omitted")
(defconst cscope-file-separator-end-regex
"\n"
"Regex to match a file-end separator. This is just an empty
line, and this has to match what xcscope.el normally outputs in
its 'cscope-process-filter'. This is assumed to appear at the
start of a line, so the leading ^ must be omitted")
;;;;
;;;; Faces for fontification
;;;;
(defcustom cscope-use-face t
"Whether to use text highlighting (like font-lock) or not."
:group 'cscope
:type '(boolean))
(defface cscope-file-face
'((((class color) (background dark))
(:foreground "yellow"))
(((class color) (background light))
(:foreground "blue"))
(t (:bold t)))
"Face used to highlight file name in the *cscope* buffer."
:group 'cscope)
(defface cscope-function-face
'((((class color) (background dark))
(:foreground "cyan"))
(((class color) (background light))
(:foreground "magenta"))
(t (:bold t)))
"Face used to highlight function name in the *cscope* buffer."
:group 'cscope)
(defface cscope-line-number-face
'((((class color) (background dark))
(:foreground "red"))
(((class color) (background light))
(:foreground "red"))
(t (:bold t)))
"Face used to highlight line number in the *cscope* buffer."
:group 'cscope)
(defface cscope-mouse-face
'((((class color) (background dark))
(:foreground "white" :background "blue"))
(((class color) (background light))
(:foreground "white" :background "blue"))
(t (:bold nil)))
"Face used when mouse pointer is within the region of an entry."
:group 'cscope)
(defface cscope-separator-face
'((((class color) (background dark))
(:bold t :overline t :underline t :foreground "red"))
(((class color) (background light))
(:bold t :overline t :underline t :foreground "red"))
(t (:bold t)))
"Face used to highlight the separator in the *cscope* buffer."
:group 'cscope)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Probably, nothing user-customizable past this point.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defconst cscope-running-in-xemacs (string-match "XEmacs\\|Lucid" emacs-version))
(defconst cscope-start-file-process (if cscope-running-in-xemacs 'start-process 'start-file-process)
"The function used to launch external processes. Xemacs doesn't
have full TRAMP support here, so the less featureful function is
selected for it")
(defvar cscope-list-entry-keymap
(let ((map (make-keymap)))
(suppress-keymap map)
;; The following section does not appear in the "Cscope" menu.
(if cscope-running-in-xemacs
(progn
(define-key map [button2] 'cscope-mouse-select-entry-other-window)
(define-key map [(shift button2)] 'cscope-mouse-select-entry-inplace))
(define-key map [mouse-2] 'cscope-mouse-select-entry-other-window)
(define-key map [S-mouse-2] 'cscope-mouse-select-entry-inplace))
;; \r is for the text-mode console emacs
(define-key map [return] 'cscope-select-entry-other-window)
(define-key map "\r" 'cscope-select-entry-other-window)
;; this works for the graphics emacsen-only. Default xterm on Debian does
;; not know how to see this key combination
(define-key map (kbd "<S-return>") 'cscope-select-entry-inplace)
(define-key map " " 'cscope-show-entry-other-window)
(define-key map "o" 'cscope-select-entry-one-window)
(define-key map "q" 'cscope-bury-buffer)
(define-key map "Q" 'cscope-quit)
(define-key map "h" 'cscope-help)
(define-key map "?" 'cscope-help)
;; The following line corresponds to be beginning of the "Cscope" menu.
(define-key map "s" 'cscope-find-this-symbol)
(define-key map "d" 'cscope-find-this-symbol)
(define-key map "g" 'cscope-find-global-definition)
(define-key map "G" 'cscope-find-global-definition-no-prompting)
(define-key map "=" 'cscope-find-assignments-to-this-symbol)
(define-key map "c" 'cscope-find-functions-calling-this-function)
(define-key map "C" 'cscope-find-called-functions)
(define-key map "t" 'cscope-find-this-text-string)
(define-key map "e" 'cscope-find-egrep-pattern)
(define-key map "f" 'cscope-find-this-file)
(define-key map "i" 'cscope-find-files-including-file)
;; --- (The '---' indicates that this line corresponds to a menu separator.)
(define-key map (kbd "p") 'cscope-history-backward-line)
(define-key map (kbd "M-p") 'cscope-history-backward-file)
(define-key map (kbd "P") 'cscope-history-backward-file)
(define-key map (kbd "M-P") 'cscope-history-backward-result)
(define-key map (kbd "n") 'cscope-history-forward-line)
(define-key map (kbd "M-n") 'cscope-history-forward-file)
(define-key map (kbd "N") 'cscope-history-forward-file)
(define-key map (kbd "M-N") 'cscope-history-forward-result)
(define-key map (kbd "k") 'cscope-history-kill-line)
(define-key map (kbd "M-k") 'cscope-history-kill-file)
(define-key map (kbd "M-K") 'cscope-history-kill-result)
(define-key map "u" 'cscope-pop-mark)
;; ---
(define-key map "r" 'cscope-rerun-search-at-point)
;; ---
(define-key map "a" 'cscope-set-initial-directory)
(define-key map "A" 'cscope-unset-initial-directory)
;; ---
(define-key map "L" 'cscope-create-list-of-files-to-index)
(define-key map "I" 'cscope-index-files)
(define-key map "E" 'cscope-edit-list-of-files-to-index)
(define-key map "W" 'cscope-tell-user-about-directory)