Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Separate iedit-mode-from-isearch

Remove iedit-case-sensitive-local and iedit-case-sensistive-global

Do not start Iedit mode if matches are not the same length

Define default key bindings when `iedit-toogle-key-default' is defined.

If `iedit-toogle-key-default' is nil, default key bindings are not going to be defined.
  • Loading branch information...
commit e4d67bdb06d8e49820adbb8759430853375d9aa9 1 parent 466ab11
victorhge authored

Showing 2 changed files with 54 additions and 42 deletions. Show diff stats Hide diff stats

  1. +10 14 iedit-lib.el
  2. +44 28 iedit.el
24 iedit-lib.el
@@ -3,7 +3,7 @@
3 3
4 4 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
5 5
6   -;; Time-stamp: <2012-09-06 11:07:10 Victor Ren>
  6 +;; Time-stamp: <2012-09-07 16:28:18 Victor Ren>
7 7 ;; Author: Victor Ren <victorhge@gmail.com>
8 8 ;; Keywords: occurrence region simultaneous rectangle refactoring
9 9 ;; Version: 0.97
@@ -75,14 +75,10 @@ occurrence overlay is used to provide a different face
75 75 configurable via `iedit-occurrence-face'. The list is sorted by
76 76 the position of overlays.")
77 77
78   -(defvar iedit-case-sensitive-local iedit-case-sensitive-default
  78 +(defvar iedit-case-sensitive iedit-case-sensitive-default
79 79 "This is buffer local variable.
80 80 If no-nil, matching is case sensitive.")
81 81
82   -(defvar iedit-case-sensitive-global iedit-case-sensitive-default
83   - "This is global variable.
84   -If no-nil, matching is case sensitive.")
85   -
86 82 (defvar iedit-unmatched-lines-invisible nil
87 83 "This is buffer local variable which indicates whether
88 84 unmatched lines are hided.")
@@ -125,7 +121,7 @@ is not applied to other occurrences when it is true.")
125 121
126 122 (make-variable-buffer-local 'iedit-occurrences-overlays)
127 123 (make-variable-buffer-local 'iedit-unmatched-lines-invisible)
128   -(make-variable-buffer-local 'iedit-case-sensitive-local)
  124 +(make-local-variable 'iedit-case-sensitive)
129 125 (make-variable-buffer-local 'iedit-forward-success)
130 126 (make-variable-buffer-local 'iedit-before-modification-string)
131 127 (make-variable-buffer-local 'iedit-before-modification-undo-list)
@@ -170,7 +166,7 @@ is not applied to other occurrences when it is true.")
170 166 (defvar iedit-occurrence-keymap 'iedit-occurrence-keymap-default
171 167 "Keymap used within occurrence overlays.
172 168 It should be set before occurrence overlay is created.")
173   -(make-local-variable 'iedit-occurrence-context-lines)
  169 +(make-local-variable 'iedit-occurrence-keymap)
174 170
175 171 (defun iedit-help-for-occurrences ()
176 172 "Display `iedit-occurrence-keymap-default'"
@@ -187,21 +183,21 @@ It should be set before occurrence overlay is created.")
187 183 (substitute-command-keys "\\[iedit-last-occurrence]") ":first/last "
188 184 )))
189 185
190   -(defun iedit-make-occurrences-overlays (occurrence-exp beg end)
191   - "Create occurrence overlays for `occurrence-exp' in a region.
  186 +(defun iedit-make-occurrences-overlays (occurrence-regexp beg end)
  187 + "Create occurrence overlays for `occurrence-regexp' in a region.
192 188 Return the number of occurrences."
193 189 (setq iedit-aborting nil)
194 190 (setq iedit-occurrences-overlays nil)
195 191 ;; Find and record each occurrence's markers and add the overlay to the occurrences
196 192 (let ((counter 0)
197   - (case-fold-search (not iedit-case-sensitive-local)))
  193 + (case-fold-search (not iedit-case-sensitive)))
198 194 (save-excursion
199 195 (goto-char beg)
200   - (while (re-search-forward occurrence-exp end t)
  196 + (while (re-search-forward occurrence-regexp end t)
201 197 (push (iedit-make-occurrence-overlay (match-beginning 0) (match-end 0))
202 198 iedit-occurrences-overlays)
203 199 (setq counter (1+ counter)))
204   - (message "%d matches for \"%s\"" counter (iedit-printable occurrence-exp))
  200 + (message "%d matches for \"%s\"" counter (iedit-printable occurrence-regexp))
205 201 (when (/= 0 counter)
206 202 (setq iedit-occurrences-overlays (nreverse iedit-occurrences-overlays))
207 203 (if iedit-unmatched-lines-invisible
@@ -220,7 +216,7 @@ Return the number of occurrences."
220 216 "Create next or previous occurrence overlay for `occurrence-exp'."
221 217 (or point
222 218 (setq point (point)))
223   - (let ((case-fold-search (not iedit-case-sensitive-local)))
  219 + (let ((case-fold-search (not iedit-case-sensitive)))
224 220 (save-excursion
225 221 (goto-char point)
226 222 (if (not (if forward
72 iedit.el
@@ -2,7 +2,7 @@
2 2
3 3 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
4 4
5   -;; Time-stamp: <2012-09-05 09:47:56 Victor Ren>
  5 +;; Time-stamp: <2012-09-07 17:26:42 Victor Ren>
6 6 ;; Author: Victor Ren <victorhge@gmail.com>
7 7 ;; Keywords: occurrence region simultaneous refactoring
8 8 ;; Version: 0.97
@@ -200,10 +200,11 @@ This is like `describe-bindings', but displays only Iedit keys."
200 200 (describe-function 'iedit-mode)))
201 201
202 202 ;;; Default key bindings:
203   -(define-key global-map iedit-toogle-key-default 'iedit-mode)
204   -(define-key isearch-mode-map iedit-toogle-key-default 'iedit-mode)
205   -(define-key esc-map iedit-toogle-key-default 'iedit-execute-last-modification)
206   -(define-key help-map iedit-toogle-key-default 'iedit-mode-toggle-on-function)
  203 +(when iedit-toogle-key-default
  204 + (define-key global-map iedit-toogle-key-default 'iedit-mode)
  205 + (define-key isearch-mode-map iedit-toogle-key-default 'iedit-mode-from-isearch)
  206 + (define-key esc-map iedit-toogle-key-default 'iedit-execute-last-modification)
  207 + (define-key help-map iedit-toogle-key-default 'iedit-mode-toggle-on-function))
207 208
208 209 ;; Avoid to restore Iedit mode when restoring desktop
209 210 (add-to-list 'desktop-minor-mode-handlers
@@ -273,9 +274,9 @@ If region active, Iedit mode is limited within the current
273 274 region.
274 275
275 276 With repeated universal prefix argument, the occurrence when
276   -Iedit mode is turned off last time (might be in other buffer) is used
277   -as occurrence. If region active, Iedit mode is limited within
278   -the current region.
  277 +Iedit mode is turned off last time (might be in other buffer) is
  278 +used as occurrence. If region active, Iedit mode is limited
  279 +within the current region.
279 280
280 281 If Iedit mode is on and region is active, Iedit mode is
281 282 restricted in the region, e.g. the occurrences outside of the
@@ -316,10 +317,6 @@ Keymap used within overlays:
316 317 ((iedit-region-active)
317 318 (setq occurrence (buffer-substring-no-properties
318 319 (mark) (point))))
319   - ((and isearch-mode (not (string= isearch-string "")))
320   - (setq occurrence (buffer-substring-no-properties
321   - (point) isearch-other-end))
322   - (isearch-exit))
323 320 ((and iedit-current-symbol-default (current-word t))
324 321 (setq occurrence (current-word))
325 322 (when iedit-only-at-symbol-boundaries
@@ -337,30 +334,50 @@ Keymap used within overlays:
337 334 (setq iedit-only-complete-symbol-local complete-symbol)
338 335 (setq mark-active nil)
339 336 (run-hooks 'deactivate-mark-hook)
340   - (setq iedit-case-sensitive-local iedit-case-sensitive-default)
341   - (iedit-start occurrence beg end))))
342   -
343   -(defun iedit-start (occurrence-exp beg end)
344   - "Start Iedit mode for the OCCURRENCE-EXP in the current buffer."
  337 + (iedit-start (iedit-regexp-quote occurrence) beg end))))
  338 +
  339 +(defun iedit-mode-from-isearch (regexp)
  340 + "Start Iedit mode using last search string as the regexp."
  341 + (interactive
  342 + (let ((regexp (cond
  343 + ((functionp isearch-word)
  344 + (funcall isearch-word isearch-string))
  345 + (isearch-word (word-search-regexp isearch-string))
  346 + (isearch-regexp isearch-string)
  347 + (t (regexp-quote isearch-string)))))
  348 + (list regexp)))
  349 + (isearch-exit)
  350 + (iedit-start regexp (point-min) (point-max))
  351 + ;; TODO: reconsider how to avoid the loop in iedit-same-length
  352 + (if (iedit-same-length)
  353 + nil
  354 + (iedit-done)
  355 + (message "Matches are not the same length.")))
  356 +
  357 +(defun iedit-start (occurrence-regexp beg end)
  358 + "Start Iedit mode for the `occurrence-regexp' in the current buffer."
345 359 (setq iedit-unmatched-lines-invisible iedit-unmatched-lines-invisible-default)
346   - (setq iedit-initial-string-local occurrence-exp)
347   - (iedit-refresh occurrence-exp beg end)
  360 + (setq iedit-initial-string-local occurrence-regexp)
  361 + (iedit-start2 occurrence-regexp beg end)
348 362 (run-hooks 'iedit-mode-hook)
349 363 (add-hook 'kbd-macro-termination-hook 'iedit-done nil t)
350 364 (add-hook 'change-major-mode-hook 'iedit-done nil t)
351 365 (add-hook 'iedit-aborting-hook 'iedit-done nil t))
352 366
353   -(defun iedit-refresh (occurrence-exp beg end)
  367 +(defun iedit-regexp-quote (exp)
  368 + "Return a regexp string."
  369 + (if iedit-only-complete-symbol-local
  370 + (concat "\\_<" (regexp-quote exp) "\\_>")
  371 + (regexp-quote exp)))
  372 +
  373 +(defun iedit-start2 (occurrence-regexp beg end)
354 374 "Refresh Iedit mode."
355   - (setq occurrence-exp (regexp-quote occurrence-exp))
356 375 (setq iedit-occurrence-keymap iedit-mode-occurrence-keymap)
357   - (when iedit-only-complete-symbol-local
358   - (setq occurrence-exp (concat "\\_<" occurrence-exp "\\_>")))
359 376 (setq iedit-mode
360 377 (propertize
361 378 (concat " Iedit:"
362 379 (number-to-string
363   - (iedit-make-occurrences-overlays occurrence-exp beg end)))
  380 + (iedit-make-occurrences-overlays occurrence-regexp beg end)))
364 381 'face
365 382 'font-lock-warning-face))
366 383 (force-mode-line-update))
@@ -374,7 +391,6 @@ the initial string globally."
374 391 (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
375 392 (setq iedit-last-occurrence-global iedit-last-occurrence-local)
376 393 (setq iedit-last-initial-string-global iedit-initial-string-local)
377   - (setq iedit-case-sensitive-global iedit-case-sensitive-local)
378 394
379 395 (iedit-cleanup)
380 396
@@ -412,7 +428,7 @@ the initial string globally."
412 428 (error "No modification available"))
413 429 (let ((occurrence-exp (regexp-quote iedit-last-initial-string-global))
414 430 (replacement iedit-last-occurrence-global)
415   - (case-fold-search (not iedit-case-sensitive-global))
  431 + (case-fold-search (not iedit-case-sensitive))
416 432 beg end)
417 433 (when case-fold-search
418 434 (setq occurrence-exp (downcase occurrence-exp))
@@ -464,14 +480,14 @@ the initial string globally."
464 480 "Toggle case-sensitive matching occurrences.
465 481 Todo: how about region"
466 482 (interactive)
467   - (setq iedit-case-sensitive-local (not iedit-case-sensitive-local))
  483 + (setq iedit-case-sensitive (not iedit-case-sensitive))
468 484 (if iedit-buffering
469 485 (iedit-stop-buffering))
470 486 (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
471 487 (when iedit-last-occurrence-local
472 488 (remove-overlays nil nil iedit-occurrence-overlay-name t)
473 489 (iedit-show-all)
474   - (iedit-refresh iedit-last-occurrence-local (point-min) (point-max))))
  490 + (iedit-start2 (iedit-regexp-quote iedit-last-occurrence-local) (point-min) (point-max))))
475 491
476 492 (provide 'iedit)
477 493

0 comments on commit e4d67bd

Please sign in to comment.
Something went wrong with that request. Please try again.