Reduce the `cl-lib' dependency and fix minor bugs in the process

This commit is contained in:
Gerard Vermeulen 2024-06-17 16:09:11 +02:00
parent 5d6a749a77
commit 6e0d21f7b7

View File

@ -1238,7 +1238,7 @@ sub makeglossaries {
(with-current-buffer buffer (with-current-buffer buffer
(let ((mode major-mode)) (let ((mode major-mode))
(push mode result)))) (push mode result))))
(cl-sort (cl-remove-duplicates result) #'string-lessp))) (sort (cl-remove-duplicates result))))
#+end_src #+end_src
@ -1977,9 +1977,9 @@ 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)
(cl-destructuring-bind (exit-code output) (pcase-let ((`(,exit-code ,output)
(shell-command-with-exit-code (shell-command-with-exit-code
"luaotfload-tool" "-vv" "--update" "--force") "luaotfload-tool" "-vv" "--update" "--force")))
(if (= 0 exit-code) (if (= 0 exit-code)
(message "%s" (string-trim output)) (message "%s" (string-trim output))
(error "%s" (string-trim output)))))) (error "%s" (string-trim output))))))
@ -2529,7 +2529,7 @@ def __org_babel_python_format_value(result, result_file, result_params):
result))))) result)))))
result)) result))
(mapcar #'list (cl-sort (org-babel-active-languages) #'string-lessp)) (mapcar #'list (sort (org-babel-active-languages)))
#+end_src #+end_src
#+caption[Active Org Babel languages]: #+caption[Active Org Babel languages]:
@ -2642,8 +2642,8 @@ 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)
(cl-destructuring-bind (exit-code output) (pcase-let ((`(,exit-code ,output)
(shell-command-with-exit-code "rm" "-rf" "$(biber --cache)") (shell-command-with-exit-code "rm" "-rf" "$(biber --cache)")))
(if (= 0 exit-code) (if (= 0 exit-code)
(message "%s" (string-trim output)) (message "%s" (string-trim output))
(error "%s" (string-trim output)))))) (error "%s" (string-trim output))))))
@ -4867,40 +4867,38 @@ through =cat= to remove escape sequences.
(when (executable-find "pyenv") (when (executable-find "pyenv")
(defun pyenv-full-path (version) (defun pyenv-full-path (version)
"Return the full path for VERSION." "Return the full path for VERSION."
(unless (string= version "system") (concat (pyenv-root) (file-name-as-directory "versions") version))
(concat (pyenv-root) (file-name-as-directory "versions") version)))
(defun pyenv-root () (defun pyenv-root ()
"Return \"pyenv root\" as a directory." "Return \"pyenv root\" as a directory."
(cl-destructuring-bind (exit-code output) (pcase-let ((`(,exit-code ,output)
(shell-command-with-exit-code "pyenv" "root") (shell-command-with-exit-code "pyenv" "root")))
(if (= 0 exit-code) (if (= 0 exit-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\"."
(cl-destructuring-bind (exit-code output) (pcase-let ((`(,exit-code ,output)
(shell-command-with-exit-code "pyenv" "version-name") (shell-command-with-exit-code "pyenv" "version-name")))
(if (= 0 exit-code) (if (= 0 exit-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."
Complete the result with \"system\"." (pcase-let ((`(,exit-code ,output)
(cl-destructuring-bind (exit-code output) (shell-command-with-exit-code
(shell-command-with-exit-code "pyenv" "versions" "--bare" "--skip-aliases")))
"pyenv" "versions" "--bare" "--skip-aliases")
(if (= 0 exit-code) (if (= 0 exit-code)
(cons "system" (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."
(cl-destructuring-bind (exit-code output) (pcase-let ((`(,exit-code ,output)
(shell-command-with-exit-code (shell-command-with-exit-code
"pyenv" "virtualenvs" "--bare" "--skip-aliases") "pyenv" "virtualenvs" "--bare" "--skip-aliases")))
(if (= 0 exit-code) (if (= 0 exit-code)
(split-string output) (split-string output)
(error "%s" (string-trim output)))))) (error "%s" (string-trim output))))))
@ -4911,10 +4909,10 @@ Complete the result with \"system\"."
#+name: lst:select-python-virtual-environment #+name: lst:select-python-virtual-environment
#+begin_src emacs-lisp -n :results silent #+begin_src emacs-lisp -n :results silent
(with-eval-after-load 'python (with-eval-after-load 'python
(when (cl-every #'fboundp '(pyenv-full-path (when (and (fboundp 'pyenv-full-path)
pyenv-version-name (fboundp 'pyenv-version-name)
pyenv-versions (fboundp 'pyenv-versions)
pyenv-virtualenvs)) (fboundp 'pyenv-virtualenvs))
(setq python-shell-virtualenv-root (setq python-shell-virtualenv-root
(pyenv-full-path (or (pyenv-version-name) (pyenv-full-path (or (pyenv-version-name)
(car (pyenv-virtualenvs)) (car (pyenv-virtualenvs))
@ -4923,7 +4921,7 @@ Complete the result with \"system\"."
python-shell-virtualenv-root) python-shell-virtualenv-root)
(defun set-python-shell-virtualenv-root-to-pyenv-version () (defun set-python-shell-virtualenv-root-to-pyenv-version ()
"Set `python-shell-virtual-env-root' to a pyenv version." "Set `python-shell-virtualenv-root' to a pyenv version."
(interactive) (interactive)
(let* ((version-name (pyenv-version-name)) (let* ((version-name (pyenv-version-name))
(prompt (format "pyenv version (%s): " version-name)) (prompt (format "pyenv version (%s): " version-name))
@ -4936,7 +4934,7 @@ Complete the result with \"system\"."
python-shell-virtualenv-root))) python-shell-virtualenv-root)))
(defun set-python-shell-virtualenv-root-to-pyenv-virtualenv () (defun set-python-shell-virtualenv-root-to-pyenv-virtualenv ()
"Set `python-shell-virtual-env-root' to a pyenv virtualenv." "Set `python-shell-virtualenv-root' to a pyenv virtualenv."
(interactive) (interactive)
(let* ((version-name (pyenv-version-name)) (let* ((version-name (pyenv-version-name))
(prompt (format "pyenv virtualenv (%s): " version-name)) (prompt (format "pyenv virtualenv (%s): " version-name))