Giter Club home page Giter Club logo

spacemod's Introduction

spacemod

spacemod is a text search-and-replace tool optimized towards refactoring code.

# example.py (before)
copy_file(to_file=to_file, from_file=from_file)

copy_file(
    to_file=get_file(filepath, mode),
    from_file=get_file_writer(other_filepath, other_mode)
)
# Use spacemod's custom pattern-matching language to deal with whitespace easier.
# Without -S, normal regex patterns are assumed.

$ spacemod -S \
  'copy_file ( to_file= (.*) , from_file= (.*) )' \
  'copy_file($2, $1)' \
  example.py

# spacemod will open interactive TUI and ask for approval of diffs. Use
# --accept-all to use spacemod non-interactively.
# example.py (after)
copy_file(from_file, to_file)

copy_file(get_file_writer(other_filepath, other_mode)
, get_file(filepath, mode))

It is very similar to fastmod, but with some additional features:

  • Undo stack. Approved a diff too soon? Hit [u]ndo to revert.
  • Yes to all diffs like this. Auto-approve future diffs with the exact same content.
  • Parenthesis-matching (experimental). Besides regex, spacemod also supports a custom regex-like language that requires less escaping and whitespace-handling.

Installation

Check the website for installation options.

Matching Modes

By default, you use regexes to replace text. See Matching modes for the alternative modes that spacemod supports.

Alternatives

There are many tools like spacemod, some of which may suit your needs better. Take a look at Alternatives.

License

Licensed under MIT, see ./LICENSE.

spacemod's People

Contributors

striezel avatar untitaker 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

Watchers

 avatar  avatar  avatar

Forkers

icodein

spacemod's Issues

-F (literal/verbatim) mode

Sometimes pattern-matching becomes too burdensome and I'd like to do what fastmod can do with -F

However, at the same time, this pattern-matching is supposed to be less burdensome than raw regexes.

from fastmod help:

    -F, --fixed-strings
            Treat REGEX as a literal string. Avoids the need to escape regex metacharacters (compare to ripgrep's option
            of the same name).

should we extend our pattern-matching language to allow for different/easier ways of escaping things instead? bailing out of regexes entirely is a bit heavy-handed and inflexible

spacemod "^(\d*)" -F "a.literal.string" "(.*)" "replacestring"

would be the same as ^(\d*)a\.literal\.string(.*)

Undo button

I sometimes hit enter too fast. It would be really cool to be able to have an undo stack. Probably requires keeping everything in RAM

Spacemod bug while refactoring html5gum

command line:

spacemod 'machine_helper.state = (.+) ; slf.reader.unread_char ( (.+) ) ; ControlToken::Continue' 'reconsume_in!($2, $1)' /tmp/lol.rs

code:

                c => {
                    machine_helper.state = State::ScriptData;
                    slf.reader.unread_char(c);
                    ControlToken::Continue
                }
                }
                Some("<") => {
                    machine_helper.state = State::ScriptDataEscapedLessThanSign;
                    ControlToken::Continue
                }
                Some("\0") => {
                    emitter.emit_error(Error::UnexpectedNullCharacter);
                    emitter.emit_string("\u{fffd}");
                    ControlToken::Continue
                }
                None => {
                    emitter.emit_error(Error::EofInScriptHtmlCommentLikeText);
                    ControlToken::Eof
                }
                Some(xs) => {
                    emitter.emit_string(xs);
                    ControlToken::Continue
                }
            }
        ),

Accept diff option

We have accept change to specific file (y) and accept all (A)

There should be something in-between. How about "accept this exact diff in other files too"?

Basic regex mode

We should have a flag to interpret the string as a regular regex. I also think it should probably be the default mode to make the transition from fastmod easier.

Either that or we make changes to the parens matching syntax to make it harder to accidentally write something that works in fastmod but not in spacemod.

Use multiple cores to search and match files

We can probably use rayon in the background to search files while the user is approving diffs. This would reduce waiting time between diffs. I think it'd be worth the extra complexity, and in order to fix some other bugs some refactoring is necessary anyway.

see also #2

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.