diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2020-12-21 22:05:37 +0100 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2020-12-21 22:05:37 +0100 |
commit | f329a3180ead740bb85e1edfc48ae360a56f7ffd (patch) | |
tree | e5710512f8c9dbed77cbda51753c479865b77f8d /lisp/emacs-lisp/subr-x.el | |
parent | e967ba301857edd15778a018ae716e4e98fa2fa9 (diff) | |
download | emacs-f329a3180ead740bb85e1edfc48ae360a56f7ffd.tar.gz emacs-f329a3180ead740bb85e1edfc48ae360a56f7ffd.tar.bz2 emacs-f329a3180ead740bb85e1edfc48ae360a56f7ffd.zip |
Add string-chop-newline
* doc/lispref/strings.texi (Creating Strings): Document it.
* lisp/emacs-lisp/subr-x.el (string-chop-newline): Add new function.
Diffstat (limited to 'lisp/emacs-lisp/subr-x.el')
-rw-r--r-- | lisp/emacs-lisp/subr-x.el | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 78d0b054b35..80d4cb9b650 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -337,6 +337,10 @@ string." (and (> length 0) (make-string pad-length (or padding ?\s))))))) +(defun string-chop-newline (string) + "Remove the final newline (if any) from STRING." + (replace-regexp-in-string "\n\\'" "" string)) + (defun replace-region-contents (beg end replace-fn &optional max-secs max-costs) "Replace the region between BEG and END using REPLACE-FN. |