Commit 21cefa0b authored by Marko Bencun's avatar Marko Bencun

Add new customization: vr/plain

Issue #45
parent 4ab9426a
;;; visual-regexp.el --- A regexp/replace command for Emacs with interactive visual feedback
;; Copyright (C) 2013-2016 Marko Bencun
;; Copyright (C) 2013-2017 Marko Bencun
;; Author: Marko Bencun <mbencun@gmail.com>
;; URL: https://github.com/benma/visual-regexp.el/
;; Version: 1.0
;; Version: 1.1
;; Package-Requires: ((cl-lib "0.2"))
;; Keywords: regexp, replace, visual, feedback
......@@ -24,6 +24,7 @@
;; along with visual-regexp. If not, see <http://www.gnu.org/licenses/>.
;;; WHAT'S NEW
;; 1.1: Add new customization: vr/plain
;; 1.0: Add support for one prompt for search/replace, using query-replace-from-to-separator
;; (query-replace history like in Emacs 25).
;; Breaking changes:
......@@ -211,6 +212,12 @@ If nil, don't limit the number of matches shown in visual feedback."
:type 'symbol
:group 'visual-regexp)
(defcustom vr/plain nil
"If non-nil, use plain search/replace instead of regexp search/replace."
:type 'boolean
:group 'visual-regexp)
(defvar vr/initialize-hook nil
"Hook called before vr/replace and vr/query-replace")
......@@ -478,8 +485,8 @@ visible all the time in the minibuffer."
(while (and looping
(condition-case err
(if forward
(re-search-forward regexp-string vr--target-buffer-end t)
(re-search-backward regexp-string vr--target-buffer-start t))
(funcall (if vr/plain 'search-forward 're-search-forward) regexp-string vr--target-buffer-end t)
(funcall (if 'vr/plain search-backward 're-search-backward) regexp-string vr--target-buffer-start t))
(invalid-regexp (progn (setq message-line (car (cdr err))) nil))))
(when (or (not feedback-limit) (< i feedback-limit)) ;; let outer loop finish so we can get the matches count
(cl-loop for (start end) on (match-data) by 'cddr
......@@ -540,8 +547,8 @@ visible all the time in the minibuffer."
;; (match-data) could have been modified in the meantime, e.g. by vr--get-regexp-string->pcre-to-elisp.
(set-match-data match-data)
(if (stringp replacement)
(match-substitute-replacement replacement nocasify)
(match-substitute-replacement (funcall (car replacement) (cdr replacement) i) nocasify)))))
(match-substitute-replacement replacement nocasify vr/plain)
(match-substitute-replacement (funcall (car replacement) (cdr replacement) i) nocasify vr/plain)))))
(defun vr--do-replace-feedback-match-callback (replacement match-data i)
(let ((begin (cl-first match-data))
......@@ -591,7 +598,7 @@ visible all the time in the minibuffer."
(while (and
looping
(condition-case err
(re-search-forward regexp-string vr--target-buffer-end t)
(funcall (if vr/plain 'search-forward 're-search-forward) regexp-string vr--target-buffer-end t)
('invalid-regexp (progn (setq message-line (car (cdr err))) nil))))
(condition-case err
(progn
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment