I have this loop:
(catch 'QUIT (while (search-forward-regexp "\\([^\n\\]\\(?:\\\\\\\\\\)*\\|^\\(?:\\\\\\\\\\)+\\)%.*\n" nil t) (save-excursion (let ((b (make-marker)) (e (make-marker)) MatchedStringOverlay ACTION) (set-marker b (match-beginning 0)) (set-marker e (point)) (setq MatchedStringOverlay (make-overlay b e)) (unwind-protect (progn (overlay-put MatchedStringOverlay 'face '(:background "OliveDrab1")) (setq ACTION (read-char "Options: - [y] erase string and the corresponding \"newline\" - [l] erase string keeping the corresponding \"newline\" - [n] skip - [q] quit: ")) (cond ((char-equal ACTION ?y) (replace-match "\\1")) ((char-equal ACTION ?l) (replace-match "\\1\n")) ((char-equal ACTION ?n) nil) ((char-equal ACTION ?q) (throw 'QUIT nil)) ) ) (remove-overlays b e)) ))) )
It work fine for my purposes but it would be better if I could get this behaviour: Let's say I chose the
[y] option, I'd like to perform the replacement but "pause" the loop until the
[y] key is released. The best would be if, while pressing
[y] I could
undo the action pressing another key (e.g.
I'm, obviously, not asking you to write the code for me, but I'd like to know if it is possible to get what I figured out and, if so, what to look at.
EDIT. I figured out a simpler way to get way to get what I need, buy using lowcase or Uppercase version of char but I'm also interested to learn about