aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2005-07-24 02:29:14 +0000
committerJuanma Barranquero2005-07-24 02:29:14 +0000
commit78690f09b148ce22c677684f8ffa77ffe4dab056 (patch)
treeb133addf3b3d53d692d3edde2875475b57a01108
parentac0385c8f13aa76fe602aeb58eb8541e5e943d29 (diff)
downloademacs-78690f09b148ce22c677684f8ffa77ffe4dab056.tar.gz
emacs-78690f09b148ce22c677684f8ffa77ffe4dab056.zip
(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.
-rw-r--r--lisp/emacs-lisp/re-builder.el63
1 files changed, 24 insertions, 39 deletions
diff --git a/lisp/emacs-lisp/re-builder.el b/lisp/emacs-lisp/re-builder.el
index bdfe79b3b6a..e0a3c5ed285 100644
--- a/lisp/emacs-lisp/re-builder.el
+++ b/lisp/emacs-lisp/re-builder.el
@@ -299,20 +299,6 @@ Except for Lisp syntax this is the same as `reb-regexp'.")
299 (add-hook 'kill-buffer-hook 'reb-kill-buffer) 299 (add-hook 'kill-buffer-hook 'reb-kill-buffer)
300 (reb-auto-update nil nil nil)) 300 (reb-auto-update nil nil nil))
301 301
302
303;; Handy macro for doing things in other windows
304(defmacro reb-with-current-window (window &rest body)
305 "With WINDOW selected evaluate BODY forms and reselect previous window."
306
307 (let ((oldwindow (make-symbol "*oldwindow*")))
308 `(let ((,oldwindow (selected-window)))
309 (select-window ,window)
310 (unwind-protect
311 (progn
312 ,@body)
313 (select-window ,oldwindow)))))
314(put 'reb-with-current-window 'lisp-indent-function 0)
315
316(defun reb-color-display-p () 302(defun reb-color-display-p ()
317 "Return t if display is capable of displaying colors." 303 "Return t if display is capable of displaying colors."
318 (eq 'color 304 (eq 'color
@@ -330,6 +316,15 @@ Except for Lisp syntax this is the same as `reb-regexp'.")
330 "Return binding for SYMBOL in the RE Builder target buffer." 316 "Return binding for SYMBOL in the RE Builder target buffer."
331 `(with-current-buffer reb-target-buffer ,symbol)) 317 `(with-current-buffer reb-target-buffer ,symbol))
332 318
319(defun reb-initialize-buffer ()
320 "Initialize the current buffer as a RE Builder buffer."
321 (erase-buffer)
322 (reb-insert-regexp)
323 (goto-char (+ 2 (point-min)))
324 (cond ((reb-lisp-syntax-p)
325 (reb-lisp-mode))
326 (t (reb-mode))))
327
333;;; This is to help people find this in Apropos. 328;;; This is to help people find this in Apropos.
334;;;###autoload 329;;;###autoload
335(defalias 'regexp-builder 're-builder) 330(defalias 'regexp-builder 're-builder)
@@ -349,13 +344,7 @@ Except for Lisp syntax this is the same as `reb-regexp'.")
349 reb-window-config (current-window-configuration)) 344 reb-window-config (current-window-configuration))
350 (select-window (split-window (selected-window) (- (window-height) 4))) 345 (select-window (split-window (selected-window) (- (window-height) 4)))
351 (switch-to-buffer (get-buffer-create reb-buffer)) 346 (switch-to-buffer (get-buffer-create reb-buffer))
352 (erase-buffer) 347 (reb-initialize-buffer)))
353 (reb-insert-regexp)
354 (goto-char (+ 2 (point-min)))
355 (cond
356 ((reb-lisp-syntax-p)
357 (reb-lisp-mode))
358 (t (reb-mode)))))
359 348
360(defun reb-change-target-buffer (buf) 349(defun reb-change-target-buffer (buf)
361 "Change the target buffer and display it in the target window." 350 "Change the target buffer and display it in the target window."
@@ -393,8 +382,7 @@ Except for Lisp syntax this is the same as `reb-regexp'.")
393 (interactive) 382 (interactive)
394 383
395 (reb-assert-buffer-in-window) 384 (reb-assert-buffer-in-window)
396 (reb-with-current-window 385 (with-selected-window reb-target-window
397 reb-target-window
398 (if (not (re-search-forward reb-regexp (point-max) t)) 386 (if (not (re-search-forward reb-regexp (point-max) t))
399 (message "No more matches.") 387 (message "No more matches.")
400 (reb-show-subexp 388 (reb-show-subexp
@@ -406,13 +394,15 @@ Except for Lisp syntax this is the same as `reb-regexp'.")
406 (interactive) 394 (interactive)
407 395
408 (reb-assert-buffer-in-window) 396 (reb-assert-buffer-in-window)
409 (reb-with-current-window reb-target-window 397 (with-selected-window reb-target-window
410 (goto-char (1- (point))) 398 (let ((p (point)))
411 (if (not (re-search-backward reb-regexp (point-min) t)) 399 (goto-char (1- p))
412 (message "No more matches.") 400 (if (re-search-backward reb-regexp (point-min) t)
413 (reb-show-subexp 401 (reb-show-subexp
414 (or (and reb-subexp-mode reb-subexp-displayed) 0) 402 (or (and reb-subexp-mode reb-subexp-displayed) 0)
415 t)))) 403 t)
404 (goto-char p)
405 (message "No more matches.")))))
416 406
417(defun reb-toggle-case () 407(defun reb-toggle-case ()
418 "Toggle case sensitivity of searches for RE Builder target buffer." 408 "Toggle case sensitivity of searches for RE Builder target buffer."
@@ -449,7 +439,7 @@ On color displays this just puts point to the end of the expression as
449the match should already be marked by an overlay. 439the match should already be marked by an overlay.
450On other displays jump to the beginning and the end of it. 440On other displays jump to the beginning and the end of it.
451If the optional PAUSE is non-nil then pause at the end in any case." 441If the optional PAUSE is non-nil then pause at the end in any case."
452 (reb-with-current-window reb-target-window 442 (with-selected-window reb-target-window
453 (if (not (reb-color-display-p)) 443 (if (not (reb-color-display-p))
454 (progn (goto-char (match-beginning subexp)) 444 (progn (goto-char (match-beginning subexp))
455 (sit-for reb-blink-delay))) 445 (sit-for reb-blink-delay)))
@@ -479,14 +469,9 @@ Optional argument SYNTAX must be specified if called non-interactively."
479 (if (memq syntax '(read string lisp-re sregex rx)) 469 (if (memq syntax '(read string lisp-re sregex rx))
480 (let ((buffer (get-buffer reb-buffer))) 470 (let ((buffer (get-buffer reb-buffer)))
481 (setq reb-re-syntax syntax) 471 (setq reb-re-syntax syntax)
482 (if buffer 472 (when buffer
483 (with-current-buffer buffer 473 (with-current-buffer buffer
484 (erase-buffer) 474 (reb-initialize-buffer))))
485 (reb-insert-regexp)
486 (goto-char (+ 2 (point-min)))
487 (cond ((reb-lisp-syntax-p)
488 (reb-lisp-mode))
489 (t (reb-mode))))))
490 (error "Invalid syntax: %s" syntax))) 475 (error "Invalid syntax: %s" syntax)))
491 476
492 477