about summary refs log tree commit diff
path: root/configs/shared/.emacs.d/wpc/prelude.el
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2019-12-23T17·31+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-01-06T15·25+0000
commit5785a5d126210e8c9651da038b6c8b083041fef6 (patch)
tree2303a7bc5b7928b528e06e1abb899119882c15bb /configs/shared/.emacs.d/wpc/prelude.el
parentc078f0452666e4d7a03d234393ccec7210a86642 (diff)
Support prelude/start-process
If you refer to the previous commit where I change shell-command usages to
start-process function calls, you'll see the rationale for why I prefer
start-process.

This commit introduces a more ergonomic API for start-process that fits most of
my current use-cases of it. This cleans up the code. I have introduced a bug in
the way that I'm tokenizing the COMMAND value. I've tracked that with a
TODO. For now it only affects the `xmodmap -e '<command-string>'` calls, which
isn't too disruptive.
Diffstat (limited to 'configs/shared/.emacs.d/wpc/prelude.el')
-rw-r--r--configs/shared/.emacs.d/wpc/prelude.el17
1 files changed, 16 insertions, 1 deletions
diff --git a/configs/shared/.emacs.d/wpc/prelude.el b/configs/shared/.emacs.d/wpc/prelude.el
index fb45962789..c1579d5589 100644
--- a/configs/shared/.emacs.d/wpc/prelude.el
+++ b/configs/shared/.emacs.d/wpc/prelude.el
@@ -20,7 +20,6 @@
 (require 'dash)
 (require 'f)
 
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Libraries
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -111,6 +110,22 @@ difficult to troubleshoot bugs in your init files."
   "Read input from user with PROMPT."
   (read-string prompt))
 
+;; TODO: Fix the bug with tokenizing here, since it will split any whitespace
+;; character, (even though it shouldn't in the case of quoted string in shell).
+;; e.g. - "xmodmap -e 'one two three'" => '("xmodmap" "-e" "'one two three'")
+(cl-defun prelude/start-process (&key name command)
+  "Pass command string, COMMAND, and the function name, NAME.
+This is a wrapper around `start-process' that has an API that resembles
+`shell-command'."
+  (let* ((tokens (string/split " " command))
+         (program-name (list/head tokens))
+         (program-args (list/tail tokens)))
+    (apply #'start-process
+           `(,(string/format "*%s<%s>*" program-name name)
+             ,nil
+             ,program-name
+             ,@program-args))))
+
 (defun prelude/executable-exists? (name)
   "Return t if CLI tool NAME exists according to `exec-path'."
   (let ((file (locate-file name exec-path)))