Mercurial > emacs
changeset 64624:c3a907cbd503
(reb-with-current-window): Delete.
(reb-next-match, reb-show-subexp): Use `with-selected-window' instead of
`reb-with-current-window'.
(reb-prev-match): Likewise. Also, don't move left if the search was
unsuccessful.
(reb-initialize-buffer): New function.
(re-builder, reb-change-syntax): Use it.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Sun, 24 Jul 2005 02:29:14 +0000 |
parents | 9a399e33edd3 |
children | 82afe4f1cb04 |
files | lisp/emacs-lisp/re-builder.el |
diffstat | 1 files changed, 24 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/emacs-lisp/re-builder.el Sun Jul 24 01:18:23 2005 +0000 +++ b/lisp/emacs-lisp/re-builder.el Sun Jul 24 02:29:14 2005 +0000 @@ -299,20 +299,6 @@ (add-hook 'kill-buffer-hook 'reb-kill-buffer) (reb-auto-update nil nil nil)) - -;; Handy macro for doing things in other windows -(defmacro reb-with-current-window (window &rest body) - "With WINDOW selected evaluate BODY forms and reselect previous window." - - (let ((oldwindow (make-symbol "*oldwindow*"))) - `(let ((,oldwindow (selected-window))) - (select-window ,window) - (unwind-protect - (progn - ,@body) - (select-window ,oldwindow))))) -(put 'reb-with-current-window 'lisp-indent-function 0) - (defun reb-color-display-p () "Return t if display is capable of displaying colors." (eq 'color @@ -330,6 +316,15 @@ "Return binding for SYMBOL in the RE Builder target buffer." `(with-current-buffer reb-target-buffer ,symbol)) +(defun reb-initialize-buffer () + "Initialize the current buffer as a RE Builder buffer." + (erase-buffer) + (reb-insert-regexp) + (goto-char (+ 2 (point-min))) + (cond ((reb-lisp-syntax-p) + (reb-lisp-mode)) + (t (reb-mode)))) + ;;; This is to help people find this in Apropos. ;;;###autoload (defalias 'regexp-builder 're-builder) @@ -349,13 +344,7 @@ reb-window-config (current-window-configuration)) (select-window (split-window (selected-window) (- (window-height) 4))) (switch-to-buffer (get-buffer-create reb-buffer)) - (erase-buffer) - (reb-insert-regexp) - (goto-char (+ 2 (point-min))) - (cond - ((reb-lisp-syntax-p) - (reb-lisp-mode)) - (t (reb-mode))))) + (reb-initialize-buffer))) (defun reb-change-target-buffer (buf) "Change the target buffer and display it in the target window." @@ -393,8 +382,7 @@ (interactive) (reb-assert-buffer-in-window) - (reb-with-current-window - reb-target-window + (with-selected-window reb-target-window (if (not (re-search-forward reb-regexp (point-max) t)) (message "No more matches.") (reb-show-subexp @@ -406,13 +394,15 @@ (interactive) (reb-assert-buffer-in-window) - (reb-with-current-window reb-target-window - (goto-char (1- (point))) - (if (not (re-search-backward reb-regexp (point-min) t)) - (message "No more matches.") - (reb-show-subexp - (or (and reb-subexp-mode reb-subexp-displayed) 0) - t)))) + (with-selected-window reb-target-window + (let ((p (point))) + (goto-char (1- p)) + (if (re-search-backward reb-regexp (point-min) t) + (reb-show-subexp + (or (and reb-subexp-mode reb-subexp-displayed) 0) + t) + (goto-char p) + (message "No more matches."))))) (defun reb-toggle-case () "Toggle case sensitivity of searches for RE Builder target buffer." @@ -449,7 +439,7 @@ the match should already be marked by an overlay. On other displays jump to the beginning and the end of it. If the optional PAUSE is non-nil then pause at the end in any case." - (reb-with-current-window reb-target-window + (with-selected-window reb-target-window (if (not (reb-color-display-p)) (progn (goto-char (match-beginning subexp)) (sit-for reb-blink-delay))) @@ -479,14 +469,9 @@ (if (memq syntax '(read string lisp-re sregex rx)) (let ((buffer (get-buffer reb-buffer))) (setq reb-re-syntax syntax) - (if buffer - (with-current-buffer buffer - (erase-buffer) - (reb-insert-regexp) - (goto-char (+ 2 (point-min))) - (cond ((reb-lisp-syntax-p) - (reb-lisp-mode)) - (t (reb-mode)))))) + (when buffer + (with-current-buffer buffer + (reb-initialize-buffer)))) (error "Invalid syntax: %s" syntax)))