Fix compilation of xmenu.c and unexcoff.c, clean up MSDOS source files.
[bpt/emacs.git] / lisp / emacs-lisp / re-builder.el
index a0fe628..1845eff 100644 (file)
@@ -1,17 +1,17 @@
 ;;; re-builder.el --- building Regexps with visual feedback
 
 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 ;; Author: Detlev Zundel <dzu@gnu.org>
 ;; Keywords: matching, lisp, tools
 
 ;; 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
@@ -19,9 +19,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, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 ;; this limit allowing an easy way to see all matches.
 
 ;; Currently `re-builder' understands five different forms of input,
-;; namely `read', `string', `rx', `sregex' and `lisp-re' syntax.  Read
+;; namely `read', `string', `rx', and `sregex' syntax.  Read
 ;; syntax and string syntax are both delimited by `"'s and behave
 ;; according to their name.  With the `string' syntax there's no need
 ;; to escape the backslashes and double quotes simplifying the editing
 ;; somewhat.  The other three allow editing of symbolic regular
-;; expressions supported by the packages of the same name.  (`lisp-re'
-;; is a package by me and its support may go away as it is nearly the
-;; same as the `sregex' package in Emacs)
+;; expressions supported by the packages of the same name.
 
 ;; Editing symbolic expressions is done through a major mode derived
 ;; from `emacs-lisp-mode' so you'll get all the good stuff like
 
 (defcustom reb-re-syntax 'read
   "Syntax for the REs in the RE Builder.
-Can either be `read', `string', `sregex', `lisp-re', `rx'."
+Can either be `read', `string', `sregex', or `rx'."
   :group 're-builder
   :type '(choice (const :tag "Read syntax" read)
                 (const :tag "String syntax" string)
                 (const :tag "`sregex' syntax" sregex)
-                (const :tag "`lisp-re' syntax" lisp-re)
                 (const :tag "`rx' syntax" rx)))
 
 (defcustom reb-auto-match-limit 200
@@ -250,7 +245,7 @@ Except for Lisp syntax this is the same as `reb-regexp'.")
     (define-key menu-map [rt]
       '(menu-item "Case sensitive" reb-toggle-case
                  :button (:toggle . case-fold-search)
-                 :help "Toggle case sensitivity of searches for RE Builder target buffer."))
+                 :help "Toggle case sensitivity of searches for RE Builder target buffer"))
     (define-key menu-map [rb]
       '(menu-item "Change target buffer..." reb-change-target-buffer
                  :help "Change the target buffer and display it in the target window"))
@@ -275,24 +270,16 @@ Except for Lisp syntax this is the same as `reb-regexp'.")
     map)
   "Keymap used by the RE Builder.")
 
