Switch to `get-program-code-output' and explicit destructuring

This commit is contained in:
Gerard Vermeulen 2024-06-17 19:31:20 +02:00
parent 6e0d21f7b7
commit b2f3aa4ef7

View File

@ -905,10 +905,10 @@ output to =stdout=.
#+name: lst:process-utilities #+name: lst:process-utilities
#+begin_src emacs-lisp -n :results silent #+begin_src emacs-lisp -n :results silent
;; https://gitlab.com/howardabrams/spacemacs.d/blob/master/layers/ha-org/funcs.el#L418 ;; https://gitlab.com/howardabrams/spacemacs.d/blob/master/layers/ha-org/funcs.el#L418
(defun shell-command-with-exit-code (program &rest args) (defun get-program-code-output (program &rest args)
"Run PROGRAM with ARGS and return exit-code and output in a list." "Run PROGRAM with ARGS and return the `cons' of return-code and output."
(with-temp-buffer (with-temp-buffer
(list (apply 'call-process program nil (current-buffer) nil args) (cons (apply 'call-process program nil (current-buffer) nil args)
(buffer-substring-no-properties (point-min) (point-max))))) (buffer-substring-no-properties (point-min) (point-max)))))
#+end_src #+end_src
@ -1977,10 +1977,11 @@ configuration objectives:
(defun update-lualatex-opentype-font-name-database () (defun update-lualatex-opentype-font-name-database ()
"Update the \"OpenType Font\" name database for \"LuaLaTeX\"." "Update the \"OpenType Font\" name database for \"LuaLaTeX\"."
(interactive) (interactive)
(pcase-let ((`(,exit-code ,output) (let* ((pair (get-program-code-output
(shell-command-with-exit-code "luaotfload-tool" "-vv" "--update" "--force"))
"luaotfload-tool" "-vv" "--update" "--force"))) (return-code (car pair))
(if (= 0 exit-code) (output (cdr pair)))
(if (= 0 return-code)
(message "%s" (string-trim output)) (message "%s" (string-trim output))
(error "%s" (string-trim output)))))) (error "%s" (string-trim output))))))
#+end_src #+end_src
@ -2642,9 +2643,10 @@ valid directories and files. In an [[https://orgmode.org/][Org-mode]] buffer th
(defun biber-delete-cache () (defun biber-delete-cache ()
"Delete the `Biber' cache to get rid of `Biber' exit code 2." "Delete the `Biber' cache to get rid of `Biber' exit code 2."
(interactive) (interactive)
(pcase-let ((`(,exit-code ,output) (let* ((pair (get-program-code-output "rm" "-rf" "$(biber --cache)"))
(shell-command-with-exit-code "rm" "-rf" "$(biber --cache)"))) (return-code (car pair))
(if (= 0 exit-code) (output (cdr pair)))
(if (= 0 return-code)
(message "%s" (string-trim output)) (message "%s" (string-trim output))
(error "%s" (string-trim output)))))) (error "%s" (string-trim output))))))
#+end_src #+end_src
@ -4871,35 +4873,39 @@ through =cat= to remove escape sequences.
(defun pyenv-root () (defun pyenv-root ()
"Return \"pyenv root\" as a directory." "Return \"pyenv root\" as a directory."
(pcase-let ((`(,exit-code ,output) (let* ((pair (get-program-code-output "pyenv" "root"))
(shell-command-with-exit-code "pyenv" "root"))) (return-code (car pair))
(if (= 0 exit-code) (output (cdr pair)))
(if (= 0 return-code)
(file-name-as-directory (string-trim output)) (file-name-as-directory (string-trim output))
(error "%s" (string-trim output))))) (error "%s" (string-trim output)))))
(defun pyenv-version-name () (defun pyenv-version-name ()
"Return \"pyenv version-name\"." "Return \"pyenv version-name\"."
(pcase-let ((`(,exit-code ,output) (let* ((pair (get-program-code-output "pyenv" "version-name"))
(shell-command-with-exit-code "pyenv" "version-name"))) (return-code (car pair))
(if (= 0 exit-code) (output (cdr pair)))
(if (= 0 return-code)
(string-trim output) (string-trim output)
(error "%s" (string-trim output))))) (error "%s" (string-trim output)))))
(defun pyenv-versions () (defun pyenv-versions ()
"Return \"pyenv versions --bare --skip-aliases\" as a list." "Return \"pyenv versions --bare --skip-aliases\" as a list."
(pcase-let ((`(,exit-code ,output) (let* ((pair (get-program-code-output
(shell-command-with-exit-code "pyenv" "versions" "--bare" "--skip-aliases"))
"pyenv" "versions" "--bare" "--skip-aliases"))) (return-code (car pair))
(if (= 0 exit-code) (output (cdr pair)))
(if (= 0 return-code)
(split-string output) (split-string output)
(error "%s" (string-trim output))))) (error "%s" (string-trim output)))))
(defun pyenv-virtualenvs () (defun pyenv-virtualenvs ()
"Return \"pyenv virtualenvs --bare --skip-aliases\" as a list." "Return \"pyenv virtualenvs --bare --skip-aliases\" as a list."
(pcase-let ((`(,exit-code ,output) (let* ((pair (get-program-code-output
(shell-command-with-exit-code "pyenv" "virtualenvs" "--bare" "--skip-aliases"))
"pyenv" "virtualenvs" "--bare" "--skip-aliases"))) (return-code (car pair))
(if (= 0 exit-code) (output (cdr pair)))
(if (= 0 return-code)
(split-string output) (split-string output)
(error "%s" (string-trim output)))))) (error "%s" (string-trim output))))))
#+end_src #+end_src