How do I delete the newline from a process output?

前端 未结 4 1280
傲寒
傲寒 2021-01-11 09:39

I call git get the toplevel dir (according to Is there a way to get the git root directory in one command? ).

(let ((tmpbuffer (get-buffer-create (make-temp-         


        
4条回答
  •  不知归路
    2021-01-11 10:01

    If you only want to remove a newline at the very end of the output, use

    (replace-regexp-in-string "\n\\'" "" 
      (shell-command-to-string "git rev-parse --show-toplevel"))
    

    The accepted answer also replaces pairs of newlines ("\n\n") in the output by single newlines ("\n"), because $ matches at the end of the string or after a newline, while \\' only matches at the end of the string.

提交回复
热议问题