Move lang/org => org/*

Since lang/org has grown (and is expected to grow much, much more), it
has been given its own module category.

Concerns #129, #138
This commit is contained in:
Henrik Lissner 2017-07-05 02:33:41 +02:00
parent 576a91b66c
commit d2d4166b42
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
31 changed files with 774 additions and 721 deletions

View file

@ -1,27 +0,0 @@
;;; lang/org/+agenda.el -*- lexical-binding: t; -*-
(after! org-agenda
(setq-default
diary-file (concat doom-local-dir "diary.org")
;; calendar-mark-diary-entries-flag nil
org-agenda-dim-blocked-tasks nil
org-agenda-files (directory-files +org-dir t "\\.org$" t)
org-agenda-inhibit-startup t
org-agenda-skip-unavailable-files nil)
(after! recentf
;; Don't clobber recentf with agenda files
(defun +org-is-agenda-file (filename)
(cl-find (file-truename filename) org-agenda-files
:key #'file-truename
:test #'equal))
(add-to-list 'recentf-exclude #'+org-is-agenda-file))
;;
(map! :map org-agenda-mode-map
:e "<escape>" #'org-agenda-Quit
:e "m" #'org-agenda-month-view
:e "C-j" #'org-agenda-next-item
:e "C-k" #'org-agenda-previous-item
:e "C-n" #'org-agenda-next-item
:e "C-p" #'org-agenda-previous-item))

View file

@ -1,46 +0,0 @@
;;; lang/org/+attach.el -*- lexical-binding: t; -*-
;; FIXME Needs to be rewritten
;;
;; Initializes my own org-mode attachment system. I didn't like Org's native
;; one. Mine stores attachments in a global org .attach directory. It also
;; implements drag-and-drop file support and attachment icons. It also treats
;; images specially.
;;
;; To clean up unreferenced attachments, call `doom/org-cleanup-attachments'
(add-hook '+org-init-hook #'+org|init-attach t)
(defun +org|init-attach ()
(setq org-attach-directory +org-attachment-dir)
;; Don't track attachments in projectile or recentf
(push ".attach" projectile-globally-ignored-file-suffixes)
(after! recentf
(push (format "/%s.+$" (regexp-quote +org-attachment-dir)) recentf-exclude))
;; FIXME Use all-the-icons
;; (doom-fix-unicode '("FontAwesome" 13) ? ? ? ? ? ? ? ?)
;; Drag-and-drop support
(require 'org-download)
(setq-default org-download-image-dir +org-attachment-dir
org-download-heading-lvl nil
org-download-timestamp "_%Y%m%d_%H%M%S")
(setq org-download-screenshot-method
(cond (IS-MAC "screencapture -i %s")
(IS-LINUX "maim --opengl -s %s")))
;; Write download paths relative to current file
(advice-add #'org-download--dir-2 :override #'ignore)
(defun +org*download-fullname (path)
(file-relative-name path (file-name-directory (buffer-file-name))))
(advice-add #'org-download--fullname :filter-return #'+org*download-fullname)
;; Add another drag-and-drop handler that will handle anything but image files
(setq dnd-protocol-alist `(("^\\(https?\\|ftp\\|file\\|nfs\\):\\(//\\)?" . doom/org-download-dnd)
,@dnd-protocol-alist))
;; keybinds
;; (map! :leader :n "oa" (find-file-in! +org-attachment-dir))
)

View file

@ -1,52 +0,0 @@
;;; lang/org/+babel.el -*- lexical-binding: t; -*-
(add-hook '+org-init-hook #'+org|init-babel t)
(defun +org|init-babel ()
(setq org-confirm-babel-evaluate nil ; you don't need my permission
org-src-fontify-natively t ; make code pretty
org-src-preserve-indentation t
org-src-tab-acts-natively t
org-src-window-setup 'current-window
org-edit-src-content-indentation 0)
(org-babel-do-load-languages
'org-babel-load-languages
(mapcar (lambda (sym) (cons sym t))
'(calc
css
emacs-lisp
haskell
js
latex
ledger
lilypond
lisp
matlab
plantuml
python
restclient
ruby
rust
sh
sqlite
sql-mode
translate
)))
;; In a recent update, `org-babel-get-header' was removed from org-mode, which
;; is something a fair number of babel plugins use. So until those plugins
;; update...
(defun org-babel-get-header (params key &optional others)
(delq nil
(mapcar
(lambda (p) (if (funcall (if others #'not #'identity) (eq (car p) key)) p))
params)))
;; I prefer C-c C-c for confirming over the default C-c '
(map! :map org-src-mode-map "C-c C-c" #'org-edit-src-exit)
;; I know the keybindings, no need for the header line
(defun +org|src-mode-remove-header ()
(when header-line-format (setq header-line-format nil)))
(add-hook 'org-src-mode-hook #'+org|src-mode-remove-header))

View file

@ -1,62 +0,0 @@
;;; lang/org/+capture.el -*- lexical-binding: t; -*-
;; Sets up two `org-capture' workflows that I like:
;;
;; 1. The traditional way: invoking `org-capture' directly (or through a
;; command, like :org).
;;
;; 2. Through a org-capture popup frame that is invoked from outside Emacs (the
;; script is in ~/.emacs.d/bin). This lets me open an org-capture box
;; anywhere I can call org-capture, like, say, from qutebrowser, vimperator,
;; dmenu or a global keybinding.
(add-hook '+org-init-hook #'+org|init-capture t)
(defun +org|init-capture ()
"Set up a sane `org-capture' workflow."
(setq org-default-notes-file (concat +org-dir "notes.org"))
(setq org-capture-templates
'(;; TODO: New Task (todo)
;; TODO: New vocabulary word
("c" "Changelog" entry
(file+headline (expand-file-name "CHANGELOG.org" (doom/project-root)) "Unreleased")
"* %?")
;; ("p" "Project Notes" entry
;; (file+headline org-default-notes-file "Inbox")
;; "* %u %?\n%i" :prepend t)
;; ("m" "Major-mode Notes" entry
;; (file+headline org-default-notes-file "Inbox")
;; "* %u %?\n%i" :prepend t)
("n" "Notes" entry
(file+headline (concat +org-dir "notes.org") "Inbox")
"* %u %?\n%i" :prepend t)
;; ("v" "Vocab" entry
;; (file+headline (concat org-directory "topics/vocab.org") "Unsorted")
;; "** %i%?\n")
))
;; Allows the Emacs mini-frame (opened from an external shell script to run
;; and clean up properly) if the frame is named "org-capture".
(require 'org-capture)
(require 'org-protocol)
(defun +org*capture-init (&rest _)
"Makes sure the org-capture window is the only window in the frame."
(when (equal "org-capture" (frame-parameter nil 'name))
(setq mode-line-format nil)
(delete-other-windows)))
(advice-add #'org-capture :after #'+org*capture-init)
(defun +org|capture-finalize ()
"Closes the frame once org-capture is done."
(when (equal "org-capture" (frame-parameter nil 'name))
(when (and (featurep 'persp-mode) persp-mode)
(+workspace/delete (+workspace-current-name)))
(delete-frame)))
(add-hook 'org-capture-after-finalize-hook #'+org|capture-finalize))

View file

@ -1,28 +0,0 @@
;;; lang/org/+export.el -*- lexical-binding: t; -*-
;; My own, centralized exporting system as well.
(add-hook '+org-init-hook #'+org|init-export t)
(defun +org|init-export ()
(setq org-export-directory (expand-file-name ".export" +org-dir)
org-export-backends '(ascii html latex md)
org-export-with-toc t
org-export-with-author t)
;; Export to a central directory (why isn't this easier?)
(unless (file-directory-p org-export-directory)
(make-directory org-export-directory t))
(defun +org*export-output-file-name (args)
(unless (nth 2 args)
(setq args (append args (list org-export-directory))))
args)
(advice-add #'org-export-output-file-name :filter-args #'+org*export-output-file-name)
;; (require 'ox-pandoc)
;; (setq org-pandoc-options '((standalone . t) (mathjax . t) (parse-raw . t)))
;; keybinds
;; (map! :leader :n "oe" (find-file-in! org-export-directory))
)

View file

@ -1,26 +0,0 @@
;;; lang/org/+notebook.el -*- lexical-binding: t; -*-
;; While I program, write or plan, I want easy access to notes of various kinds,
;; such as major-mode/language specific notes, or project-specific notes. They
;; can be accessed via `+org/browse-notes-for-major-mode' and
;; `+org/browse-notes-for-project'.
;; (add-hook '+org-init-hook '+org|init-notebook t)
(defvar +org-notes-dir (concat +org-dir "notes/")
"The directory where the notes are kept.")
(defvar +org-code-notes-dir (concat +org-notes-dir "code/")
"The directory where programming notes and snippets are kept.")
(defvar +org-project-notes-dir (concat +org-notes-dir "projects/")
"The directory where project notes are kept.")
(defvar +org-notes-code-alist
'((js2-mode . "javascript"))
"An alist mapping certain modes (symbols) to their org notes directory name.
If a mode isn't here, it's guessed by stripping out the -mode suffix and
replacing '+' characters with 'p's.")
;; (defun +org|init-notebook ())

View file

@ -1,52 +0,0 @@
;;; lang/org/autoload/attach.el -*- lexical-binding: t; -*-
(defun +org--attach-icon (path)
(char-to-string (pcase (downcase (file-name-extension path))
("jpg" ?) ("jpeg" ?) ("png" ?) ("gif" ?)
("pdf" ?)
("ppt" ?) ("pptx" ?)
("xls" ?) ("xlsx" ?)
("doc" ?) ("docx" ?)
("ogg" ?) ("mp3" ?) ("wav" ?)
("mp4" ?) ("mov" ?) ("avi" ?)
("zip" ?) ("gz" ?) ("tar" ?) ("7z" ?) ("rar" ?)
(_ ?))))
;;;###autoload
(defun +org-cleanup-attachments ()
;; "Deletes any attachments that are no longer present in the org-mode buffer."
(let* ((attachments-local (+org-attachments))
(attachments (directory-files org-attach-directory t "^[^.]" t))
(to-delete (cl-set-difference attachments-local attachments)))
;; TODO
to-delete))
(defun +org-attachments ()
(unless (eq major-mode 'org-mode)
(user-error "Not an org buffer"))
(org-save-outline-visibility nil
(let ((attachments '())
element)
(when (and (file-directory-p org-attach-directory)
(> (length (file-expand-wildcards (expand-file-name "*" org-attach-directory))) 0))
(save-excursion
(goto-char (point-min))
(while (progn (org-next-link) (not org-link-search-failed))
(setq element (org-element-context))
(when-let (file (and (eq (org-element-type element) 'link)
(expand-file-name (org-element-property :path element))))
(when (and (string= (org-element-property :type element) "file")
(string= (concat (file-name-base (directory-file-name (file-name-directory file))) "/")
org-attach-directory)
(file-exists-p file))
(push file attachments))))))
(cl-remove-duplicates attachments))))
;;;###autoload
(defun +org-download-dnd (uri action)
(if (eq major-mode 'org-mode)
(doom:org-attach uri) ;; FIXME
(let ((dnd-protocol-alist
(rassq-delete-all '+org-download-dnd (copy-alist dnd-protocol-alist))))
(dnd-handle-one-url nil action uri))))

View file

@ -1,10 +0,0 @@
;;; lang/org/autoload/babel.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +org/edit-special-same-window ()
(interactive)
(let ((shackle-rules '(("^\\*Org Src" :align t :select t :regexp t :noesc t :same t))))
(call-interactively #'org-edit-special)
;; FIXME too tightly coupled with doom-buffer-mode
(when (fboundp 'solaire-mode)
(solaire-mode +1))))

View file

@ -1,11 +0,0 @@
;;; lang/org/autoload/capture.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +org/capture (&optional key string)
"Initializes the current frame as a pop-up `org-capture' frame."
(interactive)
(let ((key (or key "n"))
(string (unless (string-empty-p string) string)))
(if string
(org-capture-string string key)
(org-capture nil key))))

View file

@ -1,41 +0,0 @@
;;; lang/org/autoload/evil.el -*- lexical-binding: t; -*-
;;;###autoload (autoload '+org:capture "lang/org/autoload/evil" nil t)
(evil-define-operator +org:capture (&optional beg end)
"Send a selection to `doom/org-capture'."
:move-point nil :type inclusive
(interactive "<r>")
(org-capture-string
(when (and (evil-visual-state-p) beg end)
(buffer-substring beg end))))
;;;###autoload (autoload '+org:attach "lang/org/autoload/evil" nil t)
(evil-define-command +org:attach (&optional uri)
(interactive "<a>")
(unless (eq major-mode 'org-mode)
(user-error "Not in an org-mode buffer"))
(if uri
(let* ((rel-path (org-download--fullname uri))
(new-path (expand-file-name rel-path))
(image-p (image-type-from-file-name uri)))
(cond ((string-match-p (concat "^" (regexp-opt '("http" "https" "nfs" "ftp" "file")) ":/") uri)
(url-copy-file uri new-path))
(t (copy-file uri new-path)))
(unless new-path
(user-error "No file was provided"))
(if (evil-visual-state-p)
(org-insert-link nil (format "./%s" rel-path)
(concat (buffer-substring-no-properties (region-beginning) (region-end))
" " (doom--org-attach-icon rel-path)))
(insert (if image-p
(format "[[./%s]] " rel-path)
(format "%s [[./%s][%s]] "
(doom--org-attach-icon rel-path)
rel-path (file-name-nondirectory (directory-file-name rel-path))))))
(when (string-match-p (regexp-opt '("jpg" "jpeg" "gif" "png")) (file-name-extension rel-path))
(org-redisplay-inline-images)))
(let ((default-directory ".attach/"))
(if (file-exists-p default-directory)
(call-interactively 'find-file)
(user-error "No attachments")))))

View file

@ -1,36 +0,0 @@
;;; lang/org/autoload/notebook.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +org-mode-notes-dir ()
"Return the directory were `major-mode's org notes files are."
(if-let (name (cdr (assq major-mode +org-notes-code-alist)))
(expand-file-name (concat name "/") +org-code-notes-dir)
(let ((mode-name (s-replace "+" "p" (s-chop-suffix "-mode" (symbol-name major-mode)))))
(expand-file-name (concat mode-name "/") +org-code-notes-dir))))
(defun +org--explore-notes (dir)
(unless (file-directory-p dir)
(error "Directory doesn't exist: %s" dir))
(if (fboundp '+evil/neotree)
(neotree-dir dir)
(let ((default-directory dir))
(call-interactively (command-remapping 'find-file)))))
;;;###autoload
(defun +org/browse-notes-for-major-mode ()
"Browse org notes in `+org-code-notes-dir' in neotree, ido, ivy or helm --
whichever is available."
(interactive)
(let ((dir (+org-mode-notes-dir)))
(unless (file-in-directory-p dir +org-code-notes-dir)
(error "Invalid location for %s notes: %s" major-mode (abbreviate-file-name dir)))
(unless (file-directory-p dir)
(make-directory dir t))
(+org--explore-notes dir)))
;;;###autoload
(defun +org/browse-notes-for-project ()
"Browse org notes in `+org-project-notes-dir' in neotree, ido, ivy or helm --
whichever is available."
(interactive)
(+org--explore-notes +org-project-notes-dir))

View file

@ -1,216 +0,0 @@
;;; lang/org/autoload/org.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +org/indent ()
"Indent the current item (header or item). Otherwise, forward to
`self-insert-command'."
(interactive)
(cond ((org-at-item-p)
(org-indent-item-tree))
((org-at-heading-p)
(ignore-errors (org-demote)))
((org-in-src-block-p t)
(doom/dumb-indent))
(t
(call-interactively #'self-insert-command))))
;;;###autoload
(defun +org/indent-or-next-field-or-yas-expand ()
"Depending on the context either a) indent the current line, b) go the next
table field or c) run `yas-expand'."
(interactive)
(call-interactively
(cond ((and (bound-and-true-p yas-minor-mode)
(yas--templates-for-key-at-point))
#'yas-expand)
((org-at-table-p)
#'org-table-next-field)
(t
#'+org/indent))))
;;;###autoload
(defun +org/dedent ()
"Dedent the current item (header or item). Otherwise, forward to
`self-insert-command'."
(interactive)
(cond ((org-at-item-p)
(org-list-indent-item-generic
-1 nil
(save-excursion
(when (org-region-active-p)
(goto-char (region-beginning)))
(org-list-struct))))
((org-at-heading-p)
(ignore-errors (org-promote)))
(t
(call-interactively #'self-insert-command))))
;;;###autoload
(defun +org/dedent-or-prev-field ()
"Depending on the context either dedent the current item or go the previous
table field."
(interactive)
(call-interactively
(if (org-at-table-p)
#'org-table-previous-field
#'+org/dedent)))
;;;###autoload
(defun +org/insert-item (direction)
"Inserts a new heading, table cell or item, depending on the context.
DIRECTION can be 'above or 'below.
I use this instead of `org-insert-item' or `org-insert-heading' which are too
opinionated and perform this simple task incorrectly (e.g. whitespace in the
wrong places)."
(interactive)
(let* ((context (org-element-lineage
(org-element-context)
'(table table-row headline inlinetask item plain-list)
t))
(type (org-element-type context)))
(cond ((eq type 'item)
(let ((marker (org-element-property :bullet context))
(pad (save-excursion
(back-to-indentation)
(- (point) (line-beginning-position)))))
(pcase direction
('below
(goto-char (line-end-position))
(insert (concat "\n" (make-string pad ? ) marker)))
('above
(goto-char (line-beginning-position))
(insert (make-string pad ? ) marker)
(save-excursion (insert "\n")))))
(when (org-element-property :checkbox context)
(insert "[ ] ")))
((memq type '(table table-row))
(pcase direction
('below (org-table-insert-row t))
('above (+org/table-prepend-row-or-shift-up))))
((memq type '(headline inlinetask plain-list))
(let* ((subcontext (org-element-context))
(level (save-excursion
(org-back-to-heading)
(org-element-property
:level
(if (eq (org-element-type subcontext) 'headline)
subcontext
1)))))
(pcase direction
('below
(let ((at-eol (= (point) (1- (line-end-position)))))
(goto-char (line-end-position))
(org-end-of-subtree)
(insert (concat "\n"
(when (= level 1)
(if at-eol
(ignore (cl-incf level))
"\n"))
(make-string level ?*)
" "))))
('above
(org-back-to-heading)
(org-insert-heading)
(when (= level 1)
(save-excursion (evil-open-above 1))
(save-excursion (insert "\n")))))
(when (org-element-property :todo-type context)
(org-todo 'todo))))
(t (user-error "Not a valid list, heading or table")))
(when (bound-and-true-p evil-mode)
(evil-append-line 1))))
;;;###autoload
(defun +org/toggle-fold ()
"Toggle the local fold at the point (as opposed to cycling through all levels
with `org-cycle'). Also removes babel result blocks, if run from a code block."
(interactive)
(save-excursion
(org-beginning-of-line)
(cond ((org-in-src-block-p)
(org-babel-remove-result))
((org-at-heading-p)
(outline-toggle-children))
((org-at-item-p)
(let ((window-beg (window-start)))
(org-cycle)
(set-window-start nil window-beg))))))
;;;###autoload
(defun +org/toggle-checkbox ()
"Toggle the presence of a checkbox in the current item."
(interactive)
(org-toggle-checkbox '(4)))
;;;###autoload
(defun +org/dwim-at-point ()
"Do-what-I-mean at point. This includes following timestamp links, aligning
tables, toggling checkboxes/todos, executing babel blocks, previewing latex
fragments, opening links, or refreshing images."
(interactive)
(let* ((scroll-pt (window-start))
(context (org-element-context))
(type (org-element-type context)))
(cond
((memq type '(planning timestamp))
(org-follow-timestamp-link))
((memq type '(table table-row))
(if (org-element-property :tblfm (org-element-property :parent context))
(org-table-recalculate t)
(org-table-align)))
((org-element-property :checkbox (org-element-lineage context '(item) t))
(let ((match (and (org-at-item-checkbox-p) (match-string 1))))
(org-toggle-checkbox (if (equal match "[ ]") '(16)))))
((and (eq type 'headline)
(org-element-property :todo-type context))
(org-todo
(if (eq (org-element-property :todo-type context) 'done) 'todo 'done)))
((and (eq type 'headline)
(string= "ARCHIVE" (car-safe (org-get-tags))))
(org-force-cycle-archived))
((eq type 'headline)
(org-remove-latex-fragment-image-overlays)
(org-toggle-latex-fragment '(4)))
((eq type 'babel-call)
(org-babel-lob-execute-maybe))
((memq type '(src-block inline-src-block))
(org-babel-execute-src-block))
((memq type '(latex-fragment latex-environment))
(org-toggle-latex-fragment))
((eq type 'link)
(let ((path (org-element-property :path (org-element-lineage context '(link) t))))
(if (and path (image-type-from-file-name path))
(+org/refresh-inline-images)
(org-open-at-point))))
(t (+org/refresh-inline-images)))
(set-window-start nil scroll-pt)))
;;;###autoload
(defun +org/refresh-inline-images ()
"Refresh image previews in the current heading/tree."
(interactive)
(if (> (length org-inline-image-overlays) 0)
(org-remove-inline-images)
(org-display-inline-images
t t
(if (org-before-first-heading-p)
(line-beginning-position)
(save-excursion (org-back-to-heading) (point)))
(if (org-before-first-heading-p)
(line-end-position)
(save-excursion (org-end-of-subtree) (point))))))

View file

@ -1,66 +0,0 @@
;;; lang/org/autoload/tables.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +org/table-next-row ()
"Go to the next row (same column) in the current table."
(interactive)
(if (org-at-table-p)
(org-table-next-row)
(org-down-element)))
;;;###autoload
(defun +org/table-previous-row ()
"Go to the previous row (same column) in the current table. Before doing so,
re-align the table if necessary. (Necessary because org-mode has a
`org-table-next-row', but not `org-table-previous-row')"
(interactive)
(if (org-at-table-p)
(progn
(org-table-maybe-eval-formula)
(org-table-maybe-recalculate-line)
(if (and org-table-automatic-realign
org-table-may-need-update)
(org-table-align))
(let ((col (org-table-current-column)))
(beginning-of-line 0)
(when (or (not (org-at-table-p)) (org-at-table-hline-p))
(beginning-of-line))
(org-table-goto-column col)
(skip-chars-backward "^|\n\r")
(when (org-looking-at-p " ") (forward-char))))
(org-up-element)))
;;;###autoload
(defun +org/table-next-field ()
(interactive)
(if (org-at-table-p) (org-table-next-field) (org-end-of-line)))
;;;###autoload
(defun +org/table-previous-field ()
(interactive)
(if (org-at-table-p) (org-table-previous-field) (org-beginning-of-line)))
;;;###autoload
(defun +org/table-append-field-or-shift-right ()
(interactive)
(org-shiftmetaright)
(when (org-at-table-p) (org-metaright)))
;;;###autoload
(defun +org/table-prepend-field-or-shift-left ()
(interactive)
(if (org-at-table-p) (org-shiftmetaright) (org-shiftmetaleft)))
;;;###autoload
(defun +org/table-append-row-or-shift-down ()
(interactive)
(org-shiftmetadown)
(when (org-at-table-p) (org-metadown)))
;;;###autoload
(defun +org/table-prepend-row-or-shift-up ()
(interactive)
(if (org-at-table-p)
(org-shiftmetadown)
(org-shiftmetaup)))

View file

@ -1,10 +0,0 @@
;;; lang/org/autoload/util.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +org-get-property (name &optional _file) ; TODO Add FILE
"Get a propery from an org file."
(save-excursion
(goto-char 1)
(re-search-forward (format "^#\\+%s:[ \t]*\\([^\n]+\\)" (upcase name)) nil t)
(buffer-substring-no-properties (match-beginning 1) (match-end 1))))

View file

@ -1,396 +0,0 @@
;;; lang/org/config.el -*- lexical-binding: t; -*-
;; A few things you can expect
;; + `org-capture' in a popup frame (can be invoked from outside emacs too)
;; + Exported files are put in a centralized location (see
;; `org-export-directory')
;; + Inline latex previews (requires latex and dvipng programs)
;; + Inline code block execution for various languages
;; + TODO A simpler attachment system (with auto-deleting support) and
;; drag-and-drop for images and documents into org files
;; + TODO Custom links for class notes
;; + TODO An org-mode based CRM (including invoicing and pdf exporting) (see custom-crm)
;; + TODO A tag-based file browser reminiscient of Evernote and Quiver (there's neotree too!)
(defvar +org-init-hook nil
"TODO")
(add-hook 'org-load-hook #'+org|init)
(add-hook 'org-mode-hook #'+org|hook)
;; Custom variables
(defvar +org-dir (expand-file-name "~/work/org/")
"The directory where org files are kept.")
(defvaralias 'org-directory '+org-dir)
(defvar +org-attachment-dir ".attach/"
"Where to store attachments (relative to current org file).")
;; Ensure ELPA org is prioritized above built-in org.
(when-let (path (locate-library "org" nil doom--package-load-path))
(cl-pushnew (file-name-directory path) load-path))
(load! +agenda)
(load! +attach)
(load! +capture)
(load! +export)
(load! +notebook)
(load! +babel)
;;
;; Config
;;
(defun +org|hook ()
"Run everytime `org-mode' is enabled."
(setq line-spacing 1)
;; show-paren-mode causes problems for org-indent-mode
(make-local-variable 'show-paren-mode)
(setq show-paren-mode nil)
(visual-line-mode +1)
(when (and (featurep 'evil) evil-mode)
(evil-org-mode +1))
(require 'toc-org)
(toc-org-enable)
(unless org-agenda-inhibit-startup
;; My version of the 'overview' #+STARTUP option: expand first-level
;; headings.
(when (eq org-startup-folded t)
(outline-hide-sublevels 2))
;; If saveplace places the point in a folded position, unfold it on load
(when (outline-invisible-p)
(ignore-errors
(save-excursion
(outline-previous-visible-heading 1)
(org-show-subtree)))))
(defun +org|realign-table-maybe ()
"Auto-align table under cursor."
(when (org-at-table-p)
(save-excursion
(org-table-align))))
(add-hook 'evil-insert-state-exit-hook #'+org|realign-table-maybe nil t)
(defun +org|update-cookies ()
"Update counts in headlines (aka \"cookies\")."
(when (and buffer-file-name (file-exists-p buffer-file-name))
(org-update-statistics-cookies t)))
(add-hook 'before-save-hook #'+org|update-cookies nil t)
(add-hook 'evil-insert-state-exit-hook #'+org|update-cookies nil t))
(defun +org|init ()
"Initializes org core."
(define-minor-mode evil-org-mode
"Evil-mode bindings for org-mode."
:init-value nil
:lighter " !"
:keymap (make-sparse-keymap)
:group 'evil-org)
(setq-default
org-export-coding-system 'utf-8
org-todo-keywords
'((sequence "[ ](t)" "[-](p)" "[?](m)" "|" "[X](d)")
(sequence "TODO(T)" "|" "DONE(D)")
(sequence "IDEA(i)" "NEXT(n)" "ACTIVE(a)" "WAITING(w)" "LATER(l)"
"|" "CANCELLED(c)"))
;; Behavior
org-blank-before-new-entry '((heading . nil) (plain-list-item . auto))
org-catch-invisible-edits 'show
org-checkbox-hierarchical-statistics nil
org-enforce-todo-checkbox-dependencies nil
org-confirm-elisp-link-function nil
org-default-priority ?C
org-hierarchical-todo-statistics t
org-loop-over-headlines-in-active-region t
org-refile-use-outline-path t
org-special-ctrl-a/e t
;; Sorting/refiling
org-archive-location (concat +org-dir "/archived/%s::")
org-refile-targets '((nil . (:maxlevel . 2))) ; display full path in refile completion
;; Latex
org-highlight-latex-and-related '(latex)
org-latex-create-formula-image-program 'dvipng
org-latex-image-default-width ".9\\linewidth"
org-latex-preview-ltxpng-directory (concat doom-cache-dir "/ltxpng/")
org-latex-remove-logfiles nil
org-startup-with-latex-preview nil
;; org-latex-packages-alist
;; '(("" "gauss" t)
;; ("" "physics" t) TODO Install this)
)
(let ((ext-regexp (regexp-opt '("GIF" "JPG" "JPEG" "SVG" "TIF" "TIFF" "BMP" "XPM"
"gif" "jpg" "jpeg" "svg" "tif" "tiff" "bmp" "xpm"))))
(setq iimage-mode-image-regex-alist
`((,(concat "\\(`?file://\\|\\[\\[\\|<\\|`\\)?\\([-+./_0-9a-zA-Z]+\\."
ext-regexp "\\)\\(\\]\\]\\|>\\|'\\)?") . 2)
(,(concat "<\\(http://.+\\." ext-regexp "\\)>") . 1))))
;; enable gpg support
(require 'org-crypt)
(org-crypt-use-before-save-magic)
(setq org-tags-exclude-from-inheritance '("crypt")
org-crypt-key user-mail-address
epa-file-encrypt-to user-mail-address)
;; smartparens config
(sp-with-modes '(org-mode)
(sp-local-pair "\\[" "\\]" :post-handlers '(("| " "SPC")))
(sp-local-pair "\\(" "\\)" :post-handlers '(("| " "SPC")))
(sp-local-pair "$$" "$$" :post-handlers '((:add " | ")) :unless '(sp-point-at-bol-p))
(sp-local-pair "{" nil))
;; Initialize everything else
(+org|init-ui)
(+org|init-keybinds)
(run-hooks '+org-init-hook)
(+org|hacks))
(defun +org|init-ui ()
"Configures the UI for `org-mode'."
(setq-default
org-fontify-done-headline t
org-fontify-quote-and-verse-blocks t
org-fontify-whole-heading-line t
org-hide-emphasis-markers nil
org-hide-leading-stars t
org-hide-leading-stars-before-indent-mode t
org-image-actual-width nil
org-indent-indentation-per-level 2
org-pretty-entities nil
org-pretty-entities-include-sub-superscripts t
org-startup-folded t
org-startup-indented t
org-startup-with-inline-images nil
org-tags-column 0
org-use-sub-superscripts '{}
;; Appearance
outline-blank-line t
org-indent-mode-turns-on-hiding-stars t
org-adapt-indentation nil
org-cycle-separator-lines 1
org-cycle-include-plain-lists t
;; org-ellipsis "  "
org-entities-user '(("flat" "\\flat" nil "" "" "266D" "")
("sharp" "\\sharp" nil "" "" "266F" ""))
org-footnote-auto-label 'plain
org-hidden-keywords nil
;; LaTeX previews are too small and usually render to light backgrounds, so
;; this enlargens them and ensures their background (and foreground) match the
;; current theme.
org-format-latex-options
(plist-put org-format-latex-options :scale 1.5)
org-format-latex-options
(plist-put org-format-latex-options
:background (face-attribute (or (cadr (assq 'default face-remapping-alist))
'default)
:background nil t)))
(define-minor-mode +org-pretty-mode
"TODO"
:init-value nil
:lighter " *"
:group 'evil-org
(setq org-hide-emphasis-markers +org-pretty-mode)
(org-toggle-pretty-entities)
;; In case the above un-align tables
(org-table-map-tables 'org-table-align t))
;; Use ivy/helm if either is available
(when (or (featurep! :completion ivy)
(featurep! :completion helm))
(setq-default org-completion-use-ido nil
org-outline-path-complete-in-steps nil))
;; Custom fontification
(defsubst +org--tag-face (n)
(let ((kwd (match-string n)))
(or (and (equal kwd "#") 'org-tag)
(and (equal kwd "@") 'org-special-keyword))))
(defun +org|adjust-faces ()
"Correct (and improve) org-mode's font-lock keywords.
1. Re-set `org-todo' & `org-headline-done' faces, to make them respect
underlying faces.
2. Fontify item bullets
3. Fontify item checkboxes (and when they're marked done)"
(let ((org-todo (format org-heading-keyword-regexp-format
org-todo-regexp))
(org-done (format org-heading-keyword-regexp-format
(concat "\\(?:" (mapconcat #'regexp-quote org-done-keywords "\\|") "\\)"))))
(setq
org-font-lock-extra-keywords
(append (org-delete-all
`(("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
(0 (org-get-checkbox-statistics-face) t))
(,org-todo (2 (org-get-todo-face 2) t))
(,org-done (2 'org-headline-done t)))
org-font-lock-extra-keywords)
`((,org-todo (2 (org-get-todo-face 2) prepend))
(,org-done (2 'org-headline-done prepend))
;; Make checkbox statistic cookies respect underlying faces
("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
(0 (org-get-checkbox-statistics-face) prepend))
;; I like how org-mode fontifies checked TODOs and want this to extend to
;; checked checkbox items:
("^[ \t]*\\(?:[-+*]\\|[0-9]+[).]\\)[ \t]+\\(\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\[\\(?:X\\|\\([0-9]+\\)/\\2\\)\\][^\n]*\n\\)"
1 'org-headline-done prepend)
;; make plain list bullets stand out
("^ *\\([-+]\\|[0-9]+[).]\\) " 1 'org-list-dt append)
;; and separators/dividers
("^ *\\(-----+\\)$" 1 'org-meta-line)
;; custom #hashtags & @at-tags for another level of organization
;; TODO refactor this into a single rule
("\\s-\\(\\([#@]\\)[^ \n]+\\)" 1 (+org--tag-face 2)))))))
(add-hook 'org-font-lock-set-keywords-hook #'+org|adjust-faces)
;; The standard unicode characters are usually misaligned depending on the
;; font. This bugs me. Personally, markdown #-marks for headlines are more
;; elegant, so we use those.
(def-package! org-bullets
:commands org-bullets-mode
:init (add-hook 'org-mode-hook #'org-bullets-mode)
:config (setq org-bullets-bullet-list '("#"))))
(defun +org|init-keybinds ()
"Initialize my `org-mode' keybindings."
(map! (:map org-mode-map
"RET" #'org-return-indent
"C-j" nil
"C-k" nil)
(:map evil-org-mode-map
:n "RET" #'+org/dwim-at-point
;;
:ni "A-L" #'org-shiftmetaright
:ni "A-H" #'org-shiftmetaleft
:ni "A-K" #'org-shiftmetaup
:ni "A-J" #'org-shiftmetadown
;; Expand tables (or shiftmeta move)
:ni "C-S-l" #'+org/table-append-field-or-shift-right
:ni "C-S-h" #'+org/table-prepend-field-or-shift-left
:ni "C-S-k" #'+org/table-prepend-row-or-shift-up
:ni "C-S-j" #'+org/table-append-row-or-shift-down
;; Navigate table cells
:i "C-L" #'+org/table-next-field
:i "C-H" #'+org/table-previous-field
:i "C-K" #'+org/table-previous-row
:i "C-J" #'+org/table-next-row
:i "C-e" #'org-end-of-line
:i "C-a" #'org-beginning-of-line
:i [tab] #'+org/indent-or-next-field-or-yas-expand
:i [backtab] #'+org/dedent-or-prev-field
:n [tab] #'+org/toggle-fold
:v [backtab] #'+snippets/expand-on-region
:nv "j" #'evil-next-visual-line
:nv "k" #'evil-previous-visual-line
:i "M-a" (λ! (evil-visual-state) (org-mark-element))
:n "M-a" #'org-mark-element
:v "M-a" #'mark-whole-buffer
:ni [M-return] (λ! (+org/insert-item 'below))
:ni [S-M-return] (λ! (+org/insert-item 'above))
(:localleader
:n "RET" #'org-archive-subtree
:n "SPC" #'+org/toggle-checkbox
:n "/" #'org-sparse-tree
:n "=" #'org-align-all-tags
:n "?" #'org-tags-view
:n "a" #'org-agenda
:n "d" #'org-time-stamp
:n "D" #'org-deadline
:n "e" #'org-edit-special
:n "E" #'+org/edit-special-same-window
:n "n" (λ! (if (buffer-narrowed-p) (widen) (org-narrow-to-subtree)))
:n "r" #'org-refile
:n "R" (λ! (org-metaleft) (org-archive-to-archive-sibling)) ; archive to parent sibling
:n "s" #'org-schedule
:n "t" (λ! (org-todo (if (org-entry-is-todo-p) 'none 'todo)))
:v "t" (λ! (evil-ex-normal evil-visual-beginning evil-visual-end "\\t"))
:n "T" #'org-todo
:n "v" #'variable-pitch-mode
:nv "l" #'org-insert-link
:nv "L" #'org-store-link
;:n "w" #'writing-mode
;:n "x" #'+org/remove-link
)
;; TODO Improve folding bindings
:n "za" #'+org/toggle-fold
:n "zA" #'org-shifttab
:n "zc" #'outline-hide-subtree
:n "zC" (λ! (outline-hide-sublevels 1))
:n "zd" (lambda (&optional arg) (interactive "p") (outline-hide-sublevels (or arg 3)))
:n "zm" (λ! (outline-hide-sublevels 1))
:n "zo" #'outline-show-subtree
:n "zO" #'outline-show-all
:n "zr" #'outline-show-all
:m "]]" (λ! (org-forward-heading-same-level nil) (org-beginning-of-line))
:m "[[" (λ! (org-backward-heading-same-level nil) (org-beginning-of-line))
:m "]l" #'org-next-link
:m "[l" #'org-previous-link
:m "gh" #'outline-up-heading
:m "gj" #'org-forward-heading-same-level
:m "gk" #'org-backward-heading-same-level
:m "gl" (λ! (call-interactively #'outline-next-visible-heading) (outline-show-children))
:n "go" #'org-open-at-point
:n "gO" (λ! (let ((org-link-frame-setup (append '((file . find-file-other-window)) org-link-frame-setup))
(org-file-apps '(("\\.org$" . emacs)
(t . "open \"%s\""))))
(call-interactively #'org-open-at-point)))
:n "gQ" #'org-fill-paragraph
:m "$" #'org-end-of-line
:m "^" #'org-beginning-of-line
:n "<" #'org-metaleft
:n ">" #'org-metaright
:v "<" (λ! (org-metaleft) (evil-visual-restore))
:v ">" (λ! (org-metaright) (evil-visual-restore))
:n "-" #'org-cycle-list-bullet
:m "<tab>" #'org-cycle)))
(defun +org|hacks ()
"Getting org to behave."
;; Don't open separate windows
(cl-pushnew '(file . find-file) org-link-frame-setup)
;; Let OS decide what to do with files when opened
(setq org-file-apps
`(("\\.org$" . emacs)
(t . ,(cond (IS-MAC "open -R \"%s\"")
(IS-LINUX "xdg-open \"%s\"")))))
;; Remove highlights on ESC
(defun +org|remove-occur-highlights ()
(when (derived-mode-p 'org-mode)
(org-remove-occur-highlights)
t))
(add-hook '+evil-esc-hook #'+org|remove-occur-highlights))

View file

@ -1,20 +0,0 @@
;; -*- no-byte-compile: t; -*-
;;; lang/org/packages.el
;; NOTE This is an insecure source, but unavoidable if we want org 9.0+.
;; orgmode.org offers no secure access to this repo. If this bothers you,
;; comment out this `package!' block and download org-plus-contrib from
;; orgmode.org.
(package! org-plus-contrib :recipe (:fetcher git :url "http://orgmode.org/org-mode.git"))
(package! org-download)
(package! org-bullets :recipe (:fetcher github :repo "hlissner/org-bullets"))
(package! toc-org)
(package! ob-go)
(package! ob-mongo)
(package! ob-redis)
(package! ob-restclient)
(package! ob-rust :recipe (:fetcher github :repo "zweifisch/ob-rust"))
(package! ob-sql-mode)
(package! ob-translate)
;; (package! ox-pandox)