;; -*- lexical-binding: t; -*- ;;; init-org.el --- org initialization ;; ;; Filename: init-org.el ;; Description: Initialize Org, Toc-org, HTMLize, OX-GFM ;; Author: Mingde (Matthew) Zeng ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Fri Mar 15 11:09:30 2019 (-0400) ;; Version: 3.0 ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d org toc-org htmlize ox-gfm ;; Compatibility: emacs-version >= 26.1 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Commentary: ;; ;; This initializes org toc-org htmlize ox-gfm ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or (at ;; your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Code: ;; OrgPac (use-package org :ensure t ;; :defer t :bind (("C-c l" . org-store-link) ("C-c a" . org-agenda) ("C-c c" . org-capture) (:map org-mode-map (("C-c C-p" . eaf-org-export-to-pdf-and-open) ("C-c ;" . nil) ("C-c C-." . org-time-stamp-inactive) ))) :custom (org-directory "~/Documents/Org-mode/") (org-default-notes-file (concat org-directory "/agenda/notes.org")) (org-log-done 'time) (calendar-latitude 43.65107) ;; Prerequisite: set it to your location, currently default: Toronto, Canada (calendar-longitude -79.347015) ;; Usable for M-x `sunrise-sunset' or in `org-agenda' (org-export-backends (quote (ascii html icalendar latex md odt))) (org-use-speed-commands t) (org-confirm-babel-evaluate 'nil) (org-latex-listings-options '(("breaklines" "true"))) (org-latex-listings 'minted) (org-latex-src-block-backend 'minted) (org-export-with-LaTeX-fragments t) (org-deadline-warning-days 7) (org-todo-keywords '((sequence "TODO(t)" "IN-PROGRESS(p)" "REVIEW(r)" "PAUSED" "|" "DONE(d)" "CANCELED(c@)") (sequence "ISSUE(i)" "BUG(b)" "KNOWN(k)" "|" "FIXED(f)"))) (org-todo-keyword-faces '(("TODO" . "red") ("DONE" . "green") ("IN-PROGRESS" . "lightblue") ("REVIEW" . "magenta") ("PAUSED" . "magenta") ("CANCELED" . "gray") ("ISSUE" . "red") ("BUG" . "orange") ("KNOWN" . "yellow") ("FIXED" . "green"))) (org-agenda-window-setup 'other-window) (org-startup-indented t) (org-latex-pdf-process '("lualatex -shell-escape -interaction nonstopmode -output-directory %o %f" "lualatex -shell-escape -interaction nonstopmode -output-directory %o %f")) (add-to-list 'org-latex-classes '("intemo-report" "\\documentclass[a4paper,oneside]{intemo-org-report} [NO-DEFAULT-PACKAGES] [PACKAGES] [EXTRA]" ("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))) (add-to-list 'org-latex-classes '("intemo-article" "\\documentclass[a4paper,oneside]{intemo-org-article} [NO-DEFAULT-PACKAGES] [PACKAGES] [EXTRA]" ("\\section{%s}" . "\\chapter*{%s}") ("\\subsection{%s}" . "\\section*{%s}") ("\\subsubsection{%s}" . "\\subsection*{%s}") ) ) :custom-face (org-agenda-current-time ((t (:foreground "spring green")))) :config (add-to-list 'org-latex-packages-alist '("" "listings")) (unless (version< org-version "9.2") (require 'org-tempo)) (setq org-agenda-files (list (concat org-directory "agenda/"))) (org-babel-do-load-languages 'org-babel-load-languages '(;; other Babel languages (C . t) (python . t) (plantuml . t))) (defun org-export-toggle-syntax-highlight () "Setup variables to turn on syntax highlighting when calling `org-latex-export-to-pdf'." (interactive) (setq-local org-latex-listings 'minted) (add-to-list 'org-latex-packages-alist '("newfloat" "minted"))) (defun org-table-insert-vertical-hline () "Insert a #+attr_latex to the current buffer, default the align to |c|c|c|, adjust if necessary." (interactive) (insert "#+attr_latex: :align |c|c|c|")) ;; Modify export direcotry (defun org-export-output-file-name-modified (orig-fun extension &optional subtreep pub-dir) (unless pub-dir (setq pub-dir "org-exported") (unless (file-directory-p pub-dir) (make-directory pub-dir))) (apply orig-fun extension subtreep pub-dir nil)) (advice-add 'org-export-output-file-name :around #'org-export-output-file-name-modified) (setq org-capture-templates '(("t" "Personal todo" entry (file+headline +org-capture-todo-file "Inbox") "* TODO %? :@general:" :prepend t) ("f" "Empty" entry (file+headline +org-capture-todo-file "Inbox") "* TODO %?" :prepend t) ("w" "WATCH" entry (file+headline +org-capture-todo-file "Inbox") "* TODO %? :@watch:" :prepend t) ("r" "READ" entry (file+headline +org-capture-todo-file "Inbox") "* TODO %? :@read:" :prepend t) ("c" "CHECK" entry (file+headline +org-capture-todo-file "Inbox") "* TODO %? :@check:" :prepend t) ("i" "Got a new idea?" entry (file+headline +org-capture-todo-file "Inbox") "* TODO %? :@idea:" :prepend t) ("j" "Journal" entry (file+headline +org-capture-journal-file "Posts") "*** %?\n:DATE:\n%<[%Y-%m-%d %a %H:%M]>\n:END:" :prepend t))) (setq org-agenda-custom-commands '( ("f" "Today Tasks" ( (agenda "" ((org-agenda-span 4))) (org-ql-block '(and (todo "TODO") (or (scheduled) (deadline))) ((org-ql-block-header "Soon"))) )) ("v" "General Tasks" ( (agenda "" ((org-agenda-span 4))) (org-ql-block '(and (priority "A") (not (deadline)) (not (scheduled))) ((org-ql-block-header "High-priority tasks"))) (org-ql-block '(and (todo "TODO") (tags "@idea") (not (tags "@later")) (not (deadline)) (not (scheduled))) ((org-ql-block-header "Looking for an idea?"))) (org-ql-block '(and (todo "TODO") (tags "@write") (not (tags "@later")) (not (tags "project")) (not (deadline)) (not (scheduled))) ((org-ql-block-header "Write something:"))) (org-roam-ql-agenda-block '(and (todo "TODO"))) )))) ) ;; -OrgPac ;; OrgRoamPac (use-package org-roam :ensure t :demand t ;; Ensure org-roam is loaded by default :custom (org-roam-directory "~/Documents/Org-mode/brain") (org-roam-completion-everywhere t) :bind (("C-c n l" . org-roam-buffer-toggle) ("C-c n f" . org-roam-node-find) ("C-c n i" . org-roam-node-insert) ("C-c n I" . org-roam-node-insert-immediate) ("C-c n t" . my/org-roam-capture-task) :map org-mode-map ("C-M-i" . completion-at-point) :map org-roam-dailies-map ("Y" . org-roam-dailies-capture-yesterday) ("T" . org-roam-dailies-capture-tomorrow)) :bind-keymap ("C-c n d" . org-roam-dailies-map) :config (require 'org-roam-dailies) ;; Ensure the keymap is available (org-roam-db-autosync-mode)) (defun my/org-roam-filter-by-tag (tag-name) (lambda (node) (member tag-name (org-roam-node-tags node)))) (defun my/org-roam-list-notes-by-tag (tag-name) (mapcar #'org-roam-node-file (seq-filter (my/org-roam-filter-by-tag tag-name) (org-roam-node-list)))) (defun my/org-roam-refresh-agenda-list () (interactive) (setq org-agenda-files (my/org-roam-list-notes-by-tag "Project"))) ;; Build the agenda list the first time for the session (my/org-roam-refresh-agenda-list) (defun my/org-roam-project-finalize-hook () "Adds the captured project file to `org-agenda-files' if the capture was not aborted." ;; Remove the hook since it was added temporarily (remove-hook 'org-capture-after-finalize-hook #'my/org-roam-project-finalize-hook) ;; Add project file to the agenda list if the capture was confirmed (unless org-note-abort (with-current-buffer (org-capture-get :buffer) (add-to-list 'org-agenda-files (buffer-file-name))))) ;;; This does not work, something wrong with template.. ;; (defun my/org-roam-find-project () ;; (interactive) ;; ;; Add the project file to the agenda after capture is finished ;; (add-hook 'org-capture-after-finalize-hook #'my/org-roam-project-finalize-hook) ;; ;; Select a project file to open, creating it if necessary ;; (org-roam-node-find ;; nil ;; nil ;; (my/org-roam-filter-by-tag "Project") ;; :templates '(("p" "project" plain "* Goals\n\n%?\n\n* Tasks\n\n* TODO Add initial tasks\n\n* Dates\n\n" ;; :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n#+category: ${title}\n#+filetags: Project") ;; :unnarrowed t)))) (defun my/org-roam-capture-task () (interactive) ;; Add the project file to the agenda after capture is finished (add-hook 'org-capture-after-finalize-hook #'my/org-roam-project-finalize-hook) ;; Capture the new task, creating the project file if necessary (org-roam-capture- :node (org-roam-node-read nil (my/org-roam-filter-by-tag "Project")) :templates '(("p" "project" plain "** TODO %?" :if-new (file+head+olp "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n#+category: ${title}\n#+filetags: Project" ("Tasks")))))) ;; ~OrgRoamPac (use-package org-roam-ql :after (org-roam) :bind ((:map org-roam-mode-map ;; Have org-roam-ql's transient available in org-roam-mode buffers ("v" . org-roam-ql-buffer-dispatch) :map minibuffer-mode-map ;; Be able to add titles in queries while in minibuffer. ;; This is similar to `org-roam-node-insert', but adds ;; only title as a string. ("C-c n i" . org-roam-ql-insert-node-title)))) ;; -OrgRoamPac ;; TocOrgPac (use-package toc-org :hook (org-mode . toc-org-mode)) ;; -TocOrgPac ;; HTMLIZEPac (use-package htmlize :defer t) ;; -HTMLIZEPac ;; OXGFMPac (use-package ox-gfm :defer t) ;; -OXGFMPac ;; PlantUMLPac (use-package plantuml-mode :defer t :custom (org-plantuml-jar-path (expand-file-name "~/tools/plantuml/plantuml.jar"))) ;; -PlantUMLPac ;; Org-ql (use-package org-ql :defer t ) ;; -Org-ql (provide 'init-org) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; init-org.el ends here