shell-command-to-string -> doom-call-process #1887

Minor optimization to remove a layer of indirection when starting
processes.
This commit is contained in:
Henrik Lissner 2019-11-07 18:20:38 -05:00
parent 873fc5c0db
commit 44d5e097c9
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
5 changed files with 46 additions and 45 deletions

View file

@ -32,9 +32,8 @@ ready to be pasted in a bug report on github."
(doom-modules (doom-modules)))
(cl-letf
(((symbol-function 'sh)
(lambda (format)
(string-trim
(shell-command-to-string format)))))
(lambda (&rest args)
(cdr (apply #'doom-call-process args)))))
`((emacs
(version . ,emacs-version)
(features ,@system-configuration-features)
@ -47,14 +46,14 @@ ready to be pasted in a bug report on github."
'server-running))))
(doom
(version . ,doom-version)
(build . ,(sh "git log -1 --format=\"%D %h %ci\"")))
(build . ,(sh "git" "log" "-1" "--format=%D %h %ci")))
(system
(type . ,system-type)
(config . ,system-configuration)
(shell . ,shell-file-name)
(uname . ,(if IS-WINDOWS
"n/a"
(sh "uname -msrv")))
(sh "uname" "-msrv")))
(path . ,(mapcar #'abbreviate-file-name exec-path)))
(config
(envfile
@ -117,7 +116,7 @@ branch and commit."
"n/a")
(or (vc-git-working-revision doom-core-dir)
"n/a")
(or (string-trim (shell-command-to-string "git log -1 --format=%ci"))
(or (cdr (doom-call-process "git" "log" "-1" "--format=%ci"))
"n/a"))))
;;;###autoload

View file

@ -395,13 +395,15 @@ current file is in, or d) the module associated with the current major mode (see
(message "Couldn't find the config block"))))))))
(defun doom--help-package-configs (package)
;; TODO Add git checks, in case ~/.emacs.d isn't a git repo
(let ((default-directory doom-emacs-dir))
;; TODO Use ripgrep instead
(split-string
(shell-command-to-string
(format "git grep --no-break --no-heading --line-number '%s %s\\($\\| \\)' ':(exclude)*.org'"
(cdr (doom-call-process
"git" "grep" "--no-break" "--no-heading" "--line-number"
(format "%s %s\\($\\| \\)"
"\\(^;;;###package\\|(after!\\|(use-package!\\)"
package))
package)
":(exclude)*.org"))
"\n" t)))
;;;###autoload
@ -463,8 +465,8 @@ If prefix arg is present, refresh the cache."
(`straight
(format! "Straight (%s)\n%s"
(let ((default-directory (straight--build-dir (symbol-name package))))
(string-trim
(shell-command-to-string "git log -1 --format=\"%D %h %ci\"")))
(cdr
(doom-call-process "git" "log" "-1" "--format=%D %h %ci")))
(indent
13 (string-trim
(pp-to-string

View file

@ -179,22 +179,22 @@ If ARG (universal argument), open selection in other-window."
.type .file .line)))))
(defun +ivy--tasks (target)
(let* (case-fold-search
(task-tags (mapcar #'car +ivy-task-tags))
(cmd
(format "%s -H -S --no-heading -- %s %s"
(let (case-fold-search)
(cl-loop with task-tags = (mapcar #'car +ivy-task-tags)
with out =
(cdr
(apply #'doom-call-process
(append
(or (when-let (bin (executable-find "rg"))
(concat bin " --line-number"))
(list bin "--line-number"))
(when-let (bin (executable-find "ag"))
(concat bin " --numbers"))
(error "ripgrep & the_silver_searcher are unavailable"))
(shell-quote-argument
(list bin "--numbers"))
(user-error "ripgrep & the_silver_searcher are unavailable"))
(list "-H" "-S" "--no-heading" "--"
(concat "\\s("
(string-join task-tags "|")
")([\\s:]|\\([^)]+\\):?)"))
target)))
(save-match-data
(cl-loop with out = (shell-command-to-string cmd)
")([\\s:]|\\([^)]+\\):?)")
target))))
for x in (and out (split-string out "\n" t))
when (condition-case-unless-debug ex
(string-match
@ -210,7 +210,7 @@ If ARG (universal argument), open selection in other-window."
collect `((type . ,(match-string 3 x))
(desc . ,(match-string 4 x))
(file . ,(match-string 1 x))
(line . ,(match-string 2 x)))))))
(line . ,(match-string 2 x))))))
(defun +ivy--tasks-open-action (x)
"Jump to the file and line of the current task."

View file

@ -100,7 +100,7 @@
(interactive)
(let* ((msg-path (car (plist-get (notmuch-tree-get-message-properties) :filename)))
(temp (make-temp-file "notmuch-message-" nil ".eml")))
(shell-command-to-string (format "cp '%s' '%s'" msg-path temp))
(doom-call-process "cp" msg-path temp)
(start-process-shell-command "email" nil (format "xdg-open '%s'" temp))))
;;;###autoload
@ -108,7 +108,7 @@
(interactive)
(let* ((msg-path (car (plist-get (notmuch-show-get-message-properties) :filename)))
(temp (make-temp-file "notmuch-message-" nil ".eml")))
(shell-command-to-string (format "cp '%s' '%s'" msg-path temp))
(doom-call-process "cp" msg-path temp)
(start-process-shell-command "email" nil (format "xdg-open '%s'" temp))))

View file

@ -21,12 +21,12 @@ Make sure your src block has a :session param.")
(defun +org--ob-ipython-generate-local-path-from-remote (session host params)
"Given a remote SESSION with PARAMS and corresponding HOST, copy remote config to local, start a jupyter console to generate a new one."
(let* ((runtime-dir
(substring (shell-command-to-string (concat "ssh " host " jupyter --runtime-dir")) 0 -1))
(cdr
(doom-call-process "ssh " host "jupyter" "--runtime-dir")))
(runtime-file (concat runtime-dir "/" "kernel-" session ".json"))
(tramp-path (concat "/ssh:" host ":" runtime-file))
(tramp-copy (concat (or +ob-ipython-local-runtime-dir
(substring (shell-command-to-string "jupyter --runtime-dir")
0 -1))
(cdr (doom-call-process "jupyter" "--runtime-dir")))
"/remote-" host "-kernel-" session ".json"))
(local-path
(concat