-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecb-common-browser.el
2169 lines (1863 loc) · 97.7 KB
/
ecb-common-browser.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
;;; ecb-common-browser.el --- common browsing stuff for Emacs
;; Copyright (C) 2000 - 2005 Jesper Nordenberg,
;; Klaus Berndl,
;; Kevin A. Burton,
;; Free Software Foundation, Inc.
;; Author: Jesper Nordenberg <[email protected]>
;; Klaus Berndl <[email protected]>
;; Kevin A. Burton <[email protected]>
;; Maintainer: Klaus Berndl <[email protected]>
;; Keywords: browser, code, programming, tools
;; Created: 2004
;; 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 PATICULAR 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;; $Id: ecb-common-browser.el,v 1.39 2009/05/15 15:19:53 berndl Exp $
;;; History
;;
;; For the ChangeLog of this file see the CVS-repository. For a complete
;; history of the ECB-package see the file NEWS.
;;; Code:
(eval-when-compile
(require 'silentcomp))
(require 'ecb-util)
(require 'tree-buffer)
;; (require 'ecb-layout) ;; causes cyclic dependencies!
(require 'ecb-mode-line)
(require 'ecb-navigate)
;; various loads
(require 'assoc)
(eval-when-compile
;; to avoid compiler grips
(require 'cl))
(silentcomp-defvar modeline-map)
(defgroup ecb-tree-buffer nil
"General settings related to the tree-buffers of ECB."
:group 'ecb
:prefix "ecb-")
(defcustom ecb-bucket-node-display '("" "" ecb-bucket-node-face)
"*How ECB displays bucket-nodes in a ECB tree-buffer.
Bucket-nodes have only one job: Nodes with similar properties will be dropped
into one bucket for such a common property and all these nodes will be added
as children to the bucket-node. Besides being expandable and collapsable a
bucket-node has no senseful action assigned. Examples for bucket-nodes are
\"[+] Variables\", \"[+] Dependencies\" etc. in the Methods-buffer or buckets
which combine filenames with same extension under a bucket-node with name this
extension.
This option defines how bucket-node should be displayed. The name of the
bucket-node is computed by ECB but you can define a prefix, a suffix and a
special face for the bucket-node
The default are empty prefix/suffix-strings and 'ecb-bucket-node-face'. But
an alternative can be for example '\(\"[\" \"]\" nil) which means no special
face and a display like \"[+] [<bucket-name>]\"."
:group 'ecb-tree-buffer
:set (function (lambda (symbol value)
(set symbol value)
(ecb-clear-tag-tree-cache)))
:type '(list (string :tag "Bucket-prefix" :value "[")
(string :tag "Bucket-suffix" :value "]")
(choice :tag "Bucket-face" :menu-tag "Bucket-face"
(const :tag "No special face" :value nil)
(face :tag "Face" :value ecb-bucket-node-face)))
:initialize 'custom-initialize-default)
(defcustom ecb-use-speedbar-instead-native-tree-buffer nil
"*If true then uses speedbar for directories, sources or methods.
This means that speedbar is integrated in the ECB-frame and is displayed in
that window normally displaying the standard ECB-directories-buffer,
ECB-sources-buffer or ECB-methods-buffer.
This option takes effect in all layouts which contain either a directory
window, a sources window or a method window.
This option can have four valid values:
- nil: Do not use speedbar \(default)
- dir: Use speedbar instead of the standard directories-buffer
- source: Use speedbar instead of the standard sources-buffer
- method: Use speedbar instead of the standard methods-buffer
Note: For directories and sources a similar effect and usability is available
by setting this option to nil \(or 'method) and setting
`ecb-show-sources-in-directories-buffer' to not nil, because this combination
displays also directories and sources in one window.
`ecb-use-speedbar-instead-native-tree-buffer' is for people who like the
speedbar way handling directories and source-files or methods and want it in
conjunction with ECB."
:group 'ecb-tree-buffer
:group 'ecb-directories
:group 'ecb-sources
:group 'ecb-methods
:type '(radio (const :tag "Do not use speedbar" :value nil)
(const :tag "For directories" :value dir)
(const :tag "For sources" :value source)
(const :tag "For methods" :value method))
:initialize 'custom-initialize-default
:set (function (lambda (sym val)
(set sym val)
(if (and (boundp 'ecb-minor-mode) ecb-minor-mode)
(ecb-redraw-layout-full)))))
(defvar ecb-tree-do-not-leave-window-after-select--internal nil
"Only set by customizing `ecb-tree-do-not-leave-window-after-select' or
calling `ecb-toggle-do-not-leave-window-after-select'! Do not set this
variable directly, it is only for internal uses!")
(defcustom ecb-tree-do-not-leave-window-after-select nil
"*Tree-buffers which stay selected after a key- or mouse-selection.
If a buffer \(either its name or the variable-symbol which holds the name) is
contained in this list then selecting a tree-node either by RET or by a
mouse-click doesn't leave that tree-buffer after the node-selection but
performes only the appropriate action \(opening a new source, selecting a
method etc.) but point stays in the tree-buffer. In tree-buffers not contained
in this option normaly a node-selection selects as \"last\" action the right
edit-window or maximizes the next senseful tree-buffer in case of a currently
maximized tree-buffer \(see `ecb-maximize-next-after-maximized-select').
The buffer-name can either be defined as plain string or with a symbol which
contains the buffer-name as value. The latter one is recommended for the
builtin ECB-tree-buffers because then simply the related option-symbol can be
used.
A special remark for the `ecb-directories-buffer-name': Of course here the
value of this option is only relevant if the name of the current layout is
contained in `ecb-show-sources-in-directories-buffer' or if the value of
`ecb-show-sources-in-directories-buffer' is 'always and the clicked ot hitted
node represents a sourcefile \(otherwise this would not make any sense)!
The setting in this option is only the default for each tree-buffer. With the
command `ecb-toggle-do-not-leave-window-after-select' the behavior of a
node-selection can be changed fast and easy in a tree-buffer without
customizing this option, but of course not for future Emacs sessions!"
:group 'ecb-tree-buffer
:set (function (lambda (sym val)
(set sym val)
(setq ecb-tree-do-not-leave-window-after-select--internal
(ecb-copy-list val))))
:type '(repeat (choice :menu-tag "Buffer-name"
(string :tag "Buffer-name as string")
(symbol :tag "Symbol holding buffer-name"))))
(defcustom ecb-tree-indent 4
"*Indent size for tree buffer.
If you change this during ECB is activated you must deactivate and activate
ECB again to take effect."
:group 'ecb-tree-buffer
:group 'ecb-most-important
:type 'integer)
(defcustom ecb-tree-expand-symbol-before t
"*Show the expand symbol before the items in a tree.
When the expand-symbol is located before the items then the tree looks like:
\[-] ECB
\[+] code-save
\[-] ecb-images
\[-] directories
When located after then the tree looks like:
ECB \[-]
code-save \[+]
ecb-images \[-]
directories \[-]
The after-example above use a value of 2 for `ecb-tree-indent' whereas the
before-example uses a value of 4.
It is recommended to display the expand-symbol before because otherwise it
could be that with a deep nested item-structure with and/or with long
item-names \(e.g. a deep directory-structure with some long
subdirectory-names) the expand-symbol is not visible in the tree-buffer and
the tree-buffer has to be horizontal scrolled to expand an item."
:group 'ecb-tree-buffer
:group 'ecb-most-important
:type 'boolean)
;; we can savely set here 'image as default because the tree-buffer-lib checks
;; itslef if image-support is possible and switches back to 'ascii-style if not.
(defcustom ecb-tree-buffer-style 'image
"*The style of the tree-buffers.
There are three different styles available:
Image-style \(value 'image):
Very nice and modern - just try it. For this style the options
`ecb-tree-indent' and `ecb-tree-expand-symbol-before' have no effect!
The value 'image means use image-style if images can be displayed with current
Emacs-setup \(otherwise auto. 'ascii-style is used).
Note: GNU Emacs <= 21.3.X for Windows does not support image-display so ECB
uses always 'ascii-guides even when here 'image is set!
Ascii-style with guide-lines \(value 'ascii-guides):
\[-] ECB
| \[+] code-save
`- \[-] ecb-images
| \[-] directories
| | \[-] height-15
| | | * close.xpm
| | | * empty.xpm
| | | * leaf.xpm
| | `- * open.xpm
| | \[+] height-17
| | \[+] height-19
| `- \[+] height-21
| \[x] history
| \[x] methods
`- \[x] sources
Ascii-style without guide-lines \(value 'ascii-no-guides) - this is the style
used by ECB <= 1.96:
\[-] ECB
\[+] code-save
\[-] ecb-images
\[-] directories
\[-] height-15
* close.xpm
* empty.xpm
* leaf.xpm
* open.xpm
\[+] height-17
\[+] height-19
\[+] height-21
\[x] history
\[x] methods
\[x] sources
With both ascii-styles the tree-layout can be affected with the options
`ecb-tree-indent' and `ecb-tree-expand-symbol-before'."
:group 'ecb-tree-buffer
:group 'ecb-most-important
:type '(radio (const :tag "Images-style" :value image)
(const :tag "Ascii-style with guide-lines" :value ascii-guides)
(const :tag "Ascii-style w/o guide-lines" :value ascii-no-guides)))
;; TODO: Klaus Berndl <[email protected]>: add here the analyse buffer if
;; additonal images are necessary - but currently i don't think we need
;; special images for this analyse-stuff.
(defcustom ecb-tree-image-icons-directories
(let ((base (concat (if ecb-regular-xemacs-package-p
(format "%s" (locate-data-directory "ecb"))
ecb-ecb-dir)
"ecb-images/")))
(cons (concat base "default/height-17")
(mapcar (function (lambda (i)
(cons (car i) (concat base (cdr i)))))
'((ecb-directories-buffer-name . "directories/height-17")
(ecb-sources-buffer-name . "sources/height-14_to_21")
(ecb-methods-buffer-name . "methods/height-14_to_21")))))
"*Directories where the images for the tree-buffer can be found.
This is a cons cell where:
car: Default directory where the default images for the tree-buffer can be
found. It should contain an image for every name of
`tree-buffer-tree-image-names'. The name of an image-file must be:
\"ecb-<NAME of TREE-BUFFER-TREE-IMAGE-NAMES>.<ALLOWED EXTENSIONS>\".
cdr: This is a list where each element is a cons again with: car is the buffer
name of the tree-buffer for which a special image-path should be used. The
buffer-name can either be defined as plain string or with a symbol which
contains the buffer-name as value. The latter one is recommended for the
builtin ECB-tree-buffers because then simply the related option-symbol can be
used \(e.g. the symbol `ecb-directories-buffer-name'). The cdr is the the
full-path of an additional image-directorie which is searched first for images
needed for the related tree-buffer. If the image can not be found in this
directory then the default-directory \(see above) is searched. If the
image can't even be found there the related ascii-symbol is used - which is
defined in `tree-buffer-tree-image-names'. If a tree-buffer is not contained
in this list then there is no additional special image-directory for it.
ECB comes with predefined images in several different heights - so for the
most senseful font-heights of a tree-buffer a fitting image-size should be
available. The images reside either in the subdirectory \"ecb-images\" of the
ECB-installation or - if ECB is installed as regular XEmacs-package - in the
ECB-etc data-directory \(the directory returned by \(locate-data-directory
\"ecb\")."
:group 'ecb-tree-buffer
:type '(cons (directory :tag "Full default image-path")
(repeat (cons (choice :menu-tag "Buffer-name"
(string :tag "Buffer-name as string")
(symbol :tag "Symbol holding
buffer-name"))
(directory :tag "Full image-path for this tree-buffer")))))
(defcustom ecb-tree-truncate-lines '(ecb-directories-buffer-name
ecb-sources-buffer-name
ecb-methods-buffer-name
ecb-history-buffer-name
ecb-analyse-buffer-name)
"*Truncate lines in ECB buffers.
If a buffer \(either its name or the variable-symbol which holds the name) is
contained in this list then line-truncation is switched on for this buffer
otherwise it is off.
The buffer-name can either be defined as plain string or with a symbol which
contains the buffer-name as value. The latter one is recommended to switch on
line-truncation for one of the builtin ECB-tree-buffers because then simply
the related option-symbol can be used. To truncate lines in the builtin
directories tree-buffer just add the symbol `ecb-directories-buffer-name' to
this option.
If you change this during ECB is activated you must deactivate and activate
ECB again to take effect."
:group 'ecb-tree-buffer
:group 'ecb-most-important
:type '(repeat (choice :menu-tag "Buffer-name"
(string :tag "Buffer-name as string")
(symbol :tag "Symbol holding buffer-name"))))
(defcustom ecb-tree-easy-hor-scroll 5
"*Scroll step for easy hor. scrolling via mouse-click in tree-buffers.
XEmacs has horizontal scroll-bars so invisible parts beyond the right
window-border of a tree-buffer can always made visible very easy.
GNU Emacs does not have hor. scroll-bars so especially with the mouse it is
quite impossible to scroll smoothly right and left. The functions
`scroll-left' and `scroll-right' can be annoying and are also not bound to
mouse-buttons.
If this option is a positive integer S then in all ECB-tree-buffers the keys
\[M-mouse-1] and \[M-mouse-3] are bound to scrolling left rsp. right with
scroll-step S - clicking with mouse-1 or mouse-2 onto the edge of the modeline
has the same effect, i.e. if you click with mouse-1 onto the left \(rsp.
right) edge of the modeline you will scroll left \(rsp. right). Additionally
\[C-M-mouse-1] and \[C-M-mouse-3] are bound to scrolling left rsp. right with
scroll-step `window-width' - 2. Default is a scroll-step of 5. If the value is
nil then no keys for horizontal scrolling are bound."
:group 'ecb-tree-buffer
:type '(radio :value 5
(const :tag "No hor. mouse scrolling" :value nil)
(integer :tag "Scroll step")))
(defcustom ecb-tree-make-parent-node-sticky t
"*Make the parent-node sticky in the headerline of the tree-buffer.
If not nil then the first line of the tree-buffer is used as header-line which
is used to display the next unvisible parent of the first visible node as
sticky, so always the parent of a node is visible and clickable. If a node has
no parent then just the next node above is displayed in the header-line. The
node displayed in the header-line is exactly in the same manner clickable as
all other nodes.
See also `ecb-tree-stickynode-indent-string'.
This feature is only available with Gnu Emacs, not with XEmacs."
:group 'ecb-tree-buffer
:group 'ecb-most-important
:type 'boolean)
(defcustom ecb-tree-stickynode-indent-string (tree-buffer-sticky-default-indent-string)
"*String used to indent the stickynode.
This string is used to match the space used by scrollbars and
fringe so it does not appear that the node-name is moving left/right
when it lands in the sticky line.
Normally the needed value is computed automatically by ECB. But if the result
is not matching this option allows to customize the indent-string.
The default value is computed by the function
`tree-buffer-sticky-default-indent-string', so you can change the needed value
with that starting-point.
Changing this option takes only effect after restarting Emacs!"
:group 'ecb-tree-buffer
:type 'string)
;; TODO: Klaus Berndl <[email protected]>: maybe we should change this to a
;; type analogous to ecb-tree-truncate-lines
(defcustom ecb-truncate-long-names t
"*Truncate long names that don't fit in the width of the ECB windows.
If you change this during ECB is activated you must deactivate and activate
ECB again to take effect."
:group 'ecb-tree-buffer
:type 'boolean)
;; TODO: Klaus Berndl <[email protected]>: maybe we should change this to a
;; type analogous to ecb-tree-truncate-lines
(defcustom ecb-tree-incremental-search 'prefix
"*Enable incremental search in the ECB-tree-buffers.
For a detailed explanation see the online help section \"Working with the
keyboard in the ECB buffers\". If you change this during ECB is activated you
must deactivate and activate ECB again to take effect."
:group 'ecb-tree-buffer
:type '(radio (const :tag "Match only prefix"
:value prefix)
(const :tag "Match every substring"
:value substring)
(const :tag "No incremental search"
:value nil)))
(defcustom ecb-tree-navigation-by-arrow t
"*Enable smart navigation in the tree-windows by horizontal arrow-keys.
If not nil then the left- and right-arrow keys work in the ECB tree-window in
the following smart way if onto an expandable node:
+ Left-arrow: If node is expanded then it will be collapsed otherwise point
jumps to the next \"higher\" node in the hierarchical tree \(higher means
the next higher tree-level or - if no higher level available - the next
higher node on the same level).
+ Right-arrow: If node is not expanded then it will be expanded.
Onto a not expandable node the horizontal arrow-keys go one character in the
senseful correct direction.
If this option is changed the new value takes first effect after deactivating
ECB and then activating it again!"
:group 'ecb-tree-buffer
:type 'boolean)
(defun ecb-show-any-node-info-by-mouse-moving-p ()
"Return not nil if for at least one tree-buffer showing node info only by
moving the mouse over a node is activated. See
`ecb-directories-show-node-info' etc...."
(let ((when-list (mapcar (function (lambda (elem)
(car (symbol-value elem))))
'(ecb-directories-show-node-info
ecb-sources-show-node-info
ecb-methods-show-node-info
ecb-history-show-node-info
ecb-analyse-show-node-info
))))
(or (member 'if-too-long when-list)
(member 'always when-list))))
(defcustom ecb-primary-secondary-mouse-buttons 'mouse-2--C-mouse-2
"*Primary- and secondary mouse button for using the ECB-buffers.
A click with the primary button causes the main effect in each ECB-buffer:
- ECB Directories: Expanding/collapsing nodes and displaying files in the ECB
Sources buffer.
- ECB sources/history: Opening the file in that edit-window specified by the
option `ecb-mouse-click-destination'.
- ECB Methods: Jumping to the method in that edit-window specified by the
option `ecb-mouse-click-destination'.
A click with the primary mouse-button while the SHIFT-key is pressed called
the POWER-click and does the following \(depending on the ECB-buffer where the
POWER-click occurs):
+ Directory-buffer: Refreshing the directory-contents-cache \(see
`ecb-cache-directory-contents').
+ Sources- and History-buffer: Only displaying the source-contents in the
method-buffer but not displaying the source-file in the edit-window.
+ Methods-buffer: Narrowing to the clicked method/variable/ect... \(see
`ecb-tag-visit-post-actions'). This works only for sources supported by
semantic!
In addition always the whole node-name is displayed in the minibuffer after a
POWER-click \(for this see `ecb-directories-show-node-info' etc...).
The secondary mouse-button is for opening \(jumping to) the file in another
edit-window \(see the documentation `ecb-mouse-click-destination').
The following combinations are possible:
- primary: mouse-2, secondary: C-mouse-2 \(means mouse-2 while CTRL-key is
pressed). This is the default setting.
- primary: mouse-1, secondary: C-mouse-1
- primary: mouse-1, secondary: mouse-2
Note: If the tree-buffers are used with the keyboard instead with the mouse
then [RET] is interpreted as primary mouse-button and [C-RET] as secondary
mouse-button!
If you change this during ECB is activated you must deactivate and activate
ECB again to take effect!"
:group 'ecb-tree-buffer
:group 'ecb-most-important
:type '(radio (const :tag "Primary: mouse-2, secondary: Ctrl-mouse-2"
:value mouse-2--C-mouse-2)
(const :tag "Primary: mouse-1, secondary: Ctrl-mouse-1"
:value mouse-1--C-mouse-1)
(const :tag "Primary: mouse-1, secondary: mouse-2"
:value mouse-1--mouse-2)))
(defcustom ecb-tree-mouse-action-trigger 'button-release
"*When the tree-buffer mouse-action should be triggered.
This option determines the moment a mouse-action in a tree-buffer is
triggered. This can be either direct after pressing a mouse-button \(value
'button-press) or not until releasing the mouse-button \(value:
'button-release).
If you change this during ECB is activated you must deactivate and activate
ECB again to take effect!"
:group 'ecb-tree-buffer
:type '(radio (const :tag "After button release" :value button-release)
(const :tag "After button press" :value button-press)))
(defcustom ecb-mouse-click-destination 'last-point
"*Destination of a mouse-button click.
Defines in which edit-window \(if splitted) ECB does the \"right\" action
\(opening a source, jumping to a method/variable etc.) after clicking with a
mouse-button \(see `ecb-primary-secondary-mouse-buttons') onto a node. There
are two possible choices:
- left-top: Does the \"right\" action always in the left/topmost edit-window.
- last-point: Does the \"right\" action always in that edit-window which had
the point before.
This is if the user has clicked either with the primary mouse-button or
has activated a popup-menu in the tree-buffer.
A click with the secondary mouse-button \(see again
`ecb-primary-secondary-mouse-buttons') does the \"right\" action always in
another edit-window related to the setting in this option: If there are two
edit-windows then the \"other\" edit-window is used and for more than 2
edit-windows the \"next\" edit-window is used \(whereas the next edit-window
of the last edit-window is the first edit-window).
If the edit-window is not splitted this setting has no effect.
Note: If the tree-buffers are used with the keyboard instead with the mouse
then this option takes effect too because [RET] is interpreted as primary
mouse-button and [C-RET] as secondary mouse-button!"
:group 'ecb-tree-buffer
:group 'ecb-most-important
:type '(radio (const :tag "Left/topmost edit-window"
:value left-top)
(const :tag "Last edit-window with point"
:value last-point)))
(defcustom ecb-common-tree-buffer-after-create-hook nil
"*Local hook running at the end of each tree-buffer creation.
Every function of this hook is called once without arguments direct after
creating a tree-buffer of ECB and it's local key-map. So for example a function
could be added which performs calls of `local-set-key' to define new
key-bindings for EVERY tree-buffer.
The following keys must not be rebind in all tree-buffers:
- <RET> and all combinations with <Shift> and <Ctrl>
- <TAB>
- `C-t'"
:group 'ecb-tree-buffer
:type 'hook)
(defcustom ecb-basic-buffer-sync '(Info-mode dired-mode)
"*Synchronize the basic ECB-buffers automatically with current edit buffer.
The basic ECB-buffers are the buffers for directories, sources, methods and
history.
If 'always then the synchronization takes place always a buffer changes in the
edit window, if nil then never. If a list of major-modes then only if the
`major-mode' of the new buffer belongs NOT to this list.
But in every case the synchronization takes only place if the current-buffer
in the edit-window has a relation to files or directories. Examples for the
former one are all programming-language-modes, `Info-mode' too, an example for
the latter one is `dired-mode'. For all major-modes related to
non-file/directory-buffers like `help-mode', `customize-mode' and others never
an autom. synchronization will be done!
It's recommended to exclude at least `Info-mode' because it makes no sense to
synchronize the ECB-windows after calling the Info help. Per default also
`dired-mode' is excluded but it can also making sense to synchronize the
ECB-directories/sources windows with the current directory in the
dired-buffer.
IMPORTANT NOTE: Every time the synchronization is done the hook
`ecb-basic-buffer-sync-hook' is evaluated."
:group 'ecb-tree-buffer
:type '(radio :tag "Synchronize basic ECB buffers"
(const :tag "Always" :value always)
(const :tag "Never" nil)
(repeat :tag "Not with these modes"
(symbol :tag "mode"))))
(defcustom ecb-basic-buffer-sync-delay 0.25
"*Time Emacs must be idle before the special ECB-buffers are synchronized.
Synchronizing is done with the current source displayed in the edit window. If
nil then there is no delay, means synchronization takes place immediately. A
small value of about 0.25 seconds saves CPU resources and you get even though
almost the same effect as if you set no delay."
:group 'ecb-tree-buffer
:type '(radio (const :tag "No synchronizing delay"
:value nil)
(number :tag "Idle time before synchronizing"
:value 0.25))
:set (function (lambda (symbol value)
(set symbol value)
(if ecb-minor-mode
(ecb-activate-ecb-autocontrol-function
value 'ecb-basic-buffer-sync))))
:initialize 'custom-initialize-default)
(defcustom ecb-basic-buffer-sync-hook nil
"*Hook run at the end of `ecb-basic-buffer-sync'.
See documentation of `ecb-basic-buffer-sync' for conditions when
synchronization takes place and so in turn these hooks are evaluated.
Precondition for such a hook:
Current buffer is the buffer of the currently selected edit-window.
Postcondition for such a hook:
Point must stay in the same edit-window as before evaluating the hook.
Important note: If the option `ecb-basic-buffer-sync' is not nil
the function `ecb-basic-buffer-sync' is running either every time
Emacs is idle or even after every command \(see
`ecb-basic-buffer-sync-delay'). So these hooks can be really
called very often! Therefore each function of this hook
should/must check in an efficient way at beginning if its task
have to be really performed and then do them only if really
necessary! Otherwise performance of Emacs could slow down
dramatically!
It is strongly recommended that each function added to this hook uses the
macro `ecb-do-if-buffer-visible-in-ecb-frame' at beginning! See
`ecb-speedbar-buffer-sync' and `ecb-eshell-buffer-sync' for
examples how to use this macro!"
:group 'ecb-tree-buffer
:type 'hook)
;;====================================================
;; Internals
;;====================================================
;;; ----- advice stuff -------------------------------------
(defvar ecb-adviced-function-sets nil
"A list of adviced-function sets defined with `defecb-advice-set'.
Each element is a cons-cell where car is the advice-set-var and cdr is an
indicator if the caller of `ecb-with-original-adviced-function-set' is the
outmost caller.
DO NOT CHANGE THIS!")
(defvar ecb-adviced-permanent-function-sets nil
"A list of symbols, each of them an advice-set which should be permanent.
Permanent means this advice set will not be disabled during deactivation of
ECB. This variable is only set by `defecb-advice-set'.
DO NOT CHANGE THIS!")
(defvar ecb-adviced-functions nil
"A list of all advices defined with `defecb-advice'.
This list is the set union of the values of all function-sets of
`ecb-adviced-function-sets'.
DO NOT CHANGE THIS!")
(defvar ecb-advices-debug-error nil
"It not nil then each advice of ECB reports when it's en/disabled or called.")
(defun ecb-advices-debug-error (advice class action &rest args)
"Run ARGS through `format' and write it to the *Messages*-buffer.
ADVICE is the adviced-function-symbol, CLASS is the advice-class \(after,
around or before) and ACTION is one of the symbols 'calling, 'enabling,
'disabling or 'reporting.
This will build up a message string like:
ECB <version>: debug <ACTION> of '<CLASS>' advice ADVICE: ARGS.
If ARGS is nil then only the message above is reported."
(when ecb-advices-debug-error
(message (concat (format "ECB %s: debug %s of '%s' advice %s "
ecb-version
action
class
advice)
(if args
(apply 'format args))))))
(defmacro defecb-advice-set (advice-set docstring &optional permanent)
"Defines an advice-set for ECB.
This defines a variable which will contain adviced functions defined by
`defecb-advice-set'. This is a set of advices which can be enabled or disabled
\"en block\" which must be done either by `ecb-enable-advices',
`ecb-disable-advices' or `ecb-with-original-adviced-function-set'.
Before defining a new advice-set it's recommended to take a look at the value
of `ecb-adviced-function-sets' if there is already a suitable advice-set.
IMPORTANT: Each advice in ECB must be defined by `defecb-advice' and must
belong to an advice-set previously defined by `defecb-advice-set'!
All advice-sets of ECB will be automatically\(!) disabled at load-time of the
ecb-library and at deactivation-time of ECB. But: Enabling of a certain
advice-set must be done appropriately.
If optional argument PERMANENT is t then this advice-set will NOT be disabled
at deactivation-time of ECB! Calling `ecb-disable-advices' for an advice set
defined with permanent is t will take no effect unless the optional argument
FORCE-PERMANENT of this function is set to not nil.
PERMANENT can also be a function which will be called by `ecb-disable-advices'
for this advice set \(the function gets one argument: the symbol of the
advice-set) and have to return not nil if the advice-set should not be disable
by `ecb-disable-advices' unless the FORCE-PERMANENT of this function is set to
not nil.
Example:
\(defecb-advice-set ecb-always-disabled-advices
\"These advices are always disabled.\")"
`(eval-and-compile
(add-to-list 'ecb-adviced-function-sets (cons (quote ,advice-set), nil))
,(if permanent
`(add-to-list 'ecb-adviced-permanent-function-sets
(cons (quote ,advice-set) ,permanent)))
(defvar ,advice-set nil ,docstring)))
(put 'defecb-advice-set 'lisp-indent-function 1)
(defmacro defecb-advice (adviced-function advice-class advice-set advice-docstring &rest body)
"Defines an advice for ADVICED-FUNCTION with ADVICE-CLASS for ADVICE-SET.
ADVICED-FUNCTION must be an advicable object \(e.g. a function, a subr
etc...). ADVICE-CLASS must be one of around, after or before. ADVICE-SET must
ba an advice-set previously defined by `defecb-advice-set'. ADVICE-DOCSTRING
ist the docstring for the advice. BODY is the program-code for the advice as
it would be written with `defadvice'.
Do not quote ADVICED-FUNCTION, ADVICE-CLASS and ADVICE-SET.
Example:
\(defecb-advice delete-frame around ecb-layout-basic-adviced-functions
\"If FRAME is equal to the ECB frame then...\"
\(let \(\(frame \(or \(ad-get-arg 0) \(selected-frame))))
\(if \(and ecb-minor-mode
\(equal frame ecb-frame))
\(when \(ecb-confirm \"Attempt to delete the ECB-frame....Proceed? \")
\(ecb-deactivate-internal)
ad-do-it)
ad-do-it)))"
`(progn
(if (assoc (quote ,advice-set) ecb-adviced-function-sets)
(add-to-list (quote ,advice-set)
(cons (quote ,adviced-function) (quote ,advice-class)))
(error "The advice-set %s does not exist!"
(symbol-name (quote ,advice-set))))
(if (not (member (quote ,advice-class)
'(around after before)))
(error "The advice-class %s is not allowed - only around, after and before!"
(symbol-name (quote ,advice-class))))
(add-to-list 'ecb-adviced-functions (cons (quote ,adviced-function) (quote ,advice-class)))
(eval-and-compile
(defadvice ,adviced-function (,advice-class ecb)
,advice-docstring
(ecb-advices-debug-error (quote ,adviced-function)
(quote ,advice-class)
'calling)
,@body))))
(put 'defecb-advice 'lisp-indent-function 3)
;; (insert (pp (macroexpand '(defecb-advice insert around
;; ecb-always-disabled-advices "doc"
;; (message "test")))))
(defun ecb-enable-ecb-advice (function-symbol advice-class arg)
"If ARG is greater or equal zero then enable the adviced version of
FUNCTION-SYMBOL. Otherwise disable the adviced version. The advice must be
defined with class ADVICE-CLASS by `defecb-advice'.
IMPORTANT: Do not use the function directly. Always use `ecb-enable-advices',
`ecb-disable-advices' or `ecb-with-original-adviced-function-set'!."
(if (< arg 0)
(progn
(ad-disable-advice function-symbol advice-class 'ecb)
(ad-activate function-symbol)
(ecb-advices-debug-error function-symbol advice-class 'disabling))
(ad-enable-advice function-symbol advice-class 'ecb)
(ad-activate function-symbol)
(ecb-advices-debug-error function-symbol advice-class 'enabling)))
(defun ecb-enable-advices (adviced-function-set-var)
"Enable all advices of ADVICED-FUNCTION-SET-VAR, which must be defined by
`defecb-advice-set'."
(if ecb-advices-debug-error
(message "ECB %s: debug enabling the advice-set: %s"
ecb-version adviced-function-set-var))
(if (eq adviced-function-set-var 'ecb-always-disabled-advices)
(error "The advice-set ecb-always-disabled-advices must not be enabled!"))
(if (not (assq adviced-function-set-var ecb-adviced-function-sets))
(error "The adviced function set %s is not defined by defecb-advice-set!"
(symbol-name adviced-function-set-var)))
(dolist (elem (symbol-value adviced-function-set-var))
(ecb-enable-ecb-advice (car elem) (cdr elem) 1)))
(defun ecb-disable-advices (adviced-function-set-var &optional force-permanent)
"Disable all advices of ADVICED-FUNCTION-SET-VAR, which must be defined by
`defecb-advice-set'
This function tests if ADVICED-FUNCTION-SET-VAR has been defined as permanent
by `defecb-advice-set'.
Calling `ecb-disable-advices' for an advice set defined with
permanent t will take no effect unless the optional argument
FORCE-PERMANENT is set to not nil. If the advice set is defined as permanent
with a permanent-disable-function then this function is called with
ADVICED-FUNCTION-SET-VAR as argument; if this function returns not nil then
the adviced will be treated as permanent and will not being disabled.
If optional FORCE-PERMANENT is not nil then ADVICED-FUNCTION-SET-VAR will
be disabled regardless if permanent or not."
(if ecb-advices-debug-error
(message "ECB %s: debug disabling the advice-set: %s"
ecb-version adviced-function-set-var))
(if (not (assq adviced-function-set-var ecb-adviced-function-sets))
(error "The adviced function set %s is not defined by defecb-advice-set!"
(symbol-name adviced-function-set-var)))
(let ((permanent (if force-permanent
nil
(cdr (assq adviced-function-set-var
ecb-adviced-permanent-function-sets)))))
(unless (or (eq permanent t)
(and (functionp permanent)
(funcall permanent adviced-function-set-var)))
(dolist (elem (symbol-value adviced-function-set-var))
(ecb-enable-ecb-advice (car elem) (cdr elem) -1)))))
;; for the outmost-caller-stuff see ecb-with-original-adviced-function-set
(defmacro ecb-with-ecb-advice (function-symbol advice-class &rest body)
"Evaluates BODY with the adviced version of FUNCTION-SYMBOL. The advice must
be defined by `defecb-advice' with class ADVICE-CLASS for the advice-set
`ecb-always-disabled-advices'. Otherwise an error occurs. The advice is only
active during BODY.
BODY is protected by `unwind-protect' so in each case the advice
will be disabled after finishing this macro unless it is nested
within a call to this macro for the *same* FUNCTION-SYMBOL and
ADVICE-CLASS-combination! This means that the usage of this macro
is save for arbitrary nested calls, so full BODY is guaranted
being evaluated with enabled ADVICE-CLASS advice for
FUNCTION-SYMBOL.
Returns the value of BODY.
Example where this macro is used for `walk-windows' within another advice:
\(ecb-with-ecb-advice 'walk-windows 'around
ad-do-it)"
(let ((outmost-caller-p (make-symbol "outmost-caller-p")))
;; we have to check if we are the outmost-caller of this macro for this
;; adviced function AND the advice-class! different advice-classes for the
;; same function have to be treated differently!!
`(let ((,outmost-caller-p (unless (member ,advice-class (get ,function-symbol 'ecb-with-ecb-advice))
(put ,function-symbol 'ecb-with-ecb-advice
(append (list ,advice-class) (get ,function-symbol 'ecb-with-ecb-advice)))
,advice-class)))
(if (not (member (cons ,function-symbol ,advice-class)
ecb-always-disabled-advices))
(error "Advice for %s with class %s not registered in ecb-always-disabled-advices!"
(symbol-name ,function-symbol)
(symbol-name ,advice-class)))
(if ecb-advices-debug-error
(message "ECB %s: debug with always disabled ecb-advice: %s %s - ENTRY"
ecb-version ,advice-class ,function-symbol))
(unwind-protect
(progn
(when ,outmost-caller-p
(ecb-enable-ecb-advice ,function-symbol ,advice-class 1))
,@body)
(when ,outmost-caller-p
;; Only if we are the outmost caller we are allowed to disable the
;; enabled advice
(put ,function-symbol 'ecb-with-ecb-advice
(delete ,advice-class (get ,function-symbol 'ecb-with-ecb-advice)))
(ecb-enable-ecb-advice ,function-symbol ,advice-class -1))
(if ecb-advices-debug-error
(message "ECB %s: debug with always disabled ecb-advice: %s %s - EXIT"
ecb-version ,advice-class ,function-symbol))))))
(put 'ecb-with-ecb-advice 'lisp-indent-function 2)
;; (insert (pp (macroexpand '(ecb-with-ecb-advice 'one-window-p 'around
;; (message "")))))
(defmacro ecb-with-original-adviced-function-set (adviced-function-set-var &rest body)
"Evaluates BODY with all adviced functions of ADVICED-FUNCTION-SET-VAR
being disabled \(means with their original definition). Restores always \(even
if an error occurs during evaluating BODY) the previous state of the adviced
functions, means it depends if the call to this macro is the outermost call:
Only if it is the outermost-call the advices of the used advice-set will be
disabled after finishing. So full BODY is guaranted being evaluated with
disabled advices of ADVICED-FUNCTION-SET-VAR.
ADVICED-FUNCTION-SET-VAR must be defined by `defecb-advice-set' and all
advices of this set must be defined by `defecb-advice'. Otherwise an error
occurs.
Example:
\(ecb-with-original-adviced-function-set 'ecb-layout-basic-adviced-functions
\(do-something..))"
(let ((outmost-caller-p (make-symbol "outmost-caller-p")))
`(let ((,outmost-caller-p
(unless (equal (cdr (assq ,adviced-function-set-var ecb-adviced-function-sets))
'outmost-caller)
;; if we are the outmost caller of this macro we store this
;; for
;; a) following callers
;; b) ourself, so we can later reset is
(setcdr (assq ,adviced-function-set-var ecb-adviced-function-sets) 'outmost-caller))
))
(if ecb-advices-debug-error
(message "ECB %s: debug with original advice-set: %s - ENTRY"
ecb-version ,adviced-function-set-var))
(unwind-protect
(progn
(when ,outmost-caller-p
;; we must force disabling permanent advice-sets too
(ecb-disable-advices ,adviced-function-set-var t))
,@body)
(when ,outmost-caller-p
;; Only if we are the outmost caller we are allowed to re-enable the
;; disabled advice-set
(setcdr (assq ,adviced-function-set-var ecb-adviced-function-sets) nil)
(ecb-enable-advices ,adviced-function-set-var))
(if ecb-advices-debug-error
(message "ECB %s: debug with original advice-set: %s - EXIT"
ecb-version ,adviced-function-set-var))))))
(put 'ecb-with-original-adviced-function-set 'lisp-indent-function 1)
(defecb-advice-set ecb-always-disabled-advices
"These advices are always disabled.
This advice-set can not be enabled by `ecb-enable-advices' but such an
advice has to be activated 'on demand' by the caller. Such an advice must be
used with the macro `ecb-with-ecb-advice'.")
;; -- window stuff
(defun ecb-combine-ecb-button/edit-win-nr (ecb-button edit-window-nr)
"Depending on ECB-BUTTON and EDIT-WINDOW-NR return one value:
- nil if ECB-BUTTON is 1.
- t if ECB-BUTTON is 2 and the edit-area of ECB is splitted.
- EDIT-WINDOW-NR if ECB-BUTTON is 3."
(case ecb-button
(1 nil)
(2 (ecb-edit-window-splitted))
(3 edit-window-nr)))
(defun ecb-get-edit-window (other-edit-window)
"Get the correct edit-window. Which one is the correct one depends on the
value of OTHER-EDIT-WINDOW \(which is a value returned by
`ecb-combine-ecb-button/edit-win-nr') and `ecb-mouse-click-destination'.
- OTHER-EDIT-WINDOW is nil: Get the edit-window according to the option
`ecb-mouse-click-destination'.
- OTHER-EDIT-WINDOW is t: Get the next edit-window in the cyclic list of
current edit-windows starting either from the left-top-most one or from the
last edit-window with point (depends on
`ecb-mouse-click-destination').
- OTHER-EDIT-WINDOW is an integer: Get exactly the edit-window with that
number > 0."
(let ((edit-win-list (ecb-canonical-edit-windows-list)))
(typecase other-edit-window
(null
(if (eq ecb-mouse-click-destination 'left-top)
(car edit-win-list)
ecb-last-edit-window-with-point))
(integer
(ecb-get-edit-window-by-number other-edit-window edit-win-list))
(otherwise
(ecb-next-listelem edit-win-list
(if (eq ecb-mouse-click-destination 'left-top)
(car edit-win-list)
ecb-last-edit-window-with-point))))))
(defun ecb-source-make (filename &optional buffer)
"Build a source-object from FILENAME and BUFFER.
If optional arg BUFFER is nil then the just FILENAME is returned.
If BUFFER is not nil then it can be either a buffer-object or a buffer-name.
A cons is returned where car is FILENAME and cdr is the buffername of BUFFER."
(let ((buffername (when buffer
(if (bufferp buffer)
(buffer-name buffer)
buffer))))
(if buffername
(cons filename buffername)
filename)))
(defun ecb-source-get-filename (source)
"SOURCE is either a string, then it is a filename or a cons, then the car is
the filename and the cdr is the buffer-name, whereas the latter one can be the
name of an indirect-buffer."