+2008-03-25 Juanma Barranquero <lekktu@gmail.com>
+
+ * emacs-lisp/re-builder.el (reb-mode-common): Remove reference to
+ bogus variable `reb-kill-buffer'; don't make hooks buffer-local,
+ use the LOCAL arg of `add-hook'.
+ (reb-blink-delay, reb-mode-hook, reb-re-syntax, reb-auto-match-limit):
+ Remove spurious * from defcustom docstrings.
+ (reb-next-match, reb-prev-match, reb-enter-subexp-mode):
+ Fix typos in messages.
+ (reb-mode-buffer-p): New function.
+ (re-builder, reb-kill-buffer): Use `reb-mode-buffer-p'. Use `when'.
+ (top, reb-show-subexp, reb-auto-update, reb-auto-update)
+ (reb-delete-overlays, reb-cook-regexp, reb-update-regexp)
+ (reb-update-overlays): Use `unless', `when'.
+ (re-builder-unload-function): New function.
+
2008-03-25 Dan Nicolaescu <dann@ics.uci.edu>
* vc-hooks.el (vc-state): Add documentation for 'missing.
* simple.el (transient-mark-mode): Turn on by default.
-2008-03-23 Xavier Maillard <xma@gnu.org>
-
- * saveplace.el: fix a typo in the commentary section.
-
2008-03-23 Dan Nicolaescu <dann@ics.uci.edu>
* vc-bzr.el (vc-bzr-state): Return 'removed for removed files and
subdirectories.
* vc.el (vc-status-prepare-status-buffer): Fix thinko.
- (vc-status-menu-map): Add binding for
- vc-status-kill-dir-status-process. Add :enable for vc-status-refresh.
+ (vc-status-menu-map): Add binding for vc-status-kill-dir-status-process.
+ Add :enable for vc-status-refresh.
(vc-status-menu-map-filter): Remove vc-ignore-menu-filter test.
- (vc-status-tool-bar-map): Add binding for vc-status-kill-dir-status-process.
+ (vc-status-tool-bar-map): Add binding for
+ vc-status-kill-dir-status-process.
Don't test display-graphic-p and don't bind vc-ignore-menu-filter.
(vc-update-vc-status-buffer, vc-status-kill-dir-status-process):
Reset vc-status-process-buffer.
(vc-status): If the buffer is already in vc-status-mode only refresh.
(vc-status-mark-buffer-changed): Add an optional file parameter.
(vc-resynch-buffer): Use it.
- (vc-delete-file): Expand the file name before using it. Be
- careful to not create a new buffer with the old file contents.
+ (vc-delete-file): Expand the file name before using it.
+ Be careful to not create a new buffer with the old file contents.
Update the VC state after performing the operation.
2008-03-23 Andreas Schwab <schwab@suse.de>
- * menu-bar.el (menu-bar-showhide-fringe-ind-menu) [mixed]: Fix
- radio button condition.
+ * menu-bar.el (menu-bar-showhide-fringe-ind-menu) [mixed]:
+ Fix radio button condition.
[box]: Likewise.
[customize]: Add radio button.
;;; Code:
;; On XEmacs, load the overlay compatibility library
-(if (not (fboundp 'make-overlay))
- (require 'overlay))
+(unless (fboundp 'make-overlay)
+ (require 'overlay))
;; User customizable variables
(defgroup re-builder nil
:prefix "reb-")
(defcustom reb-blink-delay 0.5
- "*Seconds to blink cursor for next/previous match in RE Builder."
+ "Seconds to blink cursor for next/previous match in RE Builder."
:group 're-builder
:type 'number)
(defcustom reb-mode-hook nil
- "*Hooks to run on entering RE Builder mode."
+ "Hooks to run on entering RE Builder mode."
:group 're-builder
:type 'hook)
(defcustom reb-re-syntax 'read
- "*Syntax for the REs in the RE Builder.
+ "Syntax for the REs in the RE Builder.
Can either be `read', `string', `sregex', `lisp-re', `rx'."
:group 're-builder
:type '(choice (const :tag "Read syntax" read)
(const :tag "`rx' syntax" rx)))
(defcustom reb-auto-match-limit 200
- "*Positive integer limiting the matches for RE Builder auto updates.
+ "Positive integer limiting the matches for RE Builder auto updates.
Set it to nil if you don't want limits here."
:group 're-builder
:type '(restricted-sexp :match-alternatives
mode-line-buffer-identification
'(25 . ("%b" reb-mode-string reb-valid-string)))
(reb-update-modestring)
- (make-local-variable 'after-change-functions)
- (add-hook 'after-change-functions
- 'reb-auto-update)
+ (add-hook 'after-change-functions 'reb-auto-update nil t)
;; At least make the overlays go away if the buffer is killed
- (make-local-variable 'reb-kill-buffer)
- (add-hook 'kill-buffer-hook 'reb-kill-buffer)
+ (add-hook 'kill-buffer-hook 'reb-kill-buffer nil t)
(reb-auto-update nil nil nil))
(defun reb-color-display-p ()
(reb-lisp-mode))
(t (reb-mode))))
+(defun reb-mode-buffer-p ()
+ "Return non-nil if the current buffer is a RE Builder buffer."
+ (memq major-mode '(reb-mode reb-lisp-mode)))
+
;;; This is to help people find this in Apropos.
;;;###autoload
(defalias 'regexp-builder 're-builder)
(interactive)
(if (and (string= (buffer-name) reb-buffer)
- (memq major-mode '(reb-mode reb-lisp-mode)))
+ (reb-mode-buffer-p))
(message "Already in the RE Builder")
- (if reb-target-buffer
- (reb-delete-overlays))
+ (when reb-target-buffer
+ (reb-delete-overlays))
(setq reb-target-buffer (current-buffer)
reb-target-window (selected-window)
reb-window-config (current-window-configuration))
(reb-assert-buffer-in-window)
(with-selected-window reb-target-window
(if (not (re-search-forward reb-regexp (point-max) t))
- (message "No more matches.")
+ (message "No more matches")
(reb-show-subexp
(or (and reb-subexp-mode reb-subexp-displayed) 0)
t))))
(or (and reb-subexp-mode reb-subexp-displayed) 0)
t)
(goto-char p)
- (message "No more matches.")))))
+ (message "No more matches")))))
(defun reb-toggle-case ()
"Toggle case sensitivity of searches for RE Builder target buffer."
(setq reb-subexp-mode t)
(reb-update-modestring)
(use-local-map reb-subexp-mode-map)
- (message "`0'-`9' to display subexpressions `q' to quit subexp mode."))
+ (message "`0'-`9' to display subexpressions `q' to quit subexp mode"))
(defun reb-show-subexp (subexp &optional pause)
"Visually show limit of subexpression SUBEXP of recent search.
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."
(with-selected-window reb-target-window
- (if (not (reb-color-display-p))
- (progn (goto-char (match-beginning subexp))
- (sit-for reb-blink-delay)))
+ (unless (reb-color-display-p)
+ (goto-char (match-beginning subexp))
+ (sit-for reb-blink-delay))
(goto-char (match-end subexp))
- (if (or (not (reb-color-display-p)) pause)
- (sit-for reb-blink-delay))))
+ (when (or (not (reb-color-display-p)) pause)
+ (sit-for reb-blink-delay))))
(defun reb-quit-subexp-mode ()
"Quit the subexpression mode in the RE Builder."
(new-valid
(condition-case nil
(progn
- (if (or (reb-update-regexp) force)
- (progn
- (reb-assert-buffer-in-window)
- (reb-do-update)))
+ (when (or (reb-update-regexp) force)
+ (reb-assert-buffer-in-window)
+ (reb-do-update))
"")
(error " *invalid*"))))
(setq reb-valid-string new-valid)
;; Through the caching of the re a change invalidating the syntax
;; for symbolic expressions will not delete the overlays so we
;; catch it here
- (if (and (reb-lisp-syntax-p)
- (not (string= prev-valid new-valid))
- (string= prev-valid ""))
- (reb-delete-overlays))))
+ (when (and (reb-lisp-syntax-p)
+ (not (string= prev-valid new-valid))
+ (string= prev-valid ""))
+ (reb-delete-overlays))))
(defun reb-delete-overlays ()
"Delete all RE Builder overlays in the `reb-target-buffer' buffer."
- (if (buffer-live-p reb-target-buffer)
+ (when (buffer-live-p reb-target-buffer)
(with-current-buffer reb-target-buffer
(mapc 'delete-overlay reb-overlays)
(setq reb-overlays nil))))
(defun reb-kill-buffer ()
"When the RE Builder buffer is killed make sure no overlays stay around."
- (if (member major-mode '(reb-mode reb-lisp-mode))
- (reb-delete-overlays)))
+ (when (reb-mode-buffer-p)
+ (reb-delete-overlays)))
;; The next functions are the interface between the regexp and
(defun reb-cook-regexp (re)
"Return RE after processing it according to `reb-re-syntax'."
(cond ((eq reb-re-syntax 'lisp-re)
- (if (fboundp 'lre-compile-string)
- (lre-compile-string (eval (car (read-from-string re))))))
+ (when (fboundp 'lre-compile-string)
+ (lre-compile-string (eval (car (read-from-string re))))))
((eq reb-re-syntax 'sregex)
(apply 'sregex (eval (car (read-from-string re)))))
((eq reb-re-syntax 'rx)
(not (string= oldre re))
(setq reb-regexp re)
;; Only update the source re for the lisp formats
- (if (reb-lisp-syntax-p)
- (setq reb-regexp-src re-src)))))))
+ (when (reb-lisp-syntax-p)
+ (setq reb-regexp-src re-src)))))))
;; And now the real core of the whole thing
(re-search-forward re (point-max) t)
(or (not reb-auto-match-limit)
(< matches reb-auto-match-limit)))
- (if (= 0 (length (match-string 0)))
- (unless (eobp)
- (forward-char 1)))
+ (when (and (= 0 (length (match-string 0)))
+ (not (eobp)))
+ (forward-char 1))
(let ((i 0)
suffix max-suffix)
(setq matches (1+ matches))
(while (<= i subexps)
- (if (and (or (not subexp) (= subexp i))
- (match-beginning i))
- (let ((overlay (make-overlay (match-beginning i)
- (match-end i)))
- ;; When we have exceeded the number of provided faces,
- ;; cycle thru them where `max-suffix' denotes the maximum
- ;; suffix for `reb-match-*' that has been defined and
- ;; `suffix' the suffix calculated for the current match.
- (face
- (cond
- (max-suffix
- (if (= suffix max-suffix)
- (setq suffix 1)
- (setq suffix (1+ suffix)))
- (intern-soft (format "reb-match-%d" suffix)))
- ((intern-soft (format "reb-match-%d" i)))
- ((setq max-suffix (1- i))
- (setq suffix 1)
- ;; `reb-match-1' must exist.
- 'reb-match-1))))
- (unless firstmatch (setq firstmatch (match-data)))
- (setq reb-overlays (cons overlay reb-overlays)
- submatches (1+ submatches))
- (overlay-put overlay 'face face)
- (overlay-put overlay 'priority i)))
+ (when (and (or (not subexp) (= subexp i))
+ (match-beginning i))
+ (let ((overlay (make-overlay (match-beginning i)
+ (match-end i)))
+ ;; When we have exceeded the number of provided faces,
+ ;; cycle thru them where `max-suffix' denotes the maximum
+ ;; suffix for `reb-match-*' that has been defined and
+ ;; `suffix' the suffix calculated for the current match.
+ (face
+ (cond
+ (max-suffix
+ (if (= suffix max-suffix)
+ (setq suffix 1)
+ (setq suffix (1+ suffix)))
+ (intern-soft (format "reb-match-%d" suffix)))
+ ((intern-soft (format "reb-match-%d" i)))
+ ((setq max-suffix (1- i))
+ (setq suffix 1)
+ ;; `reb-match-1' must exist.
+ 'reb-match-1))))
+ (unless firstmatch (setq firstmatch (match-data)))
+ (setq reb-overlays (cons overlay reb-overlays)
+ submatches (1+ submatches))
+ (overlay-put overlay 'face face)
+ (overlay-put overlay 'priority i)))
(setq i (1+ i))))))
(let ((count (if subexp submatches matches)))
(message "%s %smatch%s%s"
(if (and reb-auto-match-limit
(= reb-auto-match-limit count))
" (limit reached)" "")))
- (if firstmatch
- (progn (store-match-data firstmatch)
- (reb-show-subexp (or subexp 0))))))
+ (when firstmatch
+ (store-match-data firstmatch)
+ (reb-show-subexp (or subexp 0)))))
+
+;; The End
+(defun re-builder-unload-function ()
+ "Unload the RE Builder library."
+ (when (buffer-live-p (get-buffer reb-buffer))
+ (with-current-buffer reb-buffer
+ (remove-hook 'after-change-functions 'reb-auto-update t)
+ (remove-hook 'kill-buffer-hook 'reb-kill-buffer t)
+ (when (reb-mode-buffer-p)
+ (reb-delete-overlays)
+ (funcall default-major-mode))))
+ ;; continue standard unloading
+ nil)
(provide 're-builder)