From f9a67dde682f24aa31891bfabb0e9fa84ef4adcc Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 14 Nov 2024 13:56:52 -0500 Subject: [PATCH] Handle carriage return in inf-ruby output Added a custom function `inf-ruby-process-carriage-return` to clean up unwanted carriage returns from inf-ruby output. This function is now hooked into `comint-preoutput-filter-functions` to process output in `inf-ruby-mode`. This change ensures better handling of newline characters in the output stream. --- emacs/.emacs.d/config/init-ruby.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/emacs/.emacs.d/config/init-ruby.el b/emacs/.emacs.d/config/init-ruby.el index 2efa2a0..7259cf2 100644 --- a/emacs/.emacs.d/config/init-ruby.el +++ b/emacs/.emacs.d/config/init-ruby.el @@ -18,7 +18,16 @@ :commands (inf-ruby inf-ruby-console-auto) :general ([remap inf-ruby] #'inf-ruby-console-auto) - :hook (after-init . inf-ruby-switch-setup)) + :hook (after-init . inf-ruby-switch-setup) + :config + (defun inf-ruby-process-carriage-return (output) + (let ((processed (replace-regexp-in-string ".*\r" "" output))) + (if (string-match-p "\\`\n" processed) + (replace-regexp-in-string "\\`\n" "" processed) + processed))) + (defun inf-ruby-carriage-return-hook () + (add-hook 'comint-preoutput-filter-functions #'inf-ruby-process-carriage-return nil t)) + (add-hook 'inf-ruby-mode-hook #'inf-ruby-carriage-return-hook)) (use-package rbenv :hook (after-init . global-rbenv-mode)