-(defun reb-mode ()
-  "Major mode for interactively building Regular Expressions.
-\\{reb-mode-map}"
-  (interactive)
-  (kill-all-local-variables)
-  (setq major-mode 'reb-mode
-        mode-name "RE Builder")
+(define-derived-mode reb-mode nil "RE Builder"
+  "Major mode for interactively building Regular Expressions."
   (set (make-local-variable 'blink-matching-paren) nil)
-  (use-local-map reb-mode-map)
-  (reb-mode-common)
-  (run-mode-hooks 'reb-mode-hook))
+  (reb-mode-common))
 
 (define-derived-mode reb-lisp-mode
   emacs-lisp-mode "RE Builder Lisp"
   "Major mode for interactively building symbolic Regular Expressions."
-  (cond ((eq reb-re-syntax 'lisp-re)   ; Pull in packages
-        (require 'lisp-re))            ; as needed
-       ((eq reb-re-syntax 'sregex)     ; sregex is not autoloaded
+  ;; Pull in packages as needed
+  (cond        ((eq reb-re-syntax 'sregex)     ; sregex is not autoloaded
         (require 'sregex))             ; right now..
        ((eq reb-re-syntax 'rx)         ; rx-to-string is autoloaded
         (require 'rx)))                ; require rx anyway
@@ -338,7 +325,7 @@ Except for Lisp syntax this is the same as `reb-regexp'.")
 
 (defsubst reb-lisp-syntax-p ()
   "Return non-nil if RE Builder uses a Lisp syntax."
-  (memq reb-re-syntax '(lisp-re sregex rx)))
+  (memq reb-re-syntax '(sregex rx)))
 
 (defmacro reb-target-binding (symbol)
   "Return binding for SYMBOL in the RE Builder target buffer."
@@ -351,7 +338,8 @@ Except for Lisp syntax this is the same as `reb-regexp'.")
   (goto-char (+ 2 (point-min)))
   (cond ((reb-lisp-syntax-p)
          (reb-lisp-mode))
-        (t (reb-mode))))
+        (t (reb-mode)))
+  (reb-do-update))
 
 (defun reb-mode-buffer-p ()
   "Return non-nil if the current buffer is a RE Builder buffer."
@@ -372,9 +360,11 @@ Except for Lisp syntax this is the same as `reb-regexp'.")
     (when reb-target-buffer
       (reb-delete-overlays))
     (setq reb-target-buffer (current-buffer)
-          reb-target-window (selected-window)
-          reb-window-config (current-window-configuration))
-    (select-window (split-window (selected-window) (- (window-height) 4)))
+          reb-target-window (selected-window))
+    (select-window (or (get-buffer-window reb-buffer)
+                      (progn
+                        (setq reb-window-config (current-window-configuration))
+                        (split-window (selected-window) (- (window-height) 4)))))
     (switch-to-buffer (get-buffer-create reb-buffer))
     (reb-initialize-buffer)))
 
@@ -495,10 +485,10 @@ Optional argument SYNTAX must be specified if called non-interactively."
    (list (intern
          (completing-read "Select syntax: "
                           (mapcar (lambda (el) (cons (symbol-name el) 1))
-                                  '(read string lisp-re sregex rx))
+                                  '(read string sregex rx))
                           nil t (symbol-name reb-re-syntax)))))
 
-  (if (memq syntax '(read string lisp-re sregex rx))
+  (if (memq syntax '(read string sregex rx))
       (let ((buffer (get-buffer reb-buffer)))
        (setq reb-re-syntax syntax)
        (when buffer
@@ -526,7 +516,6 @@ optional fourth argument FORCE is non-nil."
         (condition-case nil
             (progn
               (when (or (reb-update-regexp) force)
-                (reb-assert-buffer-in-window)
                 (reb-do-update))
               "")
           (error " *invalid*"))))
@@ -571,7 +560,7 @@ optional fourth argument FORCE is non-nil."
   (interactive)
 
   (setq reb-subexp-displayed
-       (or subexp (string-to-number (format "%c" last-command-char))))
+       (or subexp (string-to-number (format "%c" last-command-event))))
   (reb-update-modestring)
   (reb-do-update reb-subexp-displayed))
 
@@ -623,10 +612,7 @@ optional fourth argument FORCE is non-nil."
 
 (defun reb-cook-regexp (re)
   "Return RE after processing it according to `reb-re-syntax'."
-  (cond ((eq reb-re-syntax 'lisp-re)
-        (when (fboundp 'lre-compile-string)
-          (lre-compile-string (eval (car (read-from-string re))))))
-       ((eq reb-re-syntax 'sregex)
+  (cond ((eq reb-re-syntax 'sregex)
         (apply 'sregex (eval (car (read-from-string re)))))
        ((eq reb-re-syntax 'rx)
         (rx-to-string (eval (car (read-from-string re)))))
@@ -665,8 +651,7 @@ If SUBEXP is non-nil mark only the corresponding sub-expressions."
         (matches 0)
         (submatches 0)
         firstmatch)
-    (save-excursion
-      (set-buffer reb-target-buffer)
+    (with-current-buffer reb-target-buffer
       (reb-delete-overlays)
       (goto-char (point-min))
       (while (and (not (eobp))
@@ -727,7 +712,7 @@ If SUBEXP is non-nil mark only the corresponding sub-expressions."
       (remove-hook 'kill-buffer-hook 'reb-kill-buffer t)
       (when (reb-mode-buffer-p)
        (reb-delete-overlays)
-       (funcall default-major-mode))))
+       (funcall (or (default-value 'major-mode) 'fundamental-mode)))))
   ;; continue standard unloading
   nil)