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:
parent
9f8277b2c4
commit
5f00db871e
12 changed files with 600 additions and 601 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
;;;###autoload
|
||||
(defun +org-dragndrop-download-dnd-fn (uri action)
|
||||
"TODO"
|
||||
"Handle file links and base64 data uris."
|
||||
(if (eq major-mode 'org-mode)
|
||||
(+org-attach/uri uri)
|
||||
(let ((dnd-protocol-alist
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
;;; lang/org/autoload/contrib-present.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +present)
|
||||
|
||||
(defvar +org-present--overlays nil)
|
||||
;;;###autoload
|
||||
(defun +org-present/start ()
|
||||
"TODO"
|
||||
(interactive)
|
||||
(unless (derived-mode-p 'org-mode)
|
||||
(error "Not in an org buffer"))
|
||||
(call-interactively #'org-tree-slide-mode)
|
||||
(add-hook 'kill-buffer-hook #'+org-present--cleanup-org-tree-slides-mode))
|
||||
;;
|
||||
;;; Helpers
|
||||
|
||||
(defun +org-present--cleanup-org-tree-slides-mode ()
|
||||
(unless (cl-loop for buf in (doom-buffers-in-mode 'org-mode)
|
||||
if (buffer-local-value 'org-tree-slide-mode buf)
|
||||
return t)
|
||||
(org-tree-slide-mode -1)
|
||||
(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
|
||||
(defun +org-present-add-overlays-h ()
|
||||
"TODO"
|
||||
(add-to-invisibility-spec '(+org-present))
|
||||
(save-excursion
|
||||
;; hide org-mode options starting with #+
|
||||
|
@ -32,11 +38,13 @@
|
|||
|
||||
;;;###autoload
|
||||
(defun +org-present-remove-overlays-h ()
|
||||
"TODO"
|
||||
(mapc #'delete-overlay +org-present--overlays)
|
||||
(remove-from-invisibility-spec '(+org-present)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-present-detect-slide-h ()
|
||||
"TODO"
|
||||
(outline-show-all)
|
||||
(if (member "title" (org-get-tags))
|
||||
(text-scale-set 10)
|
||||
|
@ -48,6 +56,7 @@
|
|||
(defvar cwm-centered-window-width)
|
||||
;;;###autoload
|
||||
(defun +org-present-init-org-tree-window-h ()
|
||||
"TODO"
|
||||
"Set up the org window for presentation."
|
||||
(doom/window-maximize-buffer)
|
||||
(let ((arg (if org-tree-slide-mode +1 -1)))
|
||||
|
@ -75,16 +84,14 @@
|
|||
|
||||
|
||||
;;
|
||||
;;; Helpers
|
||||
;;; Commands
|
||||
|
||||
(defun +org-present--cleanup-org-tree-slides-mode ()
|
||||
(unless (cl-loop for buf in (doom-buffers-in-mode 'org-mode)
|
||||
if (buffer-local-value 'org-tree-slide-mode buf)
|
||||
return t)
|
||||
(org-tree-slide-mode -1)
|
||||
(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)))
|
||||
(defvar +org-present--overlays nil)
|
||||
;;;###autoload
|
||||
(defun +org-present/start ()
|
||||
"TODO"
|
||||
(interactive)
|
||||
(unless (derived-mode-p 'org-mode)
|
||||
(error "Not in an org buffer"))
|
||||
(call-interactively #'org-tree-slide-mode)
|
||||
(add-hook 'kill-buffer-hook #'+org-present--cleanup-org-tree-slides-mode))
|
||||
|
|
|
@ -1,19 +1,5 @@
|
|||
;;; 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
|
||||
"A list of all indexed attachments in `org-directory'.")
|
||||
|
@ -21,7 +7,7 @@
|
|||
(defvar +org-attachments-files nil
|
||||
"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
|
||||
and END (defaults to `point-min' and `point-max')."
|
||||
(let ((case-fold-search t)
|
||||
|
@ -39,6 +25,21 @@ and END (defaults to `point-min' and `point-max')."
|
|||
(push (file-name-nondirectory link) attachments))))))
|
||||
(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
|
||||
(defun +org-attach/sync (arg)
|
||||
"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))
|
||||
(dolist (org-file (directory-files-recursively org-directory "\\.org$"))
|
||||
(insert-file-contents-literally org-file))
|
||||
(setq +org-attachments (+org-attachments--list)))
|
||||
(setq +org-attachments (+org-list-attachments)))
|
||||
;; clean up
|
||||
(let ((deleted 0))
|
||||
(dolist (file (cl-set-difference +org-attachments-files +org-attachments
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
(defvar org-capture-initial)
|
||||
|
||||
|
||||
;;
|
||||
;; External frame
|
||||
;;; External frame
|
||||
|
||||
;;;###autoload
|
||||
(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)
|
||||
(let ((filename (file-name-nondirectory path)))
|
||||
|
|
|
@ -11,11 +11,10 @@
|
|||
(IS-MAC ox-clip-osx-cmd))))
|
||||
(IS-LINUX
|
||||
(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))
|
||||
(apply
|
||||
'start-process "ox-clip" "*ox-clip*"
|
||||
(split-string ox-clip-linux-cmd " ")))))))
|
||||
(apply #'start-process "ox-clip" "*ox-clip*"
|
||||
(split-string ox-clip-linux-cmd " ")))))))
|
||||
|
||||
|
||||
;;
|
||||
|
|
|
@ -30,3 +30,20 @@
|
|||
(buffer-substring-no-properties (point) (point-max)))
|
||||
(message "Download of image \"%s\" failed" link)
|
||||
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))))
|
||||
|
|
97
modules/lang/org/autoload/org-tables.el
Normal file
97
modules/lang/org/autoload/org-tables.el
Normal 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)))
|
|
@ -17,162 +17,20 @@
|
|||
;;
|
||||
;;; Helpers
|
||||
|
||||
(defun +org--get-property (name &optional bound)
|
||||
(save-excursion
|
||||
(let ((re (format "^#\\+%s:[ \t]*\\([^\n]+\\)" (upcase name))))
|
||||
(goto-char (point-min))
|
||||
(when (re-search-forward re bound t)
|
||||
(buffer-substring-no-properties (match-beginning 1) (match-end 1))))))
|
||||
(defun +org--refresh-inline-images-in-subtree ()
|
||||
"Refresh image previews in the current heading/tree."
|
||||
(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-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)."
|
||||
(defun +org--insert-item (direction)
|
||||
(let* ((context
|
||||
(save-excursion
|
||||
(when (bolp)
|
||||
|
@ -252,17 +110,173 @@ wrong places)."
|
|||
(when (bound-and-true-p evil-local-mode)
|
||||
(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
|
||||
(defun +org/insert-item-below (count)
|
||||
"Inserts a new heading, table cell or item below the current one."
|
||||
(interactive "p")
|
||||
(dotimes (_ count)
|
||||
(+org-insert-item 'below)))
|
||||
(dotimes (_ count) (+org--insert-item 'below)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/insert-item-above (count)
|
||||
"Inserts a new heading, table cell or item above the current one."
|
||||
(interactive "p")
|
||||
(dotimes (_ count)
|
||||
(+org-insert-item 'above)))
|
||||
(dotimes (_ count) (+org--insert-item 'above)))
|
||||
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/dedent ()
|
||||
|
@ -279,40 +293,8 @@ wrong places)."
|
|||
(ignore-errors (org-promote)))
|
||||
((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
|
||||
(defalias #'+org/toggle-fold #'+org-cycle-only-current-subtree-h)
|
||||
|
||||
|
@ -363,29 +345,6 @@ another level of headings on each invocation."
|
|||
;;
|
||||
;;; 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
|
||||
(defun +org-indent-maybe-h ()
|
||||
"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))
|
||||
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
|
||||
(defun +org-update-cookies-h ()
|
||||
"Update counts in headlines (aka \"cookies\")."
|
||||
|
@ -464,13 +413,6 @@ with `org-cycle')."
|
|||
(org-cycle-internal-local)
|
||||
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
|
||||
(defun +org-unfold-to-2nd-level-or-point-h ()
|
||||
"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."
|
||||
(unless org-agenda-inhibit-startup
|
||||
(when (eq org-startup-folded t)
|
||||
(outline-hide-sublevels 2))
|
||||
(outline-hide-sublevels +org-initial-fold-level))
|
||||
(when (outline-invisible-p)
|
||||
(ignore-errors
|
||||
(save-excursion
|
||||
|
@ -486,12 +428,11 @@ unfold to point on startup."
|
|||
(org-show-subtree))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-enable-auto-reformat-tables-h ()
|
||||
"Realign tables & update formulas when exiting insert mode (`evil-mode')."
|
||||
(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)))
|
||||
(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
|
||||
(defun +org-enable-auto-update-cookies-h ()
|
||||
|
@ -499,38 +440,3 @@ unfold to point on startup."
|
|||
(when (featurep 'evil)
|
||||
(add-hook 'evil-insert-state-exit-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)))
|
||||
|
|
|
@ -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))
|
Loading…
Add table
Add a link
Reference in a new issue