-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsimple-call-tree.el
3128 lines (2942 loc) · 144 KB
/
simple-call-tree.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
;;; simple-call-tree.el --- analyze source code based on font-lock text-properties
;; Filename: simple-call-tree.el
;; Description: analyze source code based on font-lock text-properties
;; Author: Joe Bloggs <[email protected]>
;; Maintainer: Joe Bloggs <[email protected]>
;; Copyleft (Ↄ) 2012, Joe Bloggs, all rites reversed.
;; Created: 2012-11-01 21:28:07
;; Version: 20151116.1603
;; Package-Requires: ((emacs "24.3") (anaphora "1.0.0"))
;; Last-Updated: Mon Nov 16 16:03:18 2015
;; By: Joe Bloggs
;; URL: http://www.emacswiki.org/emacs/download/simple-call-tree.el
;; https://github.com/vapniks/simple-call-tree
;; Keywords: programming
;; Compatibility: GNU Emacs 24.3
;;
;; Features that might be required by this library:
;;
;; `anaphora' `thingatpt' `outshine' `fm' `org' `cl' `ido' `newcomment'
;;
;;; This file is NOT part of GNU Emacs
;;; License
;;
;; 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 3, 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 this program; see the file COPYING.
;; If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Bitcoin donations gratefully accepted: 1AmWPmshr6i9gajMi1yqHgx7BYzpPKuzMz
;;;; Introduction:
;; This library is based on simple-call-tree.el by Alex Schroeder, but you
;; do not need that library to use it (this is a replacement).
;; It displays a buffer containing a call tree for functions in source
;; code files. You can easily & quickly navigate the call tree, displaying
;; the code in another window, and apply query-replace or other commands
;; to individual functions.
;; When the command `simple-call-tree-display-buffer' or `simple-call-tree-current-function'
;; is executed a call tree for the functions in the current buffer will be created,
;; and in the latter case the point in the call tree is placed on the header
;; closest to its position in the original buffer.
;; If called with a prefix arg the user is also prompted for other files to include
;; in the call tree.
;; By default the call tree is displayed in a buffer called *Simple Call Tree: <BUFNAME>*,
;; where <BUFNAME> is the name of the buffer that the call tree was created from.
;; There is a dedicated menu in the menu-bar showing various commands
;; and their keybindings. Most of these commands are self explanatory
;; so try them out.
;;;; Navigation:
;; You can navigate the call tree either by moving through consecutive
;; headers (n/p or N/P keys) or by jumping to main branches (j for branch
;; corresponding to function at point, and J to prompt for a function).
;; When you jump to a branch, it is added to `simple-call-tree-jump-ring',
;; and you can navigate your jump history using the </> keys.
;; You can also add the function under point to the jump-ring with the . key.
;; If you use a negative prefix (e.g. C--) before pressing j then the branch
;; jumped to will not be added to the jump-ring.
;; If you have fm.el (available here: http://www.damtp.cam.ac.uk/user/sje30/emacs/fm.el)
;; you can press f to toggle follow mode on/off.
;;;; Display
;; Normally child branches correspond to functions/variables called by the parent
;; branch. However, if you invert the tree by pressing i then the child branches
;; will correspond to functions that call the parent branch.
;; You can sort the tree in various different ways, and change the depth of the tree.
;; You can narrow the tree to the function at point by pressing /
;; You can display extra information such as docstrings next to each item in the tree
;; by pressing C-c C-n, and customize the types of information that can be displayed
;; (see `simple-call-tree-notes-functions').
;;;; Exporting:
;; The tree can be exported in its current state with the `simple-call-tree-export-org-tree'
;; command, and you can alter the types of links with the `simple-call-tree-org-link-style' option.
;; This may be useful for project management.
;;;; Refactoring
;; You can perform `query-replace' or `query-replace-regexp' on the function at
;; point by pressing % or C-%, or any other arbitrary command by pressing !
;; This may be useful when refactoring.
;;; Commands:
;;
;; Below is a complete list of commands:
;;
;; `simple-call-tree-mode'
;; The major-mode for the one-key menu buffer.
;; Keybinding: M-x simple-call-tree-mode
;; `simple-call-tree-next-todo'
;; Move to next todo state for current function.
;; Keybinding: <S-right>
;; `simple-call-tree-prev-todo'
;; Move to previous todo state for current function.
;; Keybinding: <S-left>
;; `simple-call-tree-up-priority'
;; Change current function to the next priority level.
;; Keybinding: <S-up>
;; `simple-call-tree-down-priority'
;; Change current function to the previous priority level.
;; Keybinding: <S-down>
;; `simple-call-tree-add-tags'
;; Add tags in VALUE to the function(s) FUNCS.
;; Keybinding: C-c C-a
;; `simple-call-tree-build-tree'
;; Build the simple-call-tree and display it in the "*Simple Call Tree*" buffer.
;; Keybinding: R
;; `simple-call-tree-current-function'
;; Display call tree at location for for function at point.
;; `simple-call-tree-export-org-tree'
;; Create an org-tree from the currently visible items, and put it in an org buffer.
;; Keybinding: M-x simple-call-tree-export-org-tree
;; `simple-call-tree-export-items'
;; Export the currently visible items into a buffer.
;; Keybinding: M-x simple-call-tree-export-items
;; `simple-call-tree-save'
;; Save the file corresponding to header at point.
;; Keybinding: C-x C-s
;; `simple-call-tree-reverse'
;; Reverse the order of the branches & sub-branches in `simple-call-tree-alist' and `simple-call-tree-inverted-alist'.
;; Keybinding: r
;; `simple-call-tree-sort-by-num-descendants'
;; Sort the branches in the *Simple Call Tree* buffer by the number of descendants to depth DEPTH.
;; Keybinding: d
;; `simple-call-tree-sort-by-name'
;; Sort the functions in the *Simple Call Tree* buffer alphabetically.
;; Keybinding: n
;; `simple-call-tree-sort-by-position'
;; Sort the functions in the *Simple Call Tree* buffer by position.
;; Keybinding: p
;; `simple-call-tree-sort-by-face'
;; Sort the items in the *Simple Call Tree* buffer according to the display face name.
;; Keybinding: f
;; `simple-call-tree-sort-by-todo'
;; Sort the items in the *Simple Call Tree* buffer by TODO state.
;; Keybinding: T
;; `simple-call-tree-sort-by-priority'
;; Sort the items in the *Simple Call Tree* buffer by priority level.
;; Keybinding: P
;; `simple-call-tree-sort-by-size'
;; Sort the items in the *Simple Call Tree* buffer by size.
;; Keybinding: s
;; `simple-call-tree-sort-by-mark'
;; Sort the marked items in the *Simple Call Tree* buffer before the unmarked ones.
;; Keybinding: *
;; `simple-call-tree-quit'
;; Quit the *Simple Call Tree* buffer.
;; Keybinding: q
;; `simple-call-tree-invert-buffer'
;; Invert the tree in *Simple Call Tree* buffer.
;; Keybinding: i
;; `simple-call-tree-change-maxdepth'
;; Alter the maximum tree depth (MAXDEPTH) in the *Simple Call Tree* buffer.
;; Keybinding: M-x simple-call-tree-change-maxdepth
;; `simple-call-tree-change-default-view'
;; Change the values of `simple-call-tree-default-view' and `simple-call-tree-default-recenter'.
;; Keybinding: C-c C-v
;; `simple-call-tree-view-function'
;; Display the source code corresponding to current header.
;; Keybinding: C-o
;; `simple-call-tree-jump-prev'
;; Jump to the previous function in the `simple-call-tree-jump-ring'.
;; Keybinding: <
;; `simple-call-tree-jump-next'
;; Jump to the next chain in the `simple-call-tree-jump-ring'.
;; Keybinding: >
;; `simple-call-tree-jump-ring-add'
;; Add the call chain at point to the jump-ring.
;; Keybinding: .
;; `simple-call-tree-jump-ring-remove'
;; Remove the current item from the jump-ring.
;; Keybinding: -
;; `simple-call-tree-jump-to-function'
;; Move cursor to the line corresponding to the function header with name FNSTR
;; Keybinding: j
;; `simple-call-tree-move-top'
;; Move cursor to the toplevel parent of this function.
;; Keybinding: ^
;; `simple-call-tree-move-next'
;; Move cursor to the next item.
;; Keybinding: M-x simple-call-tree-move-next
;; `simple-call-tree-move-prev'
;; Move cursor to the previous item.
;; Keybinding: M-x simple-call-tree-move-prev
;; `simple-call-tree-move-next-samelevel'
;; Move cursor to the next item at the same level as the current one, and recenter.
;; Keybinding: N
;; `simple-call-tree-move-prev-samelevel'
;; Move cursor to the previous item at the same level as the current one, and recenter.
;; Keybinding: <C-up>
;; `simple-call-tree-move-next-marked'
;; Move cursor to the next marked item.
;; Keybinding: M-g n
;; `simple-call-tree-move-prev-marked'
;; Move cursor to the next marked item.
;; Keybinding: M-g p
;; `simple-call-tree-move-next-todo'
;; Move cursor to the next item with a TODO state that isn't done.
;; Keybinding: M-n
;; `simple-call-tree-move-prev-todo'
;; Move cursor to the next item with a TODO state that isn't done.
;; Keybinding: M-p
;; `simple-call-tree-toggle-narrowing'
;; Toggle narrowing of *Simple Call Tree* buffer.
;; Keybinding: /
;; `simple-call-tree-display-notes'
;; Append NOTES to FUNCS in *Simple Call Tree* buffer.
;; Keybinding: C-c C-n
;; `simple-call-tree-toggle-duplicates'
;; Toggle the inclusion of duplicate sub-branches in the call tree.
;; Keybinding: D
;; `simple-call-tree-apply-command'
;; Apply command CMD on function(s) FUNCS.
;; Keybinding: !
;; `simple-call-tree-query-replace'
;; Perform query-replace on the marked items or the item at point in the *Simple Call Tree* buffer.
;; Keybinding: %
;; `simple-call-tree-query-replace-regexp'
;; Perform `query-replace-regexp' on the marked items or the item at point in the *Simple Call Tree* buffer.
;; Keybinding: C-%
;; `simple-call-tree-bookmark'
;; Set bookmarks the marked items or the item at point in the *Simple Call Tree* buffer.
;; Keybinding: B
;; `simple-call-tree-delete-other-windows'
;; Make the *Simple Call Tree* buffer fill the frame.
;; Keybinding: 1
;; `simple-call-tree-mark'
;; Mark the item named FUNC.
;; Keybinding: m
;; `simple-call-tree-unmark'
;; Unmark the item named FUNC.
;; Keybinding: u
;; `simple-call-tree-unmark-all'
;; Unmark all items.
;; Keybinding: U
;; `simple-call-tree-toggle-marks'
;; Toggle marks (unmarked become marked and marked become unmarked).
;; Keybinding: M-x simple-call-tree-toggle-marks
;; `simple-call-tree-mark-by-name'
;; Mark all items with names matching regular expression REGEX.
;; Keybinding: M-x simple-call-tree-mark-by-name
;; `simple-call-tree-mark-by-source'
;; Mark all items with source code matching regular expression REGEX.
;; Keybinding: M-x simple-call-tree-mark-by-source
;; `simple-call-tree-mark-by-tag-match'
;; Mark all items with code matching regular expression REGEX.
;; Keybinding: t
;; `simple-call-tree-mark-by-priority'
;; Mark all items with priority VALUE.
;; Keybinding: M-x simple-call-tree-mark-by-priority
;; `simple-call-tree-mark-by-todo'
;; Mark all items with TODO state matching regular expression REGEX.
;; Keybinding: M-x simple-call-tree-mark-by-todo
;; `simple-call-tree-mark-by-face'
;; Mark all items with display face FACE.
;; Keybinding: M-x simple-call-tree-mark-by-face
;; `simple-call-tree-mark-by-buffer'
;; Mark all items corresponding to source code in buffer BUF.
;; Keybinding: b
;; `simple-call-tree-kill-marked'
;; Remove all marked items from the *Simple Call Tree* buffer.
;; Keybinding: k
;; `simple-call-tree-revert'
;; Redisplay the *Simple Call Tree* buffer.
;; Keybinding: g
;;
;;; Customizable Options:
;;
;; Below is a list of customizable options:
;;
;; `simple-call-tree-default-recenter'
;; How to recenter the window after moving to another function in the "*Simple Call Tree*" buffer.
;; default = (quote middle)
;; `simple-call-tree-default-view'
;; How to recenter the window after viewing a toplevel header.
;; default = (quote top)
;; `simple-call-tree-window-splits'
;; Alist of items containing info about how to split the window when viewing code (e.g. in follow mode).
;; default = (quote ((2 1.5 5.0 right below ...) (1 5 below)))
;; `simple-call-tree-default-valid-fonts'
;; List of fonts to use for finding objects to include in the call tree.
;; default = (quote (font-lock-function-name-face font-lock-variable-name-face))
;; `simple-call-tree-default-invalid-fonts'
;; List of fonts that should not be in the text property of any valid token.
;; default = (quote (font-lock-comment-face font-lock-string-face font-lock-doc-face font-lock-keyword-face font-lock-warning-face ...))
;; `simple-call-tree-default-sort-method'
;; The default sort method to use when a call tree is newly created.
;; default = (quote position)
;; `simple-call-tree-default-maxdepth'
;; The depth at which new call trees should be displayed.
;; default = 2
;; `simple-call-tree-major-mode-alist'
;; Alist of major modes, and information to use for identifying objects for the simple call tree.
;; default = (quote ((emacs-lisp-mode ... nil ... nil ...) (cperl-mode nil nil ... nil ...) (haskell-mode nil ... ... ... ...) (perl-mode nil nil ... nil ...) (python-mode ... nil ... nil ...) ...))
;; `simple-call-tree-org-link-style'
;; Style used for links of child headers when exporting org tree using `simple-call-tree-export-org-tree'.
;; default = (quote radio)
;; `simple-call-tree-org-todo-keywords'
;; List of different TODO keywords, if nil then the keywords in `org-todo-keywords' will be used.
;; default = nil
;; `simple-call-tree-org-not-done-keywords'
;; List of TODO keywords representing not done states.
;; default = (quote ("TODO" "STARTED" "WAITING" "CHECK" "BROKEN"))
;; `simple-call-tree-org-highest-priority'
;; See `org-highest-priority'.
;; default = org-highest-priority
;; `simple-call-tree-org-lowest-priority'
;; See `org-lowest-priority'.
;; default = org-lowest-priority
;; `simple-call-tree-org-tag-alist'
;; See `org-tag-alist'.
;; default = org-tag-alist
;; `simple-call-tree-notes-functions'
;; Alist of (DESCRIPTION . NOTES) used for selecting the NOTES arg of ‘simple-call-tree-display-notes’.
;; `simple-call-tree-mark-face'
;; Face to use for marked items in the *Simple Call Tree* buffer.
;; default = (if (featurep (quote dired+)) diredp-flag-mark-line (quote highlight))
;; `simple-call-tree-jump-ring-max'
;; Maximum number of elements in `simple-call-tree-jump-ring', before old elements are removed.
;; default = 20
;;; Installation:
;;
;; Put simple-call-tree.el in a directory in your load-path, e.g. ~/.emacs.d/
;; You can add a directory to your load-path with the following line in ~/.emacs
;; (add-to-list 'load-path (expand-file-name "~/elisp"))
;; where ~/elisp is the directory you want to add
;; (you don't need to do this for ~/.emacs.d - it's added by default).
;;
;; Add the following to your ~/.emacs startup file.
;;
;; (require 'simple-call-tree)
;;
;; You might also want to define a key for creating the call tree,
;; e.g. like this:
;;
;; (global-set-key (kbd "C-c S") 'simple-call-tree-current-function)
;;; Acknowledgements:
;;
;; Alex Schroeder - the creator of the original simple-call-tree.el
;;
;;
;;; TODO
;;
;; Use / key for filtering headers by name (for consistency with other modes such as gnus & dired)
;; and use a different key for narrowing to the current header.
;;
;; Allow adding headers for arbitrary locations
;; If anyone wants to implement the following ideas, please do:
;; More reliable code for building tree (handle duplicate function names properly).
;; Code for managing refactoring commands (to be applied to marked functions).
;; Multiple query replace command for substituting appropriate lisp macros -
;; e.g. replace (setq list (remove x list)) with (callf2 remove x list)
;; Code for finding (and highlighting?) duplicate code and other code smells (difficult).
;; Idea: break each function down into a list of keywords for the language in question,
;; and look for common subsequences (not too short) among functions.
;;; Require
(require 'thingatpt)
(require 'outshine nil t)
(require 'fm nil t)
(require 'hl-line nil t)
(require 'anaphora)
(require 'cl-lib)
(require 'org)
(require 'ido)
(require 'newcomment)
(comment-normalize-vars)
;;; Code:
;; simple-call-tree-info: DONE
(defgroup simple-call-tree nil
"Simple call tree - display a simple call tree for functions in a buffer."
:group 'tools
:link '(url-link "http://www.emacswiki.org/SimpleCallTree"))
;; simple-call-tree-info: DONE
(defcustom simple-call-tree-default-recenter 'middle
"How to recenter the window after moving to another function in the \"*Simple Call Tree*\" buffer.
Can be one of the following symbols: 'top 'middle 'bottom.
This variable is used by the `simple-call-tree-jump-to-function' function when no prefix arg is given,
and by `simple-call-tree-visit-function' and `simple-call-tree-view-function' (for non-toplevel headers)."
:group 'simple-call-tree
:type '(choice (const :tag "Top" top)
(const :tag "Middle" middle)
(const :tag "Bottom" bottom)))
;; simple-call-tree-info: DONE
(defcustom simple-call-tree-default-view 'top
"How to recenter the window after viewing a toplevel header.
This applied to viewing with `simple-call-tree-view-function', and with `simple-call-tree-visit-function'
in follow-mode. It can be one of the following symbols: 'top 'middle 'bottom.
You can change it's value temporarily with the `simple-call-tree-change-default-view' command.
This only applies to toplevel headers, see `simple-call-tree-default-recenter' for other headers."
:group 'simple-call-tree
:type '(choice (const :tag "Top" top)
(const :tag "Middle" middle)
(const :tag "Bottom" bottom)))
;; simple-call-tree-info: DONE
(define-widget 'window-split 'lazy
"Window split location; either an integer number of rows/columns or a proportion of the existing window size.
The value is used as an argument to the `split-window' function.
If the value is positive it indicates the size of the existing window after splitting, if negative then its
absolute value indicates the size of the new window created after splitting."
:tag "Window split location"
:type '(choice (integer :tag "Rows/columns"
:help-echo "Number of rows/columns for existing window (+ve) / new window (-ve)"
:validate
(lambda (w)
(let ((v (widget-value w)))
(unless (and (integerp v)
(not (= v 0)))
(widget-put w :error
"Value must be non-zero")
w))))
(float :tag "Proportion"
:help-echo "Proportion of window to use for existing window (+ve) / new window (-ve)"
:validate
(lambda (w)
(let ((v (widget-value w)))
(unless (and (<= v 1.0) (>= v -1.0))
(widget-put w :error
"Value must be between -1.0 & 1.0")
w))))))
;; simple-call-tree-info: DONE
(define-widget 'split-orientation 'lazy
"Side parameter used by `split-window' function"
:tag "Window location"
:type '(choice :value below
(const :tag "Left" left)
(const :tag "Right" right)
(const :tag "Above" above)
(const :tag "Below" below)))
;; simple-call-tree-info: DONE
(define-widget 'positive-float 'float
"Positive floating point number."
:tag "Float"
:validate (lambda (w)
(when (<= (widget-value w) 0)
(widget-put w :error "Value must be positive")
w)))
;; simple-call-tree-info: CHANGE option to show code in separate frame
(defcustom simple-call-tree-window-splits '((2 1.5 5.0 right below 5 2) (1 5 below))
"Alist of items containing info about how to split the window when viewing code (e.g. in follow mode).
The item used to determine the split is the first item with a car that is either an integer less
than or equal to the current depth, or an s-expression that evaluates to non-nil.
The cdr is used to determine the size and orientation of the split, which are then fed into the
`split-window' function. It can be either a list of size & orientation values for fixed splitting,
or a list of 6 parameters for adaptive splitting.
For fixed splitting the size parameter can be interpreted in one of the following ways:
positive integer - number of columns/rows to use for the *Simple Call Tree* window
negative integer - number of columns/rows to use for the code window
float in range (0,1) - proportion of total columns/rows in existing window to use for
the *Simple Call Tree* window after the split
float in range (-1,0) - proportion of total columns/rows in existing window to use for the
code window after the split
The orientation parameter can be either 'left, 'right, 'above, 'below, and indicates the position
of the code window relative to the *Simple Call Tree* window after the split.
For adaptive splitting the following 6 parameters need to be specified (or left at default values):
1st param: value of space in code window relative to space in call-tree window (c2t in formulas below).
A larger value means that the split will have a larger code window. Values between 1 & 5 work well.
2nd param: value of rows relative to columns (v2h in formulas below). A larger value increases the likelihood
of a vertical split. Values between 1 & 20 work well.
3rd param: orientation of code window for horizontal splits (either left or right)
4th param: orientation of code window for vertical splits (either above or below)
5th param: minimum number of columns in horizontal split windows. If the split would otherwise result in
a code window or call-tree window smaller than this value, it will be enlarged. The value
can be a positive integer, or a proportion of total columns (i.e. a float between 0.0 & 1.0).
6th param: minimum number of rows in vertical split windows as either a positive integer, or a
proportion of total rows (i.e. a float between 0.0 & 1.0).
To calculate the location and orientation of the adaptive split the following formulas are used:
value of horizontal split: c2t*(width-hsplit) - (maxl-hsplit)^1.5
value of vertical split: v2h*c2t*(height-vsplit) - v2h*(maxh-vsplit)^1.5
where:
width & height = width & height of *Simple Call Tree* window before the split
hsplit & vsplit = positions of horizontal & vertical splits (in number of columns/rows)
maxl = maximum length of lines in *Simple Call Tree* buffer (excluding tags)
maxh = maximum number of lines under headers in *Simple Call Tree* buffer
c2t = value of space in code window relative to space in *Simple Call Tree* window
v2h = value of vertical split rows relative to horizontal split columns
The values of hsplit & vsplit are chosen to maximize the above mentioned formulas. These value are then
adjusted to ensure that they are within the bounds specified by the 5th & 6th parameters, and maxh & maxl
respectively, and then substituted back into the formulas to obtain values for the horizontal & vertical splits.
Whichever has the greatest value is the chosen split."
;; Note: several different value formulas were tried before arriving at the ones stated above. It is tempting to
;; take square roots of the first term (to have a decreasing marginal value of code window size), or a power of
;; 2 instead of 1.5 for the second term, but this results in formulas that are harder to maximize or less responsive
;; to parameter changes.
:group 'simple-call-tree
:type '(alist :key-type
(choice :tag "Condition"
(integer :tag "Minimum depth"
:help-echo "Select split if tree depth is at least this number"
:value 1
:validate
(lambda (w)
(when (< (widget-value w) 1)
(widget-put w :error "Depth must be greater than 0")
w)))
(sexp :tag "S-expression"
:help-echo "Select split if sexp evaluates to non-nil"))
:value-type
(choice :tag "Code window display"
(list :tag "Fixed"
(window-split :tag "Size" :value 10)
(split-orientation :tag "Orientation of code window"
:value below))
(list :tag "Adaptive"
(positive-float
:tag "Ratio of values of code to call-tree windows"
:value 2.0)
(positive-float
:tag "Ratio of values of rows to columns"
:value 3.0)
(split-orientation
:tag "Location of code window for horizontal split"
:value right)
(split-orientation
:tag "Location of code window for vertical split"
:value below)
(window-split :tag "Min columns" :value 5
:validate
(lambda (w)
(when (<= (widget-value w) 0)
(widget-put w :error "Value must be > 0")
w)))
(window-split :tag "Min rows" :value 2
:validate
(lambda (w)
(when (<= (widget-value w) 0)
(widget-put w :error "Value must be > 0")
w)))))))
;; simple-call-tree-info: DONE
(defcustom simple-call-tree-default-valid-fonts
'(font-lock-function-name-face
font-lock-variable-name-face)
"List of fonts to use for finding objects to include in the call tree."
:group 'simple-call-tree
:type '(repeat face))
;; simple-call-tree-info: DONE
(defcustom simple-call-tree-default-invalid-fonts
'(font-lock-comment-face
font-lock-string-face
font-lock-doc-face
font-lock-keyword-face
font-lock-warning-face
font-lock-preprocessor-face)
"List of fonts that should not be in the text property of any valid token."
:group 'simple-call-tree
:type '(repeat face))
;; simple-call-tree-info: DONE
(defcustom simple-call-tree-default-sort-method 'position
"The default sort method to use when a call tree is newly created.
The children of each header will be sorted separately."
:group 'simple-call-tree
:type '(choice (const :tag "Sort by position" position)
(const :tag "Sort by name" name)
(const :tag "Sort by number of descendants" numdescend)
(const :tag "Sort by size" size)
(const :tag "Sort by face" face)
(const :tag "Sort by TODO state" todo)
(const :tag "Sort by priority" priority)
(const :tag "Sort by mark" mark)))
;; simple-call-tree-info: DONE
(defcustom simple-call-tree-default-maxdepth 2
"The depth at which new call trees should be displayed."
:group 'simple-call-tree
:type 'integer)
;; simple-call-tree-info: DONE
(defcustom simple-call-tree-major-mode-alist
'((emacs-lisp-mode (font-lock-function-name-face
font-lock-variable-name-face
font-lock-type-face)
nil
(lambda (pos)
(goto-char pos)
(backward-word)
(eq (get-text-property (point) 'face)
'font-lock-keyword-face))
nil t nil nil)
(cperl-mode nil nil (lambda (pos)
(goto-char pos)
(beginning-of-line)
(looking-at "sub"))
nil nil "\\(^\\|\\s-\\)" nil)
(haskell-mode nil (font-lock-function-name-face
font-lock-comment-face
font-lock-string-face
font-lock-doc-face
font-lock-keyword-face
font-lock-warning-face
font-lock-preprocessor-face)
(lambda (pos)
(goto-char pos)
(beginning-of-line)
(let ((thistoken (symbol-at-point)))
(previous-line)
(not (string= (symbol-at-point) thistoken))))
(lambda nil (haskell-ds-forward-decl)
(unless (= (point) (point-max)) (point)))
t
"\\(:\\|\\_<\\)"
"\\s-")
(perl-mode nil nil (lambda (pos)
(goto-char pos)
(beginning-of-line)
(looking-at "sub"))
nil nil "\\(^\\|\\s-\\)" nil)
(python-mode (font-lock-function-name-face
font-lock-variable-name-face
font-lock-type-face)
nil (lambda (pos)
(goto-char pos)
(beginning-of-line)
(re-search-forward "\\<")
(or (looking-at "def\\|class")
(eq (get-text-property (point) 'face)
font-lock-variable-name-face)))
nil
(lambda nil
(backward-char)
(if (eq (get-text-property (point) 'face)
font-lock-variable-name-face)
(end-of-line)
(end-of-defun)))
nil nil)
(matlab-mode (font-lock-function-name-face)
nil
(lambda (pos)
(re-search-backward "^function" (line-beginning-position) t))
(lambda nil
(if (re-search-forward "^function\\s-*\\S-+\\s-*=\\s-*" (point-max) t)
(point)))
matlab-end-of-defun
nil nil))
"Alist of major modes, and information to use for identifying objects for the simple call tree.
Each element is a list in the form '(MAJOR-MODE VALID-FONTS INVALID-FONTS START-TEST END-TEST) where:
MAJOR-MODE is the symbol for the major-mode that this items applies to.
VALID-FONTS is either nil or a list of fonts for finding objects for the call tree (functions/variables/etc).
If nil then `simple-call-tree-default-valid-fonts' will be used.
INVALID-FONTS is either nil or a list of fonts that should not be present in the text properties of
any objects to be added to the call tree. If nil then `simple-call-tree-default-invalid-fonts' will be used.
The invalid fonts will also be checked when finding function calls.
START-TEST indicates how to determing the start of the next object. Potential objects are found by checking
the fonts of tokens in the buffer (against VALID-FONTS). If START-TEST is a function then it will be used as
an additional check for potential objects. It will be passed the buffer position of the beginning of the
current token to check, and should return non-nil if it represents a valid object.
NEXT-FUNC is an alternative way of determining the locations of functions.
It is either nil, meaning the function locations will be determined by fonts and maybe START-TEST,
or a function of no args which returns the position of the next function in the buffer or nil if
there are no further functions.
END-FUNC indicates how to find the end of the current object when parsing a buffer for the call tree.
It can be either a function taking no args which moves point to the end of the current function,
or any non-nil value which means to use the `end-of-defun' function, or nil which means that font changes
will be used to determine the end of an object.
START-REGEXP a regular expression to match the beginning of a token, you can probably leave this blank.
By default it is \"\\_<\".
END-REGEXP a regular expression to match the end of a token, by default this is \"\\_>\"."
:group 'simple-call-tree
:type '(repeat (list (symbol :tag "major-mode symbol")
(repeat :tag "Include faces"
:doc "List of faces corresponding to items to include in the call tree."
(face :help-echo "Face of items to include in the call tree."))
(repeat :tag "Exclude faces"
(face :help-echo "Face of items to exclude from the call tree."))
(choice :tag "Start test"
(const :tag "Font only" nil)
(function
:tag "Function"
:help-echo "Function that evaluates to true when point is at beginning of function name."))
(choice :tag "Next function test"
(const :tag "Font only" nil)
(function
:tag "Function"
:help-echo "Function to return position of next function in the buffer."))
(choice :tag "End test"
(const :tag "Font only" nil)
(const :tag "end-of-defun function" t)
(function :tag "Other function" :help-echo "Function for finding end of object"))
(choice :tag "Start regexp"
(const :tag "Use default value (\"\\_<\")" nil)
(regexp :tag "Start regexp"
:help-echo "regexp to match the beginning of a token"))
(choice :tag "End regexp"
(const :tag "Use default value (\"\\_>\")" nil)
(regexp :tag "End regexp"
:help-echo "regexp to match the end of a token"))))
:link '(variable-link simple-call-tree-default-valid-fonts))
;; simple-call-tree-info: DONE
(defcustom simple-call-tree-org-link-style 'radio
"Style used for links of child headers when exporting org tree using `simple-call-tree-export-org-tree'."
:group 'simple-call-tree
:type '(choice (const :tag "internal radio link" radio)
(const :tag "link to source code" source)))
;; simple-call-tree-info: DONE
(defcustom simple-call-tree-org-todo-keywords nil
"List of different TODO keywords, if nil then the keywords in `org-todo-keywords' will be used."
:group 'simple-call-tree
:type '(choice (repeat :tag "Choose keywords" (string :tag "Keyword"))
(const :tag "Use org-todo-keywords" nil)))
;; simple-call-tree-info: DONE
(defcustom simple-call-tree-org-not-done-keywords '("TODO" "STARTED" "WAITING" "CHECK" "BROKEN")
"List of TODO keywords representing not done states."
:group 'simple-call-tree
:type '(repeat :tag "Choose keywords" (string :tag "Keyword")))
;; simple-call-tree-info: DONE
(defcustom simple-call-tree-org-highest-priority org-highest-priority
"See `org-highest-priority'."
:group 'simple-call-tree
:type 'character)
;; simple-call-tree-info: DONE
(defcustom simple-call-tree-org-lowest-priority org-lowest-priority
"See `org-lowest-priority'."
:group 'simple-call-tree
:type 'character)
;; simple-call-tree-info: DONE
(defcustom simple-call-tree-org-tag-alist org-tag-alist
"See `org-tag-alist'."
:group 'simple-call-tree
:type '(alist :key-type (string :tag "Tag name")
:value-type (character :tag "Access char")))
;; simple-call-tree-info: CHECK
(defcustom simple-call-tree-notes-functions
'(("TODO notes" . simple-call-tree-get-todo-note)
("Docstring" . simple-call-tree-get-docstring)
("None" . ""))
"Alist of (DESCRIPTION . NOTES) used for selecting the NOTES arg of `simple-call-tree-display-notes'."
:group 'simple-call-tree
:type '(alist :key-type (string :tag "Description")
:value-type (function :tag "Function"
:help-echo "Function takes function name as arg and returns a string")))
;; simple-call-tree-info: DONE
(defun simple-call-tree-org-todo-keywords nil
"Return list of all TODO states.
If `simple-call-tree-org-todo-keywords' is nil then the states in `org-todo-keywords' are returned
as a flat list."
(or simple-call-tree-org-todo-keywords
(cl-remove-if (lambda (x) (or (symbolp x)
(equal x "|")))
(cl-mapcan 'identity org-todo-keywords))))
;; simple-call-tree-info: DONE
(cl-defun simple-call-tree-get-item (func &optional (alist simple-call-tree-alist))
"Return the item in `simple-call-tree-alist' corresponding with function named FUNC."
(cl-assoc-if (lambda (x) (simple-call-tree-compare-items (car x) func)) alist))
;; simple-call-tree-info: DONE
(defun simple-call-tree-tags-to-string (tags)
(when (> (length tags) 0)
(concat ":" (mapconcat (lambda (x)
(propertize x 'font-lock-face (org-get-tag-face x)))
tags ":") ":")))
;; simple-call-tree-info: DONE
(defun simple-call-tree-string-to-tags (str)
(aif str (split-string (substring-no-properties it) "[ \f\t\n\r\v,;:]+" t)))
;; Major-mode for simple call tree
;; simple-call-tree-info: DONE
(define-derived-mode simple-call-tree-mode outline-mode "Simple Call Tree"
"The major-mode for the one-key menu buffer."
:group 'simple-call-tree
(setq simple-call-tree-mode-map (make-keymap)
buffer-read-only nil
comment-start ";"
truncate-lines t)
(outline-minor-mode 1)
(setq outline-regexp "^[|*]\\([-<>]*\\)\\(\\( +\\w+\\)?\\)\\(\\( \\[#.\\]\\)?\\) "
outline-level 'simple-call-tree-outline-level)
;; Define keys
(define-key simple-call-tree-mode-map (kbd "q") 'simple-call-tree-quit)
(define-key simple-call-tree-mode-map (kbd "C-x C-s") 'simple-call-tree-save)
;; Sorting commands
(define-prefix-command 'simple-call-tree-sort-map)
(define-key simple-call-tree-mode-map (kbd "s") 'simple-call-tree-sort-map)
(define-key simple-call-tree-mode-map (kbd "s n") 'simple-call-tree-sort-by-name)
(define-key simple-call-tree-mode-map (kbd "s p") 'simple-call-tree-sort-by-position)
(define-key simple-call-tree-mode-map (kbd "s f") 'simple-call-tree-sort-by-face)
(define-key simple-call-tree-mode-map (kbd "s d") 'simple-call-tree-sort-by-num-descendants)
(define-key simple-call-tree-mode-map (kbd "s s") 'simple-call-tree-sort-by-size)
(define-key simple-call-tree-mode-map (kbd "s T") 'simple-call-tree-sort-by-todo)
(define-key simple-call-tree-mode-map (kbd "s P") 'simple-call-tree-sort-by-priority)
(define-key simple-call-tree-mode-map (kbd "s *") 'simple-call-tree-sort-by-mark)
(define-key simple-call-tree-mode-map (kbd "s r") 'simple-call-tree-reverse)
(define-key simple-call-tree-mode-map (kbd "<C-S-up>") 'simple-call-tree-move-item-up)
(define-key simple-call-tree-mode-map (kbd "<C-S-down>") 'simple-call-tree-move-item-down)
;; Display altering commands
(define-key simple-call-tree-mode-map (kbd "i") 'simple-call-tree-invert-buffer)
(define-key simple-call-tree-mode-map (kbd "d") 'simple-call-tree-change-maxdepth)
(define-key simple-call-tree-mode-map (kbd "D") 'simple-call-tree-toggle-duplicates)
(define-key simple-call-tree-mode-map (kbd "g") 'simple-call-tree-revert)
(define-key simple-call-tree-mode-map (kbd "R") 'simple-call-tree-build-tree)
;; Marking commands
(define-prefix-command 'simple-call-tree-mark-map)
(define-key simple-call-tree-mode-map (kbd "*") 'simple-call-tree-mark-map)
(define-key simple-call-tree-mode-map (kbd "* n") 'simple-call-tree-mark-by-name)
(define-key simple-call-tree-mode-map (kbd "* f") 'simple-call-tree-mark-by-face)
(define-key simple-call-tree-mode-map (kbd "* s") 'simple-call-tree-mark-by-source)
(define-key simple-call-tree-mode-map (kbd "* T") 'simple-call-tree-mark-by-todo)
(define-key simple-call-tree-mode-map (kbd "* p") 'simple-call-tree-mark-by-priority)
(define-key simple-call-tree-mode-map (kbd "* t") 'simple-call-tree-mark-by-tag-match)
(define-key simple-call-tree-mode-map (kbd "* b") 'simple-call-tree-mark-by-buffer)
(define-key simple-call-tree-mode-map (kbd "m") 'simple-call-tree-mark)
(define-key simple-call-tree-mode-map (kbd "u") 'simple-call-tree-unmark)
(define-key simple-call-tree-mode-map (kbd "U") 'simple-call-tree-unmark-all)
(define-key simple-call-tree-mode-map (kbd "t") 'simple-call-tree-toggle-marks)
;; Hide/show commands
(if (featurep 'outshine)
(define-key simple-call-tree-mode-map (kbd "<tab>") 'outshine-cycle)
(define-key simple-call-tree-mode-map (kbd "<tab>") 'outline-toggle-children))
(define-key simple-call-tree-mode-map (kbd "<right>") 'outline-show-children)
(define-key simple-call-tree-mode-map (kbd "<left>") 'hide-subtree)
(define-key simple-call-tree-mode-map (kbd "a") 'show-all)
(define-key simple-call-tree-mode-map (kbd "1") 'simple-call-tree-delete-other-windows)
(define-key simple-call-tree-mode-map (kbd "h") 'hide-sublevels)
(define-key simple-call-tree-mode-map (kbd "w") 'widen)
(define-key simple-call-tree-mode-map (kbd "/") 'simple-call-tree-toggle-narrowing)
;; View/visit commands
(define-key simple-call-tree-mode-map (kbd "SPC") 'simple-call-tree-view-function)
(define-key simple-call-tree-mode-map (kbd "C-o") 'simple-call-tree-view-function)
(define-key simple-call-tree-mode-map (kbd "v") 'simple-call-tree-view-function)
(define-key simple-call-tree-mode-map (kbd "V") #'(lambda nil (interactive) (simple-call-tree-view-function t)))
(define-key simple-call-tree-mode-map (kbd "<return>") 'simple-call-tree-visit-function)
(define-key simple-call-tree-mode-map (kbd "o") 'simple-call-tree-visit-function)
;; Movement commands
(define-key simple-call-tree-mode-map (kbd "^") 'simple-call-tree-move-top)
(define-key simple-call-tree-mode-map (kbd "n") 'simple-call-tree-move-next)
(define-key simple-call-tree-mode-map (kbd "p") 'simple-call-tree-move-prev)
(define-key simple-call-tree-mode-map (kbd "N") 'simple-call-tree-move-next-samelevel)
(define-key simple-call-tree-mode-map (kbd "P") 'simple-call-tree-move-prev-samelevel)
(define-key simple-call-tree-mode-map (kbd "M-p") 'simple-call-tree-move-prev-todo)
(define-key simple-call-tree-mode-map (kbd "M-n") 'simple-call-tree-move-next-todo)
(define-key simple-call-tree-mode-map (kbd "C->") 'simple-call-tree-move-next-marked)
(define-key simple-call-tree-mode-map (kbd "C-<") 'simple-call-tree-move-prev-marked)
(define-key simple-call-tree-mode-map (kbd "M-g n") 'simple-call-tree-move-next-marked)
(define-key simple-call-tree-mode-map (kbd "M-g p") 'simple-call-tree-move-prev-marked)
(define-key simple-call-tree-mode-map (kbd "M-g M-n") 'simple-call-tree-move-next-marked)
(define-key simple-call-tree-mode-map (kbd "M-g M-p") 'simple-call-tree-move-prev-marked)
(define-key simple-call-tree-mode-map (kbd "<C-up>") 'simple-call-tree-move-prev-samelevel)
(define-key simple-call-tree-mode-map (kbd "<C-down>") 'simple-call-tree-move-next-samelevel)
(define-key simple-call-tree-mode-map (kbd "<C-left>") 'outline-up-heading)
(define-key simple-call-tree-mode-map (kbd "<C-right>") 'outline-next-heading)
;; Jump ring commands
(define-key simple-call-tree-mode-map (kbd "j") 'simple-call-tree-jump-to-function)
(define-key simple-call-tree-mode-map (kbd "J") #'(lambda nil (interactive)
(setq current-prefix-arg 1)
(call-interactively 'simple-call-tree-jump-to-function)))
(define-key simple-call-tree-mode-map (kbd "C-j") #'(lambda nil (interactive)
(setq current-prefix-arg 1)
(call-interactively 'simple-call-tree-jump-to-function)))
(define-key simple-call-tree-mode-map (kbd ".") 'simple-call-tree-jump-ring-add)
(define-key simple-call-tree-mode-map (kbd "-") 'simple-call-tree-jump-ring-remove)
(define-key simple-call-tree-mode-map (kbd "<") 'simple-call-tree-jump-prev)
(define-key simple-call-tree-mode-map (kbd ">") 'simple-call-tree-jump-next)
;; Applying commands
(define-key simple-call-tree-mode-map (kbd "B") 'simple-call-tree-bookmark)
(define-key simple-call-tree-mode-map (kbd "%") 'simple-call-tree-query-replace)
(define-key simple-call-tree-mode-map (kbd "C-%") 'simple-call-tree-query-replace-regexp)
(define-key simple-call-tree-mode-map (kbd "!") 'simple-call-tree-apply-command)
(define-key simple-call-tree-mode-map (kbd "k") 'simple-call-tree-kill-marked)
;; org attribute commands
(define-key simple-call-tree-mode-map (kbd "<S-right>") 'simple-call-tree-next-todo)
(define-key simple-call-tree-mode-map (kbd "<S-left>") 'simple-call-tree-prev-todo)
(define-key simple-call-tree-mode-map (kbd "<S-up>") 'simple-call-tree-up-priority)
(define-key simple-call-tree-mode-map (kbd "<S-down>") 'simple-call-tree-down-priority)
(define-key simple-call-tree-mode-map (kbd "C-c C-c") 'simple-call-tree-set-tags)
(define-key simple-call-tree-mode-map (kbd "C-c C-q") 'simple-call-tree-set-tags)
(define-key simple-call-tree-mode-map (kbd "C-c C-a") 'simple-call-tree-add-tags)
(define-key simple-call-tree-mode-map (kbd "C-c C-t") 'simple-call-tree-set-todo)
(define-key simple-call-tree-mode-map (kbd "C-c C-n") 'simple-call-tree-display-notes)
(define-key simple-call-tree-mode-map (kbd "C-c C-v") 'simple-call-tree-change-default-view)
(define-key simple-call-tree-mode-map (kbd "C-c ,") 'simple-call-tree-set-priority)
;; Set the keymap
(use-local-map simple-call-tree-mode-map)
;; Menu definition
(easy-menu-define nil simple-call-tree-mode-map "test"
`("Simple Call Tree"
["Quit" simple-call-tree-quit
:help "Quit and bury this buffer"]
["Rebuild tree" simple-call-tree-build-tree
:help "Rebuild the call tree"]
["Rename buffer" simple-call-tree-rename-buffer
:help "Rename the buffer"]
["View Function At Point" simple-call-tree-view-function
:help "View the function at point"
:key "v"]
["Change Default View" simple-call-tree-change-default-view
:help "Change which part of a function is viewed by default"]
["Visit Function At Point" simple-call-tree-visit-function
:help "Visit the function at point"]
["Sort items..." (keymap "Sort"
(name menu-item "By name" simple-call-tree-sort-by-name)
(position menu-item "By position" simple-call-tree-sort-by-position)
(numdescend menu-item "By number of descendants" simple-call-tree-sort-by-num-descendants)
(size menu-item "By size" simple-call-tree-sort-by-size)
(face menu-item "By face/type" simple-call-tree-sort-by-face)
(todo menu-item "By TODO state" simple-call-tree-sort-by-todo)
(priority menu-item "By priority" simple-call-tree-sort-by-priority)
(mark menu-item "By mark" simple-call-tree-sort-by-mark)
(reverse menu-item "Reverse order" simple-call-tree-reverse)
(moveup menu-item "Move item up" simple-call-tree-move-item-up)
(movedown menu-item "Move item down" simple-call-tree-move-item-down))]
["Mark items..."
(keymap "Mark"
(mark menu-item "Mark current item" simple-call-tree-mark
:help "Mark toplevel item at point")
(unmark menu-item "Unmark current item" simple-call-tree-unmark
:help "Unmark the toplevel item at point")
(unmarkall menu-item "Unmark all items" simple-call-tree-unmark-all
:help "Unmark all marked items")
(toggle menu-item "Toggle marks" simple-call-tree-toggle-marks
:help "Toggle marks: marked files become unmarked, and vice versa.")
(name menu-item "By name match (regexp)..." simple-call-tree-mark-by-name
:help "Mark items with names matching regexp")
(source menu-item "By source code match (regexp)..." simple-call-tree-mark-by-source
:help "Mark items with source code matching regexp")
(todo menu-item "By TODO state (regexp)..." simple-call-tree-mark-by-todo
:help "Mark items with matching TODO state")
(priority menu-item "By priority..." simple-call-tree-mark-by-priority
:help "Mark items with matching priority level")
(tagmatch menu-item "By tag-match..." simple-call-tree-mark-by-tag-match
:help "Mark items with matching tags")
(buffer menu-item "By source buffer..." simple-call-tree-mark-by-buffer
:help "Mark items with source code in matching buffer"))]
["Operate on items..."
(keymap "Operate"
(kill menu-item "Kill marked items" simple-call-tree-kill-marked
:help "Remove marked items from the buffer")
(todo menu-item "Set TODO state..." simple-call-tree-set-todo
:help "Set TODO state of current/marked items (with prefix arg remove TODO)")
(priority menu-item "Set priority level..." simple-call-tree-set-priority
:help "Set priority level of current/marked items (with prefix arg remove priority)")
(tags menu-item "Set tags..." simple-call-tree-set-tags
:help "Set tags for current/marked items")
(addtags menu-item "Add tags..." simple-call-tree-add-tags
:help "Add tags to current/marked items (with prefix arg remove tags)")
(addnotes menu-item "Display notes..." simple-call-tree-display-notes
:help "Display notes/docstring after function/variable names...")
(queryreplace menu-item "Replace String..." simple-call-tree-query-replace
:help "Perform query-replace on the function at point")
(queryreplaceregex menu-item "Replace Regexp..." simple-call-tree-query-replace-regexp
:help "Perform query-replace-regexp on the function at point")
(bookmark menu-item "Add Bookmark" simple-call-tree-bookmark
:help "Create a bookmark for the position corresponding to the function at point")
(arbitrary menu-item "Apply Arbitrary Command..." simple-call-tree-apply-command
:help "Apply an arbitrary elisp command to the function at point"))]
["Export..."
(keymap "Export"
(source menu-item "Export source code..." simple-call-tree-export-items