Refactor problem spec code
This commit is contained in:
parent
ef7caec424
commit
52a62591b6
49
config.org
49
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.")
|
"An alist of regexps matching problem specs.")
|
||||||
|
|
||||||
(setq ~/org-problem-spec-alist
|
(setq ~/org-problem-spec-alist
|
||||||
`((,(rx (group (+ digit))
|
`((,(rx (group (+ digit))
|
||||||
(* space) "-" (* space)
|
(* space) "-" (* space)
|
||||||
(group (+ digit))
|
(group (+ digit))
|
||||||
(* space) "odd")
|
(* space) "odd")
|
||||||
. ,(lambda (beg end)
|
. ,(lambda (beg end)
|
||||||
(when (cl-evenp beg) (cl-incf beg))
|
(when (cl-evenp beg) (cl-incf beg))
|
||||||
(number-sequence beg end 2)))
|
(number-sequence beg end 2)))
|
||||||
(,(rx (group (+ digit))
|
(,(rx (group (+ digit))
|
||||||
(* space) "-" (* space)
|
(* space) "-" (* space)
|
||||||
(group (+ digit))
|
(group (+ digit))
|
||||||
(* space) "even")
|
(* space) "even")
|
||||||
. ,(lambda (beg end)
|
. ,(lambda (beg end)
|
||||||
(when (cl-oddp beg) (cl-incf beg))
|
(when (cl-oddp beg) (cl-incf beg))
|
||||||
(number-sequence beg end 2)))
|
(number-sequence beg end 2)))
|
||||||
(,(rx (group (+ digit))
|
(,(rx (group (+ digit))
|
||||||
(* space) "-" (* space)
|
(* space) "-" (* space)
|
||||||
(group (+ digit))) . number-sequence)
|
(group (+ digit))) . number-sequence)
|
||||||
(,(rx (group (+ digit))) . list)))
|
(,(rx (group (+ digit))) . list)))
|
||||||
|
|
||||||
|
|
||||||
(defun ~/org-generate-problem-list (&rest specs)
|
(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
|
(problems
|
||||||
(mapcan
|
(mapcan
|
||||||
(lambda (spec)
|
(lambda (spec)
|
||||||
(let* ((match (car (or (--keep
|
(let* ((match
|
||||||
(when-let ((x (cdr-safe
|
(or (--some (-some-> (s-match (car it) spec)
|
||||||
(s-match (car it) spec))))
|
cdr (cons (cdr it)))
|
||||||
(cons x (cdr it)))
|
alist)
|
||||||
alist)
|
(user-error "Invalid problem spec \"%s\"" spec))))
|
||||||
(user-error "Invalid problem spec")))))
|
|
||||||
(apply (cdr match) (mapcar #'string-to-number (car match)))))
|
(apply (cdr match) (mapcar #'string-to-number (car match)))))
|
||||||
specs)))
|
specs)))
|
||||||
(insert "\n")
|
(move-to-left-margin)
|
||||||
(dolist (num problems)
|
(dolist (num problems)
|
||||||
(insert (format "- [ ] %d\n" num)))))
|
(insert (format "- [ ] %d\n" num)))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
Loading…
Reference in a new issue