Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chrisalcantara opened this issue Apr 10, 2021 · 4 comments
Open

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

chrisalcantara opened this issue Apr 10, 2021 · 4 comments

Comments

@chrisalcantara
Copy link
Contributor

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
Copy link
Contributor

syohex commented Apr 13, 2021

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
Copy link
Contributor Author

chrisalcantara commented Apr 13, 2021

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
Copy link
Contributor

syohex commented Apr 13, 2021

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants