Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
50
Task/Simple-database/Emacs-Lisp/simple-database.l
Normal file
50
Task/Simple-database/Emacs-Lisp/simple-database.l
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
(defun dbe-next-id ()
|
||||
(unless (boundp '**dbe-current-id**) (setq **dbe-current-id** 1))
|
||||
(let ((id **dbe-current-id**))
|
||||
(cl-incf **dbe-current-id**)
|
||||
id ) )
|
||||
|
||||
(defun dbe-rows (fn-handle-row &rest params)
|
||||
(let ((has-more 't) current-line linum1 linum2
|
||||
(fn-continue (plist-get params :continue)))
|
||||
(save-window-excursion
|
||||
(switch-to-buffer "**content**")
|
||||
(beginning-of-buffer)
|
||||
(if fn-continue (setq has-more (funcall fn-continue)))
|
||||
(while has-more
|
||||
(setq current-line
|
||||
(buffer-substring (line-beginning-position)
|
||||
(line-end-position)))
|
||||
(unless (string= current-line "")
|
||||
(funcall fn-handle-row (read current-line)))
|
||||
(if fn-continue (setq has-more (funcall fn-continue)))
|
||||
(setq linum1 (line-number-at-pos (point)))
|
||||
(forward-line)
|
||||
(setq linum2 (line-number-at-pos (point)))
|
||||
(if (= linum1 linum2) (setq has-more nil))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(defun dbe-insert (row)
|
||||
(interactive "xPlease enter the row data in plist format: ")
|
||||
(save-window-excursion
|
||||
(switch-to-buffer "**content**")
|
||||
(end-of-buffer)
|
||||
(let (row-data)
|
||||
(setq row-data (append (list 'id (dbe-next-id)) (ensure-list row)))
|
||||
(insert (format "%s\n" row-data))
|
||||
(message ">> Row added: %s" row-data) ) ) )
|
||||
|
||||
(defun dbe-find-by-id (row-id)
|
||||
(interactive "nPlease enter row id: ")
|
||||
(let (row-found)
|
||||
(dbe-rows (lambda (row)
|
||||
(when (equal (plist-get row 'id) row-id)
|
||||
(setq row-found row)) )
|
||||
:continue (lambda () (null row-found)))
|
||||
(message ">> Row found: %s" row-found)
|
||||
)
|
||||
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue