emacsorphanage / quickrun

Run command quickly. This packages is inspired quickrun.vim
GNU General Public License v3.0
480 stars 43 forks source link

How to hide new-line characters in output? #135

Open chrisalcantara opened 3 years ago

chrisalcantara commented 3 years ago

For me, I keep getting the ^M new line character for output. Here is an example when running an emacs-lisp file:

2021-04-10-164332_580x55_scrot

I have this is my init.el to set the coding system, but it doesn't seem to work.

(setq default-buffer-file-coding-system 'utf-8-auto)

I'd appreciate the help.

syohex commented 3 years ago

How about adding a hook which removes ^M as below ?

(defun my/quickrun-after-hook ()
  (save-excursion
    (let ((buffer-read-only nil))
      (goto-char (point-min))
      (while (re-search-forward "^M" nil t) ;; You need to type `C-q C-m` for inserting `^M` character. This is not two characters `^` and `M`
    (replace-match "")))))

(add-hook 'quickrun-after-run-hook #'my/quickrun-after-hook)
chrisalcantara commented 3 years ago

Thanks for the suggestion, @syohex. But the regex looks like it's searching for the letter M at the beginning of each line.

Running a script like this:

main() {
    echo "Hello"
}

main()

Turns into this:

ain() {
    echo "Hello"
}

ain()

I wonder if this is legal regex syntax: re-search-forward "\\^M" nil t) using two backslashes to escape the caret?

syohex commented 3 years ago

As I commented, it is not ^ and M characters, it's carriage return(\r) character. Can you try to type it by C-q C-m or M-x quoted-insert and C-m.

chrisalcantara commented 3 years ago

Got it, @syohex! I didn't read your comment carefully, and now I understand what you meant with c-q c-m.