From ae319fccc64f35c52a247633c67f72c924396b03 Mon Sep 17 00:00:00 2001 From: TEC Date: Sun, 5 Feb 2023 12:34:55 +0800 Subject: [PATCH 3/6] ox: Feature condition/implementation convenience * lisp/ox.el (org-export-update-features): Add a convenience function for users to edit the feature condition/implementation lists. --- lisp/ox.el | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/lisp/ox.el b/lisp/ox.el index 1a75ed28d..32f1c6016 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -2246,6 +2246,48 @@ (defun org-export-generate-features-preamble (info) (append (delq nil feat-snippets) (list "")) "\n"))) +(defun org-export-update-features (backend &rest feature-property-value-lists) + "For BACKEND's export spec, set all FEATURE-PROPERTY-VALUE-LISTS. + +Specifically, for each (FEATURE . PROPERTY-VALUE-LIST) entry of +FEATURE-PROPERTY-VALUE-LISTS, each :PROPERTY VALUE pair of +PROPERTY-VALUE-PAIRS is set to VALUE within the backend's feature +implementation plist. The sole exception to this is the +:condition property, the value of which is set in the backend's +feature condition plist instead. + +This can be used to both modify existing entries, and create new ones. + +\(fn BACKEND &rest (FEATURE PROPERTY-VALUE-PAIRS...)...)" + (declare (indent 1)) + (let ((backend-var (intern (format "org-%s-feature-implementations" backend))) + (backend-cf (intern (format "org-%s-conditional-features" backend)))) + (unless (boundp backend-var) + (error "Feature implementations for %s cannot be set as %s is undefined" + backend backend-var)) + (dolist (feature-property-value-set feature-property-value-lists) + (let ((feature (car feature-property-value-set)) + (property-value-pairs (copy-sequence (cdr feature-property-value-set)))) + (while property-value-pairs + (if (eq (car property-value-pairs) :condition) + (let ((condition (progn (pop property-value-pairs) + (pop property-value-pairs)))) + (unless (boundp backend-cf) + (error "Feature condition for %s cannot be set as %s is undefined" + backend backend-cf)) + (cond + ((rassoc feature (symbol-value backend-cf)) + (if condition + (setcar (rassoc feature (symbol-value backend-cf)) + condition) + (set backend-cf (delq (rassoc feature (symbol-value backend-cf)) + (symbol-value backend-cf))))) + (condition + (add-to-list backend-cf (cons condition feature))))) + (setf (alist-get feature (symbol-value backend-var)) + (plist-put (alist-get feature (symbol-value backend-var)) + (pop property-value-pairs) (pop property-value-pairs))))))))) + ;;; The Filter System ;; -- 2.39.0