Add id to each item
* undone/main.scm (get-field-value): Allow specification of default return if no key is found. (next-id): New function. (add): Add `id' to the todo item.
This commit is contained in:
parent
62cde9b1c8
commit
271b33f910
1 changed files with 15 additions and 2 deletions
|
@ -12,8 +12,13 @@
|
|||
(define-syntax get-field-value
|
||||
(lambda (x)
|
||||
(syntax-case x ()
|
||||
((_ key alist default)
|
||||
#'(let ((field (get-field key alist)))
|
||||
(if field
|
||||
(cdr field)
|
||||
default)))
|
||||
((_ key alist)
|
||||
#'(cdr (get-field key alist))))))
|
||||
#'(get-field-value key alist #f)))))
|
||||
|
||||
(define-syntax define-view
|
||||
(lambda (x)
|
||||
|
@ -126,6 +131,7 @@
|
|||
(mkdir path)))
|
||||
|
||||
(define (save)
|
||||
|
||||
"Save the list."
|
||||
(mkdirs (dirname todo-list-file))
|
||||
|
||||
|
@ -133,13 +139,20 @@
|
|||
(write todo-list port)
|
||||
(close-port port)))
|
||||
|
||||
(define (next-id)
|
||||
"Look through all known todo items and get the next id."
|
||||
(1+ (apply max (map (lambda (elm)
|
||||
(get-field-value id elm 0))
|
||||
todo-list))))
|
||||
|
||||
(define (add args)
|
||||
"Add item to the list."
|
||||
(set! todo-list
|
||||
(append todo-list
|
||||
(list
|
||||
(append
|
||||
`((content . ,(string-trim-right (read-delimited ""))))
|
||||
`((id . ,(next-id))
|
||||
(content . ,(string-trim-right (read-delimited ""))))
|
||||
(map (lambda (arg)
|
||||
(let* ((pair (string-split arg #\=))
|
||||
(var (string->symbol (car pair)))
|
||||
|
|
Loading…
Reference in a new issue