dev: merging from master:

This commit is contained in:
Matt Nish-Lapidus 2024-09-07 22:24:35 -04:00
commit 30782f0cb3
58 changed files with 208 additions and 160 deletions

View file

@ -180,6 +180,14 @@ If set to nil, only display benchmark if a CLI explicitly requested with a
non-nil :benchmark property.
If set to `always', show the benchmark no matter what.")
(defvar doom-cli-shell
(pcase (getenv "__DOOMSH")
("ps1" 'pwsh)
(_ 'sh))
"What shell environment Doom has been started with.
Can be `pwsh' if invoked via bin/doom.ps1, or `sh' in unix environments.")
;;; Internal variables
(defvar doom-cli--context nil)
(defvar doom-cli--exit-code 255)
@ -1121,9 +1129,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"))
(shext (if (eq doom-cli-shell 'pwsh) "ps1" "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.%s") pid step shtype))
(script-file (format (doom-path temporary-file-directory "doom.%s.%s.%s") pid step shext))
(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))))
@ -1163,20 +1171,20 @@ 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
(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"
(pcase-exhaustive doom-cli-shell
(`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"))
(`pwsh `("try {\n"
,(cl-loop for (var . val) in persisted-env
concat (format " $__%s = $env:%s; $env:%s = %S\n "
var var var val))
@ -1286,7 +1294,7 @@ 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 ((equal (getenv "__DOOMSH") "ps1")
(cond ((eq doom-cli-shell 'pwsh)
;; Pager isn't supported in powershell
(doom-cli--exit 0 context))
@ -1322,16 +1330,18 @@ ARGS are options passed to less. If DOOMPAGER is set, ARGS are ignored."
ARGS are options passed to less. If DOOMPAGER is set, ARGS are ignored."
(doom-cli--exit
(let ((threshold (ceiling (* (doom-cli-context-height context)
doom-cli-pager-ratio))))
(if (>= (let ((stdout (doom-cli-context-stdout context)))
(if (fboundp 'buffer-line-statistics)
(car (buffer-line-statistics stdout))
(with-current-buffer stdout
(count-lines (point-min) (point-max)))))
threshold)
(cons :pager args)
0))
(if (eq doom-cli-shell 'pwsh)
0
(let ((threshold (ceiling (* (doom-cli-context-height context)
doom-cli-pager-ratio))))
(if (>= (let ((stdout (doom-cli-context-stdout context)))
(if (fboundp 'buffer-line-statistics)
(car (buffer-line-statistics stdout))
(with-current-buffer stdout
(count-lines (point-min) (point-max)))))
threshold)
(cons :pager args)
0)))
context))
;; (defun doom-cli--exit-editor (args context)) ; TODO Launch $EDITOR

View file

@ -73,6 +73,17 @@ and Emacs states, and for non-evil users.")
(key-binding (vconcat (cl-subseq keys 0 -1) [C-i]) nil t)))
[C-i] [?\C-i])))
;; HACK: Same as C-i, but C-m is a little harder. There is no workaround for
;; this for the terminal.
(define-key input-decode-map
[?\C-m] (cmd! (if (when-let ((keys (this-single-command-raw-keys)))
(and (display-graphic-p)
(not (cl-position 'return keys))
(not (cl-position 'kp-return keys))
;; Fall back if no <C-m> keybind can be found.
(key-binding (vconcat (cl-subseq keys 0 -1) [C-m]) nil t)))
[C-m] [?\C-m])))
;;
;;; Universal, non-nuclear escape

View file

@ -183,7 +183,7 @@ And if it's a function, evaluate it."
(put 'projectile-git-submodule-command 'initial-value projectile-git-submodule-command)
(setq projectile-git-submodule-command nil
;; Include and follow symlinks in file listings.
projectile-git-fd-args (concat "-L -tl " projectile-git-fd-args)
projectile-git-fd-args (concat "-tl " projectile-git-fd-args)
projectile-indexing-method 'hybrid
projectile-generic-command
(lambda (_)

View file

@ -270,7 +270,7 @@ These files should not be shared across systems. By default, it is used by
(defvar doom-data-dir
(if doom-profile
(if doom--system-windows-p
(expand-file-name "doomemacs/data/" (getenv-internal "APPDATA"))
(expand-file-name "doomemacs/data/" (getenv-internal "LOCALAPPDATA"))
(expand-file-name "doom/" (or (getenv-internal "XDG_DATA_HOME") "~/.local/share")))
;; DEPRECATED: .local will be removed entirely in 3.0
(file-name-concat doom-local-dir "etc/"))
@ -289,7 +289,7 @@ For profile-local data files, use `doom-profile-data-dir' instead.")
(defvar doom-cache-dir
(if doom-profile
(if doom--system-windows-p
(expand-file-name "doomemacs/cache/" (getenv-internal "APPDATA"))
(expand-file-name "doomemacs/cache/" (getenv-internal "LOCALAPPDATA"))
(expand-file-name "doom/" (or (getenv-internal "XDG_CACHE_HOME") "~/.cache")))
;; DEPRECATED: .local will be removed entirely in 3.0
(file-name-concat doom-local-dir "cache/"))
@ -308,7 +308,7 @@ For profile-local cache files, use `doom-profile-cache-dir' instead.")
(defvar doom-state-dir
(if doom-profile
(if doom--system-windows-p
(expand-file-name "doomemacs/state/" (getenv-internal "APPDATA"))
(expand-file-name "doomemacs/state/" (getenv-internal "LOCALAPPDATA"))
(expand-file-name "doom/" (or (getenv-internal "XDG_STATE_HOME") "~/.local/state")))
;; DEPRECATED: .local will be removed entirely in 3.0
(file-name-concat doom-local-dir "state/"))

View file

@ -91,12 +91,12 @@ If no project is active, return all buffers."
;;;###autoload
(defun doom-special-buffer-p (buf)
"Returns non-nil if BUF's name starts and ends with an *."
(equal (substring (buffer-name buf) 0 1) "*"))
(char-equal ?* (aref (buffer-name buf) 0)))
;;;###autoload
(defun doom-temp-buffer-p (buf)
"Returns non-nil if BUF is temporary."
(equal (substring (buffer-name buf) 0 1) " "))
(char-equal ?\s (aref (buffer-name buf) 0)))
;;;###autoload
(defun doom-visible-buffer-p (buf)
@ -111,12 +111,14 @@ If no project is active, return all buffers."
;;;###autoload
(defun doom-non-file-visiting-buffer-p (buf)
"Returns non-nil if BUF does not have a value for `buffer-file-name'."
(not (buffer-file-name buf)))
(not (buffer-file-name (or (buffer-base-buffer buf) buf))))
;;;###autoload
(defun doom-real-buffer-list (&optional buffer-list)
"Return a list of buffers that satisfy `doom-real-buffer-p'."
(cl-remove-if-not #'doom-real-buffer-p (or buffer-list (doom-buffer-list))))
(cl-loop for buf in (or buffer-list (doom-buffer-list))
if (doom-real-buffer-p buf)
collect buf))
;;;###autoload
(defun doom-real-buffer-p (buffer-or-name)
@ -160,15 +162,13 @@ See `doom-real-buffer-p' for details on what that means."
"Return a list of buffers whose `major-mode' is `eq' to MODE(S).
If DERIVED-P, test with `derived-mode-p', otherwise use `eq'."
(let ((modes (ensure-list modes)))
(cl-remove-if-not (if derived-p
(lambda (buf)
(apply #'provided-mode-derived-p
(buffer-local-value 'major-mode buf)
modes))
(lambda (buf)
(memq (buffer-local-value 'major-mode buf) modes)))
(or buffer-list (doom-buffer-list)))))
(cl-loop with modes = (ensure-list modes)
for buf in (or buffer-list (doom-buffer-list))
for mode = (buffer-local-value 'major-mode buf)
if (if derived-p
(apply #'provided-mode-derived-p mode modes)
(memq mode modes))
collect buf))
;;;###autoload
(defun doom-visible-windows (&optional window-list)
@ -187,20 +187,23 @@ If DERIVED-P, test with `derived-mode-p', otherwise use `eq'."
if (window-list frame)
nconc (mapcar #'window-buffer it)))))
(if buffer-list
(cl-delete-if (lambda (b) (memq b buffer-list))
buffers)
(delete-dups buffers))))
(cl-loop for buf in buffers
unless (memq buf buffer-list)
collect buffers)
buffers)))
;;;###autoload
(defun doom-buried-buffers (&optional buffer-list)
"Get a list of buffers that are buried."
(cl-remove-if #'get-buffer-window (or buffer-list (doom-buffer-list))))
(cl-loop for buf in (or buffer-list (doom-buffer-list))
unless (doom-visible-buffer-p buf)
collect buf))
;;;###autoload
(defun doom-matching-buffers (pattern &optional buffer-list)
"Get a list of all buffers that match the regex PATTERN."
(cl-loop for buf in (or buffer-list (doom-buffer-list))
when (string-match-p pattern (buffer-name buf))
if (string-match-p pattern (buffer-name buf))
collect buf))
;;;###autoload

View file

@ -78,8 +78,8 @@ And jumps to your `doom!' block."
(format "%s sync -B -e"
;; /usr/bin/env doesn't exist on Android
(if (featurep :system 'android)
"sh %%s"
"%%s"))
"sh %s"
"%s"))
"Command that `doom/reload' runs.")
;;;###autoload
(defun doom/reload ()
@ -147,8 +147,8 @@ imported into Emacs."
(format "%s upgrade -B --force"
;; /usr/bin/env doesn't exist on Android
(if (featurep :system 'android)
"sh %%s"
"%%s"))
"sh %s"
"%s"))
"Command that `doom/upgrade' runs.")
;;;###autoload
(defun doom/upgrade ()

View file

@ -45,6 +45,7 @@ This is used by `file-exists-p!' and `project-file-exists-p!'."
Ignores `nil' elements in SEGMENTS, and is intended as a fast compromise between
`expand-file-name' (slow, but accurate), `file-name-concat' (fast, but
inaccurate)."
(declare (side-effect-free t))
;; PERF: An empty `file-name-handler-alist' = faster `expand-file-name'.
(let (file-name-handler-alist)
(expand-file-name
@ -69,7 +70,9 @@ If the glob ends in a slash, only returns matching directories."
file-name-handler-alist
(path (apply #'file-name-concat segments)))
(if (string-suffix-p "/" path)
(cl-delete-if-not #'file-directory-p (file-expand-wildcards (substring path 0 -1)))
(cl-loop for file in (file-expand-wildcards (substring path 0 -1))
if (file-directory-p file)
collect file)
(file-expand-wildcards path))))
;;;###autoload