Last active
January 11, 2021 02:06
-
-
Save Zyrohex/f98b5888b87d0323793567a02ba3a164 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 nm/convert-filename-format (&optional time-p folder-path) | |
"Prompts user for filename and directory, and returns the value in a cleaned up format. | |
If TIME-P is t, then includes date+time stamp in filename, FOLDER-PATH is the folder | |
location to search for files." | |
(let* ((file (replace-in-string " " "-" (downcase (read-file-name "select file: " (if folder-path (concat folder-path) org-directory)))))) | |
(if (file-exists-p file) | |
(concat file) | |
(if (s-ends-with? ".org" file) | |
(concat (format "%s%s" (file-name-directory file) (if time-p (concat (format-time-string "%Y%m%d%H%M%S-") (file-name-nondirectory (downcase file))) | |
(concat (file-name-nondirectory (downcase file)))))) | |
(concat (format "%s%s.org" (file-name-directory file) (if time-p (concat (format-time-string "%Y%m%d%H%M%S-") (file-name-nondirectory (downcase file))) | |
(concat (file-name-nondirectory (downcase file)))))))))) | |
(defun nm/find-file-or-create (time-p folder-path &optional type header) | |
"Creates a new file, TYPE can be PROJ or NOTE to insert their relative templates | |
if header is a string then it will search for that headline, or else create it. | |
time-p if t, will pass in formatted time-string into the filename and folder-path | |
is the default path when prompting the user for a filename." | |
(interactive) | |
(let* ((file (nm/convert-filename-format time-p folder-path))) | |
(if (file-exists-p file) | |
(find-file file) | |
(when (equal "note" type) (find-file file) | |
(insert (format "%s\n%s\n%s\n\n" | |
(downcase (format "#+title: %s" (replace-in-string "-" " " (replace-regexp-in-string "[0-9]+-" "" (replace-in-string ".org" "" (file-name-nondirectory file)))))) | |
(downcase (concat "#+author: " user-full-name)) | |
(downcase (concat "#+email: " user-mail-address))))) | |
(when (equal "project" type) (find-file file) | |
(insert (format "%s\n%s\n%s\n\n* Requirements\n\n* Timeframe\n\n* Notes\n\n* Tasks\n" | |
(downcase (format "#+title: %s" (replace-in-string "-" " " (replace-regexp-in-string "[0-9]+-" "" (replace-in-string ".org" "" (file-name-nondirectory file)))))) | |
(downcase (concat "#+author: " user-full-name )) | |
(downcase (concat "#+email: " user-mail-address))))) | |
(when (equal nil type) (find-file))) | |
;; If user passes in header argument, search for it and if the search fails to find the header, then create it. | |
(if header (unless (progn (goto-char (point-min)) (re-search-forward (format "^*+ %s" header))) | |
(goto-char (point-max)) | |
(newline) | |
(insert (format "* %s" header)) | |
(newline))))) | |
(defun nm/create-notes-file () | |
"Function for creating a notes file under org-capture-templates." | |
(nm/find-file-or-create t org-directory "note")) | |
(defun nm/find-project-task () | |
"Function for creating a project file under org-capture-templates." | |
(nm/find-file-or-create t "~/projects/orgmode/gtd/projects" "project" "Tasks")) | |
(defun nm/find-project-timeframe () | |
"Function for creating a project file under org-capture-templates." | |
(nm/find-file-or-create t "~/projects/orgmode/gtd/projects" "project" "Timeframe")) | |
(defun nm/find-project-requirement () | |
"Function for creating a project file under org-capture-templates." | |
(nm/find-file-or-create t "~/projects/orgmode/gtd/projects" "project" "Requirements")) | |
(defun nm/find-project-note () | |
"Function for creating a project file under org-capture-templates." | |
(nm/find-file-or-create t "~/projects/orgmode/gtd/projects" "project" "Notes")) | |
(setq org-capture-templates '(("c" " checklist") | |
("g" " gtd") | |
("b" " bullet journal") | |
("n" " notes") | |
("r" " resources") | |
("p" " projects"))) | |
(push '("pt" " task" entry (function nm/find-project-task) "* REFILE %^{task} %^g" :empty-lines-before 1 :empty-lines-after 1) org-capture-templates) | |
(push '("pr" " define requirements" item (function nm/find-project-requirement) "" :empty-lines-before 1 :empty-lines-after 1) org-capture-templates) | |
(push '("pn" " note" entry (function nm/find-project-note) "* " :empty-lines-before 1 :empty-lines-after 1) org-capture-templates) | |
(push '("pf" " timeframe" entry (function nm/find-project-timeframe) "* %^{timeframe entry} [%<%Y-%m-%d %a %H:%M>]\n:PROPERTIES:\n:CREATED: %U\n:END:\n%?" :empty-lines-before 1 :empty-lines-after 1) org-capture-templates) | |
(push '("cs" " simple checklist" checkitem (file+olp "~/projects/orgmode/gtd/tasks.org" "Checklists") "- [ ] %?") org-capture-templates) | |
(push '("cd" " checklist [date]" checkitem (file+function "~/projects/orgmode/gtd/tasks.org" nm/org-capture-to-task-file) "- [ ] %?") org-capture-templates) | |
(push '("gs" " simple task" entry (file+olp "~/projects/orgmode/gtd/tasks.org" "Inbox") "* REFILE %^{task} %^g\n:PROPERTIES:\n:CREATED: %U\n:END:\n") org-capture-templates) | |
(push '("gk" " task [kill-ring]" entry (file+olp "~/projects/orgmode/gtd/tasks.org" "Inbox") "* REFILE %^{task} %^g\n:PROPERTIES:\n:CREATED: %U\n:END:\n%c") org-capture-templates) | |
(push '("gg" " task with goal" entry (file+olp "~/projects/orgmode/gtd/tasks.org" "Inbox") "* REFILE %^{task}%^{GOAL}p %^g\n:PROPERTIES:\n:CREATED: %U\n:END:\n") org-capture-templates) | |
(push '("bt" " bullet task" entry (file+function "~/projects/orgmode/gtd/bullet.org" nm/capture-bullet-journal) "* REFILE %^{task} %^g\n:PROPERTIES:\n:CREATED: %U\n:END:\n" :empty-lines-before 1 :empty-lines-after 1) org-capture-templates) | |
(push '("nj" " journal" entry (function nm/capture-to-journal) "* %^{entry}\n:PROPERTIES:\n:CREATED: %U\n:END:\n%?") org-capture-templates) | |
(push '("na" " append" plain (function nm/org-capture-log) " *Note added:* [%<%Y-%m-%d %a %H:%M>]\n%?" :empty-lines-before 1 :empty-lines-after 1) org-capture-templates) | |
(push '("nn" " new note" plain (function nm/create-notes-file) "%?" :unnarrowed t :empty-lines-before 1 :empty-lines-after 1) org-capture-templates) | |
(push '("rr" " research literature" entry (file+function "~/projects/orgmode/gtd/websources.org" nm/enter-headline-websources) "* READ %(get-page-title (current-kill 0))") org-capture-templates) | |
(push '("rf" " rss feed" entry (file+function "~/projects/orgmode/elfeed.org" nm/return-headline-in-file) "* %^{link}") org-capture-templates) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment