diff options
| author | Stefan Kangas | 2021-02-20 07:34:52 +0100 |
|---|---|---|
| committer | Stefan Kangas | 2021-02-20 07:55:04 +0100 |
| commit | d184895a42b37718cded839b95252e7bb165bcfd (patch) | |
| tree | 520728590ac6d1e3442131d125e93bdd8bff77fa | |
| parent | 7b12747e2f2136bc76bfbeb3648131281ec14961 (diff) | |
| download | emacs-d184895a42b37718cded839b95252e7bb165bcfd.tar.gz emacs-d184895a42b37718cded839b95252e7bb165bcfd.zip | |
Convert re-builder menu to easy-menu-define
* lisp/emacs-lisp/re-builder.el (reb-mode-map): Move menu
definition from here...
(reb-mode-menu): ...to here, and rewrite using easy-menu-define.
| -rw-r--r-- | lisp/emacs-lisp/re-builder.el | 78 |
1 files changed, 29 insertions, 49 deletions
diff --git a/lisp/emacs-lisp/re-builder.el b/lisp/emacs-lisp/re-builder.el index ce8d98df807..7f404c8296c 100644 --- a/lisp/emacs-lisp/re-builder.el +++ b/lisp/emacs-lisp/re-builder.el | |||
| @@ -217,8 +217,7 @@ Except for Lisp syntax this is the same as `reb-regexp'.") | |||
| 217 | 217 | ||
| 218 | ;; Define the local "\C-c" keymap | 218 | ;; Define the local "\C-c" keymap |
| 219 | (defvar reb-mode-map | 219 | (defvar reb-mode-map |
| 220 | (let ((map (make-sparse-keymap)) | 220 | (let ((map (make-sparse-keymap))) |
| 221 | (menu-map (make-sparse-keymap))) | ||
| 222 | (define-key map "\C-c\C-c" 'reb-toggle-case) | 221 | (define-key map "\C-c\C-c" 'reb-toggle-case) |
| 223 | (define-key map "\C-c\C-q" 'reb-quit) | 222 | (define-key map "\C-c\C-q" 'reb-quit) |
| 224 | (define-key map "\C-c\C-w" 'reb-copy) | 223 | (define-key map "\C-c\C-w" 'reb-copy) |
| @@ -228,43 +227,37 @@ Except for Lisp syntax this is the same as `reb-regexp'.") | |||
| 228 | (define-key map "\C-c\C-e" 'reb-enter-subexp-mode) | 227 | (define-key map "\C-c\C-e" 'reb-enter-subexp-mode) |
| 229 | (define-key map "\C-c\C-b" 'reb-change-target-buffer) | 228 | (define-key map "\C-c\C-b" 'reb-change-target-buffer) |
| 230 | (define-key map "\C-c\C-u" 'reb-force-update) | 229 | (define-key map "\C-c\C-u" 'reb-force-update) |
| 231 | (define-key map [menu-bar reb-mode] (cons "Re-Builder" menu-map)) | ||
| 232 | (define-key menu-map [rq] | ||
| 233 | '(menu-item "Quit" reb-quit | ||
| 234 | :help "Quit the RE Builder mode")) | ||
| 235 | (define-key menu-map [div1] '(menu-item "--")) | ||
| 236 | (define-key menu-map [rt] | ||
| 237 | '(menu-item "Case sensitive" reb-toggle-case | ||
| 238 | :button (:toggle . (with-current-buffer | ||
| 239 | reb-target-buffer | ||
| 240 | (null case-fold-search))) | ||
| 241 | :help "Toggle case sensitivity of searches for RE Builder target buffer")) | ||
| 242 | (define-key menu-map [rb] | ||
| 243 | '(menu-item "Change target buffer..." reb-change-target-buffer | ||
| 244 | :help "Change the target buffer and display it in the target window")) | ||
| 245 | (define-key menu-map [rs] | ||
| 246 | '(menu-item "Change syntax..." reb-change-syntax | ||
| 247 | :help "Change the syntax used by the RE Builder")) | ||
| 248 | (define-key menu-map [div2] '(menu-item "--")) | ||
| 249 | (define-key menu-map [re] | ||
| 250 | '(menu-item "Enter subexpression mode" reb-enter-subexp-mode | ||
| 251 | :help "Enter the subexpression mode in the RE Builder")) | ||
| 252 | (define-key menu-map [ru] | ||
| 253 | '(menu-item "Force update" reb-force-update | ||
| 254 | :help "Force an update in the RE Builder target window without a match limit")) | ||
| 255 | (define-key menu-map [rn] | ||
| 256 | '(menu-item "Go to next match" reb-next-match | ||
| 257 | :help "Go to next match in the RE Builder target window")) | ||
| 258 | (define-key menu-map [rp] | ||
| 259 | '(menu-item "Go to previous match" reb-prev-match | ||
| 260 | :help "Go to previous match in the RE Builder target window")) | ||
| 261 | (define-key menu-map [div3] '(menu-item "--")) | ||
| 262 | (define-key menu-map [rc] | ||
| 263 | '(menu-item "Copy current RE" reb-copy | ||
| 264 | :help "Copy current RE into the kill ring for later insertion")) | ||
| 265 | map) | 230 | map) |
| 266 | "Keymap used by the RE Builder.") | 231 | "Keymap used by the RE Builder.") |
| 267 | 232 | ||
| 233 | (easy-menu-define reb-mode-menu reb-mode-map | ||
| 234 | "Menu for the RE Builder." | ||
| 235 | '("Re-Builder" | ||
| 236 | ["Copy current RE" reb-copy | ||
| 237 | :help "Copy current RE into the kill ring for later insertion"] | ||
| 238 | "---" | ||
| 239 | ["Go to previous match" reb-prev-match | ||
| 240 | :help "Go to previous match in the RE Builder target window"] | ||
| 241 | ["Go to next match" reb-next-match | ||
| 242 | :help "Go to next match in the RE Builder target window"] | ||
| 243 | ["Force update" reb-force-update | ||
| 244 | :help "Force an update in the RE Builder target window without a match limit"] | ||
| 245 | ["Enter subexpression mode" reb-enter-subexp-mode | ||
| 246 | :help "Enter the subexpression mode in the RE Builder"] | ||
| 247 | "---" | ||
| 248 | ["Change syntax..." reb-change-syntax | ||
| 249 | :help "Change the syntax used by the RE Builder"] | ||
| 250 | ["Change target buffer..." reb-change-target-buffer | ||
| 251 | :help "Change the target buffer and display it in the target window"] | ||
| 252 | ["Case sensitive" reb-toggle-case | ||
| 253 | :button (:toggle . (with-current-buffer | ||
| 254 | reb-target-buffer | ||
| 255 | (null case-fold-search))) | ||
| 256 | :help "Toggle case sensitivity of searches for RE Builder target buffer"] | ||
| 257 | "---" | ||
| 258 | ["Quit" reb-quit | ||
| 259 | :help "Quit the RE Builder mode"])) | ||
| 260 | |||
| 268 | (define-derived-mode reb-mode nil "RE Builder" | 261 | (define-derived-mode reb-mode nil "RE Builder" |
| 269 | "Major mode for interactively building Regular Expressions." | 262 | "Major mode for interactively building Regular Expressions." |
| 270 | (setq-local blink-matching-paren nil) | 263 | (setq-local blink-matching-paren nil) |
| @@ -368,7 +361,6 @@ matching parts of the target buffer will be highlighted." | |||
| 368 | (defun reb-change-target-buffer (buf) | 361 | (defun reb-change-target-buffer (buf) |
| 369 | "Change the target buffer and display it in the target window." | 362 | "Change the target buffer and display it in the target window." |
| 370 | (interactive "bSet target buffer to: ") | 363 | (interactive "bSet target buffer to: ") |
| 371 | |||
| 372 | (let ((buffer (get-buffer buf))) | 364 | (let ((buffer (get-buffer buf))) |
| 373 | (if (not buffer) | 365 | (if (not buffer) |
| 374 | (error "No such buffer") | 366 | (error "No such buffer") |
| @@ -381,7 +373,6 @@ matching parts of the target buffer will be highlighted." | |||
| 381 | (defun reb-force-update () | 373 | (defun reb-force-update () |
| 382 | "Force an update in the RE Builder target window without a match limit." | 374 | "Force an update in the RE Builder target window without a match limit." |
| 383 | (interactive) | 375 | (interactive) |
| 384 | |||
| 385 | (let ((reb-auto-match-limit nil)) | 376 | (let ((reb-auto-match-limit nil)) |
| 386 | (reb-update-overlays | 377 | (reb-update-overlays |
| 387 | (if reb-subexp-mode reb-subexp-displayed nil)))) | 378 | (if reb-subexp-mode reb-subexp-displayed nil)))) |
| @@ -389,7 +380,6 @@ matching parts of the target buffer will be highlighted." | |||
| 389 | (defun reb-quit () | 380 | (defun reb-quit () |
| 390 | "Quit the RE Builder mode." | 381 | "Quit the RE Builder mode." |
| 391 | (interactive) | 382 | (interactive) |
| 392 | |||
| 393 | (setq reb-subexp-mode nil | 383 | (setq reb-subexp-mode nil |
| 394 | reb-subexp-displayed nil) | 384 | reb-subexp-displayed nil) |
| 395 | (reb-delete-overlays) | 385 | (reb-delete-overlays) |
| @@ -399,7 +389,6 @@ matching parts of the target buffer will be highlighted." | |||
| 399 | (defun reb-next-match () | 389 | (defun reb-next-match () |
| 400 | "Go to next match in the RE Builder target window." | 390 | "Go to next match in the RE Builder target window." |
| 401 | (interactive) | 391 | (interactive) |
| 402 | |||
| 403 | (reb-assert-buffer-in-window) | 392 | (reb-assert-buffer-in-window) |
| 404 | (with-selected-window reb-target-window | 393 | (with-selected-window reb-target-window |
| 405 | (if (not (re-search-forward reb-regexp (point-max) t)) | 394 | (if (not (re-search-forward reb-regexp (point-max) t)) |
| @@ -411,7 +400,6 @@ matching parts of the target buffer will be highlighted." | |||
| 411 | (defun reb-prev-match () | 400 | (defun reb-prev-match () |
| 412 | "Go to previous match in the RE Builder target window." | 401 | "Go to previous match in the RE Builder target window." |
| 413 | (interactive) | 402 | (interactive) |
| 414 | |||
| 415 | (reb-assert-buffer-in-window) | 403 | (reb-assert-buffer-in-window) |
| 416 | (with-selected-window reb-target-window | 404 | (with-selected-window reb-target-window |
| 417 | (let ((p (point))) | 405 | (let ((p (point))) |
| @@ -426,7 +414,6 @@ matching parts of the target buffer will be highlighted." | |||
| 426 | (defun reb-toggle-case () | 414 | (defun reb-toggle-case () |
| 427 | "Toggle case sensitivity of searches for RE Builder target buffer." | 415 | "Toggle case sensitivity of searches for RE Builder target buffer." |
| 428 | (interactive) | 416 | (interactive) |
| 429 | |||
| 430 | (with-current-buffer reb-target-buffer | 417 | (with-current-buffer reb-target-buffer |
| 431 | (setq case-fold-search (not case-fold-search))) | 418 | (setq case-fold-search (not case-fold-search))) |
| 432 | (reb-update-modestring) | 419 | (reb-update-modestring) |
| @@ -435,7 +422,6 @@ matching parts of the target buffer will be highlighted." | |||
| 435 | (defun reb-copy () | 422 | (defun reb-copy () |
| 436 | "Copy current RE into the kill ring for later insertion." | 423 | "Copy current RE into the kill ring for later insertion." |
| 437 | (interactive) | 424 | (interactive) |
| 438 | |||
| 439 | (reb-update-regexp) | 425 | (reb-update-regexp) |
| 440 | (let ((re (with-output-to-string | 426 | (let ((re (with-output-to-string |
| 441 | (print (reb-target-binding reb-regexp))))) | 427 | (print (reb-target-binding reb-regexp))))) |
| @@ -503,7 +489,6 @@ Optional argument SYNTAX must be specified if called non-interactively." | |||
| 503 | (defun reb-do-update (&optional subexp) | 489 | (defun reb-do-update (&optional subexp) |
| 504 | "Update matches in the RE Builder target window. | 490 | "Update matches in the RE Builder target window. |
| 505 | If SUBEXP is non-nil mark only the corresponding sub-expressions." | 491 | If SUBEXP is non-nil mark only the corresponding sub-expressions." |
| 506 | |||
| 507 | (reb-assert-buffer-in-window) | 492 | (reb-assert-buffer-in-window) |
| 508 | (reb-update-regexp) | 493 | (reb-update-regexp) |
| 509 | (reb-update-overlays subexp)) | 494 | (reb-update-overlays subexp)) |
| @@ -541,7 +526,6 @@ optional fourth argument FORCE is non-nil." | |||
| 541 | 526 | ||
| 542 | (defun reb-assert-buffer-in-window () | 527 | (defun reb-assert-buffer-in-window () |
| 543 | "Assert that `reb-target-buffer' is displayed in `reb-target-window'." | 528 | "Assert that `reb-target-buffer' is displayed in `reb-target-window'." |
| 544 | |||
| 545 | (if (not (eq reb-target-buffer (window-buffer reb-target-window))) | 529 | (if (not (eq reb-target-buffer (window-buffer reb-target-window))) |
| 546 | (set-window-buffer reb-target-window reb-target-buffer))) | 530 | (set-window-buffer reb-target-window reb-target-buffer))) |
| 547 | 531 | ||
| @@ -560,7 +544,6 @@ optional fourth argument FORCE is non-nil." | |||
| 560 | (defun reb-display-subexp (&optional subexp) | 544 | (defun reb-display-subexp (&optional subexp) |
| 561 | "Highlight only subexpression SUBEXP in the RE Builder." | 545 | "Highlight only subexpression SUBEXP in the RE Builder." |
| 562 | (interactive) | 546 | (interactive) |
| 563 | |||
| 564 | (setq reb-subexp-displayed | 547 | (setq reb-subexp-displayed |
| 565 | (or subexp (string-to-number (format "%c" last-command-event)))) | 548 | (or subexp (string-to-number (format "%c" last-command-event)))) |
| 566 | (reb-update-modestring) | 549 | (reb-update-modestring) |
| @@ -568,7 +551,6 @@ optional fourth argument FORCE is non-nil." | |||
| 568 | 551 | ||
| 569 | (defun reb-kill-buffer () | 552 | (defun reb-kill-buffer () |
| 570 | "When the RE Builder buffer is killed make sure no overlays stay around." | 553 | "When the RE Builder buffer is killed make sure no overlays stay around." |
| 571 | |||
| 572 | (when (reb-mode-buffer-p) | 554 | (when (reb-mode-buffer-p) |
| 573 | (reb-delete-overlays))) | 555 | (reb-delete-overlays))) |
| 574 | 556 | ||
| @@ -600,7 +582,6 @@ optional fourth argument FORCE is non-nil." | |||
| 600 | 582 | ||
| 601 | (defun reb-insert-regexp () | 583 | (defun reb-insert-regexp () |
| 602 | "Insert current RE." | 584 | "Insert current RE." |
| 603 | |||
| 604 | (let ((re (or (reb-target-binding reb-regexp) | 585 | (let ((re (or (reb-target-binding reb-regexp) |
| 605 | (reb-empty-regexp)))) | 586 | (reb-empty-regexp)))) |
| 606 | (cond ((eq reb-re-syntax 'read) | 587 | (cond ((eq reb-re-syntax 'read) |
| @@ -636,7 +617,6 @@ Return t if the (cooked) expression changed." | |||
| 636 | ;; And now the real core of the whole thing | 617 | ;; And now the real core of the whole thing |
| 637 | (defun reb-count-subexps (re) | 618 | (defun reb-count-subexps (re) |
| 638 | "Return number of sub-expressions in the regexp RE." | 619 | "Return number of sub-expressions in the regexp RE." |
| 639 | |||
| 640 | (let ((i 0) (beg 0)) | 620 | (let ((i 0) (beg 0)) |
| 641 | (while (string-match "\\\\(" re beg) | 621 | (while (string-match "\\\\(" re beg) |
| 642 | (setq i (1+ i) | 622 | (setq i (1+ i) |