[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/iedit 54b2495af7 214/301: More default occurrence types
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/iedit 54b2495af7 214/301: More default occurrence types |
Date: |
Mon, 10 Jan 2022 22:59:03 -0500 (EST) |
branch: elpa/iedit
commit 54b2495af755ca840a7aacbaad77f72b8b4a67b6
Author: Victor Ren <victorhge@gmail.com>
Commit: Victor Ren <victorhge@gmail.com>
More default occurrence types
The ideas are stolen from evil-iedit of Justin Burkett
<justin@burkett.cc>
Before there are just two types of default occurrence, symbol or not
symbol. Now there are email, url, word and others.
So that Justin don't have to advice iedit-regexp-quote in evil-iedit.
---
iedit-tests.el | 6 ++--
iedit.el | 86 ++++++++++++++++++++++++++++++++++++++++------------------
2 files changed, 62 insertions(+), 30 deletions(-)
diff --git a/iedit-tests.el b/iedit-tests.el
index b0be63092a..748355fd52 100644
--- a/iedit-tests.el
+++ b/iedit-tests.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2016-05-17 11:46:10 Victor Ren>
+;; Time-stamp: <2016-06-17 10:38:46 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Version: 0.97
;; X-URL: http://www.emacswiki.org/emacs/Iedit
@@ -114,7 +114,7 @@ foo"
(iedit-mode)
(should (= 4 (length iedit-occurrences-overlays)))
(should (string= iedit-initial-string-local "foo"))
- (should (null iedit-only-complete-symbol-local))
+ (should (eq 'selection iedit-occurrence-type-local))
(goto-char 1)
(set-mark-command nil)
(forward-line 3)
@@ -135,7 +135,7 @@ foo"
(iedit-mode)
(should (= 7 (length iedit-occurrences-overlays)))
(should (string= iedit-initial-string-local "foo"))
- (should (null iedit-only-complete-symbol-local))
+ (should (eq 'selection iedit-occurrence-type-local))
(goto-char 1)
(insert "123")
(should (string= (buffer-string)
diff --git a/iedit.el b/iedit.el
index 3d2d62e12f..a624d110ae 100644
--- a/iedit.el
+++ b/iedit.el
@@ -2,11 +2,12 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2016-06-12 13:58:26 Victor Ren>
+;; Time-stamp: <2016-06-17 11:28:45 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Keywords: occurrence region simultaneous refactoring
;; Version: 0.9.9
;; X-URL: http://www.emacswiki.org/emacs/Iedit
+;; https://github.com/victorhge/iedit
;; Compatibility: GNU Emacs: 22.x, 23.x, 24.x
;; This file is not part of GNU Emacs, but it is distributed under
@@ -66,6 +67,7 @@
;;; todo:
;; - Add more easy access keys for whole occurrence
+;; - pair in html
;;; Contributors
;; Adam Lindberg <eproxus@gmail.com> added a case sensitivity option that can
be toggled.
@@ -95,13 +97,17 @@ isearch-mode-map, esc-map and help-map."
(defvar iedit-mode nil) ;; Name of the minor mode
-(defvar iedit-only-complete-symbol-local t
+(defvar iedit-use-symbol-boundaries t
+ "If no-nil, matches have to start and end at symbol boundaries. Otherwise,
+matches starts and end at word bondaries.")
+
+(defvar iedit-occurrence-type-local 'symbol
"This is buffer local variable which indicates the occurrence
-only matches complete symbol.")
+type. It might be (symbol word other).")
-(defvar iedit-only-complete-symbol-global t
+(defvar iedit-occurrence-type-global 'symbol
"This is global variable which indicates the last global occurrence
-only matches complete symbol.")
+type. It might be (symbol word other).")
(defvar iedit-last-occurrence-local nil
"This is buffer local variable which is the occurrence when
@@ -128,30 +134,31 @@ point should be included in the replacement region.")
"This is a global variable indicating how many lines down from
point should be included in the replacement region.")
-(defvar iedit-default-occurrence '(lambda () (current-word t))
- "This is a function which returns a string as occurrence candidate.
-The default is the current symbol under the point. This local
-buffer varialbe can be configured in some modes. An example of
-how to use this variable:
+(defvar iedit-default-occurrence-mode-local nil
+ "This is a mode special function get a string as occurrence candidate.
+It is called in `iedit-default-occurrence'. This local buffer
+varialbe can be configured in some modes. An example of how to
+use this variable:
(add-hook 'perl-mode-hook
'(lambda ()
- (setq iedit-default-occurrence
+ (setq iedit-default-occurrence-mode-local
'(lambda ()
(let* ((bound (bounds-of-thing-at-point 'symbol))
(prefix-char (char-after (1- (car bound)))))
(if (memq prefix-char '(?$ ?% ?@ ?*))
(progn
- (setq iedit-only-complete-symbol-local nil)
+ (setq iedit-occurrence-type-local 'other)
(buffer-substring-no-properties (1- (car bound))
(cdr bound)))
(buffer-substring-no-properties (car bound) (cdr
bound))))))))
'$%@*' will be included in the occurrences in perl mode.")
(make-variable-buffer-local 'iedit-mode)
-(make-variable-buffer-local 'iedit-only-complete-symbol-local)
+(make-variable-buffer-local 'iedit-use-symbol-boundaries)
+(make-variable-buffer-local 'iedit-occurrence-type-local)
(make-variable-buffer-local 'iedit-last-occurrence-local)
(make-variable-buffer-local 'iedit-initial-string-local)
(make-variable-buffer-local 'iedit-initial-region)
-(make-variable-buffer-local 'iedit-default-occurrence)
+(make-variable-buffer-local 'iedit-default-occurrence-mode-local)
(or (assq 'iedit-mode minor-mode-alist)
(nconc minor-mode-alist
@@ -332,16 +339,14 @@ Keymap used within overlays:
\\{iedit-mode-occurrence-keymap}"
(interactive "P")
(if iedit-mode
- (progn
- (iedit-mode-on-action arg)
- (setq iedit-only-complete-symbol-global
iedit-only-complete-symbol-local))
+ (iedit-mode-on-action arg)
(iedit-barf-if-lib-active)
(let (occurrence
(beg (if (eq major-mode 'occur-edit-mode) ; skip the first occurrence
(next-single-char-property-change 1 'read-only)
(point-min)))
(end (point-max)))
- ;; Get the occurrence and iedit-only-complete-symbol-local
+ ;; Get the occurrence and iedit-occurrence-type-local
(cond ((and arg
(= 4 (prefix-numeric-value arg))
iedit-last-occurrence-local)
@@ -350,13 +355,12 @@ Keymap used within overlays:
(= 16 (prefix-numeric-value arg))
iedit-last-initial-string-global)
(setq occurrence iedit-last-initial-string-global)
- (setq iedit-only-complete-symbol-local
iedit-only-complete-symbol-global))
+ (setq iedit-occurrence-type-local iedit-occurrence-type-global))
((iedit-region-active)
(setq occurrence (buffer-substring-no-properties
(mark) (point)))
- (setq iedit-only-complete-symbol-local nil))
- (t (setq iedit-only-complete-symbol-local t); might be changed by
iedit-default-occurrence
- (setq occurrence (funcall iedit-default-occurrence))
+ (setq iedit-occurrence-type-local 'selection))
+ (t (setq occurrence (iedit-default-occurrence))
(unless occurrence
(error "No candidate of the occurrence, cannot enable Iedit
mode"))))
;; Get the scope
@@ -427,11 +431,37 @@ Keymap used within overlays:
(add-hook 'change-major-mode-hook 'iedit-done nil t)
(add-hook 'iedit-aborting-hook 'iedit-done nil t))
+(defun iedit-default-occurrence()
+ "This function returns a string as occurrence candidate."
+ (let (occurrence-str)
+ (cond
+ ((thing-at-point 'url)
+ (setq occurrence-str (thing-at-point 'url))
+ (setq iedit-occurrence-type-local 'url))
+
+ ((thing-at-point 'email)
+ (setq occurrence-str (thing-at-point 'email))
+ (setq iedit-occurrence-type-local 'email))
+
+ (iedit-default-occurrence-mode-local
+ (funcall iedit-default-occurrence-mode-local))
+
+ ((and iedit-use-symbol-boundaries ;option
+ (thing-at-point 'symbol))
+ (setq occurrence-str (thing-at-point 'symbol))
+ (setq iedit-occurrence-type-local 'symbol))
+
+ ((thing-at-point 'word)
+ (setq occurrence-str (thing-at-point 'word))
+ (setq iedit-occurrence-type-local 'word)))
+ occurrence-str))
+
(defun iedit-regexp-quote (exp)
"Return a regexp string."
- (if iedit-only-complete-symbol-local
- (concat "\\_<" (regexp-quote exp) "\\_>")
- (regexp-quote exp)))
+ (cl-case iedit-occurrence-type-local
+ ('symbol (concat "\\_<" (regexp-quote exp) "\\_>"))
+ ('word (concat "\\<" (regexp-quote exp) "\\>"))
+ ( t (regexp-quote exp))))
(defun iedit-start2 (occurrence-regexp beg end)
"Refresh Iedit mode."
@@ -452,6 +482,7 @@ the initial string globally."
(when iedit-buffering
(iedit-stop-buffering))
(setq iedit-last-occurrence-local (iedit-current-occurrence-string))
+ (setq iedit-occurrence-type-global iedit-occurrence-type-local)
(setq iedit-last-occurrence-global iedit-last-occurrence-local)
(setq iedit-last-initial-string-global iedit-initial-string-local)
(if iedit-last-occurrence-local
@@ -495,8 +526,9 @@ the initial string globally."
(when case-fold-search
(setq occurrence-exp (downcase occurrence-exp))
(setq replacement (downcase replacement)))
- (if iedit-only-complete-symbol-global
- (setq occurrence-exp (concat "\\_<" occurrence-exp "\\_>")))
+ ;; `iedit-regexp-quote' depends on iedit-occurrence-type-local
+ (setq iedit-occurrence-type-local iedit-occurrence-type-global)
+ (setq occurrence-exp (iedit-regexp-quote occurrence-exp))
(when (iedit-region-active)
(setq beg (region-beginning))
(setq end (region-end)))
- [nongnu] elpa/iedit 52c4865e5b 197/301: Add special prefix argument 1, (continued)
- [nongnu] elpa/iedit 52c4865e5b 197/301: Add special prefix argument 1, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 8d20094a11 182/301: Use the original case in the iedit-replace default value, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 1242c675d2 164/301: Add save-window-excursion, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit b5a3415b00 180/301: Merge pull request #47 from zhenya1007/help-char-can-be-meta, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 6019d3c376 170/301: defvar iedit-current-symbol, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 22f4729ae9 150/301: Add test case for iedit-hide-unmatched-lines, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 4884f61a3b 188/301: Merge branch 'master' of github.com:victorhge/iedit, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 607e82c7b0 208/301: rename `iedit-current-symbol` to `iedit-default-occurrence`, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 1eabaa061a 210/301: Merge branch 'master' of github.com:victorhge/iedit, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit a6d8568379 161/301: Merge pull request #35 from lewang/ensure-skip-mofication-once, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 54b2495af7 214/301: More default occurrence types,
ELPA Syncer <=
- [nongnu] elpa/iedit 5b0b618a20 219/301: Quit iedit-mode in `before-revert-hook', ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 7a6a0d65ab 252/301: Replace deprecated cl with cl-lib, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit c1b672cfc9 270/301: Fix bug #115. Now properly disable iedit-mode during desktop restore., ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 76ff4aa6b9 218/301: Merge pull request #64 from justbur/sgml-error, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 2221a517a8 227/301: Fix comments, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 0ef1410ec5 259/301: Add iedit-show/hide-occurrence-lines, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 326b6f7787 263/301: Merge `iedit-number-occurrences' and `iedit-increment-occurrences', ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 02bad3e3b9 240/301: Fix compile warnings, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit abb577e447 236/301: Merge pull request #77 from EdwardBetts/spelling, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 39919478f9 230/301: fix C-R-RET key binding problem in term, ELPA Syncer, 2022/01/10