Giter Site home page Giter Site logo

iedit's Introduction

Iedit - Edit multiple occurrences in the same way simultaneously

http://melpa.org/packages/iedit-badge.svg http://stable.melpa.org/packages/iedit-badge.svg

./iedit-demo.gif

Introduction

This package includes Emacs minor modes (iedit-mode and iedit-rectangle-mode) based on a API library (iedit-lib) and allows you to alter one occurrence of some text in a buffer (possibly narrowed) or region, and simultaneously have other occurrences changed in the same way, with visual feedback as you type.

`iedit-mode’ is a great alternative of build-in replace commands:

  • A more intuitive way to alter all the occurrences at once
  • Visual feedback
  • Less keystrokes in most cases
  • Preserve case optionally

Normal work flow of Iedit mode is like:

  • Move point to a target by `isearch’ or other moving commands
  • Press C-;(The default key binding) to enable Iedit mode. The thing under the point is recognized as an occurrence, and all the occurrences in the buffer are highlighted
  • Edit one of the occurrences The change is applied to other occurrences simultaneously.
  • Finish - by pressing C-; again

Many other work flows to highlight occurrences are possible, for example, activation from isearch, incremental selection and markup tag pair selection.

You can also use Iedit mode as a quick way to temporarily show only the buffer lines that match the current text being edited. This gives you the effect of a temporary `keep-lines’ or `occur’. To get this effect, hit C-’ when in Iedit mode - it toggles hiding non-matching lines.

`iedit-mode’ is optimized for renaming refactoring in many ways:

  • The symbol under point is selected as occurrence by default and only complete symbols are matched
  • With digit prefix argument 0, only occurrences in current function are matched
  • Last renaming refactoring is remembered and can be applied to other buffers later
  • Once in iedit mode, you can select a region and hit C-; again to restrict the search area to the region
  • Restricting the search area to just the current line can be done by pressing M-I.
  • Restricting the search area to the lines near the current line can be done by pressing M-{ and M-}. These will expand the search region one line at a time from the top and bottom. Add a prefix argument to go the opposite direction.

Iedit-rectangle-mode provides rectangle support with visible rectangle highlighting, which is similar with cua mode rectangle support. But it’s lighter weight and uses iedit mechanisms.

There are also some other facilities you may never think about. Refer to the document of function `iedit-mode’ (C-h f iedit-mode RET) for more details.

Installation instruction

Installing from MELPA

The easiest way to install and keep Iedit up-to-date is using Emacs’s built-in package manager. Iedit is available in the MELPA repository. Refer to http://melpa.org/#/getting-started for how to install a package from MELPA.

Installing from GitHub

You can also clone Iedit’s repository or download a zip package from GitHub https://github.com/victorhge/iedit

You will need to add a few extra lines in your .emacs file, to make your Emacs knows about the package:

(add-to-list 'load-path "~/dir/to/your/iedit")
(require 'iedit)

iedit's People

Contributors

articuluxe avatar duianto avatar edwardbetts avatar ergus avatar gallipo avatar imwihfm avatar jasminpatry avatar jorgenschaefer avatar justbur avatar leungbk avatar lionel- avatar mbneedham avatar mgalgs avatar miciah avatar pierre-rouleau avatar skangas avatar thierryvolpiatto avatar tsdh avatar victorhge avatar vifon avatar yesudeep avatar zhenya-1007 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iedit's Issues

Wishlist: treat selection as a symbol

Hi everyone,
In some buffer "-" is treated as a seperator, and I can't edit symbol like "hello-world" as a whole, it would be nice if I select a region and do edit on all instance of that region in the buffer.
Thank you for your consideration!

show "%d/%d" in the mode line

When the iedit occur is working, the mode line shows the total number of the matching words.
Does there exists some settings to replace the info of mode line with "%d/%d", such as "1/20",
which 1 means the word is the first one, and 20 is the total matching words. Thanks.

Wrong behavior when deleting text from inside an occurrence to end of line

With Emacs 24.5 and latest version of iedit, I experience weird behavior when the cursor is inside an occurrence and I delete the text from the cursor to the end of the line.

To reproduce:

    1. emacs -Q -L /path/to/iedit/directory
    1. M-: (require 'iedit)
    1. change contents of scratch buffer to this:
foobar qux
foobar qux
    1. move cursor to "b" in the first line
    1. M-x iedit-mode -> "foobar" in both lines is highlighted
    1. C-k (kill-line)

Expected result: buffer will look like this, with "foo" highlighted in both lines:

foo qux
foo qux

Actual result: iedit-mode is deactivated (nothing is highlighted), buffer looks like this:

foo
foobar qux

Original Issue reported by @jdwaterson here: syl20bnr/spacemacs#3193

'C-;' is not working

hi, im using evil and the default key is not working. But when i do M-x iedit-mode i get a text below the status bar saying " you can activate iedit-mode by C-;"

iedit-restrict-current-line should reset iedit-num-lines-to-expand-up/down to 0

Hi,

First, thanks for iedit -- I've only recently started using it (as part of spacemacs) but I find it very useful.

Here's the issue I'm having. If I execute the following sequence of commands:
iedit-restrict-current-line
iedit-expand-up-a-line
iedit-expand-down-a-line
iedit-expand-down-a-line
the search range will be -1/+2.

If I then do
iedit-restrict-current-line
again, the search will be restricted to the current line. But if I then do
iedit-expand-up-a-line
the search range will be -2/+2; i.e., the range counters weren't reset.

I'm aware I can use a prefix argument to reduce the range, but this is awkward, and the current behavior is (to me at least) very unintuitive.

A simple fix for this would be to modify iedit-restrict-current-line so that it sets the range counters to 0. I can put together a PR with this change if it sounds acceptable.

Low priority overlay

When I try to use iedit in a buffer with flymake errors, flymake's overlay overrules iedit's match highlighting because it has a higher priority. I made the following change to fix it:

Index: iedit.el
===================================================================
--- iedit.el    (revision 1784)
+++ iedit.el    (working copy)
@@ -76,6 +76,11 @@
   :type 'face
   :group 'iedit)

+(defcustom iedit-overlay-priority 200
+  "The priority of the overlay used to indicated matches."
+  :type 'integer
+  :group 'iedit)
+
 (defcustom iedit-current-word-default 't
   "If no-nil, use current word by default for the occurrence."
   :type 'boolean
@@ -271,6 +276,7 @@
     (overlay-put occurrence 'insert-in-front-hooks '(iedit-occurrence-update))
     (overlay-put occurrence 'insert-behind-hooks '(iedit-occurrence-update))
     (overlay-put occurrence 'modification-hooks '(iedit-occurrence-update))
+    (overlay-put occurrence 'priority iedit-overlay-priority)
     occurrence))

 (defun iedit-make-unmatched-lines-overlay (begin end)

200 is a higher priority than highlight-current-line (60) and flymake (100) use, but lower than show-paren (1000) and auto-complete (9999) do.

(Excuse the svn diff format.)

Replace from specific line to the end down (> 10 matches)

Windows 10, Emacs 25.1, package iedit

Suppose I has text:

1.aaa_1111_hello
2.aaa_2222_hello
3.aaa_1111_hello
4.aaa_4444_hello
5.aaa_1111_hello
6.aaa_5555_hello
7.aaa_1111_hello
8.aaa_1111_hello
...
100.aaa_1111_hello

I want to replace all (100 lines) "_1111" by text "_zero"

Steps:

Select text "_1111"
1.M-x iedit-mode
2.M-D (to delete all find text _1111)
3.Input new text _zero

Here result.

1.aaa_zero_hello
2.aaa_2222_hello
3.aaa_zero_hello
4.aaa_4444_hello
5.aaa_zero_hello
6.aaa_5555_hello
7.aaa_zero_hello
8.aaa_zero_hello
...
100.aaa_zero_hello

OK.

But now I want to replace text ONLY from line "5.aaa_1111_hello" and to the end down.
So as result I need to replace 98 lines.

The result must like this:

1.aaa_1111_hello
2.aaa_2222_hello
3.aaa_1111_hello
4.aaa_4444_hello
5.aaa_zero_hello
6.aaa_5555_hello
7.aaa**_zero**_hello
8.aaa**_zero**_hello
...
100.aaa**_zero**_hello

Is it possible by iedit?

Change the highlighting color

I wonder is there any way to change the highlighted occurrences color? The current color accidentally coincides with my background color. So, it is hard for me to visualize all the occurrences.

iedit-expand-up/down-to-occurrence seem flipped

THe current binding is counter-intuitive to me. It seems that "\M-p", which everywhere else in emacs is bound to an action that goes backward, is here used to expand the region forward, and "\M-n" used elsewhere for actions that go ahead, is here used to expand the region backward. Could these be flipped? If you like I can make a pull request.

Nice feature, by the way.

buggy behaviour in some buffers

Hello,

Thanks for this package. Just discovered it and am so sad about an issue preventing its use in my php buffers.

After selecting the string to be replaced, only part of it gets replaced as shown in video here : https://videobin.org/+isn/mw7.html

Not sure about what details I could give you. Please let me know how I could help you debugging this more if you can have a look at that.
(my configuration is here if that might give some contextual info : https://github.com/kermorgant/.emacs.d)

Different highlighting behavior depending on major mode

First, thanks for the awesome tool.

I've got a problem where I want to modify the occurrences of some text with special characters inside a string. It works correctly in the scratch buffer, but in a .cpp file, it does not.

Consider the following text:

    printf("some @special text");
    string special = "more @special text");

In the scratch buffer, if I press C-; when the cursor is on the "c" in @special (in the first line) it correctly only highlights "@special" in both lines.

However, in a C++ buffer, the same action results in only "special" (without the @) being highlighted, and it highlights all three occurrences of the string. This occurs even if I have already defined a region that contains the @ sign prior to pressing C-;

Attached is an init.el file that reproduces the behavior.
init.el.zip

why does iedit-transient-mark-sensitive exist?

It's a bug to not be sensitive to transient-mark-mode. That's the fundamental premise of enabling this minor-mode. The user is indicating that the region he's interested in will always have the mark active and be highlighted.

Emacs already has built-ins that respect this -- region-active-p. Why not just use that?

iedit not installable as package

M-x list-packages does not have iedit—is there some other repository I need to add? Or is this something that simply hasn't been paid attention to yet?

iedit fails in c++ code if GTAGS files are present

Hi !

In a c++ code (not tested with other language), iedit-mode fails replacing code if GTAGS, GPATH, GRTAGS are present (in my case they are located at the root of my c++ project). Some words are partially replaced (while well highlighted), others correctly replaced. When I removed these gtags files, iedit works very well.

Note: you have to restart emacs to get the issue after creating/removing gtags files.

Some info if needed:

  • my configuration is https://github.com/Lecrapouille/DotEmacs
  • I binded iedit-mode with the F11 key
  • I binded gtags with the F1 key. This will create gtags files
  • For having gtags you have to do something like sudo apt-get install global

Add to MELPA stable?

Could you also add to MELPA stable, please? Because it only includes commits marked with release tags, I would expect it to become one of the more popular repositories over time.

Make it possible to toggle value of iedit-only-at-symbol-boundaries

I recently found myself needing to change all occurrences of "pdf-view" to "pdf-tools" in a buffer. A perfect job for IEdit, I thought. I was a little surprised that when "pdf-view" occurred as part of a variable name rather than the whole symbol, IEdit ignored it.

This is good default behavior, but sometimes I want the other one; it would be useful to have something analogous to iedit-toggle-case-sensitive.

Misbehaving command 'iedit-mode after custom mapping.

I mapped iedit-mode to "C-i" globally.
(define-key global-map (kbd "C-i") 'iedit-mode)

Now when I press that key "C-i", it gets me to iedit-mode alright. But when I press the combination again it doens't turn off iedit-mode. It basically functions as iedit-next-occurance ? Am I missing something?

iedit-switch-to-mc-mode errors with Invalid function: mc/save-excursion

I'm trying out the M-M (switch to multiple cursors) binding and it always fails for me with:

iedit-switch-to-mc-mode: Invalid function: mc/save-excursion

I'm not sure what's wrong, `mc/save-excursion' is defined:

mc/save-excursion is a Lisp macro in ‘multiple-cursors-core.el’.

Failure of finding matches

EXAMPLE: I have the following text in the buffer -
This is

When I put the cursor between i and s and then press <C-;>, there is an error called "0 matches for http://is".

Anybody knows what is the cause for this? (My emacs version is 23.1.1)

Thanks!

Leaves buffer with no current mark

For some reason if I set the mark, invoke iedit-mode, then end
iedit-mode, the buffer no longer has a mark set. This means that using
popping the mark or exchanging it with point, as I often do for quick
navigational purposes, does not work. Most Emacs commands will leave
the last mark in place or set a new one pushing back on the mark ring.

Iedit is so excellent I continue to use it regularly in spite of
this annoyance. Thanks for it!

provide API for other packages to use iedit

mark-multiple is something similar to iedit: git://github.com/magnars/mark-multiple.el.git

My rectangle feature was "inspired" from mark-multiple. Iedit is much better for my uses, though.

It would be nice to have API to use iedit in a non-systematic way. For example this function:

iedit-mark(start, length)

This way another package can use Iedit to mark arbitrary parts of the buffer as master/mirror edits.

lag when editing with iedit-mode on

When editing c++ file (less than 3000 lines) with iedit-mode on, and there are no more than 10 matches, it lags too much. Emacs uses more than 80% of cpu when typing chars.

Not 100% reproduciable. But it happens too often.

iedit-restrict-function doesn't update mode-line text correctly

Description

The Iedit: 1/3 mode-line text, doesn't update correctly after calling iedit-restrict-function.

Steps to reproduce

  • Start Emacs
  • Open a new buffer C-x b test
  • Copy and paste this example text:
;; pre function comment

(defun test ()
;; first comment
;; second comment
;; third comment
)

;; post function comment
  • place the cursor on the word "comment", on the line:
;; second comment
  • Enter Iedit state: C-;, the mode-line correctly shows: Iedit:3/5
  • Restrict the occurrences to the current function: S-M-h

Observed behaviour:

The modeline now shows Iedit:0/3
The total number of occurrences 3 has updated correctly, but the current occurrence shows 0.

Expected behaviour:

The 0 should say 2.

Note:

Pressing Tab to move the cursor to the next occurrence, updates to the correct mode-line text Iedit:3/3

System Info:

iedit-20180207.1019
Emacs 26.1
Windows 10 Version 1803

Default major mode

Would it be possible to configure the buffer default mode ?

Currently it uses fundamental mode be nice if it could be changed to use Text mode or some other basic mode for editing.

or perhaps an iedit mode based of fundamental mode then you could make changes to iedit mode with out effecting other fundamental buffers.

C-; binding overrides user binding

First of all, let me say thanks to everyone who contributes to iedit.

I ran into this problem after installing another package that depends on iedit. I have a keybind under C-;, and after an upgrade today I was perplexed to find it had been overriden by a mode which I've never used before.

The keybinding convention recommends "C-c followed by any other punctuation character" for minor modes. But mostly, it was just confusing to find such a low-level key overriden.

Could you check whether the key is not already taken before binding it?

Best,

Doesn't work with multi-occur

To reproduce:

  1. M-x multi-occur-in-matching-buffers, select some buffers, select some matching text that occurs in more than 1 buffer
  2. In the Occur buffer, press e for edit mode
  3. move to one of the matches, press C-; to activate iedit
  4. change the matches

result: only one of the buffers is actually updated, the rest are not.

I think it is because of this:
https://github.com/victorhge/iedit/blob/master/iedit.el#L828

the modification hooks are disabled, and multi-occur depends on them to update the files.

Feature: sublime style incremental select

It would be nice to have something like sublime's CTRL-d that incrementally selects next occurrences.

I know that is possible to expand the region below or on top, but as I've seen there's no way to select only the next occurrence and not just the next line (that could or could not have one or more than one occurrences)

[Feature Request] Add C-u C-; binding for refactor function.

;; - With digit prefix argument 0, only occurrences in current function are matched

Hi, i use iedit for a long time ... but i never remember this C-u 0 C-; binding ...
I am wonder why add a extra 0 to this binding?

when i use iedit, i only remember C-; and some times to try C-u C-;, but never
try C-u 0 C-; ...

so , i thought, this 0 is not necessary, maybe we could add a C-u C-; support?

Thanks.

fix test failures

I tried to run tests on 24.2.1 and got:

Selector: t
Passed: 16
Failed: 7 (7 unexpected)
Total: 23/23

The default keybinding doesn't work

I've try (global-set-key [(control ?\;)] 'iedit-mode) and (require 'iedit);
and neither of them make the keybinding C-; work correctly.
And i am using Emacs in X-windows.
The keybinding C-; only show something looks like pop-tip, and the "pop-tip" got all the content of clipboard on it - shows by a list that have a number before every item , i can press the number to choose one item and it will be paste to Emacs's buffer ...
I've try remove all the package , and C-; shows the "pop-tip" too , i don't know to make C-; work for iedit

skip read-only text

diff --git a/iedit-lib.el b/iedit-lib.el
index 636c0bb..a7d92b0 100644
--- a/iedit-lib.el
+++ b/iedit-lib.el
@@ -194,9 +194,10 @@ Return the number of occurrences."
     (save-excursion
       (goto-char beg)
       (while (re-search-forward occurrence-regexp end t)
-        (push (iedit-make-occurrence-overlay (match-beginning 0) (match-end 0))
-              iedit-occurrences-overlays)
-        (setq counter (1+ counter)))
+        (unless (text-property-not-all (match-beginning 0) (match-end 0) 'read-only nil)
+          (push (iedit-make-occurrence-overlay (match-beginning 0) (match-end 0))
+                iedit-occurrences-overlays)
+          (setq counter (1+ counter))))
       (message "%d matches for \"%s\"" counter (iedit-printable occurrence-regexp))
       (when (/= 0 counter)
         (setq iedit-occurrences-overlays (nreverse iedit-occurrences-overlays))

you can check out
(wdired-isearch-filter-read-only) in wdired.el or
query-replace-skip-read-only in replace.el

iedit-mode seems to be broken in Emacs 26.1

M-x iedit-mode does highlight matches, and I am able to navigate between them. But when I edit any of the matches, only the match I've edited is changed, the rest are not.

iedit-mode started to misbehave after I upgraded to Emacs 26.1.

Could somebody please confirm/refute this regression report?

tab doesn't work in gui Emacs

Hello,

in the gui version of Emacs, hitting the tab key after entering "iedit-mode" doesn't call "iedit-next-occurrence" but the global binding of tab. Works in terminal however. This helps:

(define-key iedit-lib-keymap [tab] 'iedit-next-occurrence)

Can we please fix this in the source? Thanks.

Push latest to melpa

You fixed an issue for me recently, but the latest melpa version is 20120306. Would be nice to have the fixes in the repository.

[feature request] add flag to exclude iedit changes from undo buffer

As far as I understand the docs and source, there's no such feature yet, I wrote the following work-around:

;; Keep buffer-undo-list as is while iedit is active, that is, as long
;; as I am  inside iedit I can undo/redo  current occurences. However,
;; if I leave iedit and issue  the undo command, ALL changes made with
;; iedit  are undone,  whereas the  default behaviour  would be  to go
;; through every change made iside iedit, which I hate.

;; iedit doesn't  provide a customizable  flag to configure  it's undo
;; behavior, so, I modify it myself using defadvice.

(setq my-buffer-undo-list nil)
(advice-add 'iedit-mode :before '(lambda (&rest args) ;; save current
                                   (setq my-buffer-undo-list buffer-undo-list)))

(advice-add 'iedit-mode :after '(lambda (&rest args)  ;; restore previously saved
                                  (setq buffer-undo-list my-buffer-undo-list)))

Maybe this is of use for others, therefore I'm posting it here.

Thanks for iedit anyway, I LOVE LOVE LOVE it 👍

M-H needs feedback

A message of something like "restricted to current function, xx matches".

Ideally, flashing the affected region would be good as well, i.e. pulse the highlight face.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.