mbsync-el icon indicating copy to clipboard operation
mbsync-el copied to clipboard

Carriage return handling in process buffer

Open shader opened this issue 3 years ago • 1 comments

I just started to use mbsync.el for automating the fetch+reload process with gnus; thanks for your work.

When running mbsync, the sync process spits out progress update lines ending with ^M to overwrite the output, but the simple process buffer currently just concatenates them with literal "^M" characters instead.

I found this code snippet on SO for a process filter that handles carriage returns:

;Fill the buffer in the same way as it would be shown in bash
(defun shelllike-filter (proc string)
  (let* ((buffer (process-buffer proc))
         (window (get-buffer-window buffer)))
    (with-current-buffer buffer
      (if (not (mark)) (push-mark))
      (exchange-point-and-mark) ;Use the mark to represent the cursor location
      (dolist (char (append string nil))
    (cond ((char-equal char ?\r)
           (move-beginning-of-line 1))
          ((char-equal char ?\n)
           (move-end-of-line 1) (newline))
          (t
           (if (/= (point) (point-max)) ;Overwrite character
           (delete-char 1))
           (insert char))))
      (exchange-point-and-mark))
    (if window
      (with-selected-window window
        (goto-char (point-max))))))

Could something like that be integrated into mbsync.el's process filter for cleaner output?

shader avatar Oct 02 '22 20:10 shader

Hi @shader ; I've not been using either Gnus or mbsync-el in a long long time now. Please hack it your way and consider opening a PR here to improve it! Thanks

dimitri avatar Oct 03 '22 11:10 dimitri