Skip to content

Commit

Permalink
Handle carriage return the same way compilation-buffer does
Browse files Browse the repository at this point in the history
  • Loading branch information
BlankSpruce committed Jun 30, 2022
1 parent f4d123c commit 6eab294
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ W => open eshell without executing
change the /justl-executable/ variable to set any explicit path.
- You can also control the width of the RECIPE column in the justl
buffer via /justl-recipe width/. By default it has a value of 20.
- You can enable customize how output from *just* is processed
with /justl-process-filter/ variable.

* Future

Expand Down
40 changes: 26 additions & 14 deletions justl.el
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
;; Keywords: just justfile tools processes
;; URL: https://github.com/psibi/justl.el
;; License: GNU General Public License >= 3
;; Package-Requires: ((transient "0.1.0") (emacs "25.3") (xterm-color "2.0") (s "1.2.0") (f "0.20.0"))
;; Package-Requires: ((transient "0.1.0") (emacs "25.3") (s "1.2.0") (f "0.20.0"))

;;; Commentary:

Expand Down Expand Up @@ -60,17 +60,22 @@
;;
;; You can also control the width of the RECIPE column in the justl
;; buffer via `justl-recipe width`. By default it has a value of 20.
;;
;; You can enable customize how output from *just* is processed
;; with /justl-process-filter/ variable.
;;

;;; Code:

(require 'ansi-color)
(require 'transient)
(require 'cl-lib)
(require 'xterm-color)
(require 'eshell)
(require 'esh-mode)
(require 's)
(require 'f)
(require 'compile)
(require 'comint)

(defgroup justl nil
"Justfile customization group."
Expand All @@ -90,6 +95,12 @@
:type 'integer
:group 'justl)

(defcustom justl-process-filter
#'justl-default-process-filter
"Filter to use for subprocess handling just."
:type 'function
:group 'justl)

(cl-defstruct justl-jrecipe name args)
(cl-defstruct justl-jarg arg default)

Expand Down Expand Up @@ -283,20 +294,21 @@ CMD is the just command as a list."
process-name
err))))))

(defun justl--xterm-color-filter (proc string)
"Filter function for PROC handling colors.
(defun justl-default-process-filter (proc string)
"Filter function for PROC handling colors and carriage return.
STRING is the data returned by the PROC"
(when (buffer-live-p (process-buffer proc))
(with-current-buffer (process-buffer proc)
(let ((inhibit-read-only t)
(moving (= (point) (process-mark proc))))
(save-excursion
;; Insert the text, advancing the process marker.
(goto-char (process-mark proc))
(insert (xterm-color-filter string))
(set-marker (process-mark proc) (point)))
(if moving (goto-char (process-mark proc)))))))
(let ((inhibit-read-only t))
(unwind-protect
(progn
(widen)
(goto-char (marker-position (process-mark proc)))
(insert string)
(comint-carriage-motion (process-mark proc) (point))
(ansi-color-apply-on-region (process-mark proc) (point))
(set-marker (process-mark proc) (point))))))))

(defun justl-compilation-setup-buffer (buf dir mode &optional no-mode-line)
"Setup the compilation buffer for just-compile-mode.
Expand Down Expand Up @@ -349,7 +361,7 @@ ARGS is a plist that affects how the process is run.

(setq-local justl--justfile (justl--justfile-from-arg (elt command 1)))
(run-hook-with-args 'compilation-start-hook process)
(set-process-filter process 'justl--xterm-color-filter)
(set-process-filter process justl-process-filter)
(set-process-sentinel process sentinel)
(set-process-coding-system process 'utf-8-emacs-unix 'utf-8-emacs-unix)
(pop-to-buffer buf)))))
Expand Down Expand Up @@ -430,7 +442,7 @@ ARGS is a ist of arguments."
(justl--log-command process-name cmd)
(make-process :name process-name
:buffer buffer-name
:filter 'justl--xterm-color-filter
:filter justl-process-filter
:sentinel #'justl--sentinel
:file-handler t
:stderr nil
Expand Down

0 comments on commit 6eab294

Please sign in to comment.