Mark face aliases with "-face" suffix as obsolete.
[bpt/emacs.git] / lisp / progmodes / ebrowse.el
1 ;;; ebrowse.el --- Emacs C++ class browser & tags facility
2
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
4 ;; 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 ;; Free Software Foundation Inc.
6
7 ;; Author: Gerd Moellmann <gerd@gnu.org>
8 ;; Maintainer: FSF
9 ;; Keywords: C++ tags tools
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25
26 ;;; Commentary:
27
28 ;; This package implements
29
30 ;; - A class browser for C++
31 ;; - A complete set of tags-like functions working on class trees
32 ;; - An electric buffer list showing class browser buffers only
33
34 ;; Documentation is found in a separate Info file.
35
36 ;;; Code:
37
38 (require 'easymenu)
39 (require 'view)
40 (require 'ebuff-menu)
41
42 (eval-when-compile
43 (require 'cl)
44 (require 'helper))
45
46 \f
47 ;;; User-options
48
49 (defgroup ebrowse nil
50 "Settings for the C++ class browser."
51 :group 'tools)
52
53
54 (defcustom ebrowse-search-path nil
55 "*List of directories to search for source files in a class tree.
56 Elements should be directory names; nil as an element means to try
57 to find source files relative to the location of the BROWSE file loaded."
58 :group 'ebrowse
59 :type '(repeat (choice (const :tag "Default" nil)
60 (string :tag "Directory"))))
61
62
63 (defcustom ebrowse-view/find-hook nil
64 "*Hooks run after finding or viewing a member or class."
65 :group 'ebrowse
66 :type 'hook)
67
68
69 (defcustom ebrowse-not-found-hook nil
70 "*Hooks run when finding or viewing a member or class was not successful."
71 :group 'ebrowse
72 :type 'hook)
73
74
75 (defcustom ebrowse-electric-list-mode-hook nil
76 "*Hook called by `ebrowse-electric-position-mode'."
77 :group 'ebrowse
78 :type 'hook)
79
80
81 (defcustom ebrowse-max-positions 50
82 "*Number of markers saved on electric position stack."
83 :group 'ebrowse
84 :type 'integer)
85
86
87 \f
88 (defgroup ebrowse-tree nil
89 "Settings for class tree buffers."
90 :group 'ebrowse)
91
92
93 (defcustom ebrowse-tree-mode-hook nil
94 "*Hook run in each new tree buffer."
95 :group 'ebrowse-tree
96 :type 'hook)
97
98
99 (defcustom ebrowse-tree-buffer-name "*Tree*"
100 "*The default name of class tree buffers."
101 :group 'ebrowse-tree
102 :type 'string)
103
104
105 (defcustom ebrowse--indentation 4
106 "*The amount by which subclasses are indented in the tree."
107 :group 'ebrowse-tree
108 :type 'integer)
109
110
111 (defcustom ebrowse-source-file-column 40
112 "*The column in which source file names are displayed in the tree."
113 :group 'ebrowse-tree
114 :type 'integer)
115
116
117 (defcustom ebrowse-tree-left-margin 2
118 "*Amount of space left at the left side of the tree display.
119 This space is used to display markers."
120 :group 'ebrowse-tree
121 :type 'integer)
122
123
124 \f
125 (defgroup ebrowse-member nil
126 "Settings for member buffers."
127 :group 'ebrowse)
128
129
130 (defcustom ebrowse-default-declaration-column 25
131 "*The column in which member declarations are displayed in member buffers."
132 :group 'ebrowse-member
133 :type 'integer)
134
135
136 (defcustom ebrowse-default-column-width 25
137 "*The width of the columns in member buffers (short display form)."
138 :group 'ebrowse-member
139 :type 'integer)
140
141
142 (defcustom ebrowse-member-buffer-name "*Members*"
143 "*The name of the buffer for member display."
144 :group 'ebrowse-member
145 :type 'string)
146
147
148 (defcustom ebrowse-member-mode-hook nil
149 "*Run in each new member buffer."
150 :group 'ebrowse-member
151 :type 'hook)
152
153
154 \f
155 (defgroup ebrowse-faces nil
156 "Faces used by Ebrowse."
157 :group 'ebrowse)
158
159
160 (defface ebrowse-tree-mark
161 '((((min-colors 88)) (:foreground "red1"))
162 (t (:foreground "red")))
163 "*The face used for the mark character in the tree."
164 :group 'ebrowse-faces)
165 (define-obsolete-face-alias 'ebrowse-tree-mark-face 'ebrowse-tree-mark "22.1")
166
167
168 (defface ebrowse-root-class
169 '((((min-colors 88)) (:weight bold :foreground "blue1"))
170 (t (:weight bold :foreground "blue")))
171 "*The face used for root classes in the tree."
172 :group 'ebrowse-faces)
173 (define-obsolete-face-alias 'ebrowse-root-class-face 'ebrowse-root-class "22.1")
174
175
176 (defface ebrowse-file-name
177 '((t (:italic t)))
178 "*The face for filenames displayed in the tree."
179 :group 'ebrowse-faces)
180 (define-obsolete-face-alias 'ebrowse-file-name-face 'ebrowse-file-name "22.1")
181
182
183 (defface ebrowse-default
184 '((t nil))
185 "*Face for everything else in the tree not having other faces."
186 :group 'ebrowse-faces)
187 (define-obsolete-face-alias 'ebrowse-default-face 'ebrowse-default "22.1")
188
189
190 (defface ebrowse-member-attribute
191 '((((min-colors 88)) (:foreground "red1"))
192 (t (:foreground "red")))
193 "*Face used to display member attributes."
194 :group 'ebrowse-faces)
195 (define-obsolete-face-alias 'ebrowse-member-attribute-face
196 'ebrowse-member-attribute "22.1")
197
198
199 (defface ebrowse-member-class
200 '((t (:foreground "purple")))
201 "*Face used to display the class title in member buffers."
202 :group 'ebrowse-faces)
203 (define-obsolete-face-alias 'ebrowse-member-class-face
204 'ebrowse-member-class "22.1")
205
206
207 (defface ebrowse-progress
208 '((((min-colors 88)) (:background "blue1"))
209 (t (:background "blue")))
210 "*Face for progress indicator."
211 :group 'ebrowse-faces)
212 (define-obsolete-face-alias 'ebrowse-progress-face 'ebrowse-progress "22.1")
213
214
215 \f
216 ;;; Utilities.
217
218 (defun ebrowse-some (predicate vector)
219 "Return true if PREDICATE is true of some element of VECTOR.
220 If so, return the value returned by PREDICATE."
221 (let ((length (length vector))
222 (i 0)
223 result)
224 (while (and (< i length) (not result))
225 (setq result (funcall predicate (aref vector i))
226 i (1+ i)))
227 result))
228
229
230 (defun ebrowse-every (predicate vector)
231 "Return true if PREDICATE is true of every element of VECTOR."
232 (let ((length (length vector))
233 (i 0)
234 (result t))
235 (while (and (< i length) result)
236 (setq result (funcall predicate (aref vector i))
237 i (1+ i)))
238 result))
239
240
241 (defun ebrowse-position (item list &optional test)
242 "Return the position of ITEM in LIST or nil if not found.
243 Compare items with `eq' or TEST if specified."
244 (let ((i 0) found)
245 (cond (test
246 (while list
247 (when (funcall test item (car list))
248 (setq found i list nil))
249 (setq list (cdr list) i (1+ i))))
250 (t
251 (while list
252 (when (eq item (car list))
253 (setq found i list nil))
254 (setq list (cdr list) i (1+ i)))))
255 found))
256
257
258 (defun ebrowse-delete-if-not (predicate list)
259 "Remove elements not satisfying PREDICATE from LIST and return the result.
260 This is a destructive operation."
261 (let (result)
262 (while list
263 (let ((next (cdr list)))
264 (when (funcall predicate (car list))
265 (setq result (nconc result list))
266 (setf (cdr list) nil))
267 (setq list next)))
268 result))
269
270
271 (defmacro ebrowse-output (&rest body)
272 "Eval BODY with a writable current buffer.
273 Preserve buffer's modified state."
274 (let ((modified (make-symbol "--ebrowse-output--")))
275 `(let (buffer-read-only (,modified (buffer-modified-p)))
276 (unwind-protect
277 (progn ,@body)
278 (set-buffer-modified-p ,modified)))))
279
280
281 (defmacro ebrowse-ignoring-completion-case (&rest body)
282 "Eval BODY with `completion-ignore-case' bound to t."
283 `(let ((completion-ignore-case t))
284 ,@body))
285
286
287 (defmacro ebrowse-save-selective (&rest body)
288 "Eval BODY with `selective-display' restored at the end."
289 (let ((var (make-symbol "var")))
290 `(let ((,var selective-display))
291 (unwind-protect
292 (progn ,@body)
293 (setq selective-display ,var)))))
294
295
296 (defmacro ebrowse-for-all-trees (spec &rest body)
297 "For all trees in SPEC, eval BODY."
298 (let ((var (make-symbol "var"))
299 (spec-var (car spec))
300 (array (cadr spec)))
301 `(loop for ,var being the symbols of ,array
302 as ,spec-var = (get ,var 'ebrowse-root) do
303 (when (vectorp ,spec-var)
304 ,@body))))
305
306 ;;; Set indentation for macros above.
307
308 (put 'ebrowse-output 'lisp-indent-hook 0)
309 (put 'ebrowse-ignoring-completion-case 'lisp-indent-hook 0)
310 (put 'ebrowse-save-selective 'lisp-indent-hook 0)
311 (put 'ebrowse-for-all-trees 'lisp-indent-hook 1)
312
313
314 (defsubst ebrowse-set-face (start end face)
315 "Set face of a region START END to FACE."
316 (overlay-put (make-overlay start end) 'face face))
317
318
319 (defun ebrowse-completing-read-value (prompt table initial-input)
320 "Read a string in the minibuffer, with completion.
321 Case is ignored in completions.
322
323 PROMPT is a string to prompt with; normally it ends in a colon and a space.
324 TABLE is an alist whose elements' cars are strings, or an obarray.
325 TABLE can also be a function to do the completion itself.
326 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.
327 If it is (STRING . POSITION), the initial input
328 is STRING, but point is placed POSITION characters into the string."
329 (ebrowse-ignoring-completion-case
330 (completing-read prompt table nil t initial-input)))
331
332
333 (defun ebrowse-value-in-buffer (sym buffer)
334 "Return the value of SYM in BUFFER."
335 (let ((old-buffer (current-buffer)))
336 (unwind-protect
337 (progn
338 (set-buffer buffer)
339 (symbol-value sym))
340 (set-buffer old-buffer))))
341
342
343 (defun ebrowse-rename-buffer (new-name)
344 "Rename current buffer to NEW-NAME.
345 If a buffer with name NEW-NAME already exists, delete it first."
346 (let ((old-buffer (get-buffer new-name)))
347 (unless (eq old-buffer (current-buffer))
348 (when old-buffer
349 (save-excursion (kill-buffer old-buffer)))
350 (rename-buffer new-name))))
351
352
353 (defun ebrowse-trim-string (string)
354 "Return a copy of STRING with leading white space removed.
355 Replace sequences of newlines with a single space."
356 (when (string-match "^[ \t\n\r]+" string)
357 (setq string (substring string (match-end 0))))
358 (loop while (string-match "[\n]+" string)
359 finally return string do
360 (setq string (replace-match " " nil t string))))
361
362
363 (defun ebrowse-width-of-drawable-area ()
364 "Return the width of the display area for the current buffer.
365 If buffer is displayed in a window, use that window's width,
366 otherwise use the current frame's width."
367 (let ((window (get-buffer-window (current-buffer))))
368 (if window
369 (window-width window)
370 (frame-width))))
371
372 \f
373 ;;; Structure definitions
374
375 (defstruct (ebrowse-hs (:type vector) :named)
376 "Header structure found at the head of BROWSE files."
377 ;; A version string that is compared against the version number of
378 ;; the Lisp package when the file is loaded. This is done to
379 ;; detect file format changes.
380 version
381 ;; Command line options used for producing the BROWSE file.
382 command-line-options
383 ;; The following slot is currently not used. It's kept to keep
384 ;; the file format compatible.
385 unused
386 ;; A slot that is filled out after the tree is loaded. This slot is
387 ;; set to a hash table mapping members to lists of classes in which
388 ;; they are defined.
389 member-table)
390
391
392 (defstruct (ebrowse-ts (:type vector) :named)
393 "Tree structure.
394 Following the header structure, a BROWSE file contains a number
395 of `ebrowse-ts' structures, each one describing one root class of
396 the class hierarchy with all its subclasses."
397 ;; A `ebrowse-cs' structure describing the root class.
398 class
399 ;; A list of `ebrowse-ts' structures for all subclasses.
400 subclasses
401 ;; Lists of `ebrowse-ms' structures for each member in a group of
402 ;; members.
403 member-variables member-functions static-variables static-functions
404 friends types
405 ;; List of `ebrowse-ts' structures for base classes. This slot is
406 ;; filled at load time.
407 base-classes
408 ;; A marker slot used in the tree buffer (can be saved back to disk.
409 mark)
410
411
412 (defstruct (ebrowse-bs (:type vector) :named)
413 "Common sub-structure.
414 A common structure defining an occurrence of some name in the
415 source files."
416 ;; The class or member name as a string constant
417 name
418 ;; An optional string for the scope of nested classes or for
419 ;; namespaces.
420 scope
421 ;; Various flags describing properties of classes/members, e.g. is
422 ;; template, is const etc.
423 flags
424 ;; File in which the entity is found. If this is part of a
425 ;; `ebrowse-ms' member description structure, and FILE is nil, then
426 ;; search for the name in the SOURCE-FILE of the members class.
427 file
428 ;; Regular expression to search for. This slot can be a number in
429 ;; which case the number is the file position at which the regular
430 ;; expression is found in a separate regexp file (see the header
431 ;; structure). This slot can be nil in which case the regular
432 ;; expression will be generated from the class/member name.
433 pattern
434 ;; The buffer position at which the search for the class or member
435 ;; will start.
436 point)
437
438
439 (defstruct (ebrowse-cs (:include ebrowse-bs) (:type vector) :named)
440 "Class structure.
441 This is the structure stored in the CLASS slot of a `ebrowse-ts'
442 structure. It describes the location of the class declaration."
443 source-file)
444
445
446 (defstruct (ebrowse-ms (:include ebrowse-bs) (:type vector) :named)
447 "Member structure.
448 This is the structure describing a single member. The `ebrowse-ts'
449 structure contains various lists for the different types of
450 members."
451 ;; Public, protected, private
452 visibility
453 ;; The file in which the member's definition can be found.
454 definition-file
455 ;; Same as PATTERN above, but for the member definition.
456 definition-pattern
457 ;; Same as POINT above but for member definition.
458 definition-point)
459
460
461 \f
462 ;;; Some macros to access the FLAGS slot of a MEMBER.
463
464 (defsubst ebrowse-member-bit-set-p (member bit)
465 "Value is non-nil if MEMBER's bit BIT is set."
466 (/= 0 (logand (ebrowse-bs-flags member) bit)))
467
468
469 (defsubst ebrowse-virtual-p (member)
470 "Value is non-nil if MEMBER is virtual."
471 (ebrowse-member-bit-set-p member 1))
472
473
474 (defsubst ebrowse-inline-p (member)
475 "Value is non-nil if MEMBER is inline."
476 (ebrowse-member-bit-set-p member 2))
477
478
479 (defsubst ebrowse-const-p (member)
480 "Value is non-nil if MEMBER is const."
481 (ebrowse-member-bit-set-p member 4))
482
483
484 (defsubst ebrowse-pure-virtual-p (member)
485 "Value is non-nil if MEMBER is a pure virtual function."
486 (ebrowse-member-bit-set-p member 8))
487
488
489 (defsubst ebrowse-mutable-p (member)
490 "Value is non-nil if MEMBER is mutable."
491 (ebrowse-member-bit-set-p member 16))
492
493
494 (defsubst ebrowse-template-p (member)
495 "Value is non-nil if MEMBER is a template."
496 (ebrowse-member-bit-set-p member 32))
497
498
499 (defsubst ebrowse-explicit-p (member)
500 "Value is non-nil if MEMBER is explicit."
501 (ebrowse-member-bit-set-p member 64))
502
503
504 (defsubst ebrowse-throw-list-p (member)
505 "Value is non-nil if MEMBER has a throw specification."
506 (ebrowse-member-bit-set-p member 128))
507
508
509 (defsubst ebrowse-extern-c-p (member)
510 "Value is non-nil if MEMBER.is `extern \"C\"'."
511 (ebrowse-member-bit-set-p member 256))
512
513
514 (defsubst ebrowse-define-p (member)
515 "Value is non-nil if MEMBER is a define."
516 (ebrowse-member-bit-set-p member 512))
517
518
519 (defconst ebrowse-version-string "ebrowse 5.0"
520 "Version string expected in BROWSE files.")
521
522
523 (defconst ebrowse-globals-name "*Globals*"
524 "The name used for the surrogate class.containing global entities.
525 This must be the same that `ebrowse' uses.")
526
527
528 (defvar ebrowse--last-regexp nil
529 "Last regular expression searched for in tree and member buffers.
530 Each tree and member buffer maintains its own search history.")
531 (make-variable-buffer-local 'ebrowse--last-regexp)
532
533
534 (defconst ebrowse-member-list-accessors
535 '(ebrowse-ts-member-variables
536 ebrowse-ts-member-functions
537 ebrowse-ts-static-variables
538 ebrowse-ts-static-functions
539 ebrowse-ts-friends
540 ebrowse-ts-types)
541 "List of accessors for member lists.
542 Each element is the symbol of an accessor function.
543 The nth element must be the accessor for the nth member list
544 in an `ebrowse-ts' structure.")
545
546
547 ;;; FIXME: Add more doc strings for the buffer-local variables below.
548
549 (defvar ebrowse--tree-obarray nil
550 "Obarray holding all `ebrowse-ts' structures of a class tree.
551 Buffer-local in Ebrowse buffers.")
552
553
554 (defvar ebrowse--tags-file-name nil
555 "File from which BROWSE file was loaded.
556 Buffer-local in Ebrowse buffers.")
557
558
559 (defvar ebrowse--header nil
560 "Header structure of type `ebrowse-hs' of a class tree.
561 Buffer-local in Ebrowse buffers.")
562
563
564 (defvar ebrowse--frozen-flag nil
565 "Non-nil means an Ebrowse buffer won't be reused.
566 Buffer-local in Ebrowse buffers.")
567
568
569 (defvar ebrowse--show-file-names-flag nil
570 "Non-nil means show file names in a tree buffer.
571 Buffer-local in Ebrowse tree buffers.")
572
573
574 (defvar ebrowse--long-display-flag nil
575 "Non-nil means show members in long display form.
576 Buffer-local in Ebrowse member buffers.")
577
578
579 (defvar ebrowse--n-columns nil
580 "Number of columns to display for short member display form.
581 Buffer-local in Ebrowse member buffers.")
582
583
584 (defvar ebrowse--column-width nil
585 "Width of a columns to display for short member display form.
586 Buffer-local in Ebrowse member buffers.")
587
588
589 (defvar ebrowse--virtual-display-flag nil
590 "Non-nil means display virtual members in a member buffer.
591 Buffer-local in Ebrowse member buffers.")
592
593
594 (defvar ebrowse--inline-display-flag nil
595 "Non-nil means display inline members in a member buffer.
596 Buffer-local in Ebrowse member buffers.")
597
598
599 (defvar ebrowse--const-display-flag nil
600 "Non-nil means display const members in a member buffer.
601 Buffer-local in Ebrowse member buffers.")
602
603
604 (defvar ebrowse--pure-display-flag nil
605 "Non-nil means display pure virtual members in a member buffer.
606 Buffer-local in Ebrowse member buffers.")
607
608
609 (defvar ebrowse--filters nil
610 "Filter for display of public, protected, and private members.
611 This is a vector of three elements. An element nil means the
612 corresponding members are not shown.
613 Buffer-local in Ebrowse member buffers.")
614
615
616 (defvar ebrowse--show-inherited-flag nil
617 "Non-nil means display inherited members in a member buffer.
618 Buffer-local in Ebrowse member buffers.")
619
620
621 (defvar ebrowse--attributes-flag nil
622 "Non-nil means display member attributes in a member buffer.
623 Buffer-local in Ebrowse member buffers.")
624
625
626 (defvar ebrowse--source-regexp-flag nil
627 "Non-nil means display member regexps in a member buffer.
628 Buffer-local in Ebrowse member buffers.")
629
630
631 (defvar ebrowse--displayed-class nil
632 "Class displayed in a member buffer, a `ebrowse-ts' structure.
633 Buffer-local in Ebrowse member buffers.")
634
635
636 (defvar ebrowse--accessor nil
637 "Member list displayed in a member buffer.
638 This is a symbol whose function definition is an accessor for the
639 member list in `ebrowse-cs' structures.
640 Buffer-local in Ebrowse member buffers.")
641
642
643 (defvar ebrowse--member-list nil
644 "The list of `ebrowse-ms' structures displayed in a member buffer.
645 Buffer-local in Ebrowse member buffers.")
646
647
648 (defvar ebrowse--decl-column nil
649 "Column in which declarations are displayed in member buffers.
650 Buffer-local in Ebrowse member buffers.")
651
652
653 (defvar ebrowse--frame-configuration nil
654 "Frame configuration saved when viewing a class/member in another frame.
655 Buffer-local in Ebrowse buffers.")
656
657
658 (defvar ebrowse--view-exit-action nil
659 "Action to perform after viewing a class/member.
660 Either `kill-buffer' or nil.
661 Buffer-local in Ebrowse buffers.")
662
663
664 (defvar ebrowse--tree nil
665 "Class tree.
666 Buffer-local in Ebrowse buffers.")
667
668
669 ;;; Temporaries used to communicate with `ebrowse-find-pattern'.
670
671 (defvar ebrowse-temp-position-to-view nil)
672 (defvar ebrowse-temp-info-to-view nil)
673
674
675 (defvar ebrowse-tree-mode-map ()
676 "The keymap used in tree mode buffers.")
677
678
679 (defvar ebrowse--member-mode-strings nil
680 "Strings displayed in the mode line of member buffers.")
681
682
683 (defvar ebrowse-member-mode-map ()
684 "The keymap used in the member buffers.")
685
686
687 ;;; Define mode line titles for each member list.
688
689 (put 'ebrowse-ts-member-variables 'ebrowse-title "Member Variables")
690 (put 'ebrowse-ts-member-functions 'ebrowse-title "Member Functions")
691 (put 'ebrowse-ts-static-variables 'ebrowse-title "Static Variables")
692 (put 'ebrowse-ts-static-functions 'ebrowse-title "Static Functions")
693 (put 'ebrowse-ts-friends 'ebrowse-title "Friends")
694 (put 'ebrowse-ts-types 'ebrowse-title "Types")
695
696 (put 'ebrowse-ts-member-variables 'ebrowse-global-title "Global Variables")
697 (put 'ebrowse-ts-member-functions 'ebrowse-global-title "Global Functions")
698 (put 'ebrowse-ts-static-variables 'ebrowse-global-title "Static Variables")
699 (put 'ebrowse-ts-static-functions 'ebrowse-global-title "Static Functions")
700 (put 'ebrowse-ts-friends 'ebrowse-global-title "Defines")
701 (put 'ebrowse-ts-types 'ebrowse-global-title "Types")
702
703
704 \f
705 ;;; Operations on `ebrowse-ts' structures
706
707 (defun ebrowse-files-table (&optional marked-only)
708 "Return an obarray containing all files mentioned in the current tree.
709 The tree is expected in the buffer-local variable `ebrowse--tree-obarray'.
710 MARKED-ONLY non-nil means include marked classes only."
711 (let ((files (make-hash-table :test 'equal))
712 (i -1))
713 (ebrowse-for-all-trees (tree ebrowse--tree-obarray)
714 (when (or (not marked-only) (ebrowse-ts-mark tree))
715 (let ((class (ebrowse-ts-class tree)))
716 (when (zerop (% (incf i) 20))
717 (ebrowse-show-progress "Preparing file list" (zerop i)))
718 ;; Add files mentioned in class description
719 (let ((source-file (ebrowse-cs-source-file class))
720 (file (ebrowse-cs-file class)))
721 (when source-file
722 (puthash source-file source-file files))
723 (when file
724 (puthash file file files))
725 ;; For all member lists in this class
726 (loop for accessor in ebrowse-member-list-accessors do
727 (loop for m in (funcall accessor tree)
728 for file = (ebrowse-ms-file m)
729 for def-file = (ebrowse-ms-definition-file m) do
730 (when file
731 (puthash file file files))
732 (when def-file
733 (puthash def-file def-file files))))))))
734 files))
735
736
737 (defun ebrowse-files-list (&optional marked-only)
738 "Return a list containing all files mentioned in a tree.
739 MARKED-ONLY non-nil means include marked classes only."
740 (let (list)
741 (maphash #'(lambda (file dummy) (setq list (cons file list)))
742 (ebrowse-files-table marked-only))
743 list))
744
745
746 (defun* ebrowse-marked-classes-p ()
747 "Value is non-nil if any class in the current class tree is marked."
748 (ebrowse-for-all-trees (tree ebrowse--tree-obarray)
749 (when (ebrowse-ts-mark tree)
750 (return-from ebrowse-marked-classes-p tree))))
751
752
753 (defsubst ebrowse-globals-tree-p (tree)
754 "Return t if TREE is the one for global entities."
755 (string= (ebrowse-bs-name (ebrowse-ts-class tree))
756 ebrowse-globals-name))
757
758
759 (defsubst ebrowse-qualified-class-name (class)
760 "Return the name of CLASS with scope prepended, if any."
761 (if (ebrowse-cs-scope class)
762 (concat (ebrowse-cs-scope class) "::" (ebrowse-cs-name class))
763 (ebrowse-cs-name class)))
764
765
766 (defun ebrowse-tree-obarray-as-alist (&optional qualified-names-p)
767 "Return an alist describing all classes in a tree.
768 Each elements in the list has the form (CLASS-NAME . TREE).
769 CLASS-NAME is the name of the class. TREE is the
770 class tree whose root is QUALIFIED-CLASS-NAME.
771 QUALIFIED-NAMES-P non-nil means return qualified names as CLASS-NAME.
772 The class tree is found in the buffer-local variable `ebrowse--tree-obarray'."
773 (let (alist)
774 (if qualified-names-p
775 (ebrowse-for-all-trees (tree ebrowse--tree-obarray)
776 (setq alist
777 (acons (ebrowse-qualified-class-name (ebrowse-ts-class tree))
778 tree alist)))
779 (ebrowse-for-all-trees (tree ebrowse--tree-obarray)
780 (setq alist
781 (acons (ebrowse-cs-name (ebrowse-ts-class tree))
782 tree alist))))
783 alist))
784
785
786 (defun ebrowse-sort-tree-list (list)
787 "Sort a LIST of `ebrowse-ts' structures by qualified class names."
788 (sort list
789 #'(lambda (a b)
790 (string< (ebrowse-qualified-class-name (ebrowse-ts-class a))
791 (ebrowse-qualified-class-name (ebrowse-ts-class b))))))
792
793
794 (defun ebrowse-class-in-tree (class tree)
795 "Search for a class with name CLASS in TREE.
796 If CLASS is found, return the tail of TREE starting at CLASS. This function
797 is used during the load phase where classes appended to a file replace older
798 class information."
799 (let ((tclass (ebrowse-ts-class class))
800 found)
801 (while (and tree (not found))
802 (let ((root-ptr tree))
803 (when (string= (ebrowse-qualified-class-name (ebrowse-ts-class (car root-ptr)))
804 (ebrowse-qualified-class-name tclass))
805 (setq found root-ptr))
806 (setq tree (cdr tree))))
807 found))
808
809
810 (defun ebrowse-base-classes (tree)
811 "Return list of base-classes of TREE by searching subclass lists.
812 This function must be used instead of the struct slot
813 `base-classes' to access the base-class list directly because it
814 computes this information lazily."
815 (or (ebrowse-ts-base-classes tree)
816 (setf (ebrowse-ts-base-classes tree)
817 (loop with to-search = (list tree)
818 with result = nil
819 as search = (pop to-search)
820 while search finally return result
821 do (ebrowse-for-all-trees (ti ebrowse--tree-obarray)
822 (when (memq search (ebrowse-ts-subclasses ti))
823 (unless (memq ti result)
824 (setq result (nconc result (list ti))))
825 (push ti to-search)))))))
826
827
828 (defun ebrowse-direct-base-classes (tree)
829 "Return the list of direct super classes of TREE."
830 (let (result)
831 (dolist (s (ebrowse-base-classes tree))
832 (when (memq tree (ebrowse-ts-subclasses s))
833 (setq result (cons s result))))
834 result))
835
836
837 \f
838 ;;; Operations on MEMBER structures/lists
839
840 (defun ebrowse-name/accessor-alist (tree accessor)
841 "Return an alist containing all members of TREE in group ACCESSOR.
842 ACCESSOR is the accessor function for the member list.
843 Elements of the result have the form (NAME . ACCESSOR), where NAME
844 is the member name."
845 (loop for member in (funcall accessor tree)
846 collect (cons (ebrowse-ms-name member) accessor)))
847
848
849 (defun ebrowse-name/accessor-alist-for-visible-members ()
850 "Return an alist describing all members visible in the current buffer.
851 Each element of the list has the form (MEMBER-NAME . ACCESSOR),
852 where MEMBER-NAME is the member's name, and ACCESSOR is the struct
853 accessor with which the member's list can be accessed in an `ebrowse-ts'
854 structure. The list includes inherited members if these are visible."
855 (let* ((list (ebrowse-name/accessor-alist ebrowse--displayed-class
856 ebrowse--accessor)))
857 (if ebrowse--show-inherited-flag
858 (nconc list
859 (loop for tree in (ebrowse-base-classes
860 ebrowse--displayed-class)
861 nconc (ebrowse-name/accessor-alist
862 tree ebrowse--accessor)))
863 list)))
864
865
866 (defun ebrowse-name/accessor-alist-for-class-members ()
867 "Like `ebrowse-name/accessor-alist-for-visible-members'.
868 This function includes members of base classes if base class members
869 are visible in the buffer."
870 (let (list)
871 (dolist (func ebrowse-member-list-accessors list)
872 (setq list (nconc list (ebrowse-name/accessor-alist
873 ebrowse--displayed-class func)))
874 (when ebrowse--show-inherited-flag
875 (dolist (class (ebrowse-base-classes ebrowse--displayed-class))
876 (setq list
877 (nconc list (ebrowse-name/accessor-alist class func))))))))
878
879 \f
880 ;;; Progress indication
881
882 (defvar ebrowse-n-boxes 0)
883 (defconst ebrowse-max-boxes 60)
884
885 (defun ebrowse-show-progress (title &optional start)
886 "Display a progress indicator.
887 TITLE is the title of the progress message. START non-nil means
888 this is the first progress message displayed."
889 (let (message-log-max)
890 (when start (setq ebrowse-n-boxes 0))
891 (setq ebrowse-n-boxes (mod (1+ ebrowse-n-boxes) ebrowse-max-boxes))
892 (message "%s: %s" title
893 (propertize (make-string ebrowse-n-boxes
894 (if (display-color-p) ?\ ?+))
895 'face 'ebrowse-progress))))
896
897 \f
898 ;;; Reading a tree from disk
899
900 (defun ebrowse-read ()
901 "Read `ebrowse-hs' and `ebrowse-ts' structures in the current buffer.
902 Return a list (HEADER TREE) where HEADER is the file header read
903 and TREE is a list of `ebrowse-ts' structures forming the class tree."
904 (let ((header (condition-case nil
905 (read (current-buffer))
906 (error (error "No Ebrowse file header found"))))
907 tree)
908 ;; Check file format.
909 (unless (ebrowse-hs-p header)
910 (error "No Ebrowse file header found"))
911 (unless (string= (ebrowse-hs-version header) ebrowse-version-string)
912 (error "File has wrong version `%s' (`%s' expected)"
913 (ebrowse-hs-version header) ebrowse-version-string))
914 ;; Read Lisp objects. Temporarily increase `gc-cons-threshold' to
915 ;; prevent a GC that would not free any memory.
916 (let ((gc-cons-threshold 2000000))
917 (while (not (progn (skip-chars-forward " \t\n\r") (eobp)))
918 (let* ((root (read (current-buffer)))
919 (old-root-ptr (ebrowse-class-in-tree root tree)))
920 (ebrowse-show-progress "Reading data" (null tree))
921 (if old-root-ptr
922 (setcar old-root-ptr root)
923 (push root tree)))))
924 (garbage-collect)
925 (list header tree)))
926
927
928 (defun ebrowse-revert-tree-buffer-from-file (ignore-auto-save noconfirm)
929 "Function installed as `revert-buffer-function' in tree buffers.
930 See that variable's documentation for the meaning of IGNORE-AUTO-SAVE and
931 NOCONFIRM."
932 (when (or noconfirm (yes-or-no-p "Revert tree from disk? "))
933 (loop for member-buffer in (ebrowse-same-tree-member-buffer-list)
934 do (kill-buffer member-buffer))
935 (erase-buffer)
936 (with-no-warnings
937 (insert-file (or buffer-file-name ebrowse--tags-file-name)))
938 (ebrowse-tree-mode)
939 (current-buffer)))
940
941
942 (defun ebrowse-create-tree-buffer (tree tags-file header obarray pop)
943 "Create a new tree buffer for tree TREE.
944 The tree was loaded from file TAGS-FILE.
945 HEADER is the header structure of the file.
946 OBARRAY is an obarray with a symbol for each class in the tree.
947 POP non-nil means popup the buffer up at the end.
948 Return the buffer created."
949 (let ((name ebrowse-tree-buffer-name))
950 (set-buffer (get-buffer-create name))
951 (ebrowse-tree-mode)
952 (setq ebrowse--tree tree
953 ebrowse--tags-file-name tags-file
954 ebrowse--tree-obarray obarray
955 ebrowse--header header
956 ebrowse--frozen-flag nil)
957 (ebrowse-redraw-tree)
958 (set-buffer-modified-p nil)
959 (case pop
960 (switch (switch-to-buffer name))
961 (pop (pop-to-buffer name)))
962 (current-buffer)))
963
964
965 \f
966 ;;; Operations for member obarrays
967
968 (defun ebrowse-fill-member-table ()
969 "Return an obarray holding all members of all classes in the current tree.
970
971 For each member, a symbol is added to the obarray. Members are
972 extracted from the buffer-local tree `ebrowse--tree-obarray'.
973
974 Each symbol has its property `ebrowse-info' set to a list (TREE MEMBER-LIST
975 MEMBER) where TREE is the tree in which the member is defined,
976 MEMBER-LIST is a symbol describing the member list in which the member
977 is found, and MEMBER is a MEMBER structure describing the member.
978
979 The slot `member-table' of the buffer-local header structure of
980 type `ebrowse-hs' is set to the resulting obarray."
981 (let ((members (make-hash-table :test 'equal))
982 (i -1))
983 (setf (ebrowse-hs-member-table ebrowse--header) nil)
984 (garbage-collect)
985 ;; For all classes...
986 (ebrowse-for-all-trees (c ebrowse--tree-obarray)
987 (when (zerop (% (incf i) 10))
988 (ebrowse-show-progress "Preparing member lookup" (zerop i)))
989 (loop for f in ebrowse-member-list-accessors do
990 (loop for m in (funcall f c) do
991 (let* ((member-name (ebrowse-ms-name m))
992 (value (gethash member-name members)))
993 (push (list c f m) value)
994 (puthash member-name value members)))))
995 (setf (ebrowse-hs-member-table ebrowse--header) members)))
996
997
998 (defun ebrowse-member-table (header)
999 "Return the member obarray. Build it if it hasn't been set up yet.
1000 HEADER is the tree header structure of the class tree."
1001 (when (null (ebrowse-hs-member-table header))
1002 (loop for buffer in (ebrowse-browser-buffer-list)
1003 until (eq header (ebrowse-value-in-buffer 'ebrowse--header buffer))
1004 finally do
1005 (save-excursion
1006 (set-buffer buffer)
1007 (ebrowse-fill-member-table))))
1008 (ebrowse-hs-member-table header))
1009
1010
1011 \f
1012 ;;; Operations on TREE obarrays
1013
1014 (defun ebrowse-build-tree-obarray (tree)
1015 "Make sure every class in TREE is represented by a unique object.
1016 Build obarray of all classes in TREE."
1017 (let ((classes (make-vector 127 0)))
1018 ;; Add root classes...
1019 (loop for root in tree
1020 as sym =
1021 (intern (ebrowse-qualified-class-name (ebrowse-ts-class root)) classes)
1022 do (unless (get sym 'ebrowse-root)
1023 (setf (get sym 'ebrowse-root) root)))
1024 ;; Process subclasses
1025 (ebrowse-insert-supers tree classes)
1026 classes))
1027
1028
1029 (defun ebrowse-insert-supers (tree classes)
1030 "Build base class lists in class tree TREE.
1031 CLASSES is an obarray used to collect classes.
1032
1033 Helper function for `ebrowse-build-tree-obarray'. Base classes should
1034 be ordered so that immediate base classes come first, then the base
1035 class of the immediate base class and so on. This means that we must
1036 construct the base-class list top down with adding each level at the
1037 beginning of the base-class list.
1038
1039 We have to be cautious here not to end up in an infinite recursion
1040 if for some reason a circle is in the inheritance graph."
1041 (loop for class in tree
1042 as subclasses = (ebrowse-ts-subclasses class) do
1043 ;; Make sure every class is represented by a unique object
1044 (loop for subclass on subclasses
1045 as sym = (intern
1046 (ebrowse-qualified-class-name (ebrowse-ts-class (car subclass)))
1047 classes)
1048 as next = nil
1049 do
1050 ;; Replace the subclass tree with the one found in
1051 ;; CLASSES if there is already an entry for that class
1052 ;; in it. Otherwise make a new entry.
1053 ;;
1054 ;; CAVEAT: If by some means (e.g., use of the
1055 ;; preprocessor in class declarations, a name is marked
1056 ;; as a subclass of itself on some path, we would end up
1057 ;; in an endless loop. We have to omit subclasses from
1058 ;; the recursion that already have been processed.
1059 (if (get sym 'ebrowse-root)
1060 (setf (car subclass) (get sym 'ebrowse-root))
1061 (setf (get sym 'ebrowse-root) (car subclass))))
1062 ;; Process subclasses
1063 (ebrowse-insert-supers subclasses classes)))
1064
1065 \f
1066 ;;; Tree buffers
1067
1068 (unless ebrowse-tree-mode-map
1069 (let ((map (make-keymap)))
1070 (setf ebrowse-tree-mode-map map)
1071 (suppress-keymap map)
1072
1073 (when (display-mouse-p)
1074 (define-key map [down-mouse-3] 'ebrowse-mouse-3-in-tree-buffer)
1075 (define-key map [mouse-2] 'ebrowse-mouse-2-in-tree-buffer)
1076 (define-key map [down-mouse-1] 'ebrowse-mouse-1-in-tree-buffer))
1077
1078 (let ((map1 (make-sparse-keymap)))
1079 (suppress-keymap map1 t)
1080 (define-key map "L" map1)
1081 (define-key map1 "d" 'ebrowse-tree-command:show-friends)
1082 (define-key map1 "f" 'ebrowse-tree-command:show-member-functions)
1083 (define-key map1 "F" 'ebrowse-tree-command:show-static-member-functions)
1084 (define-key map1 "t" 'ebrowse-tree-command:show-types)
1085 (define-key map1 "v" 'ebrowse-tree-command:show-member-variables)
1086 (define-key map1 "V" 'ebrowse-tree-command:show-static-member-variables))
1087
1088 (let ((map1 (make-sparse-keymap)))
1089 (suppress-keymap map1 t)
1090 (define-key map "M" map1)
1091 (define-key map1 "a" 'ebrowse-mark-all-classes)
1092 (define-key map1 "t" 'ebrowse-toggle-mark-at-point))
1093
1094 (let ((map1 (make-sparse-keymap)))
1095 (suppress-keymap map1 t)
1096 (define-key map "T" map1)
1097 (define-key map1 "f" 'ebrowse-toggle-file-name-display)
1098 (define-key map1 "s" 'ebrowse-show-file-name-at-point)
1099 (define-key map1 "w" 'ebrowse-set-tree-indentation)
1100 (define-key map "x" 'ebrowse-statistics))
1101
1102 (define-key map "n" 'ebrowse-repeat-member-search)
1103 (define-key map "q" 'bury-buffer)
1104 (define-key map "*" 'ebrowse-expand-all)
1105 (define-key map "+" 'ebrowse-expand-branch)
1106 (define-key map "-" 'ebrowse-collapse-branch)
1107 (define-key map "/" 'ebrowse-read-class-name-and-go)
1108 (define-key map " " 'ebrowse-view-class-declaration)
1109 (define-key map "?" 'describe-mode)
1110 (define-key map "\C-i" 'ebrowse-pop/switch-to-member-buffer-for-same-tree)
1111 (define-key map "\C-k" 'ebrowse-remove-class-at-point)
1112 (define-key map "\C-l" 'ebrowse-redraw-tree)
1113 (define-key map "\C-m" 'ebrowse-find-class-declaration)))
1114
1115
1116 \f
1117 ;;; Tree-mode - mode for tree buffers
1118
1119 ;;;###autoload
1120 (defun ebrowse-tree-mode ()
1121 "Major mode for Ebrowse class tree buffers.
1122 Each line corresponds to a class in a class tree.
1123 Letters do not insert themselves, they are commands.
1124 File operations in the tree buffer work on class tree data structures.
1125 E.g.\\[save-buffer] writes the tree to the file it was loaded from.
1126
1127 Tree mode key bindings:
1128 \\{ebrowse-tree-mode-map}"
1129 (interactive)
1130 (let* ((ident (propertized-buffer-identification "C++ Tree"))
1131 header tree buffer-read-only)
1132
1133 (kill-all-local-variables)
1134 (use-local-map ebrowse-tree-mode-map)
1135 (buffer-disable-undo)
1136
1137 (unless (zerop (buffer-size))
1138 (goto-char (point-min))
1139 (multiple-value-setq (header tree) (values-list (ebrowse-read)))
1140 (message "Sorting. Please be patient...")
1141 (setq tree (ebrowse-sort-tree-list tree))
1142 (erase-buffer)
1143 (message nil))
1144
1145 (mapc 'make-local-variable
1146 '(ebrowse--tags-file-name
1147 ebrowse--indentation
1148 ebrowse--tree
1149 ebrowse--header
1150 ebrowse--show-file-names-flag
1151 ebrowse--frozen-flag
1152 ebrowse--tree-obarray
1153 revert-buffer-function))
1154
1155 (setf ebrowse--show-file-names-flag nil
1156 ebrowse--tree-obarray (make-vector 127 0)
1157 ebrowse--frozen-flag nil
1158 major-mode 'ebrowse-tree-mode
1159 mode-name "Ebrowse-Tree"
1160 mode-line-buffer-identification ident
1161 buffer-read-only t
1162 selective-display t
1163 selective-display-ellipses t
1164 revert-buffer-function 'ebrowse-revert-tree-buffer-from-file
1165 ebrowse--header header
1166 ebrowse--tree tree
1167 ebrowse--tags-file-name (buffer-file-name)
1168 ebrowse--tree-obarray (and tree (ebrowse-build-tree-obarray tree))
1169 ebrowse--frozen-flag nil)
1170
1171 (add-hook 'local-write-file-hooks 'ebrowse-write-file-hook-fn)
1172 (modify-syntax-entry ?_ (char-to-string (char-syntax ?a)))
1173 (when tree
1174 (ebrowse-redraw-tree)
1175 (set-buffer-modified-p nil))
1176 (run-mode-hooks 'ebrowse-tree-mode-hook)))
1177
1178
1179
1180 (defun ebrowse-update-tree-buffer-mode-line ()
1181 "Update the tree buffer mode line."
1182 (ebrowse-rename-buffer (if ebrowse--frozen-flag
1183 (ebrowse-frozen-tree-buffer-name
1184 ebrowse--tags-file-name)
1185 ebrowse-tree-buffer-name))
1186 (force-mode-line-update))
1187
1188
1189 \f
1190 ;;; Removing classes from trees
1191
1192 (defun ebrowse-remove-class-and-kill-member-buffers (tree class)
1193 "Remove from TREE class CLASS.
1194 Kill all member buffers still containing a reference to the class."
1195 (let ((sym (intern-soft (ebrowse-cs-name (ebrowse-ts-class class))
1196 ebrowse--tree-obarray)))
1197 (setf tree (delq class tree)
1198 (get sym 'ebrowse-root) nil)
1199 (dolist (root tree)
1200 (setf (ebrowse-ts-subclasses root)
1201 (delq class (ebrowse-ts-subclasses root))
1202 (ebrowse-ts-base-classes root) nil)
1203 (ebrowse-remove-class-and-kill-member-buffers
1204 (ebrowse-ts-subclasses root) class))
1205 (ebrowse-kill-member-buffers-displaying class)
1206 tree))
1207
1208
1209 (defun ebrowse-remove-class-at-point (forced)
1210 "Remove the class point is on from the class tree.
1211 Do not ask for confirmation if FORCED is non-nil."
1212 (interactive "P")
1213 (let* ((class (ebrowse-tree-at-point))
1214 (class-name (ebrowse-cs-name (ebrowse-ts-class class)))
1215 (subclasses (ebrowse-ts-subclasses class)))
1216 (cond ((or forced
1217 (y-or-n-p (concat "Delete class " class-name "? ")))
1218 (setf ebrowse--tree (ebrowse-remove-class-and-kill-member-buffers
1219 ebrowse--tree class))
1220 (set-buffer-modified-p t)
1221 (message "%s %sdeleted." class-name
1222 (if subclasses "and derived classes " ""))
1223 (ebrowse-redraw-tree))
1224 (t (message "Aborted")))))
1225
1226
1227 \f
1228 ;;; Marking classes in the tree buffer
1229
1230 (defun ebrowse-toggle-mark-at-point (&optional n-times)
1231 "Toggle mark for class cursor is on.
1232 If given a numeric N-TIMES argument, mark that many classes."
1233 (interactive "p")
1234 (let (to-change pnt)
1235 ;; Get the classes whose mark must be toggled. Note that
1236 ;; ebrowse-tree-at-point might issue an error.
1237 (condition-case error
1238 (loop repeat (or n-times 1)
1239 as tree = (ebrowse-tree-at-point)
1240 do (progn
1241 (setf (ebrowse-ts-mark tree) (not (ebrowse-ts-mark tree)))
1242 (forward-line 1)
1243 (push tree to-change)))
1244 (error nil))
1245 (save-excursion
1246 ;; For all these classes, reverse the mark char in the display
1247 ;; by a regexp replace over the whole buffer. The reason for this
1248 ;; is that classes might have multiple base classes. If this is
1249 ;; the case, they are displayed more than once in the tree.
1250 (ebrowse-output
1251 (loop for tree in to-change
1252 as regexp = (concat "^.*\\b"
1253 (regexp-quote
1254 (ebrowse-cs-name (ebrowse-ts-class tree)))
1255 "\\b")
1256 do
1257 (goto-char (point-min))
1258 (loop while (re-search-forward regexp nil t)
1259 do (progn
1260 (goto-char (match-beginning 0))
1261 (delete-char 1)
1262 (insert-char (if (ebrowse-ts-mark tree) ?> ? ) 1)
1263 (ebrowse-set-mark-props (1- (point)) (point) tree)
1264 (goto-char (match-end 0)))))))))
1265
1266
1267 (defun ebrowse-mark-all-classes (prefix)
1268 "Unmark, with PREFIX mark, all classes in the tree."
1269 (interactive "P")
1270 (ebrowse-for-all-trees (tree ebrowse--tree-obarray)
1271 (setf (ebrowse-ts-mark tree) prefix))
1272 (ebrowse-redraw-marks (point-min) (point-max)))
1273
1274
1275 (defun ebrowse-redraw-marks (start end)
1276 "Display class marker signs in the tree between START and END."
1277 (interactive)
1278 (save-excursion
1279 (ebrowse-output
1280 (catch 'end
1281 (goto-char (point-min))
1282 (dolist (root ebrowse--tree)
1283 (ebrowse-draw-marks-fn root start end))))
1284 (ebrowse-update-tree-buffer-mode-line)))
1285
1286
1287 (defun ebrowse-draw-marks-fn (tree start end)
1288 "Display class marker signs in TREE between START and END."
1289 (when (>= (point) start)
1290 (delete-char 1)
1291 (insert (if (ebrowse-ts-mark tree) ?> ? ))
1292 (ebrowse-set-mark-props (1- (point)) (point) tree))
1293 (forward-line 1)
1294 (when (> (point) end)
1295 (throw 'end nil))
1296 (dolist (sub (ebrowse-ts-subclasses tree))
1297 (ebrowse-draw-marks-fn sub start end)))
1298
1299
1300 \f
1301 ;;; File name display in tree buffers
1302
1303 (defun ebrowse-show-file-name-at-point (prefix)
1304 "Show filename in the line point is in.
1305 With PREFIX, insert that many filenames."
1306 (interactive "p")
1307 (unless ebrowse--show-file-names-flag
1308 (ebrowse-output
1309 (dotimes (i prefix)
1310 (let ((tree (ebrowse-tree-at-point))
1311 start
1312 file-name-existing)
1313 (beginning-of-line)
1314 (skip-chars-forward " \t*a-zA-Z0-9_")
1315 (setq start (point)
1316 file-name-existing (looking-at "("))
1317 (delete-region start (save-excursion (end-of-line) (point)))
1318 (unless file-name-existing
1319 (indent-to ebrowse-source-file-column)
1320 (insert "(" (or (ebrowse-cs-file
1321 (ebrowse-ts-class tree))
1322 "unknown")
1323 ")"))
1324 (ebrowse-set-face start (point) 'ebrowse-file-name)
1325 (beginning-of-line)
1326 (forward-line 1))))))
1327
1328
1329 (defun ebrowse-toggle-file-name-display ()
1330 "Toggle display of filenames in tree buffer."
1331 (interactive)
1332 (setf ebrowse--show-file-names-flag (not ebrowse--show-file-names-flag))
1333 (let ((old-line (count-lines (point-min) (point))))
1334 (ebrowse-redraw-tree)
1335 (goto-char (point-min))
1336 (forward-line (1- old-line))))
1337
1338
1339 \f
1340 ;;; General member and tree buffer functions
1341
1342 (defun ebrowse-member-buffer-p (buffer)
1343 "Value is non-nil if BUFFER is a member buffer."
1344 (eq (cdr (assoc 'major-mode (buffer-local-variables buffer)))
1345 'ebrowse-member-mode))
1346
1347
1348 (defun ebrowse-tree-buffer-p (buffer)
1349 "Value is non-nil if BUFFER is a class tree buffer."
1350 (eq (cdr (assoc 'major-mode (buffer-local-variables buffer)))
1351 'ebrowse-tree-mode))
1352
1353
1354 (defun ebrowse-buffer-p (buffer)
1355 "Value is non-nil if BUFFER is a tree or member buffer."
1356 (memq (cdr (assoc 'major-mode (buffer-local-variables buffer)))
1357 '(ebrowse-tree-mode ebrowse-member-mode)))
1358
1359
1360 (defun ebrowse-browser-buffer-list ()
1361 "Return a list of all tree or member buffers."
1362 (ebrowse-delete-if-not 'ebrowse-buffer-p (buffer-list)))
1363
1364
1365 (defun ebrowse-member-buffer-list ()
1366 "Return a list of all member buffers."
1367 (ebrowse-delete-if-not 'ebrowse-member-buffer-p (buffer-list)))
1368
1369
1370 (defun ebrowse-tree-buffer-list ()
1371 "Return a list of all tree buffers."
1372 (ebrowse-delete-if-not 'ebrowse-tree-buffer-p (buffer-list)))
1373
1374
1375 (defun ebrowse-known-class-trees-buffer-list ()
1376 "Return a list of buffers containing class trees.
1377 The list will contain, for each class tree loaded,
1378 one buffer. Prefer tree buffers over member buffers."
1379 (let ((buffers (nconc (ebrowse-tree-buffer-list)
1380 (ebrowse-member-buffer-list)))
1381 (set (make-hash-table))
1382 result)
1383 (dolist (buffer buffers)
1384 (let ((tree (ebrowse-value-in-buffer 'ebrowse--tree buffer)))
1385 (unless (gethash tree set)
1386 (push buffer result))
1387 (puthash tree t set)))
1388 result))
1389
1390
1391 (defun ebrowse-same-tree-member-buffer-list ()
1392 "Return a list of members buffers with same tree as current buffer."
1393 (ebrowse-delete-if-not
1394 #'(lambda (buffer)
1395 (eq (ebrowse-value-in-buffer 'ebrowse--tree buffer)
1396 ebrowse--tree))
1397 (ebrowse-member-buffer-list)))
1398
1399
1400 \f
1401 (defun ebrowse-pop/switch-to-member-buffer-for-same-tree (arg)
1402 "Pop to the buffer displaying members.
1403 Switch to buffer if prefix ARG.
1404 If no member buffer exists, make one."
1405 (interactive "P")
1406 (let ((buf (or (first (ebrowse-same-tree-member-buffer-list))
1407 (get-buffer ebrowse-member-buffer-name)
1408 (ebrowse-tree-command:show-member-functions))))
1409 (when buf
1410 (if arg
1411 (switch-to-buffer buf)
1412 (pop-to-buffer buf)))
1413 buf))
1414
1415
1416 (defun ebrowse-switch-to-next-member-buffer ()
1417 "Switch to next member buffer."
1418 (interactive)
1419 (let* ((list (ebrowse-member-buffer-list))
1420 (next-list (cdr (memq (current-buffer) list)))
1421 (next-buffer (if next-list (car next-list) (car list))))
1422 (if (eq next-buffer (current-buffer))
1423 (error "No next buffer")
1424 (bury-buffer)
1425 (switch-to-buffer next-buffer))))
1426
1427
1428 (defun ebrowse-kill-member-buffers-displaying (tree)
1429 "Kill all member buffers displaying TREE."
1430 (loop for buffer in (ebrowse-member-buffer-list)
1431 as class = (ebrowse-value-in-buffer 'ebrowse--displayed-class buffer)
1432 when (eq class tree) do (kill-buffer buffer)))
1433
1434
1435 (defun ebrowse-frozen-tree-buffer-name (tags-file-name)
1436 "Return the buffer name of a tree which is associated TAGS-FILE-NAME."
1437 (concat ebrowse-tree-buffer-name " (" tags-file-name ")"))
1438
1439
1440 (defun ebrowse-pop-to-browser-buffer (arg)
1441 "Pop to a browser buffer from any other buffer.
1442 Pop to member buffer if no prefix ARG, to tree buffer otherwise."
1443 (interactive "P")
1444 (let ((buffer (get-buffer (if arg
1445 ebrowse-tree-buffer-name
1446 ebrowse-member-buffer-name))))
1447 (unless buffer
1448 (setq buffer
1449 (get-buffer (if arg
1450 ebrowse-member-buffer-name
1451 ebrowse-tree-buffer-name))))
1452 (unless buffer
1453 (error "No browser buffer found"))
1454 (pop-to-buffer buffer)))
1455
1456
1457 \f
1458 ;;; Misc tree buffer commands
1459
1460 (defun ebrowse-set-tree-indentation ()
1461 "Set the indentation width of the tree display."
1462 (interactive)
1463 (let ((width (string-to-number (read-from-minibuffer
1464 (concat "Indentation ("
1465 (int-to-string ebrowse--indentation)
1466 "): ")))))
1467 (when (plusp width)
1468 (setf ebrowse--indentation width)
1469 (ebrowse-redraw-tree))))
1470
1471
1472 (defun ebrowse-read-class-name-and-go (&optional class)
1473 "Position cursor on CLASS.
1474 Read a class name from the minibuffer if CLASS is nil."
1475 (interactive)
1476 (ebrowse-ignoring-completion-case
1477 ;; If no class specified, read the class name from mini-buffer
1478 (unless class
1479 (setf class
1480 (completing-read "Goto class: "
1481 (ebrowse-tree-obarray-as-alist) nil t)))
1482 (ebrowse-save-selective
1483 (goto-char (point-min))
1484 (widen)
1485 (setf selective-display nil)
1486 (setq ebrowse--last-regexp (concat "\\b" class "\\b"))
1487 (if (re-search-forward ebrowse--last-regexp nil t)
1488 (progn
1489 (goto-char (match-beginning 0))
1490 (ebrowse-unhide-base-classes))
1491 (error "Not found")))))
1492
1493
1494 \f
1495 ;;; Showing various kinds of member buffers
1496
1497 (defun ebrowse-tree-command:show-member-variables (arg)
1498 "Display member variables; with prefix ARG in frozen member buffer."
1499 (interactive "P")
1500 (ebrowse-display-member-buffer 'ebrowse-ts-member-variables arg))
1501
1502
1503 (defun ebrowse-tree-command:show-member-functions (&optional arg)
1504 "Display member functions; with prefix ARG in frozen member buffer."
1505 (interactive "P")
1506 (ebrowse-display-member-buffer 'ebrowse-ts-member-functions arg))
1507
1508
1509 (defun ebrowse-tree-command:show-static-member-variables (arg)
1510 "Display static member variables; with prefix ARG in frozen member buffer."
1511 (interactive "P")
1512 (ebrowse-display-member-buffer 'ebrowse-ts-static-variables arg))
1513
1514
1515 (defun ebrowse-tree-command:show-static-member-functions (arg)
1516 "Display static member functions; with prefix ARG in frozen member buffer."
1517 (interactive "P")
1518 (ebrowse-display-member-buffer 'ebrowse-ts-static-functions arg))
1519
1520
1521 (defun ebrowse-tree-command:show-friends (arg)
1522 "Display friend functions; with prefix ARG in frozen member buffer."
1523 (interactive "P")
1524 (ebrowse-display-member-buffer 'ebrowse-ts-friends arg))
1525
1526
1527 (defun ebrowse-tree-command:show-types (arg)
1528 "Display types defined in a class; with prefix ARG in frozen member buffer."
1529 (interactive "P")
1530 (ebrowse-display-member-buffer 'ebrowse-ts-types arg))
1531
1532
1533 \f
1534 ;;; Viewing or finding a class declaration
1535
1536 (defun ebrowse-tree-at-point ()
1537 "Return the class structure for the class point is on."
1538 (or (get-text-property (point) 'ebrowse-tree)
1539 (error "Not on a class")))
1540
1541
1542 (defun* ebrowse-view/find-class-declaration (&key view where)
1543 "View or find the declarator of the class point is on.
1544 VIEW non-nil means view it. WHERE is additional position info."
1545 (let* ((class (ebrowse-ts-class (ebrowse-tree-at-point)))
1546 (file (ebrowse-cs-file class))
1547 (browse-struct (make-ebrowse-bs
1548 :name (ebrowse-cs-name class)
1549 :pattern (ebrowse-cs-pattern class)
1550 :flags (ebrowse-cs-flags class)
1551 :file (ebrowse-cs-file class)
1552 :point (ebrowse-cs-point class))))
1553 (ebrowse-view/find-file-and-search-pattern
1554 browse-struct
1555 (list ebrowse--header class nil)
1556 file
1557 ebrowse--tags-file-name
1558 view
1559 where)))
1560
1561
1562 (defun ebrowse-find-class-declaration (prefix-arg)
1563 "Find a class declaration and position cursor on it.
1564 PREFIX-ARG 4 means find it in another window.
1565 PREFIX-ARG 5 means find it in another frame."
1566 (interactive "p")
1567 (ebrowse-view/find-class-declaration
1568 :view nil
1569 :where (cond ((= prefix-arg 4) 'other-window)
1570 ((= prefix-arg 5) 'other-frame)
1571 (t 'this-window))))
1572
1573
1574 (defun ebrowse-view-class-declaration (prefix-arg)
1575 "View class declaration and position cursor on it.
1576 PREFIX-ARG 4 means view it in another window.
1577 PREFIX-ARG 5 means view it in another frame."
1578 (interactive "p")
1579 (ebrowse-view/find-class-declaration
1580 :view 'view
1581 :where (cond ((= prefix-arg 4) 'other-window)
1582 ((= prefix-arg 5) 'other-frame)
1583 (t 'this-window))))
1584
1585
1586 \f
1587 ;;; The FIND engine
1588
1589 (defun ebrowse-find-source-file (file tags-file-name)
1590 "Find source file FILE.
1591 Source files are searched for (a) relative to TAGS-FILE-NAME
1592 which is the path of the BROWSE file from which the class tree was loaded,
1593 and (b) in the directories named in `ebrowse-search-path'."
1594 (let (file-name
1595 (try-file (expand-file-name file
1596 (file-name-directory tags-file-name))))
1597 (if (file-readable-p try-file)
1598 (setq file-name try-file)
1599 (let ((search-in ebrowse-search-path))
1600 (while (and search-in
1601 (null file-name))
1602 (let ((try-file (expand-file-name file (car search-in))))
1603 (if (file-readable-p try-file)
1604 (setq file-name try-file))
1605 (setq search-in (cdr search-in))))))
1606 (unless file-name
1607 (error "File `%s' not found" file))
1608 file-name))
1609
1610
1611 (defun ebrowse-view-exit-fn (buffer)
1612 "Function called when exiting View mode in BUFFER.
1613 Restore frame configuration active before viewing the file,
1614 and possibly kill the viewed buffer."
1615 (let (exit-action original-frame-configuration)
1616 (save-excursion
1617 (set-buffer buffer)
1618 (setq original-frame-configuration ebrowse--frame-configuration
1619 exit-action ebrowse--view-exit-action))
1620 ;; Delete the frame in which we viewed.
1621 (mapc 'delete-frame
1622 (loop for frame in (frame-list)
1623 when (not (assq frame original-frame-configuration))
1624 collect frame))
1625 (when exit-action
1626 (funcall exit-action buffer))))
1627
1628
1629 (defun ebrowse-view-file-other-frame (file)
1630 "View a file FILE in another frame.
1631 The new frame is deleted when you quit viewing the file in that frame."
1632 (interactive)
1633 (let ((old-frame-configuration (current-frame-configuration))
1634 (had-a-buf (get-file-buffer file))
1635 (buf-to-view (find-file-noselect file)))
1636 (switch-to-buffer-other-frame buf-to-view)
1637 (make-local-variable 'ebrowse--frame-configuration)
1638 (setq ebrowse--frame-configuration old-frame-configuration)
1639 (make-local-variable 'ebrowse--view-exit-action)
1640 (setq ebrowse--view-exit-action
1641 (and (not had-a-buf)
1642 (not (buffer-modified-p buf-to-view))
1643 'kill-buffer))
1644 (view-mode-enter (cons (selected-window) (cons (selected-window) t))
1645 'ebrowse-view-exit-fn)))
1646
1647 (defun ebrowse-view/find-file-and-search-pattern
1648 (struc info file tags-file-name &optional view where)
1649 "Find or view a member or class.
1650 STRUC is an `ebrowse-bs' structure (or a structure including that)
1651 describing what to search.
1652 INFO is a list (HEADER MEMBER-OR-CLASS ACCESSOR). HEADER is the
1653 header structure of a class tree. MEMBER-OR-CLASS is either an
1654 `ebrowse-ms' or `ebrowse-cs' structure depending on what is searched.
1655 ACCESSOR is an accessor function for the member list of a member
1656 if MEMBER-OR-CLASS is an `ebrowse-ms'.
1657 FILE is the file to search the member in.
1658 FILE is not taken out of STRUC here because the filename in STRUC
1659 may be nil in which case the filename of the class description is used.
1660 TAGS-FILE-NAME is the name of the BROWSE file from which the
1661 tree was loaded.
1662 If VIEW is non-nil, view file else find the file.
1663 WHERE is either `other-window', `other-frame' or `this-window' and
1664 specifies where to find/view the result."
1665 (unless file
1666 (error "Sorry, no file information available for %s"
1667 (ebrowse-bs-name struc)))
1668 ;; Get the source file to view or find.
1669 (setf file (ebrowse-find-source-file file tags-file-name))
1670 ;; If current window is dedicated, use another frame.
1671 (when (window-dedicated-p (selected-window))
1672 (setf where 'other-window))
1673 (cond (view
1674 (setf ebrowse-temp-position-to-view struc
1675 ebrowse-temp-info-to-view info)
1676 (unless (boundp 'view-mode-hook)
1677 (setq view-mode-hook nil))
1678 (push 'ebrowse-find-pattern view-mode-hook)
1679 (case where
1680 (other-window (view-file-other-window file))
1681 (other-frame (ebrowse-view-file-other-frame file))
1682 (t (view-file file))))
1683 (t
1684 (case where
1685 (other-window (find-file-other-window file))
1686 (other-frame (find-file-other-frame file))
1687 (t (find-file file)))
1688 (ebrowse-find-pattern struc info))))
1689
1690
1691 (defun ebrowse-symbol-regexp (name)
1692 "Generate a suitable regular expression for a member or class NAME.
1693 This is `regexp-quote' for most symbols, except for operator names
1694 which may contain whitespace. For these symbols, replace white
1695 space in the symbol name (generated by BROWSE) with a regular
1696 expression matching any number of whitespace characters."
1697 (loop with regexp = (regexp-quote name)
1698 with start = 0
1699 finally return regexp
1700 while (string-match "[ \t]+" regexp start)
1701 do (setq regexp (concat (substring regexp 0 (match-beginning 0))
1702 "[ \t]*"
1703 (substring regexp (match-end 0)))
1704 start (+ (match-beginning 0) 5))))
1705
1706
1707 (defun ebrowse-class-declaration-regexp (name)
1708 "Construct a regexp for a declaration of class NAME."
1709 (concat "^[ \t]*\\(template[ \t\n]*<.*>\\)?"
1710 "[ \t\n]*\\(class\\|struct\\|union\\).*\\S_"
1711 (ebrowse-symbol-regexp name)
1712 "\\S_"))
1713
1714
1715 (defun ebrowse-variable-declaration-regexp (name)
1716 "Construct a regexp for matching a variable NAME."
1717 (concat "\\S_" (ebrowse-symbol-regexp name) "\\S_"))
1718
1719
1720 (defun ebrowse-function-declaration/definition-regexp (name)
1721 "Construct a regexp for matching a function NAME."
1722 (concat "^[a-zA-Z0-9_:*&<>, \t]*\\S_"
1723 (ebrowse-symbol-regexp name)
1724 "[ \t\n]*("))
1725
1726
1727 (defun ebrowse-pp-define-regexp (name)
1728 "Construct a regexp matching a define of NAME."
1729 (concat "^[ \t]*#[ \t]*define[ \t]+" (regexp-quote name)))
1730
1731
1732 (defun* ebrowse-find-pattern (&optional position info &aux viewing)
1733 "Find a pattern.
1734
1735 This is a kluge: Ebrowse allows you to find or view a file containing
1736 a pattern. To be able to do a search in a viewed buffer,
1737 `view-mode-hook' is temporarily set to this function;
1738 `ebrowse-temp-position-to-view' holds what to search for.
1739
1740 INFO is a list (TREE-HEADER TREE-OR-MEMBER MEMBER-LIST)."
1741 (unless position
1742 (pop view-mode-hook)
1743 (setf viewing t
1744 position ebrowse-temp-position-to-view
1745 info ebrowse-temp-info-to-view))
1746 (widen)
1747 (let* ((pattern (ebrowse-bs-pattern position))
1748 (start (ebrowse-bs-point position))
1749 (offset 100)
1750 found)
1751 (destructuring-bind (header class-or-member member-list) info
1752 ;; If no pattern is specified, construct one from the member name.
1753 (when (stringp pattern)
1754 (setq pattern (concat "^.*" (regexp-quote pattern))))
1755 ;; Construct a regular expression if none given.
1756 (unless pattern
1757 (typecase class-or-member
1758 (ebrowse-ms
1759 (case member-list
1760 ((ebrowse-ts-member-variables
1761 ebrowse-ts-static-variables
1762 ebrowse-ts-types)
1763 (setf pattern (ebrowse-variable-declaration-regexp
1764 (ebrowse-bs-name position))))
1765 (otherwise
1766 (if (ebrowse-define-p class-or-member)
1767 (setf pattern (ebrowse-pp-define-regexp (ebrowse-bs-name position)))
1768 (setf pattern (ebrowse-function-declaration/definition-regexp
1769 (ebrowse-bs-name position)))))))
1770 (ebrowse-cs
1771 (setf pattern (ebrowse-class-declaration-regexp
1772 (ebrowse-bs-name position))))))
1773 ;; Begin searching some OFFSET from the original point where the
1774 ;; regular expression was found by the parse, and step forward.
1775 ;; When there is no regular expression in the database and a
1776 ;; member definition/declaration was not seen by the parser,
1777 ;; START will be 0.
1778 (when (and (boundp 'ebrowse-debug)
1779 (symbol-value 'ebrowse-debug))
1780 (y-or-n-p (format "start = %d? " start))
1781 (y-or-n-p pattern))
1782 (setf found
1783 (loop do (goto-char (max (point-min) (- start offset)))
1784 when (re-search-forward pattern (+ start offset) t) return t
1785 never (bobp)
1786 do (incf offset offset)))
1787 (cond (found
1788 (beginning-of-line)
1789 (run-hooks 'ebrowse-view/find-hook))
1790 ((numberp (ebrowse-bs-pattern position))
1791 (goto-char start)
1792 (if ebrowse-not-found-hook
1793 (run-hooks 'ebrowse-not-found-hook)
1794 (message "Not found")
1795 (sit-for 2)))
1796 (t
1797 (if ebrowse-not-found-hook
1798 (run-hooks 'ebrowse-not-found-hook)
1799 (unless viewing
1800 (error "Not found"))
1801 (message "Not found")
1802 (sit-for 2)))))))
1803
1804 \f
1805 ;;; Drawing the tree
1806
1807 (defun ebrowse-redraw-tree (&optional quietly)
1808 "Redisplay the complete tree.
1809 QUIETLY non-nil means don't display progress messages."
1810 (interactive)
1811 (or quietly (message "Displaying..."))
1812 (save-excursion
1813 (ebrowse-output
1814 (erase-buffer)
1815 (ebrowse-draw-tree-fn)))
1816 (ebrowse-update-tree-buffer-mode-line)
1817 (or quietly (message nil)))
1818
1819
1820 (defun ebrowse-set-mark-props (start end tree)
1821 "Set text properties for class marker signs between START and END.
1822 TREE denotes the class shown."
1823 (add-text-properties
1824 start end
1825 `(mouse-face highlight ebrowse-what mark ebrowse-tree ,tree
1826 help-echo "double-mouse-1: mark/unmark"))
1827 (ebrowse-set-face start end 'ebrowse-tree-mark))
1828
1829
1830 (defun* ebrowse-draw-tree-fn (&aux stack1 stack2 start)
1831 "Display a single class and recursively its subclasses.
1832 This function may look weird, but this is faster than recursion."
1833 (setq stack1 (make-list (length ebrowse--tree) 0)
1834 stack2 (copy-sequence ebrowse--tree))
1835 (loop while stack2
1836 as level = (pop stack1)
1837 as tree = (pop stack2)
1838 as class = (ebrowse-ts-class tree) do
1839 (let ((start-of-line (point))
1840 start-of-class-name end-of-class-name)
1841 ;; Insert mark
1842 (insert (if (ebrowse-ts-mark tree) ">" " "))
1843
1844 ;; Indent and insert class name
1845 (indent-to (+ (* level ebrowse--indentation)
1846 ebrowse-tree-left-margin))
1847 (setq start (point))
1848 (insert (ebrowse-qualified-class-name class))
1849
1850 ;; If template class, add <>
1851 (when (ebrowse-template-p class)
1852 (insert "<>"))
1853 (ebrowse-set-face start (point) (if (zerop level)
1854 'ebrowse-root-class
1855 'ebrowse-default))
1856 (setf start-of-class-name start
1857 end-of-class-name (point))
1858 ;; If filenames are to be displayed...
1859 (when ebrowse--show-file-names-flag
1860 (indent-to ebrowse-source-file-column)
1861 (setq start (point))
1862 (insert "("
1863 (or (ebrowse-cs-file class)
1864 "unknown")
1865 ")")
1866 (ebrowse-set-face start (point) 'ebrowse-file-name))
1867 (ebrowse-set-mark-props start-of-line (1+ start-of-line) tree)
1868 (add-text-properties
1869 start-of-class-name end-of-class-name
1870 `(mouse-face highlight ebrowse-what class-name
1871 ebrowse-tree ,tree
1872 help-echo "double-mouse-1: (un)expand tree; mouse-2: member functions, mouse-3: menu"))
1873 (insert "\n"))
1874 ;; Push subclasses, if any.
1875 (when (ebrowse-ts-subclasses tree)
1876 (setq stack2
1877 (nconc (copy-sequence (ebrowse-ts-subclasses tree)) stack2)
1878 stack1
1879 (nconc (make-list (length (ebrowse-ts-subclasses tree))
1880 (1+ level)) stack1)))))
1881
1882
1883 \f
1884 ;;; Expanding/ collapsing tree branches
1885
1886 (defun ebrowse-expand-branch (arg)
1887 "Expand a sub-tree that has been previously collapsed.
1888 With prefix ARG, expand all sub-trees."
1889 (interactive "P")
1890 (if arg
1891 (ebrowse-expand-all arg)
1892 (ebrowse-collapse-fn nil)))
1893
1894
1895 (defun ebrowse-collapse-branch (arg)
1896 "Fold (do no longer display) the subclasses of the current class.
1897 \(The class cursor is on.) With prefix ARG, fold all trees in the buffer."
1898 (interactive "P")
1899 (if arg
1900 (ebrowse-expand-all (not arg))
1901 (ebrowse-collapse-fn t)))
1902
1903
1904 (defun ebrowse-expand-all (collapse)
1905 "Expand or fold all trees in the buffer.
1906 COLLAPSE non-nil means fold them."
1907 (interactive "P")
1908 (let ((line-end (if collapse "^\n" "^\r"))
1909 (insertion (if collapse "\r" "\n")))
1910 (ebrowse-output
1911 (save-excursion
1912 (goto-char (point-min))
1913 (while (not (progn (skip-chars-forward line-end) (eobp)))
1914 (when (or (not collapse)
1915 (looking-at "\n "))
1916 (delete-char 1)
1917 (insert insertion))
1918 (when collapse
1919 (skip-chars-forward "\n ")))))))
1920
1921
1922 (defun ebrowse-unhide-base-classes ()
1923 "Unhide the line the cursor is on and all base classes."
1924 (ebrowse-output
1925 (save-excursion
1926 (let (indent last-indent)
1927 (skip-chars-backward "^\r\n")
1928 (when (not (looking-at "[\r\n][^ \t]"))
1929 (skip-chars-forward "\r\n \t")
1930 (while (and (or (null last-indent) ;first time
1931 (> indent 1)) ;not root class
1932 (re-search-backward "[\r\n][ \t]*" nil t))
1933 (setf indent (- (match-end 0)
1934 (match-beginning 0)))
1935 (when (or (null last-indent)
1936 (< indent last-indent))
1937 (setf last-indent indent)
1938 (when (looking-at "\r")
1939 (delete-char 1)
1940 (insert 10)))
1941 (backward-char 1)))))))
1942
1943
1944 (defun ebrowse-hide-line (collapse)
1945 "Hide/show a single line in the tree.
1946 COLLAPSE non-nil means hide."
1947 (save-excursion
1948 (ebrowse-output
1949 (skip-chars-forward "^\r\n")
1950 (delete-char 1)
1951 (insert (if collapse 13 10)))))
1952
1953
1954 (defun ebrowse-collapse-fn (collapse)
1955 "Collapse or expand a branch of the tree.
1956 COLLAPSE non-nil means collapse the branch."
1957 (ebrowse-output
1958 (save-excursion
1959 (beginning-of-line)
1960 (skip-chars-forward "> \t")
1961 (let ((indentation (current-column)))
1962 (while (and (not (eobp))
1963 (save-excursion
1964 (skip-chars-forward "^\r\n")
1965 (goto-char (1+ (point)))
1966 (skip-chars-forward "> \t")
1967 (> (current-column) indentation)))
1968 (ebrowse-hide-line collapse)
1969 (skip-chars-forward "^\r\n")
1970 (goto-char (1+ (point))))))))
1971
1972 \f
1973 ;;; Electric tree selection
1974
1975 (defvar ebrowse-electric-list-mode-map ()
1976 "Keymap used in electric Ebrowse buffer list window.")
1977
1978
1979 (unless ebrowse-electric-list-mode-map
1980 (let ((map (make-keymap))
1981 (submap (make-keymap)))
1982 (setq ebrowse-electric-list-mode-map map)
1983 (fillarray (car (cdr map)) 'ebrowse-electric-list-undefined)
1984 (fillarray (car (cdr submap)) 'ebrowse-electric-list-undefined)
1985 (define-key map "\e" submap)
1986 (define-key map "\C-z" 'suspend-frame)
1987 (define-key map "\C-h" 'Helper-help)
1988 (define-key map "?" 'Helper-describe-bindings)
1989 (define-key map "\C-c" nil)
1990 (define-key map "\C-c\C-c" 'ebrowse-electric-list-quit)
1991 (define-key map "q" 'ebrowse-electric-list-quit)
1992 (define-key map " " 'ebrowse-electric-list-select)
1993 (define-key map "\C-l" 'recenter)
1994 (define-key map "\C-u" 'universal-argument)
1995 (define-key map "\C-p" 'previous-line)
1996 (define-key map "\C-n" 'next-line)
1997 (define-key map "p" 'previous-line)
1998 (define-key map "n" 'next-line)
1999 (define-key map "v" 'ebrowse-electric-view-buffer)
2000 (define-key map "\C-v" 'scroll-up)
2001 (define-key map "\ev" 'scroll-down)
2002 (define-key map "\e\C-v" 'scroll-other-window)
2003 (define-key map "\e>" 'end-of-buffer)
2004 (define-key map "\e<" 'beginning-of-buffer)
2005 (define-key map "\e>" 'end-of-buffer)))
2006
2007 (put 'ebrowse-electric-list-mode 'mode-class 'special)
2008 (put 'ebrowse-electric-list-undefined 'suppress-keymap t)
2009
2010
2011 (defun ebrowse-electric-list-mode ()
2012 "Mode for electric tree list mode."
2013 (kill-all-local-variables)
2014 (use-local-map ebrowse-electric-list-mode-map)
2015 (setq mode-name "Electric Position Menu"
2016 mode-line-buffer-identification "Electric Tree Menu")
2017 (when (memq 'mode-name mode-line-format)
2018 (setq mode-line-format (copy-sequence mode-line-format))
2019 (setcar (memq 'mode-name mode-line-format) "Tree Buffers"))
2020 (make-local-variable 'Helper-return-blurb)
2021 (setq Helper-return-blurb "return to buffer editing"
2022 truncate-lines t
2023 buffer-read-only t
2024 major-mode 'ebrowse-electric-list-mode)
2025 (run-mode-hooks 'ebrowse-electric-list-mode-hook))
2026
2027
2028 (defun ebrowse-list-tree-buffers ()
2029 "Display a list of all tree buffers."
2030 (set-buffer (get-buffer-create "*Tree Buffers*"))
2031 (setq buffer-read-only nil)
2032 (erase-buffer)
2033 (insert "Tree\n" "----\n")
2034 (dolist (buffer (ebrowse-known-class-trees-buffer-list))
2035 (insert (buffer-name buffer) "\n"))
2036 (setq buffer-read-only t))
2037
2038
2039 ;;;###autoload
2040 (defun ebrowse-electric-choose-tree ()
2041 "Return a buffer containing a tree or nil if no tree found or canceled."
2042 (interactive)
2043 (unless (car (ebrowse-known-class-trees-buffer-list))
2044 (error "No tree buffers"))
2045 (let (select buffer window)
2046 (save-window-excursion
2047 (save-window-excursion (ebrowse-list-tree-buffers))
2048 (setq window (Electric-pop-up-window "*Tree Buffers*")
2049 buffer (window-buffer window))
2050 (shrink-window-if-larger-than-buffer window)
2051 (unwind-protect
2052 (progn
2053 (set-buffer buffer)
2054 (ebrowse-electric-list-mode)
2055 (setq select
2056 (catch 'ebrowse-electric-list-select
2057 (message "<<< Press Space to bury the list >>>")
2058 (let ((first (progn (goto-char (point-min))
2059 (forward-line 2)
2060 (point)))
2061 (last (progn (goto-char (point-max))
2062 (forward-line -1)
2063 (point)))
2064 (goal-column 0))
2065 (goto-char first)
2066 (Electric-command-loop 'ebrowse-electric-list-select
2067 nil
2068 t
2069 'ebrowse-electric-list-looper
2070 (cons first last))))))
2071 (set-buffer buffer)
2072 (bury-buffer buffer)
2073 (message nil)))
2074 (when select
2075 (set-buffer buffer)
2076 (setq select (ebrowse-electric-get-buffer select)))
2077 (kill-buffer buffer)
2078 select))
2079
2080
2081 (defun ebrowse-electric-list-looper (state condition)
2082 "Prevent cursor from moving beyond the buffer end.
2083 Don't let it move into the title lines.
2084 See 'Electric-command-loop' for a description of STATE and CONDITION."
2085 (cond ((and condition
2086 (not (memq (car condition)
2087 '(buffer-read-only end-of-buffer
2088 beginning-of-buffer))))
2089 (signal (car condition) (cdr condition)))
2090 ((< (point) (car state))
2091 (goto-char (point-min))
2092 (forward-line 2))
2093 ((> (point) (cdr state))
2094 (goto-char (point-max))
2095 (forward-line -1)
2096 (if (pos-visible-in-window-p (point-max))
2097 (recenter -1)))))
2098
2099
2100 (defun ebrowse-electric-list-undefined ()
2101 "Function called for keys that are undefined."
2102 (interactive)
2103 (message "Type C-h for help, ? for commands, q to quit, Space to select.")
2104 (sit-for 4))
2105
2106
2107 (defun ebrowse-electric-list-quit ()
2108 "Discard the buffer list."
2109 (interactive)
2110 (throw 'ebrowse-electric-list-select nil))
2111
2112
2113 (defun ebrowse-electric-list-select ()
2114 "Select a buffer from the buffer list."
2115 (interactive)
2116 (throw 'ebrowse-electric-list-select (point)))
2117
2118
2119 (defun ebrowse-electric-get-buffer (point)
2120 "Get a buffer corresponding to the line POINT is in."
2121 (let ((index (- (count-lines (point-min) point) 2)))
2122 (nth index (ebrowse-known-class-trees-buffer-list))))
2123
2124
2125 ;;; View a buffer for a tree.
2126
2127 (defun ebrowse-electric-view-buffer ()
2128 "View buffer point is on."
2129 (interactive)
2130 (let ((buffer (ebrowse-electric-get-buffer (point))))
2131 (cond (buffer
2132 (view-buffer buffer))
2133 (t
2134 (error "Buffer no longer exists")))))
2135
2136
2137 (defun ebrowse-choose-from-browser-buffers ()
2138 "Read a browser buffer name from the minibuffer and return that buffer."
2139 (let* ((buffers (ebrowse-known-class-trees-buffer-list)))
2140 (if buffers
2141 (if (not (second buffers))
2142 (first buffers)
2143 (or (ebrowse-electric-choose-tree) (error "No tree buffer")))
2144 (let* ((insert-default-directory t)
2145 (file (read-file-name "Find tree: " nil nil t)))
2146 (save-excursion
2147 (find-file file))
2148 (find-buffer-visiting file)))))
2149
2150 \f
2151 ;;; Member buffers
2152
2153 (unless ebrowse-member-mode-map
2154 (let ((map (make-keymap)))
2155 (setf ebrowse-member-mode-map map)
2156 (suppress-keymap map)
2157
2158 (when (display-mouse-p)
2159 (define-key map [down-mouse-3] 'ebrowse-member-mouse-3)
2160 (define-key map [mouse-2] 'ebrowse-member-mouse-2))
2161
2162 (let ((map1 (make-sparse-keymap)))
2163 (suppress-keymap map1 t)
2164 (define-key map "C" map1)
2165 (define-key map1 "b" 'ebrowse-switch-member-buffer-to-base-class)
2166 (define-key map1 "c" 'ebrowse-switch-member-buffer-to-any-class)
2167 (define-key map1 "d" 'ebrowse-switch-member-buffer-to-derived-class)
2168 (define-key map1 "n" 'ebrowse-switch-member-buffer-to-next-sibling-class)
2169 (define-key map1 "p" 'ebrowse-switch-member-buffer-to-previous-sibling-class))
2170
2171 (let ((map1 (make-sparse-keymap)))
2172 (suppress-keymap map1 t)
2173 (define-key map "D" map1)
2174 (define-key map1 "a" 'ebrowse-toggle-member-attributes-display)
2175 (define-key map1 "b" 'ebrowse-toggle-base-class-display)
2176 (define-key map1 "f" 'ebrowse-freeze-member-buffer)
2177 (define-key map1 "l" 'ebrowse-toggle-long-short-display)
2178 (define-key map1 "r" 'ebrowse-toggle-regexp-display)
2179 (define-key map1 "w" 'ebrowse-set-member-buffer-column-width))
2180
2181 (let ((map1 (make-sparse-keymap)))
2182 (suppress-keymap map1 t)
2183 (define-key map "F" map1)
2184 (let ((map2 (make-sparse-keymap)))
2185 (suppress-keymap map2 t)
2186 (define-key map1 "a" map2)
2187 (define-key map2 "i" 'ebrowse-toggle-private-member-filter)
2188 (define-key map2 "o" 'ebrowse-toggle-protected-member-filter)
2189 (define-key map2 "u" 'ebrowse-toggle-public-member-filter))
2190 (define-key map1 "c" 'ebrowse-toggle-const-member-filter)
2191 (define-key map1 "i" 'ebrowse-toggle-inline-member-filter)
2192 (define-key map1 "p" 'ebrowse-toggle-pure-member-filter)
2193 (define-key map1 "r" 'ebrowse-remove-all-member-filters)
2194 (define-key map1 "v" 'ebrowse-toggle-virtual-member-filter))
2195
2196 (let ((map1 (make-sparse-keymap)))
2197 (suppress-keymap map1 t)
2198 (define-key map "L" map1)
2199 (define-key map1 "d" 'ebrowse-display-friends-member-list)
2200 (define-key map1 "f" 'ebrowse-display-function-member-list)
2201 (define-key map1 "F" 'ebrowse-display-static-functions-member-list)
2202 (define-key map1 "n" 'ebrowse-display-next-member-list)
2203 (define-key map1 "p" 'ebrowse-display-previous-member-list)
2204 (define-key map1 "t" 'ebrowse-display-types-member-list)
2205 (define-key map1 "v" 'ebrowse-display-variables-member-list)
2206 (define-key map1 "V" 'ebrowse-display-static-variables-member-list))
2207
2208 (let ((map1 (make-sparse-keymap)))
2209 (suppress-keymap map1 t)
2210 (define-key map "G" map1)
2211 (define-key map1 "m" 'ebrowse-goto-visible-member/all-member-lists)
2212 (define-key map1 "n" 'ebrowse-repeat-member-search)
2213 (define-key map1 "v" 'ebrowse-goto-visible-member))
2214
2215 (define-key map "f" 'ebrowse-find-member-declaration)
2216 (define-key map "m" 'ebrowse-switch-to-next-member-buffer)
2217 (define-key map "q" 'bury-buffer)
2218 (define-key map "t" 'ebrowse-show-displayed-class-in-tree)
2219 (define-key map "v" 'ebrowse-view-member-declaration)
2220 (define-key map " " 'ebrowse-view-member-definition)
2221 (define-key map "?" 'describe-mode)
2222 (define-key map "\C-i" 'ebrowse-pop-from-member-to-tree-buffer)
2223 (define-key map "\C-l" 'ebrowse-redisplay-member-buffer)
2224 (define-key map "\C-m" 'ebrowse-find-member-definition)))
2225
2226
2227 \f
2228 ;;; Member mode
2229
2230 ;;;###autoload
2231 (defun ebrowse-member-mode ()
2232 "Major mode for Ebrowse member buffers.
2233
2234 \\{ebrowse-member-mode-map}"
2235 (kill-all-local-variables)
2236 (use-local-map ebrowse-member-mode-map)
2237 (setq major-mode 'ebrowse-member-mode)
2238 (mapc 'make-local-variable
2239 '(ebrowse--decl-column ;display column
2240 ebrowse--n-columns ;number of short columns
2241 ebrowse--column-width ;width of columns above
2242 ebrowse--show-inherited-flag ;include inherited members?
2243 ebrowse--filters ;public, protected, private
2244 ebrowse--accessor ;vars, functions, friends
2245 ebrowse--displayed-class ;class displayed
2246 ebrowse--long-display-flag ;display with regexps?
2247 ebrowse--source-regexp-flag ;show source regexp?
2248 ebrowse--attributes-flag ;show `virtual' and `inline'
2249 ebrowse--member-list ;list of members displayed
2250 ebrowse--tree ;the class tree
2251 ebrowse--member-mode-strings ;part of mode line
2252 ebrowse--tags-file-name ;
2253 ebrowse--header
2254 ebrowse--tree-obarray
2255 ebrowse--virtual-display-flag
2256 ebrowse--inline-display-flag
2257 ebrowse--const-display-flag
2258 ebrowse--pure-display-flag
2259 ebrowse--frozen-flag)) ;buffer not automagically reused
2260 (setq mode-name "Ebrowse-Members"
2261 mode-line-buffer-identification
2262 (propertized-buffer-identification "C++ Members")
2263 buffer-read-only t
2264 ebrowse--long-display-flag nil
2265 ebrowse--attributes-flag t
2266 ebrowse--show-inherited-flag t
2267 ebrowse--source-regexp-flag nil
2268 ebrowse--filters [0 1 2]
2269 ebrowse--decl-column ebrowse-default-declaration-column
2270 ebrowse--column-width ebrowse-default-column-width
2271 ebrowse--virtual-display-flag nil
2272 ebrowse--inline-display-flag nil
2273 ebrowse--const-display-flag nil
2274 ebrowse--pure-display-flag nil)
2275 (modify-syntax-entry ?_ (char-to-string (char-syntax ?a)))
2276 (run-mode-hooks 'ebrowse-member-mode-hook))
2277
2278
2279 \f
2280 ;;; Member mode mode line
2281
2282 (defsubst ebrowse-class-name-displayed-in-member-buffer ()
2283 "Return the name of the class displayed in the member buffer."
2284 (ebrowse-cs-name (ebrowse-ts-class ebrowse--displayed-class)))
2285
2286
2287 (defsubst ebrowse-member-list-name ()
2288 "Return a string describing what is displayed in the member buffer."
2289 (get ebrowse--accessor (if (ebrowse-globals-tree-p ebrowse--displayed-class)
2290 'ebrowse-global-title
2291 'ebrowse-title)))
2292
2293
2294 (defun ebrowse-update-member-buffer-mode-line ()
2295 "Update the mode line of member buffers."
2296 (let* ((name (when ebrowse--frozen-flag
2297 (concat (ebrowse-class-name-displayed-in-member-buffer)
2298 " ")))
2299 (ident (concat name (ebrowse-member-list-name))))
2300 (setq mode-line-buffer-identification
2301 (propertized-buffer-identification ident))
2302 (ebrowse-rename-buffer (if name ident ebrowse-member-buffer-name))
2303 (force-mode-line-update)))
2304
2305
2306 ;;; Misc member buffer commands
2307
2308 (defun ebrowse-freeze-member-buffer ()
2309 "Toggle frozen status of current buffer."
2310 (interactive)
2311 (setq ebrowse--frozen-flag (not ebrowse--frozen-flag))
2312 (ebrowse-redisplay-member-buffer))
2313
2314
2315 (defun ebrowse-show-displayed-class-in-tree (arg)
2316 "Show the currently displayed class in the tree window.
2317 With prefix ARG, switch to the tree buffer else pop to it."
2318 (interactive "P")
2319 (let ((class-name (ebrowse-class-name-displayed-in-member-buffer)))
2320 (when (ebrowse-pop-from-member-to-tree-buffer arg)
2321 (ebrowse-read-class-name-and-go class-name))))
2322
2323
2324 (defun ebrowse-set-member-buffer-column-width ()
2325 "Set the column width of the member display.
2326 The new width is read from the minibuffer."
2327 (interactive)
2328 (let ((width (string-to-number
2329 (read-from-minibuffer
2330 (concat "Column width ("
2331 (int-to-string (if ebrowse--long-display-flag
2332 ebrowse--decl-column
2333 ebrowse--column-width))
2334 "): ")))))
2335 (when (plusp width)
2336 (if ebrowse--long-display-flag
2337 (setq ebrowse--decl-column width)
2338 (setq ebrowse--column-width width))
2339 (ebrowse-redisplay-member-buffer))))
2340
2341
2342 (defun ebrowse-pop-from-member-to-tree-buffer (arg)
2343 "Pop from a member buffer to the matching tree buffer.
2344 Switch to the buffer if prefix ARG. If no tree buffer exists,
2345 make one."
2346 (interactive "P")
2347 (let ((buf (or (get-buffer (ebrowse-frozen-tree-buffer-name
2348 ebrowse--tags-file-name))
2349 (get-buffer ebrowse-tree-buffer-name)
2350 (ebrowse-create-tree-buffer ebrowse--tree
2351 ebrowse--tags-file-name
2352 ebrowse--header
2353 ebrowse--tree-obarray
2354 'pop))))
2355 (and buf
2356 (funcall (if arg 'switch-to-buffer 'pop-to-buffer) buf))
2357 buf))
2358
2359
2360 \f
2361 ;;; Switching between member lists
2362
2363 (defun ebrowse-display-member-list-for-accessor (accessor)
2364 "Switch the member buffer to display the member list for ACCESSOR."
2365 (setf ebrowse--accessor accessor
2366 ebrowse--member-list (funcall accessor ebrowse--displayed-class))
2367 (ebrowse-redisplay-member-buffer))
2368
2369
2370 (defun ebrowse-cyclic-display-next/previous-member-list (incr)
2371 "Switch buffer to INCR'th next/previous list of members."
2372 (let ((index (ebrowse-position ebrowse--accessor
2373 ebrowse-member-list-accessors)))
2374 (setf ebrowse--accessor
2375 (cond ((plusp incr)
2376 (or (nth (1+ index)
2377 ebrowse-member-list-accessors)
2378 (first ebrowse-member-list-accessors)))
2379 ((minusp incr)
2380 (or (and (>= (decf index) 0)
2381 (nth index
2382 ebrowse-member-list-accessors))
2383 (first (last ebrowse-member-list-accessors))))))
2384 (ebrowse-display-member-list-for-accessor ebrowse--accessor)))
2385
2386
2387 (defun ebrowse-display-next-member-list ()
2388 "Switch buffer to next member list."
2389 (interactive)
2390 (ebrowse-cyclic-display-next/previous-member-list 1))
2391
2392
2393 (defun ebrowse-display-previous-member-list ()
2394 "Switch buffer to previous member list."
2395 (interactive)
2396 (ebrowse-cyclic-display-next/previous-member-list -1))
2397
2398
2399 (defun ebrowse-display-function-member-list ()
2400 "Display the list of member functions."
2401 (interactive)
2402 (ebrowse-display-member-list-for-accessor 'ebrowse-ts-member-functions))
2403
2404
2405 (defun ebrowse-display-variables-member-list ()
2406 "Display the list of member variables."
2407 (interactive)
2408 (ebrowse-display-member-list-for-accessor 'ebrowse-ts-member-variables))
2409
2410
2411 (defun ebrowse-display-static-variables-member-list ()
2412 "Display the list of static member variables."
2413 (interactive)
2414 (ebrowse-display-member-list-for-accessor 'ebrowse-ts-static-variables))
2415
2416
2417 (defun ebrowse-display-static-functions-member-list ()
2418 "Display the list of static member functions."
2419 (interactive)
2420 (ebrowse-display-member-list-for-accessor 'ebrowse-ts-static-functions))
2421
2422
2423 (defun ebrowse-display-friends-member-list ()
2424 "Display the list of friends."
2425 (interactive)
2426 (ebrowse-display-member-list-for-accessor 'ebrowse-ts-friends))
2427
2428
2429 (defun ebrowse-display-types-member-list ()
2430 "Display the list of types."
2431 (interactive)
2432 (ebrowse-display-member-list-for-accessor 'ebrowse-ts-types))
2433
2434
2435 \f
2436 ;;; Filters and other display attributes
2437
2438 (defun ebrowse-toggle-member-attributes-display ()
2439 "Toggle display of `virtual', `inline', `const' etc."
2440 (interactive)
2441 (setq ebrowse--attributes-flag (not ebrowse--attributes-flag))
2442 (ebrowse-redisplay-member-buffer))
2443
2444
2445 (defun ebrowse-toggle-base-class-display ()
2446 "Toggle the display of members inherited from base classes."
2447 (interactive)
2448 (setf ebrowse--show-inherited-flag (not ebrowse--show-inherited-flag))
2449 (ebrowse-redisplay-member-buffer))
2450
2451
2452 (defun ebrowse-toggle-pure-member-filter ()
2453 "Toggle display of pure virtual members."
2454 (interactive)
2455 (setf ebrowse--pure-display-flag (not ebrowse--pure-display-flag))
2456 (ebrowse-redisplay-member-buffer))
2457
2458
2459 (defun ebrowse-toggle-const-member-filter ()
2460 "Toggle display of const members."
2461 (interactive)
2462 (setf ebrowse--const-display-flag (not ebrowse--const-display-flag))
2463 (ebrowse-redisplay-member-buffer))
2464
2465
2466 (defun ebrowse-toggle-inline-member-filter ()
2467 "Toggle display of inline members."
2468 (interactive)
2469 (setf ebrowse--inline-display-flag (not ebrowse--inline-display-flag))
2470 (ebrowse-redisplay-member-buffer))
2471
2472
2473 (defun ebrowse-toggle-virtual-member-filter ()
2474 "Toggle display of virtual members."
2475 (interactive)
2476 (setf ebrowse--virtual-display-flag (not ebrowse--virtual-display-flag))
2477 (ebrowse-redisplay-member-buffer))
2478
2479
2480 (defun ebrowse-remove-all-member-filters ()
2481 "Remove all filters."
2482 (interactive)
2483 (dotimes (i 3)
2484 (aset ebrowse--filters i i))
2485 (setq ebrowse--pure-display-flag nil
2486 ebrowse--const-display-flag nil
2487 ebrowse--virtual-display-flag nil
2488 ebrowse--inline-display-flag nil)
2489 (ebrowse-redisplay-member-buffer))
2490
2491
2492 (defun ebrowse-toggle-public-member-filter ()
2493 "Toggle visibility of public members."
2494 (interactive)
2495 (ebrowse-set-member-access-visibility 0)
2496 (ebrowse-redisplay-member-buffer))
2497
2498
2499 (defun ebrowse-toggle-protected-member-filter ()
2500 "Toggle visibility of protected members."
2501 (interactive)
2502 (ebrowse-set-member-access-visibility 1)
2503 (ebrowse-redisplay-member-buffer))
2504
2505
2506 (defun ebrowse-toggle-private-member-filter ()
2507 "Toggle visibility of private members."
2508 (interactive)
2509 (ebrowse-set-member-access-visibility 2)
2510 (ebrowse-redisplay-member-buffer))
2511
2512
2513 (defun ebrowse-set-member-access-visibility (vis)
2514 (setf (aref ebrowse--filters vis)
2515 (if (aref ebrowse--filters vis) nil vis)))
2516
2517
2518 (defun ebrowse-toggle-long-short-display ()
2519 "Toggle between long and short display form of member buffers."
2520 (interactive)
2521 (setf ebrowse--long-display-flag (not ebrowse--long-display-flag))
2522 (ebrowse-redisplay-member-buffer))
2523
2524
2525 (defun ebrowse-toggle-regexp-display ()
2526 "Toggle declaration/definition regular expression display.
2527 Used in member buffers showing the long display form."
2528 (interactive)
2529 (setf ebrowse--source-regexp-flag (not ebrowse--source-regexp-flag))
2530 (ebrowse-redisplay-member-buffer))
2531
2532
2533 \f
2534 ;;; Viewing/finding members
2535
2536 (defun ebrowse-find-member-definition (&optional prefix)
2537 "Find the file containing a member definition.
2538 With PREFIX 4. find file in another window, with prefix 5
2539 find file in another frame."
2540 (interactive "p")
2541 (ebrowse-view/find-member-declaration/definition prefix nil t))
2542
2543
2544 (defun ebrowse-view-member-definition (prefix)
2545 "View the file containing a member definition.
2546 With PREFIX 4. find file in another window, with prefix 5
2547 find file in another frame."
2548 (interactive "p")
2549 (ebrowse-view/find-member-declaration/definition prefix t t))
2550
2551
2552 (defun ebrowse-find-member-declaration (prefix)
2553 "Find the file containing a member's declaration.
2554 With PREFIX 4. find file in another window, with prefix 5
2555 find file in another frame."
2556 (interactive "p")
2557 (ebrowse-view/find-member-declaration/definition prefix nil))
2558
2559
2560 (defun ebrowse-view-member-declaration (prefix)
2561 "View the file containing a member's declaration.
2562 With PREFIX 4. find file in another window, with prefix 5
2563 find file in another frame."
2564 (interactive "p")
2565 (ebrowse-view/find-member-declaration/definition prefix t))
2566
2567
2568 (defun* ebrowse-view/find-member-declaration/definition
2569 (prefix view &optional definition info header tags-file-name)
2570 "Find or view a member declaration or definition.
2571 With PREFIX 4. find file in another window, with prefix 5
2572 find file in another frame.
2573 DEFINITION non-nil means find the definition, otherwise find the
2574 declaration.
2575 INFO is a list (TREE ACCESSOR MEMBER) describing the member to
2576 search.
2577 TAGS-FILE-NAME is the file name of the BROWSE file."
2578 (unless header
2579 (setq header ebrowse--header))
2580 (unless tags-file-name
2581 (setq tags-file-name ebrowse--tags-file-name))
2582 (let (tree member accessor file on-class
2583 (where (if (= prefix 4) 'other-window
2584 (if (= prefix 5) 'other-frame 'this-window))))
2585 ;; If not given as parameters, get the necessary information
2586 ;; out of the member buffer.
2587 (if info
2588 (setq tree (first info)
2589 accessor (second info)
2590 member (third info))
2591 (multiple-value-setq (tree member on-class)
2592 (values-list (ebrowse-member-info-from-point)))
2593 (setq accessor ebrowse--accessor))
2594 ;; View/find class if on a line containing a class name.
2595 (when on-class
2596 (return-from ebrowse-view/find-member-declaration/definition
2597 (ebrowse-view/find-file-and-search-pattern
2598 (ebrowse-ts-class tree)
2599 (list ebrowse--header (ebrowse-ts-class tree) nil)
2600 (ebrowse-cs-file (ebrowse-ts-class tree))
2601 tags-file-name view where)))
2602 ;; For some member lists, it doesn't make sense to search for
2603 ;; a definition. If this is requested, silently search for the
2604 ;; declaration.
2605 (when (and definition
2606 (eq accessor 'ebrowse-ts-member-variables))
2607 (setq definition nil))
2608 ;; Construct a suitable `browse' struct for definitions.
2609 (when definition
2610 (setf member (make-ebrowse-ms
2611 :name (ebrowse-ms-name member)
2612 :file (ebrowse-ms-definition-file member)
2613 :pattern (ebrowse-ms-definition-pattern
2614 member)
2615 :flags (ebrowse-ms-flags member)
2616 :point (ebrowse-ms-definition-point
2617 member))))
2618 ;; When no file information in member, use that of the class
2619 (setf file (or (ebrowse-ms-file member)
2620 (if definition
2621 (ebrowse-cs-source-file (ebrowse-ts-class tree))
2622 (ebrowse-cs-file (ebrowse-ts-class tree)))))
2623 ;; When we have no regular expressions in the database the only
2624 ;; indication that the parser hasn't seen a definition/declaration
2625 ;; is that the search start point will be zero.
2626 (if (or (null file) (zerop (ebrowse-ms-point member)))
2627 (if (y-or-n-p (concat "No information about "
2628 (if definition "definition" "declaration")
2629 ". Search for "
2630 (if definition "declaration" "definition")
2631 " of `"
2632 (ebrowse-ms-name member)
2633 "'? "))
2634 (progn
2635 (message nil)
2636 ;; Recurse with new info.
2637 (ebrowse-view/find-member-declaration/definition
2638 prefix view (not definition) info header tags-file-name))
2639 (error "Search canceled"))
2640 ;; Find that thing.
2641 (ebrowse-view/find-file-and-search-pattern
2642 (make-ebrowse-bs :name (ebrowse-ms-name member)
2643 :pattern (ebrowse-ms-pattern member)
2644 :file (ebrowse-ms-file member)
2645 :flags (ebrowse-ms-flags member)
2646 :point (ebrowse-ms-point member))
2647 (list header member accessor)
2648 file
2649 tags-file-name
2650 view
2651 where))))
2652
2653
2654 \f
2655 ;;; Drawing the member buffer
2656
2657 (defun ebrowse-redisplay-member-buffer ()
2658 "Force buffer redisplay."
2659 (interactive)
2660 (let ((display-fn (if ebrowse--long-display-flag
2661 'ebrowse-draw-member-long-fn
2662 'ebrowse-draw-member-short-fn)))
2663 (ebrowse-output
2664 (erase-buffer)
2665 ;; Show this class
2666 (ebrowse-draw-member-buffer-class-line)
2667 (funcall display-fn ebrowse--member-list ebrowse--displayed-class)
2668 ;; Show inherited members if corresponding switch is on
2669 (when ebrowse--show-inherited-flag
2670 (dolist (super (ebrowse-base-classes ebrowse--displayed-class))
2671 (goto-char (point-max))
2672 (insert (if (bolp) "\n\n" "\n"))
2673 (ebrowse-draw-member-buffer-class-line super)
2674 (funcall display-fn (funcall ebrowse--accessor super) super)))
2675 (ebrowse-update-member-buffer-mode-line))))
2676
2677
2678 (defun ebrowse-draw-member-buffer-class-line (&optional class)
2679 "Display the title line for a class section in the member buffer.
2680 CLASS non-nil means display that class' title. Otherwise use
2681 the class cursor is on."
2682 (let ((start (point))
2683 (tree (or class ebrowse--displayed-class))
2684 class-name-start
2685 class-name-end)
2686 (insert "class ")
2687 (setq class-name-start (point))
2688 (insert (ebrowse-qualified-class-name (ebrowse-ts-class tree)))
2689 (when (ebrowse-template-p (ebrowse-ts-class tree))
2690 (insert "<>"))
2691 (setq class-name-end (point))
2692 (insert ":\n\n")
2693 (ebrowse-set-face start (point) 'ebrowse-member-class)
2694 (add-text-properties
2695 class-name-start class-name-end
2696 '(ebrowse-what class-name
2697 mouse-face highlight
2698 help-echo "mouse-3: menu"))
2699 (put-text-property start class-name-end 'ebrowse-tree tree)))
2700
2701
2702 (defun ebrowse-display-member-buffer (list &optional stand-alone class)
2703 "Start point for member buffer creation.
2704 LIST is the member list to display. STAND-ALONE non-nil
2705 means the member buffer is standalone. CLASS is its class."
2706 (let* ((classes ebrowse--tree-obarray)
2707 (tree ebrowse--tree)
2708 (tags-file-name ebrowse--tags-file-name)
2709 (header ebrowse--header)
2710 temp-buffer-setup-hook
2711 (temp-buffer (get-buffer ebrowse-member-buffer-name)))
2712 ;; Get the class description from the name the cursor
2713 ;; is on if not specified as an argument.
2714 (unless class
2715 (setq class (ebrowse-tree-at-point)))
2716 (save-selected-window
2717 (if temp-buffer
2718 (pop-to-buffer temp-buffer)
2719 (pop-to-buffer (get-buffer-create ebrowse-member-buffer-name))
2720 ;; If new buffer, set the mode and initial values of locals
2721 (ebrowse-member-mode))
2722 ;; Set local variables
2723 (setq ebrowse--member-list (funcall list class)
2724 ebrowse--displayed-class class
2725 ebrowse--accessor list
2726 ebrowse--tree-obarray classes
2727 ebrowse--frozen-flag stand-alone
2728 ebrowse--tags-file-name tags-file-name
2729 ebrowse--header header
2730 ebrowse--tree tree
2731 buffer-read-only t)
2732 (ebrowse-redisplay-member-buffer)
2733 (current-buffer))))
2734
2735
2736 (defun ebrowse-member-display-p (member)
2737 "Return t if MEMBER must be displayed under the current filter settings."
2738 (if (and (aref ebrowse--filters (ebrowse-ms-visibility member))
2739 (or (null ebrowse--const-display-flag)
2740 (ebrowse-const-p member))
2741 (or (null ebrowse--inline-display-flag)
2742 (ebrowse-inline-p member))
2743 (or (null ebrowse--pure-display-flag)
2744 (ebrowse-bs-p member))
2745 (or (null ebrowse--virtual-display-flag)
2746 (ebrowse-virtual-p member)))
2747 member))
2748
2749
2750 (defun ebrowse-draw-member-attributes (member)
2751 "Insert a string for the attributes of MEMBER."
2752 (insert (if (ebrowse-template-p member) "T" "-")
2753 (if (ebrowse-extern-c-p member) "C" "-")
2754 (if (ebrowse-virtual-p member) "v" "-")
2755 (if (ebrowse-inline-p member) "i" "-")
2756 (if (ebrowse-const-p member) "c" "-")
2757 (if (ebrowse-pure-virtual-p member) "0" "-")
2758 (if (ebrowse-mutable-p member) "m" "-")
2759 (if (ebrowse-explicit-p member) "e" "-")
2760 (if (ebrowse-throw-list-p member) "t" "-")))
2761
2762
2763 (defun ebrowse-draw-member-regexp (member-struc)
2764 "Insert a string for the regular expression matching MEMBER-STRUC."
2765 (let ((pattern (if ebrowse--source-regexp-flag
2766 (ebrowse-ms-definition-pattern
2767 member-struc)
2768 (ebrowse-ms-pattern member-struc))))
2769 (cond ((stringp pattern)
2770 (insert (ebrowse-trim-string pattern) "...\n")
2771 (beginning-of-line 0)
2772 (move-to-column (+ 4 ebrowse--decl-column))
2773 (while (re-search-forward "[ \t]+" nil t)
2774 (delete-region (match-beginning 0) (match-end 0))
2775 (insert " "))
2776 (beginning-of-line 2))
2777 (t
2778 (insert "[not recorded or unknown]\n")))))
2779
2780
2781 (defun ebrowse-draw-member-long-fn (member-list tree)
2782 "Display member buffer for MEMBER-LIST in long form.
2783 TREE is the class tree of MEMBER-LIST."
2784 (dolist (member-struc (mapcar 'ebrowse-member-display-p member-list))
2785 (when member-struc
2786 (let ((name (ebrowse-ms-name member-struc))
2787 (start (point)))
2788 ;; Insert member name truncated to the right length
2789 (insert (substring name
2790 0
2791 (min (length name)
2792 (1- ebrowse--decl-column))))
2793 (add-text-properties
2794 start (point)
2795 `(mouse-face highlight ebrowse-what member-name
2796 ebrowse-member ,member-struc
2797 ebrowse-tree ,tree
2798 help-echo "mouse-2: view definition; mouse-3: menu"))
2799 ;; Display virtual, inline, and const status
2800 (setf start (point))
2801 (indent-to ebrowse--decl-column)
2802 (put-text-property start (point) 'mouse-face nil)
2803 (when ebrowse--attributes-flag
2804 (let ((start (point)))
2805 (insert "<")
2806 (ebrowse-draw-member-attributes member-struc)
2807 (insert ">")
2808 (ebrowse-set-face start (point)
2809 'ebrowse-member-attribute)))
2810 (insert " ")
2811 (ebrowse-draw-member-regexp member-struc))))
2812 (insert "\n")
2813 (goto-char (point-min)))
2814
2815
2816 (defun ebrowse-draw-member-short-fn (member-list tree)
2817 "Display MEMBER-LIST in short form.
2818 TREE is the class tree in which the members are found."
2819 (let ((i 0)
2820 (column-width (+ ebrowse--column-width
2821 (if ebrowse--attributes-flag 12 0))))
2822 ;; Get the number of columns to draw.
2823 (setq ebrowse--n-columns
2824 (max 1 (/ (ebrowse-width-of-drawable-area) column-width)))
2825 (dolist (member (mapcar #'ebrowse-member-display-p member-list))
2826 (when member
2827 (let ((name (ebrowse-ms-name member))
2828 start-of-entry
2829 (start-of-column (point))
2830 start-of-name)
2831 (indent-to (* i column-width))
2832 (put-text-property start-of-column (point) 'mouse-face nil)
2833 (setq start-of-entry (point))
2834 ;; Show various attributes
2835 (when ebrowse--attributes-flag
2836 (insert "<")
2837 (ebrowse-draw-member-attributes member)
2838 (insert "> ")
2839 (ebrowse-set-face start-of-entry (point)
2840 'ebrowse-member-attribute))
2841 ;; insert member name truncated to column width
2842 (setq start-of-name (point))
2843 (insert (substring name 0
2844 (min (length name)
2845 (1- ebrowse--column-width))))
2846 ;; set text properties
2847 (add-text-properties
2848 start-of-name (point)
2849 `(ebrowse-what member-name
2850 ebrowse-member ,member
2851 mouse-face highlight
2852 ebrowse-tree ,tree
2853 help-echo "mouse-2: view definition; mouse-3: menu"))
2854 (incf i)
2855 (when (>= i ebrowse--n-columns)
2856 (setf i 0)
2857 (insert "\n")))))
2858 (when (plusp i)
2859 (insert "\n"))
2860 (goto-char (point-min))))
2861
2862
2863 \f
2864 ;;; Killing members from tree
2865
2866 (defun ebrowse-member-info-from-point ()
2867 "Ger information about the member at point.
2868 The result has the form (TREE MEMBER NULL-P). TREE is the tree
2869 we're in, MEMBER is the member we're on. NULL-P is t if MEMBER
2870 is nil."
2871 (let ((tree (or (get-text-property (point) 'ebrowse-tree)
2872 (error "No information at point")))
2873 (member (get-text-property (point) 'ebrowse-member)))
2874 (list tree member (null member))))
2875
2876
2877 \f
2878 ;;; Switching member buffer to display a selected member
2879
2880 (defun ebrowse-goto-visible-member/all-member-lists (prefix)
2881 "Position cursor on a member read from the minibuffer.
2882 With PREFIX, search all members in the tree. Otherwise consider
2883 only members visible in the buffer."
2884 (interactive "p")
2885 (ebrowse-ignoring-completion-case
2886 (let* ((completion-list (ebrowse-name/accessor-alist-for-class-members))
2887 (member (completing-read "Goto member: " completion-list nil t))
2888 (accessor (cdr (assoc member completion-list))))
2889 (unless accessor
2890 (error "`%s' not found" member))
2891 (unless (eq accessor ebrowse--accessor)
2892 (setf ebrowse--accessor accessor
2893 ebrowse--member-list (funcall accessor ebrowse--displayed-class))
2894 (ebrowse-redisplay-member-buffer))
2895 (ebrowse-move-point-to-member member))))
2896
2897
2898 (defun ebrowse-goto-visible-member (repeat)
2899 "Position point on a member.
2900 Read the member's name from the minibuffer. Consider only members
2901 visible in the member buffer.
2902 REPEAT non-nil means repeat the search that number of times."
2903 (interactive "p")
2904 (ebrowse-ignoring-completion-case
2905 ;; Read member name
2906 (let* ((completion-list (ebrowse-name/accessor-alist-for-visible-members))
2907 (member (completing-read "Goto member: " completion-list nil t)))
2908 (ebrowse-move-point-to-member member repeat))))
2909
2910
2911 \f
2912 ;;; Searching a member in the member buffer
2913
2914 (defun ebrowse-repeat-member-search (repeat)
2915 "Repeat the last regular expression search.
2916 REPEAT, if specified, says repeat the search REPEAT times."
2917 (interactive "p")
2918 (unless ebrowse--last-regexp
2919 (error "No regular expression remembered"))
2920 ;; Skip over word the point is on
2921 (skip-chars-forward "^ \t\n")
2922 ;; Search for regexp from point
2923 (if (re-search-forward ebrowse--last-regexp nil t repeat)
2924 (progn
2925 (goto-char (match-beginning 0))
2926 (skip-chars-forward " \t\n"))
2927 ;; If not found above, repeat search from buffer start
2928 (goto-char (point-min))
2929 (if (re-search-forward ebrowse--last-regexp nil t)
2930 (progn
2931 (goto-char (match-beginning 0))
2932 (skip-chars-forward " \t\n"))
2933 (error "Not found"))))
2934
2935
2936 (defun* ebrowse-move-point-to-member (name &optional count &aux member)
2937 "Set point on member NAME in the member buffer
2938 COUNT, if specified, says search the COUNT'th member with the same name."
2939 (goto-char (point-min))
2940 (widen)
2941 (setq member
2942 (substring name 0 (min (length name) (1- ebrowse--column-width)))
2943 ebrowse--last-regexp
2944 (concat "[ \t\n]" (regexp-quote member) "[ \n\t]"))
2945 (if (re-search-forward ebrowse--last-regexp nil t count)
2946 (goto-char (1+ (match-beginning 0)))
2947 (error "Not found")))
2948
2949
2950 \f
2951 ;;; Switching member buffer to another class.
2952
2953 (defun ebrowse-switch-member-buffer-to-other-class (title compl-list)
2954 "Switch member buffer to a class read from the minibuffer.
2955 Use TITLE as minibuffer prompt.
2956 COMPL-LIST is a completion list to use."
2957 (let* ((initial (unless (second compl-list)
2958 (first (first compl-list))))
2959 (class (or (ebrowse-completing-read-value title compl-list initial)
2960 (error "Not found"))))
2961 (setf ebrowse--displayed-class class
2962 ebrowse--member-list (funcall ebrowse--accessor ebrowse--displayed-class))
2963 (ebrowse-redisplay-member-buffer)))
2964
2965
2966 (defun ebrowse-switch-member-buffer-to-any-class ()
2967 "Switch member buffer to a class read from the minibuffer."
2968 (interactive)
2969 (ebrowse-switch-member-buffer-to-other-class
2970 "Goto class: " (ebrowse-tree-obarray-as-alist)))
2971
2972
2973 (defun ebrowse-switch-member-buffer-to-base-class (arg)
2974 "Switch buffer to ARG'th base class."
2975 (interactive "P")
2976 (let ((supers (or (ebrowse-direct-base-classes ebrowse--displayed-class)
2977 (error "No base classes"))))
2978 (if (and arg (second supers))
2979 (let ((alist (loop for s in supers
2980 collect (cons (ebrowse-qualified-class-name
2981 (ebrowse-ts-class s))
2982 s))))
2983 (ebrowse-switch-member-buffer-to-other-class
2984 "Goto base class: " alist))
2985 (setq ebrowse--displayed-class (first supers)
2986 ebrowse--member-list
2987 (funcall ebrowse--accessor ebrowse--displayed-class))
2988 (ebrowse-redisplay-member-buffer))))
2989
2990 (defun ebrowse-switch-member-buffer-to-next-sibling-class (arg)
2991 "Move to ARG'th next sibling."
2992 (interactive "p")
2993 (ebrowse-switch-member-buffer-to-sibling-class arg))
2994
2995
2996 (defun ebrowse-switch-member-buffer-to-previous-sibling-class (arg)
2997 "Move to ARG'th previous sibling."
2998 (interactive "p")
2999 (ebrowse-switch-member-buffer-to-sibling-class (- arg)))
3000
3001
3002 (defun ebrowse-switch-member-buffer-to-sibling-class (inc)
3003 "Switch member display to nth sibling class.
3004 Prefix arg INC specifies which one."
3005 (interactive "p")
3006 (let ((containing-list ebrowse--tree)
3007 index cls
3008 (supers (ebrowse-direct-base-classes ebrowse--displayed-class)))
3009 (flet ((trees-alist (trees)
3010 (loop for tr in trees
3011 collect (cons (ebrowse-cs-name
3012 (ebrowse-ts-class tr)) tr))))
3013 (when supers
3014 (let ((tree (if (second supers)
3015 (ebrowse-completing-read-value
3016 "Relative to base class: "
3017 (trees-alist supers) nil)
3018 (first supers))))
3019 (unless tree (error "Not found"))
3020 (setq containing-list (ebrowse-ts-subclasses tree)))))
3021 (setq index (+ inc (ebrowse-position ebrowse--displayed-class
3022 containing-list)))
3023 (cond ((minusp index) (message "No previous class"))
3024 ((null (nth index containing-list)) (message "No next class")))
3025 (setq index (max 0 (min index (1- (length containing-list)))))
3026 (setq cls (nth index containing-list))
3027 (setf ebrowse--displayed-class cls
3028 ebrowse--member-list (funcall ebrowse--accessor cls))
3029 (ebrowse-redisplay-member-buffer)))
3030
3031
3032 (defun ebrowse-switch-member-buffer-to-derived-class (arg)
3033 "Switch member display to nth derived class.
3034 Prefix arg ARG says which class should be displayed. Default is
3035 the first derived class."
3036 (interactive "P")
3037 (flet ((ebrowse-tree-obarray-as-alist ()
3038 (loop for s in (ebrowse-ts-subclasses
3039 ebrowse--displayed-class)
3040 collect (cons (ebrowse-cs-name
3041 (ebrowse-ts-class s)) s))))
3042 (let ((subs (or (ebrowse-ts-subclasses ebrowse--displayed-class)
3043 (error "No derived classes"))))
3044 (if (and arg (second subs))
3045 (ebrowse-switch-member-buffer-to-other-class
3046 "Goto derived class: " (ebrowse-tree-obarray-as-alist))
3047 (setq ebrowse--displayed-class (first subs)
3048 ebrowse--member-list
3049 (funcall ebrowse--accessor ebrowse--displayed-class))
3050 (ebrowse-redisplay-member-buffer)))))
3051
3052
3053 \f
3054 ;;; Member buffer mouse functions
3055
3056 (defun ebrowse-displaying-functions ()
3057 (eq ebrowse--accessor 'ebrowse-ts-member-functions))
3058 (defun ebrowse-displaying-variables ()
3059 (eq ebrowse--accessor 'ebrowse-ts-member-variables))
3060 (defun ebrowse-displaying-static-functions ()
3061 )
3062 (defun ebrowse-displaying-static-variables ()
3063 )
3064 (defun ebrowse-displaying-types ()
3065 (eq ebrowse--accessor 'ebrowse-ts-types))
3066 (defun ebrowse-displaying-friends ()
3067 (eq ebrowse--accessor 'ebrowse-ts-friends))
3068
3069 (easy-menu-define
3070 ebrowse-member-buffer-object-menu ebrowse-member-mode-map
3071 "Object menu for the member buffer itself."
3072 '("Members"
3073 ("Members List"
3074 ["Functions" ebrowse-display-function-member-list
3075 :help "Show the list of member functions"
3076 :style radio
3077 :selected (eq ebrowse--accessor 'ebrowse-ts-member-functions)
3078 :active t]
3079 ["Variables" ebrowse-display-variables-member-list
3080 :help "Show the list of member variables"
3081 :style radio
3082 :selected (eq ebrowse--accessor 'ebrowse-ts-member-variables)
3083 :active t]
3084 ["Static Functions" ebrowse-display-static-functions-member-list
3085 :help "Show the list of static member functions"
3086 :style radio
3087 :selected (eq ebrowse--accessor 'ebrowse-ts-static-functions)
3088 :active t]
3089 ["Static Variables" ebrowse-display-static-variables-member-list
3090 :help "Show the list of static member variables"
3091 :style radio
3092 :selected (eq ebrowse--accessor 'ebrowse-ts-static-variables)
3093 :active t]
3094 ["Types" ebrowse-display-types-member-list
3095 :help "Show the list of nested types"
3096 :style radio
3097 :selected (eq ebrowse--accessor 'ebrowse-ts-types)
3098 :active t]
3099 ["Friends/Defines" ebrowse-display-friends-member-list
3100 :help "Show the list of friends or defines"
3101 :style radio
3102 :selected (eq ebrowse--accessor 'ebrowse-ts-friends)
3103 :active t])
3104 ("Class"
3105 ["Up" ebrowse-switch-member-buffer-to-base-class
3106 :help "Show the base class of this class"
3107 :active t]
3108 ["Down" ebrowse-switch-member-buffer-to-derived-class
3109 :help "Show a derived class class of this class"
3110 :active t]
3111 ["Next Sibling" ebrowse-switch-member-buffer-to-next-sibling-class
3112 :help "Show the next sibling class"
3113 :active t]
3114 ["Previous Sibling" ebrowse-switch-member-buffer-to-previous-sibling-class
3115 :help "Show the previous sibling class"
3116 :active t])
3117 ("Member"
3118 ["Show in Tree" ebrowse-show-displayed-class-in-tree
3119 :help "Show this class in the class tree"
3120 :active t]
3121 ["Find in this Class" ebrowse-goto-visible-member
3122 :help "Search for a member of this class"
3123 :active t]
3124 ["Find in Tree" ebrowse-goto-visible-member/all-member-lists
3125 :help "Search for a member in any class"
3126 :active t])
3127 ("Display"
3128 ["Inherited" ebrowse-toggle-base-class-display
3129 :help "Toggle display of inherited members"
3130 :style toggle
3131 :selected ebrowse--show-inherited-flag
3132 :active t]
3133 ["Attributes" ebrowse-toggle-member-attributes-display
3134 :help "Show member attributes"
3135 :style toggle
3136 :selected ebrowse--attributes-flag
3137 :active t]
3138 ["Long Display" ebrowse-toggle-long-short-display
3139 :help "Toggle the member display format"
3140 :style toggle
3141 :selected ebrowse--long-display-flag
3142 :active t]
3143 ["Column Width" ebrowse-set-member-buffer-column-width
3144 :help "Set the display's column width"
3145 :active t])
3146 ("Filter"
3147 ["Public" ebrowse-toggle-public-member-filter
3148 :help "Toggle the visibility of public members"
3149 :style toggle
3150 :selected (not (aref ebrowse--filters 0))
3151 :active t]
3152 ["Protected" ebrowse-toggle-protected-member-filter
3153 :help "Toggle the visibility of protected members"
3154 :style toggle
3155 :selected (not (aref ebrowse--filters 1))
3156 :active t]
3157 ["Private" ebrowse-toggle-private-member-filter
3158 :help "Toggle the visibility of private members"
3159 :style toggle
3160 :selected (not (aref ebrowse--filters 2))
3161 :active t]
3162 ["Virtual" ebrowse-toggle-virtual-member-filter
3163 :help "Toggle the visibility of virtual members"
3164 :style toggle
3165 :selected ebrowse--virtual-display-flag
3166 :active t]
3167 ["Inline" ebrowse-toggle-inline-member-filter
3168 :help "Toggle the visibility of inline members"
3169 :style toggle
3170 :selected ebrowse--inline-display-flag
3171 :active t]
3172 ["Const" ebrowse-toggle-const-member-filter
3173 :help "Toggle the visibility of const members"
3174 :style toggle
3175 :selected ebrowse--const-display-flag
3176 :active t]
3177 ["Pure" ebrowse-toggle-pure-member-filter
3178 :help "Toggle the visibility of pure virtual members"
3179 :style toggle
3180 :selected ebrowse--pure-display-flag
3181 :active t]
3182 "-----------------"
3183 ["Show all" ebrowse-remove-all-member-filters
3184 :help "Remove any display filters"
3185 :active t])
3186 ("Buffer"
3187 ["Tree" ebrowse-pop-from-member-to-tree-buffer
3188 :help "Pop to the class tree buffer"
3189 :active t]
3190 ["Next Member Buffer" ebrowse-switch-to-next-member-buffer
3191 :help "Switch to the next member buffer of this class tree"
3192 :active t]
3193 ["Freeze" ebrowse-freeze-member-buffer
3194 :help "Freeze (do not reuse) this member buffer"
3195 :active t])))
3196
3197
3198 (defun ebrowse-on-class-name ()
3199 "Value is non-nil if point is on a class name."
3200 (eq (get-text-property (point) 'ebrowse-what) 'class-name))
3201
3202
3203 (defun ebrowse-on-member-name ()
3204 "Value is non-nil if point is on a member name."
3205 (eq (get-text-property (point) 'ebrowse-what) 'member-name))
3206
3207
3208 (easy-menu-define
3209 ebrowse-member-class-name-object-menu ebrowse-member-mode-map
3210 "Object menu for class names in member buffer."
3211 '("Class"
3212 ["Find" ebrowse-find-member-definition
3213 :help "Find this class in the source files"
3214 :active (eq (get-text-property (point) 'ebrowse-what) 'class-name)]
3215 ["View" ebrowse-view-member-definition
3216 :help "View this class in the source files"
3217 :active (eq (get-text-property (point) 'ebrowse-what) 'class-name)]))
3218
3219
3220 (easy-menu-define
3221 ebrowse-member-name-object-menu ebrowse-member-mode-map
3222 "Object menu for member names"
3223 '("Ebrowse"
3224 ["Find Definition" ebrowse-find-member-definition
3225 :help "Find this member's definition in the source files"
3226 :active (ebrowse-on-member-name)]
3227 ["Find Declaration" ebrowse-find-member-declaration
3228 :help "Find this member's declaration in the source files"
3229 :active (ebrowse-on-member-name)]
3230 ["View Definition" ebrowse-view-member-definition
3231 :help "View this member's definition in the source files"
3232 :active (ebrowse-on-member-name)]
3233 ["View Declaration" ebrowse-view-member-declaration
3234 :help "View this member's declaration in the source files"
3235 :active (ebrowse-on-member-name)]))
3236
3237
3238 (defun ebrowse-member-mouse-3 (event)
3239 "Handle `mouse-3' events in member buffers.
3240 EVENT is the mouse event."
3241 (interactive "e")
3242 (mouse-set-point event)
3243 (case (event-click-count event)
3244 (2 (ebrowse-find-member-definition))
3245 (1 (case (get-text-property (posn-point (event-start event))
3246 'ebrowse-what)
3247 (member-name
3248 (ebrowse-popup-menu ebrowse-member-name-object-menu event))
3249 (class-name
3250 (ebrowse-popup-menu ebrowse-member-class-name-object-menu event))
3251 (t
3252 (ebrowse-popup-menu ebrowse-member-buffer-object-menu event))))))
3253
3254
3255 (defun ebrowse-member-mouse-2 (event)
3256 "Handle `mouse-2' events in member buffers.
3257 EVENT is the mouse event."
3258 (interactive "e")
3259 (mouse-set-point event)
3260 (case (event-click-count event)
3261 (2 (ebrowse-find-member-definition))
3262 (1 (case (get-text-property (posn-point (event-start event))
3263 'ebrowse-what)
3264 (member-name
3265 (ebrowse-view-member-definition 0))))))
3266
3267
3268 \f
3269 ;;; Tags view/find
3270
3271 (defun ebrowse-class-alist-for-member (tree-header name)
3272 "Return information about a member in a class tree.
3273 TREE-HEADER is the header structure of the class tree.
3274 NAME is the name of the member.
3275 Value is an alist of elements (CLASS-NAME . (CLASS LIST NAME)),
3276 where each element describes one occurrence of member NAME in the tree.
3277 CLASS-NAME is the qualified name of the class in which the
3278 member was found. The CDR of the acons is described in function
3279 `ebrowse-class/index/member-for-member'."
3280 (let ((table (ebrowse-member-table tree-header))
3281 known-classes
3282 alist)
3283 (when name
3284 (dolist (info (gethash name table) alist)
3285 (unless (memq (first info) known-classes)
3286 (setf alist (acons (ebrowse-qualified-class-name
3287 (ebrowse-ts-class (first info)))
3288 info alist)
3289 known-classes (cons (first info) known-classes)))))))
3290
3291
3292 (defun ebrowse-choose-tree ()
3293 "Choose a class tree to use.
3294 If there's more than one class tree loaded, let the user choose
3295 the one he wants. Value is (TREE HEADER BUFFER), with TREE being
3296 the class tree, HEADER the header structure of the tree, and BUFFER
3297 being the tree or member buffer containing the tree."
3298 (let* ((buffer (ebrowse-choose-from-browser-buffers)))
3299 (if buffer (list (ebrowse-value-in-buffer 'ebrowse--tree buffer)
3300 (ebrowse-value-in-buffer 'ebrowse--header buffer)
3301 buffer))))
3302
3303
3304 (defun ebrowse-tags-read-name (header prompt)
3305 "Read a C++ identifier from the minibuffer.
3306 HEADER is the `ebrowse-hs' structure of the class tree.
3307 Prompt with PROMPT. Insert into the minibuffer a C++ identifier read
3308 from point as default. Value is a list (CLASS-NAME MEMBER-NAME)."
3309 (save-excursion
3310 (let* (start member-info (members (ebrowse-member-table header)))
3311 (multiple-value-bind (class-name member-name)
3312 (values-list (ebrowse-tags-read-member+class-name))
3313 (unless member-name
3314 (error "No member name at point"))
3315 (if members
3316 (let* ((name (ebrowse-ignoring-completion-case
3317 (completing-read prompt members nil nil member-name)))
3318 (completion-result (try-completion name members)))
3319 ;; Cannot rely on `try-completion' returning t for exact
3320 ;; matches! It returns the name as a string.
3321 (unless (setq member-info (gethash name members))
3322 (if (y-or-n-p "No exact match found. Try substrings? ")
3323 (setq name
3324 (or (first (ebrowse-list-of-matching-members
3325 members (regexp-quote name) name))
3326 (error "Sorry, nothing found")))
3327 (error "Canceled")))
3328 (list class-name name))
3329 (list class-name (read-from-minibuffer prompt member-name)))))))
3330
3331
3332 (defun ebrowse-tags-read-member+class-name ()
3333 "Read a C++ identifier from point.
3334 Value is (CLASS-NAME MEMBER-NAME).
3335 CLASS-NAME is the name of the class if the identifier was qualified.
3336 It is nil otherwise.
3337 MEMBER-NAME is the name of the member found."
3338 (save-excursion
3339 (skip-chars-backward "a-zA-Z0-9_")
3340 (let* ((start (point))
3341 (name (progn (skip-chars-forward "a-zA-Z0-9_")
3342 (buffer-substring start (point))))
3343 class)
3344 (list class name))))
3345
3346
3347 (defun ebrowse-tags-choose-class (tree header name initial-class-name)
3348 "Read a class name for a member from the minibuffer.
3349 TREE is the class tree we operate on.
3350 HEADER is its header structure.
3351 NAME is the name of the member.
3352 INITIAL-CLASS-NAME is an initial class name to insert in the minibuffer.
3353 Value is a list (TREE ACCESSOR MEMBER) for the member."
3354 (let ((alist (or (ebrowse-class-alist-for-member header name)
3355 (error "No classes with member `%s' found" name))))
3356 (ebrowse-ignoring-completion-case
3357 (if (null (second alist))
3358 (cdr (first alist))
3359 (push ?\? unread-command-events)
3360 (cdr (assoc (completing-read "In class: "
3361 alist nil t initial-class-name)
3362 alist))))))
3363
3364
3365 (defun* ebrowse-tags-view/find-member-decl/defn
3366 (prefix &key view definition member-name)
3367 "If VIEW is t, view, else find an occurrence of MEMBER-NAME.
3368
3369 If DEFINITION is t, find or view the member definition else its
3370 declaration. This function reads the member's name from the
3371 current buffer like FIND-TAG. It then prepares a completion list
3372 of all classes containing a member with the given name and lets
3373 the user choose the class to use. As a last step, a tags search
3374 is performed that positions point on the member declaration or
3375 definition."
3376 (multiple-value-bind
3377 (tree header tree-buffer) (values-list (ebrowse-choose-tree))
3378 (unless tree (error "No class tree"))
3379 (let* ((marker (point-marker))
3380 class-name
3381 (name member-name)
3382 info)
3383 (unless name
3384 (multiple-value-setq (class-name name)
3385 (values-list
3386 (ebrowse-tags-read-name
3387 header
3388 (concat (if view "View" "Find") " member "
3389 (if definition "definition" "declaration") ": ")))))
3390 (setq info (ebrowse-tags-choose-class tree header name class-name))
3391 (ebrowse-push-position marker info)
3392 ;; Goto the occurrence of the member
3393 (ebrowse-view/find-member-declaration/definition
3394 prefix view definition info
3395 header
3396 (ebrowse-value-in-buffer 'ebrowse--tags-file-name tree-buffer))
3397 ;; Record position jumped to
3398 (ebrowse-push-position (point-marker) info t))))
3399
3400
3401 ;;;###autoload
3402 (defun ebrowse-tags-view-declaration ()
3403 "View declaration of member at point."
3404 (interactive)
3405 (ebrowse-tags-view/find-member-decl/defn 0 :view t :definition nil))
3406
3407
3408 ;;;###autoload
3409 (defun ebrowse-tags-find-declaration ()
3410 "Find declaration of member at point."
3411 (interactive)
3412 (ebrowse-tags-view/find-member-decl/defn 0 :view nil :definition nil))
3413
3414
3415 ;;;###autoload
3416 (defun ebrowse-tags-view-definition ()
3417 "View definition of member at point."
3418 (interactive)
3419 (ebrowse-tags-view/find-member-decl/defn 0 :view t :definition t))
3420
3421
3422 ;;;###autoload
3423 (defun ebrowse-tags-find-definition ()
3424 "Find definition of member at point."
3425 (interactive)
3426 (ebrowse-tags-view/find-member-decl/defn 0 :view nil :definition t))
3427
3428
3429 (defun ebrowse-tags-view-declaration-other-window ()
3430 "View declaration of member at point in other window."
3431 (interactive)
3432 (ebrowse-tags-view/find-member-decl/defn 4 :view t :definition nil))
3433
3434
3435 ;;;###autoload
3436 (defun ebrowse-tags-find-declaration-other-window ()
3437 "Find declaration of member at point in other window."
3438 (interactive)
3439 (ebrowse-tags-view/find-member-decl/defn 4 :view nil :definition nil))
3440
3441
3442 ;;;###autoload
3443 (defun ebrowse-tags-view-definition-other-window ()
3444 "View definition of member at point in other window."
3445 (interactive)
3446 (ebrowse-tags-view/find-member-decl/defn 4 :view t :definition t))
3447
3448
3449 ;;;###autoload
3450 (defun ebrowse-tags-find-definition-other-window ()
3451 "Find definition of member at point in other window."
3452 (interactive)
3453 (ebrowse-tags-view/find-member-decl/defn 4 :view nil :definition t))
3454
3455
3456 (defun ebrowse-tags-view-declaration-other-frame ()
3457 "View definition of member at point in other frame."
3458 (interactive)
3459 (ebrowse-tags-view/find-member-decl/defn 5 :view t :definition nil))
3460
3461
3462 ;;;###autoload
3463 (defun ebrowse-tags-find-declaration-other-frame ()
3464 "Find definition of member at point in other frame."
3465 (interactive)
3466 (ebrowse-tags-view/find-member-decl/defn 5 :view nil :definition nil))
3467
3468
3469 ;;;###autoload
3470 (defun ebrowse-tags-view-definition-other-frame ()
3471 "View definition of member at point in other frame."
3472 (interactive)
3473 (ebrowse-tags-view/find-member-decl/defn 5 :view t :definition t))
3474
3475
3476 ;;;###autoload
3477 (defun ebrowse-tags-find-definition-other-frame ()
3478 "Find definition of member at point in other frame."
3479 (interactive)
3480 (ebrowse-tags-view/find-member-decl/defn 5 :view nil :definition t))
3481
3482
3483 (defun ebrowse-tags-select/create-member-buffer (tree-buffer info)
3484 "Select or create member buffer.
3485 TREE-BUFFER specifies the tree to use. INFO describes the member.
3486 It is a list (TREE ACCESSOR MEMBER)."
3487 (let ((buffer (get-buffer ebrowse-member-buffer-name)))
3488 (cond ((null buffer)
3489 (set-buffer tree-buffer)
3490 (switch-to-buffer (ebrowse-display-member-buffer
3491 (second info) nil (first info))))
3492 (t
3493 (switch-to-buffer buffer)
3494 (setq ebrowse--displayed-class (first info)
3495 ebrowse--accessor (second info)
3496 ebrowse--member-list (funcall ebrowse--accessor ebrowse--displayed-class))
3497 (ebrowse-redisplay-member-buffer)))
3498 (ebrowse-move-point-to-member (ebrowse-ms-name (third info)))))
3499
3500
3501 (defun ebrowse-tags-display-member-buffer (&optional fix-name)
3502 "Display a member buffer for a member.
3503 FIX-NAME non-nil means display the buffer for that member.
3504 Otherwise read a member name from point."
3505 (interactive)
3506 (multiple-value-bind
3507 (tree header tree-buffer) (values-list (ebrowse-choose-tree))
3508 (unless tree (error "No class tree"))
3509 (let* ((marker (point-marker)) class-name (name fix-name) info)
3510 (unless name
3511 (multiple-value-setq (class-name name)
3512 (values-list
3513 (ebrowse-tags-read-name header
3514 (concat "Find member list of: ")))))
3515 (setq info (ebrowse-tags-choose-class tree header name class-name))
3516 (ebrowse-push-position marker info)
3517 (ebrowse-tags-select/create-member-buffer tree-buffer info))))
3518
3519
3520 (defun ebrowse-list-of-matching-members (members regexp &optional name)
3521 "Return a list of members in table MEMBERS matching REGEXP or NAME.
3522 Both NAME and REGEXP may be nil in which case exact or regexp matches
3523 are not performed."
3524 (let (list)
3525 (when (or name regexp)
3526 (maphash #'(lambda (member-name info)
3527 (when (or (and name (string= name member-name))
3528 (and regexp (string-match regexp member-name)))
3529 (setq list (cons member-name list))))
3530 members))
3531 list))
3532
3533
3534 (defun ebrowse-tags-apropos ()
3535 "Display a list of members matching a regexp read from the minibuffer."
3536 (interactive)
3537 (let* ((buffer (or (ebrowse-choose-from-browser-buffers)
3538 (error "No tree buffer")))
3539 (header (ebrowse-value-in-buffer 'ebrowse--header buffer))
3540 (members (ebrowse-member-table header))
3541 temp-buffer-setup-hook
3542 (regexp (read-from-minibuffer "List members matching regexp: ")))
3543 (with-output-to-temp-buffer (concat "*Apropos Members*")
3544 (set-buffer standard-output)
3545 (erase-buffer)
3546 (insert "Members matching `" regexp "'\n\n")
3547 (loop for s in (ebrowse-list-of-matching-members members regexp) do
3548 (loop for info in (gethash s members) do
3549 (ebrowse-draw-file-member-info info))))))
3550
3551
3552 (defun ebrowse-tags-list-members-in-file ()
3553 "Display a list of members found in a file.
3554 The file name is read from the minibuffer."
3555 (interactive)
3556 (let* ((buffer (or (ebrowse-choose-from-browser-buffers)
3557 (error "No tree buffer")))
3558 (files (save-excursion (set-buffer buffer) (ebrowse-files-table)))
3559 (file (completing-read "List members in file: " files nil t))
3560 (header (ebrowse-value-in-buffer 'ebrowse--header buffer))
3561 temp-buffer-setup-hook
3562 (members (ebrowse-member-table header)))
3563 (with-output-to-temp-buffer (concat "*Members in file " file "*")
3564 (set-buffer standard-output)
3565 (maphash
3566 #'(lambda (member-name list)
3567 (loop for info in list
3568 as member = (third info)
3569 as class = (ebrowse-ts-class (first info))
3570 when (or (and (null (ebrowse-ms-file member))
3571 (string= (ebrowse-cs-file class) file))
3572 (string= file (ebrowse-ms-file member)))
3573 do (ebrowse-draw-file-member-info info "decl.")
3574 when (or (and (null (ebrowse-ms-definition-file member))
3575 (string= (ebrowse-cs-source-file class) file))
3576 (string= file (ebrowse-ms-definition-file member)))
3577 do (ebrowse-draw-file-member-info info "defn.")))
3578 members))))
3579
3580
3581 (defun* ebrowse-draw-file-member-info (info &optional (kind ""))
3582 "Display a line in the members info buffer.
3583 INFO describes the member. It has the form (TREE ACCESSOR MEMBER).
3584 TREE is the class of the member to display.
3585 ACCESSOR is the accessor symbol of its member list.
3586 MEMBER is the member structure.
3587 KIND is an additional string printed in the buffer."
3588 (let* ((tree (first info))
3589 (globals-p (ebrowse-globals-tree-p tree)))
3590 (unless globals-p
3591 (insert (ebrowse-cs-name (ebrowse-ts-class tree))))
3592 (insert "::" (ebrowse-ms-name (third info)))
3593 (indent-to 40)
3594 (insert kind)
3595 (indent-to 50)
3596 (insert (case (second info)
3597 ('ebrowse-ts-member-functions "member function")
3598 ('ebrowse-ts-member-variables "member variable")
3599 ('ebrowse-ts-static-functions "static function")
3600 ('ebrowse-ts-static-variables "static variable")
3601 ('ebrowse-ts-friends (if globals-p "define" "friend"))
3602 ('ebrowse-ts-types "type")
3603 (t "unknown"))
3604 "\n")))
3605
3606 (defvar ebrowse-last-completion nil
3607 "Text inserted by the last completion operation.")
3608
3609
3610 (defvar ebrowse-last-completion-start nil
3611 "String which was the basis for the last completion operation.")
3612
3613
3614 (defvar ebrowse-last-completion-location nil
3615 "Buffer position at which the last completion operation was initiated.")
3616
3617
3618 (defvar ebrowse-last-completion-obarray nil
3619 "Member used in last completion operation.")
3620
3621
3622 (make-variable-buffer-local 'ebrowse-last-completion-obarray)
3623 (make-variable-buffer-local 'ebrowse-last-completion-location)
3624 (make-variable-buffer-local 'ebrowse-last-completion)
3625 (make-variable-buffer-local 'ebrowse-last-completion-start)
3626
3627
3628 \f
3629 (defun ebrowse-some-member-table ()
3630 "Return a hash table containing all members of a tree.
3631 If there's only one tree loaded, use that. Otherwise let the
3632 use choose a tree."
3633 (let* ((buffers (ebrowse-known-class-trees-buffer-list))
3634 (buffer (cond ((and (first buffers) (not (second buffers)))
3635 (first buffers))
3636 (t (or (ebrowse-electric-choose-tree)
3637 (error "No tree buffer")))))
3638 (header (ebrowse-value-in-buffer 'ebrowse--header buffer)))
3639 (ebrowse-member-table header)))
3640
3641
3642 (defun ebrowse-cyclic-successor-in-string-list (string list)
3643 "Return the item following STRING in LIST.
3644 If STRING is the last element, return the first element as successor."
3645 (or (nth (1+ (ebrowse-position string list 'string=)) list)
3646 (first list)))
3647
3648 \f
3649 ;;; Symbol completion
3650
3651 ;;;###autoload
3652 (defun* ebrowse-tags-complete-symbol (prefix)
3653 "Perform completion on the C++ symbol preceding point.
3654 A second call of this function without changing point inserts the next match.
3655 A call with prefix PREFIX reads the symbol to insert from the minibuffer with
3656 completion."
3657 (interactive "P")
3658 (let* ((end (point))
3659 (begin (save-excursion (skip-chars-backward "a-zA-Z_0-9") (point)))
3660 (pattern (buffer-substring begin end))
3661 list completion)
3662 (cond
3663 ;; With prefix, read name from minibuffer with completion.
3664 (prefix
3665 (let* ((members (ebrowse-some-member-table))
3666 (completion (completing-read "Insert member: "
3667 members nil t pattern)))
3668 (when completion
3669 (setf ebrowse-last-completion-location nil)
3670 (delete-region begin end)
3671 (insert completion))))
3672 ;; If this function is called at the same point the last
3673 ;; expansion ended, insert the next expansion.
3674 ((eq (point) ebrowse-last-completion-location)
3675 (setf list (all-completions ebrowse-last-completion-start
3676 ebrowse-last-completion-obarray)
3677 completion (ebrowse-cyclic-successor-in-string-list
3678 ebrowse-last-completion list))
3679 (cond ((null completion)
3680 (error "No completion"))
3681 ((string= completion pattern)
3682 (error "No further completion"))
3683 (t
3684 (delete-region begin end)
3685 (insert completion)
3686 (setf ebrowse-last-completion completion
3687 ebrowse-last-completion-location (point)))))
3688 ;; First time the function is called at some position in the
3689 ;; buffer: Start new completion.
3690 (t
3691 (let* ((members (ebrowse-some-member-table))
3692 (completion (first (all-completions pattern members nil))))
3693 (cond ((eq completion t))
3694 ((null completion)
3695 (error "Can't find completion for `%s'" pattern))
3696 (t
3697 (delete-region begin end)
3698 (insert completion)
3699
3700 (setf ebrowse-last-completion-location (point)
3701 ebrowse-last-completion-start pattern
3702 ebrowse-last-completion completion
3703 ebrowse-last-completion-obarray members))))))))
3704
3705 \f
3706 ;;; Tags query replace & search
3707
3708 (defvar ebrowse-tags-loop-form ()
3709 "Form for `ebrowse-loop-continue'.
3710 Evaluated for each file in the tree. If it returns nil, proceed
3711 with the next file.")
3712
3713 (defvar ebrowse-tags-next-file-list ()
3714 "A list of files to be processed.")
3715
3716
3717 (defvar ebrowse-tags-next-file-path nil
3718 "The path relative to which files have to be searched.")
3719
3720
3721 (defvar ebrowse-tags-loop-last-file nil
3722 "The last file visited via `ebrowse-tags-loop'.")
3723
3724
3725 (defun ebrowse-tags-next-file (&optional initialize tree-buffer)
3726 "Select next file among files in current tag table.
3727 Non-nil argument INITIALIZE (prefix arg, if interactive) initializes
3728 to the beginning of the list of files in the tag table.
3729 TREE-BUFFER specifies the class tree we operate on."
3730 (interactive "P")
3731 ;; Call with INITIALIZE non-nil initializes the files list.
3732 ;; If more than one tree buffer is loaded, let the user choose
3733 ;; on which tree (s)he wants to operate.
3734 (when initialize
3735 (let ((buffer (or tree-buffer (ebrowse-choose-from-browser-buffers))))
3736 (save-excursion
3737 (set-buffer buffer)
3738 (setq ebrowse-tags-next-file-list
3739 (ebrowse-files-list (ebrowse-marked-classes-p))
3740 ebrowse-tags-loop-last-file
3741 nil
3742 ebrowse-tags-next-file-path
3743 (file-name-directory ebrowse--tags-file-name)))))
3744 ;; End of the loop if the stack of files is empty.
3745 (unless ebrowse-tags-next-file-list
3746 (error "All files processed"))
3747 ;; ebrowse-tags-loop-last-file is the last file that was visited due
3748 ;; to a call to BROWSE-LOOP (see below). If that file is still
3749 ;; in memory, and it wasn't modified, throw its buffer away to
3750 ;; prevent cluttering up the buffer list.
3751 (when ebrowse-tags-loop-last-file
3752 (let ((buffer (get-file-buffer ebrowse-tags-loop-last-file)))
3753 (when (and buffer
3754 (not (buffer-modified-p buffer)))
3755 (kill-buffer buffer))))
3756 ;; Remember this buffer file name for later deletion, if it
3757 ;; wasn't visited by other means.
3758 (let ((file (expand-file-name (car ebrowse-tags-next-file-list)
3759 ebrowse-tags-next-file-path)))
3760 (setq ebrowse-tags-loop-last-file (if (get-file-buffer file) nil file))
3761 ;; Find the file and pop the file list. Pop has to be done
3762 ;; before the file is loaded because FIND-FILE might encounter
3763 ;; an error, and we want to be able to proceed with the next
3764 ;; file in this case.
3765 (pop ebrowse-tags-next-file-list)
3766 (find-file file)))
3767
3768
3769 ;;;###autoload
3770 (defun ebrowse-tags-loop-continue (&optional first-time tree-buffer)
3771 "Repeat last operation on files in tree.
3772 FIRST-TIME non-nil means this is not a repetition, but the first time.
3773 TREE-BUFFER if indirectly specifies which files to loop over."
3774 (interactive)
3775 (when first-time
3776 (ebrowse-tags-next-file first-time tree-buffer)
3777 (goto-char (point-min)))
3778 (while (not (eval ebrowse-tags-loop-form))
3779 (ebrowse-tags-next-file)
3780 (message "Scanning file `%s'..." buffer-file-name)
3781 (goto-char (point-min))))
3782
3783
3784 ;;;###autoload
3785 (defun ebrowse-tags-search (regexp)
3786 "Search for REGEXP in all files in a tree.
3787 If marked classes exist, process marked classes, only.
3788 If regular expression is nil, repeat last search."
3789 (interactive "sTree search (regexp): ")
3790 (if (and (string= regexp "")
3791 (eq (car ebrowse-tags-loop-form) 're-search-forward))
3792 (ebrowse-tags-loop-continue)
3793 (setq ebrowse-tags-loop-form (list 're-search-forward regexp nil t))
3794 (ebrowse-tags-loop-continue 'first-time)))
3795
3796
3797 ;;;###autoload
3798 (defun ebrowse-tags-query-replace (from to)
3799 "Query replace FROM with TO in all files of a class tree.
3800 With prefix arg, process files of marked classes only."
3801 (interactive
3802 "sTree query replace (regexp): \nsTree query replace %s by: ")
3803 (setq ebrowse-tags-loop-form
3804 (list 'and (list 'save-excursion
3805 (list 're-search-forward from nil t))
3806 (list 'not (list 'perform-replace from to t t nil))))
3807 (ebrowse-tags-loop-continue 'first-time))
3808
3809
3810 ;;;###autoload
3811 (defun ebrowse-tags-search-member-use (&optional fix-name)
3812 "Search for call sites of a member.
3813 If FIX-NAME is specified, search uses of that member.
3814 Otherwise, read a member name from the minibuffer.
3815 Searches in all files mentioned in a class tree for something that
3816 looks like a function call to the member."
3817 (interactive)
3818 ;; Choose the tree to use if there is more than one.
3819 (multiple-value-bind (tree header tree-buffer)
3820 (values-list (ebrowse-choose-tree))
3821 (unless tree
3822 (error "No class tree"))
3823 ;; Get the member name NAME (class-name is ignored).
3824 (let ((name fix-name) class-name regexp)
3825 (unless name
3826 (multiple-value-setq (class-name name)
3827 (values-list (ebrowse-tags-read-name header "Find calls of: "))))
3828 ;; Set tags loop form to search for member and begin loop.
3829 (setq regexp (concat "\\<" name "[ \t]*(")
3830 ebrowse-tags-loop-form (list 're-search-forward regexp nil t))
3831 (ebrowse-tags-loop-continue 'first-time tree-buffer))))
3832
3833
3834 \f
3835 ;;; Tags position management
3836
3837 ;;; Structures of this kind are the elements of the position stack.
3838
3839 (defstruct (ebrowse-position (:type vector) :named)
3840 file-name ; in which file
3841 point ; point in file
3842 target ; t if target of a jump
3843 info) ; (CLASS FUNC MEMBER) jumped to
3844
3845
3846 (defvar ebrowse-position-stack ()
3847 "Stack of `ebrowse-position' structured.")
3848
3849
3850 (defvar ebrowse-position-index 0
3851 "Current position in position stack.")
3852
3853
3854 (defun ebrowse-position-name (position)
3855 "Return an identifying string for POSITION.
3856 The string is printed in the electric position list buffer."
3857 (let ((info (ebrowse-position-info position)))
3858 (concat (if (ebrowse-position-target position) "at " "to ")
3859 (ebrowse-cs-name (ebrowse-ts-class (first info)))
3860 "::" (ebrowse-ms-name (third info)))))
3861
3862
3863 (defun ebrowse-view/find-position (position &optional view)
3864 "Position point on POSITION.
3865 If VIEW is non-nil, view the position, otherwise find it."
3866 (cond ((not view)
3867 (find-file (ebrowse-position-file-name position))
3868 (goto-char (ebrowse-position-point position)))
3869 (t
3870 (unwind-protect
3871 (progn
3872 (push (function
3873 (lambda ()
3874 (goto-char (ebrowse-position-point position))))
3875 view-mode-hook)
3876 (view-file (ebrowse-position-file-name position)))
3877 (pop view-mode-hook)))))
3878
3879
3880 (defun ebrowse-push-position (marker info &optional target)
3881 "Push current position on position stack.
3882 MARKER is the marker to remember as position.
3883 INFO is a list (CLASS FUNC MEMBER) specifying what we jumped to.
3884 TARGET non-nil means we performed a jump.
3885 Positions in buffers that have no file names are not saved."
3886 (when (buffer-file-name (marker-buffer marker))
3887 (let ((too-much (- (length ebrowse-position-stack)
3888 ebrowse-max-positions)))
3889 ;; Do not let the stack grow to infinity.
3890 (when (plusp too-much)
3891 (setq ebrowse-position-stack
3892 (butlast ebrowse-position-stack too-much)))
3893 ;; Push the position.
3894 (push (make-ebrowse-position
3895 :file-name (buffer-file-name (marker-buffer marker))
3896 :point (marker-position marker)
3897 :target target
3898 :info info)
3899 ebrowse-position-stack))))
3900
3901
3902 (defun ebrowse-move-in-position-stack (increment)
3903 "Move by INCREMENT in the position stack."
3904 (let ((length (length ebrowse-position-stack)))
3905 (when (zerop length)
3906 (error "No positions remembered"))
3907 (setq ebrowse-position-index
3908 (mod (+ increment ebrowse-position-index) length))
3909 (message "Position %d of %d " ebrowse-position-index length)
3910 (ebrowse-view/find-position (nth ebrowse-position-index
3911 ebrowse-position-stack))))
3912
3913
3914 ;;;###autoload
3915 (defun ebrowse-back-in-position-stack (arg)
3916 "Move backward in the position stack.
3917 Prefix arg ARG says how much."
3918 (interactive "p")
3919 (ebrowse-move-in-position-stack (max 1 arg)))
3920
3921
3922 ;;;###autoload
3923 (defun ebrowse-forward-in-position-stack (arg)
3924 "Move forward in the position stack.
3925 Prefix arg ARG says how much."
3926 (interactive "p")
3927 (ebrowse-move-in-position-stack (min -1 (- arg))))
3928
3929
3930 \f
3931 ;;; Electric position list
3932
3933 (defvar ebrowse-electric-position-mode-map ()
3934 "Keymap used in electric position stack window.")
3935
3936
3937 (defvar ebrowse-electric-position-mode-hook nil
3938 "If non-nil, its value is called by `ebrowse-electric-position-mode'.")
3939
3940
3941 (unless ebrowse-electric-position-mode-map
3942 (let ((map (make-keymap))
3943 (submap (make-keymap)))
3944 (setq ebrowse-electric-position-mode-map map)
3945 (fillarray (car (cdr map)) 'ebrowse-electric-position-undefined)
3946 (fillarray (car (cdr submap)) 'ebrowse-electric-position-undefined)
3947 (define-key map "\e" submap)
3948 (define-key map "\C-z" 'suspend-frame)
3949 (define-key map "\C-h" 'Helper-help)
3950 (define-key map "?" 'Helper-describe-bindings)
3951 (define-key map "\C-c" nil)
3952 (define-key map "\C-c\C-c" 'ebrowse-electric-position-quit)
3953 (define-key map "q" 'ebrowse-electric-position-quit)
3954 (define-key map " " 'ebrowse-electric-select-position)
3955 (define-key map "\C-l" 'recenter)
3956 (define-key map "\C-u" 'universal-argument)
3957 (define-key map "\C-p" 'previous-line)
3958 (define-key map "\C-n" 'next-line)
3959 (define-key map "p" 'previous-line)
3960 (define-key map "n" 'next-line)
3961 (define-key map "v" 'ebrowse-electric-view-position)
3962 (define-key map "\C-v" 'scroll-up)
3963 (define-key map "\ev" 'scroll-down)
3964 (define-key map "\e\C-v" 'scroll-other-window)
3965 (define-key map "\e>" 'end-of-buffer)
3966 (define-key map "\e<" 'beginning-of-buffer)
3967 (define-key map "\e>" 'end-of-buffer)))
3968
3969 (put 'ebrowse-electric-position-mode 'mode-class 'special)
3970 (put 'ebrowse-electric-position-undefined 'suppress-keymap t)
3971
3972
3973 (defun ebrowse-electric-position-mode ()
3974 "Mode for electric position buffers.
3975 Runs the hook `ebrowse-electric-position-mode-hook'."
3976 (kill-all-local-variables)
3977 (use-local-map ebrowse-electric-position-mode-map)
3978 (setq mode-name "Electric Position Menu"
3979 mode-line-buffer-identification "Electric Position Menu")
3980 (when (memq 'mode-name mode-line-format)
3981 (setq mode-line-format (copy-sequence mode-line-format))
3982 (setcar (memq 'mode-name mode-line-format) "Positions"))
3983 (make-local-variable 'Helper-return-blurb)
3984 (setq Helper-return-blurb "return to buffer editing"
3985 truncate-lines t
3986 buffer-read-only t
3987 major-mode 'ebrowse-electric-position-mode)
3988 (run-mode-hooks 'ebrowse-electric-position-mode-hook))
3989
3990
3991 (defun ebrowse-draw-position-buffer ()
3992 "Display positions in buffer *Positions*."
3993 (set-buffer (get-buffer-create "*Positions*"))
3994 (setq buffer-read-only nil)
3995 (erase-buffer)
3996 (insert "File Point Description\n"
3997 "---- ----- -----------\n")
3998 (dolist (position ebrowse-position-stack)
3999 (insert (file-name-nondirectory (ebrowse-position-file-name position)))
4000 (indent-to 15)
4001 (insert (int-to-string (ebrowse-position-point position)))
4002 (indent-to 22)
4003 (insert (ebrowse-position-name position) "\n"))
4004 (setq buffer-read-only t))
4005
4006
4007 ;;;###autoload
4008 (defun ebrowse-electric-position-menu ()
4009 "List positions in the position stack in an electric buffer."
4010 (interactive)
4011 (unless ebrowse-position-stack
4012 (error "No positions remembered"))
4013 (let (select buffer window)
4014 (save-window-excursion
4015 (save-window-excursion (ebrowse-draw-position-buffer))
4016 (setq window (Electric-pop-up-window "*Positions*")
4017 buffer (window-buffer window))
4018 (shrink-window-if-larger-than-buffer window)
4019 (unwind-protect
4020 (progn
4021 (set-buffer buffer)
4022 (ebrowse-electric-position-mode)
4023 (setq select
4024 (catch 'ebrowse-electric-select-position
4025 (message "<<< Press Space to bury the list >>>")
4026 (let ((first (progn (goto-char (point-min))
4027 (forward-line 2)
4028 (point)))
4029 (last (progn (goto-char (point-max))
4030 (forward-line -1)
4031 (point)))
4032 (goal-column 0))
4033 (goto-char first)
4034 (Electric-command-loop 'ebrowse-electric-select-position
4035 nil t
4036 'ebrowse-electric-position-looper
4037 (cons first last))))))
4038 (set-buffer buffer)
4039 (bury-buffer buffer)
4040 (message nil)))
4041 (when select
4042 (set-buffer buffer)
4043 (ebrowse-electric-find-position select))
4044 (kill-buffer buffer)))
4045
4046
4047 (defun ebrowse-electric-position-looper (state condition)
4048 "Prevent moving point on invalid lines.
4049 Called from `Electric-command-loop'. See there for the meaning
4050 of STATE and CONDITION."
4051 (cond ((and condition
4052 (not (memq (car condition) '(buffer-read-only
4053 end-of-buffer
4054 beginning-of-buffer))))
4055 (signal (car condition) (cdr condition)))
4056 ((< (point) (car state))
4057 (goto-char (point-min))
4058 (forward-line 2))
4059 ((> (point) (cdr state))
4060 (goto-char (point-max))
4061 (forward-line -1)
4062 (if (pos-visible-in-window-p (point-max))
4063 (recenter -1)))))
4064
4065
4066 (defun ebrowse-electric-position-undefined ()
4067 "Function called for undefined keys."
4068 (interactive)
4069 (message "Type C-h for help, ? for commands, q to quit, Space to execute")
4070 (sit-for 4))
4071
4072
4073 (defun ebrowse-electric-position-quit ()
4074 "Leave the electric position list."
4075 (interactive)
4076 (throw 'ebrowse-electric-select-position nil))
4077
4078
4079 (defun ebrowse-electric-select-position ()
4080 "Select a position from the list."
4081 (interactive)
4082 (throw 'ebrowse-electric-select-position (point)))
4083
4084
4085 (defun ebrowse-electric-find-position (point &optional view)
4086 "View/find what is described by the line at POINT.
4087 If VIEW is non-nil, view else find source files."
4088 (let ((index (- (count-lines (point-min) point) 2)))
4089 (ebrowse-view/find-position (nth index
4090 ebrowse-position-stack) view)))
4091
4092
4093 (defun ebrowse-electric-view-position ()
4094 "View the position described by the line point is in."
4095 (interactive)
4096 (ebrowse-electric-find-position (point) t))
4097
4098
4099 \f
4100 ;;; Saving trees to disk
4101
4102 (defun ebrowse-write-file-hook-fn ()
4103 "Write current buffer as a class tree.
4104 Installed on `local-write-file-hooks'."
4105 (ebrowse-save-tree)
4106 t)
4107
4108
4109 ;;;###autoload
4110 (defun ebrowse-save-tree ()
4111 "Save current tree in same file it was loaded from."
4112 (interactive)
4113 (ebrowse-save-tree-as (or buffer-file-name ebrowse--tags-file-name)))
4114
4115
4116 ;;;###autoload
4117 (defun ebrowse-save-tree-as (&optional file-name)
4118 "Write the current tree data structure to a file.
4119 Read the file name from the minibuffer if interactive.
4120 Otherwise, FILE-NAME specifies the file to save the tree in."
4121 (interactive "FSave tree as: ")
4122 (let ((temp-buffer (get-buffer-create "*Tree Output"))
4123 (old-standard-output standard-output)
4124 (header (copy-ebrowse-hs ebrowse--header))
4125 (tree ebrowse--tree))
4126 (unwind-protect
4127 (save-excursion
4128 (set-buffer (setq standard-output temp-buffer))
4129 (erase-buffer)
4130 (setf (ebrowse-hs-member-table header) nil)
4131 (insert (prin1-to-string header) " ")
4132 (mapc 'ebrowse-save-class tree)
4133 (write-file file-name)
4134 (message "Tree written to file `%s'" file-name))
4135 (kill-buffer temp-buffer)
4136 (set-buffer-modified-p nil)
4137 (ebrowse-update-tree-buffer-mode-line)
4138 (setq standard-output old-standard-output))))
4139
4140
4141 (defun ebrowse-save-class (class)
4142 "Write single class CLASS to current buffer."
4143 (message "%s..." (ebrowse-cs-name (ebrowse-ts-class class)))
4144 (insert "[ebrowse-ts ")
4145 (prin1 (ebrowse-ts-class class)) ;class name
4146 (insert "(") ;list of subclasses
4147 (mapc 'ebrowse-save-class (ebrowse-ts-subclasses class))
4148 (insert ")")
4149 (dolist (func ebrowse-member-list-accessors)
4150 (prin1 (funcall func class))
4151 (insert "\n"))
4152 (insert "()") ;base-classes slot
4153 (prin1 (ebrowse-ts-mark class))
4154 (insert "]\n"))
4155
4156
4157 \f
4158 ;;; Statistics
4159
4160 ;;;###autoload
4161 (defun ebrowse-statistics ()
4162 "Display statistics for a class tree."
4163 (interactive)
4164 (let ((tree-file (buffer-file-name))
4165 temp-buffer-setup-hook)
4166 (with-output-to-temp-buffer "*Tree Statistics*"
4167 (multiple-value-bind (classes member-functions member-variables
4168 static-functions static-variables)
4169 (values-list (ebrowse-gather-statistics))
4170 (set-buffer standard-output)
4171 (erase-buffer)
4172 (insert "STATISTICS FOR TREE " (or tree-file "unknown") ":\n\n")
4173 (ebrowse-print-statistics-line "Number of classes:" classes)
4174 (ebrowse-print-statistics-line "Number of member functions:"
4175 member-functions)
4176 (ebrowse-print-statistics-line "Number of member variables:"
4177 member-variables)
4178 (ebrowse-print-statistics-line "Number of static functions:"
4179 static-functions)
4180 (ebrowse-print-statistics-line "Number of static variables:"
4181 static-variables)))))
4182
4183
4184 (defun ebrowse-print-statistics-line (title value)
4185 "Print a line in the statistics buffer.
4186 TITLE is the title of the line, VALUE is a number to be printed
4187 after that."
4188 (insert title)
4189 (indent-to 40)
4190 (insert (format "%d\n" value)))
4191
4192
4193 (defun ebrowse-gather-statistics ()
4194 "Return statistics for a class tree.
4195 The result is a list (NUMBER-OF-CLASSES NUMBER-OF-MEMBER-FUNCTIONS
4196 NUMBER-OF-INSTANCE-VARIABLES NUMBER-OF-STATIC-FUNCTIONS
4197 NUMBER-OF-STATIC-VARIABLES:"
4198 (let ((classes 0) (member-functions 0) (member-variables 0)
4199 (static-functions 0) (static-variables 0))
4200 (ebrowse-for-all-trees (tree ebrowse--tree-obarray)
4201 (incf classes)
4202 (incf member-functions (length (ebrowse-ts-member-functions tree)))
4203 (incf member-variables (length (ebrowse-ts-member-variables tree)))
4204 (incf static-functions (length (ebrowse-ts-static-functions tree)))
4205 (incf static-variables (length (ebrowse-ts-static-variables tree))))
4206 (list classes member-functions member-variables
4207 static-functions static-variables)))
4208
4209
4210 \f
4211 ;;; Global key bindings
4212
4213 ;;; The following can be used to bind key sequences starting with
4214 ;;; prefix `\C-c\C-m' to browse commands.
4215
4216 (defvar ebrowse-global-map nil
4217 "*Keymap for Ebrowse commands.")
4218
4219
4220 (defvar ebrowse-global-prefix-key "\C-c\C-m"
4221 "Prefix key for Ebrowse commands.")
4222
4223
4224 (defvar ebrowse-global-submap-4 nil
4225 "Keymap used for `ebrowse-global-prefix' followed by `4'.")
4226
4227
4228 (defvar ebrowse-global-submap-5 nil
4229 "Keymap used for `ebrowse-global-prefix' followed by `5'.")
4230
4231
4232 (unless ebrowse-global-map
4233 (setq ebrowse-global-map (make-sparse-keymap))
4234 (setq ebrowse-global-submap-4 (make-sparse-keymap))
4235 (setq ebrowse-global-submap-5 (make-sparse-keymap))
4236 (define-key ebrowse-global-map "a" 'ebrowse-tags-apropos)
4237 (define-key ebrowse-global-map "b" 'ebrowse-pop-to-browser-buffer)
4238 (define-key ebrowse-global-map "-" 'ebrowse-back-in-position-stack)
4239 (define-key ebrowse-global-map "+" 'ebrowse-forward-in-position-stack)
4240 (define-key ebrowse-global-map "l" 'ebrowse-tags-list-members-in-file)
4241 (define-key ebrowse-global-map "m" 'ebrowse-tags-display-member-buffer)
4242 (define-key ebrowse-global-map "n" 'ebrowse-tags-next-file)
4243 (define-key ebrowse-global-map "p" 'ebrowse-electric-position-menu)
4244 (define-key ebrowse-global-map "s" 'ebrowse-tags-search)
4245 (define-key ebrowse-global-map "u" 'ebrowse-tags-search-member-use)
4246 (define-key ebrowse-global-map "v" 'ebrowse-tags-view-definition)
4247 (define-key ebrowse-global-map "V" 'ebrowse-tags-view-declaration)
4248 (define-key ebrowse-global-map "%" 'ebrowse-tags-query-replace)
4249 (define-key ebrowse-global-map "." 'ebrowse-tags-find-definition)
4250 (define-key ebrowse-global-map "f" 'ebrowse-tags-find-definition)
4251 (define-key ebrowse-global-map "F" 'ebrowse-tags-find-declaration)
4252 (define-key ebrowse-global-map "," 'ebrowse-tags-loop-continue)
4253 (define-key ebrowse-global-map " " 'ebrowse-electric-buffer-list)
4254 (define-key ebrowse-global-map "\t" 'ebrowse-tags-complete-symbol)
4255 (define-key ebrowse-global-map "4" ebrowse-global-submap-4)
4256 (define-key ebrowse-global-submap-4 "." 'ebrowse-tags-find-definition-other-window)
4257 (define-key ebrowse-global-submap-4 "f" 'ebrowse-tags-find-definition-other-window)
4258 (define-key ebrowse-global-submap-4 "v" 'ebrowse-tags-find-declaration-other-window)
4259 (define-key ebrowse-global-submap-4 "F" 'ebrowse-tags-view-definition-other-window)
4260 (define-key ebrowse-global-submap-4 "V" 'ebrowse-tags-view-declaration-other-window)
4261 (define-key ebrowse-global-map "5" ebrowse-global-submap-5)
4262 (define-key ebrowse-global-submap-5 "." 'ebrowse-tags-find-definition-other-frame)
4263 (define-key ebrowse-global-submap-5 "f" 'ebrowse-tags-find-definition-other-frame)
4264 (define-key ebrowse-global-submap-5 "v" 'ebrowse-tags-find-declaration-other-frame)
4265 (define-key ebrowse-global-submap-5 "F" 'ebrowse-tags-view-definition-other-frame)
4266 (define-key ebrowse-global-submap-5 "V" 'ebrowse-tags-view-declaration-other-frame)
4267 (define-key global-map ebrowse-global-prefix-key ebrowse-global-map))
4268
4269
4270 \f
4271 ;;; Electric C++ browser buffer menu
4272
4273 ;;; Electric buffer menu customization to display only some buffers
4274 ;;; (in this case Tree buffers). There is only one problem with this:
4275 ;;; If the very first character typed in the buffer menu is a space,
4276 ;;; this will select the buffer from which the buffer menu was
4277 ;;; invoked. But this buffer is not displayed in the buffer list if
4278 ;;; it isn't a tree buffer. I therefore let the buffer menu command
4279 ;;; loop read the command `p' via `unread-command-char'. This command
4280 ;;; has no effect since we are on the first line of the buffer.
4281
4282 (defvar electric-buffer-menu-mode-hook nil)
4283
4284
4285 (defun ebrowse-hack-electric-buffer-menu ()
4286 "Hack the electric buffer menu to display browser buffers."
4287 (let (non-empty)
4288 (unwind-protect
4289 (save-excursion
4290 (setq buffer-read-only nil)
4291 (goto-char 1)
4292 (forward-line 2)
4293 (while (not (eobp))
4294 (let ((b (Buffer-menu-buffer nil)))
4295 (if (or (ebrowse-buffer-p b)
4296 (string= (buffer-name b) "*Apropos Members*"))
4297 (progn (forward-line 1)
4298 (setq non-empty t))
4299 (delete-region (point)
4300 (save-excursion (end-of-line)
4301 (min (point-max)
4302 (1+ (point)))))))))
4303 (unless non-empty
4304 (error "No tree buffers"))
4305 (setf unread-command-events (listify-key-sequence "p"))
4306 (shrink-window-if-larger-than-buffer (selected-window))
4307 (setq buffer-read-only t))))
4308
4309
4310 (defun ebrowse-select-1st-to-9nth ()
4311 "Select the nth entry in the list by the keys 1..9."
4312 (interactive)
4313 (let* ((maxlin (count-lines (point-min) (point-max)))
4314 (n (min maxlin (+ 2 (string-to-number (this-command-keys))))))
4315 (goto-char (point-min))
4316 (forward-line (1- n))
4317 (throw 'electric-buffer-menu-select (point))))
4318
4319
4320 (defun ebrowse-install-1-to-9-keys ()
4321 "Define keys 1..9 to select the 1st to 9nth entry in the list."
4322 (dotimes (i 9)
4323 (define-key (current-local-map) (char-to-string (+ i ?1))
4324 'ebrowse-select-1st-to-9nth)))
4325
4326
4327 (defun ebrowse-electric-buffer-list ()
4328 "Display an electric list of Ebrowse buffers."
4329 (interactive)
4330 (unwind-protect
4331 (progn
4332 (add-hook 'electric-buffer-menu-mode-hook
4333 'ebrowse-hack-electric-buffer-menu)
4334 (add-hook 'electric-buffer-menu-mode-hook
4335 'ebrowse-install-1-to-9-keys)
4336 (call-interactively 'electric-buffer-list))
4337 (remove-hook 'electric-buffer-menu-mode-hook
4338 'ebrowse-hack-electric-buffer-menu)))
4339
4340 \f
4341 ;;; Mouse support
4342
4343 (defun ebrowse-mouse-find-member (event)
4344 "Find the member clicked on in another frame.
4345 EVENT is a mouse button event."
4346 (interactive "e")
4347 (mouse-set-point event)
4348 (let (start name)
4349 (save-excursion
4350 (skip-chars-backward "a-zA-Z0-9_")
4351 (setq start (point))
4352 (skip-chars-forward "a-zA-Z0-9_")
4353 (setq name (buffer-substring start (point))))
4354 (ebrowse-tags-view/find-member-decl/defn
4355 5 :view nil :definition t :member-name name)))
4356
4357
4358 (defun ebrowse-popup-menu (menu event)
4359 "Pop up MENU and perform an action if something was selected.
4360 EVENT is the mouse event."
4361 (save-selected-window
4362 (select-window (posn-window (event-start event)))
4363 (let ((selection (x-popup-menu event menu)) binding)
4364 (while selection
4365 (setq binding (lookup-key (or binding menu) (vector (car selection)))
4366 selection (cdr selection)))
4367 (when binding
4368 (call-interactively binding)))))
4369
4370
4371 (easy-menu-define
4372 ebrowse-tree-buffer-class-object-menu ebrowse-tree-mode-map
4373 "Object menu for classes in the tree buffer"
4374 '("Class"
4375 ["Functions" ebrowse-tree-command:show-member-functions
4376 :help "Display a list of member functions"
4377 :active t]
4378 ["Variables" ebrowse-tree-command:show-member-variables
4379 :help "Display a list of member variables"
4380 :active t]
4381 ["Static Functions" ebrowse-tree-command:show-static-member-functions
4382 :help "Display a list of static member functions"
4383 :active t]
4384 ["Static Variables" ebrowse-tree-command:show-static-member-variables
4385 :help "Display a list of static member variables"
4386 :active t]
4387 ["Friends/ Defines" ebrowse-tree-command:show-friends
4388 :help "Display a list of friends of a class"
4389 :active t]
4390 ["Types" ebrowse-tree-command:show-types
4391 :help "Display a list of types defined in a class"
4392 :active t]
4393 "-----------------"
4394 ["View" ebrowse-view-class-declaration
4395 :help "View class declaration"
4396 :active (eq (get-text-property (point) 'ebrowse-what) 'class-name)]
4397 ["Find" ebrowse-find-class-declaration
4398 :help "Find class declaration in file"
4399 :active (eq (get-text-property (point) 'ebrowse-what) 'class-name)]
4400 "-----------------"
4401 ["Mark" ebrowse-toggle-mark-at-point
4402 :help "Mark class point is on"
4403 :active (eq (get-text-property (point) 'ebrowse-what) 'class-name)]
4404 "-----------------"
4405 ["Collapse" ebrowse-collapse-branch
4406 :help "Collapse subtree under class point is on"
4407 :active (eq (get-text-property (point) 'ebrowse-what) 'class-name)]
4408 ["Expand" ebrowse-expand-branch
4409 :help "Expand subtree under class point is on"
4410 :active (eq (get-text-property (point) 'ebrowse-what) 'class-name)]))
4411
4412
4413 (easy-menu-define
4414 ebrowse-tree-buffer-object-menu ebrowse-tree-mode-map
4415 "Object menu for tree buffers"
4416 '("Ebrowse"
4417 ["Filename Display" ebrowse-toggle-file-name-display
4418 :help "Toggle display of source files names"
4419 :style toggle
4420 :selected ebrowse--show-file-names-flag
4421 :active t]
4422 ["Tree Indentation" ebrowse-set-tree-indentation
4423 :help "Set the tree's indentation"
4424 :active t]
4425 ["Unmark All Classes" ebrowse-mark-all-classes
4426 :help "Unmark all classes in the class tree"
4427 :active t]
4428 ["Expand All" ebrowse-expand-all
4429 :help "Expand all subtrees in the class tree"
4430 :active t]
4431 ["Statistics" ebrowse-statistics
4432 :help "Show a buffer with class hierarchy statistics"
4433 :active t]
4434 ["Find Class" ebrowse-read-class-name-and-go
4435 :help "Find a class in the tree"
4436 :active t]
4437 ["Member Buffer" ebrowse-pop/switch-to-member-buffer-for-same-tree
4438 :help "Show a member buffer for this class tree"
4439 :active t]))
4440
4441
4442 (defun ebrowse-mouse-3-in-tree-buffer (event)
4443 "Perform mouse actions in tree buffers.
4444 EVENT is the mouse event."
4445 (interactive "e")
4446 (mouse-set-point event)
4447 (let* ((where (posn-point (event-start event)))
4448 (property (get-text-property where 'ebrowse-what)))
4449 (case (event-click-count event)
4450 (1
4451 (case property
4452 (class-name
4453 (ebrowse-popup-menu ebrowse-tree-buffer-class-object-menu event))
4454 (t
4455 (ebrowse-popup-menu ebrowse-tree-buffer-object-menu event)))))))
4456
4457
4458 (defun ebrowse-mouse-2-in-tree-buffer (event)
4459 "Perform mouse actions in tree buffers.
4460 EVENT is the mouse event."
4461 (interactive "e")
4462 (mouse-set-point event)
4463 (let* ((where (posn-point (event-start event)))
4464 (property (get-text-property where 'ebrowse-what)))
4465 (case (event-click-count event)
4466 (1 (case property
4467 (class-name
4468 (ebrowse-tree-command:show-member-functions)))))))
4469
4470
4471 (defun ebrowse-mouse-1-in-tree-buffer (event)
4472 "Perform mouse actions in tree buffers.
4473 EVENT is the mouse event."
4474 (interactive "e")
4475 (mouse-set-point event)
4476 (let* ((where (posn-point (event-start event)))
4477 (property (get-text-property where 'ebrowse-what)))
4478 (case (event-click-count event)
4479 (2 (case property
4480 (class-name
4481 (let ((collapsed (save-excursion (skip-chars-forward "^\r\n")
4482 (looking-at "\r"))))
4483 (ebrowse-collapse-fn (not collapsed))))
4484 (mark
4485 (ebrowse-toggle-mark-at-point 1)))))))
4486
4487
4488 \f
4489 (provide 'ebrowse)
4490
4491 ;; Local variables:
4492 ;; eval:(put 'ebrowse-output 'lisp-indent-hook 0)
4493 ;; eval:(put 'ebrowse-ignoring-completion-case 'lisp-indent-hook 0)
4494 ;; eval:(put 'ebrowse-save-selective 'lisp-indent-hook 0)
4495 ;; eval:(put 'ebrowse-for-all-trees 'lisp-indent-hook 1)
4496 ;; End:
4497
4498 ;; arch-tag: 4fa3c8bf-1771-479b-bcd7-b029c7c9677b
4499 ;;; ebrowse.el ends here