From cd217883df6ef6e89ac688754b134830fcb43e15 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Thu, 24 Aug 2023 06:53:17 +0700 Subject: [PATCH] Emacs: First org-capture templates for Leetcode --- .config/emacs/init.org | 67 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/.config/emacs/init.org b/.config/emacs/init.org index 923ce07..37ebbc4 100644 --- a/.config/emacs/init.org +++ b/.config/emacs/init.org @@ -1553,6 +1553,7 @@ When called interactively, prompt for BUFFER." ("b" "~/Documents/Books/" "Books") ("p" "~/Development/" "Dev") ("t" "~/TYCS/" "Teachyourselfcs") + ("n" "~/Notes/" "OrgNotes") ("r" "~/Repositories" "Repos") ("B" "~/pCloudDrive/" "pCloud"))) @@ -1837,7 +1838,6 @@ the right frame, I'm going to use the frame's name to close and remove the hook (add-hook 'delete-frame-functions #'joe/kill-vterm-scratch) (add-hook 'kill-buffer-hook #'joe/kill-frame)))) #+end_src - ** Undo Fu #+begin_src emacs-lisp (require 'undo-fu) @@ -2295,6 +2295,7 @@ and there's no need for a middle-man when it's already been implemented. (defun joe/org-init () (setq org-todo-keywords '((sequence "TODO" "IN-PROGRESS" "|" "DONE" "BACKLOG"))) (setq org-agenda-files '("~/Notes/Schedule.org")) + (setq org-directory "~/Notes/") (org-babel-do-load-languages 'org-babel-load-languages @@ -2356,16 +2357,64 @@ and there's no need for a middle-man when it's already been implemented. (evil-define-key 'normal calendar-mode-map (kbd "RET") #'org-calendar-select) -(defun org-capture-today() - (concat "<" (format-time-string "%Y-%m-%d") ">")) -;; (setq org-capture-templates -;; '(("d" "New Coding Challenge" entry -;; (file+headline "~/Notes/Daily.org") -;; (concat "* Today's Date" "\n" -;; "** Schedule" "\n" -;; "** Notes & Resources" "\n")))) +#+end_src +** Org-capture +#+begin_src emacs-lisp +;; (defun my-org-capture-today () +;; (concat "<" (format-time-string "%Y-%m-%d %a") ">")) + +(defun joe/capture-leetcode-template () + (mapconcat + 'identity + '("#+TITLE: Leetcode %?: " + "#+AUTHOR: Joseph Ferano" + "#+STARTUP: show2levels" + "#+TAGS: " + "" + "* Python Solution :python:" + ":PROPERTIES:" + ":CompletionTime: 7m" + ":TimeComplexity: O(logn)" + ":MemoryComplexity: O(h)" + ":END:" + ":LOGBOOK:" + ":END:" + "" + "#+begin_src python" + "#+end_src" + "** Review" + "** Techniques & Patterns") + "\n")) + +(defun joe/capture-leetcode-newfile () + (let* ((title (read-string "Title: ")) + (title (string-replace " " "-" title)) + (title (string-replace "." "" title))) + (expand-file-name (format "%s.org" title) "~/Development/coding-challenges/leetcode/"))) + + +(setq org-capture-templates + `( + ("l" "Leetcode Solution" plain + (function ,(lambda () (find-file (joe/capture-leetcode-newfile)))) + #'joe/capture-leetcode-template) + ("d" "Demo of adding to a daily.org" entry + ;; A relative file name is interpreted based on + ;; `org-directory'. + (file+headline "/tmp/daily.org" "Daily notes") + #'my-org-capture-daily-note) + + ("D" "Demo of adding to a daily.org with a prompt" entry + ;; A relative file name is interpreted based on + ;; `org-directory'. + (file+headline "/tmp/daily.org" "Daily notes") + ,(concat + "** " "%^t" "\n" + "*** Schedule" "\n" + "*** Notes" "\n" + "*** Resources" "\n")))) #+end_src ** Magit