Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 807 lines (712 sloc) 33.671 kb
e9a94852 »
2010-03-08 updates
1 ;;; iedit.el --- Edit multiple regions with the same content simultaneously.
2
02946e07 »
2012-01-17 Update contributors and spell check
3 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
e9a94852 »
2010-03-08 updates
4
0d4027fe »
2012-02-02 Move save-excursion out of dolist
5 ;; Time-stamp: <2012-02-02 23:32:57 Victor Ren>
e9a94852 »
2010-03-08 updates
6 ;; Author: Victor Ren <victorhge@gmail.com>
7 ;; Keywords: occurrence region replace simultaneous
9b3aaa8f »
2012-01-29 Fix occurrence from history does not exist problem
8 ;; Version: 0.92
9a891d7a »
2010-03-13 updates
9 ;; X-URL: http://www.emacswiki.org/emacs/iedit.el
5ad28b5e »
2011-02-25 updates
10 ;; Compatibility: GNU Emacs: 22.x, 23.x, 24.x
e9a94852 »
2010-03-08 updates
11
12 ;; This file is not part of GNU Emacs, but it is distributed under
13 ;; the same terms as GNU Emacs.
14
15 ;; GNU Emacs is free software: you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation, either version 3 of the License, or
18 ;; (at your option) any later version.
19
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
24
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27
28 ;;; Commentary:
29
30 ;; This package provides a more intuitive way of replace-string operation:
31 ;;
32 ;; - Select the occurrence in the buffer
da0a2470 »
2011-10-27 Add option to match only complete words, not inside words
33 ;; In Transient Mark mode, just mark a region, the content of the
e9a94852 »
2010-03-08 updates
34 ;; region will be used as the occurrence. (if Transient Mark mode is disabled,
35 ;; using C-u C-x C-x or C-SPC C-SPC to activate it just for this one time).
36 ;;
37 ;; - Start iedit minor mode - by press C-;
38 ;; All occurrences of the content in the buffer are highlighted
39 ;;
40 ;; - Edit one of the contents
41 ;; The change is applied to other contents simultaneously
42 ;;
43 ;; - Finish - by pressing C-; again
44
f808bf1c »
2012-01-17 Merge from lewang/master and update comments
45 ;; If Transient Mark mode is disabled or the region is not active, the current
6d969922 »
2012-01-17 Remove duplicated comments
46 ;; symbol (returns from `current-word') is used as the occurrence by default.
e9a94852 »
2010-03-08 updates
47
48 ;; You can also switch to iedit mode from isearch mode directly. The current
49 ;; search string is used as the occurrence.
50
51 ;; If you would like to replace-string on certain region, use "narrowing" first.
52
53 ;;; Suggested key bindings:
54 ;;
55 ;; (define-key global-map (kbd "C-;") 'iedit-mode)
56 ;; (define-key isearch-mode-map (kbd "C-;") 'iedit-mode)
57
58 ;;; todo:
9b3aaa8f »
2012-01-29 Fix occurrence from history does not exist problem
59 ;; - profile to find bottleneck for huge file
60 ;; - Add more easy access keys for whole occurrence
02946e07 »
2012-01-17 Update contributors and spell check
61 ;; - C-n,C-p is slow when unmatched lines are hided.
5ad28b5e »
2011-02-25 updates
62 ;; - toggle blank line between matched lines?
ec6785b0 »
2012-01-14 host on git
63 ;; - ert unit test
e9a94852 »
2010-03-08 updates
64
ec6785b0 »
2012-01-14 host on git
65 ;;; Contributors
66 ;; Adam Lindberg <eproxus@gmail.com> added a case sensitivity option that can be toggled.
02946e07 »
2012-01-17 Update contributors and spell check
67
68 ;; Tassilo Horn <tassilo@member.fsf.org> added an option to match only complete
69 ;; words, not inside words
70
9b3aaa8f »
2012-01-29 Fix occurrence from history does not exist problem
71 ;; Le Wang <l26wang@gmail.com> proposed to match only complete symbols, not
e99e65fc »
2012-02-02 Fix current point move problem when call iedit-replace-occurrences.
72 ;; inside symbols, contributed rectangle support
ec6785b0 »
2012-01-14 host on git
73
e9a94852 »
2010-03-08 updates
74 ;;; Code:
75
76 (eval-when-compile (require 'cl))
77
78 (defgroup iedit nil
79 "Edit multiple regions with the same content simultaneously."
80 :prefix "iedit-"
81 :group 'replace
82 :group 'convenience)
83
84 (defcustom iedit-occurrence-face 'highlight
85 "*Face used for the occurrences' default values."
86 :type 'face
87 :group 'iedit)
88
fc71952c »
2012-01-17 Boolean `t'
89 (defcustom iedit-current-symbol-default t
f808bf1c »
2012-01-17 Merge from lewang/master and update comments
90 "If no-nil, use current symbol by default for the occurrence."
e9a94852 »
2010-03-08 updates
91 :type 'boolean
92 :group 'iedit)
93
fc71952c »
2012-01-17 Boolean `t'
94 (defcustom iedit-case-sensitive-default t
5ad28b5e »
2011-02-25 updates
95 "If no-nil, matching is case sensitive"
96 :type 'boolean
97 :group 'iedit)
98
f808bf1c »
2012-01-17 Merge from lewang/master and update comments
99 (defcustom iedit-only-at-symbol-boundaries t
100 "If no-nil, matches have to start and end at symbol boundaries.
da0a2470 »
2011-10-27 Add option to match only complete words, not inside words
101 For example, when invoking iedit-mode on the \"in\" in the
102 sentence \"The king in the castle...\", the \"king\" is not
103 edited."
104 :type 'boolean
105 :group 'iedit)
106
e9a94852 »
2010-03-08 updates
107 (defcustom iedit-unmatched-lines-invisible-default nil
9a891d7a »
2010-03-13 updates
108 "If no-nil, hide lines that do not cover any occurrences by
109 default."
e9a94852 »
2010-03-08 updates
110 :type 'boolean
111 :group 'iedit)
112
113 (defvar iedit-mode-hook nil
114 "Function(s) to call after starting up an iedit.")
115
116 (defvar iedit-mode-end-hook nil
117 "Function(s) to call after terminating an iedit.")
118
119 (defvar iedit-mode nil) ;; Name of the minor mode
120
121 (make-variable-buffer-local 'iedit-mode)
122
123 (or (assq 'iedit-mode minor-mode-alist)
124 (nconc minor-mode-alist
9bc57d2a »
2012-01-30 make iedit-skipped-modification-once buffer local
125 (list '(iedit-mode iedit-mode))))
e9a94852 »
2010-03-08 updates
126
127 (defvar iedit-occurrences-overlays nil
9a891d7a »
2010-03-13 updates
128 "The occurrences slot contains a list of overlays used to
129 indicate the position of each occurrence. In addition, the
130 occurrence overlay is used to provide a different face
131 configurable via `iedit-occurrence-face'.")
e9a94852 »
2010-03-08 updates
132
6e492250 »
2012-01-30 Add iedit-toggle-case-sensitive
133 (defvar iedit-case-sensitive iedit-case-sensitive-default
5ad28b5e »
2011-02-25 updates
134 "This is buffer local variable. If no-nil, matching is case
135 sensitive.")
136
e9a94852 »
2010-03-08 updates
137 (defvar iedit-unmatched-lines-invisible nil
9a891d7a »
2010-03-13 updates
138 "This is buffer local variable which indicates whether
139 unmatched lines are hided.")
e9a94852 »
2010-03-08 updates
140
141 (defvar iedit-last-occurrence-in-history nil
142 "This is buffer local variable which is the occurrence when
9a891d7a »
2010-03-13 updates
143 iedit mode is turned off last time.")
144
0edc86ff »
2012-01-25 Fix the last occurrence problem when it is a complete symbol.
145 (defvar iedit-current-occurrence-complete-symbol nil
146 "This is buffer local variable which indicates the occurrence
147 only matches complete symbol.")
148
9a891d7a »
2010-03-13 updates
149 (defvar iedit-forward-success t
039c0e23 »
2012-01-24 Postpone iedit-done after commands are excuted.
150 "This is buffer local variable which indicates the moving
9a891d7a »
2010-03-13 updates
151 forward or backward successful")
e9a94852 »
2010-03-08 updates
152
c8dac6be »
2012-01-21 exit iedit mode when change is not inside of occurrence.
153 (defvar iedit-before-modification-string ""
154 "This is buffer local variable which is the buffer substring that is going to be changed.")
d4b9fd53 »
2012-01-20 don't call hooks when there is only text properites change
155
c53a885f »
2012-01-30 Add bufferring modification functionalities
156 (defvar iedit-before-modification-undo-list nil
157 "This is buffer local variable which is the buffer undo list before modification.")
039c0e23 »
2012-01-24 Postpone iedit-done after commands are excuted.
158 ;; `iedit-occurrence-update' gets called twice when change==0 and occurrence
a75c4464 »
2012-01-26 fix bug with autopair and iedit-rect
159 ;; is zero-width (beg==end)
039c0e23 »
2012-01-24 Postpone iedit-done after commands are excuted.
160 ;; -- for front and back insertion.
a75c4464 »
2012-01-26 fix bug with autopair and iedit-rect
161 (defvar iedit-skipped-modification-once nil
162 "Variable used to skip first modification hook run when insertion against a zero-width occurrence.")
039c0e23 »
2012-01-24 Postpone iedit-done after commands are excuted.
163
164 (defvar iedit-aborting nil
165 "This is buffer local variable which indicates iedit-mode is aborting.")
166
c53a885f »
2012-01-30 Add bufferring modification functionalities
167 (defvar iedit-buffering nil
168 "This is buffer local variable which indicates iedit-mode is
169 buffering, which means the modification to the current
170 occurrence is not applied to other occurrences when it is true.")
171
e9a94852 »
2010-03-08 updates
172 (make-variable-buffer-local 'iedit-occurrences-overlays)
173 (make-variable-buffer-local 'iedit-unmatched-lines-invisible)
5ad28b5e »
2011-02-25 updates
174 (make-variable-buffer-local 'iedit-case-sensitive)
9a891d7a »
2010-03-13 updates
175 (make-variable-buffer-local 'iedit-last-occurrence-in-history)
176 (make-variable-buffer-local 'iedit-forward-success)
c8dac6be »
2012-01-21 exit iedit mode when change is not inside of occurrence.
177 (make-variable-buffer-local 'iedit-before-modification-string)
c53a885f »
2012-01-30 Add bufferring modification functionalities
178 (make-variable-buffer-local 'iedit-before-modification-undo-list)
9bc57d2a »
2012-01-30 make iedit-skipped-modification-once buffer local
179 (make-variable-buffer-local 'iedit-skipped-modification-once)
039c0e23 »
2012-01-24 Postpone iedit-done after commands are excuted.
180 (make-variable-buffer-local 'iedit-aborting)
c53a885f »
2012-01-30 Add bufferring modification functionalities
181 (make-variable-buffer-local 'iedit-buffering)
e9a94852 »
2010-03-08 updates
182
183 (defconst iedit-occurrence-overlay-name 'iedit-occurrence-overlay-name)
184 (defconst iedit-invisible-overlay-name 'iedit-invisible-overlay-name)
5ad28b5e »
2011-02-25 updates
185
186 ;;; Define iedit help map.
187 (eval-when-compile (require 'help-macro))
188
189 (defvar iedit-help-map
190 (let ((map (make-sparse-keymap)))
191 (define-key map (char-to-string help-char) 'iedit-help-for-help)
192 (define-key map [help] 'iedit-help-for-help)
193 (define-key map [f1] 'iedit-help-for-help)
194 (define-key map "?" 'iedit-help-for-help)
195 (define-key map "b" 'iedit-describe-bindings)
196 (define-key map "k" 'iedit-describe-key)
197 (define-key map "m" 'iedit-describe-mode)
198 (define-key map "q" 'help-quit)
199 map)
200 "Keymap for characters following the Help key for iedit mode.")
201
9bc57d2a »
2012-01-30 make iedit-skipped-modification-once buffer local
202 (make-help-screen
203 iedit-help-for-help-internal
204 (purecopy "Type a help option: [bkm] or ?")
205 "You have typed %THIS-KEY%, the help character. Type a Help option:
5ad28b5e »
2011-02-25 updates
206 \(Type \\<help-map>\\[help-quit] to exit the Help command.)
207
208 b Display all Iedit key bindings.
209 k KEYS Display full documentation of Iedit key sequence.
210 m Display documentation of Iedit mode.
211
212 You can't type here other help keys available in the global help map,
213 but outside of this help window when you type them in Iedit mode,
214 they exit Iedit mode before displaying global help."
9bc57d2a »
2012-01-30 make iedit-skipped-modification-once buffer local
215 iedit-help-map)
5ad28b5e »
2011-02-25 updates
216
217 (defun iedit-help-for-help ()
218 "Display Iedit help menu."
219 (interactive)
220 (let (same-window-buffer-names same-window-regexps)
221 (iedit-help-for-help-internal)))
222
223 (defun iedit-describe-bindings ()
224 "Show a list of all keys defined in Iedit mode, and their definitions.
225 This is like `describe-bindings', but displays only Iedit keys."
226 (interactive)
227 (let (same-window-buffer-names same-window-regexps)
228 (with-help-window "*Help*"
229 (with-current-buffer standard-output
c53a885f »
2012-01-30 Add bufferring modification functionalities
230 (princ "Iedit Mode Bindings:
231 ")
da47784c »
2012-01-29 Add iedit mode easy access keys
232 (princ (substitute-command-keys "\\{iedit-occurrence-local-map}"))))))
5ad28b5e »
2011-02-25 updates
233
234 (defun iedit-describe-key ()
235 "Display documentation of the function invoked by iedit key."
236 (interactive)
237 (let (same-window-buffer-names same-window-regexps)
238 (call-interactively 'describe-key)))
239
240 (defun iedit-describe-mode ()
241 "Display documentation of iedit mode."
242 (interactive)
243 (let (same-window-buffer-names same-window-regexps)
244 (describe-function 'iedit-mode)))
245
246 ;;; Define iedit mode map
1d070b7d »
2012-01-25 move init code for iedit-mode-map inside defvar
247 (defvar iedit-mode-map
652087d6 »
2012-01-27 fix warning: the function `make-sparse-key-map' is not known to be
248 (let ((map (make-sparse-keymap)))
1d070b7d »
2012-01-25 move init code for iedit-mode-map inside defvar
249 ;; Default key bindings
652087d6 »
2012-01-27 fix warning: the function `make-sparse-key-map' is not known to be
250 (define-key map (kbd "TAB") 'iedit-next-occurrence)
251 (define-key map (kbd "<S-tab>") 'iedit-prev-occurrence)
252 (define-key map (kbd "<S-iso-lefttab>") 'iedit-prev-occurrence)
253 (define-key map (kbd "<backtab>") 'iedit-prev-occurrence)
254 (define-key map (kbd "C-'") 'iedit-toggle-unmatched-lines-visible)
255 (define-key map (char-to-string help-char) iedit-help-map)
256 (define-key map [help] iedit-help-map)
257 (define-key map [f1] iedit-help-map)
1d070b7d »
2012-01-25 move init code for iedit-mode-map inside defvar
258 map)
e9a94852 »
2010-03-08 updates
259 "Keymap used while iedit mode is enabled.")
260
da47784c »
2012-01-29 Add iedit mode easy access keys
261 (defvar iedit-occurrence-local-map
262 (let ((map (make-sparse-keymap)))
263 (set-keymap-parent map iedit-mode-map)
264 (define-key map (kbd "M-u") 'iedit-upcase-occurrences)
265 (define-key map (kbd "M-l") 'iedit-downcase-occurrences)
266 (define-key map (kbd "M-r") 'iedit-replace-occurrences)
6e492250 »
2012-01-30 Add iedit-toggle-case-sensitive
267 (define-key map (kbd "M-C") 'iedit-clear-occurrences)
268 (define-key map (kbd "M-c") 'iedit-toggle-case-sensitive)
c53a885f »
2012-01-30 Add bufferring modification functionalities
269 (define-key map (kbd "M-D") 'iedit-delete-occurrences)
78f606d4 »
2012-02-02 Add iedit-number-occurrences function
270 (define-key map (kbd "M-N") 'iedit-number-occurrences)
c53a885f »
2012-01-30 Add bufferring modification functionalities
271 (define-key map [C-return] 'iedit-toggle-buffering)
7d18e5d7 »
2012-01-29 Add a help command C-? for occurrences
272 (define-key map (kbd "C-?") 'iedit-help-for-occurrences)
da47784c »
2012-01-29 Add iedit mode easy access keys
273 map)
274 "Keymap used within overlays.")
275
7d18e5d7 »
2012-01-29 Add a help command C-? for occurrences
276 (defun iedit-help-for-occurrences ()
277 "Display iedit-occurrence-local-map."
278 (interactive)
c53a885f »
2012-01-30 Add bufferring modification functionalities
279 (message "M-u/l:up/downcase M-r:replace M-c:clear M-D:delete C-return:buffering C-?:help"))
7d18e5d7 »
2012-01-29 Add a help command C-? for occurrences
280
e9a94852 »
2010-03-08 updates
281 (or (assq 'iedit-mode minor-mode-map-alist)
282 (setq minor-mode-map-alist
5ad28b5e »
2011-02-25 updates
283 (cons (cons 'iedit-mode iedit-mode-map) minor-mode-map-alist)))
e9a94852 »
2010-03-08 updates
284
285 ;;;###autoload
286 (defun iedit-mode (&optional arg)
287 "Toggle iedit mode.
288 If iedit mode is off, turn iedit mode on, off otherwise.
289
290 In Transient Mark mode, when iedit mode is turned on, all the
f808bf1c »
2012-01-17 Merge from lewang/master and update comments
291 occurrences of the current region are highlighted. If one
e9a94852 »
2010-03-08 updates
292 occurrence is modified, the change are propagated to all other
293 occurrences simultaneously.
294
295 If Transient Mark mode is disabled or the region is not active,
6d969922 »
2012-01-17 Remove duplicated comments
296 the current symbol (returns from `current-word') is used as the
297 occurrence by default. The occurrences of the current
298 symbol, but not include occurrences that are part of other
299 symbols, are highlighted. This is good for renaming refactoring
300 during programming. If you still want to match all the
301 occurrences, even though they are parts of other symbols, you may
302 have to select the symbol first.
e9a94852 »
2010-03-08 updates
303
304 You can also switch to iedit mode from isearch mode directly. The
305 current search string is used as occurrence. All occurrences of
306 the current search string are highlighted.
307
ec765ee0 »
2012-01-19 implement interactive string-rectangle mode with universal argument a…
308 With a universal prefix argument and no active region, the
309 occurrence when iedit is turned off last time is used as
310 occurrence. This is intended to recover last iedit which is
311 turned off by mistake.
312
313 With a universal prefix argument and region active, interactively
314 edit region as a string rectangle.
e9a94852 »
2010-03-08 updates
315
316 Commands:
da47784c »
2012-01-29 Add iedit mode easy access keys
317 \\{iedit-occurrence-local-map}"
e08ad592 »
2012-02-01 Make Iedit mode available for read only buffer
318 (interactive "P")
e9a94852 »
2010-03-08 updates
319 (if iedit-mode
320 (iedit-done)
ec765ee0 »
2012-01-19 implement interactive string-rectangle mode with universal argument a…
321 (let (occurrence rect-string)
322 (cond ((and arg
0edc86ff »
2012-01-25 Fix the last occurrence problem when it is a complete symbol.
323 (or (not transient-mark-mode) (not mark-active)
324 (equal (mark) (point)))
ec765ee0 »
2012-01-19 implement interactive string-rectangle mode with universal argument a…
325 iedit-last-occurrence-in-history)
e9a94852 »
2010-03-08 updates
326 (setq occurrence iedit-last-occurrence-in-history))
ec765ee0 »
2012-01-19 implement interactive string-rectangle mode with universal argument a…
327 ((and arg
0edc86ff »
2012-01-25 Fix the last occurrence problem when it is a complete symbol.
328 transient-mark-mode mark-active (not (equal (mark) (point))))
ec765ee0 »
2012-01-19 implement interactive string-rectangle mode with universal argument a…
329 (setq rect-string t))
e9a94852 »
2010-03-08 updates
330 ((and transient-mark-mode mark-active (not (equal (mark) (point))))
df6c2ad9 »
2012-01-18 fix search to use regexp-quote when needed
331 (setq occurrence (regexp-quote (buffer-substring-no-properties
332 (mark) (point)))))
e9a94852 »
2010-03-08 updates
333 ((and isearch-mode (not (string= isearch-string "")))
0edc86ff »
2012-01-25 Fix the last occurrence problem when it is a complete symbol.
334 (setq occurrence (regexp-quote (buffer-substring-no-properties
335 (point) isearch-other-end)))
e9a94852 »
2010-03-08 updates
336 (isearch-exit))
f808bf1c »
2012-01-17 Merge from lewang/master and update comments
337 ((and iedit-current-symbol-default (current-word t))
df6c2ad9 »
2012-01-18 fix search to use regexp-quote when needed
338 (setq occurrence (regexp-quote (current-word)))
f808bf1c »
2012-01-17 Merge from lewang/master and update comments
339 (when iedit-only-at-symbol-boundaries
0edc86ff »
2012-01-25 Fix the last occurrence problem when it is a complete symbol.
340 (setq iedit-current-occurrence-complete-symbol t)
e08ad592 »
2012-02-01 Make Iedit mode available for read only buffer
341 (setq occurrence (concat "\\_<" occurrence "\\_>"))))
e9a94852 »
2010-03-08 updates
342 (t (error "No candidate of the occurrence, cannot enable iedit mode.")))
ec765ee0 »
2012-01-19 implement interactive string-rectangle mode with universal argument a…
343 (if rect-string
344 (let ((beg (region-beginning))
345 (end (region-end)))
346 (deactivate-mark)
347 (iedit-rectangle beg end))
348 (deactivate-mark)
6e492250 »
2012-01-30 Add iedit-toggle-case-sensitive
349 (setq iedit-case-sensitive iedit-case-sensitive-default)
ec765ee0 »
2012-01-19 implement interactive string-rectangle mode with universal argument a…
350 (iedit-start occurrence)))))
e9a94852 »
2010-03-08 updates
351
f808bf1c »
2012-01-17 Merge from lewang/master and update comments
352 (defun iedit-start (occurrence-exp)
353 "Start an iedit for the occurrence-exp in the current buffer."
e9a94852 »
2010-03-08 updates
354 (setq iedit-occurrences-overlays nil)
355 (setq iedit-unmatched-lines-invisible iedit-unmatched-lines-invisible-default)
9b3aaa8f »
2012-01-29 Fix occurrence from history does not exist problem
356 (setq iedit-aborting nil)
e9a94852 »
2010-03-08 updates
357 ;; Find and record each occurrence's markers and add the overlay to the occurrences
5ad28b5e »
2011-02-25 updates
358 (let ((counter 0)
f808bf1c »
2012-01-17 Merge from lewang/master and update comments
359 (case-fold-search (not iedit-case-sensitive)))
360 (save-excursion
361 (goto-char (point-min))
362 (while (re-search-forward occurrence-exp nil t)
363 (push (iedit-make-occurrence-overlay (match-beginning 0) (match-end 0))
364 iedit-occurrences-overlays)
9b3aaa8f »
2012-01-29 Fix occurrence from history does not exist problem
365 (setq counter (1+ counter)))
366 (if (= 0 counter)
367 (error "0 matches for \"%s\""
368 (if (> (length occurrence-exp) 50)
369 (concat (substring occurrence-exp 0 50) "...")
370 occurrence-exp))
371 (setq iedit-occurrences-overlays (nreverse iedit-occurrences-overlays))
372 (if iedit-unmatched-lines-invisible
373 (iedit-hide-unmatched-lines)))
da0a2470 »
2011-10-27 Add option to match only complete words, not inside words
374 (message "%d matches for \"%s\""
375 counter
e9a94852 »
2010-03-08 updates
376 (if (> (length occurrence-exp) 50)
377 (concat (substring occurrence-exp 0 50) "...")
9b3aaa8f »
2012-01-29 Fix occurrence from history does not exist problem
378 occurrence-exp))))
379 (setq iedit-mode (propertize " Iedit" 'face 'font-lock-warning-face))
380 (force-mode-line-update)
381 (run-hooks 'iedit-mode-hook)
382 ;; (add-hook 'mouse-leave-buffer-hook 'iedit-done)
383 (add-hook 'kbd-macro-termination-hook 'iedit-done))
5ad28b5e »
2011-02-25 updates
384
039c0e23 »
2012-01-24 Postpone iedit-done after commands are excuted.
385
ec765ee0 »
2012-01-19 implement interactive string-rectangle mode with universal argument a…
386 (defun iedit-rectangle (beg end)
387 "Start an iedit for the region as a rectangle"
e08ad592 »
2012-02-01 Make Iedit mode available for read only buffer
388 (barf-if-buffer-read-only)
ec765ee0 »
2012-01-19 implement interactive string-rectangle mode with universal argument a…
389 (setq iedit-mode (propertize " Iedit-RECT" 'face 'font-lock-warning-face))
390 (setq iedit-occurrences-overlays nil)
391 (force-mode-line-update)
392 (run-hooks 'iedit-mode-hook)
393 (add-hook 'kbd-macro-termination-hook 'iedit-done)
c53a885f »
2012-01-30 Add bufferring modification functionalities
394 (save-excursion
395 (let ((beg-col (progn (goto-char beg) (current-column)))
396 (end-col (progn (goto-char end) (current-column))))
397 (when (< end-col beg-col)
398 (rotatef beg-col end-col))
399 (goto-char beg)
400 (loop do (progn
401 (push (iedit-make-occurrence-overlay
402 (progn
403 (move-to-column beg-col t)
404 (point))
405 (progn
406 (move-to-column end-col t)
407 (point)))
408 iedit-occurrences-overlays)
409 (forward-line 1))
410 until (> (point) end))
411 (setq iedit-occurrences-overlays (nreverse iedit-occurrences-overlays)))))
ec765ee0 »
2012-01-19 implement interactive string-rectangle mode with universal argument a…
412
e9a94852 »
2010-03-08 updates
413 (defun iedit-done ()
414 "Exit iedit mode."
c53a885f »
2012-01-30 Add bufferring modification functionalities
415 (if iedit-buffering
416 (iedit-stop-buffering))
17ce9738 »
2012-01-27 Clean up code
417 (let* ((ov (car iedit-occurrences-overlays))
418 (beg (overlay-start ov))
419 (end (overlay-end ov)))
0edc86ff »
2012-01-25 Fix the last occurrence problem when it is a complete symbol.
420 (setq iedit-last-occurrence-in-history
17ce9738 »
2012-01-27 Clean up code
421 (if (and ov (/= beg end))
422 (let ((substring (buffer-substring-no-properties beg end)))
0edc86ff »
2012-01-25 Fix the last occurrence problem when it is a complete symbol.
423 (if iedit-current-occurrence-complete-symbol
424 (concat "\\_<" substring "\\_>")
425 substring))
426 nil)
427 ))
428 (setq iedit-current-occurrence-complete-symbol nil)
e9a94852 »
2010-03-08 updates
429 (remove-overlays (point-min) (point-max) iedit-occurrence-overlay-name t)
430 (remove-overlays (point-min) (point-max) iedit-invisible-overlay-name t)
431 (setq iedit-occurrences-overlays nil)
c53a885f »
2012-01-30 Add bufferring modification functionalities
432 (setq iedit-aborting nil)
433 (setq iedit-before-modification-string "")
434 (setq iedit-before-modification-undo-list nil)
5ad28b5e »
2011-02-25 updates
435 ;; (remove-hook 'mouse-leave-buffer-hook 'iedit-done)
e9a94852 »
2010-03-08 updates
436 (remove-hook 'kbd-macro-termination-hook 'iedit-done)
437 (setq iedit-mode nil)
438 (force-mode-line-update)
439 (run-hooks 'iedit-mode-end-hook))
440
441 (defun iedit-make-occurrence-overlay (begin end)
442 "Create an overlay for an occurrence in iedit mode.
443 Add the properties for the overlay: a face used to display a
444 occurrence's default value, and modification hooks to update
445 occurrences if the user starts typing."
446 (let ((occurrence (make-overlay begin end (current-buffer) nil t)))
447 (overlay-put occurrence iedit-occurrence-overlay-name t)
448 (overlay-put occurrence 'face iedit-occurrence-face)
da47784c »
2012-01-29 Add iedit mode easy access keys
449 (overlay-put occurrence 'local-map iedit-occurrence-local-map)
e9a94852 »
2010-03-08 updates
450 (overlay-put occurrence 'insert-in-front-hooks '(iedit-occurrence-update))
451 (overlay-put occurrence 'insert-behind-hooks '(iedit-occurrence-update))
452 (overlay-put occurrence 'modification-hooks '(iedit-occurrence-update))
453 occurrence))
454
455 (defun iedit-make-unmatched-lines-overlay (begin end)
456 "Create an overlay for lines between two occurrences in iedit mode."
457 (let ((unmatched-lines-overlay (make-overlay begin end (current-buffer) nil t)))
458 (overlay-put unmatched-lines-overlay iedit-invisible-overlay-name t)
459 (overlay-put unmatched-lines-overlay 'invisible t)
460 (overlay-put unmatched-lines-overlay 'intangible t)
461 unmatched-lines-overlay))
462
6e492250 »
2012-01-30 Add iedit-toggle-case-sensitive
463 (defun iedit-reset-aborting ()
464 "Turning iedit-mode off and reset iedit-aborting. `iedit-done'
465 is postponed after the command is executed for avoiding
466 iedit-occurrence-update is called for a removed overlay."
467 (iedit-done)
468 (remove-hook 'post-command-hook 'iedit-reset-aborting t)
469 (setq iedit-aborting nil))
470
e9a94852 »
2010-03-08 updates
471 (defun iedit-occurrence-update (occurrence after beg end &optional change)
472 "Update all occurrences.
9a891d7a »
2010-03-13 updates
473 This modification hook is triggered when a user edits any
c8dac6be »
2012-01-21 exit iedit mode when change is not inside of occurrence.
474 occurrence and is responsible for updating all other occurrences.
475 Current supported edits are insertion, yank, deletion and replacement.
476 If this modification is going out of the occurrence, it will
7d18e5d7 »
2012-01-29 Add a help command C-? for occurrences
477 exit iedit mode."
039c0e23 »
2012-01-24 Postpone iedit-done after commands are excuted.
478 (when (and (not iedit-aborting )
0edc86ff »
2012-01-25 Fix the last occurrence problem when it is a complete symbol.
479 (not undo-in-progress)) ; undo will do all the update
c8dac6be »
2012-01-21 exit iedit mode when change is not inside of occurrence.
480 ;; before modification
13ecba13 »
2012-01-25 Merge branch 'upstream-master'
481 (if (null after)
c8dac6be »
2012-01-21 exit iedit mode when change is not inside of occurrence.
482 (if (or (< beg (overlay-start occurrence))
483 (> end (overlay-end occurrence)))
0edc86ff »
2012-01-25 Fix the last occurrence problem when it is a complete symbol.
484 (progn (setq iedit-aborting t) ; abort iedit-mode
485 (add-hook 'post-command-hook 'iedit-reset-aborting nil t))
17ce9738 »
2012-01-27 Clean up code
486 (setq iedit-before-modification-string
487 (buffer-substring-no-properties beg end)))
20c10759 »
2012-01-26 remove conditions on setting `iedit-before-modification-string'.
488 ;; after modification
c53a885f »
2012-01-30 Add bufferring modification functionalities
489 (when (not iedit-buffering)
9bc57d2a »
2012-01-30 make iedit-skipped-modification-once buffer local
490 ;; Check if we are inserting into zero-width occurrence. If so, then
491 ;; TWO modification hooks will be called -- "insert-in-front-hooks" and
492 ;; "insert-behind-hooks". We need to run just once.
c53a885f »
2012-01-30 Add bufferring modification functionalities
493 (if (and (= beg (overlay-start occurrence))
494 (= end (overlay-end occurrence))
495 (= change 0)
496 (not iedit-skipped-modification-once))
497 (setq iedit-skipped-modification-once t)
498 (setq iedit-skipped-modification-once nil)
499 (when (or (eq 0 change) ;; insertion
500 (eq beg end) ;; deletion
501 (not (string= iedit-before-modification-string
502 (buffer-substring-no-properties beg end))))
503 (let ((inhibit-modification-hooks t) ; todo: extract this as a function
504 (offset (- beg (overlay-start occurrence)))
505 (value (buffer-substring-no-properties beg end)))
506 (save-excursion
507 ;; insertion or yank
508 (if (eq 0 change)
509 (dolist (another-occurrence (remove occurrence iedit-occurrences-overlays))
510 (progn
511 (goto-char (+ (overlay-start another-occurrence) offset))
512 (insert-and-inherit value)))
513 ;; deletion
b81b9d60 »
2012-01-27 Clean code.
514 (dolist (another-occurrence (remove occurrence iedit-occurrences-overlays))
c53a885f »
2012-01-30 Add bufferring modification functionalities
515 (let* ((beginning (+ (overlay-start another-occurrence) offset))
516 (ending (+ beginning change)))
517 (delete-region beginning ending)
518 (unless (eq beg end) ;; replacement
519 (goto-char beginning)
520 (insert-and-inherit value)))))))))))))
17ce9738 »
2012-01-27 Clean up code
521 ;; (elp-instrument-list '(insert-and-inherit delete-region goto-char iedit-occurrence-update buffer-substring-no-properties string= re-search-forward replace-match))
c8dac6be »
2012-01-21 exit iedit mode when change is not inside of occurrence.
522
7d18e5d7 »
2012-01-29 Add a help command C-? for occurrences
523 ;; slowest version:
c8dac6be »
2012-01-21 exit iedit mode when change is not inside of occurrence.
524 ;; (defun iedit-occurrence-update (occurrence after beg end &optional change)
525 ;; "Update all occurrences.
526 ;; This modification hook is triggered when a user edits any
527 ;; occurrence and is responsible for updating all other
528 ;; occurrences."
529 ;; (when (and after (not undo-in-progress)) ; undo will do all the work
530 ;; (let ((value (buffer-substring-no-properties
531 ;; (overlay-start occurrence) (overlay-end occurrence)))
532 ;; (inhibit-modification-hooks t))
533 ;; (save-excursion
b81b9d60 »
2012-01-27 Clean code.
534 ;; (dolist (another-occurrence iedit-occurrences-overlays)
535 ;; (if (not (eq another-occurrence occurrence))
c8dac6be »
2012-01-21 exit iedit mode when change is not inside of occurrence.
536 ;; (progn
b81b9d60 »
2012-01-27 Clean code.
537 ;; (goto-char (overlay-start another-occurrence))
538 ;; (delete-region (overlay-start another-occurrence)
539 ;; (overlay-end another-occurrence))
c8dac6be »
2012-01-21 exit iedit mode when change is not inside of occurrence.
540 ;; (insert value))))))))
541
542 ;; ;; todo \\_<
543 ;; (defun iedit-occurrence-update (occurrence after beg end &optional change)
544 ;; "Update all occurrences.
545 ;; This modification hook is triggered when a user edits any
546 ;; occurrence and is responsible for updating all other
547 ;; occurrences."
548 ;; (when (not undo-in-progress) ; undo will do all the work
13ecba13 »
2012-01-25 Merge branch 'upstream-master'
549 ;; (if (null after)
c8dac6be »
2012-01-21 exit iedit mode when change is not inside of occurrence.
550 ;; (if (or (< beg (overlay-start occurrence))
551 ;; (> end (overlay-end occurrence)))
552 ;; (iedit-done)
553 ;; (setq iedit-before-modification-string
554 ;; (buffer-substring-no-properties
555 ;; (overlay-start occurrence) (overlay-end occurrence))))
556 ;; (let ((value (buffer-substring-no-properties
557 ;; (overlay-start occurrence) (overlay-end occurrence)))
558 ;; (inhibit-modification-hooks t))
559 ;; (save-excursion
560 ;; (goto-char (overlay-end occurrence))
561 ;; (while (re-search-forward iedit-before-modification-string nil t)
562 ;; (replace-match value nil nil))
563 ;; (goto-char (point-min))
564 ;; (while (re-search-forward iedit-before-modification-string (overlay-start occurrence) t)
565 ;; (replace-match value nil nil)))))))
e9a94852 »
2010-03-08 updates
566
567 (defun iedit-next-occurrence ()
9a891d7a »
2010-03-13 updates
568 "Move forward to the next occurrence in the `iedit'.
ec6785b0 »
2012-01-14 host on git
569 If the point is already in the last occurrences, you are asked to type
9a891d7a »
2010-03-13 updates
570 another `iedit-next-occurrence', it starts again from the
571 beginning of the buffer."
e9a94852 »
2010-03-08 updates
572 (interactive)
9a891d7a »
2010-03-13 updates
573 (let ((pos (point))
574 (in-occurrence (get-char-property (point) 'iedit-occurrence-overlay-name)))
575 (when in-occurrence
576 (setq pos (next-single-char-property-change pos 'iedit-occurrence-overlay-name)))
577 (setq pos (next-single-char-property-change pos 'iedit-occurrence-overlay-name))
da0a2470 »
2011-10-27 Add option to match only complete words, not inside words
578
9a891d7a »
2010-03-13 updates
579 (if (/= pos (point-max))
580 (setq iedit-forward-success t)
581 (if (and iedit-forward-success in-occurrence)
582 (progn (message "This is the last occurrence.")
583 (setq iedit-forward-success nil))
da0a2470 »
2011-10-27 Add option to match only complete words, not inside words
584 (progn
9a891d7a »
2010-03-13 updates
585 (if (get-char-property (point-min) 'iedit-occurrence-overlay-name)
586 (setq pos (point-min))
587 (setq pos (next-single-char-property-change (point-min) 'iedit-occurrence-overlay-name)))
588 (setq iedit-forward-success t)
589 (message "Located the first occurrence."))))
590 (when iedit-forward-success
591 (goto-char pos))))
e9a94852 »
2010-03-08 updates
592
593 (defun iedit-prev-occurrence ()
9a891d7a »
2010-03-13 updates
594 "Move backward to the previous occurrence in the `iedit'.
ec6785b0 »
2012-01-14 host on git
595 If the point is already in the first occurrences, you are asked to type
9a891d7a »
2010-03-13 updates
596 another `iedit-prev-occurrence', it starts again from the end of
597 the buffer."
e9a94852 »
2010-03-08 updates
598 (interactive)
9a891d7a »
2010-03-13 updates
599 (let ((pos (point))
600 (in-occurrence (get-char-property (point) 'iedit-occurrence-overlay-name)))
601 (when in-occurrence
602 (setq pos (previous-single-char-property-change pos 'iedit-occurrence-overlay-name)))
603 (setq pos (previous-single-char-property-change pos 'iedit-occurrence-overlay-name))
5ad28b5e »
2011-02-25 updates
604 ;; At the start of the first occurrence
9a891d7a »
2010-03-13 updates
605 (if (or (and (eq pos (point-min))
606 (not (get-char-property (point-min) 'iedit-occurrence-overlay-name)))
da0a2470 »
2011-10-27 Add option to match only complete words, not inside words
607 (and (eq (point) (point-min))
9a891d7a »
2010-03-13 updates
608 in-occurrence))
609 (if (and iedit-forward-success in-occurrence)
610 (progn (message "This is the first occurrence.")
611 (setq iedit-forward-success nil))
da0a2470 »
2011-10-27 Add option to match only complete words, not inside words
612 (progn
9a891d7a »
2010-03-13 updates
613 (setq pos (previous-single-char-property-change (point-max) 'iedit-occurrence-overlay-name))
614 (if (not (get-char-property (- (point-max) 1) 'iedit-occurrence-overlay-name))
615 (setq pos (previous-single-char-property-change pos 'iedit-occurrence-overlay-name)))
616 (setq iedit-forward-success t)
617 (message "Located the last occurrence.")))
618 (setq iedit-forward-success t))
619 (when iedit-forward-success
620 (goto-char pos))))
e9a94852 »
2010-03-08 updates
621
622 (defun iedit-toggle-unmatched-lines-visible ()
623 "Toggle whether to display unmatched lines."
624 (interactive)
625 (setq iedit-unmatched-lines-invisible (not iedit-unmatched-lines-invisible))
626 (if iedit-unmatched-lines-invisible
627 (iedit-hide-unmatched-lines)
628 (remove-overlays (point-min) (point-max) iedit-invisible-overlay-name t)))
629
6e492250 »
2012-01-30 Add iedit-toggle-case-sensitive
630 (defun iedit-hide-unmatched-lines ()
631 "Hide unmatched lines using invisible overlay."
632 (let ((prev-occurrence-end 0)
633 (unmatched-lines nil))
634 (save-excursion
635 (dolist (overlay iedit-occurrences-overlays)
636 (goto-char (overlay-start overlay))
637 (let ((line-beginning (line-beginning-position)))
638 (if (> line-beginning (1+ prev-occurrence-end))
639 (push (list (1+ prev-occurrence-end) (1- line-beginning)) unmatched-lines)))
640 (goto-char (overlay-end overlay))
641 (setq prev-occurrence-end (line-end-position)))
642 (if (< prev-occurrence-end (point-max))
643 (push (list (1+ prev-occurrence-end) (point-max)) unmatched-lines))
644 (when unmatched-lines
645 (dolist (unmatch unmatched-lines)
646 (iedit-make-unmatched-lines-overlay (car unmatch) (cadr unmatch)))))))
647
648 ;;;; functions for overlay local-map
e99e65fc »
2012-02-02 Fix current point move problem when call iedit-replace-occurrences.
649 (defun iedit-apply-on-occurrences (function &rest args)
da47784c »
2012-01-29 Add iedit mode easy access keys
650 "Call function for each occurrence."
651 (let* ((ov (car iedit-occurrences-overlays))
652 (beg (overlay-start ov))
653 (end (overlay-end ov)))
654 (when (/= beg end)
655 (let ((inhibit-modification-hooks t))
0d4027fe »
2012-02-02 Move save-excursion out of dolist
656 (save-excursion
657 (dolist (occurrence iedit-occurrences-overlays)
658 (apply function (overlay-start occurrence) (overlay-end occurrence) args)))))))
da47784c »
2012-01-29 Add iedit mode easy access keys
659
660 (defun iedit-upcase-occurrences ()
661 "Covert occurrences to upper case."
e08ad592 »
2012-02-01 Make Iedit mode available for read only buffer
662 (interactive "*")
e99e65fc »
2012-02-02 Fix current point move problem when call iedit-replace-occurrences.
663 (iedit-apply-on-occurrences 'upcase-region))
da47784c »
2012-01-29 Add iedit mode easy access keys
664
665 (defun iedit-downcase-occurrences()
666 "Covert occurrences to lower case."
e08ad592 »
2012-02-01 Make Iedit mode available for read only buffer
667 (interactive "*")
e99e65fc »
2012-02-02 Fix current point move problem when call iedit-replace-occurrences.
668 (iedit-apply-on-occurrences 'downcase-region))
da47784c »
2012-01-29 Add iedit mode easy access keys
669
670 (defun iedit-replace-occurrences(string)
671 "Replace occurrences with STRING."
e99e65fc »
2012-02-02 Fix current point move problem when call iedit-replace-occurrences.
672 (interactive "*sString: ")
673 (let* ((ov (iedit-find-current-occurrence-overlay))
674 (offset (- (point) (overlay-start ov))))
675 (iedit-apply-on-occurrences
676 (lambda (beg end string)
677 (delete-region beg end)
678 (goto-char beg)
0d4027fe »
2012-02-02 Move save-excursion out of dolist
679 (insert-and-inherit string))
e99e65fc »
2012-02-02 Fix current point move problem when call iedit-replace-occurrences.
680 string)
681 (goto-char (+ (overlay-start ov) offset))))
da47784c »
2012-01-29 Add iedit mode easy access keys
682
683 (defun iedit-clear-occurrences()
684 "Replace occurrences with blank spaces."
e08ad592 »
2012-02-01 Make Iedit mode available for read only buffer
685 (interactive "*")
78f606d4 »
2012-02-02 Add iedit-number-occurrences function
686 (let* ((ov (car iedit-occurrences-overlays))
687 (count (- (overlay-end ov) (overlay-start ov))))
688 (iedit-replace-occurrences (make-string count 32))))
da47784c »
2012-01-29 Add iedit mode easy access keys
689
690 (defun iedit-delete-occurrences()
691 "Delete occurrences."
e08ad592 »
2012-02-01 Make Iedit mode available for read only buffer
692 (interactive "*")
e99e65fc »
2012-02-02 Fix current point move problem when call iedit-replace-occurrences.
693 (iedit-apply-on-occurrences 'delete-region))
da47784c »
2012-01-29 Add iedit mode easy access keys
694
c53a885f »
2012-01-30 Add bufferring modification functionalities
695 (defun iedit-toggle-buffering ()
696 "Toggle buffering."
e08ad592 »
2012-02-01 Make Iedit mode available for read only buffer
697 (interactive "*")
c53a885f »
2012-01-30 Add bufferring modification functionalities
698 (if iedit-buffering
699 (iedit-stop-buffering)
700 (iedit-start-buffering)))
701
78f606d4 »
2012-02-02 Add iedit-number-occurrences function
702 (defun iedit-toggle-case-sensitive ()
703 "Toggle case-sensitive matching occurrences."
704 (interactive)
705 (iedit-done)
706 (setq iedit-case-sensitive (not iedit-case-sensitive))
707 (iedit-start iedit-last-occurrence-in-history))
708
c53a885f »
2012-01-30 Add bufferring modification functionalities
709 (defun iedit-start-buffering ()
710 "Start buffering."
711 (setq iedit-buffering t)
712 (let* ((ov (iedit-find-current-occurrence-overlay))
713 (beg (overlay-start ov))
714 (end (overlay-end ov)))
715 (setq iedit-before-modification-string
716 (buffer-substring-no-properties beg end))
717 (setq iedit-before-modification-undo-list buffer-undo-list)
718 (setq iedit-mode (propertize " Iedit-B" 'face 'font-lock-warning-face))
719 (force-mode-line-update)
720 (message "Iedit-mode buffering.")))
721
722 (defun iedit-stop-buffering ()
723 "Stop buffering and apply the modification to other occurrences."
724 (let* ((inhibit-modification-hooks t)
725 (ov (iedit-find-current-occurrence-overlay))
726 (beg (overlay-start ov))
727 (end (overlay-end ov))
728 (modified-string (buffer-substring-no-properties beg end))
e08ad592 »
2012-02-01 Make Iedit mode available for read only buffer
729 (offset (- (point) beg))) ;; delete-region moves cursor
c53a885f »
2012-01-30 Add bufferring modification functionalities
730 (when (not (string= iedit-before-modification-string modified-string))
731 (save-excursion
9bc57d2a »
2012-01-30 make iedit-skipped-modification-once buffer local
732 ;; Rollback the current modification and buffer-undo-list. This is to
733 ;; avoid the inconsistency if user undoes modifications
734 (delete-region beg end)
735 (goto-char beg)
736 (insert-and-inherit iedit-before-modification-string)
737 (setq buffer-undo-list iedit-before-modification-undo-list)
738 (dolist (occurrence iedit-occurrences-overlays) ; todo:extract as a function
739 (let ((beginning (overlay-start occurrence))
740 (ending (overlay-end occurrence)))
741 (delete-region beginning ending)
742 (unless (eq beg end) ;; replacement
743 (goto-char beginning)
744 (insert-and-inherit modified-string)))))
c53a885f »
2012-01-30 Add bufferring modification functionalities
745 (goto-char (+ (overlay-start ov) offset))))
746 (setq iedit-buffering nil)
747 (setq iedit-mode (propertize " Iedit" 'face 'font-lock-warning-face))
748 (force-mode-line-update)
749 (setq iedit-before-modification-undo-list nil)
9bc57d2a »
2012-01-30 make iedit-skipped-modification-once buffer local
750 (message "Iedit-mode buffering stopped."))
c53a885f »
2012-01-30 Add bufferring modification functionalities
751
78f606d4 »
2012-02-02 Add iedit-number-occurrences function
752 (defvar iedit-number-line-counter
753 "Occurrence number for 'iedit-number-occurrences")
754
0d4027fe »
2012-02-02 Move save-excursion out of dolist
755 (defun iedit-default-line-number-format (start-at)
78f606d4 »
2012-02-02 Add iedit-number-occurrences function
756 (concat "%"
757 (int-to-string
758 (length (int-to-string
759 (1- (+ (length iedit-occurrences-overlays) start-at)))))
760 "d "))
761
762 (defun iedit-number-occurrences (start-at &optional format)
763 "Insert numbers in front of the occurrences.
764
765 START-AT, if non-nil, should be a number from which to begin
766 counting. FORMAT, if non-nil, should be a format string to pass
767 to `format' along with the line count. When called interactively
768 with a prefix argument, prompt for START-AT and FORMAT."
769 (interactive
770 (if current-prefix-arg
771 (let* ((start-at (read-number "Number to count from: " 1)))
772 (list start-at
773 (read-string "Format string: "
0d4027fe »
2012-02-02 Move save-excursion out of dolist
774 (iedit-default-line-number-format
78f606d4 »
2012-02-02 Add iedit-number-occurrences function
775 start-at))))
776 (list 1 nil)))
777 (unless format
0d4027fe »
2012-02-02 Move save-excursion out of dolist
778 (setq format (iedit-default-line-number-format start-at)))
78f606d4 »
2012-02-02 Add iedit-number-occurrences function
779 (let ((iedit-number-line-counter start-at))
780 (iedit-apply-on-occurrences
781 (lambda (beg _end format-string)
782 (goto-char beg)
783 (insert (format format-string iedit-number-line-counter))
784 (setq iedit-number-line-counter
785 (1+ iedit-number-line-counter))) format)))
786
c53a885f »
2012-01-30 Add bufferring modification functionalities
787 (defun iedit-find-current-occurrence-overlay ()
788 "Always return the current occurrence overlay at point or point - 1,
789 since this function is supposed to be called in overlay local-map."
790 (or (iedit-find-overlay (point) 'iedit-occurrence-overlay-name)
791 (iedit-find-overlay (1- (point)) 'iedit-occurrence-overlay-name)))
792
793 (defun iedit-find-overlay (point property)
794 "Return the overlay with PROPERTY at POINT."
795 (let ((overlays (overlays-at point))
796 found)
797 (while (and overlays (not found))
798 (let ((overlay (car overlays)))
799 (if (overlay-get overlay property)
800 (setq found overlay)
801 (setq overlays (cdr overlays)))))
802 found))
803
e9a94852 »
2010-03-08 updates
804 (provide 'iedit)
805
806 ;;; iedit.el ends here
Something went wrong with that request. Please try again.