Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aaronjensen/0ec335a4802b40d16dc02a17259f6848 to your computer and use it in GitHub Desktop.

Select an option

Save aaronjensen/0ec335a4802b40d16dc02a17259f6848 to your computer and use it in GitHub Desktop.
Ghostel deprioritization
(defvar c/ghostel-taskpolicy-command
(when-let ((taskpolicy (and (eq system-type 'darwin)
(executable-find "taskpolicy"))))
(list taskpolicy "-c" "utility"))
"Command prefix used to start Ghostel shells with lower macOS priority.")
(defun c/ghostel--make-process-with-taskpolicy (make-process &rest args)
"Apply `c/ghostel-taskpolicy-command' to Ghostel's spawned shell."
(let ((command (plist-get args :command)))
(when (and c/ghostel-taskpolicy-command
(equal (plist-get args :name) "ghostel")
(listp command)
(not (equal (car command) (car c/ghostel-taskpolicy-command))))
(setq args (plist-put args :command
(append c/ghostel-taskpolicy-command command))))
(apply make-process args)))
(defun c/ghostel--spawn-pty-with-taskpolicy (spawn-pty &rest args)
"Start Ghostel processes under macOS background scheduling policy."
(let ((real-make-process (symbol-function 'make-process)))
(cl-letf (((symbol-function 'make-process)
(lambda (&rest plist)
(apply #'c/ghostel--make-process-with-taskpolicy
real-make-process plist))))
(apply spawn-pty args))))
;; Reduces priority of ghostel so that the rest of Emacs is responsive, even
;; when running tests in several projects - Aaron, Wed May 27 2026
(advice-add #'ghostel--spawn-pty :around #'c/ghostel--spawn-pty-with-taskpolicy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment