From 05fee51dc87d348939889d8913fc413207a9997b Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Tue, 28 Mar 2023 14:21:15 +0200 Subject: [PATCH] emacs: Add inventory functions --- emacs/doom/config.org | 51 +++++++++++++++++++++++++++++++++++++++++++ emacs/doom/init.el | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/emacs/doom/config.org b/emacs/doom/config.org index edcc4f5..7f4c87e 100644 --- a/emacs/doom/config.org +++ b/emacs/doom/config.org @@ -333,7 +333,58 @@ Return nil if on a link url, markup, html, or references." ;; '("\\.m$" . matlab-mode)) ;; (setq matlab-indent-function t) ;; (setq matlab-shell-command "matlab") + +(defun fd-inventory-transfer() + (interactive) + ()) #+end_src + +** Inventory +#+begin_src emacs-lisp :tangle yes +(defun fd-inventory-transfer() + (interactive) + (fd-inventory-transfer-check-if-valid-table) + (let ((location-from (string-trim (org-table-get 1 2))) + (location-to (string-trim (org-table-get 1 3))) + (item-name (string-trim (org-table-get-field 1)))) + (let (transfer-amount) + (setq transfer-amount (read-number (concat "Transfer from " location-from " to " location-to ": "))) + (fd-inventory-transfer-log-transfer transfer-amount item-name location-from location-to) + (fd-inventory-transfer-do-transfer transfer-amount) + (org-table-align) + ))) + +(defun fd-inventory-transfer-check-if-valid-table () + (unless (org-at-table-p) (error "You are not inside a table")) + (unless (and (string-match-p "^[[:blank:]]*-?[0-9]+[[:blank:]]*$" (org-table-get-field 2)) + (string-match-p "^[[:blank:]]*-?[0-9]+[[:blank:]]*$" (org-table-get-field 3))) + (error "Amounts in table are not numbers")) + (if (or (string= "" (org-table-get 1 2)) + (string= "" (org-table-get 1 3))) + (error "No valid table header"))) + +(defun fd-inventory-transfer-do-transfer(amount) + (let* ((amount-from-location (string-to-number (org-table-get-field 2))) + (amount-to-location (string-to-number (org-table-get-field 3))) + (amount-from-location-new (- amount-from-location amount)) + (amount-to-location-new (+ amount-to-location amount))) + (progn (org-table-get-field 2 (number-to-string amount-from-location-new)) + (org-table-get-field 3 (number-to-string amount-to-location-new))))) + +(defun fd-inventory-transfer-log-transfer(amount item-name from-location to-location) + (save-excursion + (let* ((log-heading-point (or (org-find-exact-headline-in-buffer "Transfer log" nil t) + (progn (goto-char (org-table-end)) + (org-insert-heading) + (insert "Transfer log") + (point))))) + (goto-char log-heading-point) + (forward-line) + (let ((message (concat "- " (format-time-string "%d.%m.%Y") ": *" (number-to-string amount) "* =" item-name "= from " from-location " to " to-location "\n"))) + (insert message)) + ))) +#+end_src + ** Python #+begin_src emacs-lisp :tangle yes diff --git a/emacs/doom/init.el b/emacs/doom/init.el index fd8eeb5..d71e7da 100644 --- a/emacs/doom/init.el +++ b/emacs/doom/init.el @@ -87,7 +87,7 @@ :tools ;;ansible biblio ; Writes a PhD for you (citation needed) - ;;debugger ; FIXME stepping through code, to help you add bugs + (debugger +lsp) ; FIXME stepping through code, to help you add bugs ;;direnv docker ;;editorconfig ; let someone else argue about tabs vs spaces