Max Nikulin writes: > I still prefer to avoid replacement of latex newlines back to empty > string. Though I am really happy with the following code, I expected a > more concise snippet. Unit tests may found bugs in it. > > (let ((contents "\n\n 0 \n\n\na b\nc d e \n\n\nf g \n h i\n\n")) > ;; Strip leading newlines. > (setq contents > (replace-regexp-in-string > (rx string-start (1+ (0+ blank) ?\n)) "" > contents 'fixed-case 'literal)) > ;; Add explicit line breaks and strip trailing spaces. > (setq contents > (replace-regexp-in-string > (rx (0+ blank) ?\n > (optional (group (1+ (0+ blank) ?\n))) > (optional (group (0+ blank) (not (any blank ?\n))))) > (lambda (m) > (let ((par (match-string 1 m)) > (next (match-string 2 m))) > (if next > (concat (if par "\n\n" "\\\\\n") > next) > ""))) > contents 'fixed-case 'literal)) > ;; Indented lines. > (replace-regexp-in-string > (rx line-start (1+ blank)) > (lambda (m) (format "\\hspace*{%dem}" (length m))) > contents 'fixed-case 'literal)) > > Feel free to use it for inspiration during your work on a patch.
OK, thanks a lot. (BTW, I have yet to reply to some interesting things you mention in this thread about the verse environment).