emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/dslide 39495bb1c2 05/21: warn when propertize is given unq


From: ELPA Syncer
Subject: [nongnu] elpa/dslide 39495bb1c2 05/21: warn when propertize is given unquoted lists. better parsing.
Date: Tue, 17 Dec 2024 13:00:52 -0500 (EST)

branch: elpa/dslide
commit 39495bb1c206ae862f3cd2372c951e7ead5425ac
Author: Psionik K <73710933+psionic-k@users.noreply.github.com>
Commit: Psionik K <73710933+psionic-k@users.noreply.github.com>

    warn when propertize is given unquoted lists.  better parsing.
    
    parsing gets used later by new / changed actions
---
 NEWS.org      |  2 ++
 dslide.el     | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 test/demo.org |  6 ++----
 3 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index 88dcfe163e..0c6706681f 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -14,6 +14,8 @@
 * v0.6.0 Fighting Spam 💌 :latest:
 ** Added ➕
 ** Changed 🙅
+- ⚠️ Propertize action now warns on unquoted lists.  Please use quoted lists.  
In my opinion, all lists should be considered quoted in org, but this change is 
consistent with babel parameters being evaluated when unquoted.
+- Yet more manual Kaizen.  Seriously, check it out by installing dslide.
 ** Fixed 💩
 * v0.5.6 Let There Be News 🗞️
 - ⛔ The concept of default actions has been marked for deprecation.  This is 
preparation for instantiating actions on-demand rather than per slide.  The 
action system may undergo some overhaul internally.
diff --git a/dslide.el b/dslide.el
index 4869156f1c..601c366de0 100644
--- a/dslide.el
+++ b/dslide.el
@@ -1331,12 +1331,22 @@ for `dslide-contents-map'.")
   (dslide-section-map
    obj t                                ; t for all types
    (lambda (e)
-     (when-let ((props (nreverse (dslide-element-plist
-                                  :attr_dslide_propertize e)))
+     (when-let ((props (nreverse (dslide-read-affiliated
+                                  e :attr_dslide_propertize nil t)))
                 (overlay (make-overlay (org-element-property :post-affiliated 
e)
                                        (1- (org-element-property :end e)))))
        (while-let ((value (pop props))
                    (prop (pop props)))
+         (when (listp value)
+           (if (eq (car value) 'quote)
+               (setq value (cdr value))
+             (delay-warning
+              '(dslide dslide-propertize dslide-unquoted)
+              (format "Propertize Unquoted list on %s"
+                      (without-restriction
+                        (line-number-at-pos
+                         (org-element-property :begin e))))
+              :warning)))
          (overlay-put overlay prop value))
        (push overlay dslide-overlays)))))
 
@@ -3000,6 +3010,51 @@ the caller."
          '(dslide)
          (format "Class name not a class: %s" class-name))
         nil))))
+;; XXX the text property action lists are unquoted while babel block lists are
+;; quoted.  It would be better to normalize behavior, unquoted quoted lists
+;; and warning on unquoted lists.
+(defun dslide-read-plist (plist-string &optional start keywords)
+  "Reads PLIST-STRING into a plist.
+Returns a cons of (PLIST-READ . FINAL-STRING-INDEX) to support
+further reading.  When keywords is non-nil, signal
+wrong-type-argument if any keys are not keywords.  Missing
+terminal values will be interpreted as nil."
+  (let ((pos (or start 0))
+        result)
+    (condition-case nil
+        (while pos
+          (let* ((key (read-from-string plist-string pos)))
+            (if (or (null keywords)
+                    (keywordp (car key)))
+                (push (car key) result)
+              (signal 'wrong-type-argument
+                      (format "Symbol is not a keyword: %S" (car key))))
+            (let ((val (read-from-string plist-string (cdr key))))
+              (push (car val) result)
+              (setq pos (cdr val)))))
+      (end-of-file nil))
+    (nreverse result)))
+
+(defun dslide-read-affiliated (element property &optional keywords merged)
+  "Return plist for PROPERTY of ELEMENT.
+Affiliated keywords can have a list of value when several of the
+same affilated keyword annotate an object.  When optional
+KEYWORDS is t, non-keywords will signal wrong-type-argument.
+When optional MERGED is non-nil, return a merged plist.  The
+top-most affiliated keyword is considered the last to be called
+and thus overwrites the inner keywords when merging."
+  (let ((found (org-element-property property element))
+        read)
+    (while-let ((f (pop found)))
+      (let ((plist (dslide-read-plist f 0 keywords)))
+        (if merged
+            (while-let ((key (pop plist)))
+              (push key read)
+              (push (pop plist) read))
+          (push plist read))))
+    ;; Either reverses all keys or reverses the keyword order, making first
+    ;; keys in the outer list first in the result either way.
+    (nreverse read)))
 
 ;; * Contents Highlight Line
 
diff --git a/test/demo.org b/test/demo.org
index f8c4ff054d..641db3f669 100644
--- a/test/demo.org
+++ b/test/demo.org
@@ -164,13 +164,11 @@ This is another case where you can use 
~dslide-deck-develop~ to see the comments
 ** TODO Todos and Tags :tag1:tag2:tag3:
 Todos and tags are by default hidden.  Set ~dslide-hide-tags~ and 
~dslide-hide-todos~ if you need them visible in a presentation.
 * Fancy Text
-:PROPERTIES:
-:DSLIDE_ACTIONS: dslide-action-propertize
-:END:
 Add text properties to an element using the =attr_dslide_propertize= 
affiliated keyword.  No quoting is required.  Lists will be interpreted as such.
 
-#+attr_dslide_propertize: face (:background "#ddddff" :foreground "#000000" 
:weight bold :height 2.0)
+#+attr_dslide_propertize: face '(:background "#ddddff" :foreground "#000000" 
:weight bold :height 1.5)
 This is some fancy text
+
 * Babel Integration
 :PROPERTIES:
 :DSLIDE_ACTIONS: dslide-action-babel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]