diff options
| author | Jonas Bernoulli <jonas@bernoul.li> | 2026-04-22 18:50:20 +0200 |
|---|---|---|
| committer | Jonas Bernoulli <jonas@bernoul.li> | 2026-04-22 18:50:20 +0200 |
| commit | ad855d4e7642eadcaac675f51eebdca4fdef3c0a (patch) | |
| tree | c46dba1afea0241ee528c3fafb40f88e62621252 | |
| parent | 1f21d1f2eb0f32beeff3e51768d2eadb9a78d631 (diff) | |
[patch 8/10] lisp: Remove backward compatibility and external-only kludges
- Drop require for `compat'.
- Drop `seq' kludge.
- Drop `pp-default-function' declaration.
- Drop `signal' backward compatibility.
- Make use of `pcase-setq'.
- Drop backward compatibility in `transient--wrap-command'.
- Expect `string-edit' to exist.
- Expect `string-pixel-width' to exist.
- Expect `overriding-text-conversion-style' to exist.
| -rw-r--r-- | lisp/transient.el | 152 |
1 files changed, 22 insertions, 130 deletions
diff --git a/lisp/transient.el b/lisp/transient.el index 9e239d4..8e8ecdf 100644 --- a/lisp/transient.el +++ b/lisp/transient.el @@ -47,47 +47,12 @@ (defconst transient-version "0.13.0") (require 'cl-lib) -(require 'compat) (require 'eieio) (require 'edmacro) (require 'format-spec) (require 'pcase) (require 'pp) - -(eval-and-compile - (when (and (featurep 'seq) - (not (fboundp 'seq-keep))) - (unload-feature 'seq 'force))) (require 'seq) -(unless (fboundp 'seq-keep) - (display-warning 'transient (substitute-command-keys "\ -Transient requires `seq' >= 2.24, -but due to bad defaults, Emacs's package manager, refuses to -upgrade this and other built-in packages to higher releases -from GNU Elpa, when a package specifies that this is needed. - -To fix this, you have to add this to your init file: - - (setq package-install-upgrade-built-in t) - -Then evaluate that expression by placing the cursor after it -and typing \\[eval-last-sexp]. - -Once you have done that, you have to explicitly upgrade `seq': - - \\[package-upgrade] seq \\`RET' - -Then you also must make sure the updated version is loaded, -by evaluating this form: - - (progn (unload-feature 'seq t) (require 'seq)) - -Until you do this, you will get random errors about `seq-keep' -being undefined while using Transient. - -If you don't use the `package' package manager but still get -this warning, then your chosen package manager likely has a -similar defect.") :emergency)) (eval-when-compile (require 'subr-x)) @@ -97,7 +62,6 @@ similar defect.") :emergency)) (declare-function Man-getpage-in-background "man" (topic)) (defvar Man-notify-method) -(defvar pp-default-function) ; since Emacs 29.1 (define-obsolete-variable-alias 'transient-show-popup @@ -121,9 +85,7 @@ similar defect.") :emergency)) ,(macroexp-progn body)) ((debug error) (transient--emergency-exit ,id) - (static-if (fboundp 'error-type-p) ; since Emacs 31.1 - (signal err) - (signal (car err) (cdr err)))))) + (signal err)))) (defun transient--exit-and-debug (&rest args) (transient--emergency-exit :debugger) @@ -1736,8 +1698,7 @@ Intended for use in a group's `:setup-children' function." (equal (transient--suffix-predicate suf) (transient--suffix-predicate conflict))))) (transient-remove-suffix prefix key) - (let ((eg (transient--locate-child prefix loc))) - (setq elt (car eg) group (cadr eg)))) + (pcase-setq `(,elt ,group) (transient--locate-child prefix loc))) (let ((mem (memq elt (aref group 2)))) (pcase-exhaustive action ('insert (setcdr mem (cons elt (cdr mem))) @@ -3001,9 +2962,7 @@ value. Otherwise return CHILDREN as is.") (defun transient--wrap-command () (transient--load-command-if-autoload this-command) - (static-if (>= emacs-major-version 30) - (letrec - ((command this-command) + (letrec ((command this-command) (suffix (transient-suffix-object this-command)) (prefix transient--prefix) (advice @@ -3044,57 +3003,7 @@ value. Otherwise return CHILDREN as is.") (when (symbolp command) (remove-function (symbol-function command) advice)) (oset prefix unwind-suffix nil))))) - (transient--advise-this-command advice) - (cl-assert - (>= emacs-major-version 30) nil - "Emacs was downgraded, making it necessary to recompile Transient")) - ;; (< emacs-major-version 30) - (let* ((command this-command) - (suffix (transient-suffix-object this-command)) - (prefix transient--prefix) - (advice nil) - (advice-interactive - (lambda (spec) - (let ((abort t)) - (unwind-protect - (prog1 (let ((debugger #'transient--exit-and-debug)) - (if-let* ((obj suffix) - (grp (oref obj parent)) - (adv (or (oref obj advice*) - (oref grp advice*)))) - (funcall - adv #'advice-eval-interactive-spec spec) - (advice-eval-interactive-spec spec))) - (setq abort nil)) - (when abort - (when-let* ((unwind (oref prefix unwind-suffix))) - (transient--debug 'unwind-interactive) - (funcall unwind command)) - (when (symbolp command) - (remove-function (symbol-function command) advice)) - (oset prefix unwind-suffix nil)))))) - (advice-body - (lambda (fn &rest args) - (unwind-protect - (let ((debugger #'transient--exit-and-debug)) - (if-let* ((obj suffix) - (grp (oref obj parent)) - (adv (or (oref obj advice) - (oref obj advice*) - (oref grp advice) - (oref grp advice*)))) - (apply adv fn args) - (apply fn args))) - (when-let* ((unwind (oref prefix unwind-suffix))) - (transient--debug 'unwind-command) - (funcall unwind command)) - (when (symbolp command) - (remove-function (symbol-function command) advice)) - (oset prefix unwind-suffix nil))))) - (setq advice `(lambda (fn &rest args) - (interactive ,advice-interactive) - (apply ',advice-body fn args))) - (transient--advise-this-command advice)))) + (transient--advise-this-command advice))) (defun transient--advise-this-command (advice) "Add ADVICE around `this-command'. @@ -4106,19 +4015,18 @@ stand-alone command." (when (fboundp 'org-read-date) (org-read-date 'with-time nil nil prompt default-time))) -(static-if (fboundp 'string-edit) ; since Emacs 29.1 - (defun transient-read-string-from-buffer (prompt value _) - "Switch to a new buffer to edit STRING in a recursive edit. +(defun transient-read-string-from-buffer (prompt value _) + "Switch to a new buffer to edit STRING in a recursive edit. Like `read-string-from-buffer' but accept an additional argument as provided by `transient-infix-read' (but ignore it). Only available when using Emacs 29.1 or greater." - (string-edit prompt (or value "") - (lambda (edited) - (setq value edited) - (exit-recursive-edit)) - :abort-callback #'exit-recursive-edit) - (recursive-edit) - value)) + (string-edit prompt (or value "") + (lambda (edited) + (setq value edited) + (exit-recursive-edit)) + :abort-callback #'exit-recursive-edit) + (recursive-edit) + value) ;;;;; Prompt @@ -5198,32 +5106,17 @@ apply the face `transient-unreachable' to the complete string." (length (oref suffix key)))) (oref group suffixes)))))) -(static-if (fboundp 'string-pixel-width) ; since Emacs 29.1 - (progn ; See https://github.com/magit/magit/issues/5557. - (defalias 'transient--string-pixel-width #'string-pixel-width)) - ;; c22b735f0c6 and 61c254cafc9 cannot be backported. Some later - ;; commits could be ported, but users should instead update Emacs. - (defun transient--string-pixel-width (string) - (with-temp-buffer - (insert string) - (save-window-excursion - (set-window-dedicated-p nil nil) - (set-window-buffer nil (current-buffer)) - (car (window-text-pixel-size - nil (line-beginning-position) (point))))))) - (defun transient--column-stops (columns) (let* ((var-pitch (or transient-align-variable-pitch (oref transient--prefix variable-pitch))) - (char-width (and var-pitch (transient--string-pixel-width " ")))) + (char-width (and var-pitch (string-pixel-width " ")))) (transient--seq-reductions-from (apply-partially #'+ (* 2 (if var-pitch char-width 1))) (transient--mapn (lambda (cells min) (apply #'max (if min (if var-pitch (* min char-width) min) 0) - (mapcar (if var-pitch #'transient--string-pixel-width #'length) - cells))) + (mapcar (if var-pitch #'string-pixel-width #'length) cells))) columns (oref transient--prefix column-widths)) 0))) @@ -5636,14 +5529,13 @@ search instead." lisp-imenu-generic-expression :test #'equal) (defun transient--suspend-text-conversion-style () - (static-if (boundp 'overriding-text-conversion-style) ; since Emacs 30.1 - (when text-conversion-style - (letrec ((suspended overriding-text-conversion-style) - (fn (lambda () - (setq overriding-text-conversion-style nil) - (remove-hook 'transient-exit-hook fn)))) - (setq overriding-text-conversion-style suspended) - (add-hook 'transient-exit-hook fn))))) + (when text-conversion-style + (letrec ((suspended overriding-text-conversion-style) + (fn (lambda () + (setq overriding-text-conversion-style nil) + (remove-hook 'transient-exit-hook fn)))) + (setq overriding-text-conversion-style suspended) + (add-hook 'transient-exit-hook fn)))) (declare-function which-key-mode "ext:which-key" (&optional arg)) |
