[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/objed e9bf605 07/21: Refactor objec-replace
From: |
Clemens Radermacher |
Subject: |
[elpa] externals/objed e9bf605 07/21: Refactor objec-replace |
Date: |
Sun, 17 Mar 2019 15:00:17 -0400 (EDT) |
branch: externals/objed
commit e9bf60510d7389bbe181f01ad62c945e74dac070
Author: Clemens Radermacher <address@hidden>
Commit: Clemens Radermacher <address@hidden>
Refactor objec-replace
---
objed.el | 65 ++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 37 insertions(+), 28 deletions(-)
diff --git a/objed.el b/objed.el
index 8b81074..0551cb8 100644
--- a/objed.el
+++ b/objed.el
@@ -2814,12 +2814,12 @@ c: capitalize."
(defun objed-replace ()
"Query replace narrowed to region BEG, END."
(interactive)
- (let ((beg (objed--beg))
- (end (objed--end)))
- (if (memq objed--object '(word symbol identifier))
- (objed--replace-ident beg end)
- (save-excursion
- (save-restriction
+ (if (memq objed--object '(word symbol identifier))
+ (objed--replace-object)
+ (save-excursion
+ (save-restriction
+ (let ((beg (objed--beg))
+ (end (objed--end)))
(narrow-to-region beg end)
(goto-char (point-min))
(hl-line-unhighlight)
@@ -2828,22 +2828,25 @@ c: capitalize."
(call-interactively 'anzu-query-replace-regexp)
(call-interactively 'query-replace-regexp)))))))
-(defun objed--replace-ident (beg end)
- "Replace text between BEG and END for object(s)."
- (let ((str (objed--with-allow-input
- (read-string "Replace with: "
- nil nil (buffer-substring beg end)))))
- (if objed--marked-ovs
- (objed--do-objects (apply-partially #'objed--replace-action str)
- this-command)
- (objed--replace-action str beg end))))
-
-(defun objed--replace-action (str beg end)
- "Replace region BEG, END with STR."
+(defun objed--replace-object ()
+ "Replace current object(s) with string queried from user."
+ (let* ((beg (objed--beg))
+ (end (objed--end))
+ (str (objed--with-allow-input
+ (read-string "Replace with: "
+ nil nil (buffer-substring beg end))))
+ (n (objed--do (apply-partially
+ #'objed--replace-region-with-string str)
+ this-command)))
+ (message "Replaced %s objects." n)))
+
+
+(defun objed--replace-region-with-string (str beg end)
+ "Use string STR to replace region BEG, END."
(save-excursion
(goto-char beg)
- (delete-region beg end)
- (insert str)))
+ (search-forward (buffer-substring beg end))
+ (replace-match str)))
;; * Ipipe
@@ -3247,7 +3250,9 @@ Resets objed if appropriate."
"Execute ACTION on current object(s).
NAME is the symbol used for current op and defaults to
-`this-command'."
+`this-command'.
+
+Return number of times ACTION got applied."
(let ((name (or name this-command)))
(cond (objed--marked-ovs
(objed--do-objects action name))
@@ -3261,26 +3266,30 @@ NAME is the symbol used for current op and defaults to
(let ((text (apply #'buffer-substring range))
(range (list (set-marker (make-marker) (car range))
(set-marker (make-marker) (cadr range)))))
- (apply action range)
- (objed-exit-op name text range)))))
+ (prog1 1
+ (apply action range)
+ (objed-exit-op name text range))))))
(defun objed--do-objects (action name)
"Apply ACTION for op named NAME on marked objects."
(let ((ovs objed--marked-ovs)
- (appendp (memq action '(kill-region copy-region-as-kill))))
+ (appendp (memq action '(kill-region copy-region-as-kill)))
+ (n 0))
(save-excursion
(dolist (ov (nreverse (copy-sequence ovs)))
(let ((beg (overlay-start ov))
(end (overlay-end ov)))
(when (and beg end)
(goto-char beg)
- (funcall action beg end))
+ (funcall action beg end)
+ (cl-incf n))
(when appendp
(setq last-command 'kill-region))
(delete-overlay ov))))
- ;; always ?
- (setq objed--marked-ovs nil)
- (objed-exit-op name)))
+ (prog1 n
+ ;; always ?
+ (setq objed--marked-ovs nil)
+ (objed-exit-op name))))
(defun objed--ov-sequence-p (ovs)
- [elpa] externals/objed updated (aa8f32d -> 4cb9beb), Clemens Radermacher, 2019/03/17
- [elpa] externals/objed 209f0a6 20/21: Add reformat op, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed cc629a5 18/21: Add imenu to op map, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed 0676656 19/21: Improve url object, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed 4cb9beb 21/21: Version bump, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed 9689c72 17/21: Reinit after raise, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed 85941b8 16/21: Add objed-execute command, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed 4bb1b90 12/21: Add url object, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed 7627082 13/21: Don't ignore search errors, error with not other object found msg., Clemens Radermacher, 2019/03/17
- [elpa] externals/objed 998563a 06/21: Remove redundant :group declarations, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed e9bf605 07/21: Refactor objec-replace,
Clemens Radermacher <=
- [elpa] externals/objed 85019a8 14/21: Add raise command, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed c9b7c2a 05/21: Fix var not defined for edit-indirect, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed 2274a94 02/21: Add package-lint to linting tests, and fix its errors/warnings, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed 6ea0268 01/21: Buffer switch: Keep objed--object if possible, and update highlight, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed 1054cd8 03/21: Compile tests like elpa does, and fix the compile errors in tests, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed f5cc1ce 15/21: Remove binding for disfunct objed repeat, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed bb5d097 11/21: Improve file object, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed 96d5bc9 10/21: Add mail object, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed cc6c36f 08/21: Derive package name from current dir, Clemens Radermacher, 2019/03/17
- [elpa] externals/objed be0cd7c 09/21: Fix identifier immediate jumping if used as last command, Clemens Radermacher, 2019/03/17