home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / browser2.zip / br-utils.el < prev    next >
Lisp/Scheme  |  1995-02-17  |  7KB  |  186 lines

  1. ;;; CLASS BROWSER FOR C++
  2. ;;; $Id: br-utils.el,v 3.1 1995/02/17 18:19:36 mmann Exp $
  3. ;;;
  4. ;;; **********************************************************************
  5. ;;; Copyright (C) 1993, 1994 Gerd Moellmann. All rights reserved.
  6. ;;; Altenbergstr. 6, D-40235 Duesseldorf, Germany
  7. ;;; 100025.3303@COMPUSERVE.COM
  8. ;;; Suggestions, comments and requests for improvements are welcome.
  9. ;;; **********************************************************************
  10. ;;;
  11. ;;; This version works with both Emacs version 18 and 19, and I want
  12. ;;; to keep it that way. It requires the CL-19 Common Lisp compatibility
  13. ;;; package for Emacs 18 and 19.
  14. ;;;
  15. ;;; This file contains utilities related to the class browser.
  16. ;;; 
  17.  
  18. ;; This file may be made part of the Emacs distribution at the option
  19. ;; of the FSF.
  20.  
  21. ;; This code is distributed in the hope that it will be useful,
  22. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  23. ;; accepts responsibility to anyone for the consequences of using it
  24. ;; or for whether it serves any particular purpose or works at all,
  25. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  26. ;; License for full details.
  27.  
  28. ;; Everyone is granted permission to copy, modify and redistribute
  29. ;; this code, but only under the conditions described in the
  30. ;; GNU Emacs General Public License.   A copy of this license is
  31. ;; supposed to have been given to you along with GNU Emacs so you
  32. ;; can know your rights and responsibilities.  It should be in a
  33. ;; file named COPYING.  Among other things, the copyright notice
  34. ;; and this notice must be preserved on all copies.
  35.  
  36. ;; To autoload this feature, include the following in your `.emacs':
  37. ;;
  38. ;; (require 'br-utils)
  39.  
  40.  
  41. ;;;
  42. ;;; Options.
  43. ;;;
  44.  
  45. (defvar browse-option-define-keys t
  46.   "*If set to T binds browser commands to key sequences with prefix
  47. `\C-cb'.")
  48.  
  49. (defvar browse-option-electric-buffer-list t
  50.   "*If set to T defines function `browse-electric-buffer-list' that 
  51. lists all browse buffers.")
  52.  
  53. (defvar browse-option-electric-buffer-key t
  54.   "*If set to T defines key `\C-bb' to `browse-electric-buffer-list'.")
  55.  
  56. (defvar browse-option-install-find-file-hook t
  57.   "*If T install a find file hook that automatically browses buffers
  58. that contain the browse file signature.")
  59.  
  60.  
  61. ;;;
  62. ;;; The following can be used to bind key sequences starting with
  63. ;;; prefix `\C-cb' to browse commands.
  64. ;;; 
  65.  
  66. (when browse-option-define-keys
  67.   (defvar browse-global-map ()
  68.     "Keymap used for \C-cb* sequences.")
  69.  
  70.   (unless browse-global-map
  71.     (let ((submap (make-sparse-keymap)))
  72.       (setq browse-global-map (make-sparse-keymap))
  73.       (define-key browse-global-map "a" 'browse-tags-apropos)
  74.       (define-key browse-global-map "b" 'browse-tags-back)
  75.       (define-key browse-global-map "f" 'browse-tags-forward)
  76.       (define-key browse-global-map "l" 'browse-tags-list)
  77.       (define-key browse-global-map "m" 'browse-tags-find-member-buffer)
  78.       (define-key browse-global-map "n" 'browse-next-file)
  79.       (define-key browse-global-map "p" 'browse-electric-position-list)
  80.       (define-key browse-global-map "s" 'browse-search)
  81.       (define-key browse-global-map "u" 'browse-search-member-usage)
  82.       (define-key browse-global-map "v" 'browse-tags-view)
  83.       (define-key browse-global-map "%" 'browse-query-replace)
  84.       (define-key browse-global-map "." 'browse-tags-find)
  85.       (define-key browse-global-map "," 'browse-loop)
  86.       (define-key browse-global-map "+" submap)
  87.       (define-key submap "r" 'browse-add-region)
  88.       (define-key submap "b" 'browse-add-buffer)
  89.       (define-key global-map "\C-cb" browse-global-map))))
  90.  
  91.  
  92. ;;;
  93. ;;; Electric buffer menu customization to display only some buffers
  94. ;;; (in this case Tree buffers).   There is only one problem with this:
  95. ;;; If the very first character typed in the buffer menu is a space,
  96. ;;; this will select the buffer from which the buffer menu was invoked.
  97. ;;; But this buffer is not displayed in the buffer list if it isn`t a tree
  98. ;;; buffer.    I therefore let the buffer menu command loop read the
  99. ;;; command `p' via `unread-command-char'.   This command has no effect
  100. ;;; since we are on the first line of the buffer.
  101. ;;; 
  102.  
  103. (if browse-option-electric-buffer-list
  104.     (progn
  105.       ;; No PROVIDE, no var for hook in there...
  106.       (if (eq system-type 'ms-dos)
  107.           (load "ebuff-me")
  108.         (load "ebuff-menu"))
  109.  
  110.       (defvar electric-buffer-menu-mode-hook nil)
  111.  
  112.       (defun browse-hack-electric-buffer-menu ()
  113.     (let (non-empty)
  114.       (unwind-protect
  115.           (save-excursion
  116.         (setq buffer-read-only nil)
  117.         (goto-char 1)
  118.         (forward-line 2)
  119.         (while (not (eobp))
  120.           (let ((b (Buffer-menu-buffer nil)))
  121.             (if (or (browse-buffer-p b)
  122.                 (string= (buffer-name b) "*Apropos Members*"))
  123.             (progn (forward-line 1) (setq non-empty t))
  124.               (delete-region (point)
  125.                      (save-excursion (end-of-line)
  126.                              (min (point-max)
  127.                               (1+ (point)))))))))
  128.       (unless non-empty
  129.         (error "No tree buffers."))
  130.       (setq unread-command-char ?p)
  131.       (shrink-window-if-larger-than-buffer
  132.        (selected-window))
  133.       (setq buffer-read-only t))))
  134.  
  135.       (defun browse-electric-quick-select ()
  136.     (interactive)
  137.     (let* ((maxlin (count-lines (point-min) (point-max)))
  138.            (n (min maxlin (+ 2 (string-to-int (this-command-keys))))))
  139.       (goto-line n)
  140.       (throw 'electric-buffer-menu-select (point))))
  141.  
  142.       (defun browse-electric-install-quick-keys ()
  143.     (dotimes (i 9)
  144.       (define-key (current-local-map) (char-to-string (+ i ?1))
  145.         'browse-electric-quick-select)))
  146.  
  147.       (defun browse-electric-buffer-list ()
  148.         (interactive)
  149.     (unwind-protect
  150.         (progn
  151.           (push 'browse-hack-electric-buffer-menu
  152.             electric-buffer-menu-mode-hook)
  153.           (call-interactively 'electric-buffer-list))
  154.       (pop electric-buffer-menu-mode-hook)))))
  155.  
  156. (add-hook 'electric-buffer-menu-mode-hook 'browse-electric-install-quick-keys)
  157.  
  158. (if browse-option-electric-buffer-key
  159.     (define-key browse-global-map " " 'browse-electric-buffer-list))
  160.  
  161.  
  162. ;;;
  163. ;;; Customization of C++ mode. \C-tab or \M-tab is bound to symbol
  164. ;;; completion. For Emacs 19, C-M-mouse1 is bound to the same
  165. ;;; function as \C-b.
  166. ;;;
  167.  
  168. (require 'br-compl)
  169.  
  170. (add-hook 'c++-mode-hook
  171.           (function
  172.            (lambda ()
  173.              (cond ((browse-emacs-19-p)
  174.                     (define-key (current-local-map) [C-tab] 
  175.                       'browse-complete-symbol)
  176.                     (define-key (current-local-map) [C-M-mouse-1] 
  177.                       'browse-mouse-member-find))
  178.                    (t
  179.                     (define-key (current-local-map) "\e\C-i"
  180.                       'browse-complete-symbol))))))
  181.  
  182.  
  183. (provide 'br-utils)
  184.  
  185. ;;; end of `utils.el'
  186.