From 52a62591b6b9dbad75662f0d34f561182955d600 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Fri, 22 Mar 2024 00:54:00 -0400 Subject: [PATCH] Refactor problem spec code --- config.org | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/config.org b/config.org index 7d0d8ec..d2ba90f 100644 --- a/config.org +++ b/config.org @@ -3520,24 +3520,24 @@ This section is for code with little or no associated documentation. This could "An alist of regexps matching problem specs.") (setq ~/org-problem-spec-alist - `((,(rx (group (+ digit)) - (* space) "-" (* space) - (group (+ digit)) - (* space) "odd") - . ,(lambda (beg end) - (when (cl-evenp beg) (cl-incf beg)) - (number-sequence beg end 2))) - (,(rx (group (+ digit)) - (* space) "-" (* space) - (group (+ digit)) - (* space) "even") - . ,(lambda (beg end) - (when (cl-oddp beg) (cl-incf beg)) - (number-sequence beg end 2))) - (,(rx (group (+ digit)) - (* space) "-" (* space) - (group (+ digit))) . number-sequence) - (,(rx (group (+ digit))) . list))) + `((,(rx (group (+ digit)) + (* space) "-" (* space) + (group (+ digit)) + (* space) "odd") + . ,(lambda (beg end) + (when (cl-evenp beg) (cl-incf beg)) + (number-sequence beg end 2))) + (,(rx (group (+ digit)) + (* space) "-" (* space) + (group (+ digit)) + (* space) "even") + . ,(lambda (beg end) + (when (cl-oddp beg) (cl-incf beg)) + (number-sequence beg end 2))) + (,(rx (group (+ digit)) + (* space) "-" (* space) + (group (+ digit))) . number-sequence) + (,(rx (group (+ digit))) . list))) (defun ~/org-generate-problem-list (&rest specs) @@ -3546,15 +3546,14 @@ This section is for code with little or no associated documentation. This could (problems (mapcan (lambda (spec) - (let* ((match (car (or (--keep - (when-let ((x (cdr-safe - (s-match (car it) spec)))) - (cons x (cdr it))) - alist) - (user-error "Invalid problem spec"))))) + (let* ((match + (or (--some (-some-> (s-match (car it) spec) + cdr (cons (cdr it))) + alist) + (user-error "Invalid problem spec \"%s\"" spec)))) (apply (cdr match) (mapcar #'string-to-number (car match))))) specs))) - (insert "\n") + (move-to-left-margin) (dolist (num problems) (insert (format "- [ ] %d\n" num))))) #+end_src