summaryrefslogtreecommitdiff
path: root/piem.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2020-05-26 00:35:09 -0400
committerKyle Meyer <kyle@kyleam.com>2020-05-26 00:40:21 -0400
commit62760598b31f46cc96d1bed462ba84a80bac3641 (patch)
treeccd7afdb589e6eeedb0dbd35008d9882283ea014 /piem.el
parentc17bd6f389d3736c55a51372e06e1ce4cd3976b1 (diff)
downloadpiem-62760598b31f46cc96d1bed462ba84a80bac3641.tar.gz
Add basic mode for displaying {call,start}-process output
Diffstat (limited to 'piem.el')
-rw-r--r--piem.el69
1 files changed, 69 insertions, 0 deletions
diff --git a/piem.el b/piem.el
index 9695511..a6b3819 100644
--- a/piem.el
+++ b/piem.el
@@ -130,6 +130,75 @@ intended to be used by libraries implementing a function for
(throw 'hit (car inbox)))))))))
+;;;; Subprocess handling
+
+(defvar piem-process-mode-font-lock-keywords
+ `((,(rx line-start
+ ";;; " (or "process" "directory") ":" (one-or-more not-newline)
+ line-end)
+ (0 font-lock-comment-face t))
+ (,(rx line-start
+ "Process " (one-or-more not-newline) " finished"
+ line-end)
+ (0 font-lock-comment-face))))
+
+(define-derived-mode piem-process-mode nil "piem-process"
+ "Major mode for displaying processes created by piem."
+ :group 'piem
+ (setq buffer-read-only t)
+ (setq-local window-point-insertion-type t)
+ (setq-local font-lock-defaults
+ '(piem-process-mode-font-lock-keywords)))
+
+(define-error 'piem-process-error "piem process error")
+
+(defvar-local piem--buffer-process nil)
+
+(defun piem--process-go (buffer dir program program-args fn)
+ (setq dir (or dir default-directory))
+ (setq buffer (get-buffer-create buffer))
+ (with-current-buffer buffer
+ (when (and piem--buffer-process
+ (process-live-p piem--buffer-process))
+ (user-error "Buffer %s already has an active process: %s"
+ (current-buffer) piem--buffer-process))
+ (unless (derived-mode-p 'piem-process-mode)
+ (piem-process-mode))
+ (setq default-directory (file-name-as-directory dir))
+ (display-buffer buffer)
+ (let ((inhibit-read-only t))
+ (insert (format "
+%s
+;;; process: %S
+;;; directory: %s
+"
+ (char-to-string 12) ; form feed
+ (cons program program-args)
+ default-directory))
+ (funcall fn))))
+
+(defun piem-process-start (buffer dir program &rest program-args)
+ (setq program-args (remq nil program-args))
+ (piem--process-go
+ buffer dir program program-args
+ (lambda ()
+ (setq piem--buffer-process
+ (apply #'start-process
+ (file-name-nondirectory program)
+ (current-buffer)
+ program program-args)))))
+
+(defun piem-process-call (buffer dir program &rest program-args)
+ (setq program-args (remq nil program-args))
+ (piem--process-go
+ buffer dir program program-args
+ (lambda ()
+ (unless (= 0 (apply #'call-process program nil t nil program-args))
+ (signal 'piem-error
+ (list (format "%s call in %s failed"
+ program default-directory)))))))
+
+
;;;; Extractors
(defun piem-inbox ()