refactor: deprecate EMACS2[89]+, NATIVECOMP, MODULES

To reduce redundancy, remove the maintenance hassle that version
constants would impose later on, and rely on built-in
facilities (featurep) more over global variables or doomisms, these
global constants have been deprecated in favor of Emacs "features":

- EMACS28+   -- replace with (> emacs-major-version 27)
- EMACS29+   -- replace with (> emacs-major-version 28)
- NATIVECOMP -- replace with (featurep 'native-compile)
- MODULES    -- replace with (featurep 'dynamic-modules)

(These constants will be formally removed when v3 is released. The IS-*
constants are likely next, but I haven't decided on their substitutes
yet)

I also decided to follow native-compile's example and provide features
for Emacs' system features (since system-configuration-features' docs
outs itself as a poor method to detect features):

- dynamic-modules
- jansson
- native-compile -- this one already exists, but will instead be removed
  if it's non-functional; i.e. (native-comp-available-p) returns nil.

These are now detectable using featurep, which is fast and built-in.
This commit is contained in:
Henrik Lissner 2022-08-12 20:07:08 +02:00
parent c540f1b515
commit 0407621aff
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
12 changed files with 54 additions and 35 deletions

View file

@ -67,7 +67,7 @@ in."
"\t- might depend subtly on upstream packages updates.\n"
"You might need to unpin packages to get a fix for a specific commit of Emacs, "
"and you should be ready to downgrade Emacs if something is just not fixable."))
(EMACS29+
((> emacs-major-version 28)
(warn! "Emacs %s detected" emacs-version)
(explain! "Doom supports this version, but you are living on the edge! "
"Be prepared for breakages in future versions of Emacs."))
@ -108,13 +108,12 @@ in."
"jansson support (i.e. a native JSON library), particularly LSP users. "
"You must install a prebuilt Emacs binary with this included, or compile "
"Emacs with the --with-json option."))
(when EMACS28+
(unless NATIVECOMP
(warn! "Emacs was not built with native compilation support")
(explain! "Users will see a substantial performance gain by building Emacs with "
"native compilation support, availible in emacs 28+."
"You must install a prebuilt Emacs binary with this included, or compile "
"Emacs with the --with-native-compilation option.")))
(unless (featurep 'native-compile)
(warn! "Emacs was not built with native compilation support")
(explain! "Users will see a substantial performance gain by building Emacs with "
"native compilation support, availible in emacs 28+."
"You must install a prebuilt Emacs binary with this included, or compile "
"Emacs with the --with-native-compilation option."))
(print! (start "Checking for private config conflicts..."))
(let* ((xdg-dir (concat (or (getenv "XDG_CONFIG_HOME")

View file

@ -240,7 +240,7 @@ list remains lean."
(defun doom-packages--write-missing-eln-errors ()
"Write .error files for any expected .eln files that are missing."
(when NATIVECOMP
(when (featurep 'native-compile)
(cl-loop for file in doom-packages--eln-output-expected
for eln-name = (doom-packages--eln-file-name file)
for eln-file = (doom-packages--eln-output-file eln-name)
@ -254,7 +254,7 @@ list remains lean."
(defun doom-packages--compile-site-files ()
"Queue async compilation for all non-doom Elisp files."
(when NATIVECOMP
(when (featurep 'native-compile)
(cl-loop with paths = (cl-loop for path in load-path
unless (file-in-directory-p path doom-local-dir)
collect path)
@ -301,7 +301,7 @@ declaration) or dependency thereof that hasn't already been."
(signal 'doom-package-error (list package e))))))
(progn
(doom-packages--compile-site-files)
(when NATIVECOMP
(when (featurep 'native-compile)
(doom-packages--wait-for-native-compile-jobs)
(doom-packages--write-missing-eln-errors))
(print! (success "\033[KInstalled %d packages") (length built)))
@ -348,7 +348,7 @@ declaration) or dependency thereof that hasn't already been."
(and (eq (car-safe build) :not)
(setq want-byte-compile (not want-byte-compile)
want-native-compile (not want-native-compile)))
(unless NATIVECOMP
(unless (featurep 'native-compile)
(setq want-native-compile nil))
(and (or want-byte-compile want-native-compile)
(or (file-newer-than-file-p repo-dir build-dir)
@ -365,7 +365,7 @@ declaration) or dependency thereof that hasn't already been."
(straight-use-package (intern package))))
(progn
(doom-packages--compile-site-files)
(when NATIVECOMP
(when (featurep 'native-compile)
(doom-packages--wait-for-native-compile-jobs)
(doom-packages--write-missing-eln-errors))
;; HACK Every time you save a file in a package that straight tracks,
@ -659,7 +659,7 @@ If ELPA-P, include packages installed with package.el (M-x package-install)."
(if (not regraft-repos-p)
(ignore (print! (item "Skipping regrafting")))
(doom-packages--regraft-repos repos-to-regraft))
(when NATIVECOMP
(when (featurep 'native-compile)
(if (not eln-p)
(ignore (print! (item "Skipping native bytecode")))
(doom-packages--purge-eln))))))))

View file

@ -561,7 +561,7 @@ files, so this replace calls to `pp' with the much faster `prin1'."
(lambda (button)
(helpful-variable (button-get button 'apropos-symbol))))))
(when EMACS29+
(when (> emacs-major-version 28)
;; REVIEW This should be reported upstream to Emacs.
(defadvice! doom--find-function-search-for-symbol-save-excursion-a (fn &rest args)
"Suppress cursor movement by `find-function-search-for-symbol'.
@ -669,7 +669,7 @@ on."
;; Emacs 29 introduced faster long-line detection, so they can afford a much
;; larger `so-long-threshold' and its default `so-long-predicate'.
(if (fboundp 'buffer-line-statistics)
(unless NATIVECOMP
(unless (featurep 'native-compile)
(setq so-long-threshold 5000))
;; reduce false positives w/ larger threshold
(setq so-long-threshold 400)

View file

@ -110,7 +110,7 @@ uses a straight or package.el command directly).")
;;
;;; native-comp
(when NATIVECOMP
(when (featurep 'native-compile)
(after! comp
;; HACK Disable native-compilation for some troublesome packages
(mapc (doom-partial #'add-to-list 'native-comp-deferred-compilation-deny-list)

View file

@ -307,7 +307,7 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
(setq resize-mini-windows 'grow-only)
;; Typing yes/no is obnoxious when y/n will do
(if EMACS28+
(if (boundp 'use-short-answers)
(setq use-short-answers t)
;; DEPRECATED Remove when we drop 27.x support
(advice-add #'yes-or-no-p :override #'y-or-n-p))
@ -513,7 +513,7 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
;; Fix #2742: cursor is off by 4 characters in `artist-mode'
;; REVIEW Reported upstream https://debbugs.gnu.org/cgi/bugreport.cgi?bug=43811
;; DEPRECATED Fixed in Emacs 28; remove when we drop 27 support
(unless EMACS28+
(unless (> emacs-major-version 27)
(add-hook 'artist-mode-hook #'doom-disable-line-numbers-h))

View file

@ -77,17 +77,37 @@
;;
;;; Global constants
;; Emacs features
(defconst EMACS28+ (> emacs-major-version 27))
(defconst EMACS29+ (> emacs-major-version 28))
(defconst MODULES (bound-and-true-p module-file-suffix))
(defconst NATIVECOMP (if (fboundp 'native-comp-available-p) (native-comp-available-p)))
;; Operating system
;; DEPRECATED
(defconst IS-MAC (eq system-type 'darwin))
(defconst IS-LINUX (eq system-type 'gnu/linux))
(defconst IS-WINDOWS (memq system-type '(cygwin windows-nt ms-dos)))
(defconst IS-BSD (or IS-MAC (eq system-type 'berkeley-unix)))
(defconst IS-BSD (memq system-type '(darwin berkeley-unix gnu/kfreebsd)))
(unless (featurep 'doom)
;; Since `system-configuration-features's docs state not to rely on it to test
;; for features, let's give users an easier way to detect them.
(if (bound-and-true-p module-file-suffix)
(push 'dynamic-modules features))
(if (fboundp #'json-parse-string)
(push 'jansson features))
;; `native-compile' exists whether or not it is functional (e.g. libgcc is
;; available or not). This seems silly, so pretend it doesn't exist if it
;; isn't available.
(if (featurep 'native-compile)
(if (not (native-comp-available-p))
(delq 'native-compile features)))
;; DEPRECATED remove in v3
(defconst EMACS28+ (> emacs-major-version 27))
(defconst EMACS29+ (> emacs-major-version 28))
;; DEPRECATED remove in v3
(defconst MODULES (featurep 'dynamic-modules))
(defconst NATIVECOMP (featurep 'native-compile))
(make-obsolete-variable 'EMACS28+ "Use (>= emacs-major-version 28) instead" "3.0.0")
(make-obsolete-variable 'EMACS29+ "Use (>= emacs-major-version 29) instead" "3.0.0")
(make-obsolete-variable 'MODULES "Use (featurep 'dynamic-modules) instead" "3.0.0")
(make-obsolete-variable 'NATIVECOMP "Use (featurep 'native-compile) instead" "3.0.0"))
;;
@ -291,7 +311,7 @@ users).")
;;
;;; Native Compilation support (http://akrl.sdf.org/gccemacs.html)
(when NATIVECOMP
(when (featurep 'native-compile)
;; Don't store eln files in ~/.emacs.d/eln-cache (where they can easily be
;; deleted by 'doom upgrade').
(add-to-list 'native-comp-eln-load-path (file-name-concat doom-cache-dir "eln/")))

View file

@ -53,7 +53,7 @@ directives. By default, this only recognizes C directives.")
evil-undo-system
(cond ((featurep! :emacs undo +tree) 'undo-tree)
((featurep! :emacs undo) 'undo-fu)
(EMACS28+ 'undo-redo)))
((> emacs-major-version 27) 'undo-redo)))
;; Slow this down from 0.02 to prevent blocking in large or folded buffers
;; like magit while incrementally highlighting matches.

View file

@ -136,7 +136,7 @@ variable for an explanation of the defaults (in comments). See
elisp-slime-nav
embark
emms
,@(when EMACS29+ '(emoji))
,@(if (> emacs-major-version 28) '(emoji))
epa
ert
eshell
@ -226,7 +226,7 @@ variable for an explanation of the defaults (in comments). See
scroll-lock
selectrum
sh-script
,@(when EMACS28+ '(shortdoc))
,@(if (> emacs-major-version 27) '(shortdoc))
simple
simple-mpc
slime

View file

@ -1,5 +1,5 @@
;;; emacs/vc/autoload/bug-reference-backport.el -*- lexical-binding: t; -*-
;;;###if (not EMACS28+)
;;;###if (< emacs-major-version 28)
;; DEPRECATED Remove when Emacs 27.x support is dropped
;; In Emacs 28, the built-in bug-reference package started consulting vc for

View file

@ -1,5 +1,5 @@
;;; term/eshell/autoload/mode.el -*- lexical-binding: t; -*-
;;;###if (not EMACS28+)
;;;###if (< emacs-major-version 28)
;; DEPRECATED Remove this when we drop Emacs 27 support.

View file

@ -1,7 +1,7 @@
;;; term/vterm/config.el -*- lexical-binding: t; -*-
(use-package! vterm
:when (bound-and-true-p module-file-suffix)
:when (featurep 'dynamic-modules)
:commands vterm-mode
:hook (vterm-mode . doom-mark-buffer-as-real-h)
:hook (vterm-mode . hide-mode-line-mode) ; modeline serves no purpose in vterm

View file

@ -179,7 +179,7 @@ and cannot run in."
;; Harfbuzz and Mac builds do not need font-specific ligature support
;; if they are above emacs-27.
((and EMACS28+
((and (> emacs-major-version 27)
(or (featurep 'ns)
(string-match-p "HARFBUZZ" system-configuration-features))
(featurep 'composite)) ; Emacs loads `composite' at startup