branch: master commit dca9cb6d19f9e28ad8fa267a84710703ff38e006 Author: Ian Dunn <du...@gnu.org> Commit: Ian Dunn <du...@gnu.org>
Fixed bugs in parsing multiple forms * org-edna.el (org-edna--normalize-all-forms): New defun to parse all forms. (org-edna-string-form-to-sexp-form): Use it. (org-edna--expand-sexp-form): Fix scoping for form lists. --- org-edna-tests.el | 193 ++++++++++++++++++++++++++++-------------------------- org-edna.el | 34 +++++++--- org-edna.info | 180 ++++++++++++++++++++++++++++++-------------------- org-edna.org | 4 ++ 4 files changed, 236 insertions(+), 175 deletions(-) diff --git a/org-edna-tests.el b/org-edna-tests.el index a6b3554..83c05a3 100644 --- a/org-edna-tests.el +++ b/org-edna-tests.el @@ -151,39 +151,39 @@ (sexp (org-edna-string-form-to-sexp-form input-string 'condition))) (should (equal sexp - '((self) - (!done?)))))) + '(((self) + (!done?))))))) (ert-deftest org-edna-form-to-sexp-arguments () (let* ((input-string "match(\"checklist\") todo!(TODO)") (sexp (org-edna-string-form-to-sexp-form input-string 'action))) (should (equal sexp - '((match "checklist") - (todo! TODO)))))) + '(((match "checklist") + (todo! TODO))))))) (ert-deftest org-edna-form-to-sexp-if-no-else () (let* ((input-string "if match(\"checklist\") done? then self todo!(TODO) endif") (sexp (org-edna-string-form-to-sexp-form input-string 'action))) (should (equal sexp - '((if ((match "checklist") - (done?)) - ((self) - (todo! TODO)) - nil)))))) + '(((if ((match "checklist") + (done?)) + ((self) + (todo! TODO)) + nil))))))) (ert-deftest org-edna-form-to-sexp-if-else () (let* ((input-string "if match(\"checklist\") done? then self todo!(TODO) else siblings todo!(DONE) endif") (sexp (org-edna-string-form-to-sexp-form input-string 'action))) (should (equal sexp - '((if ((match "checklist") - (done?)) - ((self) - (todo! TODO)) - ((siblings) - (todo! DONE)))))))) + '(((if ((match "checklist") + (done?)) + ((self) + (todo! TODO)) + ((siblings) + (todo! DONE))))))))) (ert-deftest org-edna-expand-sexp-form () ;; Override cl-gentemp so we have a repeatable test @@ -224,21 +224,24 @@ (consideration1 nil) (blocking-entry1 nil)) ;; Don't need a new set of variables - (progn - (setq targets1 - (org-edna--add-targets targets1 + (let ((targets2 targets1) + (consideration2 consideration1) + (blocking-entry2 blocking-entry1)) + (setq targets2 + (org-edna--add-targets targets2 (org-edna-finder/match "checklist"))) (org-edna--handle-action 'org-edna-action/todo! - targets1 + targets2 (point-marker) '(DONE))) - ;; No new set of variables here either - (progn - (setq targets1 - (org-edna--add-targets targets1 + (let ((targets5 targets1) + (consideration5 consideration1) + (blocking-entry5 blocking-entry1)) + (setq targets5 + (org-edna--add-targets targets5 (org-edna-finder/siblings))) (org-edna--handle-action 'org-edna-action/todo! - targets1 + targets5 (point-marker) '(TODO))))) (output-form (org-edna--expand-sexp-form input-sexp))) @@ -263,45 +266,46 @@ (todo! TODO)) ((siblings) (todo! DONE))))) - (expected-form '(let - ((targets1 nil) - (consideration1 nil) - (blocking-entry1 nil)) - (if - ;; No inheritance in the conditional scope - (not - (let - ((targets2 nil) - (consideration2 nil) - (blocking-entry2 nil)) - ;; Add targets for checklist match - (setq targets2 - (org-edna--add-targets targets2 - (org-edna-finder/match "checklist"))) - ;; Handle condition - (setq blocking-entry2 - (or blocking-entry2 - (org-edna--handle-condition 'org-edna-condition/done\? 'nil 'nil targets2 consideration2))))) - ;; Use the top-level scope for then case - (progn - ;; Add targets for self finder - (setq targets1 - (org-edna--add-targets targets1 - (org-edna-finder/self))) - ;; Mark as TODO - (org-edna--handle-action 'org-edna-action/todo! targets1 - (point-marker) - '(TODO))) - ;; Use the top-level scope for the else case - (progn - ;; Find siblings - (setq targets1 - (org-edna--add-targets targets1 - (org-edna-finder/siblings))) - ;; Mark as DONE - (org-edna--handle-action 'org-edna-action/todo! targets1 - (point-marker) - '(DONE)))))) + (expected-form + '(let + ((targets1 nil) + (consideration1 nil) + (blocking-entry1 nil)) + (if + ;; No inheritance in the conditional scope + (not + (let + ((targets3 nil) + (consideration3 nil) + (blocking-entry3 nil)) + ;; Add targets for checklist match + (setq targets3 + (org-edna--add-targets targets3 + (org-edna-finder/match "checklist"))) + ;; Handle condition + (setq blocking-entry3 + (or blocking-entry3 + (org-edna--handle-condition 'org-edna-condition/done\? 'nil 'nil targets3 consideration3))))) + ;; Use the top-level scope for then case + (progn + ;; Add targets for self finder + (setq targets1 + (org-edna--add-targets targets1 + (org-edna-finder/self))) + ;; Mark as TODO + (org-edna--handle-action 'org-edna-action/todo! targets1 + (point-marker) + '(TODO))) + ;; Use the top-level scope for the else case + (progn + ;; Find siblings + (setq targets1 + (org-edna--add-targets targets1 + (org-edna-finder/siblings))) + ;; Mark as DONE + (org-edna--handle-action 'org-edna-action/todo! targets1 + (point-marker) + '(DONE)))))) (output-form (org-edna--expand-sexp-form input-sexp))) (should (equal output-form expected-form)))) @@ -323,37 +327,38 @@ (done\?)) ((self) (todo! TODO))))) - (expected-form '(let - ((targets1 nil) - (consideration1 nil) - (blocking-entry1 nil)) - (if - ;; No inheritance in the conditional scope - (not - (let - ((targets2 nil) - (consideration2 nil) - (blocking-entry2 nil)) - ;; Add targets for checklist match - (setq targets2 - (org-edna--add-targets targets2 - (org-edna-finder/match "checklist"))) - ;; Handle condition - (setq blocking-entry2 - (or blocking-entry2 - (org-edna--handle-condition 'org-edna-condition/done\? 'nil 'nil targets2 consideration2))))) - ;; Use the top-level scope for then case - (progn - ;; Add targets for self finder - (setq targets1 - (org-edna--add-targets targets1 - (org-edna-finder/self))) - ;; Mark as TODO - (org-edna--handle-action 'org-edna-action/todo! targets1 - (point-marker) - '(TODO))) - ;; End with a nil - nil))) + (expected-form + '(let + ((targets1 nil) + (consideration1 nil) + (blocking-entry1 nil)) + (if + ;; No inheritance in the conditional scope + (not + (let + ((targets3 nil) + (consideration3 nil) + (blocking-entry3 nil)) + ;; Add targets for checklist match + (setq targets3 + (org-edna--add-targets targets3 + (org-edna-finder/match "checklist"))) + ;; Handle condition + (setq blocking-entry3 + (or blocking-entry3 + (org-edna--handle-condition 'org-edna-condition/done\? 'nil 'nil targets3 consideration3))))) + ;; Use the top-level scope for then case + (progn + ;; Add targets for self finder + (setq targets1 + (org-edna--add-targets targets1 + (org-edna-finder/self))) + ;; Mark as TODO + (org-edna--handle-action 'org-edna-action/todo! targets1 + (point-marker) + '(TODO))) + ;; End with a nil + nil))) (output-form (org-edna--expand-sexp-form input-sexp))) (should (equal output-form expected-form)))) diff --git a/org-edna.el b/org-edna.el index 5f60fb9..b071b38 100644 --- a/org-edna.el +++ b/org-edna.el @@ -7,7 +7,7 @@ ;; Keywords: convenience, text, org ;; URL: https://savannah.nongnu.org/projects/org-edna-el/ ;; Package-Requires: ((emacs "25.1") (seq "2.19") (org "9.0.5")) -;; Version: 1.0beta3 +;; Version: 1.0beta4 ;; This file is part of GNU Emacs. @@ -291,16 +291,32 @@ the remainder of FORM after the current scope was parsed." (push '(!done?) final-form)) (list (nreverse final-form) remaining-form))) +(defun org-edna--normalize-all-forms (form-list action-or-condition &optional from-string) + "Normalize all forms in flat form list FORM-LIST. + +ACTION-OR-CONDITION is either 'action or 'condition, indicating +which of the two types is allowed in FORM. + +FROM-STRING is used internally, and is non-nil if FORM was +originally a string." + (pcase-let* ((`(,final-form ,rem-form) (org-edna--normalize-sexp-form form-list action-or-condition from-string))) + (setq final-form (list final-form)) + (while rem-form + (pcase-let* ((`(,new-form ,r-form) + (org-edna--normalize-sexp-form rem-form action-or-condition from-string))) + (setq final-form (append final-form (list new-form)) + rem-form r-form))) + final-form)) + (defun org-edna-string-form-to-sexp-form (string-form action-or-condition) "Parse string form STRING-FORM into an Edna sexp form. ACTION-OR-CONDITION is either 'action or 'condition, indicating which of the two types is allowed in STRING-FORM." - (car - (org-edna--normalize-sexp-form - (car (org-edna--convert-form string-form)) - action-or-condition - string-form))) + (org-edna--normalize-all-forms + (car (org-edna--convert-form string-form)) + action-or-condition + string-form)) (defun org-edna--handle-condition (func mod args targets consideration) "Handle a condition. @@ -396,13 +412,13 @@ OLD-BLOCKING-VAR are used internally." `(if (not ,(org-edna--expand-sexp-form cond)) ,(org-edna--expand-sexp-form then - '(progn) + t old-target-var old-consideration-var old-blocking-var) ,(when else (org-edna--expand-sexp-form ;; else is wrapped in a list, so take the first argument (car else) - '(progn) + t old-target-var old-consideration-var old-blocking-var)))) ((pred (lambda (arg) (symbolp (car arg)))) (org-edna--expand-single-sexp-form @@ -413,7 +429,7 @@ OLD-BLOCKING-VAR are used internally." `(,@wrapper-form ,@(mapcar (lambda (f) (org-edna--expand-sexp-form - f '(progn) target-var consideration-var blocking-var)) + f nil target-var consideration-var blocking-var)) form))))))) (defun org-edna-eval-sexp-form (sexp-form) diff --git a/org-edna.info b/org-edna.info index 1da4b0c..5a7db99 100644 --- a/org-edna.info +++ b/org-edna.info @@ -107,9 +107,16 @@ Contributing Changelog +* 1.0beta4: 10beta4. * 1.0beta3: 10beta3. * 1.0beta2: 10beta2. +1.0beta4 + +* Fixed multiple forms getting incorrect targets:: +* Fixed multiple forms not evaluating:: + + 1.0beta3 * Conditional Forms: Conditional Forms (1). @@ -1468,11 +1475,37 @@ Changelog * Menu: +* 1.0beta4: 10beta4. * 1.0beta3: 10beta3. * 1.0beta2: 10beta2. -File: org-edna.info, Node: 10beta3, Next: 10beta2, Up: Changelog +File: org-edna.info, Node: 10beta4, Next: 10beta3, Up: Changelog + +1.0beta4 +======== + +Just some bug fixes from the new form parsing. + +* Menu: + +* Fixed multiple forms getting incorrect targets:: +* Fixed multiple forms not evaluating:: + + +File: org-edna.info, Node: Fixed multiple forms getting incorrect targets, Next: Fixed multiple forms not evaluating, Up: 10beta4 + +Fixed multiple forms getting incorrect targets +---------------------------------------------- + + +File: org-edna.info, Node: Fixed multiple forms not evaluating, Prev: Fixed multiple forms getting incorrect targets, Up: 10beta4 + +Fixed multiple forms not evaluating +----------------------------------- + + +File: org-edna.info, Node: 10beta3, Next: 10beta2, Prev: 10beta4, Up: Changelog 1.0beta3 ======== @@ -1574,77 +1607,80 @@ New finders Tag Table: Node: Top225 -Node: Copying3930 -Node: Introduction4747 -Node: Installation and Setup5695 -Node: Basic Operation6488 -Node: Blockers8339 -Node: Triggers8625 -Node: Syntax8887 -Node: Basic Features9577 -Node: Finders9880 -Node: ancestors11645 -Node: children12239 -Node: descendants12649 -Node: file13171 -Node: first-child13920 -Node: ids14180 -Node: match14841 -Node: next-sibling15479 -Node: next-sibling-wrap15736 -Node: olp16050 -Node: org-file16462 -Node: parent17107 -Node: previous-sibling17305 -Node: previous-sibling-wrap17566 -Node: relatives17845 -Node: rest-of-siblings21466 -Node: rest-of-siblings-wrap21751 -Node: self22100 -Node: siblings22261 -Node: siblings-wrap22498 -Node: Actions22802 -Node: Scheduled/Deadline23544 -Node: TODO State27119 -Node: Archive27487 -Node: Chain Property27807 -Node: Clocking28090 -Node: Property28502 -Node: Priority28824 -Node: Tag29393 -Node: Effort29610 -Node: Advanced Features29999 -Node: Conditions30383 -Node: done30998 -Node: headings31162 -Node: todo-state31538 -Node: variable-set31794 -Node: has-property32223 -Node: re-search32492 -Node: Negating Conditions32852 -Node: Consideration33239 -Node: Conditional Forms34808 -Node: Setting the Properties37464 -Node: Extending Edna38548 -Node: Naming Conventions39038 -Node: Finders (1)39501 -Node: Actions (1)39867 -Node: Conditions (1)40332 -Node: Contributing41222 -Node: Bugs41773 -Node: Development42125 -Node: Documentation43278 -Node: Changelog43723 -Node: 10beta343868 -Node: Conditional Forms (1)44126 -Node: Overhauled Internal Parsing44325 -Node: Fixed consideration keywords44522 -Node: Added 'any consideration44781 -Node: 10beta244996 -Node: Added interactive keyword editor with completion45278 -Node: New uses of schedule! and deadline!45577 -Node: New ``relatives'' finder46072 -Node: New finders46468 +Node: Copying4054 +Node: Introduction4871 +Node: Installation and Setup5819 +Node: Basic Operation6612 +Node: Blockers8463 +Node: Triggers8749 +Node: Syntax9011 +Node: Basic Features9701 +Node: Finders10004 +Node: ancestors11769 +Node: children12363 +Node: descendants12773 +Node: file13295 +Node: first-child14044 +Node: ids14304 +Node: match14965 +Node: next-sibling15603 +Node: next-sibling-wrap15860 +Node: olp16174 +Node: org-file16586 +Node: parent17231 +Node: previous-sibling17429 +Node: previous-sibling-wrap17690 +Node: relatives17969 +Node: rest-of-siblings21590 +Node: rest-of-siblings-wrap21875 +Node: self22224 +Node: siblings22385 +Node: siblings-wrap22622 +Node: Actions22926 +Node: Scheduled/Deadline23668 +Node: TODO State27243 +Node: Archive27611 +Node: Chain Property27931 +Node: Clocking28214 +Node: Property28626 +Node: Priority28948 +Node: Tag29517 +Node: Effort29734 +Node: Advanced Features30123 +Node: Conditions30507 +Node: done31122 +Node: headings31286 +Node: todo-state31662 +Node: variable-set31918 +Node: has-property32347 +Node: re-search32616 +Node: Negating Conditions32976 +Node: Consideration33363 +Node: Conditional Forms34932 +Node: Setting the Properties37588 +Node: Extending Edna38672 +Node: Naming Conventions39162 +Node: Finders (1)39625 +Node: Actions (1)39991 +Node: Conditions (1)40456 +Node: Contributing41346 +Node: Bugs41897 +Node: Development42249 +Node: Documentation43402 +Node: Changelog43847 +Node: 10beta444013 +Node: Fixed multiple forms getting incorrect targets44252 +Node: Fixed multiple forms not evaluating44483 +Node: 10beta344692 +Node: Conditional Forms (1)44966 +Node: Overhauled Internal Parsing45165 +Node: Fixed consideration keywords45362 +Node: Added 'any consideration45621 +Node: 10beta245836 +Node: Added interactive keyword editor with completion46118 +Node: New uses of schedule! and deadline!46417 +Node: New ``relatives'' finder46912 +Node: New finders47308 End Tag Table diff --git a/org-edna.org b/org-edna.org index c23f80a..cb59d06 100644 --- a/org-edna.org +++ b/org-edna.org @@ -1238,6 +1238,10 @@ making any changes: :PROPERTIES: :DESCRIPTION: List of changes by version :END: +** 1.0beta4 +Just some bug fixes from the new form parsing. +*** Fixed multiple forms getting incorrect targets +*** Fixed multiple forms not evaluating ** 1.0beta3 HUGE addition here *** Conditional Forms