Fix org version conflicts due to literate config #3649
Tangling would load org libraries. If org hasn't been installed yet, this means the older version is loaded, later interfering with the installation and byte-compilation of the new package, causing down the road.
This commit is contained in:
parent
3173b39b58
commit
eb9cb0c6e9
3 changed files with 87 additions and 61 deletions
1
bin/doom
1
bin/doom
|
@ -5,7 +5,6 @@
|
||||||
:; case "$_VERSION" in *\ 2[0-5].[0-9]) echo "Detected Emacs $_VERSION"; echo "Doom only supports Emacs 26.1 and newer"; echo; exit 2 ;; esac
|
:; case "$_VERSION" in *\ 2[0-5].[0-9]) echo "Detected Emacs $_VERSION"; echo "Doom only supports Emacs 26.1 and newer"; echo; exit 2 ;; esac
|
||||||
:; _DOOMBASE="${EMACSDIR:-$(dirname "$0")/..}"
|
:; _DOOMBASE="${EMACSDIR:-$(dirname "$0")/..}"
|
||||||
:; _DOOMPOST="$_DOOMBASE/.local/.doom.sh"
|
:; _DOOMPOST="$_DOOMBASE/.local/.doom.sh"
|
||||||
:; rm -f "$_DOOMPOST"
|
|
||||||
:; $EMACS --no-site-file --script "$0" -- "$@"
|
:; $EMACS --no-site-file --script "$0" -- "$@"
|
||||||
:; CODE=$?
|
:; CODE=$?
|
||||||
:; [ -x "$_DOOMPOST" ] && PATH="$_DOOMBASE/bin:$PATH" "$_DOOMPOST" "$0" "$@"
|
:; [ -x "$_DOOMPOST" ] && PATH="$_DOOMBASE/bin:$PATH" "$_DOOMPOST" "$0" "$@"
|
||||||
|
|
|
@ -169,23 +169,42 @@ COMMAND, and passes ARGS to it."
|
||||||
(doom--cli-process cli (remq nil args)))
|
(doom--cli-process cli (remq nil args)))
|
||||||
(user-error "Couldn't find any %S command" command)))
|
(user-error "Couldn't find any %S command" command)))
|
||||||
|
|
||||||
|
(defun doom-cli--execute-after (lines)
|
||||||
|
(let ((post-script (concat doom-local-dir ".doom.sh"))
|
||||||
|
(coding-system-for-write 'utf-8)
|
||||||
|
(coding-system-for-read 'utf-8))
|
||||||
|
(with-temp-file post-script
|
||||||
|
(insert "#!/usr/bin/env sh\n"
|
||||||
|
"[ -x \"$0\" ] && rm -f \"$0\"\n"
|
||||||
|
(save-match-data
|
||||||
|
(cl-loop for env in process-environment
|
||||||
|
if (string-match "^\\([^=]+\\)=\\(.+\\)$" env)
|
||||||
|
concat (format "%s=%S\n"
|
||||||
|
(match-string 1 env)
|
||||||
|
(match-string 2 env))))
|
||||||
|
"\n"
|
||||||
|
(if (stringp lines)
|
||||||
|
lines
|
||||||
|
(string-join
|
||||||
|
(if (listp (car-safe lines))
|
||||||
|
(cl-loop for line in (doom-enlist lines)
|
||||||
|
collect (mapconcat #'shell-quote-argument (remq nil line) " "))
|
||||||
|
(list (mapconcat #'shell-quote-argument (remq nil lines) " ")))
|
||||||
|
"\n"))
|
||||||
|
"\n"))
|
||||||
|
(set-file-modes post-script #o700)))
|
||||||
|
|
||||||
|
(defun doom-cli-execute-lines-after (&rest lines)
|
||||||
|
"TODO"
|
||||||
|
(doom-cli--execute-after (string-join lines "\n")))
|
||||||
|
|
||||||
(defun doom-cli-execute-after (&rest args)
|
(defun doom-cli-execute-after (&rest args)
|
||||||
"Execute shell command ARGS after this CLI session quits.
|
"Execute shell command ARGS after this CLI session quits.
|
||||||
|
|
||||||
This is particularly useful when the capabilities of Emacs' batch terminal are
|
This is particularly useful when the capabilities of Emacs' batch terminal are
|
||||||
insufficient (like opening an instance of Emacs, or reloading Doom after a 'doom
|
insufficient (like opening an instance of Emacs, or reloading Doom after a 'doom
|
||||||
upgrade')."
|
upgrade')."
|
||||||
(let ((post-script (concat doom-local-dir ".doom.sh")))
|
(doom-cli--execute-after args))
|
||||||
(with-temp-file post-script
|
|
||||||
(insert "#!/usr/bin/env sh\n"
|
|
||||||
"rm -f " (prin1-to-string post-script) "\n"
|
|
||||||
"exec " (mapconcat #'shell-quote-argument (remq nil args) " ")
|
|
||||||
"\n"))
|
|
||||||
(let* ((current-mode (file-modes post-script))
|
|
||||||
(add-mode (logand ?\111 (default-file-modes))))
|
|
||||||
(or (/= (logand ?\111 current-mode) 0)
|
|
||||||
(zerop add-mode)
|
|
||||||
(set-file-modes post-script (logior current-mode add-mode))))))
|
|
||||||
|
|
||||||
(defmacro defcli! (name speclist &optional docstring &rest body)
|
(defmacro defcli! (name speclist &optional docstring &rest body)
|
||||||
"Defines a CLI command.
|
"Defines a CLI command.
|
||||||
|
|
|
@ -18,55 +18,63 @@ byte-compiled from.")
|
||||||
"Tangles `+literate-config-file' if it has changed."
|
"Tangles `+literate-config-file' if it has changed."
|
||||||
(print! (start "Compiling your literate config..."))
|
(print! (start "Compiling your literate config..."))
|
||||||
(print-group!
|
(print-group!
|
||||||
(let* ((default-directory doom-private-dir)
|
(and (not (getenv "NOTANGLE"))
|
||||||
(org (expand-file-name +literate-config-file))
|
(require 'ox nil t)
|
||||||
(dest (concat (file-name-sans-extension +literate-config-file) ".el")))
|
(require 'ob-tangle nil t)
|
||||||
(and (require 'ox)
|
(letf! ((default-directory doom-private-dir)
|
||||||
(require 'ob-tangle)
|
(target +literate-config-file)
|
||||||
(letf! (;; Operate on a copy because `org-babel-tangle' has
|
(cache +literate-config-cache-file)
|
||||||
;; side-effects we need to undo immediately as not to
|
(dest (concat (file-name-sans-extension target) ".el"))
|
||||||
;; overwrite the user's config; it's bad ettiquite.
|
;; Operate on a copy because `org-babel-tangle' has
|
||||||
(backup (make-temp-file (concat (file-name-nondirectory org) ".")))
|
;; side-effects we need to undo immediately as not to
|
||||||
;; A hack to prevent ob-tangle from operating relative to the
|
;; overwrite the user's config; it's bad ettiquite.
|
||||||
;; backup file and thus tangling to the wrong destinations.
|
(backup (make-temp-file (concat (file-name-nondirectory target) ".")))
|
||||||
(defun org-babel-tangle-single-block (&rest args)
|
|
||||||
(let* ((spec (apply org-babel-tangle-single-block args))
|
;; HACK A hack to prevent ob-tangle from operating relative to
|
||||||
(file (nth 1 spec))
|
;; the backup file and thus tangling to the wrong
|
||||||
(file (if (file-equal-p file backup) org file))
|
;; destinations.
|
||||||
(file (if org-babel-tangle-use-relative-file-links
|
(defun org-babel-tangle-single-block (&rest args)
|
||||||
(file-relative-name file)
|
(let* ((spec (apply org-babel-tangle-single-block args))
|
||||||
file)))
|
(file (nth 1 spec))
|
||||||
(setf (nth 1 spec) file)
|
(file (if (file-equal-p file backup) target file))
|
||||||
spec))
|
(file (if org-babel-tangle-use-relative-file-links
|
||||||
;; Ensure output conforms to the formatting of all doom CLIs
|
(file-relative-name file)
|
||||||
(defun message (msg &rest args)
|
file)))
|
||||||
(when msg
|
(setf (nth 1 spec) file)
|
||||||
(print! (info "%s") (apply #'format msg args)))))
|
spec))
|
||||||
(unwind-protect
|
;; Ensure output conforms to the formatting of all doom CLIs
|
||||||
(with-temp-file backup
|
(defun message (msg &rest args)
|
||||||
(insert-file-contents org)
|
(when msg
|
||||||
(let ((buffer-file-name backup)
|
(print! (info "%s") (apply #'format msg args)))))
|
||||||
;; Prevent unwanted entries in recentf, or formatters, or
|
(unwind-protect
|
||||||
;; anything that could be on these hooks, really. Nothing
|
(with-temp-file backup
|
||||||
;; else should be touching these files (particularly in
|
(insert-file-contents file)
|
||||||
;; interactive sessions).
|
(let ((buffer-file-name backup)
|
||||||
(write-file-functions nil)
|
;; Prevent unwanted entries in recentf, or formatters, or
|
||||||
(before-save-hook nil)
|
;; anything that could be on these hooks, really. Nothing
|
||||||
(after-save-hook nil)
|
;; else should be touching these files (particularly in
|
||||||
;; Prevent infinite recursion due to recompile-on-save
|
;; interactive sessions).
|
||||||
;; hooks later, and speed up `org-mode' init.
|
(write-file-functions nil)
|
||||||
(org-mode-hook nil)
|
(before-save-hook nil)
|
||||||
(org-inhibit-startup t))
|
(after-save-hook nil)
|
||||||
(org-mode)
|
;; Prevent infinite recursion due to recompile-on-save
|
||||||
(with-silent-modifications
|
;; hooks later, and speed up `org-mode' init.
|
||||||
;; Tangling won't ordinarily expand #+INCLUDE directives,
|
(org-mode-hook nil)
|
||||||
;; so I do it myself.
|
(org-inhibit-startup t))
|
||||||
(org-export-expand-include-keyword)
|
(org-mode)
|
||||||
(org-babel-tangle nil dest))))
|
(with-silent-modifications
|
||||||
(ignore-errors (delete-file backup)))
|
;; Tangling won't ordinarily expand #+INCLUDE directives,
|
||||||
;; Write an empty file to serve as our mtime cache
|
;; so I do it myself.
|
||||||
(with-temp-file +literate-config-cache-file)
|
(org-export-expand-include-keyword)
|
||||||
t)))))
|
(org-babel-tangle nil dest))))
|
||||||
|
(ignore-errors (delete-file backup)))
|
||||||
|
;; Write an empty file to serve as our mtime cache
|
||||||
|
(with-temp-file cache)
|
||||||
|
(unless doom-interactive-p
|
||||||
|
(message "Restarting..." )
|
||||||
|
(doom-cli-execute-lines-after "NOTANGLE=1 \"$@\"")
|
||||||
|
(kill-emacs 0))
|
||||||
|
t))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(add-hook 'org-mode-hook #'+literate-enable-recompile-h)
|
(add-hook 'org-mode-hook #'+literate-enable-recompile-h)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue