2011-04-04 11:35:16 +02:00
|
|
|
;;; re-builder.el --- building Regexps with visual feedback -*- lexical-binding: t -*-
|
2000-03-09 20:28:18 +00:00
|
|
|
|
2022-01-01 02:45:51 -05:00
|
|
|
;; Copyright (C) 1999-2022 Free Software Foundation, Inc.
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
;; Author: Detlev Zundel <dzu@gnu.org>
|
|
|
|
;; Keywords: matching, lisp, tools
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 03:21:21 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2000-03-09 20:28:18 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 03:21:21 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; When I have to come up with regular expressions that are more
|
|
|
|
;; complex than simple string matchers, especially if they contain sub
|
|
|
|
;; expressions, I find myself spending quite some time in the
|
|
|
|
;; `development cycle'. `re-builder' aims to shorten this time span
|
|
|
|
;; so I can get on with the more interesting bits.
|
|
|
|
|
|
|
|
;; With it you can have immediate visual feedback about how well the
|
|
|
|
;; regexp behaves to your expectations on the intended data.
|
|
|
|
|
|
|
|
;; When called up `re-builder' attaches itself to the current buffer
|
|
|
|
;; which becomes its target buffer, where all the matching is done.
|
|
|
|
;; The active window is split so you have a view on the data while
|
|
|
|
;; authoring the RE. If the edited expression is valid the matches in
|
|
|
|
;; the target buffer are marked automatically with colored overlays
|
|
|
|
;; (for non-color displays see below) giving you feedback over the
|
|
|
|
;; extents of the matched (sub) expressions. The (non-)validity is
|
2012-06-02 18:56:09 +08:00
|
|
|
;; shown only in the mode line without throwing the errors at you. If
|
2000-03-09 20:28:18 +00:00
|
|
|
;; you want to know the reason why RE Builder considers it as invalid
|
|
|
|
;; call `reb-force-update' ("\C-c\C-u") which should reveal the error.
|
|
|
|
|
2001-11-20 18:20:56 +00:00
|
|
|
;; The target buffer can be changed with `reb-change-target-buffer'
|
2004-08-17 09:58:06 +00:00
|
|
|
;; ("\C-c\C-b"). Changing the target buffer automatically removes
|
2001-11-20 18:20:56 +00:00
|
|
|
;; the overlays from the old buffer and displays the new one in the
|
|
|
|
;; target window.
|
|
|
|
|
2000-03-09 20:28:18 +00:00
|
|
|
;; The `re-builder' keeps the focus while updating the matches in the
|
|
|
|
;; target buffer so corrections are easy to incorporate. If you are
|
|
|
|
;; satisfied with the result you can paste the RE to the kill-ring
|
|
|
|
;; with `reb-copy' ("\C-c\C-w"), quit the `re-builder' ("\C-c\C-q")
|
|
|
|
;; and use it wherever you need it.
|
|
|
|
|
|
|
|
;; As the automatic updates can take some time on large buffers, they
|
|
|
|
;; can be limited by `reb-auto-match-limit' so that they should not
|
|
|
|
;; have a negative impact on the editing. Setting it to nil makes
|
|
|
|
;; even the auto updates go all the way. Forcing an update overrides
|
|
|
|
;; this limit allowing an easy way to see all matches.
|
|
|
|
|
2010-12-26 18:17:09 -05:00
|
|
|
;; Currently `re-builder' understands three different forms of input,
|
|
|
|
;; namely `read', `string', and `rx' syntax. Read
|
2000-03-09 20:28:18 +00:00
|
|
|
;; 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
|
2017-08-04 18:36:05 -04:00
|
|
|
;; somewhat. The `rx' syntax allows editing of symbolic regular
|
|
|
|
;; expressions supported by the package of the same name.
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
;; Editing symbolic expressions is done through a major mode derived
|
|
|
|
;; from `emacs-lisp-mode' so you'll get all the good stuff like
|
|
|
|
;; automatic indentation and font-locking etc.
|
|
|
|
|
|
|
|
;; When editing a symbolic regular expression, only the first
|
|
|
|
;; expression in the RE Builder buffer is considered, which helps
|
|
|
|
;; limiting the extent of the expression like the `"'s do for the text
|
2010-12-26 18:17:09 -05:00
|
|
|
;; modes. For the `rx' syntax the function `rx-to-string' is applied to
|
2000-03-09 20:28:18 +00:00
|
|
|
;; the evaluated expression read. So you can use quoted arguments
|
|
|
|
;; with something like '("findme") or you can construct arguments to
|
|
|
|
;; your hearts delight with a valid ELisp expression. (The compiled
|
|
|
|
;; string form will be copied by `reb-copy') If you want to take
|
|
|
|
;; a glance at the corresponding string you can temporarily change the
|
|
|
|
;; input syntax.
|
|
|
|
|
|
|
|
;; Changing the input syntax is transparent (for the obvious exception
|
|
|
|
;; non-symbolic -> symbolic) so you can change your mind as often as
|
|
|
|
;; you like.
|
|
|
|
|
|
|
|
;; There is also a shortcut function for toggling the
|
|
|
|
;; `case-fold-search' variable in the target buffer with an immediate
|
|
|
|
;; update.
|
|
|
|
|
|
|
|
|
|
|
|
;; Q: But what if my display cannot show colored overlays?
|
|
|
|
;; A: Then the cursor will flash around the matched text making it stand
|
|
|
|
;; out.
|
|
|
|
|
|
|
|
;; Q: But how can I then make out the sub-expressions?
|
2020-09-21 13:29:10 +02:00
|
|
|
;; A: That's where the `sub-expression mode' comes in. In it only the
|
2000-03-09 20:28:18 +00:00
|
|
|
;; digit keys are assigned to perform an update that will flash the
|
|
|
|
;; corresponding subexp only.
|
|
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2006-05-05 13:02:14 +00:00
|
|
|
;; User customizable variables
|
2000-03-09 20:28:18 +00:00
|
|
|
(defgroup re-builder nil
|
|
|
|
"Options for the RE Builder."
|
|
|
|
:group 'lisp
|
|
|
|
:prefix "reb-")
|
|
|
|
|
|
|
|
(defcustom reb-blink-delay 0.5
|
(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 16:49:22 +00:00
|
|
|
"Seconds to blink cursor for next/previous match in RE Builder."
|
2000-03-09 20:28:18 +00:00
|
|
|
:group 're-builder
|
|
|
|
:type 'number)
|
|
|
|
|
|
|
|
(defcustom reb-mode-hook nil
|
(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 16:49:22 +00:00
|
|
|
"Hooks to run on entering RE Builder mode."
|
2000-03-09 20:28:18 +00:00
|
|
|
:group 're-builder
|
|
|
|
:type 'hook)
|
|
|
|
|
|
|
|
(defcustom reb-re-syntax 'read
|
(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 16:49:22 +00:00
|
|
|
"Syntax for the REs in the RE Builder.
|
2010-12-26 18:17:09 -05:00
|
|
|
Can either be `read', `string', or `rx'."
|
2000-03-09 20:28:18 +00:00
|
|
|
:group 're-builder
|
|
|
|
:type '(choice (const :tag "Read syntax" read)
|
|
|
|
(const :tag "String syntax" string)
|
2007-03-05 20:27:34 +00:00
|
|
|
(const :tag "`rx' syntax" rx)))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
(defcustom reb-auto-match-limit 200
|
(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 16:49:22 +00:00
|
|
|
"Positive integer limiting the matches for RE Builder auto updates.
|
2000-03-09 20:28:18 +00:00
|
|
|
Set it to nil if you don't want limits here."
|
|
|
|
:group 're-builder
|
|
|
|
:type '(restricted-sexp :match-alternatives
|
|
|
|
(integerp 'nil)))
|
|
|
|
|
|
|
|
|
|
|
|
(defface reb-match-0
|
2001-11-22 14:55:55 +00:00
|
|
|
'((((class color) (background light))
|
|
|
|
:background "lightblue")
|
|
|
|
(((class color) (background dark))
|
|
|
|
:background "steelblue4")
|
|
|
|
(t
|
|
|
|
:inverse-video t))
|
2000-03-09 20:28:18 +00:00
|
|
|
"Used for displaying the whole match."
|
|
|
|
:group 're-builder)
|
|
|
|
|
|
|
|
(defface reb-match-1
|
2001-11-22 14:55:55 +00:00
|
|
|
'((((class color) (background light))
|
|
|
|
:background "aquamarine")
|
|
|
|
(((class color) (background dark))
|
|
|
|
:background "blue3")
|
|
|
|
(t
|
|
|
|
:inverse-video t))
|
2000-03-09 20:28:18 +00:00
|
|
|
"Used for displaying the first matching subexpression."
|
|
|
|
:group 're-builder)
|
|
|
|
|
|
|
|
(defface reb-match-2
|
2001-11-22 14:55:55 +00:00
|
|
|
'((((class color) (background light))
|
|
|
|
:background "springgreen")
|
|
|
|
(((class color) (background dark))
|
|
|
|
:background "chartreuse4")
|
|
|
|
(t
|
|
|
|
:inverse-video t))
|
2000-03-09 20:28:18 +00:00
|
|
|
"Used for displaying the second matching subexpression."
|
|
|
|
:group 're-builder)
|
|
|
|
|
|
|
|
(defface reb-match-3
|
* mh-customize.el (mh-speedbar-selected-folder-face): Special case
high number of colors displays.
* textmodes/table.el (table-cell-face): Add special case for
displays supporting a high number of colors.
* progmodes/vhdl-mode.el (vhdl-font-lock-prompt-face)
(vhdl-font-lock-reserved-words-face)
(vhdl-speedbar-architecture-face)
(vhdl-speedbar-instantiation-face)
(vhdl-speedbar-architecture-selected-face)
(vhdl-speedbar-instantiation-selected-face): Likewise.
* progmodes/sh-script.el (sh-heredoc-face): Likewise.
* progmodes/idlw-help.el (idlwave-help-link-face): Likewise.
* progmodes/ebrowse.el (ebrowse-tree-mark-face)
(ebrowse-root-class-face, ebrowse-member-attribute-face)
(ebrowse-progress-face): Likewise.
* progmodes/compile.el (compilation-info-face): Likewise.
* progmodes/cc-fonts.el (c-invalid-face): Likewise.
* emacs-lisp/re-builder.el (reb-match-3): Likewise.
* calendar/calendar.el (diary-face): Likewise.
* woman.el (woman-italic-face, woman-bold-face)
(woman-unknown-face): Likewise.
* wid-edit.el (widget-button-pressed-face): Likewise.
* whitespace.el (whitespace-highlight-face): Likewise.
* smerge-mode.el (smerge-mine-face, smerge-base-face): Likewise.
* pcvs-info.el (cvs-marked-face): Likewise.
* info.el (info-xref): Likewise.
* ido.el (ido-subdir-face, ido-indicator-face): Likewise.
* hilit-chg.el (highlight-changes-face)
(highlight-changes-delete-face): Likewise.
* hi-lock.el (hi-yellow, hi-green, hi-blue-b, hi-green-b)
(hi-red-b): Likewise.
* generic-x.el (show-tabs-tab-face, show-tabs-space-face): Likewise.
* font-lock.el (font-lock-keyword-face)
(font-lock-function-name-face, font-lock-warning-face): Likewise.
* cus-edit.el (custom-invalid-face, custom-modified-face)
(custom-set-face, custom-changed-face, custom-variable-tag-face)
(custom-group-tag-face-1, custom-group-tag-face): Likewise.
* comint.el (comint-highlight-prompt): Likewise.
2005-04-08 14:26:13 +00:00
|
|
|
'((((min-colors 88) (class color) (background light))
|
|
|
|
:background "yellow1")
|
|
|
|
(((class color) (background light))
|
2001-11-22 14:55:55 +00:00
|
|
|
:background "yellow")
|
|
|
|
(((class color) (background dark))
|
|
|
|
:background "sienna4")
|
|
|
|
(t
|
|
|
|
:inverse-video t))
|
2000-03-09 20:28:18 +00:00
|
|
|
"Used for displaying the third matching subexpression."
|
|
|
|
:group 're-builder)
|
|
|
|
|
|
|
|
;; Internal variables below
|
|
|
|
(defvar reb-mode nil
|
|
|
|
"Enables the RE Builder minor mode.")
|
|
|
|
|
|
|
|
(defvar reb-target-buffer nil
|
|
|
|
"Buffer to which the RE is applied to.")
|
|
|
|
|
|
|
|
(defvar reb-target-window nil
|
|
|
|
"Window to which the RE is applied to.")
|
|
|
|
|
2021-01-31 14:55:53 +01:00
|
|
|
(defvar-local reb-regexp nil
|
2000-03-09 20:28:18 +00:00
|
|
|
"Last regexp used by RE Builder.")
|
|
|
|
|
2021-01-31 14:55:53 +01:00
|
|
|
(defvar-local reb-regexp-src nil
|
2000-03-09 20:28:18 +00:00
|
|
|
"Last regexp used by RE Builder before processing it.
|
|
|
|
Except for Lisp syntax this is the same as `reb-regexp'.")
|
|
|
|
|
2021-01-31 14:55:53 +01:00
|
|
|
(defvar-local reb-overlays nil
|
2000-03-09 20:28:18 +00:00
|
|
|
"List of overlays of the RE Builder.")
|
|
|
|
|
|
|
|
(defvar reb-window-config nil
|
|
|
|
"Old window configuration.")
|
|
|
|
|
|
|
|
(defvar reb-subexp-mode nil
|
|
|
|
"Indicates whether sub-exp mode is active.")
|
|
|
|
|
|
|
|
(defvar reb-subexp-displayed nil
|
|
|
|
"Indicates which sub-exp is active.")
|
|
|
|
|
|
|
|
(defvar reb-mode-string ""
|
|
|
|
"String in mode line for additional info.")
|
|
|
|
|
|
|
|
(defvar reb-valid-string ""
|
|
|
|
"String in mode line showing validity of RE.")
|
|
|
|
|
|
|
|
(defconst reb-buffer "*RE-Builder*"
|
|
|
|
"Buffer to use for the RE Builder.")
|
|
|
|
|
|
|
|
;; Define the local "\C-c" keymap
|
2022-07-04 18:42:26 +02:00
|
|
|
(defvar-keymap reb-mode-map
|
|
|
|
:doc "Keymap used by the RE Builder."
|
|
|
|
"C-c C-c" #'reb-toggle-case
|
|
|
|
"C-c C-q" #'reb-quit
|
|
|
|
"C-c C-w" #'reb-copy
|
|
|
|
"C-c C-s" #'reb-next-match
|
|
|
|
"C-c C-r" #'reb-prev-match
|
|
|
|
"C-c C-i" #'reb-change-syntax
|
|
|
|
"C-c C-e" #'reb-enter-subexp-mode
|
|
|
|
"C-c C-b" #'reb-change-target-buffer
|
|
|
|
"C-c C-u" #'reb-force-update)
|
2000-03-09 20:28:18 +00:00
|
|
|
|
2021-02-20 07:34:52 +01:00
|
|
|
(easy-menu-define reb-mode-menu reb-mode-map
|
|
|
|
"Menu for the RE Builder."
|
|
|
|
'("Re-Builder"
|
|
|
|
["Copy current RE" reb-copy
|
|
|
|
:help "Copy current RE into the kill ring for later insertion"]
|
|
|
|
"---"
|
|
|
|
["Go to previous match" reb-prev-match
|
|
|
|
:help "Go to previous match in the RE Builder target window"]
|
|
|
|
["Go to next match" reb-next-match
|
|
|
|
:help "Go to next match in the RE Builder target window"]
|
|
|
|
["Force update" reb-force-update
|
|
|
|
:help "Force an update in the RE Builder target window without a match limit"]
|
|
|
|
["Enter subexpression mode" reb-enter-subexp-mode
|
|
|
|
:help "Enter the subexpression mode in the RE Builder"]
|
|
|
|
"---"
|
|
|
|
["Change syntax..." reb-change-syntax
|
|
|
|
:help "Change the syntax used by the RE Builder"]
|
|
|
|
["Change target buffer..." reb-change-target-buffer
|
|
|
|
:help "Change the target buffer and display it in the target window"]
|
|
|
|
["Case sensitive" reb-toggle-case
|
2021-02-21 10:10:03 +01:00
|
|
|
:style toggle
|
|
|
|
:selected (with-current-buffer reb-target-buffer
|
|
|
|
(null case-fold-search))
|
2021-02-20 07:34:52 +01:00
|
|
|
:help "Toggle case sensitivity of searches for RE Builder target buffer"]
|
|
|
|
"---"
|
|
|
|
["Quit" reb-quit
|
|
|
|
:help "Quit the RE Builder mode"]))
|
|
|
|
|
2008-11-29 20:25:54 +00:00
|
|
|
(define-derived-mode reb-mode nil "RE Builder"
|
|
|
|
"Major mode for interactively building Regular Expressions."
|
2020-12-04 19:12:12 +01:00
|
|
|
(setq-local blink-matching-paren nil)
|
2008-11-29 20:25:54 +00:00
|
|
|
(reb-mode-common))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
2022-07-04 18:42:26 +02:00
|
|
|
(defvar-keymap reb-lisp-mode-map
|
|
|
|
;; Use the same "\C-c" keymap as `reb-mode' and use font-locking from
|
|
|
|
;; `emacs-lisp-mode'
|
|
|
|
"C-c" (keymap-lookup reb-mode-map "C-c"))
|
Move keymap initialization into declaration.
* lisp/textmodes/enriched.el (enriched-mode-map):
* lisp/textmodes/bib-mode.el (bib-mode-map):
* lisp/term/lk201.el (lk201-function-map):
* lisp/tar-mode.el (tar-mode-map):
* lisp/replace.el (occur-mode-map):
* lisp/progmodes/idlwave.el (idlwave-rinfo-mouse-map, idlwave-rinfo-map):
* lisp/progmodes/idlw-help.el (idlwave-help-mode-map):
* lisp/progmodes/gdb-mi.el (gdb-memory-format-menu, gdb-memory-unit-menu):
* lisp/play/solitaire.el (solitaire-mode-map):
* lisp/play/snake.el (snake-mode-map, snake-null-map):
* lisp/play/pong.el (pong-mode-map):
* lisp/play/handwrite.el (menu-bar-handwrite-map):
* lisp/play/gametree.el (gametree-mode-map):
* lisp/net/rcirc.el (rcirc-mode-map, rcirc-browse-url-map
(rcirc-multiline-minor-mode-map, rcirc-track-minor-mode-map):
* lisp/net/newst-plainview.el (newsticker-menu, newsticker-mode-map)
(newsticker--url-keymap):
* lisp/net/net-utils.el (nslookup-mode-map, ftp-mode-map):
* lisp/menu-bar.el (menu-bar-file-menu, menu-bar-i-search-menu)
(menu-bar-search-menu, menu-bar-replace-menu, menu-bar-goto-menu)
(menu-bar-edit-menu, menu-bar-custom-menu)
(menu-bar-showhide-fringe-ind-menu, menu-bar-showhide-fringe-menu)
(menu-bar-showhide-scroll-bar-menu, menu-bar-showhide-menu)
(menu-bar-line-wrapping-menu, menu-bar-options-menu)
(menu-bar-games-menu, menu-bar-encryption-decryption-menu)
(menu-bar-tools-menu, menu-bar-describe-menu)
(menu-bar-search-documentation-menu, menu-bar-manuals-menu)
(menu-bar-help-menu):
* lisp/mail/rmailsum.el (rmail-summary-mode-map):
* lisp/kmacro.el (kmacro-step-edit-map):
* lisp/ibuffer.el (ibuffer-mode-groups-popup, ibuffer-mode-map)
(ibuffer-mode-operate-map):
* lisp/hi-lock.el (hi-lock-menu, hi-lock-map):
* lisp/emulation/vip.el (vip-mode-map):
* lisp/emacs-lisp/re-builder.el (reb-lisp-mode-map):
* lisp/bookmark.el (bookmark-bmenu-mode-map):
* lisp/help-mode.el (help-mode-map):
* lisp/erc/erc-list.el (erc-list-menu-mode-map):
* lisp/org/org-remember.el (org-remember-mode-map):
* lisp/org/org-src.el (org-src-mode-map): Move initialization into declaration.
2011-02-10 11:56:00 -05:00
|
|
|
|
2000-03-09 20:28:18 +00:00
|
|
|
(define-derived-mode reb-lisp-mode
|
|
|
|
emacs-lisp-mode "RE Builder Lisp"
|
2001-11-18 01:44:08 +00:00
|
|
|
"Major mode for interactively building symbolic Regular Expressions."
|
2010-07-28 01:38:46 +02:00
|
|
|
;; Pull in packages as needed
|
2021-12-03 17:18:33 +01:00
|
|
|
(when (eq reb-re-syntax 'rx) ; rx-to-string is autoloaded
|
|
|
|
(require 'rx)) ; require rx anyway
|
2000-03-09 20:28:18 +00:00
|
|
|
(reb-mode-common))
|
|
|
|
|
2022-07-04 18:42:26 +02:00
|
|
|
(defvar-keymap reb-subexp-mode-map
|
|
|
|
:doc "Keymap used by the RE Builder for the subexpression mode."
|
|
|
|
:full t :suppress t
|
|
|
|
;; Again share the "\C-c" keymap for the commands
|
|
|
|
"C-c" (keymap-lookup reb-mode-map "C-c")
|
|
|
|
"q" #'reb-quit-subexp-mode
|
|
|
|
"0" #'reb-display-subexp
|
|
|
|
"1" #'reb-display-subexp
|
|
|
|
"2" #'reb-display-subexp
|
|
|
|
"3" #'reb-display-subexp
|
|
|
|
"4" #'reb-display-subexp
|
|
|
|
"5" #'reb-display-subexp
|
|
|
|
"6" #'reb-display-subexp
|
|
|
|
"7" #'reb-display-subexp
|
|
|
|
"8" #'reb-display-subexp
|
|
|
|
"9" #'reb-display-subexp)
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
(defun reb-mode-common ()
|
2020-09-23 13:35:55 +02:00
|
|
|
"Setup functions common to functions `reb-mode' and `reb-lisp-mode'."
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
(setq reb-mode-string ""
|
|
|
|
reb-valid-string ""
|
|
|
|
mode-line-buffer-identification
|
|
|
|
'(25 . ("%b" reb-mode-string reb-valid-string)))
|
|
|
|
(reb-update-modestring)
|
(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 16:49:22 +00:00
|
|
|
(add-hook 'after-change-functions 'reb-auto-update nil t)
|
2000-03-09 20:28:18 +00:00
|
|
|
;; At least make the overlays go away if the buffer is killed
|
(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 16:49:22 +00:00
|
|
|
(add-hook 'kill-buffer-hook 'reb-kill-buffer nil t)
|
2000-03-09 20:28:18 +00:00
|
|
|
(reb-auto-update nil nil nil))
|
|
|
|
|
|
|
|
(defun reb-color-display-p ()
|
|
|
|
"Return t if display is capable of displaying colors."
|
2019-10-04 02:20:28 +02:00
|
|
|
(eq 'color (frame-parameter nil 'display-type)))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
(defsubst reb-lisp-syntax-p ()
|
2021-12-03 16:42:24 +01:00
|
|
|
"Return non-nil if RE Builder uses `rx' syntax."
|
|
|
|
(eq reb-re-syntax 'rx))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
(defmacro reb-target-binding (symbol)
|
|
|
|
"Return binding for SYMBOL in the RE Builder target buffer."
|
|
|
|
`(with-current-buffer reb-target-buffer ,symbol))
|
|
|
|
|
2005-07-24 02:29:14 +00:00
|
|
|
(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))
|
2008-11-28 23:54:23 +00:00
|
|
|
(t (reb-mode)))
|
2019-06-27 19:08:42 +02:00
|
|
|
(reb-restart-font-lock)
|
2022-02-22 14:43:35 +01:00
|
|
|
;; When using `rx' syntax, the initial syntax () is invalid. But
|
|
|
|
;; don't signal an error in that case.
|
|
|
|
(ignore-errors
|
|
|
|
(reb-do-update)))
|
2005-07-24 02:29:14 +00:00
|
|
|
|
(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 16:49:22 +00:00
|
|
|
(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)))
|
|
|
|
|
2005-02-27 10:35:51 +00:00
|
|
|
;;; This is to help people find this in Apropos.
|
|
|
|
;;;###autoload
|
2005-07-21 09:10:49 +00:00
|
|
|
(defalias 'regexp-builder 're-builder)
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun re-builder ()
|
2011-05-28 14:48:41 -04:00
|
|
|
"Construct a regexp interactively.
|
|
|
|
This command makes the current buffer the \"target\" buffer of
|
|
|
|
the regexp builder. It displays a buffer named \"*RE-Builder*\"
|
|
|
|
in another window, initially containing an empty regexp.
|
2000-03-09 20:28:18 +00:00
|
|
|
|
2011-05-28 14:48:41 -04:00
|
|
|
As you edit the regexp in the \"*RE-Builder*\" buffer, the
|
2021-05-08 13:59:03 +02:00
|
|
|
matching parts of the target buffer will be highlighted.
|
|
|
|
|
|
|
|
Case-sensitivity can be toggled with \\[reb-toggle-case]. The
|
|
|
|
regexp builder supports three different forms of input which can
|
|
|
|
be set with \\[reb-change-syntax]. More options and details are
|
2021-05-08 15:07:38 +01:00
|
|
|
provided in the Commentary section of this library."
|
2011-05-28 14:48:41 -04:00
|
|
|
(interactive)
|
2001-11-20 18:26:55 +00:00
|
|
|
(if (and (string= (buffer-name) reb-buffer)
|
(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 16:49:22 +00:00
|
|
|
(reb-mode-buffer-p))
|
2001-11-20 18:26:55 +00:00
|
|
|
(message "Already in the RE Builder")
|
(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 16:49:22 +00:00
|
|
|
(when reb-target-buffer
|
|
|
|
(reb-delete-overlays))
|
2001-11-20 18:26:55 +00:00
|
|
|
(setq reb-target-buffer (current-buffer)
|
2008-11-28 23:54:23 +00:00
|
|
|
reb-target-window (selected-window))
|
2021-07-08 20:39:39 +03:00
|
|
|
(select-window
|
|
|
|
(or (get-buffer-window reb-buffer)
|
|
|
|
(let ((dir (if (window-parameter nil 'window-side)
|
|
|
|
'bottom 'down)))
|
|
|
|
(setq reb-window-config (current-window-configuration))
|
|
|
|
(display-buffer
|
|
|
|
(get-buffer-create reb-buffer)
|
|
|
|
`((display-buffer-in-direction)
|
|
|
|
(direction . ,dir)
|
|
|
|
(dedicated . t))))))
|
2019-06-27 19:08:42 +02:00
|
|
|
(font-lock-mode 1)
|
2005-07-24 02:29:14 +00:00
|
|
|
(reb-initialize-buffer)))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
2001-11-20 18:20:56 +00:00
|
|
|
(defun reb-change-target-buffer (buf)
|
|
|
|
"Change the target buffer and display it in the target window."
|
|
|
|
(interactive "bSet target buffer to: ")
|
|
|
|
(let ((buffer (get-buffer buf)))
|
|
|
|
(if (not buffer)
|
|
|
|
(error "No such buffer")
|
|
|
|
(reb-delete-overlays)
|
|
|
|
(setq reb-target-buffer buffer)
|
|
|
|
(reb-do-update
|
|
|
|
(if reb-subexp-mode reb-subexp-displayed nil))
|
|
|
|
(reb-update-modestring))))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
(defun reb-force-update ()
|
2004-08-17 09:58:06 +00:00
|
|
|
"Force an update in the RE Builder target window without a match limit."
|
2000-03-09 20:28:18 +00:00
|
|
|
(interactive)
|
|
|
|
(let ((reb-auto-match-limit nil))
|
|
|
|
(reb-update-overlays
|
|
|
|
(if reb-subexp-mode reb-subexp-displayed nil))))
|
|
|
|
|
|
|
|
(defun reb-quit ()
|
|
|
|
"Quit the RE Builder mode."
|
|
|
|
(interactive)
|
|
|
|
(setq reb-subexp-mode nil
|
|
|
|
reb-subexp-displayed nil)
|
|
|
|
(reb-delete-overlays)
|
|
|
|
(bury-buffer)
|
|
|
|
(set-window-configuration reb-window-config))
|
|
|
|
|
|
|
|
(defun reb-next-match ()
|
|
|
|
"Go to next match in the RE Builder target window."
|
|
|
|
(interactive)
|
|
|
|
(reb-assert-buffer-in-window)
|
2005-07-24 02:29:14 +00:00
|
|
|
(with-selected-window reb-target-window
|
2000-03-09 20:28:18 +00:00
|
|
|
(if (not (re-search-forward reb-regexp (point-max) t))
|
(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 16:49:22 +00:00
|
|
|
(message "No more matches")
|
2000-03-09 20:28:18 +00:00
|
|
|
(reb-show-subexp
|
|
|
|
(or (and reb-subexp-mode reb-subexp-displayed) 0)
|
|
|
|
t))))
|
|
|
|
|
|
|
|
(defun reb-prev-match ()
|
|
|
|
"Go to previous match in the RE Builder target window."
|
|
|
|
(interactive)
|
|
|
|
(reb-assert-buffer-in-window)
|
2005-07-24 02:29:14 +00:00
|
|
|
(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)
|
(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 16:49:22 +00:00
|
|
|
(message "No more matches")))))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
(defun reb-toggle-case ()
|
|
|
|
"Toggle case sensitivity of searches for RE Builder target buffer."
|
|
|
|
(interactive)
|
|
|
|
(with-current-buffer reb-target-buffer
|
|
|
|
(setq case-fold-search (not case-fold-search)))
|
|
|
|
(reb-update-modestring)
|
|
|
|
(reb-auto-update nil nil nil t))
|
|
|
|
|
|
|
|
(defun reb-copy ()
|
|
|
|
"Copy current RE into the kill ring for later insertion."
|
|
|
|
(interactive)
|
|
|
|
(reb-update-regexp)
|
|
|
|
(let ((re (with-output-to-string
|
|
|
|
(print (reb-target-binding reb-regexp)))))
|
2019-06-27 19:08:42 +02:00
|
|
|
(setq re (substring re 1 (1- (length re))))
|
Use string-replace instead of replace-regexp-in-string
`string-replace` is easier to understand, less error-prone, much
faster, and results in shorter Lisp and byte code. Use it where
applicable and obviously safe (erring on the conservative side).
* admin/authors.el (authors-scan-change-log):
* lisp/autoinsert.el (auto-insert-alist):
* lisp/calc/calc-prog.el (calc-edit-macro-combine-alg-ent)
(calc-edit-macro-combine-ext-command)
(calc-edit-macro-combine-var-name):
* lisp/calc/calc-units.el (math-make-unit-string):
* lisp/calendar/cal-html.el (cal-html-comment):
* lisp/calendar/cal-tex.el (cal-tex-comment):
* lisp/calendar/icalendar.el (icalendar--convert-string-for-export)
(icalendar--convert-string-for-import):
* lisp/calendar/iso8601.el (iso8601--concat-regexps)
(iso8601--full-time-match, iso8601--combined-match):
* lisp/calendar/time-date.el (format-seconds):
* lisp/calendar/todo-mode.el (todo-filter-items-filename):
* lisp/cedet/cedet-files.el (cedet-directory-name-to-file-name)
(cedet-file-name-to-directory-name):
* lisp/comint.el (comint-watch-for-password-prompt):
* lisp/dired-aux.el (dired-do-chmod):
* lisp/dired-x.el (dired-man):
* lisp/dired.el (dired-insert-directory, dired-goto-file-1):
* lisp/emacs-lisp/comp.el (comp-c-func-name):
* lisp/emacs-lisp/re-builder.el (reb-copy):
* lisp/erc/erc-dcc.el (erc-dcc-unquote-filename):
* lisp/erc/erc.el (erc-quit-reason-zippy, erc-part-reason-zippy)
(erc-update-mode-line-buffer, erc-message-english-PART):
* lisp/files.el (make-backup-file-name-1, files--transform-file-name)
(read-file-modes):
* lisp/fringe.el (fringe-mode):
* lisp/gnus/gnus-art.el (gnus-button-handle-info-url):
* lisp/gnus/gnus-group.el (gnus-group-completing-read):
* lisp/gnus/gnus-icalendar.el (gnus-icalendar-event-from-ical):
* lisp/gnus/gnus-mlspl.el (gnus-group-split-fancy):
* lisp/gnus/gnus-search.el (gnus-search-query-parse-date)
(gnus-search-transform-expression, gnus-search-run-search):
* lisp/gnus/gnus-start.el (gnus-dribble-enter):
* lisp/gnus/gnus-sum.el (gnus-summary-refer-article):
* lisp/gnus/gnus-util.el (gnus-mode-string-quote):
* lisp/gnus/message.el (message-put-addresses-in-ecomplete)
(message-parse-mailto-url, message-mailto-1):
* lisp/gnus/mml-sec.el (mml-secure-epg-sign):
* lisp/gnus/mml-smime.el (mml-smime-epg-verify):
* lisp/gnus/mml2015.el (mml2015-epg-verify):
* lisp/gnus/nnmaildir.el (nnmaildir--system-name)
(nnmaildir-request-list, nnmaildir-retrieve-groups)
(nnmaildir-request-group, nnmaildir-retrieve-headers):
* lisp/gnus/nnrss.el (nnrss-node-text):
* lisp/gnus/spam-report.el (spam-report-gmane-internal)
(spam-report-user-mail-address):
* lisp/ibuffer.el (name):
* lisp/image-dired.el (image-dired-pngnq-thumb)
(image-dired-pngcrush-thumb, image-dired-optipng-thumb)
(image-dired-create-thumb-1):
* lisp/info.el (Info-set-mode-line):
* lisp/international/mule-cmds.el (describe-language-environment):
* lisp/mail/rfc2231.el (rfc2231-parse-string):
* lisp/mail/rfc2368.el (rfc2368-parse-mailto-url):
* lisp/mail/rmail.el (rmail-insert-inbox-text)
(rmail-simplified-subject-regexp):
* lisp/mail/rmailout.el (rmail-output-body-to-file):
* lisp/mail/undigest.el (rmail-digest-rfc1153):
* lisp/man.el (Man-default-man-entry):
* lisp/mouse.el (minor-mode-menu-from-indicator):
* lisp/mpc.el (mpc--debug):
* lisp/net/browse-url.el (browse-url-mail):
* lisp/net/eww.el (eww-update-header-line-format):
* lisp/net/newst-backend.el (newsticker-save-item):
* lisp/net/rcirc.el (rcirc-sentinel):
* lisp/net/soap-client.el (soap-decode-date-time):
* lisp/nxml/rng-cmpct.el (rng-c-literal-2-re):
* lisp/nxml/xmltok.el (let*):
* lisp/obsolete/nnir.el (nnir-run-swish-e, nnir-run-hyrex)
(nnir-run-find-grep):
* lisp/play/dunnet.el (dun-doassign):
* lisp/play/handwrite.el (handwrite):
* lisp/proced.el (proced-format-args):
* lisp/profiler.el (profiler-report-header-line-format):
* lisp/progmodes/gdb-mi.el (gdb-mi-quote):
* lisp/progmodes/make-mode.el (makefile-bsdmake-rule-action-regex)
(makefile-make-font-lock-keywords):
* lisp/progmodes/prolog.el (prolog-guess-fill-prefix):
* lisp/progmodes/ruby-mode.el (ruby-toggle-string-quotes):
* lisp/progmodes/sql.el (sql-remove-tabs-filter, sql-str-literal):
* lisp/progmodes/which-func.el (which-func-current):
* lisp/replace.el (query-replace-read-from)
(occur-engine, replace-quote):
* lisp/select.el (xselect--encode-string):
* lisp/ses.el (ses-export-tab):
* lisp/subr.el (shell-quote-argument):
* lisp/term/pc-win.el (msdos-show-help):
* lisp/term/w32-win.el (w32--set-selection):
* lisp/term/xterm.el (gui-backend-set-selection):
* lisp/textmodes/picture.el (picture-tab-search):
* lisp/thumbs.el (thumbs-call-setroot-command):
* lisp/tooltip.el (tooltip-show-help-non-mode):
* lisp/transient.el (transient-format-key):
* lisp/url/url-mailto.el (url-mailto):
* lisp/vc/log-edit.el (log-edit-changelog-ours-p):
* lisp/vc/vc-bzr.el (vc-bzr-status):
* lisp/vc/vc-hg.el (vc-hg--glob-to-pcre):
* lisp/vc/vc-svn.el (vc-svn-after-dir-status):
* lisp/xdg.el (xdg-desktop-strings):
* test/lisp/electric-tests.el (defun):
* test/lisp/term-tests.el (term-simple-lines):
* test/lisp/time-stamp-tests.el (formatz-mod-del-colons):
* test/lisp/wdired-tests.el (wdired-test-bug32173-01)
(wdired-test-unfinished-edit-01):
* test/src/json-tests.el (json-parse-with-custom-null-and-false-objects):
Use `string-replace` instead of `replace-regexp-in-string`.
2021-08-08 18:58:46 +02:00
|
|
|
(setq re (string-replace "\n" "\\n" re))
|
2019-06-27 19:08:42 +02:00
|
|
|
(kill-new re)
|
2019-07-09 03:25:42 +02:00
|
|
|
(message "Copied regexp `%s' to kill-ring" re)))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
;; The subexpression mode is not electric because the number of
|
|
|
|
;; matches should be seen rather than a prompt.
|
|
|
|
(defun reb-enter-subexp-mode ()
|
|
|
|
"Enter the subexpression mode in the RE Builder."
|
|
|
|
(interactive)
|
|
|
|
(setq reb-subexp-mode t)
|
|
|
|
(reb-update-modestring)
|
|
|
|
(use-local-map reb-subexp-mode-map)
|
2021-11-22 11:45:44 +01:00
|
|
|
(message (substitute-command-keys
|
|
|
|
"\\`0'-\\`9' to display subexpressions \\`q' to quit subexp mode")))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
(defun reb-show-subexp (subexp &optional pause)
|
|
|
|
"Visually show limit of subexpression SUBEXP of recent search.
|
|
|
|
On color displays this just puts point to the end of the expression as
|
|
|
|
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."
|
2005-07-24 02:29:14 +00:00
|
|
|
(with-selected-window reb-target-window
|
(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 16:49:22 +00:00
|
|
|
(unless (reb-color-display-p)
|
|
|
|
(goto-char (match-beginning subexp))
|
|
|
|
(sit-for reb-blink-delay))
|
2000-03-09 20:28:18 +00:00
|
|
|
(goto-char (match-end subexp))
|
(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 16:49:22 +00:00
|
|
|
(when (or (not (reb-color-display-p)) pause)
|
|
|
|
(sit-for reb-blink-delay))))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
(defun reb-quit-subexp-mode ()
|
|
|
|
"Quit the subexpression mode in the RE Builder."
|
|
|
|
(interactive)
|
|
|
|
(setq reb-subexp-mode nil
|
|
|
|
reb-subexp-displayed nil)
|
|
|
|
(reb-update-modestring)
|
|
|
|
(use-local-map reb-mode-map)
|
|
|
|
(reb-do-update))
|
|
|
|
|
2019-06-27 19:08:42 +02:00
|
|
|
(defvar reb-change-syntax-hist nil)
|
|
|
|
|
2000-03-09 20:28:18 +00:00
|
|
|
(defun reb-change-syntax (&optional syntax)
|
|
|
|
"Change the syntax used by the RE Builder.
|
|
|
|
Optional argument SYNTAX must be specified if called non-interactively."
|
|
|
|
(interactive
|
|
|
|
(list (intern
|
2017-02-11 14:17:26 +08:00
|
|
|
(completing-read
|
Use `format-prompt' when prompting with default values
* lisp/woman.el (woman-file-name):
* lisp/wid-edit.el (widget-file-prompt-value)
(widget-coding-system-prompt-value):
* lisp/w32-fns.el (w32-set-system-coding-system):
* lisp/vc/vc.el (vc-print-root-log):
* lisp/vc/vc-annotate.el (vc-annotate):
* lisp/vc/emerge.el (emerge-read-file-name):
* lisp/vc/ediff.el (ediff-directories)
(ediff-directory-revisions, ediff-directories3)
(ediff-merge-directories, )
(ediff-merge-directories-with-ancestor)
(ediff-merge-directory-revisions)
(ediff-merge-directory-revisions-with-ancestor)
(ediff-merge-revisions, ediff-merge-revisions-with-ancestor)
(ediff-revision):
* lisp/vc/ediff-util.el (ediff-toggle-regexp-match):
* lisp/vc/ediff-mult.el (ediff-filegroup-action):
* lisp/vc/add-log.el (prompt-for-change-log-name):
* lisp/textmodes/table.el (table-insert-row-column)
(table-span-cell, table-split-cell-horizontally)
(table-split-cell, table-justify, table-generate-source)
(table-insert-sequence, table-capture)
(table--read-from-minibuffer, table--query-justification):
* lisp/textmodes/sgml-mode.el (sgml-tag, sgml-tag-help):
* lisp/textmodes/reftex-ref.el (reftex-goto-label):
* lisp/textmodes/refer.el (refer-get-bib-files):
* lisp/textmodes/css-mode.el (css-lookup-symbol):
* lisp/term.el (serial-read-name, serial-read-speed):
* lisp/speedbar.el (speedbar-change-initial-expansion-list):
* lisp/simple.el (previous-matching-history-element)
(set-variable):
* lisp/ses.el (ses-read-cell, ses-set-column-width):
* lisp/replace.el (query-replace-read-from)
(occur-read-primary-args):
* lisp/rect.el (string-rectangle, string-insert-rectangle):
* lisp/progmodes/tcl.el (tcl-help-on-word):
* lisp/progmodes/sh-script.el (sh-set-shell):
* lisp/progmodes/python.el (python-eldoc-at-point):
* lisp/progmodes/octave.el (octave-completing-read)
(octave-update-function-file-comment, octave-insert-defun):
* lisp/progmodes/inf-lisp.el (lisp-symprompt):
* lisp/progmodes/cperl-mode.el (cperl-info-on-command)
(cperl-perldoc):
* lisp/progmodes/compile.el (compilation-find-file):
* lisp/net/rcirc.el (rcirc-prompt-for-encryption):
* lisp/net/eww.el (eww):
* lisp/net/browse-url.el (browse-url-with-browser-kind):
* lisp/man.el (man):
* lisp/mail/sendmail.el (sendmail-query-user-about-smtp):
* lisp/mail/mailalias.el (build-mail-aliases):
* lisp/mail/mailabbrev.el (merge-mail-abbrevs)
(rebuild-mail-abbrevs):
* lisp/locate.el (locate-prompt-for-search-string):
* lisp/isearch.el (isearch-occur):
* lisp/international/ogonek.el (ogonek-read-encoding)
(ogonek-read-prefix):
* lisp/international/mule.el (read-buffer-file-coding-system)
(set-terminal-coding-system, set-keyboard-coding-system)
(set-next-selection-coding-system, recode-region):
* lisp/international/mule-cmds.el ()
(universal-coding-system-argument, search-unencodable-char)
(select-safe-coding-system-interactively):
* lisp/info.el (Info-search, Info-search-backward, Info-menu):
* lisp/info-look.el (info-lookup-interactive-arguments):
* lisp/imenu.el (imenu--completion-buffer):
* lisp/ibuf-ext.el (mode, used-mode, ibuffer-mark-by-mode):
* lisp/hi-lock.el (hi-lock-unface-buffer)
(hi-lock-read-face-name):
* lisp/help.el (view-emacs-news, where-is):
* lisp/help-fns.el (describe-variable, describe-symbol)
(describe-keymap):
* lisp/gnus/mm-decode.el (mm-save-part):
* lisp/gnus/gnus-sum.el (gnus-summary-browse-url):
* lisp/gnus/gnus-group.el (gnus-group--read-bug-ids)
(gnus-group-set-current-level):
* lisp/frame.el (make-frame-on-monitor)
(close-display-connection, select-frame-by-name):
* lisp/format.el (format-encode-buffer, format-encode-region):
* lisp/files.el (recode-file-name):
* lisp/files-x.el (read-file-local-variable)
(read-file-local-variable-value, )
(read-file-local-variable-mode):
* lisp/ffap.el (ffap-menu-ask):
* lisp/faces.el (face-read-string):
* lisp/facemenu.el (facemenu-set-charset):
* lisp/erc/erc-dcc.el (erc-dcc-do-GET-command):
* lisp/emulation/edt-mapper.el (edt-mapper):
* lisp/emacs-lisp/trace.el (trace--read-args)
(trace-function-foreground, trace-function-background):
* lisp/emacs-lisp/smie.el (smie-config-set-indent):
* lisp/emacs-lisp/re-builder.el (reb-change-syntax):
* lisp/emacs-lisp/package.el (describe-package):
* lisp/emacs-lisp/find-func.el (read-library-name)
(find-function-read):
* lisp/emacs-lisp/ert.el (ert-read-test-name)
(ert-run-tests-interactively):
* lisp/emacs-lisp/disass.el (disassemble):
* lisp/emacs-lisp/debug.el (debug-on-entry)
(debug-on-variable-change):
* lisp/emacs-lisp/advice.el (ad-read-advised-function)
(ad-read-advice-class, ad-read-advice-name, ad-read-regexp):
* lisp/dired-x.el (dired--mark-suffix-interactive-spec):
* lisp/dired-aux.el (dired-diff):
* lisp/cus-edit.el (custom-variable-prompt, customize-mode)
(customize-changed-options):
* lisp/completion.el (interactive-completion-string-reader):
* lisp/calendar/timeclock.el (timeclock-ask-for-project):
* lisp/calc/calcalg3.el (calc-get-fit-variables):
* lisp/calc/calc-store.el (calc-edit-variable):
* lisp/calc/calc-bin.el (calc-word-size):
* lisp/bookmark.el (bookmark-set-internal):
* lisp/abbrev.el (read-abbrev-file): Use `format-prompt' for
prompting (bug#12443).
2020-09-06 16:56:44 +02:00
|
|
|
(format-prompt "Select syntax" reb-re-syntax)
|
2021-12-03 16:42:24 +01:00
|
|
|
'(read string rx)
|
2019-06-27 19:08:42 +02:00
|
|
|
nil t nil nil (symbol-name reb-re-syntax)
|
|
|
|
'reb-change-syntax-hist))))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
2021-12-03 16:42:24 +01:00
|
|
|
(if (memq syntax '(read string rx))
|
2000-03-09 20:28:18 +00:00
|
|
|
(let ((buffer (get-buffer reb-buffer)))
|
|
|
|
(setq reb-re-syntax syntax)
|
2005-07-24 02:29:14 +00:00
|
|
|
(when buffer
|
|
|
|
(with-current-buffer buffer
|
2022-08-18 13:17:11 +02:00
|
|
|
(reb-initialize-buffer))
|
|
|
|
(message "Switched syntax to `%s'" reb-re-syntax)))
|
2000-03-09 20:28:18 +00:00
|
|
|
(error "Invalid syntax: %s" syntax)))
|
|
|
|
|
|
|
|
|
|
|
|
;; Non-interactive functions below
|
|
|
|
(defun reb-do-update (&optional subexp)
|
|
|
|
"Update matches in the RE Builder target window.
|
|
|
|
If SUBEXP is non-nil mark only the corresponding sub-expressions."
|
|
|
|
(reb-assert-buffer-in-window)
|
|
|
|
(reb-update-regexp)
|
|
|
|
(reb-update-overlays subexp))
|
|
|
|
|
2011-04-04 11:35:16 +02:00
|
|
|
(defun reb-auto-update (_beg _end _lenold &optional force)
|
2020-09-23 13:35:55 +02:00
|
|
|
"Called from `after-change-functions' to update the display.
|
2004-05-07 00:53:56 +00:00
|
|
|
BEG, END and LENOLD are passed in from the hook.
|
2000-03-09 20:28:18 +00:00
|
|
|
An actual update is only done if the regexp has changed or if the
|
|
|
|
optional fourth argument FORCE is non-nil."
|
|
|
|
(let ((prev-valid reb-valid-string)
|
|
|
|
(new-valid
|
|
|
|
(condition-case nil
|
|
|
|
(progn
|
(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 16:49:22 +00:00
|
|
|
(when (or (reb-update-regexp) force)
|
|
|
|
(reb-do-update))
|
2000-03-09 20:28:18 +00:00
|
|
|
"")
|
|
|
|
(error " *invalid*"))))
|
|
|
|
(setq reb-valid-string new-valid)
|
|
|
|
(force-mode-line-update)
|
|
|
|
|
|
|
|
;; Through the caching of the re a change invalidating the syntax
|
|
|
|
;; for symbolic expressions will not delete the overlays so we
|
|
|
|
;; catch it here
|
(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 16:49:22 +00:00
|
|
|
(when (and (reb-lisp-syntax-p)
|
|
|
|
(not (string= prev-valid new-valid))
|
|
|
|
(string= prev-valid ""))
|
|
|
|
(reb-delete-overlays))))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
(defun reb-delete-overlays ()
|
|
|
|
"Delete all RE Builder overlays in the `reb-target-buffer' buffer."
|
(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 16:49:22 +00:00
|
|
|
(when (buffer-live-p reb-target-buffer)
|
2000-03-09 20:28:18 +00:00
|
|
|
(with-current-buffer reb-target-buffer
|
2007-09-26 00:15:01 +00:00
|
|
|
(mapc 'delete-overlay reb-overlays)
|
2000-03-09 20:28:18 +00:00
|
|
|
(setq reb-overlays nil))))
|
|
|
|
|
|
|
|
(defun reb-assert-buffer-in-window ()
|
|
|
|
"Assert that `reb-target-buffer' is displayed in `reb-target-window'."
|
|
|
|
(if (not (eq reb-target-buffer (window-buffer reb-target-window)))
|
|
|
|
(set-window-buffer reb-target-window reb-target-buffer)))
|
|
|
|
|
|
|
|
(defun reb-update-modestring ()
|
|
|
|
"Update the variable `reb-mode-string' displayed in the mode line."
|
|
|
|
(setq reb-mode-string
|
|
|
|
(concat
|
|
|
|
(if reb-subexp-mode
|
2001-01-31 08:29:28 +00:00
|
|
|
(format " (subexp %s)" (or reb-subexp-displayed "-"))
|
2000-03-09 20:28:18 +00:00
|
|
|
"")
|
|
|
|
(if (not (reb-target-binding case-fold-search))
|
|
|
|
" Case"
|
|
|
|
"")))
|
|
|
|
(force-mode-line-update))
|
|
|
|
|
|
|
|
(defun reb-display-subexp (&optional subexp)
|
|
|
|
"Highlight only subexpression SUBEXP in the RE Builder."
|
|
|
|
(interactive)
|
|
|
|
(setq reb-subexp-displayed
|
2009-01-09 04:29:16 +00:00
|
|
|
(or subexp (string-to-number (format "%c" last-command-event))))
|
2000-03-09 20:28:18 +00:00
|
|
|
(reb-update-modestring)
|
|
|
|
(reb-do-update reb-subexp-displayed))
|
|
|
|
|
|
|
|
(defun reb-kill-buffer ()
|
|
|
|
"When the RE Builder buffer is killed make sure no overlays stay around."
|
(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 16:49:22 +00:00
|
|
|
(when (reb-mode-buffer-p)
|
|
|
|
(reb-delete-overlays)))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
;; The next functions are the interface between the regexp and
|
|
|
|
;; its textual representation in the RE Builder buffer.
|
|
|
|
;; They are the only functions concerned with the actual syntax
|
|
|
|
;; being used.
|
|
|
|
(defun reb-read-regexp ()
|
|
|
|
"Read current RE."
|
|
|
|
(save-excursion
|
|
|
|
(cond ((eq reb-re-syntax 'read)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(read (current-buffer)))
|
|
|
|
((eq reb-re-syntax 'string)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(re-search-forward "\"")
|
|
|
|
(let ((beg (point)))
|
|
|
|
(goto-char (point-max))
|
|
|
|
(re-search-backward "\"")
|
|
|
|
(buffer-substring-no-properties beg (point))))
|
|
|
|
((reb-lisp-syntax-p)
|
|
|
|
(buffer-string)))))
|
|
|
|
|
|
|
|
(defun reb-empty-regexp ()
|
|
|
|
"Return empty RE for current syntax."
|
|
|
|
(cond ((reb-lisp-syntax-p) "'()")
|
|
|
|
(t "")))
|
|
|
|
|
|
|
|
(defun reb-insert-regexp ()
|
|
|
|
"Insert current RE."
|
|
|
|
(let ((re (or (reb-target-binding reb-regexp)
|
|
|
|
(reb-empty-regexp))))
|
|
|
|
(cond ((eq reb-re-syntax 'read)
|
|
|
|
(print re (current-buffer)))
|
|
|
|
((eq reb-re-syntax 'string)
|
|
|
|
(insert "\n\"" re "\""))
|
|
|
|
;; For the Lisp syntax we need the "source" of the regexp
|
|
|
|
((reb-lisp-syntax-p)
|
|
|
|
(insert (or (reb-target-binding reb-regexp-src)
|
|
|
|
(reb-empty-regexp)))))))
|
|
|
|
|
|
|
|
(defun reb-cook-regexp (re)
|
|
|
|
"Return RE after processing it according to `reb-re-syntax'."
|
2021-12-03 17:18:33 +01:00
|
|
|
(if (eq reb-re-syntax 'rx)
|
|
|
|
(rx-to-string (eval (car (read-from-string re))))
|
|
|
|
re))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
(defun reb-update-regexp ()
|
|
|
|
"Update the regexp for the target buffer.
|
|
|
|
Return t if the (cooked) expression changed."
|
|
|
|
(let* ((re-src (reb-read-regexp))
|
|
|
|
(re (reb-cook-regexp re-src)))
|
|
|
|
(with-current-buffer reb-target-buffer
|
|
|
|
(let ((oldre reb-regexp))
|
|
|
|
(prog1
|
|
|
|
(not (string= oldre re))
|
|
|
|
(setq reb-regexp re)
|
|
|
|
;; Only update the source re for the lisp formats
|
(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 16:49:22 +00:00
|
|
|
(when (reb-lisp-syntax-p)
|
|
|
|
(setq reb-regexp-src re-src)))))))
|
2000-03-09 20:28:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
;; And now the real core of the whole thing
|
|
|
|
(defun reb-count-subexps (re)
|
|
|
|
"Return number of sub-expressions in the regexp RE."
|
|
|
|
(let ((i 0) (beg 0))
|
|
|
|
(while (string-match "\\\\(" re beg)
|
|
|
|
(setq i (1+ i)
|
|
|
|
beg (match-end 0)))
|
|
|
|
i))
|
|
|
|
|
|
|
|
(defun reb-update-overlays (&optional subexp)
|
|
|
|
"Switch to `reb-target-buffer' and mark all matches of `reb-regexp'.
|
|
|
|
If SUBEXP is non-nil mark only the corresponding sub-expressions."
|
|
|
|
(let* ((re (reb-target-binding reb-regexp))
|
|
|
|
(subexps (reb-count-subexps re))
|
|
|
|
(matches 0)
|
|
|
|
(submatches 0)
|
2019-06-27 19:08:42 +02:00
|
|
|
firstmatch
|
|
|
|
here
|
|
|
|
firstmatch-after-here)
|
* textmodes/two-column.el (2C-split):
* textmodes/texnfo-upd.el (texinfo-multi-file-included-list):
* textmodes/tex-mode.el (tex-set-buffer-directory):
* textmodes/spell.el (spell-region, spell-string):
* textmodes/reftex.el (reftex-erase-buffer):
(reftex-get-file-buffer-force, reftex-kill-temporary-buffers):
* textmodes/reftex-toc.el (reftex-toc-promote-action):
* textmodes/reftex-sel.el (reftex-get-offset, reftex-insert-docstruct)
(reftex-select-item):
* textmodes/reftex-ref.el (reftex-label-info-update)
(reftex-offer-label-menu):
* textmodes/reftex-index.el (reftex-index-change-entry)
(reftex-index-phrases-info):
* textmodes/reftex-global.el (reftex-create-tags-file)
(reftex-save-all-document-buffers, reftex-ensure-write-access):
* textmodes/reftex-dcr.el (reftex-echo-ref, reftex-echo-cite)
(reftex-view-crossref-from-bibtex):
* textmodes/reftex-cite.el (reftex-bibtex-selection-callback)
(reftex-extract-bib-entries-from-thebibliography)
(reftex-all-used-citation-keys, reftex-create-bibtex-file):
* textmodes/refbib.el (r2b-capitalize-title):
(r2b-convert-buffer, r2b-help):
* textmodes/page-ext.el (pages-directory)
(pages-directory-goto-with-mouse):
* textmodes/bibtex.el (bibtex-validate-globally):
* textmodes/bib-mode.el (bib-capitalize-title):
* textmodes/artist.el (artist-clear-buffer, artist-system):
* progmodes/xscheme.el (global-set-scheme-interaction-buffer):
(local-set-scheme-interaction-buffer, xscheme-process-filter)
(verify-xscheme-buffer, xscheme-enter-interaction-mode)
(xscheme-enter-debugger-mode, xscheme-debugger-mode-p)
(xscheme-send-control-g-interrupt, xscheme-start-process)
(xscheme-process-sentinel, xscheme-cd):
* progmodes/verilog-mode.el (verilog-read-always-signals)
(verilog-set-define, verilog-getopt-file)
(verilog-module-inside-filename-p):
* progmodes/sh-script.el:
* progmodes/python.el (python-pdbtrack-get-source-buffer)
(python-pdbtrack-grub-for-buffer, python-execute-file):
* progmodes/octave-inf.el (inferior-octave):
* progmodes/idlwave.el (idlwave-scan-user-lib-files)
(idlwave-shell-compile-helper-routines, idlwave-set-local)
(idlwave-display-completion-list-xemacs, idlwave-list-abbrevs)
(idlwave-display-completion-list-emacs, idlwave-list-load-path-shadows)
(idlwave-completion-fontify-classes, idlwave-display-calling-sequence):
* progmodes/idlw-shell.el (idlwave-shell-examine-display-clear)
(idlwave-shell-filter, idlwave-shell-examine-highlight)
(idlwave-shell-sentinel, idlwave-shell-filter-directory)
(idlwave-shell-display-line, idlwave-shell-set-bp-in-module)
(idlwave-shell-examine-display, idlwave-shell-run-region)
(idlwave-shell-filter-bp, idlwave-shell-save-and-action)
(idlwave-shell-sources-filter, idlwave-shell-goto-next-error):
* progmodes/idlw-help.el (idlwave-help-get-special-help)
(idlwave-help-get-help-buffer):
* progmodes/gud.el (gud-basic-call, gud-find-class)
(gud-tooltip-activate-mouse-motions-if-enabled):
* progmodes/gdb-mi.el (gdb-mouse-toggle-breakpoint-fringe):
* progmodes/ebrowse.el (ebrowse-member-table, ebrowse-save-tree-as)
(ebrowse-view-exit-fn, ebrowse-tags-list-members-in-file)
(ebrowse-tags-next-file):
* progmodes/ebnf2ps.el (ebnf-generate-eps, ebnf-generate-eps)
(ebnf-eps-production-list, ebnf-begin-file, ebnf-log)
(ebnf-eps-finish-and-write):
* progmodes/cpp.el (cpp-edit-save):
* progmodes/cperl-mode.el (cperl-pod-to-manpage):
* progmodes/cc-defs.el (c-emacs-features):
* progmodes/antlr-mode.el (antlr-invalidate-context-cache)
(antlr-directory-dependencies):
* progmodes/ada-xref.el (ada-gnat-parse-gpr, ada-get-ali-file-name)
(ada-run-application, ada-find-in-src-path, ada-goto-parent)
(ada-find-any-references, ada-make-filename-from-adaname)
(ada-make-body-gnatstub):
* obsolete/rnews.el (news-list-news-groups):
* obsolete/resume.el (resume-suspend-hook,resume-write-buffer-to-file):
* obsolete/iso-acc.el (iso-acc-minibuf-setup):
* net/rcirc.el (rcirc-debug):
* net/newst-treeview.el (newsticker--treeview-list-add-item)
(newsticker--treeview-list-clear, newsticker-treeview-browse-url)
(newsticker--treeview-list-update-faces, newsticker-treeview-save)
(newsticker--treeview-item-show-text, newsticker--treeview-item-show)
(newsticker--treeview-tree-update-tag,newsticker--treeview-buffer-init)
(newsticker-treeview-show-item, newsticker--treeview-unfold-node)
(newsticker--treeview-list-clear-highlight)
(newsticker--treeview-list-update-highlight)
(newsticker--treeview-list-highlight-start)
(newsticker--treeview-tree-update-highlight)
(newsticker--treeview-get-selected-item)
(newsticker-treeview-mark-list-items-old)
(newsticker--treeview-set-current-node):
* net/newst-plainview.el (newsticker--buffer-set-uptodate):
* net/newst-backend.el (newsticker--get-news-by-funcall)
(newsticker--get-news-by-wget, newsticker--image-get)
(newsticker--image-sentinel):
* net/mairix.el (mairix-rmail-fetch-field, mairix-gnus-fetch-field):
* net/eudcb-ph.el (eudc-ph-do-request, eudc-ph-open-session):
(eudc-ph-close-session):
* net/eudc.el (eudc-save-options):
* language/thai-word.el (thai-update-word-table):
* language/japan-util.el (japanese-string-conversion):
* international/titdic-cnv.el (tsang-quick-converter)
(ziranma-converter, ctlau-converter):
* international/mule-cmds.el (describe-language-environment):
* international/ja-dic-cnv.el (skkdic-convert-okuri-ari)
(skkdic-convert-postfix, skkdic-convert-prefix):
(skkdic-convert-okuri-nasi, skkdic-convert):
* emacs-lisp/re-builder.el (reb-update-overlays):
* emacs-lisp/pp.el (pp-to-string, pp-display-expression):
* emacs-lisp/gulp.el (gulp-send-requests):
* emacs-lisp/find-gc.el (trace-call-tree):
* emacs-lisp/eieio-opt.el (eieio-browse, eieio-describe-class)
(eieio-describe-generic):
* emacs-lisp/eieio-base.el (eieio-persistent-read):
* emacs-lisp/edebug.el (edebug-outside-excursion):
* emacs-lisp/debug.el (debugger-make-xrefs):
* emacs-lisp/cust-print.el (custom-prin1-to-string):
* emacs-lisp/chart.el (chart-new-buffer):
* emacs-lisp/authors.el (authors-scan-el, authors-scan-change-log):
Use with-current-buffer.
* textmodes/artist.el (artist-system): Don't call
copy-sequence on a fresh string.
* progmodes/idlw-shell.el (easymenu setup): Use dolist.
2009-10-31 02:38:34 +00:00
|
|
|
(with-current-buffer reb-target-buffer
|
2019-06-27 19:08:42 +02:00
|
|
|
(setq here
|
|
|
|
(if reb-target-window
|
|
|
|
(with-selected-window reb-target-window (window-point))
|
|
|
|
(point)))
|
2000-03-09 20:28:18 +00:00
|
|
|
(reb-delete-overlays)
|
|
|
|
(goto-char (point-min))
|
2007-03-18 14:34:18 +00:00
|
|
|
(while (and (not (eobp))
|
|
|
|
(re-search-forward re (point-max) t)
|
2000-03-09 20:28:18 +00:00
|
|
|
(or (not reb-auto-match-limit)
|
|
|
|
(< matches reb-auto-match-limit)))
|
(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 16:49:22 +00:00
|
|
|
(when (and (= 0 (length (match-string 0)))
|
|
|
|
(not (eobp)))
|
|
|
|
(forward-char 1))
|
2006-05-05 13:02:14 +00:00
|
|
|
(let ((i 0)
|
|
|
|
suffix max-suffix)
|
2000-03-09 20:28:18 +00:00
|
|
|
(setq matches (1+ matches))
|
|
|
|
(while (<= i subexps)
|
(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 16:49:22 +00:00
|
|
|
(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)))
|
2019-06-27 19:08:42 +02:00
|
|
|
(unless firstmatch-after-here
|
|
|
|
(when (> (point) here)
|
|
|
|
(setq firstmatch-after-here (match-data))))
|
(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 16:49:22 +00:00
|
|
|
(setq reb-overlays (cons overlay reb-overlays)
|
|
|
|
submatches (1+ submatches))
|
|
|
|
(overlay-put overlay 'face face)
|
|
|
|
(overlay-put overlay 'priority i)))
|
2000-03-09 20:28:18 +00:00
|
|
|
(setq i (1+ i))))))
|
|
|
|
(let ((count (if subexp submatches matches)))
|
2004-08-07 12:03:54 +00:00
|
|
|
(message "%s %smatch%s%s"
|
2000-03-09 20:28:18 +00:00
|
|
|
(if (= 0 count) "No" (int-to-string count))
|
|
|
|
(if subexp "subexpression " "")
|
2004-07-09 17:16:59 +00:00
|
|
|
(if (= 1 count) "" "es")
|
2000-03-09 20:28:18 +00:00
|
|
|
(if (and reb-auto-match-limit
|
|
|
|
(= reb-auto-match-limit count))
|
|
|
|
" (limit reached)" "")))
|
(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 16:49:22 +00:00
|
|
|
(when firstmatch
|
2019-06-27 19:08:42 +02:00
|
|
|
(store-match-data (or firstmatch-after-here firstmatch))
|
(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 16:49:22 +00:00
|
|
|
(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)
|
2011-06-25 20:08:41 +02:00
|
|
|
(reb-delete-overlays))))
|
(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 16:49:22 +00:00
|
|
|
;; continue standard unloading
|
|
|
|
nil)
|
2000-03-09 20:28:18 +00:00
|
|
|
|
2019-06-27 19:08:42 +02:00
|
|
|
(defun reb-fontify-string-re (bound)
|
|
|
|
(catch 'found
|
|
|
|
;; The following loop is needed to continue searching after matches
|
|
|
|
;; that do not occur in strings. The associated regexp matches one
|
|
|
|
;; of `\\\\' `\\(' `\\(?:' `\\|' `\\)'. `\\\\' has been included to
|
|
|
|
;; avoid highlighting, for example, `\\(' in `\\\\('.
|
|
|
|
(when (memq reb-re-syntax '(read string))
|
|
|
|
(while (re-search-forward
|
|
|
|
(if (eq reb-re-syntax 'read)
|
|
|
|
;; Copied from font-lock.el
|
|
|
|
"\\(\\\\\\\\\\)\\(?:\\(\\\\\\\\\\)\\|\\((\\(?:\\?[0-9]*:\\)?\\|[|)]\\)\\)"
|
|
|
|
"\\(\\\\\\)\\(?:\\(\\\\\\)\\|\\((\\(?:\\?[0-9]*:\\)?\\|[|)]\\)\\)")
|
|
|
|
bound t)
|
|
|
|
(unless (match-beginning 2)
|
|
|
|
(let ((face (get-text-property (1- (point)) 'face)))
|
|
|
|
(when (or (and (listp face)
|
|
|
|
(memq 'font-lock-string-face face))
|
|
|
|
(eq 'font-lock-string-face face)
|
|
|
|
t)
|
|
|
|
(throw 'found t))))))))
|
|
|
|
|
|
|
|
(defface reb-regexp-grouping-backslash
|
|
|
|
'((t :inherit font-lock-keyword-face :weight bold :underline t))
|
|
|
|
"Font Lock mode face for backslashes in Lisp regexp grouping constructs."
|
|
|
|
:group 're-builder)
|
|
|
|
|
|
|
|
(defface reb-regexp-grouping-construct
|
|
|
|
'((t :inherit font-lock-keyword-face :weight bold :underline t))
|
|
|
|
"Font Lock mode face used to highlight grouping constructs in Lisp regexps."
|
|
|
|
:group 're-builder)
|
|
|
|
|
|
|
|
(defconst reb-string-font-lock-keywords
|
|
|
|
(eval-when-compile
|
|
|
|
'(((reb-fontify-string-re
|
|
|
|
(1 'reb-regexp-grouping-backslash prepend)
|
|
|
|
(3 'reb-regexp-grouping-construct prepend))
|
|
|
|
(reb-mark-non-matching-parenthesis))
|
|
|
|
nil)))
|
|
|
|
|
2020-04-04 12:00:41 -04:00
|
|
|
(defsubst reb-while (limit current where)
|
|
|
|
(if (< current limit)
|
|
|
|
(1+ current)
|
|
|
|
(message "Reached (while limit=%s, where=%s)" limit where)
|
|
|
|
nil))
|
2019-06-27 19:08:42 +02:00
|
|
|
|
|
|
|
(defun reb-mark-non-matching-parenthesis (bound)
|
|
|
|
;; We have a small string, check the whole of it, but wait until
|
|
|
|
;; everything else is fontified.
|
|
|
|
(when (>= bound (point-max))
|
2020-04-04 12:00:41 -04:00
|
|
|
(let ((n-reb 0)
|
|
|
|
left-pars
|
2019-06-27 19:08:42 +02:00
|
|
|
faces-here)
|
|
|
|
(goto-char (point-min))
|
2020-04-04 12:00:41 -04:00
|
|
|
(while (and (setq n-reb (reb-while 100 n-reb "mark-par"))
|
2019-06-27 19:08:42 +02:00
|
|
|
(not (eobp)))
|
|
|
|
(skip-chars-forward "^()")
|
|
|
|
(unless (eobp)
|
|
|
|
(setq faces-here (get-text-property (point) 'face))
|
|
|
|
;; It is already fontified, use that info:
|
|
|
|
(when (or (eq 'reb-regexp-grouping-construct faces-here)
|
|
|
|
(and (listp faces-here)
|
|
|
|
(memq 'reb-regexp-grouping-construct faces-here)))
|
|
|
|
(cond ((eq (char-after) ?\()
|
|
|
|
(setq left-pars (cons (point) left-pars)))
|
|
|
|
((eq (char-after) ?\))
|
|
|
|
(if left-pars
|
|
|
|
(setq left-pars (cdr left-pars))
|
|
|
|
(put-text-property (point) (1+ (point))
|
|
|
|
'face 'font-lock-warning-face)))
|
|
|
|
(t (message "markpar: char-after=%s"
|
|
|
|
(char-to-string (char-after))))))
|
|
|
|
(forward-char)))
|
|
|
|
(dolist (lp left-pars)
|
|
|
|
(put-text-property lp (1+ lp)
|
|
|
|
'face 'font-lock-warning-face)))))
|
|
|
|
|
|
|
|
(require 'rx)
|
|
|
|
(defconst reb-rx-font-lock-keywords
|
2019-09-25 14:29:50 -07:00
|
|
|
(let ((constituents (mapcar #'symbol-name rx--builtin-forms))
|
|
|
|
(syntax (mapcar (lambda (rec) (symbol-name (car rec)))
|
|
|
|
rx--syntax-codes))
|
2019-06-27 19:08:42 +02:00
|
|
|
(categories (mapcar (lambda (rec)
|
|
|
|
(symbol-name (car rec)))
|
2019-09-25 14:29:50 -07:00
|
|
|
rx--categories)))
|
2019-06-27 19:08:42 +02:00
|
|
|
`(
|
|
|
|
(,(concat "(" (regexp-opt (list "rx-to-string") t) "[[:space:]]")
|
|
|
|
(1 font-lock-function-name-face))
|
|
|
|
(,(concat "(" (regexp-opt (list "rx") t) "[[:space:]]")
|
|
|
|
(1 font-lock-preprocessor-face))
|
|
|
|
(,(concat "(category[[:space:]]+" (regexp-opt categories t) ")")
|
|
|
|
(1 font-lock-variable-name-face))
|
|
|
|
(,(concat "(syntax[[:space:]]+" (regexp-opt syntax t) ")")
|
|
|
|
(1 font-lock-type-face))
|
|
|
|
(,(concat "(" (regexp-opt constituents t))
|
|
|
|
(1 font-lock-keyword-face))
|
|
|
|
)))
|
|
|
|
|
|
|
|
(defun reb-restart-font-lock ()
|
|
|
|
"Restart `font-lock-mode' to fit current regexp format."
|
|
|
|
(with-current-buffer (get-buffer reb-buffer)
|
|
|
|
(let ((font-lock-is-on font-lock-mode))
|
|
|
|
(font-lock-mode -1)
|
|
|
|
(kill-local-variable 'font-lock-set-defaults)
|
2020-12-04 19:12:12 +01:00
|
|
|
;;(setq-local reb-re-syntax 'string)
|
|
|
|
;;(setq-local reb-re-syntax 'rx)
|
2019-06-27 19:08:42 +02:00
|
|
|
(setq font-lock-defaults
|
|
|
|
(cond
|
|
|
|
((memq reb-re-syntax '(read string))
|
|
|
|
reb-string-font-lock-keywords)
|
|
|
|
((eq reb-re-syntax 'rx)
|
|
|
|
'(reb-rx-font-lock-keywords
|
|
|
|
nil))
|
|
|
|
(t nil)))
|
|
|
|
(when font-lock-is-on (font-lock-mode 1)))))
|
|
|
|
|
2002-11-17 22:43:07 +00:00
|
|
|
(provide 're-builder)
|
|
|
|
|
2000-03-09 20:28:18 +00:00
|
|
|
;;; re-builder.el ends here
|