2019-07-27 17:06:55 +02:00
|
|
|
;;; lang/org/autoload/org.el -*- lexical-binding: t; -*-
|
2017-07-05 02:33:41 +02:00
|
|
|
|
2019-08-07 16:31:45 -04:00
|
|
|
;; HACK A necessary hack because org requires a compilation step after being
|
|
|
|
;; cloned, and during that compilation a org-version.el is generated with these
|
|
|
|
;; two functions, which return the output of a 'git describe ...' call in the
|
|
|
|
;; repo's root. Of course, this command won't work in a sparse clone, and more
|
|
|
|
;; than that, initiating these compilation step is a hassle, so...
|
|
|
|
;;;###autoload (defun +org--release-a () "9.3")
|
|
|
|
;;;###autoload (fset 'org-release #'+org--release-a)
|
|
|
|
;;;###autoload (fset 'org-git-version #'ignore)
|
|
|
|
|
|
|
|
;; Org itself may override the above if it's loaded too early by packages that
|
|
|
|
;; depend on it, so we have to advise it once again:
|
|
|
|
;;;###autoload (advice-add #'org-release :override #'+org--release-a)
|
|
|
|
;;;###autoload (advice-add #'org-git-version :override #'ignore)
|
|
|
|
|
2019-07-23 18:33:00 +02:00
|
|
|
;;
|
|
|
|
;;; Helpers
|
|
|
|
|
2019-10-25 20:00:06 -04:00
|
|
|
(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))))))
|
|
|
|
|
|
|
|
(defun +org--insert-item (direction)
|
|
|
|
(let* ((context
|
|
|
|
(save-excursion
|
|
|
|
(when (bolp)
|
|
|
|
(back-to-indentation)
|
|
|
|
(forward-char))
|
|
|
|
(org-element-lineage
|
|
|
|
(org-element-context)
|
|
|
|
'(table table-row headline inlinetask item plain-list)
|
|
|
|
t)))
|
|
|
|
(type (org-element-type context)))
|
|
|
|
(cond ((memq type '(item plain-list))
|
|
|
|
(let ((marker (org-element-property :bullet context))
|
|
|
|
(pad (save-excursion
|
|
|
|
(org-beginning-of-item)
|
|
|
|
(back-to-indentation)
|
|
|
|
(- (point) (line-beginning-position)))))
|
|
|
|
(save-match-data
|
|
|
|
(pcase direction
|
|
|
|
(`below
|
|
|
|
(org-end-of-item)
|
|
|
|
(backward-char)
|
|
|
|
(end-of-line)
|
|
|
|
(if (and marker (string-match "\\([0-9]+\\)\\([).] *\\)" marker))
|
|
|
|
(let ((l (line-number-at-pos)))
|
|
|
|
(org-insert-item)
|
|
|
|
(when (= l (line-number-at-pos))
|
|
|
|
(org-next-item)
|
|
|
|
(org-end-of-line)))
|
|
|
|
(insert "\n" (make-string pad 32) (or marker ""))))
|
|
|
|
(`above
|
|
|
|
(org-beginning-of-item)
|
|
|
|
(if (and marker (string-match-p "[0-9]+[).]" marker))
|
|
|
|
(org-insert-item)
|
|
|
|
(insert (make-string pad 32) (or marker ""))
|
|
|
|
(save-excursion (insert "\n")))))))
|
|
|
|
(when (org-element-property :checkbox context)
|
|
|
|
(insert "[ ] ")))
|
|
|
|
|
|
|
|
((memq type '(table table-row))
|
|
|
|
(pcase direction
|
|
|
|
('below (save-excursion (org-table-insert-row t))
|
|
|
|
(org-table-next-row))
|
|
|
|
('above (save-excursion (org-shiftmetadown))
|
|
|
|
(+org/table-previous-row))))
|
|
|
|
|
|
|
|
((memq type '(headline inlinetask))
|
|
|
|
(let ((level (if (eq (org-element-type context) 'headline)
|
|
|
|
(org-element-property :level context)
|
|
|
|
1)))
|
|
|
|
(pcase direction
|
|
|
|
(`below
|
|
|
|
(let ((at-eol (>= (point) (1- (line-end-position))))
|
|
|
|
org-insert-heading-respect-content)
|
|
|
|
(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)
|
|
|
|
(insert (make-string level ?*) " ")
|
|
|
|
(save-excursion
|
|
|
|
(insert "\n")
|
|
|
|
(if (= level 1) (insert "\n")))))
|
|
|
|
(when-let (todo-keyword (org-element-property :todo-keyword context))
|
|
|
|
(org-todo (or (car (+org-get-todo-keywords-for todo-keyword))
|
|
|
|
'todo)))))
|
|
|
|
|
|
|
|
(t (user-error "Not a valid list, heading or table")))
|
|
|
|
|
|
|
|
(when (org-invisible-p)
|
|
|
|
(org-show-hidden-entry))
|
|
|
|
(when (bound-and-true-p evil-local-mode)
|
|
|
|
(evil-insert 1))))
|
2018-06-04 18:43:51 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-10-25 20:00:06 -04:00
|
|
|
(defun +org-get-global-property (property &optional file)
|
|
|
|
"Get #+PROPERTY from an org FILE (defaults to current file)."
|
2018-06-04 18:43:51 +02:00
|
|
|
(if file
|
2019-10-25 20:00:06 -04:00
|
|
|
(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)))))))
|
2018-02-13 18:19:35 -05:00
|
|
|
|
2018-10-19 15:43:24 -04:00
|
|
|
;;;###autoload
|
2019-10-25 20:00:06 -04:00
|
|
|
(defun +org-get-todo-keywords-for (&optional keyword)
|
|
|
|
"Returns the list of todo keywords that KEYWORD belongs to."
|
2018-10-19 15:43:24 -04:00
|
|
|
(when keyword
|
2019-10-25 20:00:06 -04:00
|
|
|
(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)
|
2018-10-19 15:43:24 -04:00
|
|
|
if (eq type 'sequence)
|
|
|
|
if (member keyword keywords)
|
|
|
|
return keywords)))
|
|
|
|
|
2018-02-13 18:19:35 -05:00
|
|
|
|
|
|
|
;;
|
2019-04-10 18:47:21 -04:00
|
|
|
;;; Modes
|
2018-02-13 18:19:35 -05:00
|
|
|
|
2017-07-05 02:33:41 +02:00
|
|
|
;;;###autoload
|
|
|
|
(define-minor-mode +org-pretty-mode
|
2018-06-04 18:48:54 +02:00
|
|
|
"Hides emphasis markers and toggles pretty entities."
|
2017-07-05 02:33:41 +02:00
|
|
|
:init-value nil
|
|
|
|
:lighter " *"
|
|
|
|
:group 'evil-org
|
|
|
|
(setq org-hide-emphasis-markers +org-pretty-mode)
|
|
|
|
(org-toggle-pretty-entities)
|
2019-01-08 20:54:03 -05:00
|
|
|
(with-silent-modifications
|
2017-09-28 18:08:20 +02:00
|
|
|
;; In case the above un-align tables
|
|
|
|
(org-table-map-tables 'org-table-align t)))
|
2017-07-05 02:33:41 +02:00
|
|
|
|
|
|
|
|
2018-02-13 18:19:35 -05:00
|
|
|
;;
|
2019-04-10 18:47:21 -04:00
|
|
|
;;; Commands
|
2017-07-05 02:33:41 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +org/dwim-at-point ()
|
2017-09-07 17:35:09 +02:00
|
|
|
"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.
|
2018-03-06 18:39:34 -05:00
|
|
|
- footnote reference: jump to the footnote's definition
|
|
|
|
- footnote definition: jump to the first reference of this footnote
|
2017-09-07 17:35:09 +02:00
|
|
|
- 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."
|
2017-07-05 02:33:41 +02:00
|
|
|
(interactive)
|
2018-07-24 20:01:42 +02:00
|
|
|
(let* ((context (org-element-context))
|
2017-07-05 02:33:41 +02:00
|
|
|
(type (org-element-type context)))
|
2017-09-30 17:06:09 +02:00
|
|
|
;; skip over unimportant contexts
|
2017-10-05 01:18:03 +02:00
|
|
|
(while (and context (memq type '(verbatim code bold italic underline strike-through subscript superscript)))
|
2017-09-30 17:06:09 +02:00
|
|
|
(setq context (org-element-property :parent context)
|
|
|
|
type (org-element-type context)))
|
2017-09-07 17:35:09 +02:00
|
|
|
(pcase type
|
|
|
|
(`headline
|
2019-03-02 01:57:54 -05:00
|
|
|
(cond ((and (fboundp 'toc-org-insert-toc)
|
|
|
|
(member "TOC" (org-get-tags)))
|
|
|
|
(toc-org-insert-toc)
|
|
|
|
(message "Updating table of contents"))
|
2019-06-25 20:29:51 +02:00
|
|
|
((string= "ARCHIVE" (car-safe (org-get-tags)))
|
|
|
|
(org-force-cycle-archived))
|
|
|
|
((or (org-element-property :todo-type context)
|
|
|
|
(org-element-property :scheduled context))
|
2017-09-07 17:35:09 +02:00
|
|
|
(org-todo
|
2018-10-19 15:43:24 -04:00
|
|
|
(if (eq (org-element-property :todo-type context) 'done)
|
|
|
|
(or (car (+org-get-todo-keywords-for (org-element-property :todo-keyword context)))
|
|
|
|
'todo)
|
|
|
|
'done)))
|
2017-09-07 17:35:09 +02:00
|
|
|
(t
|
2019-10-25 20:00:06 -04:00
|
|
|
(+org--refresh-inline-images-in-subtree)
|
2019-09-20 23:10:53 -04:00
|
|
|
(org-clear-latex-preview)
|
|
|
|
(org-latex-preview '(4)))))
|
2017-09-07 17:35:09 +02:00
|
|
|
|
|
|
|
(`clock (org-clock-update-time-maybe))
|
|
|
|
|
2018-03-06 18:39:34 -05:00
|
|
|
(`footnote-reference
|
|
|
|
(org-footnote-goto-definition (org-element-property :label context)))
|
|
|
|
|
2017-09-07 17:35:09 +02:00
|
|
|
(`footnote-definition
|
2018-03-06 18:39:34 -05:00
|
|
|
(org-footnote-goto-previous-reference (org-element-property :label context)))
|
2017-09-07 17:35:09 +02:00
|
|
|
|
2017-11-09 00:35:53 +01:00
|
|
|
((or `planning `timestamp)
|
|
|
|
(org-follow-timestamp-link))
|
2017-09-07 17:35:09 +02:00
|
|
|
|
|
|
|
((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)))
|
2019-06-25 21:38:16 +02:00
|
|
|
(bound-and-true-p evil-local-mode))
|
2017-09-07 17:35:09 +02:00
|
|
|
(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)
|
2019-09-20 23:10:53 -04:00
|
|
|
(org-latex-preview))
|
2017-09-07 17:35:09 +02:00
|
|
|
|
|
|
|
(`link
|
2018-10-17 16:17:36 -04:00
|
|
|
(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)))
|
2019-10-25 20:00:06 -04:00
|
|
|
(+org--refresh-inline-images-in-subtree)
|
2017-09-07 17:35:09 +02:00
|
|
|
(org-open-at-point))))
|
|
|
|
|
2019-07-13 02:24:11 +02:00
|
|
|
((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)))))
|
|
|
|
|
2019-10-25 20:00:06 -04:00
|
|
|
(_ (+org--refresh-inline-images-in-subtree)))))
|
2017-02-19 19:01:47 -05:00
|
|
|
|
|
|
|
|
2019-10-25 20:00:06 -04:00
|
|
|
;; 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).
|
2019-06-28 16:53:26 +02:00
|
|
|
;;;###autoload
|
|
|
|
(defun +org/insert-item-below (count)
|
2019-10-25 20:00:06 -04:00
|
|
|
"Inserts a new heading, table cell or item below the current one."
|
2019-06-28 16:53:26 +02:00
|
|
|
(interactive "p")
|
2019-10-25 20:00:06 -04:00
|
|
|
(dotimes (_ count) (+org--insert-item 'below)))
|
2019-06-28 16:53:26 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +org/insert-item-above (count)
|
2019-10-25 20:00:06 -04:00
|
|
|
"Inserts a new heading, table cell or item above the current one."
|
2019-06-28 16:53:26 +02:00
|
|
|
(interactive "p")
|
2019-10-25 20:00:06 -04:00
|
|
|
(dotimes (_ count) (+org--insert-item 'above)))
|
|
|
|
|
2019-06-28 16:53:26 +02:00
|
|
|
|
2017-02-19 19:01:47 -05:00
|
|
|
;;;###autoload
|
2018-02-18 00:26:27 -05:00
|
|
|
(defun +org/dedent ()
|
|
|
|
"TODO"
|
2018-02-13 18:19:35 -05:00
|
|
|
(interactive)
|
2018-02-18 00:26:27 -05:00
|
|
|
(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)))
|
|
|
|
((call-interactively #'self-insert-command))))
|
2017-02-19 19:01:47 -05:00
|
|
|
|
2017-07-05 02:33:41 +02:00
|
|
|
|
2019-10-25 20:00:06 -04:00
|
|
|
;;; Folds
|
2018-06-04 17:46:39 +02:00
|
|
|
;;;###autoload
|
2019-07-21 02:38:42 +02:00
|
|
|
(defalias #'+org/toggle-fold #'+org-cycle-only-current-subtree-h)
|
2018-06-04 17:46:39 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +org/open-fold ()
|
|
|
|
"Open the current fold (not but its children)."
|
|
|
|
(interactive)
|
|
|
|
(+org/toggle-fold t))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defalias #'+org/close-fold #'outline-hide-subtree)
|
|
|
|
|
|
|
|
(defun +org--get-foldlevel ()
|
|
|
|
(let ((max 1))
|
|
|
|
(save-restriction
|
|
|
|
(narrow-to-region (window-start) (window-end))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (not (eobp))
|
|
|
|
(org-next-visible-heading 1)
|
|
|
|
(when (outline-invisible-p (line-end-position))
|
|
|
|
(let ((level (org-outline-level)))
|
|
|
|
(when (> level max)
|
|
|
|
(setq max level))))))
|
|
|
|
max)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +org/show-next-fold-level ()
|
|
|
|
"Decrease the fold-level of the visible area of the buffer. This unfolds
|
|
|
|
another level of headings on each invocation."
|
|
|
|
(interactive)
|
|
|
|
(let* ((current-level (+org--get-foldlevel))
|
|
|
|
(new-level (1+ current-level)))
|
|
|
|
(outline-hide-sublevels new-level)
|
|
|
|
(message "Folded to level %s" new-level)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +org/hide-next-fold-level ()
|
|
|
|
"Increase the global fold-level of the visible area of the buffer. This folds
|
|
|
|
another level of headings on each invocation."
|
|
|
|
(interactive)
|
|
|
|
(let* ((current-level (+org--get-foldlevel))
|
|
|
|
(new-level (max 1 (1- current-level))))
|
|
|
|
(outline-hide-sublevels new-level)
|
|
|
|
(message "Folded to level %s" new-level)))
|
|
|
|
|
2018-02-13 18:19:35 -05:00
|
|
|
|
|
|
|
;;
|
2019-04-10 18:47:21 -04:00
|
|
|
;;; Hooks
|
2018-02-13 18:19:35 -05:00
|
|
|
|
2017-10-05 01:23:56 +02:00
|
|
|
;;;###autoload
|
2019-07-21 02:38:42 +02:00
|
|
|
(defun +org-indent-maybe-h ()
|
2019-04-04 18:47:40 -04:00
|
|
|
"Indent the current item (header or item), if possible.
|
|
|
|
Made for `org-tab-first-hook' in evil-mode."
|
2017-10-05 01:23:56 +02:00
|
|
|
(interactive)
|
2019-06-25 21:38:16 +02:00
|
|
|
(cond ((not (and (bound-and-true-p evil-local-mode)
|
|
|
|
(evil-insert-state-p)))
|
2018-02-13 18:33:36 -05:00
|
|
|
nil)
|
|
|
|
((org-at-item-p)
|
2018-07-30 04:04:13 +02:00
|
|
|
(if (eq this-command 'org-shifttab)
|
|
|
|
(org-outdent-item-tree)
|
|
|
|
(org-indent-item-tree))
|
2018-02-13 18:19:35 -05:00
|
|
|
t)
|
|
|
|
((org-at-heading-p)
|
2018-07-30 04:04:13 +02:00
|
|
|
(ignore-errors
|
|
|
|
(if (eq this-command 'org-shifttab)
|
|
|
|
(org-promote)
|
|
|
|
(org-demote)))
|
2018-02-13 18:19:35 -05:00
|
|
|
t)
|
|
|
|
((org-in-src-block-p t)
|
2018-02-13 19:41:05 -05:00
|
|
|
(org-babel-do-in-edit-buffer
|
|
|
|
(call-interactively #'indent-for-tab-command))
|
2018-02-13 18:19:35 -05:00
|
|
|
t)))
|
2017-10-05 01:23:56 +02:00
|
|
|
|
2018-02-13 18:19:35 -05:00
|
|
|
;;;###autoload
|
2019-07-21 02:38:42 +02:00
|
|
|
(defun +org-update-cookies-h ()
|
2018-02-13 18:19:35 -05:00
|
|
|
"Update counts in headlines (aka \"cookies\")."
|
|
|
|
(when (and buffer-file-name (file-exists-p buffer-file-name))
|
2018-10-30 16:20:25 -04:00
|
|
|
(let (org-hierarchical-todo-statistics)
|
|
|
|
(org-update-parent-todo-statistics))))
|
2018-02-13 18:19:35 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-07-21 02:38:42 +02:00
|
|
|
(defun +org-yas-expand-maybe-h ()
|
2018-02-13 18:19:35 -05:00
|
|
|
"Tries to expand a yasnippet snippet, if one is available. Made for
|
|
|
|
`org-tab-first-hook'."
|
2019-02-19 19:05:49 -05:00
|
|
|
(when (bound-and-true-p yas-minor-mode)
|
2019-05-31 20:11:56 -04:00
|
|
|
(cond ((and (or (not (bound-and-true-p evil-local-mode))
|
|
|
|
(evil-insert-state-p))
|
2019-02-19 19:05:49 -05:00
|
|
|
(yas--templates-for-key-at-point))
|
|
|
|
(call-interactively #'yas-expand)
|
|
|
|
t)
|
|
|
|
((use-region-p)
|
2019-05-31 20:11:56 -04:00
|
|
|
;; Triggering mode-specific indentation is expensive in src blocks
|
|
|
|
;; (if `org-src-tab-acts-natively' is non-nil), and can cause errors,
|
|
|
|
;; so we avoid smart indentation in this case.
|
|
|
|
(let ((yas-indent-line 'fixed))
|
|
|
|
(call-interactively #'yas-insert-snippet))
|
2019-02-19 19:05:49 -05:00
|
|
|
t))))
|
2018-04-04 06:56:56 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-07-21 02:38:42 +02:00
|
|
|
(defun +org-cycle-only-current-subtree-h (&optional arg)
|
2018-04-04 06:56:56 -04:00
|
|
|
"Toggle the local fold at the point (as opposed to cycling through all levels
|
|
|
|
with `org-cycle')."
|
2018-06-04 17:46:39 +02:00
|
|
|
(interactive "P")
|
2018-04-05 17:28:30 -04:00
|
|
|
(unless (eq this-command 'org-shifttab)
|
|
|
|
(save-excursion
|
|
|
|
(org-beginning-of-line)
|
2018-08-13 15:21:03 +02:00
|
|
|
(let (invisible-p)
|
|
|
|
(when (and (org-at-heading-p)
|
|
|
|
(or org-cycle-open-archived-trees
|
|
|
|
(not (member org-archive-tag (org-get-tags))))
|
|
|
|
(or (not arg)
|
|
|
|
(setq invisible-p (outline-invisible-p (line-end-position)))))
|
|
|
|
(unless invisible-p
|
|
|
|
(setq org-cycle-subtree-status 'subtree))
|
|
|
|
(org-cycle-internal-local)
|
|
|
|
t)))))
|
2018-05-08 15:36:42 +02:00
|
|
|
|
2019-04-10 18:47:21 -04:00
|
|
|
;;;###autoload
|
2019-07-21 02:38:42 +02:00
|
|
|
(defun +org-unfold-to-2nd-level-or-point-h ()
|
2019-04-10 18:47:21 -04:00
|
|
|
"My version of the 'overview' #+STARTUP option: expand first-level headings.
|
|
|
|
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)
|
2019-10-25 20:00:06 -04:00
|
|
|
(outline-hide-sublevels +org-initial-fold-level))
|
2019-04-10 18:47:21 -04:00
|
|
|
(when (outline-invisible-p)
|
|
|
|
(ignore-errors
|
|
|
|
(save-excursion
|
|
|
|
(outline-previous-visible-heading 1)
|
|
|
|
(org-show-subtree))))))
|
|
|
|
|
|
|
|
;;;###autoload
|
2019-10-25 20:00:06 -04:00
|
|
|
(defun +org-remove-occur-highlights-h ()
|
|
|
|
"Remove org occur highlights on ESC in normal mode."
|
|
|
|
(when org-occur-highlights
|
|
|
|
(org-remove-occur-highlights)
|
|
|
|
t))
|
2019-04-10 18:47:21 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-07-21 02:38:42 +02:00
|
|
|
(defun +org-enable-auto-update-cookies-h ()
|
2019-04-10 18:47:21 -04:00
|
|
|
"Update statistics cookies when saving or exiting insert mode (`evil-mode')."
|
|
|
|
(when (featurep 'evil)
|
2019-07-21 02:38:42 +02:00
|
|
|
(add-hook 'evil-insert-state-exit-hook #'+org-update-cookies-h nil t))
|
|
|
|
(add-hook 'before-save-hook #'+org-update-cookies-h nil t))
|