Last active
September 24, 2020 23:50
-
-
Save TakesxiSximada/05de904cd0c320733cae to your computer and use it in GitHub Desktop.
org-file-table.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun org-file-table-get-file-last-update (path) | |
(format-time-string "%Y-%m-%d" | |
(file-attribute-modification-time | |
(file-attributes path)))) | |
(defun org-file-table-get-elements (path) | |
(with-current-buffer (find-file-noselect path) | |
(org-element-parse-buffer))) | |
(defun org-file-table-get-keyword-alist (elms pattern) | |
(org-element-map elms 'keyword | |
(lambda (el) | |
(let ((key (org-element-property :key el))) | |
(when (string-match pattern key) | |
`(,key . ,(org-element-property :value el))))))) | |
(defun org-file-table-create-entry (path) | |
(let* ((elms (org-file-table-get-elements path)) | |
(keyword-alist (org-file-table-get-keyword-alist elms "\\\(TITLE\\\|CATEGORY\\\|ACTION\\\)")) | |
) | |
(setq testing keyword-alist) | |
(vector | |
(org-file-table-get-file-last-update path) | |
(or (cdr (or (assoc "CATEGORY" testing) | |
(assoc "TITLE" testing))) | |
"-") | |
(or (cdr (assoc "ACTION" keyword-alist)) "-") | |
path | |
))) | |
(defun org-file-table-get-file-list () | |
(seq-map-indexed (lambda (elt idx) | |
`(,idx ,(org-file-table-create-entry elt))) | |
org-agenda-files)) | |
(defun org-file-table-refresh () | |
"Refresh the images list." | |
(setq tabulated-list-entries (org-file-table-get-file-list))) | |
(defcustom org-file-table-list-default-sort-key '("Updated" . nil) | |
"Sort key for projects." | |
:group 'org-file-table-list | |
:type '(cons (choice | |
(const "Updated") | |
(const "Name") | |
(const "Action") | |
(const "Path") | |
(const "Id") | |
(const "Created") | |
(const "Size")) | |
(choice | |
(const :tag "Ascending" nil) | |
(const :tag "Descending" t)))) | |
(define-derived-mode org-file-table-list-mode tabulated-list-mode "Org Project" | |
"Major mode for handling a list of docker images." | |
(setq tabulated-list-format [("Updated" 10 t) ("Name" 20 t) ("Action" 30 t) ("Path" 80 t)]) | |
(setq tabulated-list-padding 3) | |
(setq tabulated-list-sort-key org-file-table-list-default-sort-key) | |
(add-hook 'tabulated-list-revert-hook 'org-file-table-refresh nil t) | |
(tabulated-list-init-header) | |
(tablist-minor-mode)) | |
(defun org-file-table-list () | |
"List docker images." | |
(interactive) | |
(pop-to-buffer "*Org Project*") | |
(org-file-table-list-mode) | |
(tablist-revert)) | |
(defun org-file-table-open-file () | |
(interactive) | |
(let ((filename (aref (tabulated-list-get-entry) 3))) | |
(find-file-existing filename))) | |
(defun org-file-table-menu-mark-x (&optional _num) | |
(interactive "p") | |
(tabulated-list-put-tag "x" t)) | |
(defun org-file-table-menu-unmark (&optional _num) | |
(interactive "p") | |
(tabulated-list-put-tag " " t)) | |
(bind-keys :map org-file-table-list-mode-map | |
("M-RET" . org-file-table-open-file) | |
("RET" . org-file-table-open-file) | |
("x" . org-file-table-menu-mark-x) | |
("u" . org-file-table-menu-unmark) | |
) | |
(provide 'org-file-table) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment