lang/org: major refactor & add org-fancy-priorities package

- Fixes an issue where evil bindings weren't working in org-mode
- Significantly slims down on unnecessary keybinds
- Remove +org-init-keybinds-for-evil-h hook and reli more on our new
  evil-org fork, which has upstreamed some of our changes.
- Documents undocumented functions, remove unnused ones, and reorganize
  org's autoload libraries by convention.
- Adds org-fancy-priorities for more elegant (and subtle) priority
  display than ugly [#A] tags.
This commit is contained in:
Henrik Lissner 2019-10-25 20:00:06 -04:00
parent 9f8277b2c4
commit 5f00db871e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
12 changed files with 600 additions and 601 deletions

View file

@ -3,7 +3,7 @@
;;;###autoload ;;;###autoload
(defun +org-dragndrop-download-dnd-fn (uri action) (defun +org-dragndrop-download-dnd-fn (uri action)
"TODO" "Handle file links and base64 data uris."
(if (eq major-mode 'org-mode) (if (eq major-mode 'org-mode)
(+org-attach/uri uri) (+org-attach/uri uri)
(let ((dnd-protocol-alist (let ((dnd-protocol-alist

View file

@ -1,15 +1,20 @@
;;; lang/org/autoload/contrib-present.el -*- lexical-binding: t; -*- ;;; lang/org/autoload/contrib-present.el -*- lexical-binding: t; -*-
;;;###if (featurep! +present) ;;;###if (featurep! +present)
(defvar +org-present--overlays nil) ;;
;;;###autoload ;;; Helpers
(defun +org-present/start ()
"TODO" (defun +org-present--cleanup-org-tree-slides-mode ()
(interactive) (unless (cl-loop for buf in (doom-buffers-in-mode 'org-mode)
(unless (derived-mode-p 'org-mode) if (buffer-local-value 'org-tree-slide-mode buf)
(error "Not in an org buffer")) return t)
(call-interactively #'org-tree-slide-mode) (org-tree-slide-mode -1)
(add-hook 'kill-buffer-hook #'+org-present--cleanup-org-tree-slides-mode)) (remove-hook 'kill-buffer-hook #'+org-present--cleanup-org-tree-slides-mode)))
(defun +org-present--make-invisible (beg end)
(let ((overlay (make-overlay beg end)))
(push overlay +org-present--overlays)
(overlay-put overlay 'invisible '+org-present)))
;; ;;
@ -17,6 +22,7 @@
;;;###autoload ;;;###autoload
(defun +org-present-add-overlays-h () (defun +org-present-add-overlays-h ()
"TODO"
(add-to-invisibility-spec '(+org-present)) (add-to-invisibility-spec '(+org-present))
(save-excursion (save-excursion
;; hide org-mode options starting with #+ ;; hide org-mode options starting with #+
@ -32,11 +38,13 @@
;;;###autoload ;;;###autoload
(defun +org-present-remove-overlays-h () (defun +org-present-remove-overlays-h ()
"TODO"
(mapc #'delete-overlay +org-present--overlays) (mapc #'delete-overlay +org-present--overlays)
(remove-from-invisibility-spec '(+org-present))) (remove-from-invisibility-spec '(+org-present)))
;;;###autoload ;;;###autoload
(defun +org-present-detect-slide-h () (defun +org-present-detect-slide-h ()
"TODO"
(outline-show-all) (outline-show-all)
(if (member "title" (org-get-tags)) (if (member "title" (org-get-tags))
(text-scale-set 10) (text-scale-set 10)
@ -48,6 +56,7 @@
(defvar cwm-centered-window-width) (defvar cwm-centered-window-width)
;;;###autoload ;;;###autoload
(defun +org-present-init-org-tree-window-h () (defun +org-present-init-org-tree-window-h ()
"TODO"
"Set up the org window for presentation." "Set up the org window for presentation."
(doom/window-maximize-buffer) (doom/window-maximize-buffer)
(let ((arg (if org-tree-slide-mode +1 -1))) (let ((arg (if org-tree-slide-mode +1 -1)))
@ -75,16 +84,14 @@
;; ;;
;;; Helpers ;;; Commands
(defun +org-present--cleanup-org-tree-slides-mode () (defvar +org-present--overlays nil)
(unless (cl-loop for buf in (doom-buffers-in-mode 'org-mode) ;;;###autoload
if (buffer-local-value 'org-tree-slide-mode buf) (defun +org-present/start ()
return t) "TODO"
(org-tree-slide-mode -1) (interactive)
(remove-hook 'kill-buffer-hook #'+org-present--cleanup-org-tree-slides-mode))) (unless (derived-mode-p 'org-mode)
(error "Not in an org buffer"))
(defun +org-present--make-invisible (beg end) (call-interactively #'org-tree-slide-mode)
(let ((overlay (make-overlay beg end))) (add-hook 'kill-buffer-hook #'+org-present--cleanup-org-tree-slides-mode))
(push overlay +org-present--overlays)
(overlay-put overlay 'invisible '+org-present)))

View file

@ -1,19 +1,5 @@
;;; lang/org/autoload/org-attach.el -*- lexical-binding: t; -*- ;;; lang/org/autoload/org-attach.el -*- lexical-binding: t; -*-
(defun +org-attach--icon (path)
(char-to-string
(pcase (downcase (file-name-extension path))
((or "jpg" "jpeg" "png" "gif") ?)
("pdf" ?)
((or "ppt" "pptx") ?)
((or "xls" "xlsx") ?)
((or "doc" "docx") ?)
((or "ogg" "mp3" "wav" "aiff" "flac") ?)
((or "mp4" "mov" "avi") ?)
((or "zip" "gz" "tar" "7z" "rar") ?)
(_ ?))))
;; ;;
(defvar +org-attachments nil (defvar +org-attachments nil
"A list of all indexed attachments in `org-directory'.") "A list of all indexed attachments in `org-directory'.")
@ -21,7 +7,7 @@
(defvar +org-attachments-files nil (defvar +org-attachments-files nil
"A list of all attachments in `org-attach-id-dir'.") "A list of all attachments in `org-attach-id-dir'.")
(defun +org-attachments--list (&optional beg end) (defun +org-list-attachments (&optional beg end)
"Return a list of all attachment file names in the current buffer between BEG "Return a list of all attachment file names in the current buffer between BEG
and END (defaults to `point-min' and `point-max')." and END (defaults to `point-min' and `point-max')."
(let ((case-fold-search t) (let ((case-fold-search t)
@ -39,6 +25,21 @@ and END (defaults to `point-min' and `point-max')."
(push (file-name-nondirectory link) attachments)))))) (push (file-name-nondirectory link) attachments))))))
(cl-delete-duplicates attachments :test #'string=))) (cl-delete-duplicates attachments :test #'string=)))
;;;###autoload
(defun +org-attach-icon-for (path)
(char-to-string
(pcase (downcase (file-name-extension path))
((or "jpg" "jpeg" "png" "gif") ?)
("pdf" ?)
((or "ppt" "pptx") ?)
((or "xls" "xlsx") ?)
((or "doc" "docx") ?)
((or "ogg" "mp3" "wav" "aiff" "flac") ?)
((or "mp4" "mov" "avi") ?)
((or "zip" "gz" "tar" "7z" "rar") ?)
(_ ?))))
;;;###autoload ;;;###autoload
(defun +org-attach/sync (arg) (defun +org-attach/sync (arg)
"Reindex all attachments in `org-directory' and delete orphaned attachments in "Reindex all attachments in `org-directory' and delete orphaned attachments in
@ -51,7 +52,7 @@ and END (defaults to `point-min' and `point-max')."
(delay-mode-hooks (org-mode)) (delay-mode-hooks (org-mode))
(dolist (org-file (directory-files-recursively org-directory "\\.org$")) (dolist (org-file (directory-files-recursively org-directory "\\.org$"))
(insert-file-contents-literally org-file)) (insert-file-contents-literally org-file))
(setq +org-attachments (+org-attachments--list))) (setq +org-attachments (+org-list-attachments)))
;; clean up ;; clean up
(let ((deleted 0)) (let ((deleted 0))
(dolist (file (cl-set-difference +org-attachments-files +org-attachments (dolist (file (cl-set-difference +org-attachments-files +org-attachments

View file

@ -2,8 +2,9 @@
(defvar org-capture-initial) (defvar org-capture-initial)
;; ;;
;; External frame ;;; External frame
;;;###autoload ;;;###autoload
(defvar +org-capture-frame-parameters (defvar +org-capture-frame-parameters
@ -73,7 +74,7 @@ you're done. This can be called from an external shell script."
;; ;;
;; Capture targets ;;; Capture targets
(defun +org--capture-root (path) (defun +org--capture-root (path)
(let ((filename (file-name-nondirectory path))) (let ((filename (file-name-nondirectory path)))

View file

@ -11,11 +11,10 @@
(IS-MAC ox-clip-osx-cmd)))) (IS-MAC ox-clip-osx-cmd))))
(IS-LINUX (IS-LINUX
(let ((html (buffer-string))) (let ((html (buffer-string)))
(with-temp-file "/tmp/ox-clip-md.html" (with-temp-file (make-temp-file "ox-clip-md" nil ".html")
(insert html)) (insert html))
(apply (apply #'start-process "ox-clip" "*ox-clip*"
'start-process "ox-clip" "*ox-clip*" (split-string ox-clip-linux-cmd " ")))))))
(split-string ox-clip-linux-cmd " ")))))))
;; ;;

View file

@ -30,3 +30,20 @@
(buffer-substring-no-properties (point) (point-max))) (buffer-substring-no-properties (point) (point-max)))
(message "Download of image \"%s\" failed" link) (message "Download of image \"%s\" failed" link)
nil))) nil)))
;;
;;; Commands
;;;###autoload
(defun +org/remove-link ()
"Unlink the text at point."
(interactive)
(unless (org-in-regexp org-link-bracket-re 1)
(user-error "No link at point"))
(save-excursion
(let ((label (if (match-end 2)
(match-string-no-properties 2)
(org-link-unescape (match-string-no-properties 1)))))
(delete-region (match-beginning 0) (match-end 0))
(insert label))))

View file

@ -0,0 +1,97 @@
;;; lang/org/autoload/org-tables.el -*- lexical-binding: t; -*-
;;
;;; Row/Column traversal
;;;###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)
(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))))
;;
;;; Row/Column insertion
;;;###autoload
(defun +org/table-insert-column-left ()
"Insert a new column left of the current column."
(interactive)
(org-table-insert-column)
(org-table-move-column-left))
;;;###autoload
(defun +org/table-insert-row-below ()
"Insert a new row below the current row."
(interactive)
(org-table-insert-row 'below))
;;
;;; Hooks
;;;###autoload
(defun +org-realign-table-maybe-h ()
"Auto-align table under cursor and re-calculate formulas."
(when (and (org-at-table-p) org-table-may-need-update)
(let ((pt (point))
(inhibit-message t))
(org-table-recalculate)
(if org-table-may-need-update (org-table-align))
(goto-char pt))))
;;;###autoload
(defun +org-enable-auto-reformat-tables-h ()
"Realign tables & update formulas when exiting insert mode (`evil-mode').
Meant for `org-mode-hook'."
(when (featurep 'evil)
(add-hook 'evil-insert-state-exit-hook #'+org-realign-table-maybe-h nil t)
(add-hook 'evil-replace-state-exit-hook #'+org-realign-table-maybe-h nil t)
(advice-add #'evil-replace :after #'+org-realign-table-maybe-a)))
;;;###autoload
(defun +org-delete-backward-char-and-realign-table-maybe-h ()
"Ensure deleting characters with backspace doesn't deform the table cell."
(when (eq major-mode 'org-mode)
(org-check-before-invisible-edit 'delete-backward)
(save-match-data
(when (and (org-at-table-p)
(not (org-region-active-p))
(string-match-p "|" (buffer-substring (point-at-bol) (point)))
(looking-at-p ".*?|"))
(let ((pos (point))
(noalign (looking-at-p "[^|\n\r]* |"))
(c org-table-may-need-update))
(delete-char -1)
(unless overwrite-mode
(skip-chars-forward "^|")
(insert " ")
(goto-char (1- pos)))
;; noalign: if there were two spaces at the end, this field
;; does not determine the width of the column.
(when noalign (setq org-table-may-need-update c)))
t))))
;;
;;; Advice
;;;###autoload
(defun +org-realign-table-maybe-a (&rest _)
"Auto-align table under cursor and re-calculate formulas."
(when (eq major-mode 'org-mode)
(+org-realign-table-maybe-h)))

View file

@ -17,162 +17,20 @@
;; ;;
;;; Helpers ;;; Helpers
(defun +org--get-property (name &optional bound) (defun +org--refresh-inline-images-in-subtree ()
(save-excursion "Refresh image previews in the current heading/tree."
(let ((re (format "^#\\+%s:[ \t]*\\([^\n]+\\)" (upcase name)))) (if (> (length org-inline-image-overlays) 0)
(goto-char (point-min)) (org-remove-inline-images)
(when (re-search-forward re bound t) (org-display-inline-images
(buffer-substring-no-properties (match-beginning 1) (match-end 1)))))) 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))))))
;;;###autoload (defun +org--insert-item (direction)
(defun +org-get-property (name &optional file bound)
"Get a document property named NAME (string) from an org FILE (defaults to
current file). Only scans first 2048 bytes of the document."
(unless bound
(setq bound 2048))
(if file
(with-temp-buffer
(insert-file-contents-literally file nil 0 bound)
(+org--get-property name))
(+org--get-property name bound)))
;;;###autoload
(defun +org-get-todo-keywords-for (keyword)
"TODO"
(when keyword
(cl-loop for (type . keyword-spec) in org-todo-keywords
for keywords = (mapcar (lambda (x) (if (string-match "^\\([^(]+\\)(" x)
(match-string 1 x)
x))
keyword-spec)
if (eq type 'sequence)
if (member keyword keywords)
return keywords)))
;;
;;; Modes
;;;###autoload
(define-minor-mode +org-pretty-mode
"Hides emphasis markers and toggles pretty entities."
:init-value nil
:lighter " *"
:group 'evil-org
(setq org-hide-emphasis-markers +org-pretty-mode)
(org-toggle-pretty-entities)
(with-silent-modifications
;; In case the above un-align tables
(org-table-map-tables 'org-table-align t)))
;;
;;; Commands
;;;###autoload
(defun +org/dwim-at-point ()
"Do-what-I-mean at point.
If on a:
- checkbox list item or todo heading: toggle it.
- clock: update its time.
- headline: toggle latex fragments and inline images underneath.
- footnote reference: jump to the footnote's definition
- footnote definition: jump to the first reference of this footnote
- table-row or a TBLFM: recalculate the table's formulas
- table-cell: clear it and go into insert mode. If this is a formula cell,
recaluclate it instead.
- babel-call: execute the source block
- statistics-cookie: update it.
- latex fragment: toggle it.
- link: follow it
- otherwise, refresh all inline images in current tree."
(interactive)
(let* ((context (org-element-context))
(type (org-element-type context)))
;; skip over unimportant contexts
(while (and context (memq type '(verbatim code bold italic underline strike-through subscript superscript)))
(setq context (org-element-property :parent context)
type (org-element-type context)))
(pcase type
(`headline
(cond ((and (fboundp 'toc-org-insert-toc)
(member "TOC" (org-get-tags)))
(toc-org-insert-toc)
(message "Updating table of contents"))
((string= "ARCHIVE" (car-safe (org-get-tags)))
(org-force-cycle-archived))
((or (org-element-property :todo-type context)
(org-element-property :scheduled context))
(org-todo
(if (eq (org-element-property :todo-type context) 'done)
(or (car (+org-get-todo-keywords-for (org-element-property :todo-keyword context)))
'todo)
'done)))
(t
(+org/refresh-inline-images)
(org-clear-latex-preview)
(org-latex-preview '(4)))))
(`clock (org-clock-update-time-maybe))
(`footnote-reference
(org-footnote-goto-definition (org-element-property :label context)))
(`footnote-definition
(org-footnote-goto-previous-reference (org-element-property :label context)))
((or `planning `timestamp)
(org-follow-timestamp-link))
((or `table `table-row)
(if (org-at-TBLFM-p)
(org-table-calc-current-TBLFM)
(ignore-errors
(save-excursion
(goto-char (org-element-property :contents-begin context))
(org-call-with-arg 'org-table-recalculate (or arg t))))))
(`table-cell
(org-table-blank-field)
(org-table-recalculate)
(when (and (string-empty-p (string-trim (org-table-get-field)))
(bound-and-true-p evil-local-mode))
(evil-change-state 'insert)))
(`babel-call
(org-babel-lob-execute-maybe))
(`statistics-cookie
(save-excursion (org-update-statistics-cookies nil)))
((or `src-block `inline-src-block)
(org-babel-execute-src-block))
((or `latex-fragment `latex-environment)
(org-latex-preview))
(`link
(let* ((lineage (org-element-lineage context '(link) t))
(path (org-element-property :path lineage)))
(if (or (equal (org-element-property :type lineage) "img")
(and path (image-type-from-file-name path)))
(+org/refresh-inline-images)
(org-open-at-point))))
((guard (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)))))
(_ (+org/refresh-inline-images)))))
(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)."
(let* ((context (let* ((context
(save-excursion (save-excursion
(when (bolp) (when (bolp)
@ -252,17 +110,173 @@ wrong places)."
(when (bound-and-true-p evil-local-mode) (when (bound-and-true-p evil-local-mode)
(evil-insert 1)))) (evil-insert 1))))
;;;###autoload
(defun +org-get-global-property (property &optional file)
"Get #+PROPERTY from an org FILE (defaults to current file)."
(if file
(let ((bound 256))
(with-temp-buffer
(insert-file-contents-literally file nil 0 bound)
(goto-char (point-min))
(and (re-search-forward (format "^#\\+%s:[ \t]*\\([^\n]+\\)" (upcase name))
bound t)
(buffer-substring-no-properties (match-beginning 1)
(match-end 1)))))
(org-element-property
:value
(car (org-element-map (org-element-parse-buffer) 'keyword
(lambda (el)
(and (string-match-p property (org-element-property :key el))
el)))))))
;;;###autoload
(defun +org-get-todo-keywords-for (&optional keyword)
"Returns the list of todo keywords that KEYWORD belongs to."
(when keyword
(cl-loop for (type . keyword-spec)
in (cl-remove-if-not #'listp org-todo-keywords)
for keywords =
(mapcar (lambda (x) (if (string-match "^\\([^(]+\\)(" x)
(match-string 1 x)
x))
keyword-spec)
if (eq type 'sequence)
if (member keyword keywords)
return keywords)))
;;
;;; Modes
;;;###autoload
(define-minor-mode +org-pretty-mode
"Hides emphasis markers and toggles pretty entities."
:init-value nil
:lighter " *"
:group 'evil-org
(setq org-hide-emphasis-markers +org-pretty-mode)
(org-toggle-pretty-entities)
(with-silent-modifications
;; In case the above un-align tables
(org-table-map-tables 'org-table-align t)))
;;
;;; Commands
;;;###autoload
(defun +org/dwim-at-point ()
"Do-what-I-mean at point.
If on a:
- checkbox list item or todo heading: toggle it.
- clock: update its time.
- headline: toggle latex fragments and inline images underneath.
- footnote reference: jump to the footnote's definition
- footnote definition: jump to the first reference of this footnote
- table-row or a TBLFM: recalculate the table's formulas
- table-cell: clear it and go into insert mode. If this is a formula cell,
recaluclate it instead.
- babel-call: execute the source block
- statistics-cookie: update it.
- latex fragment: toggle it.
- link: follow it
- otherwise, refresh all inline images in current tree."
(interactive)
(let* ((context (org-element-context))
(type (org-element-type context)))
;; skip over unimportant contexts
(while (and context (memq type '(verbatim code bold italic underline strike-through subscript superscript)))
(setq context (org-element-property :parent context)
type (org-element-type context)))
(pcase type
(`headline
(cond ((and (fboundp 'toc-org-insert-toc)
(member "TOC" (org-get-tags)))
(toc-org-insert-toc)
(message "Updating table of contents"))
((string= "ARCHIVE" (car-safe (org-get-tags)))
(org-force-cycle-archived))
((or (org-element-property :todo-type context)
(org-element-property :scheduled context))
(org-todo
(if (eq (org-element-property :todo-type context) 'done)
(or (car (+org-get-todo-keywords-for (org-element-property :todo-keyword context)))
'todo)
'done)))
(t
(+org--refresh-inline-images-in-subtree)
(org-clear-latex-preview)
(org-latex-preview '(4)))))
(`clock (org-clock-update-time-maybe))
(`footnote-reference
(org-footnote-goto-definition (org-element-property :label context)))
(`footnote-definition
(org-footnote-goto-previous-reference (org-element-property :label context)))
((or `planning `timestamp)
(org-follow-timestamp-link))
((or `table `table-row)
(if (org-at-TBLFM-p)
(org-table-calc-current-TBLFM)
(ignore-errors
(save-excursion
(goto-char (org-element-property :contents-begin context))
(org-call-with-arg 'org-table-recalculate (or arg t))))))
(`table-cell
(org-table-blank-field)
(org-table-recalculate)
(when (and (string-empty-p (string-trim (org-table-get-field)))
(bound-and-true-p evil-local-mode))
(evil-change-state 'insert)))
(`babel-call
(org-babel-lob-execute-maybe))
(`statistics-cookie
(save-excursion (org-update-statistics-cookies nil)))
((or `src-block `inline-src-block)
(org-babel-execute-src-block))
((or `latex-fragment `latex-environment)
(org-latex-preview))
(`link
(let* ((lineage (org-element-lineage context '(link) t))
(path (org-element-property :path lineage)))
(if (or (equal (org-element-property :type lineage) "img")
(and path (image-type-from-file-name path)))
(+org--refresh-inline-images-in-subtree)
(org-open-at-point))))
((guard (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)))))
(_ (+org--refresh-inline-images-in-subtree)))))
;; 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).
;;;###autoload ;;;###autoload
(defun +org/insert-item-below (count) (defun +org/insert-item-below (count)
"Inserts a new heading, table cell or item below the current one."
(interactive "p") (interactive "p")
(dotimes (_ count) (dotimes (_ count) (+org--insert-item 'below)))
(+org-insert-item 'below)))
;;;###autoload ;;;###autoload
(defun +org/insert-item-above (count) (defun +org/insert-item-above (count)
"Inserts a new heading, table cell or item above the current one."
(interactive "p") (interactive "p")
(dotimes (_ count) (dotimes (_ count) (+org--insert-item 'above)))
(+org-insert-item 'above)))
;;;###autoload ;;;###autoload
(defun +org/dedent () (defun +org/dedent ()
@ -279,40 +293,8 @@ wrong places)."
(ignore-errors (org-promote))) (ignore-errors (org-promote)))
((call-interactively #'self-insert-command)))) ((call-interactively #'self-insert-command))))
;;;###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))))))
;;;###autoload
(defun +org/remove-link ()
"Unlink the text at point."
(interactive)
(unless (org-in-regexp org-link-bracket-re 1)
(user-error "No link at point"))
(save-excursion
(let ((label (if (match-end 2)
(match-string-no-properties 2)
(org-link-unescape (match-string-no-properties 1)))))
(delete-region (match-beginning 0) (match-end 0))
(insert label))))
;;;###autoload
(defun +org/toggle-checkbox ()
"Toggle the presence of a checkbox in the current item."
(interactive)
(org-toggle-checkbox '(4)))
;;; Folds
;;;###autoload ;;;###autoload
(defalias #'+org/toggle-fold #'+org-cycle-only-current-subtree-h) (defalias #'+org/toggle-fold #'+org-cycle-only-current-subtree-h)
@ -363,29 +345,6 @@ another level of headings on each invocation."
;; ;;
;;; Hooks ;;; Hooks
;;;###autoload
(defun +org-delete-backward-char-and-realign-table-maybe-h ()
"TODO"
(when (eq major-mode 'org-mode)
(org-check-before-invisible-edit 'delete-backward)
(save-match-data
(when (and (org-at-table-p)
(not (org-region-active-p))
(string-match-p "|" (buffer-substring (point-at-bol) (point)))
(looking-at-p ".*?|"))
(let ((pos (point))
(noalign (looking-at-p "[^|\n\r]* |"))
(c org-table-may-need-update))
(delete-char -1)
(unless overwrite-mode
(skip-chars-forward "^|")
(insert " ")
(goto-char (1- pos)))
;; noalign: if there were two spaces at the end, this field
;; does not determine the width of the column.
(when noalign (setq org-table-may-need-update c)))
t))))
;;;###autoload ;;;###autoload
(defun +org-indent-maybe-h () (defun +org-indent-maybe-h ()
"Indent the current item (header or item), if possible. "Indent the current item (header or item), if possible.
@ -410,16 +369,6 @@ Made for `org-tab-first-hook' in evil-mode."
(call-interactively #'indent-for-tab-command)) (call-interactively #'indent-for-tab-command))
t))) t)))
;;;###autoload
(defun +org-realign-table-maybe-h ()
"Auto-align table under cursor and re-calculate formulas."
(when (and (org-at-table-p) org-table-may-need-update)
(let ((pt (point))
(inhibit-message t))
(org-table-recalculate)
(if org-table-may-need-update (org-table-align))
(goto-char pt))))
;;;###autoload ;;;###autoload
(defun +org-update-cookies-h () (defun +org-update-cookies-h ()
"Update counts in headlines (aka \"cookies\")." "Update counts in headlines (aka \"cookies\")."
@ -464,13 +413,6 @@ with `org-cycle')."
(org-cycle-internal-local) (org-cycle-internal-local)
t))))) t)))))
;;;###autoload
(defun +org-remove-occur-highlights-h ()
"Remove org occur highlights on ESC in normal mode."
(when org-occur-highlights
(org-remove-occur-highlights)
t))
;;;###autoload ;;;###autoload
(defun +org-unfold-to-2nd-level-or-point-h () (defun +org-unfold-to-2nd-level-or-point-h ()
"My version of the 'overview' #+STARTUP option: expand first-level headings. "My version of the 'overview' #+STARTUP option: expand first-level headings.
@ -478,7 +420,7 @@ Expands the first level, but no further. If point was left somewhere deeper,
unfold to point on startup." unfold to point on startup."
(unless org-agenda-inhibit-startup (unless org-agenda-inhibit-startup
(when (eq org-startup-folded t) (when (eq org-startup-folded t)
(outline-hide-sublevels 2)) (outline-hide-sublevels +org-initial-fold-level))
(when (outline-invisible-p) (when (outline-invisible-p)
(ignore-errors (ignore-errors
(save-excursion (save-excursion
@ -486,12 +428,11 @@ unfold to point on startup."
(org-show-subtree)))))) (org-show-subtree))))))
;;;###autoload ;;;###autoload
(defun +org-enable-auto-reformat-tables-h () (defun +org-remove-occur-highlights-h ()
"Realign tables & update formulas when exiting insert mode (`evil-mode')." "Remove org occur highlights on ESC in normal mode."
(when (featurep 'evil) (when org-occur-highlights
(add-hook 'evil-insert-state-exit-hook #'+org-realign-table-maybe-h nil t) (org-remove-occur-highlights)
(add-hook 'evil-replace-state-exit-hook #'+org-realign-table-maybe-h nil t) t))
(advice-add #'evil-replace :after #'+org-realign-table-maybe-a)))
;;;###autoload ;;;###autoload
(defun +org-enable-auto-update-cookies-h () (defun +org-enable-auto-update-cookies-h ()
@ -499,38 +440,3 @@ unfold to point on startup."
(when (featurep 'evil) (when (featurep 'evil)
(add-hook 'evil-insert-state-exit-hook #'+org-update-cookies-h nil t)) (add-hook 'evil-insert-state-exit-hook #'+org-update-cookies-h nil t))
(add-hook 'before-save-hook #'+org-update-cookies-h nil t)) (add-hook 'before-save-hook #'+org-update-cookies-h nil t))
;;
;;; Advice
;;;###autoload
(defun +org-fix-newline-and-indent-in-src-blocks-a ()
"Try to mimic `newline-and-indent' with correct indentation in src blocks."
(when (org-in-src-block-p t)
(org-babel-do-in-edit-buffer
(call-interactively #'indent-for-tab-command))))
;;;###autoload
(defun +org-realign-table-maybe-a (&rest _)
"Auto-align table under cursor and re-calculate formulas."
(when (eq major-mode 'org-mode)
(+org-realign-table-maybe-h)))
;;;###autoload
(defun +org-evil-org-open-below-a (orig-fn count)
"Fix o/O creating new list items in the middle of nested plain lists. Only has
an effect when `evil-org-special-o/O' has `item' in it (not the default)."
(cl-letf (((symbol-function 'end-of-visible-line)
(lambda ()
(org-end-of-item)
(backward-char 1)
(evil-append nil))))
(funcall orig-fn count)))
;;;###autoload
(defun +org-display-link-in-eldoc-a (orig-fn &rest args)
"Display the link at point in eldoc."
(or (when-let (link (org-element-property :raw-link (org-element-context)))
(format "Link: %s" link))
(apply orig-fn args)))

View file

@ -1,41 +0,0 @@
;;; lang/org/autoload/tables.el -*- lexical-binding: t; -*-
;;
;;; Row/Column traversal
;;;###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)
(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))))
;;
;;; Row/Column insertion
;;;###autoload
(defun +org/table-insert-column-left ()
"Insert a new column left of the current column."
(interactive)
(org-table-insert-column)
(org-table-move-column-left))
;;;###autoload
(defun +org/table-insert-row-below ()
"Insert a new row below the current row."
(interactive)
(org-table-insert-row 'below))

View file

@ -1,5 +1,65 @@
;;; lang/org/config.el -*- lexical-binding: t; -*- ;;; lang/org/config.el -*- lexical-binding: t; -*-
(defvar +org-babel-mode-alist
'((cpp . C)
(C++ . C)
(D . C)
(sh . shell)
(bash . shell)
(matlab . octave))
"An alist mapping languages to babel libraries. This is necessary for babel
libraries (ob-*.el) that don't match the name of the language.
For example, with (fish . shell) will cause #+BEGIN_SRC fish to load ob-shell.el
when executed.")
(defvar +org-babel-load-functions ()
"A list of functions executed to load the current executing src block. They
take one argument (the language specified in the src block, as a string). Stops
at the first function to return non-nil.")
(defvar +org-capture-todo-file "todo.org"
"Default target for todo entries.
Is relative to `org-directory', unless it is absolute. Is used in Doom's default
`org-capture-templates'.")
(defvar +org-capture-changelog-file "changelog.org"
"Default target for changelog entries.
Is relative to `org-directory' unless it is absolute. Is used in Doom's default
`org-capture-templates'.")
(defvar +org-capture-notes-file "notes.org"
"Default target for storing notes.
Used as a fall back file for org-capture.el, for templates that do not specify a
target file.
Is relative to `org-directory', unless it is absolute. Is used in Doom's default
`org-capture-templates'.")
(defvar +org-initial-fold-level 2
"The initial fold level of org files when no #+STARTUP options for it.")
(defvar +org-enable-centralized-exports t
"If non-nil, files exported from files in `org-directory' will be stored in
`+org-export-directory', rather than the same directory has the input file(s).")
(defvar +org-export-directory ".export/"
"Where to store exported files relative to `org-directory'. Can be an absolute
path too.")
(defvar +org-habit-graph-padding 2
"The padding added to the end of the consistency graph")
(defvar +org-habit-min-width 30
"Hides the consistency graph if the `org-habit-graph-column' is less than this value")
(defvar +org-habit-graph-window-ratio 0.3
"The ratio of the consistency graphs relative to the window width")
;; ;;
;;; `org-load' hooks ;;; `org-load' hooks
@ -39,50 +99,54 @@
org-image-actual-width nil org-image-actual-width nil
org-list-description-max-indent 4 org-list-description-max-indent 4
org-priority-faces org-priority-faces
'((?a . error) '((?A . error)
(?b . warning) (?B . warning)
(?c . success)) (?C . success))
org-refile-targets org-refile-targets
'((nil :maxlevel . 3) '((nil :maxlevel . 3)
(org-agenda-files :maxlevel . 3)) (org-agenda-files :maxlevel . 3))
org-startup-indented t org-startup-indented t
org-tags-column -80
org-todo-keywords org-todo-keywords
'((sequence "TODO(t)" "PROJ(p)" "|" "DONE(d)") '((sequence "TODO(t)" "PROJ(p)" "NEXT(n)" "WAIT(h)" "|" "DONE(d)" "ABRT(a)")
(sequence "[ ](T)" "[-](P)" "[?](M)" "|" "[X](D)") (sequence "[ ](T)" "[-](-)" "[?](?)" "|" "[X](x)"))
(sequence "NEXT(n)" "WAIT(w)" "HOLD(h)" "|" "ABRT(c)"))
org-todo-keyword-faces org-todo-keyword-faces
'(("[-]" :inherit (font-lock-constant-face bold)) '(("[-]" :inherit (font-lock-constant-face bold))
("[?]" :inherit (warning bold)) ("[?]" :inherit (warning bold))
("PROJ" :inherit (bold default)) ("PROJ" :inherit (bold default))
("HOLD" :inherit (warning bold)) ("WAIT" :inherit (warning bold))
("ABRT" :inherit (error bold))) ("ABRT" :inherit (error bold)))
org-use-sub-superscripts '{} org-use-sub-superscripts '{}
;; Scale up LaTeX previews a bit (default is too small) ;; Scale up LaTeX previews a bit (default is too small)
org-format-latex-options (plist-put org-format-latex-options :scale 1.5)) org-format-latex-options (plist-put org-format-latex-options :scale 1.5))
;; Show the full link destination in minibuffer when cursor/mouse is over it ;; Previews are usually rendered with light backgrounds, so ensure their
(advice-add #'org-eldoc-documentation-function :around #'+org-display-link-in-eldoc-a) ;; background (and foreground) match the current theme.
(setq-default
org-format-latex-options
(plist-put org-format-latex-options
:background
(face-attribute (or (cadr (assq 'default face-remapping-alist))
'default)
:background nil t)))
(defadvice! +org-display-link-in-eldoc-a (orig-fn &rest args)
"Display full link in minibuffer when cursor/mouse is over it."
:around #'org-eldoc-documentation-function
(or (when-let (link (org-element-property :raw-link (org-element-context)))
(format "Link: %s" link))
(apply orig-fn args)))
;; Don't do automatic indent detection in org files ;; Don't do automatic indent detection in org files
(add-to-list 'doom-detect-indentation-excluded-modes 'org-mode nil #'eq) (add-to-list 'doom-detect-indentation-excluded-modes 'org-mode nil #'eq)
;; Previews are usually rendered with light backgrounds, so ensure their
;; background (and foreground) match the current theme.
(defun +org-update-latex-preview-background-color-h ()
(setq-default
org-format-latex-options
(plist-put org-format-latex-options
:background
(face-attribute (or (cadr (assq 'default face-remapping-alist))
'default)
:background nil t))))
(add-hook 'doom-load-theme-hook #'+org-update-latex-preview-background-color-h)
(set-pretty-symbols! 'org-mode (set-pretty-symbols! 'org-mode
:name "#+NAME:" :name "#+NAME:"
:src_block "#+BEGIN_SRC" :src_block "#+BEGIN_SRC"
:src_block_end "#+END_SRC")) :src_block_end "#+END_SRC")
(add-hook 'doom-load-theme-hook #'+org-init-appearance-h))
(defun +org-init-babel-h () (defun +org-init-babel-h ()
@ -95,8 +159,12 @@
;; I prefer C-c C-c over C-c ' (more consistent) ;; I prefer C-c C-c over C-c ' (more consistent)
(define-key org-src-mode-map (kbd "C-c C-c") #'org-edit-src-exit) (define-key org-src-mode-map (kbd "C-c C-c") #'org-edit-src-exit)
;; Use major-mode native TAB indentation in SRC blocks (defadvice! +org-fix-newline-and-indent-in-src-blocks-a ()
(advice-add #'org-return-indent :after #'+org-fix-newline-and-indent-in-src-blocks-a) "Mimic `newline-and-indent' in src blocks w/ lang-appropriate indentation."
:after #'org-return-indent
(when (org-in-src-block-p t)
(org-babel-do-in-edit-buffer
(call-interactively #'indent-for-tab-command))))
;; Refresh inline images after executing src blocks (useful for plantuml or ;; Refresh inline images after executing src blocks (useful for plantuml or
;; ipython, where the result could be an image) ;; ipython, where the result could be an image)
@ -109,24 +177,6 @@
(defun +org-init-babel-lazy-loader-h () (defun +org-init-babel-lazy-loader-h ()
"Load babel libraries lazily when babel blocks are executed." "Load babel libraries lazily when babel blocks are executed."
(defvar +org-babel-mode-alist
'((cpp . C)
(C++ . C)
(D . C)
(sh . shell)
(bash . shell)
(matlab . octave))
"An alist mapping languages to babel libraries. This is necessary for babel
libraries (ob-*.el) that don't match the name of the language.
For example, with (fish . shell) will cause #+BEGIN_SRC fish to load ob-shell.el
when executed.")
(defvar +org-babel-load-functions ()
"A list of functions executed to load the current executing src block. They
take one argument (the language specified in the src block, as a string). Stops
at the first function to return non-nil.")
(defadvice! +org--src-lazy-load-library-a (lang) (defadvice! +org--src-lazy-load-library-a (lang)
"Lazy load a babel package to ensure syntax highlighting." "Lazy load a babel package to ensure syntax highlighting."
:before #'org-src--get-lang-mode :before #'org-src--get-lang-mode
@ -163,28 +213,6 @@ I like:
2. Through a org-capture popup frame that is invoked from outside Emacs (the 2. Through a org-capture popup frame that is invoked from outside Emacs (the
~/.emacs.d/bin/org-capture script). This can be invoked from qutebrowser, ~/.emacs.d/bin/org-capture script). This can be invoked from qutebrowser,
vimperator, dmenu or a global keybinding." vimperator, dmenu or a global keybinding."
(defvar +org-capture-todo-file "todo.org"
"Default target for todo entries.
Is relative to `org-directory', unless it is absolute. Is used in Doom's default
`org-capture-templates'.")
(defvar +org-capture-changelog-file "changelog.org"
"Default target for changelog entries.
Is relative to `org-directory' unless it is absolute. Is used in Doom's default
`org-capture-templates'.")
(defvar +org-capture-notes-file "notes.org"
"Default target for storing notes.
Used as a fall back file for org-capture.el, for templates that do not specify a
target file.
Is relative to `org-directory', unless it is absolute. Is used in Doom's default
`org-capture-templates'.")
(setq org-default-notes-file (setq org-default-notes-file
(expand-file-name +org-capture-notes-file org-directory) (expand-file-name +org-capture-notes-file org-directory)
org-capture-templates org-capture-templates
@ -292,14 +320,6 @@ Some commands of interest:
(defun +org-init-centralized-exports-h () (defun +org-init-centralized-exports-h ()
"TODO" "TODO"
(defvar +org-enable-centralized-exports t
"If non-nil, files exported from files in `org-directory' will be stored in
`+org-export-directory', rather than the same directory has the input file(s).")
(defvar +org-export-directory ".export/"
"Where to store exported files relative to `org-directory'. Can be an absolute
path too.")
;; I don't have any beef with org's built-in export system, but I do wish it ;; I don't have any beef with org's built-in export system, but I do wish it
;; would export to a central directory (by default), rather than ;; would export to a central directory (by default), rather than
;; `default-directory'. This is because all my org files are usually in one ;; `default-directory'. This is because all my org files are usually in one
@ -369,10 +389,11 @@ file isn't in `org-directory'."
(org-link-set-parameters "img" :image-data-fun #'+org-inline-data-image) (org-link-set-parameters "img" :image-data-fun #'+org-inline-data-image)
;; Add support for youtube links + previews ;; Add support for youtube links + previews
(use-package! org-yt)) (require 'org-yt nil t))
(defun +org-init-export-h () (defun +org-init-export-h ()
"TODO"
(setq org-export-with-smart-quotes t (setq org-export-with-smart-quotes t
org-html-validation-link nil) org-html-validation-link nil)
@ -389,7 +410,6 @@ file isn't in `org-directory'."
:after ox :after ox
:init :init
(add-to-list 'org-export-backends 'pandoc) (add-to-list 'org-export-backends 'pandoc)
:config
(setq org-pandoc-options (setq org-pandoc-options
'((standalone . t) '((standalone . t)
(mathjax . t) (mathjax . t)
@ -398,15 +418,6 @@ file isn't in `org-directory'."
(defun +org-init-habit-h () (defun +org-init-habit-h ()
"TODO" "TODO"
(defvar +org-habit-graph-padding 2
"The padding added to the end of the consistency graph")
(defvar +org-habit-min-width 30
"Hides the consistency graph if the `org-habit-graph-column' is less than this value")
(defvar +org-habit-graph-window-ratio 0.3
"The ratio of the consistency graphs relative to the window width")
(add-hook! 'org-agenda-mode-hook (add-hook! 'org-agenda-mode-hook
(defun +org-habit-resize-graph-h () (defun +org-habit-resize-graph-h ()
"Right align and resize the consistency graphs based on "Right align and resize the consistency graphs based on
@ -528,11 +539,12 @@ between the two."
#'+org-delete-backward-char-and-realign-table-maybe-h) #'+org-delete-backward-char-and-realign-table-maybe-h)
(map! :map org-mode-map (map! :map org-mode-map
"C-c C-S-l" #'+org/remove-link
"C-c C-i" #'org-toggle-inline-images
;; textmate-esque newline insertion ;; textmate-esque newline insertion
[C-return] #'+org/insert-item-below [C-return] #'+org/insert-item-below
[C-S-return] #'+org/insert-item-above [C-S-return] #'+org/insert-item-above
"C-c C-S-l" #'+org/remove-link ;; Org-aware C-a/C-e
"C-c C-i" #'org-toggle-inline-images
[remap doom/backward-to-bol-or-indent] #'org-beginning-of-line [remap doom/backward-to-bol-or-indent] #'org-beginning-of-line
[remap doom/forward-to-last-non-comment-or-eol] #'org-end-of-line [remap doom/forward-to-last-non-comment-or-eol] #'org-end-of-line
@ -546,7 +558,6 @@ between the two."
(:when (featurep! :completion helm) (:when (featurep! :completion helm)
"." #'helm-org-in-buffer-headings "." #'helm-org-in-buffer-headings
"/" #'helm-org-agenda-files-headings) "/" #'helm-org-agenda-files-headings)
"a" #'org-attach
"d" #'org-deadline "d" #'org-deadline
"e" #'org-export-dispatch "e" #'org-export-dispatch
"f" #'org-footnote-new "f" #'org-footnote-new
@ -554,13 +565,20 @@ between the two."
"i" #'org-toggle-item "i" #'org-toggle-item
"I" #'org-toggle-inline-images "I" #'org-toggle-inline-images
"l" #'org-insert-link "l" #'org-insert-link
"L" #'org-store-link "L" #'+org/remove-link
"p" #'org-set-property "n" #'org-store-link
"o" #'org-set-property
"p" #'org-priority
"q" #'org-set-tags-command "q" #'org-set-tags-command
"r" #'org-refile "r" #'org-refile
"s" #'org-schedule "s" #'org-schedule
"t" #'org-todo "t" #'org-todo
"T" #'org-todo-list "T" #'org-todo-list
(:prefix ("a" . "attachments")
"a" #'org-attach/file
"u" #'org-attach/uri
"f" #'org-attach/find-file
"s" #'org-attach/sync)
(:prefix ("c" . "clock") (:prefix ("c" . "clock")
"c" #'org-clock-in "c" #'org-clock-in
"C" #'org-clock-out "C" #'org-clock-out
@ -606,101 +624,6 @@ between the two."
"t" #'org-agenda-todo)) "t" #'org-agenda-todo))
(defun +org-init-keybinds-for-evil-h (&rest _)
"TODO"
(when (featurep! :editor evil +everywhere)
(use-package! evil-org
:hook (org-mode . evil-org-mode)
:init
(defvar evil-org-retain-visual-state-on-shift t)
(defvar evil-org-special-o/O '(table-row))
(defvar evil-org-use-additional-insert t)
:config
(evil-org-set-key-theme evil-org-key-theme))
(use-package! evil-org-agenda
:hook (org-agenda-mode . evil-org-agenda-mode)
:config
(evil-org-agenda-set-keys)
(evil-define-key* 'motion evil-org-agenda-mode-map
(kbd doom-leader-key) nil))
;; Only fold the current tree, rather than recursively
(add-hook 'org-tab-first-hook #'+org-cycle-only-current-subtree-h t)
;; Fix o/O creating new list items in the middle of nested plain lists. Only
;; has an effect when `evil-org-special-o/O' has `item' in it (not the
;; default).
(advice-add #'evil-org-open-below :around #'+org-evil-org-open-below-a)
(map! :map outline-mode-map
;; Undo keybinds from `evil-collection-outline'
:n "^" nil
:n [backtab] nil
:n "M-j" nil
:n "M-k" nil
:n "C-j" nil
:n "C-k" nil
:n "]" nil
:n "[" nil
:map evil-org-mode-map
:ni [C-return] #'+org/insert-item-below
:ni [C-S-return] #'+org/insert-item-above
;; navigate table cells (from insert-mode)
:i "C-l" (general-predicate-dispatch 'org-end-of-line
(org-at-table-p) 'org-table-next-field)
:i "C-h" (general-predicate-dispatch 'org-beginning-of-line
(org-at-table-p) 'org-table-previous-field)
:i "C-k" (general-predicate-dispatch 'org-up-element
(org-at-table-p) '+org/table-previous-row)
:i "C-j" (general-predicate-dispatch 'org-down-element
(org-at-table-p) 'org-table-next-row)
;; moving/(de|pro)moting subtress & expanding tables (prepend/append columns/rows)
:ni "C-S-l" #'org-shiftright
:ni "C-S-h" #'org-shiftleft
:ni "C-S-k" #'org-shiftup
:ni "C-S-j" #'org-shiftdown
;; more intuitive RET keybinds
:i [return] #'org-return-indent
:i "RET" #'org-return-indent
:n [return] #'+org/dwim-at-point
:n "RET" #'+org/dwim-at-point
;; more vim-esque org motion keys (not covered by evil-org-mode)
:m "]]" (λ! (org-forward-heading-same-level nil) (org-beginning-of-line))
:m "[[" (λ! (org-backward-heading-same-level nil) (org-beginning-of-line))
:m "]h" #'org-next-visible-heading
:m "[h" #'org-previous-visible-heading
:m "]l" #'org-next-link
:m "[l" #'org-previous-link
:m "]c" #'org-babel-next-src-block
:m "[c" #'org-babel-previous-src-block
:n "gQ" #'org-fill-paragraph
:n "gr" #'org-ctrl-c-ctrl-c
;; sensible vim-esque folding keybinds
:n "za" #'+org/toggle-fold
:n "zA" #'org-shifttab
:n "zc" #'+org/close-fold
:n "zC" #'outline-hide-subtree
:n "zm" #'+org/hide-next-fold-level
:n "zn" #'org-tree-to-indirect-buffer
:n "zo" #'+org/open-fold
:n "zO" #'outline-show-subtree
:n "zr" #'+org/show-next-fold-level
:n "zR" #'outline-show-all
:n "zi" #'org-toggle-inline-images
:map org-read-date-minibuffer-local-map
"C-h" (λ! (org-eval-in-calendar '(calendar-backward-day 1)))
"C-l" (λ! (org-eval-in-calendar '(calendar-forward-day 1)))
"C-k" (λ! (org-eval-in-calendar '(calendar-backward-week 1)))
"C-j" (λ! (org-eval-in-calendar '(calendar-forward-week 1)))
"C-S-h" (λ! (org-eval-in-calendar '(calendar-backward-month 1)))
"C-S-l" (λ! (org-eval-in-calendar '(calendar-forward-month 1)))
"C-S-k" (λ! (org-eval-in-calendar '(calendar-backward-year 1)))
"C-S-j" (λ! (org-eval-in-calendar '(calendar-forward-year 1))))))
(defun +org-init-popup-rules-h () (defun +org-init-popup-rules-h ()
(set-popup-rules! (set-popup-rules!
'(("^\\*Org Links" :slot -1 :vslot -1 :size 2 :ttl 0) '(("^\\*Org Links" :slot -1 :vslot -1 :size 2 :ttl 0)
@ -776,6 +699,140 @@ compelling reason, so..."
(sp-local-pair "=" "=" :unless '(:add sp-point-before-word-p sp-in-math-p +org-sp-in-src-block-p))))) (sp-local-pair "=" "=" :unless '(:add sp-point-before-word-p sp-in-math-p +org-sp-in-src-block-p)))))
;;
;;; Packages
(use-package! toc-org ; auto-table of contents
:hook (org-mode . toc-org-enable)
:config (setq toc-org-hrefify-default "gh"))
(use-package! org-bullets ; "prettier" bullets
:hook (org-mode . org-bullets-mode))
(use-package! org-fancy-priorities ; priority icons
:hook (org-mode . org-fancy-priorities-mode)
:config (setq org-fancy-priorities-list '("" "" "")))
(use-package! org-crypt ; built-in
:commands org-encrypt-entries
:hook (org-reveal-start . org-decrypt-entry)
:config
(add-hook! 'org-mode-hook
(add-hook 'before-save-hook 'org-encrypt-entries nil t))
(add-to-list 'org-tags-exclude-from-inheritance "crypt")
(setq org-crypt-key user-mail-address))
(use-package! org-clock ; built-in
:commands org-clock-save
:init
(setq org-clock-persist-file (concat doom-etc-dir "org-clock-save.el"))
(defadvice! +org--clock-load-a (&rest _)
"Lazy load org-clock until its commands are used."
:before '(org-clock-in
org-clock-out
org-clock-in-last
org-clock-goto
org-clock-cancel)
(org-clock-load))
:config
(setq org-clock-persist t
;; Resume when clocking into task with open clock
org-clock-in-resume t)
(add-hook 'kill-emacs-hook #'org-clock-save))
(use-package! org-pdfview
:when (featurep! :tools pdf)
:commands org-pdfview-open
:init
(after! org
(delete '("\\.pdf\\'" . default) org-file-apps)
;; org links to pdf files are opened in pdf-view-mode
(add-to-list 'org-file-apps '("\\.pdf\\'" . (lambda (_file link) (org-pdfview-open link))))
;; support for links to specific pages
(add-to-list 'org-file-apps '("\\.pdf::\\([[:digit:]]+\\)\\'" . (lambda (_file link) (org-pdfview-open link))))))
(use-package! evil-org
:when (featurep! :editor evil +everywhere)
:hook (org-mode . evil-org-mode)
:init
(defvar evil-org-retain-visual-state-on-shift t)
(defvar evil-org-special-o/O '(table-row))
(defvar evil-org-use-additional-insert t)
:config
(evil-org-set-key-theme)
;; Only fold the current tree, rather than recursively
(add-hook 'org-tab-first-hook #'+org-cycle-only-current-subtree-h 'append)
(map! :map evil-org-mode-map
:ni [C-return] #'+org/insert-item-below
:ni [C-S-return] #'+org/insert-item-above
;; navigate table cells (from insert-mode)
:i "C-l" (general-predicate-dispatch 'org-end-of-line
(org-at-table-p) 'org-table-next-field)
:i "C-h" (general-predicate-dispatch 'org-beginning-of-line
(org-at-table-p) 'org-table-previous-field)
:i "C-k" (general-predicate-dispatch 'org-up-element
(org-at-table-p) '+org/table-previous-row)
:i "C-j" (general-predicate-dispatch 'org-down-element
(org-at-table-p) 'org-table-next-row)
;; moving/(de|pro)moting subtress & expanding tables (prepend/append columns/rows)
:ni "C-S-l" #'org-shiftright
:ni "C-S-h" #'org-shiftleft
:ni "C-S-k" #'org-shiftup
:ni "C-S-j" #'org-shiftdown
;; more intuitive RET keybinds
:i [return] #'org-return-indent
:i "RET" #'org-return-indent
:n [return] #'+org/dwim-at-point
:n "RET" #'+org/dwim-at-point
;; more vim-esque org motion keys (not covered by evil-org-mode)
:m "]h" #'org-forward-heading-same-level
:m "[h" #'org-backward-heading-same-level
:m "]l" #'org-next-link
:m "[l" #'org-previous-link
:m "]c" #'org-babel-next-src-block
:m "[c" #'org-babel-previous-src-block
:n "gQ" #'org-fill-paragraph
:n "gr" #'org-ctrl-c-ctrl-c
:n "gR" #'org-babel-execute-buffer
;; sensible vim-esque folding keybinds
:n "za" #'+org/toggle-fold
:n "zA" #'org-shifttab
:n "zc" #'+org/close-fold
:n "zC" #'outline-hide-subtree
:n "zm" #'+org/hide-next-fold-level
:n "zn" #'org-tree-to-indirect-buffer
:n "zo" #'+org/open-fold
:n "zO" #'outline-show-subtree
:n "zr" #'+org/show-next-fold-level
:n "zR" #'outline-show-all
:n "zi" #'org-toggle-inline-images
:map org-read-date-minibuffer-local-map
"C-h" (λ! (org-eval-in-calendar '(calendar-backward-day 1)))
"C-l" (λ! (org-eval-in-calendar '(calendar-forward-day 1)))
"C-k" (λ! (org-eval-in-calendar '(calendar-backward-week 1)))
"C-j" (λ! (org-eval-in-calendar '(calendar-forward-week 1)))
"C-S-h" (λ! (org-eval-in-calendar '(calendar-backward-month 1)))
"C-S-l" (λ! (org-eval-in-calendar '(calendar-forward-month 1)))
"C-S-k" (λ! (org-eval-in-calendar '(calendar-backward-year 1)))
"C-S-j" (λ! (org-eval-in-calendar '(calendar-forward-year 1)))))
(use-package! evil-org-agenda
:when (featurep! :editor evil +everywhere)
:hook (org-agenda-mode . evil-org-agenda-mode)
:config
(evil-org-agenda-set-keys)
(evil-define-key* 'motion evil-org-agenda-mode-map
(kbd doom-leader-key) nil))
;; ;;
;;; Bootstrap ;;; Bootstrap
@ -789,8 +846,7 @@ compelling reason, so..."
(defvar org-directory "~/org/") (defvar org-directory "~/org/")
(defvar org-attach-id-dir ".attach/") (defvar org-attach-id-dir ".attach/")
(setq org-clock-persist-file (concat doom-etc-dir "org-clock-save.el") (setq org-publish-timestamp-directory (concat doom-cache-dir "org-timestamps/")
org-publish-timestamp-directory (concat doom-cache-dir "org-timestamps/")
org-preview-latex-image-directory (concat doom-cache-dir "org-latex/")) org-preview-latex-image-directory (concat doom-cache-dir "org-latex/"))
(defvar org-modules (defvar org-modules
@ -807,14 +863,11 @@ compelling reason, so..."
)) ))
(add-hook! 'org-mode-hook (add-hook! 'org-mode-hook
#'org-bullets-mode ; "prettier" bullets ;; `show-paren-mode' causes flickering with indent overlays made by
#'toc-org-enable ; auto-table of contents
;; `show-paren-mode' causes flickering with indentation margins made by
;; `org-indent-mode', so we turn off show-paren-mode altogether ;; `org-indent-mode', so we turn off show-paren-mode altogether
#'doom-disable-show-paren-mode-h #'doom-disable-show-paren-mode-h
;; Shows a lot of false positives, so... ;; disable `show-trailing-whitespace'; shows a lot of false positives
#'doom-disable-show-trailing-whitespace-h #'doom-disable-show-trailing-whitespace-h
#'+org-enable-auto-reformat-tables-h #'+org-enable-auto-reformat-tables-h
#'+org-enable-auto-update-cookies-h #'+org-enable-auto-update-cookies-h
#'+org-unfold-to-2nd-level-or-point-h) #'+org-unfold-to-2nd-level-or-point-h)
@ -833,12 +886,17 @@ compelling reason, so..."
#'+org-init-habit-h #'+org-init-habit-h
#'+org-init-hacks-h #'+org-init-hacks-h
#'+org-init-keybinds-h #'+org-init-keybinds-h
#'+org-init-keybinds-for-evil-h ; will noop without :editor evil
#'+org-init-popup-rules-h #'+org-init-popup-rules-h
#'+org-init-protocol-h #'+org-init-protocol-h
#'+org-init-protocol-lazy-loader-h #'+org-init-protocol-lazy-loader-h
#'+org-init-smartparens-h) #'+org-init-smartparens-h)
;;; Custom org modules
(if (featurep! +dragndrop) (load! "contrib/dragndrop"))
(if (featurep! +ipython) (load! "contrib/ipython"))
(if (featurep! +pomodoro) (load! "contrib/pomodoro"))
(if (featurep! +present) (load! "contrib/present"))
;; In case the user has eagerly loaded org from their configs ;; In case the user has eagerly loaded org from their configs
(when (and (featurep 'org) (when (and (featurep 'org)
(not doom-reloading-p) (not doom-reloading-p)
@ -846,52 +904,5 @@ compelling reason, so..."
(message "`org' was already loaded by the time lang/org loaded, this may cause issues") (message "`org' was already loaded by the time lang/org loaded, this may cause issues")
(run-hooks 'org-load-hook)) (run-hooks 'org-load-hook))
;;; Custom org modules
(if (featurep! +dragndrop) (load! "contrib/dragndrop"))
(if (featurep! +ipython) (load! "contrib/ipython"))
(if (featurep! +pomodoro) (load! "contrib/pomodoro"))
(if (featurep! +present) (load! "contrib/present"))
:config :config
(add-hook 'org-open-at-point-functions #'doom-set-jump-h) (add-hook 'org-open-at-point-functions #'doom-set-jump-h))
;;; Packages
(after! toc-org
(setq toc-org-hrefify-default "gh"))
(use-package! org-pdfview
:when (featurep! :tools pdf)
:commands (org-pdfview-open)
:init
(delete '("\\.pdf\\'" . default) org-file-apps)
;; org links to pdf files are opened in pdf-view-mode
(add-to-list 'org-file-apps '("\\.pdf\\'" . (lambda (_file link) (org-pdfview-open link))))
;; support for links to specific pages
(add-to-list 'org-file-apps '("\\.pdf::\\([[:digit:]]+\\)\\'" . (lambda (_file link) (org-pdfview-open link)))))
(use-package! org-crypt ; built-in
:commands org-encrypt-entries
:hook (org-reveal-start . org-decrypt-entry)
:init
(add-hook! 'org-mode-hook
(add-hook 'before-save-hook 'org-encrypt-entries nil t))
(add-to-list 'org-tags-exclude-from-inheritance "crypt")
(setq org-crypt-key user-mail-address))
(use-package! org-clock ; built-in
:commands org-clock-save
:init
(setq org-clock-persist t
;; Resume when clocking into task with open clock
org-clock-in-resume t)
(defadvice! +org--clock-load-a (&rest _)
"Lazy load org-clock until its commands are used."
:before '(org-clock-in
org-clock-out
org-clock-in-last
org-clock-goto
org-clock-cancel)
(org-clock-load))
:config
(add-hook 'kill-emacs-hook #'org-clock-save)))

View file

@ -2,7 +2,7 @@
;;;###if (featurep! +dragndrop) ;;;###if (featurep! +dragndrop)
(use-package! org-download (use-package! org-download
:commands (org-download-dnd org-download-dnd-base64) :commands org-download-dnd org-download-dnd-base64
:init :init
;; HACK We add these manually so that org-download is truly lazy-loaded ;; HACK We add these manually so that org-download is truly lazy-loaded
(pushnew! dnd-protocol-alist (pushnew! dnd-protocol-alist
@ -26,7 +26,7 @@
"Produces and inserts a link to FILENAME into the document. "Produces and inserts a link to FILENAME into the document.
If FILENAME is an image, produce an attach:%s path, otherwise use file:%s (with If FILENAME is an image, produce an attach:%s path, otherwise use file:%s (with
an file icon produced by `+org-attach--icon')." an file icon produced by `+org-attach-icon-for')."
:override #'org-download-insert-link :override #'org-download-insert-link
(if (looking-back "^[ \t]+" (line-beginning-position)) (if (looking-back "^[ \t]+" (line-beginning-position))
(delete-region (match-beginning 0) (match-end 0)) (delete-region (match-beginning 0) (match-end 0))
@ -45,7 +45,7 @@ an file icon produced by `+org-attach--icon')."
(org-display-inline-images)) (org-display-inline-images))
((insert ((insert
(format "%s [[./%s][%s]] " (format "%s [[./%s][%s]] "
(+org-attach--icon filename) (+org-attach-icon-for filename)
(file-relative-name filename (file-name-directory buffer-file-name)) (file-relative-name filename (file-name-directory buffer-file-name))
(file-name-nondirectory (directory-file-name filename))))))) (file-name-nondirectory (directory-file-name filename)))))))

View file

@ -9,6 +9,7 @@
(package! org-plus-contrib) ; install cutting-edge version of org-mode (package! org-plus-contrib) ; install cutting-edge version of org-mode
(package! org-bullets :recipe (:host github :repo "Kaligule/org-bullets")) (package! org-bullets :recipe (:host github :repo "Kaligule/org-bullets"))
(package! org-fancy-priorities)
(package! toc-org) (package! toc-org)
(when (featurep! :editor evil +everywhere) (when (featurep! :editor evil +everywhere)
(package! evil-org :recipe (:host github :repo "hlissner/evil-org-mode"))) (package! evil-org :recipe (:host github :repo "hlissner/evil-org-mode")))