From 79684ade71dd573f8d90c85edc8a9091f51fbfba Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 6 Sep 2024 04:01:40 -0400 Subject: [PATCH 1/8] fix(latex): run after-compilation-finished hook after Tex-Tex-sentinel Fix: #8051 --- modules/lang/latex/config.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/lang/latex/config.el b/modules/lang/latex/config.el index ff31b6196..ec69af6e5 100644 --- a/modules/lang/latex/config.el +++ b/modules/lang/latex/config.el @@ -128,7 +128,18 @@ If no viewer is found, `latex-preview-pane-mode' is used.") :desc "View" "v" #'TeX-view :desc "Compile" "c" #'+latex/compile :desc "Run all" "a" #'TeX-command-run-all - :desc "Run a command" "m" #'TeX-command-master)) + :desc "Run a command" "m" #'TeX-command-master) + + ;; HACK: The standard LaTeXMk command uses `TeX-run-format', which doesn't + ;; trigger `TeX-after-compilation-finished-functions', so swap it out for + ;; `TeX-run-TeX', which does. + (defadvice! +latex--run-after-compilation-finished-functions-a (&rest args) + :after #'TeX-TeX-sentinel + (unless (TeX-error-report-has-errors-p) + (run-hook-with-args 'TeX-after-compilation-finished-functions + (with-current-buffer TeX-command-buffer + (expand-file-name + (TeX-active-master (TeX-output-extension)))))))) (use-package! tex-fold From e0a926dc1ec9e1fa66f31751d33b3e4f41b6801a Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 6 Sep 2024 16:15:57 -0400 Subject: [PATCH 2/8] tweak(indent-guides): default to character method The bitmap method is slower and not that different, visually, from the character method. Fix: #8052 Co-authored-by: nightkr --- modules/ui/indent-guides/config.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ui/indent-guides/config.el b/modules/ui/indent-guides/config.el index 58b43ea16..9312f0ad7 100644 --- a/modules/ui/indent-guides/config.el +++ b/modules/ui/indent-guides/config.el @@ -16,7 +16,7 @@ non-nil, the mode will not be activated." (use-package! highlight-indent-guides :hook ((prog-mode text-mode conf-mode) . +indent-guides-init-maybe-h) :init - (setq highlight-indent-guides-method (if (display-graphic-p) 'bitmap 'character) + (setq highlight-indent-guides-method 'character highlight-indent-guides-bitmap-function #'highlight-indent-guides--bitmap-line) (defun +indent-guides-init-maybe-h () From 9753bfb775d04cedaa955a92b3e2256ceb28b0cc Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 6 Sep 2024 16:17:07 -0400 Subject: [PATCH 3/8] fix: {back,fore}ground-color in subsequent frames New frames created after the first get initialized with #000000 as their {back,fore}ground-color parameters, for some reason, making text unreadable in dark themes. --- lisp/doom-ui.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/doom-ui.el b/lisp/doom-ui.el index 847f5301f..1d0e5978c 100644 --- a/lisp/doom-ui.el +++ b/lisp/doom-ui.el @@ -589,7 +589,9 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original (setq doom-theme theme) (put 'doom-theme 'previous-themes (or last-themes 'none)) ;; DEPRECATED Hook into `enable-theme-functions' when we target 29 - (doom-run-hooks 'doom-load-theme-hook)))))) + (doom-run-hooks 'doom-load-theme-hook) + (setf (alist-get 'foreground-color default-frame-alist) (face-foreground 'default nil t) + (alist-get 'background-color default-frame-alist) (face-background 'default nil t))))))) ;; From 8d2cf32fef9a82e1b929dc22adec3235181d7b54 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 7 Sep 2024 00:41:16 -0400 Subject: [PATCH 4/8] feat(cli): add doom.ps1 for Windows users c9acdb7 removes doom.cmd because it was broken in most cases. This adds doom.ps1; an alternative script for Windows+Powershell users, which properly initializes the state it needs. Naturally, it requires Powershell 3+ be installed on your systems, but it can be invoked from either cmd.exe or PowerShell.exe. This is the first powershell script I've ever written, so I expect edge cases (for one, shell commands passed to `exit!` will need to be guarded against the environment). This also requires emacs.exe be your $PATH, however, unless you set $EMACS to its path first. E.g. $env:EMACS = "C:\Program Files\Emacs\emacs-29.4\bin\emacs.exe" That said, if you use WSL2, you're still far better off using the bash script (bin/doom). Ref: c9acdb72a4bd --- bin/doom.ps1 | 38 +++++++++++++++++++++++++++ bin/doomscript | 1 + lisp/doom-cli-lib.el | 61 +++++++++++++++++++++++++++++--------------- 3 files changed, 80 insertions(+), 20 deletions(-) create mode 100644 bin/doom.ps1 diff --git a/bin/doom.ps1 b/bin/doom.ps1 new file mode 100644 index 000000000..be190b2f8 --- /dev/null +++ b/bin/doom.ps1 @@ -0,0 +1,38 @@ +# bin/doom.ps1 + +if (!(Get-Command -Erroraction silentlycontinue emacs.exe)) { + echo "Couldn't find emacs.exe in your $PATH." + exit 1 +} + +$doom = "$PSScriptRoot/doom" +$emacs = if ($env:EMACS) { $env:EMACS } else { (Get-Command emacs.exe).Path } +$emacsargs = "-q", "--no-site-file", "--batch" +$oldemacsdir = $env:EMACSDIR + +try { + $env:EMACSDIR = if (-not $env:EMACSDIR) { (get-item $PSScriptRoot).parent.FullName } else { $env:EMACSDIR } + $env:__DOOMSH = if (-not $env:__DOOMSH) { "ps1" } else { $env:__DOOMSH } + $env:__DOOMPID = if (-not $env:__DOOMPID) { $PID } else { $env:__DOOMPID } + $env:__DOOMSTEP = if (-not $env:__DOOMSTEP) { 0 } else { $env:__DOOMSTEP } + $cols = (Get-Host).UI.RawUI.WindowSize.Width + $lines = (Get-Host).UI.RawUI.WindowSize.Height + $env:__DOOMGEOM = if (-not $env:__DOOMGEOM) { "$cols`x$lines" } else { $env:__DOOMGEOM } + # $env:__DOOMGPIPE = if (-not $env:__DOOMGPIPE) { $env:__DOOMPIPE } else { $env:__DOOMGPIPE } + # $env:__DOOMPIPE = "" + + & $emacs $emacsargs --load "$doom" -- --no-color $args + $exit = $LASTEXITCODE +} finally { + $env:EMACSDIR = $oldemacsdir + Remove-Item Env:\__DOOMSH + Remove-Item Env:\__DOOMPID + Remove-Item Env:\__DOOMSTEP + Remove-Item Env:\__DOOMGEOM +} + +if ($exit -eq 254) { + & pwsh "$env:TMPDIR\doom.$($env:__DOOMPID).$($env:__DOOMSTEP).ps1" $PSCommandPath $args + $exit = $LASTEXITCODE +} +exit $exit diff --git a/bin/doomscript b/bin/doomscript index 490dbeb7d..2017a4c23 100755 --- a/bin/doomscript +++ b/bin/doomscript @@ -57,6 +57,7 @@ if [ ! -f "$EMACSDIR/early-init.el" ]; then fi >&2 # Some state that Doom's CLI framework needs to know about the terminal. Read # the comments at the top of bin/doom for explanations. +export __DOOMSH="${__DOOMSH:-sh}" export __DOOMPID="${__DOOMPID:-$$}" export __DOOMSTEP="${__DOOMSTEP:-0}" export __DOOMGEOM="${__DOOMGEOM:-$(tput cols 2>/dev/null)x$(tput lines 2>/dev/null)}" diff --git a/lisp/doom-cli-lib.el b/lisp/doom-cli-lib.el index 4cf8e44f5..55a62918f 100644 --- a/lisp/doom-cli-lib.el +++ b/lisp/doom-cli-lib.el @@ -1121,8 +1121,9 @@ Emacs' batch library lacks an implementation of the exec system call." (error "__DOOMSTEP envvar missing; extended `exit!' functionality will not work")) (let* ((pid (doom-cli-context-pid context)) (step (doom-cli-context-step context)) + (shtype (or (getenv "__DOOMSH") "sh")) (context-file (format (doom-path temporary-file-directory "doom.%s.%s.context") pid step)) - (script-file (format (doom-path temporary-file-directory "doom.%s.%s.sh") pid step)) + (script-file (format (doom-path temporary-file-directory "doom.%s.%s.%s") pid step shtype)) (command (if (listp args) (combine-and-quote-strings (remq nil args)) args)) (persistent-files (combine-and-quote-strings (delq nil (list script-file context-file)))) @@ -1154,24 +1155,40 @@ Emacs' batch library lacks an implementation of the exec system call." newcontext)) (doom-log "restart: writing post-script to %s" script-file) (doom-file-write - script-file `("#!/usr/bin/env sh\n" - "trap _doomcleanup EXIT\n" - "_doomcleanup() {\n rm -f " ,persistent-files "\n}\n" - "_doomrun() {\n " ,command "\n}\n" - ,(string-join persisted-env " \\\n") - ,(cl-loop for (envvar . val) - in `(("DOOMPROFILE" . ,(ignore-errors (doom-profile->id doom-profile))) - ("EMACSDIR" . ,doom-emacs-dir) - ("DOOMDIR" . ,doom-user-dir) - ("DEBUG" . ,(if init-file-debug "1")) - ("__DOOMSTEP" . ,(number-to-string (doom-cli-context-step context))) - ("__DOOMCONTEXT" . ,context-file)) - if val - concat (format "%s=%s \\\n" envvar (shell-quote-argument val))) - ,(format "PATH=\"%s%s$PATH\" \\\n" - (doom-path doom-emacs-dir "bin") - path-separator) - "_doomrun \"$@\"\n"))) + script-file + (let ((envvars `(("DOOMPROFILE" . ,(ignore-errors (doom-profile->id doom-profile))) + ("EMACSDIR" . ,doom-emacs-dir) + ("DOOMDIR" . ,doom-user-dir) + ("DEBUG" . ,(if init-file-debug "1")) + ("__DOOMPID" . ,(number-to-string (doom-cli-context-pid context))) + ("__DOOMSTEP" . ,(number-to-string (doom-cli-context-step context))) + ("__DOOMGEOM" . ,(number-to-string (doom-cli-context-step context))) + ("__DOOMCONTEXT" . ,context-file)))) + (pcase-exhaustive shtype + ("sh" `("#!/usr/bin/env sh\n" + "trap _doomcleanup EXIT\n" + "_doomcleanup() {\n rm -f " ,persistent-files "\n}\n" + "_doomrun() {\n " ,command "\n}\n" + ,(string-join persisted-env " \\\n") + ,(cl-loop for (envvar . val) in envvars + if val + concat (format "%s=%s \\\n" envvar (shell-quote-argument val))) + ,(format "PATH=\"%s%s$PATH\" \\\n" + (doom-path doom-emacs-dir "bin") + path-separator) + "_doomrun \"$@\"\n")) + ("ps1" `("try {\n" + ,(cl-loop for (envvar . val) in envvars + if val + concat (format " $__%s = $env:%s; $env:%s = %s\\\n " envvar envvar envvar (shell-quote-argument val))) + ,command + "\n} finally {\n" + ,(cl-loop for file in persistent-files + concat (format " Remote-Item -Path %S\n " file)) + ,(cl-loop for (envvar . val) in envvars + if val + concat (format " $env:%s = $__%s\\\n " envvar envvar)) + "\n}")))))) (doom-log "_doomrun: %s %s" (string-join persisted-env " ") command) (doom-log "_doomcleanup: %s" persistent-files) ;; Error code 254 is special: it indicates to the caller that the @@ -1268,7 +1285,11 @@ Arguments don't have to be switches either." ARGS are options passed to less. If DOOMPAGER is set, ARGS are ignored." (let ((pager (or doom-cli-pager (getenv "DOOMPAGER")))) - (cond ((null (or pager (executable-find "less"))) + (cond ((equal (getenv "__DOOMSH") "ps1") + ;; Pager isn't supported in powershell + (doom-cli--exit 0 context)) + + ((null (or pager (executable-find "less"))) (user-error "No pager set or available") (doom-cli--exit 1 context)) From f644c4fa6c23ba2820f102d74318b0f721b070a0 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 7 Sep 2024 00:53:20 -0400 Subject: [PATCH 5/8] feat: add basic android support --- lisp/doom-cli-lib.el | 4 +++- lisp/doom.el | 3 ++- lisp/lib/config.el | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lisp/doom-cli-lib.el b/lisp/doom-cli-lib.el index 55a62918f..a2d7b9507 100644 --- a/lisp/doom-cli-lib.el +++ b/lisp/doom-cli-lib.el @@ -1165,7 +1165,9 @@ Emacs' batch library lacks an implementation of the exec system call." ("__DOOMGEOM" . ,(number-to-string (doom-cli-context-step context))) ("__DOOMCONTEXT" . ,context-file)))) (pcase-exhaustive shtype - ("sh" `("#!/usr/bin/env sh\n" + ("sh" `(,(if (featurep :system 'android) + "#!/bin/sh\n" + "#!/usr/bin/env sh\n") "trap _doomcleanup EXIT\n" "_doomcleanup() {\n rm -f " ,persistent-files "\n}\n" "_doomrun() {\n " ,command "\n}\n" diff --git a/lisp/doom.el b/lisp/doom.el index 149f010ae..247877af9 100644 --- a/lisp/doom.el +++ b/lisp/doom.el @@ -121,7 +121,8 @@ ('darwin '(macos bsd)) ((or 'cygwin 'windows-nt 'ms-dos) '(windows)) ((or 'gnu 'gnu/linux) '(linux)) - ((or 'gnu/kfreebsd 'berkeley-unix) '(linux bsd))) + ((or 'gnu/kfreebsd 'berkeley-unix) '(linux bsd)) + ('android '(android))) "A list of symbols denoting available features in the active Doom profile.") ;; Convenience aliases for internal use only (may be removed later). diff --git a/lisp/lib/config.el b/lisp/lib/config.el index c92d4a791..df319472b 100644 --- a/lisp/lib/config.el +++ b/lisp/lib/config.el @@ -74,7 +74,12 @@ And jumps to your `doom!' block." ,on-failure)) nil 'local)))))) -(defvar doom-reload-command "%s sync -B -e" +(defvar doom-reload-command + (format "%s sync -B -e" + ;; /usr/bin/env doesn't exist on Android + (if (featurep :system 'android) + "sh %%s" + "%%s")) "Command that `doom/reload' runs.") ;;;###autoload (defun doom/reload () @@ -138,7 +143,12 @@ imported into Emacs." (doom-load-envvars-file doom-env-file) (message "Reloaded %S" (abbreviate-file-name doom-env-file)))))) -(defvar doom-upgrade-command "%s upgrade -B --force" +(defvar doom-upgrade-command + (format "%s upgrade -B --force" + ;; /usr/bin/env doesn't exist on Android + (if (featurep :system 'android) + "sh %%s" + "%%s")) "Command that `doom/upgrade' runs.") ;;;###autoload (defun doom/upgrade () From 61dc1da645b452943097c6b9dbbdb7eca2e7c469 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 7 Sep 2024 01:20:37 -0400 Subject: [PATCH 6/8] fix(cli): doom.ps1: interpolated variable in error message --- bin/doom.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/doom.ps1 b/bin/doom.ps1 index be190b2f8..b66f95526 100644 --- a/bin/doom.ps1 +++ b/bin/doom.ps1 @@ -1,7 +1,7 @@ # bin/doom.ps1 if (!(Get-Command -Erroraction silentlycontinue emacs.exe)) { - echo "Couldn't find emacs.exe in your $PATH." + echo "Couldn't find emacs.exe in your PATH." exit 1 } From 4c7aec35bac6ff77ab70337ba1b748638d9dd9be Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 7 Sep 2024 02:27:56 -0400 Subject: [PATCH 7/8] fix(cli): envvar injection into bin/doom post-script --- lisp/doom-cli-lib.el | 85 ++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/lisp/doom-cli-lib.el b/lisp/doom-cli-lib.el index a2d7b9507..8be29df1e 100644 --- a/lisp/doom-cli-lib.el +++ b/lisp/doom-cli-lib.el @@ -1128,13 +1128,20 @@ Emacs' batch library lacks an implementation of the exec system call." (persistent-files (combine-and-quote-strings (delq nil (list script-file context-file)))) (persisted-env - (save-match-data - (cl-loop with initial-env = (get 'process-environment 'initial-value) - for env in (seq-difference process-environment initial-env) - if (string-match "^\\([a-zA-Z0-9_][^=]+\\)=\\(.+\\)$" env) - collect (format "%s=%s" - (match-string 1 env) - (shell-quote-argument (match-string 2 env))))))) + (cl-remove-if-not + #'cdr (append + `(("DOOMPROFILE" . ,(ignore-errors (doom-profile->id doom-profile))) + ("EMACSDIR" . ,doom-emacs-dir) + ("DOOMDIR" . ,doom-user-dir) + ("DEBUG" . ,(if init-file-debug "1")) + ("__DOOMPID" . ,(number-to-string (doom-cli-context-pid context))) + ("__DOOMSTEP" . ,(number-to-string (doom-cli-context-step context))) + ("__DOOMCONTEXT" . ,context-file)) + (save-match-data + (cl-loop with initial-env = (get 'process-environment 'initial-value) + for env in (seq-difference process-environment initial-env) + if (string-match "^\\([a-zA-Z0-9_][^=]+\\)=\\(.+\\)$" env) + collect (cons (match-string 1 env) (match-string 2 env)))))))) (cl-incf (doom-cli-context-step context)) (with-file-modes #o600 (doom-log "restart: writing context to %s" context-file) @@ -1156,42 +1163,34 @@ Emacs' batch library lacks an implementation of the exec system call." (doom-log "restart: writing post-script to %s" script-file) (doom-file-write script-file - (let ((envvars `(("DOOMPROFILE" . ,(ignore-errors (doom-profile->id doom-profile))) - ("EMACSDIR" . ,doom-emacs-dir) - ("DOOMDIR" . ,doom-user-dir) - ("DEBUG" . ,(if init-file-debug "1")) - ("__DOOMPID" . ,(number-to-string (doom-cli-context-pid context))) - ("__DOOMSTEP" . ,(number-to-string (doom-cli-context-step context))) - ("__DOOMGEOM" . ,(number-to-string (doom-cli-context-step context))) - ("__DOOMCONTEXT" . ,context-file)))) - (pcase-exhaustive shtype - ("sh" `(,(if (featurep :system 'android) - "#!/bin/sh\n" - "#!/usr/bin/env sh\n") - "trap _doomcleanup EXIT\n" - "_doomcleanup() {\n rm -f " ,persistent-files "\n}\n" - "_doomrun() {\n " ,command "\n}\n" - ,(string-join persisted-env " \\\n") - ,(cl-loop for (envvar . val) in envvars - if val - concat (format "%s=%s \\\n" envvar (shell-quote-argument val))) - ,(format "PATH=\"%s%s$PATH\" \\\n" - (doom-path doom-emacs-dir "bin") - path-separator) - "_doomrun \"$@\"\n")) - ("ps1" `("try {\n" - ,(cl-loop for (envvar . val) in envvars - if val - concat (format " $__%s = $env:%s; $env:%s = %s\\\n " envvar envvar envvar (shell-quote-argument val))) - ,command - "\n} finally {\n" - ,(cl-loop for file in persistent-files - concat (format " Remote-Item -Path %S\n " file)) - ,(cl-loop for (envvar . val) in envvars - if val - concat (format " $env:%s = $__%s\\\n " envvar envvar)) - "\n}")))))) - (doom-log "_doomrun: %s %s" (string-join persisted-env " ") command) + (pcase-exhaustive shtype + ("sh" `(,(if (featurep :system 'android) + "#!/bin/sh\n" + "#!/usr/bin/env sh\n") + "trap _doomcleanup EXIT\n" + "_doomcleanup() {\n rm -f " ,persistent-files "\n}\n" + "_doomrun() {\n " ,command "\n}\n" + ,(cl-loop for (var . val) in persisted-env + concat (format "%s=%s \\\n" var (shell-quote-argument val))) + ,(format "PATH=\"%s%s$PATH\" \\\n" + (doom-path doom-emacs-dir "bin") + path-separator) + "_doomrun \"$@\"\n")) + ("ps1" `("try {\n" + ,(cl-loop for (var . val) in persisted-env + concat (format " $__%s = $env:%s; $env:%s = %S\n " + var var var val)) + ,command + "\n} finally {\n" + ,(cl-loop for file in persistent-files + concat (format " Remove-Item -Path %S\n " file)) + ,(cl-loop for (var . val) in envvars + concat (format " $env:%s = $__%s\n " var var)) + "\n}"))))) + (doom-log "_doomrun: %s %s" + (cl-loop for (var . val) in persisted-env + concat (format "%s=%s \\\n" var (shell-quote-argument val))) + command) (doom-log "_doomcleanup: %s" persistent-files) ;; Error code 254 is special: it indicates to the caller that the ;; post-script should be executed after this session ends. It's up to From 94a291a7f8f3425a33a8326077cfb0c9964f1631 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 7 Sep 2024 02:51:12 -0400 Subject: [PATCH 8/8] fix(cli): doom.ps1: path to post-script --- bin/doom.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/doom.ps1 b/bin/doom.ps1 index b66f95526..a8f77646b 100644 --- a/bin/doom.ps1 +++ b/bin/doom.ps1 @@ -32,7 +32,7 @@ try { } if ($exit -eq 254) { - & pwsh "$env:TMPDIR\doom.$($env:__DOOMPID).$($env:__DOOMSTEP).ps1" $PSCommandPath $args + & pwsh "$($env:temp)\doom.$($env:__DOOMPID).$($env:__DOOMSTEP).ps1" $PSCommandPath $args $exit = $LASTEXITCODE } exit $exit