It seems subr-x's string-trim-right
only operates on the last line.
How to strip trailing spaces on all lines in a variable?
It seems subr-x's string-trim-right
only operates on the last line.
How to strip trailing spaces on all lines in a variable?
This can be done by splitting and joining strings:
(require 'subr-x)
(defun string-trim-right-multiline (str)
(mapconcat 'string-trim-right
(split-string str "\n") "\n"))
Note that if you want to perform other operations on the string you can define a function:
(require 'subr-x)
(defun string-trim-right-multiline (str)
(mapconcat (function (lambda (s) (string-trim-right s)))
(split-string str "\n") "\n"))
(function (lambda (s) (string-trim-right s)))
with just 'string-trim-right
.