Use line-end-position rather than end-of-line, etc.
[bpt/emacs.git] / lisp / progmodes / ebrowse.el
index 5acbe70..7101bf2 100644 (file)
@@ -1,8 +1,8 @@
 ;;; ebrowse.el --- Emacs C++ class browser & tags facility
 
-;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-;; 2002, 2003, 2004, 2005, 2006, 2007
-;; Free Software Foundation Inc.
+;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+;;   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+;;   Free Software Foundation Inc.
 
 ;; Author: Gerd Moellmann <gerd@gnu.org>
 ;; Maintainer: FSF
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -21,9 +21,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -164,8 +162,7 @@ This space is used to display markers."
     (t (:foreground "red")))
   "*The face used for the mark character in the tree."
   :group 'ebrowse-faces)
-;; backward-compatibility alias
-(put 'ebrowse-tree-mark-face 'face-alias 'ebrowse-tree-mark)
+(define-obsolete-face-alias 'ebrowse-tree-mark-face 'ebrowse-tree-mark "22.1")
 
 
 (defface ebrowse-root-class
@@ -173,24 +170,21 @@ This space is used to display markers."
     (t (:weight bold :foreground "blue")))
   "*The face used for root classes in the tree."
   :group 'ebrowse-faces)
-;; backward-compatibility alias
-(put 'ebrowse-root-class-face 'face-alias 'ebrowse-root-class)
+(define-obsolete-face-alias 'ebrowse-root-class-face 'ebrowse-root-class "22.1")
 
 
 (defface ebrowse-file-name
   '((t (:italic t)))
   "*The face for filenames displayed in the tree."
   :group 'ebrowse-faces)
-;; backward-compatibility alias
-(put 'ebrowse-file-name-face 'face-alias 'ebrowse-file-name)
+(define-obsolete-face-alias 'ebrowse-file-name-face 'ebrowse-file-name "22.1")
 
 
 (defface ebrowse-default
   '((t nil))
   "*Face for everything else in the tree not having other faces."
   :group 'ebrowse-faces)
-;; backward-compatibility alias
-(put 'ebrowse-default-face 'face-alias 'ebrowse-default)
+(define-obsolete-face-alias 'ebrowse-default-face 'ebrowse-default "22.1")
 
 
 (defface ebrowse-member-attribute
@@ -198,16 +192,16 @@ This space is used to display markers."
     (t (:foreground "red")))
   "*Face used to display member attributes."
   :group 'ebrowse-faces)
-;; backward-compatibility alias
-(put 'ebrowse-member-attribute-face 'face-alias 'ebrowse-member-attribute)
+(define-obsolete-face-alias 'ebrowse-member-attribute-face
+  'ebrowse-member-attribute "22.1")
 
 
 (defface ebrowse-member-class
   '((t (:foreground "purple")))
   "*Face used to display the class title in member buffers."
   :group 'ebrowse-faces)
-;; backward-compatibility alias
-(put 'ebrowse-member-class-face 'face-alias 'ebrowse-member-class)
+(define-obsolete-face-alias 'ebrowse-member-class-face
+  'ebrowse-member-class "22.1")
 
 
 (defface ebrowse-progress
@@ -215,8 +209,7 @@ This space is used to display markers."
     (t (:background "blue")))
   "*Face for progress indicator."
   :group 'ebrowse-faces)
-;; backward-compatibility alias
-(put 'ebrowse-progress-face 'face-alias 'ebrowse-progress)
+(define-obsolete-face-alias 'ebrowse-progress-face 'ebrowse-progress "22.1")
 
 
 \f
@@ -896,10 +889,10 @@ this is the first progress message displayed."
   (let (message-log-max)
     (when start (setq ebrowse-n-boxes 0))
     (setq ebrowse-n-boxes (mod (1+ ebrowse-n-boxes) ebrowse-max-boxes))
-    (message (concat title ": "
-                    (propertize (make-string ebrowse-n-boxes
-                                             (if (display-color-p) ?\  ?+))
-                                'face 'ebrowse-progress)))))
+    (message "%s: %s" title
+            (propertize (make-string ebrowse-n-boxes
+                                     (if (display-color-p) ?\  ?+))
+                        'face 'ebrowse-progress))))
 
 \f
 ;;; Reading a tree from disk
@@ -1009,8 +1002,7 @@ HEADER is the tree header structure of the class tree."
     (loop for buffer in (ebrowse-browser-buffer-list)
          until (eq header (ebrowse-value-in-buffer 'ebrowse--header buffer))
          finally do
-         (save-excursion
-           (set-buffer buffer)
+         (with-current-buffer buffer
            (ebrowse-fill-member-table))))
   (ebrowse-hs-member-table header))
 
@@ -1143,7 +1135,7 @@ Tree mode key bindings:
 
     (unless (zerop (buffer-size))
       (goto-char (point-min))
-      (multiple-value-setq (header tree) (ebrowse-read))
+      (multiple-value-setq (header tree) (values-list (ebrowse-read)))
       (message "Sorting. Please be patient...")
       (setq tree (ebrowse-sort-tree-list tree))
       (erase-buffer)
@@ -1321,7 +1313,7 @@ With PREFIX, insert that many filenames."
          (skip-chars-forward " \t*a-zA-Z0-9_")
          (setq start (point)
                file-name-existing (looking-at "("))
-         (delete-region start (save-excursion (end-of-line) (point)))
+         (delete-region start (line-end-position))
          (unless file-name-existing
            (indent-to ebrowse-source-file-column)
            (insert "(" (or (ebrowse-cs-file
@@ -1339,7 +1331,8 @@ With PREFIX, insert that many filenames."
   (setf ebrowse--show-file-names-flag (not ebrowse--show-file-names-flag))
   (let ((old-line (count-lines (point-min) (point))))
     (ebrowse-redraw-tree)
-    (goto-line old-line)))
+    (goto-char (point-min))
+    (forward-line (1- old-line))))
 
 
 \f
@@ -1614,28 +1607,12 @@ and (b) in the directories named in `ebrowse-search-path'."
     file-name))
 
 
-(defun ebrowse-view-file-other-window (file)
-  "View a file FILE in another window.
-This is a replacement for `view-file-other-window' which does not
-seem to work. It should be removed when `view.el' is fixed."
-  (interactive)
-  (let ((old-arrangement (current-window-configuration))
-       (had-a-buf (get-file-buffer file))
-       (buf-to-view (find-file-noselect file)))
-    (switch-to-buffer-other-window buf-to-view)
-    (view-mode-enter old-arrangement
-                    (and (not had-a-buf)
-                         (not (buffer-modified-p buf-to-view))
-                         'kill-buffer))))
-
-
 (defun ebrowse-view-exit-fn (buffer)
   "Function called when exiting View mode in BUFFER.
 Restore frame configuration active before viewing the file,
 and possibly kill the viewed buffer."
   (let (exit-action original-frame-configuration)
-    (save-excursion
-      (set-buffer buffer)
+    (with-current-buffer buffer
       (setq original-frame-configuration ebrowse--frame-configuration
            exit-action ebrowse--view-exit-action))
     ;; Delete the frame in which we viewed.
@@ -1649,10 +1626,9 @@ and possibly kill the viewed buffer."
 
 (defun ebrowse-view-file-other-frame (file)
   "View a file FILE in another frame.
-The new frame is deleted when it is no longer used."
+The new frame is deleted when you quit viewing the file in that frame."
   (interactive)
   (let ((old-frame-configuration (current-frame-configuration))
-       (old-arrangement (current-window-configuration))
        (had-a-buf (get-file-buffer file))
        (buf-to-view (find-file-noselect file)))
     (switch-to-buffer-other-frame buf-to-view)
@@ -1663,8 +1639,8 @@ The new frame is deleted when it is no longer used."
          (and (not had-a-buf)
               (not (buffer-modified-p buf-to-view))
               'kill-buffer))
-    (view-mode-enter old-arrangement 'ebrowse-view-exit-fn)))
-
+    (view-mode-enter (cons (selected-window) (cons (selected-window) t))
+                    'ebrowse-view-exit-fn)))
 
 (defun ebrowse-view/find-file-and-search-pattern
   (struc info file tags-file-name &optional view where)
@@ -1699,7 +1675,7 @@ specifies where to find/view the result."
           (setq view-mode-hook nil))
         (push 'ebrowse-find-pattern view-mode-hook)
         (case where
-          (other-window (ebrowse-view-file-other-window file))
+          (other-window (view-file-other-window file))
           (other-frame  (ebrowse-view-file-other-frame file))
           (t            (view-file file))))
        (t
@@ -2611,7 +2587,7 @@ TAGS-FILE-NAME is the file name of the BROWSE file."
              accessor (second info)
              member (third info))
       (multiple-value-setq (tree member on-class)
-       (ebrowse-member-info-from-point))
+       (values-list (ebrowse-member-info-from-point)))
       (setq accessor ebrowse--accessor))
     ;; View/find class if on a line containing a class name.
     (when on-class
@@ -3331,7 +3307,7 @@ from point as default.  Value is a list (CLASS-NAME MEMBER-NAME)."
   (save-excursion
     (let* (start member-info (members (ebrowse-member-table header)))
       (multiple-value-bind (class-name member-name)
-         (ebrowse-tags-read-member+class-name)
+         (values-list (ebrowse-tags-read-member+class-name))
        (unless member-name
          (error "No member name at point"))
        (if members
@@ -3396,7 +3372,7 @@ the user choose the class to use.  As a last step, a tags search
 is performed that positions point on the member declaration or
 definition."
   (multiple-value-bind
-      (tree header tree-buffer) (ebrowse-choose-tree)
+      (tree header tree-buffer) (values-list (ebrowse-choose-tree))
     (unless tree (error "No class tree"))
     (let* ((marker (point-marker))
           class-name
@@ -3404,10 +3380,11 @@ definition."
           info)
       (unless name
        (multiple-value-setq (class-name name)
-         (ebrowse-tags-read-name
-          header
-          (concat (if view "View" "Find") " member "
-                  (if definition "definition" "declaration") ": "))))
+         (values-list 
+          (ebrowse-tags-read-name
+           header
+           (concat (if view "View" "Find") " member "
+                   (if definition "definition" "declaration") ": ")))))
       (setq info (ebrowse-tags-choose-class tree header name class-name))
       (ebrowse-push-position marker info)
       ;; Goto the occurrence of the member
@@ -3525,13 +3502,14 @@ FIX-NAME non-nil means display the buffer for that member.
 Otherwise read a member name from point."
   (interactive)
   (multiple-value-bind
-      (tree header tree-buffer) (ebrowse-choose-tree)
+      (tree header tree-buffer) (values-list (ebrowse-choose-tree))
     (unless tree (error "No class tree"))
     (let* ((marker (point-marker)) class-name (name fix-name) info)
       (unless name
        (multiple-value-setq (class-name name)
-         (ebrowse-tags-read-name header
-                                 (concat "Find member list of: "))))
+         (values-list 
+          (ebrowse-tags-read-name header
+                                  (concat "Find member list of: ")))))
       (setq info (ebrowse-tags-choose-class tree header name class-name))
       (ebrowse-push-position marker info)
       (ebrowse-tags-select/create-member-buffer tree-buffer info))))
@@ -3575,7 +3553,7 @@ The file name is read from the minibuffer."
   (interactive)
   (let* ((buffer (or (ebrowse-choose-from-browser-buffers)
                     (error "No tree buffer")))
-        (files (save-excursion (set-buffer buffer) (ebrowse-files-table)))
+        (files (with-current-buffer buffer (ebrowse-files-table)))
         (file (completing-read "List members in file: " files nil t))
         (header (ebrowse-value-in-buffer 'ebrowse--header buffer))
         temp-buffer-setup-hook
@@ -3753,8 +3731,7 @@ TREE-BUFFER specifies the class tree we operate on."
   ;; on which tree (s)he wants to operate.
   (when initialize
     (let ((buffer (or tree-buffer (ebrowse-choose-from-browser-buffers))))
-      (save-excursion
-       (set-buffer buffer)
+      (with-current-buffer buffer
        (setq ebrowse-tags-next-file-list
              (ebrowse-files-list (ebrowse-marked-classes-p))
              ebrowse-tags-loop-last-file
@@ -3837,14 +3814,14 @@ looks like a function call to the member."
   (interactive)
   ;; Choose the tree to use if there is more than one.
   (multiple-value-bind (tree header tree-buffer)
-      (ebrowse-choose-tree)
+      (values-list (ebrowse-choose-tree))
     (unless tree
       (error "No class tree"))
     ;; Get the member name NAME (class-name is ignored).
     (let ((name fix-name) class-name regexp)
       (unless name
        (multiple-value-setq (class-name name)
-         (ebrowse-tags-read-name header "Find calls of: ")))
+         (values-list (ebrowse-tags-read-name header "Find calls of: "))))
       ;; Set tags loop form to search for member and begin loop.
       (setq regexp (concat "\\<" name "[ \t]*(")
            ebrowse-tags-loop-form (list 're-search-forward regexp nil t))
@@ -4144,8 +4121,7 @@ Otherwise, FILE-NAME specifies the file to save the tree in."
        (header (copy-ebrowse-hs ebrowse--header))
        (tree ebrowse--tree))
     (unwind-protect
-       (save-excursion
-         (set-buffer (setq standard-output temp-buffer))
+       (with-current-buffer (setq standard-output temp-buffer)
          (erase-buffer)
          (setf (ebrowse-hs-member-table header) nil)
          (insert (prin1-to-string header) " ")
@@ -4186,7 +4162,7 @@ Otherwise, FILE-NAME specifies the file to save the tree in."
     (with-output-to-temp-buffer "*Tree Statistics*"
       (multiple-value-bind (classes member-functions member-variables
                                    static-functions static-variables)
-         (ebrowse-gather-statistics)
+         (values-list (ebrowse-gather-statistics))
        (set-buffer standard-output)
        (erase-buffer)
        (insert "STATISTICS FOR TREE " (or tree-file "unknown") ":\n\n")
@@ -4230,8 +4206,8 @@ NUMBER-OF-STATIC-VARIABLES:"
 \f
 ;;; Global key bindings
 
-;;; The following can be used to bind key sequences starting with
-;;; prefix `\C-c\C-m' to browse commands.
+;; The following can be used to bind key sequences starting with
+;; prefix `\C-c\C-m' to browse commands.
 
 (defvar ebrowse-global-map nil
   "*Keymap for Ebrowse commands.")
@@ -4290,14 +4266,14 @@ NUMBER-OF-STATIC-VARIABLES:"
 \f
 ;;; Electric C++ browser buffer menu
 
-;;; Electric buffer menu customization to display only some buffers
-;;; (in this case Tree buffers).  There is only one problem with this:
-;;; If the very first character typed in the buffer menu is a space,
-;;; this will select the buffer from which the buffer menu was
-;;; invoked.  But this buffer is not displayed in the buffer list if
-;;; it isn't a tree buffer.  I therefore let the buffer menu command
-;;; loop read the command `p' via `unread-command-char'.  This command
-;;; has no effect since we are on the first line of the buffer.
+;; Electric buffer menu customization to display only some buffers
+;; (in this case Tree buffers).  There is only one problem with this:
+;; If the very first character typed in the buffer menu is a space,
+;; this will select the buffer from which the buffer menu was
+;; invoked.  But this buffer is not displayed in the buffer list if
+;; it isn't a tree buffer.  I therefore let the buffer menu command
+;; loop read the command `p' via `unread-command-char'.  This command
+;; has no effect since we are on the first line of the buffer.
 
 (defvar electric-buffer-menu-mode-hook nil)
 
@@ -4332,7 +4308,8 @@ NUMBER-OF-STATIC-VARIABLES:"
   (interactive)
   (let* ((maxlin (count-lines (point-min) (point-max)))
         (n (min maxlin (+ 2 (string-to-number (this-command-keys))))))
-    (goto-line n)
+    (goto-char (point-min))
+    (forward-line (1- n))
     (throw 'electric-buffer-menu-select (point))))
 
 
@@ -4507,12 +4484,11 @@ EVENT is the mouse event."
 \f
 (provide 'ebrowse)
 
-;;; Local variables:
-;;; eval:(put 'ebrowse-output 'lisp-indent-hook 0)
-;;; eval:(put 'ebrowse-ignoring-completion-case 'lisp-indent-hook 0)
-;;; eval:(put 'ebrowse-save-selective 'lisp-indent-hook 0)
-;;; eval:(put 'ebrowse-for-all-trees 'lisp-indent-hook 1)
-;;; End:
+;; Local variables:
+;; eval:(put 'ebrowse-output 'lisp-indent-hook 0)
+;; eval:(put 'ebrowse-ignoring-completion-case 'lisp-indent-hook 0)
+;; eval:(put 'ebrowse-save-selective 'lisp-indent-hook 0)
+;; eval:(put 'ebrowse-for-all-trees 'lisp-indent-hook 1)
+;; End:
 
-;;; arch-tag: 4fa3c8bf-1771-479b-bcd7-b029c7c9677b
 ;;; ebrowse.el ends here