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))) (doom-modules (doom-modules)))
(cl-letf (cl-letf
(((symbol-function 'sh) (((symbol-function 'sh)
(lambda (format) (lambda (&rest args)
(string-trim (cdr (apply #'doom-call-process args)))))
(shell-command-to-string format)))))
`((emacs `((emacs
(version . ,emacs-version) (version . ,emacs-version)
(features ,@system-configuration-features) (features ,@system-configuration-features)
@ -47,14 +46,14 @@ ready to be pasted in a bug report on github."
'server-running)))) 'server-running))))
(doom (doom
(version . ,doom-version) (version . ,doom-version)
(build . ,(sh "git log -1 --format=\"%D %h %ci\""))) (build . ,(sh "git" "log" "-1" "--format=%D %h %ci")))
(system (system
(type . ,system-type) (type . ,system-type)
(config . ,system-configuration) (config . ,system-configuration)
(shell . ,shell-file-name) (shell . ,shell-file-name)
(uname . ,(if IS-WINDOWS (uname . ,(if IS-WINDOWS
"n/a" "n/a"
(sh "uname -msrv"))) (sh "uname" "-msrv")))
(path . ,(mapcar #'abbreviate-file-name exec-path))) (path . ,(mapcar #'abbreviate-file-name exec-path)))
(config (config
(envfile (envfile
@ -117,7 +116,7 @@ branch and commit."
"n/a") "n/a")
(or (vc-git-working-revision doom-core-dir) (or (vc-git-working-revision doom-core-dir)
"n/a") "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")))) "n/a"))))
;;;###autoload ;;;###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")))))))) (message "Couldn't find the config block"))))))))
(defun doom--help-package-configs (package) (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)) (let ((default-directory doom-emacs-dir))
;; TODO Use ripgrep instead
(split-string (split-string
(shell-command-to-string (cdr (doom-call-process
(format "git grep --no-break --no-heading --line-number '%s %s\\($\\| \\)' ':(exclude)*.org'" "git" "grep" "--no-break" "--no-heading" "--line-number"
"\\(^;;;###package\\|(after!\\|(use-package!\\)" (format "%s %s\\($\\| \\)"
package)) "\\(^;;;###package\\|(after!\\|(use-package!\\)"
package)
":(exclude)*.org"))
"\n" t))) "\n" t)))
;;;###autoload ;;;###autoload
@ -463,8 +465,8 @@ If prefix arg is present, refresh the cache."
(`straight (`straight
(format! "Straight (%s)\n%s" (format! "Straight (%s)\n%s"
(let ((default-directory (straight--build-dir (symbol-name package)))) (let ((default-directory (straight--build-dir (symbol-name package))))
(string-trim (cdr
(shell-command-to-string "git log -1 --format=\"%D %h %ci\""))) (doom-call-process "git" "log" "-1" "--format=%D %h %ci")))
(indent (indent
13 (string-trim 13 (string-trim
(pp-to-string (pp-to-string

View file

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

View file

@ -100,7 +100,7 @@
(interactive) (interactive)
(let* ((msg-path (car (plist-get (notmuch-tree-get-message-properties) :filename))) (let* ((msg-path (car (plist-get (notmuch-tree-get-message-properties) :filename)))
(temp (make-temp-file "notmuch-message-" nil ".eml"))) (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)))) (start-process-shell-command "email" nil (format "xdg-open '%s'" temp))))
;;;###autoload ;;;###autoload
@ -108,7 +108,7 @@
(interactive) (interactive)
(let* ((msg-path (car (plist-get (notmuch-show-get-message-properties) :filename))) (let* ((msg-path (car (plist-get (notmuch-show-get-message-properties) :filename)))
(temp (make-temp-file "notmuch-message-" nil ".eml"))) (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)))) (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) (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." "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 (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")) (runtime-file (concat runtime-dir "/" "kernel-" session ".json"))
(tramp-path (concat "/ssh:" host ":" runtime-file)) (tramp-path (concat "/ssh:" host ":" runtime-file))
(tramp-copy (concat (or +ob-ipython-local-runtime-dir (tramp-copy (concat (or +ob-ipython-local-runtime-dir
(substring (shell-command-to-string "jupyter --runtime-dir") (cdr (doom-call-process "jupyter" "--runtime-dir")))
0 -1))
"/remote-" host "-kernel-" session ".json")) "/remote-" host "-kernel-" session ".json"))
(local-path (local-path
(concat (concat