Commit a3e22dc6 authored by Marko Bencun's avatar Marko Bencun

docs

parent c44a5a0e
......@@ -28,15 +28,7 @@ Add the following code to your init file. Of course you can select your own key
```
To customize, use `M-x customize-group [RET] visual-regexp`.
## Examples
### Example 1
![Example 1](https://github.com/benma/visual-regexp.el/raw/master/screenshots/montage1.png)
### Example 2
Zero-width matches are indicated by a pipe. When replacing using a Python expression, the counter variable `i` is available.
![Example 2](https://github.com/benma/visual-regexp.el/raw/master/screenshots/montage2.png)
### Example 3
![Example 3](https://github.com/benma/visual-regexp.el/raw/master/screenshots/montage3.png)
### <a name="example4"/>Example 4
visual-regexp can be combined with `wdired-change-to-wdired-mode` to rename files directly in a dired buffer, using regular expressions with a live preview:
![Example 3](https://github.com/benma/visual-regexp.el/raw/master/screenshots/visual-regexp5B.png)
\ No newline at end of file
An interesting application of this is regexp-renaming a bunch of files directly in a dired buffer with live feedback (using `wdired-change-to-wdired-mode`):
![entering regexp](https://github.com/benma/visual-regexp.el/raw/master/screenshots/visual-regexp5A.png)
![entering replacement](https://github.com/benma/visual-regexp.el/raw/master/screenshots/visual-regexp5B.png)
\ No newline at end of file
#!/bin/sh
for i in {1..4}; do
for i in {1..1}; do
montage "visual-regexp${i}*.png" -mode Concatenate -tile 2x2 -frame 2 -geometry +0+0 -background transparent "montage$i.png";
convert "montage$i.png" -resize 918x "montage$i.png";
done
screenshots/visual-regexp0A.png

13.1 KB | W: | H:

screenshots/visual-regexp0A.png

16.4 KB | W: | H:

screenshots/visual-regexp0A.png
screenshots/visual-regexp0A.png
screenshots/visual-regexp0A.png
screenshots/visual-regexp0A.png
  • 2-up
  • Swipe
  • Onion skin
screenshots/visual-regexp0B.png

14.7 KB | W: | H:

screenshots/visual-regexp0B.png

18.4 KB | W: | H:

screenshots/visual-regexp0B.png
screenshots/visual-regexp0B.png
screenshots/visual-regexp0B.png
screenshots/visual-regexp0B.png
  • 2-up
  • Swipe
  • Onion skin
screenshots/visual-regexp1A.png

8.66 KB | W: | H:

screenshots/visual-regexp1A.png

104 KB | W: | H:

screenshots/visual-regexp1A.png
screenshots/visual-regexp1A.png
screenshots/visual-regexp1A.png
screenshots/visual-regexp1A.png
  • 2-up
  • Swipe
  • Onion skin
screenshots/visual-regexp1B.png

9.6 KB | W: | H:

screenshots/visual-regexp1B.png

103 KB | W: | H:

screenshots/visual-regexp1B.png
screenshots/visual-regexp1B.png
screenshots/visual-regexp1B.png
screenshots/visual-regexp1B.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -379,21 +379,22 @@ If nil, don't limit the number of matches shown in visual feedback."
(let ((i 0)
(looping t))
(while (and looping
(or (not feedback-limit) (< i feedback-limit))
(condition-case err
(if forward
(re-search-forward regexp-string vr--target-buffer-end t)
(re-search-backward regexp-string vr--target-buffer-start t))
('invalid-regexp (progn (setq message-line (car (cdr err))) nil))))
(loop for (start end) on (match-data) by 'cddr
for j from 0 do
(funcall callback i j start end))
(when (or (not feedback-limit) (< i feedback-limit)) ;; let outer loop finish so we can get the matches count
(loop for (start end) on (match-data) by 'cddr
for j from 0 do
(funcall callback i j start end)))
(when (= (match-beginning 0) (match-end 0))
(cond ;; don't get stuck on zero-width matches
((and forward (> vr--target-buffer-end (point))) (forward-char))
((and (not forward) (< vr--target-buffer-start (point))) (backward-char))
(t (setq looping nil))))
(setq i (1+ i))))))
(setq i (1+ i)))
(setq message-line (format "%s matches" i)))))
message-line))
(defun vr--feedback-match-callback (i j begin end)
......@@ -422,7 +423,7 @@ If nil, don't limit the number of matches shown in visual feedback."
(let ((regexp-string (vr--get-regexp-string)))
(vr--feedback-function t vr--feedback-limit 'vr--feedback-match-callback)))
(unless inhibit-message
(let ((msg (vr--compose-messages message-line (when limit-reached (format "%s matches shown, hit C-c a to show all" vr/default-feedback-limit)))))
(let ((msg (vr--compose-messages message-line (when limit-reached (format "%s matches shown, hit C-c a to show all" vr--feedback-limit)))))
(unless (string= "" msg)
(vr--minibuffer-message msg))))))
......@@ -453,18 +454,20 @@ If nil, don't limit the number of matches shown in visual feedback."
(insert buffer-contents)
(goto-char vr--target-buffer-start)
(let ((i 0)
(looping t))
(looping t)
(limit-reached nil))
(while (and
looping
(or (not feedback) (not feedback-limit) (< i feedback-limit))
(condition-case err
(re-search-forward regexp-string vr--target-buffer-end t)
('invalid-regexp (progn (setq message-line (car (cdr err))) nil))))
(condition-case err
(progn
(setq replacements (cons
(list (match-substitute-replacement replace-string) (match-beginning 0) (match-end 0) i)
replacements))
(if (or (not feedback) (not feedback-limit) (< i feedback-limit))
(setq replacements (cons
(list (match-substitute-replacement replace-string) (match-beginning 0) (match-end 0) i)
replacements))
(setq limit-reached t))
(when (= (match-beginning 0) (match-end 0))
(if (> vr--target-buffer-end (point))
(forward-char) ;; don't get stuck on zero-width matches
......@@ -473,7 +476,11 @@ If nil, don't limit the number of matches shown in visual feedback."
('error (progn
(setq message-line (car (cdr err)))
(setq replacements (list))
(setq looping nil)))))))
(setq looping nil)))))
(if feedback
(setq message-line (vr--compose-messages (format "%s matches" i) (when limit-reached (format "%s matches shown, hit C-c a to show all" feedback-limit))))
(setq message-line (format "replaced %d matches" i)))))
(list replacements message-line)))
(defun vr--do-replace-feedback ()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment