Skip to content

Commit

Permalink
retouch readme again
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Jun 26, 2023
1 parent a059649 commit 6cfe092
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,33 @@
`spacemod` is a text search-and-replace tool optimized towards refactoring
code.

<p><img src="./static/screenshot.png" /></p>
```python
# 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)
)
```

```sh
# 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
```

```python
# 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](https://github.com/facebookincubator/fastmod),
but with some additional features:
Expand All @@ -17,9 +43,6 @@ but with some additional features:
* **Parenthesis-matching (experimental).** Besides regex, spacemod also
supports a custom regex-like language that requires less escaping and
whitespace-handling.
* **Parallelism.** `spacemod` is not quite as CPU-efficient as fastmod, but
compensates by using background threads to search files while you approve
diffs.

<div class="oranda-hide">

Expand Down
25 changes: 25 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,31 @@ fn test_html5gum() {
"###);
}

#[test]
fn test_copy_file() {
let file = r#"
copy_file(to=from, from=to)
copy_file(
to=get_file(filepath, mode),
from=get_file_writer(other_filepath, other_mode)
)
"#;

let search = r#"copy_file ( to= (.*) , from= (.*) )"#;
let replace = r#"copy_file($2, $1)"#;

replacer_test!(file, search, replace, @r###"
// spacemod: steps_taken=3
copy_file(to, from)
copy_file(get_file_writer(other_filepath, other_mode)
, get_file(filepath, mode))
"###);
}

#[test]
fn test_commas() {
insta::assert_debug_snapshot!(Expr::parse_expr(r#""request_data": json.dumps ( { "options": self.options } ) ,"#, Default::default()), @r###"
Expand Down
Binary file removed static/screenshot.png
Binary file not shown.

0 comments on commit 6cfe092

Please sign in to comment.