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