I have this function:
(defun fix-mult-punct-before-footnote ()
"Scope: FOOTNOTE
Description: Fixes repeated/multiple punctuation before the \\footnote macro."
(interactive)
;; "..\footnote{" --> "..\footnote{"
;; ".,\footnote{" --> "?\footnote{"
(query-replace-regexp
"\\([,.:;!?]\\)\\([,.:;!?]\\)\\(\\\\footnote{\\)"
;; REPLACEMENT
'((lambda (data count)
(let ((M1 (match-string-no-properties 1))
(M2 (match-string-no-properties 2)))
(cond ((string= M1 M2)
(format "%s%s" M1
(regexp-quote (match-string 3))))
((not (string= M1 M2))
(format "%s%s"
(char-to-string
(read-char-choice
(format "The repeated punctuation contains heterogeneous symbols.
Choose which symbol to keep between \"%s\" and \"%s\""
M1 M2)
(list (string-to-char M1)
(string-to-char M2))))
(regexp-quote (match-string 3))))))))
nil (point-min) (point-max)))
In the read-char-choice point I'd like to add the option to skip the replacement like the n char does normally. For how the function is built now I need to choice the chars in any case and only than I can skip the replacement.
Is it possible?
I'll try to explain better my question.
For how the function is built now when the function processed the string:
.,\footnote{
the second cond case ask me which char, "," or "." use in the replacement using read-char-choice. But if I DON'T want to proceed with the replacement I can't skip it in this point. I need to choose a char and NEXT skip the replacement. I'd like to simplify the process adding a skipping solution in the read-char-choice point.
I mean somthing like:
(defun fix-mult-punct-before-footnote ()
"Ambito: FOOTNOTE
Descrizione: Corregge la punteggiatura multipla/ripetuta prima della macro \\footnote"
(interactive)
;; "..\footnote{" --> "..\footnote{"
;; ".,\footnote{" --> "?\footnote{"
(query-replace-regexp
"\\([,.:;!?]\\)\\([,.:;!?]\\)\\(\\\\footnote{\\)"
;; REPLACEMENT
'((lambda (data count)
(let ((M1 (match-string-no-properties 1))
(M2 (match-string-no-properties 2)))
(cond ((string= M1 M2)
(format "%s%s" M1
(regexp-quote (match-string 3))))
((not (string= M1 M2))
(format "%s%s"
(char-to-string
(let ((user-choice (read-char-choice
(format "The repeated punctuation contains heterogeneous symbols.
Choose which symbol to keep between \"%s\" and \"%s\" OR type \"n\" to skip this replacement: "
M1 M2)
(list (string-to-char M1)
(string-to-char M2)
?n))))
(if (equal user-choice ?n)
SOMETHING_HERE
user-choice)))
(regexp-quote (match-string 3))))))))
nil (point-min) (point-max)))
nshould do what you want. Maybe rephrase that text to make what you want more clear?