Backport Emacs-29.1 functionality to Emacs-28.2

This commit is contained in:
Gerard Vermeulen 2023-01-10 19:03:26 +01:00
parent 3a91dfffb2
commit 54363c2bdc
1 changed files with 41 additions and 9 deletions

View File

@ -196,8 +196,9 @@ that *Emacs is a self-documenting editor.*
:CUSTOM_ID: sec:init-file-header
:END:
The =user-init-file= header requires =cl-lib= and customizes Emacs variables.
It consists of four parts in listing [[lst:1st-custom-set-variables-call]],
The =user-init-file= header requires =cl-lib=, backports new functions in
Emacs-29.1 to Emacs-28.2, and customizes Emacs variables. It consists of five
parts in listing [[lst:backport-header]], [[lst:1st-custom-set-variables-call]],
[[lst:2nd-custom-set-variables-call]], [[lst:3rd-custom-set-variables-call]], and
[[lst:4th-custom-set-variables-call]] in order to limit the length of the listings
for exporting to LaTeX.
@ -213,15 +214,49 @@ example]].
The [[info:emacs#Init File][init file (info)]] does not load the ~custom-file~ as [[info:emacs#Saving Customizations][saving customizations
(info)]] recommends because of the ~custom-set-variables~ function calls.
#+caption[Customize the first set of Emacs variables]:
#+caption: Customize the first set of Emacs variables.
#+name: lst:1st-custom-set-variables-call
#+caption[Header with backport of Emacs-29.1 functionality]:
#+caption: Header with backport of Emacs-29.1 functionality.
#+name: lst:backport-header
#+begin_src emacs-lisp
;;; init.el --- user init file -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(require 'cl-lib)
(when (version< emacs-version "29.0.0")
(defmacro setopt (&rest pairs)
"Set VARIABLE/VALUE pairs, and return the final VALUE.
This is like `setq', but is meant for user options instead of
plain variables. This means that `setopt' will execute any
`custom-set' form associated with VARIABLE.
\(fn [VARIABLE VALUE]...)"
(declare (debug setq))
(unless (zerop (mod (length pairs) 2))
(error "PAIRS must have an even number of variable/value members"))
(let ((expr nil))
(while pairs
(unless (symbolp (car pairs))
(error "Attempting to set a non-symbol: %s" (car pairs)))
(push `(setopt--set ',(car pairs) ,(cadr pairs))
expr)
(setq pairs (cddr pairs)))
(macroexp-progn (nreverse expr))))
(defun setopt--set (variable value)
(custom-load-symbol variable)
;; Check that the type is correct.
(when-let ((type (get variable 'custom-type)))
(unless (widget-apply (widget-convert type) :match value)
(warn "Value `%S' does not match type %s" value type)))
(put variable 'custom-check-value (list value))
(funcall (or (get variable 'custom-set) #'set-default) variable value)))
#+end_src
#+caption[Customize the first set of Emacs variables]:
#+caption: Customize the first set of Emacs variables.
#+name: lst:1st-custom-set-variables-call
#+begin_src emacs-lisp
(custom-set-variables
'(after-save-hook #'executable-make-buffer-file-executable-if-script-p)
'(column-number-mode t)
@ -4293,10 +4328,7 @@ src_emacs-lisp{(describe-function 'inferior-emacs-lisp-mode)}.
#+name: lst:setup-ielm
#+begin_src emacs-lisp
(with-eval-after-load 'ielm
(if (version< "29.0.0" emacs-version)
(setopt ielm-dynamic-return nil)
(custom-set-variables
'(ielm-dynamic-return nil))))
(setopt ielm-dynamic-return nil))
#+end_src
** [[https://fennel-lang.org/][Fennel Programming]]