|
@@ -5457,13 +5457,13 @@ needs to be inserted at a specific position in the font-lock sequence.")
|
|
|
'(org-do-emphasis-faces (0 nil append))
|
|
|
'(org-do-emphasis-faces)))
|
|
|
;; Checkboxes
|
|
|
- '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)"
|
|
|
- 2 'org-checkbox prepend)
|
|
|
- (if org-provide-checkbox-statistics
|
|
|
+ '("^[ \t]*\\(?:[-+*]\\|[0-9]+[.)]\\)[ \t]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\(\\[[- X]\\]\\)"
|
|
|
+ 1 'org-checkbox prepend)
|
|
|
+ (if (cdr (assq 'checkbox org-list-automatic-rules))
|
|
|
'("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
|
|
|
(0 (org-get-checkbox-statistics-face) t)))
|
|
|
;; Description list items
|
|
|
- '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(.*? ::\\)"
|
|
|
+ '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\)[ \t]+\\(.*? ::\\)"
|
|
|
2 'bold prepend)
|
|
|
;; ARCHIVEd headings
|
|
|
(list (concat "^\\*+ \\(.*:" org-archive-tag ":.*\\)")
|
|
@@ -5900,12 +5900,15 @@ in special contexts.
|
|
|
(outline-next-heading)
|
|
|
(setq has-children (and (org-at-heading-p t)
|
|
|
(> (funcall outline-level) level))))
|
|
|
- (org-end-of-subtree t)
|
|
|
- (unless (eobp)
|
|
|
- (skip-chars-forward " \t\n")
|
|
|
- (beginning-of-line 1) ; in case this is an item
|
|
|
- )
|
|
|
- (setq eos (if (eobp) (point) (1- (point)))))
|
|
|
+ ;; if we're in a list, org-end-of-subtree is in fact org-end-of-item.
|
|
|
+ (if (org-at-item-p)
|
|
|
+ (setq eos (if (and (org-end-of-item) (bolp))
|
|
|
+ (1- (point))
|
|
|
+ (point)))
|
|
|
+ (org-end-of-subtree t)
|
|
|
+ (unless (eobp)
|
|
|
+ (skip-chars-forward " \t\n"))
|
|
|
+ (setq eos (if (eobp) (point) (1- (point))))))
|
|
|
;; Find out what to do next and set `this-command'
|
|
|
(cond
|
|
|
((= eos eoh)
|
|
@@ -5939,14 +5942,14 @@ in special contexts.
|
|
|
;; We just showed the children, or no children are there,
|
|
|
;; now show everything.
|
|
|
(run-hook-with-args 'org-pre-cycle-hook 'subtree)
|
|
|
- (org-show-subtree)
|
|
|
+ (outline-flag-region eoh eos nil)
|
|
|
(message (if children-skipped "SUBTREE (NO CHILDREN)" "SUBTREE"))
|
|
|
(setq org-cycle-subtree-status 'subtree)
|
|
|
(run-hook-with-args 'org-cycle-hook 'subtree))
|
|
|
(t
|
|
|
;; Default action: hide the subtree.
|
|
|
(run-hook-with-args 'org-pre-cycle-hook 'folded)
|
|
|
- (hide-subtree)
|
|
|
+ (outline-flag-region eoh eos t)
|
|
|
(message "FOLDED")
|
|
|
(setq org-cycle-subtree-status 'folded)
|
|
|
(run-hook-with-args 'org-cycle-hook 'folded)))))
|
|
@@ -7516,13 +7519,15 @@ and still retain the repeater to cover future instances of the task."
|
|
|
;;; Outline Sorting
|
|
|
|
|
|
(defun org-sort (with-case)
|
|
|
- "Call `org-sort-entries-or-items' or `org-table-sort-lines'.
|
|
|
+ "Call `org-sort-entries', `org-table-sort-lines' or `org-sort-list'.
|
|
|
Optional argument WITH-CASE means sort case-sensitively.
|
|
|
With a double prefix argument, also remove duplicate entries."
|
|
|
(interactive "P")
|
|
|
- (if (org-at-table-p)
|
|
|
- (org-call-with-arg 'org-table-sort-lines with-case)
|
|
|
- (org-call-with-arg 'org-sort-entries-or-items with-case)))
|
|
|
+ (cond
|
|
|
+ ((org-at-table-p) (org-call-with-arg 'org-table-sort-lines with-case))
|
|
|
+ ((org-at-item-p) (org-call-with-arg 'org-sort-list with-case))
|
|
|
+ (t
|
|
|
+ (org-call-with-arg 'org-sort-entries with-case))))
|
|
|
|
|
|
(defun org-sort-remove-invisible (s)
|
|
|
(remove-text-properties 0 (length s) org-rm-props s)
|
|
@@ -7540,14 +7545,12 @@ When children are sorted, the cursor is in the parent line when this
|
|
|
hook gets called. When a region or a plain list is sorted, the cursor
|
|
|
will be in the first entry of the sorted region/list.")
|
|
|
|
|
|
-(defun org-sort-entries-or-items
|
|
|
+(defun org-sort-entries
|
|
|
(&optional with-case sorting-type getkey-func compare-func property)
|
|
|
- "Sort entries on a certain level of an outline tree, or plain list items.
|
|
|
+ "Sort entries on a certain level of an outline tree.
|
|
|
If there is an active region, the entries in the region are sorted.
|
|
|
Else, if the cursor is before the first entry, sort the top-level items.
|
|
|
Else, the children of the entry at point are sorted.
|
|
|
-If the cursor is at the first item in a plain list, the list items will be
|
|
|
-sorted.
|
|
|
|
|
|
Sorting can be alphabetically, numerically, by date/time as given by
|
|
|
a time stamp, by a property or by priority.
|
|
@@ -7561,7 +7564,6 @@ n Numerically, by converting the beginning of the entry/item to a number.
|
|
|
a Alphabetically, ignoring the TODO keyword and the priority, if any.
|
|
|
t By date/time, either the first active time stamp in the entry, or, if
|
|
|
none exist, by the first inactive one.
|
|
|
- In items, only the first line will be checked.
|
|
|
s By the scheduled date/time.
|
|
|
d By deadline date/time.
|
|
|
c By creation time, which is assumed to be the first inactive time stamp
|
|
@@ -7580,7 +7582,7 @@ WITH-CASE, the sorting considers case as well."
|
|
|
(interactive "P")
|
|
|
(let ((case-func (if with-case 'identity 'downcase))
|
|
|
start beg end stars re re2
|
|
|
- txt what tmp plain-list-p)
|
|
|
+ txt what tmp)
|
|
|
;; Find beginning and end of region to sort
|
|
|
(cond
|
|
|
((org-region-active-p)
|
|
@@ -7590,15 +7592,6 @@ WITH-CASE, the sorting considers case as well."
|
|
|
(goto-char (region-beginning))
|
|
|
(if (not (org-on-heading-p)) (outline-next-heading))
|
|
|
(setq start (point)))
|
|
|
- ((org-at-item-p)
|
|
|
- ;; we will sort this plain list
|
|
|
- (org-beginning-of-item-list) (setq start (point))
|
|
|
- (org-end-of-item-list)
|
|
|
- (or (bolp) (insert "\n"))
|
|
|
- (setq end (point))
|
|
|
- (goto-char start)
|
|
|
- (setq plain-list-p t
|
|
|
- what "plain list"))
|
|
|
((or (org-on-heading-p)
|
|
|
(condition-case nil (progn (org-back-to-heading) t) (error nil)))
|
|
|
;; we will sort the children of the current headline
|
|
@@ -7631,43 +7624,39 @@ WITH-CASE, the sorting considers case as well."
|
|
|
(setq beg (point))
|
|
|
(if (>= beg end) (error "Nothing to sort"))
|
|
|
|
|
|
- (unless plain-list-p
|
|
|
- (looking-at "\\(\\*+\\)")
|
|
|
- (setq stars (match-string 1)
|
|
|
- re (concat "^" (regexp-quote stars) " +")
|
|
|
- re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
|
|
|
- txt (buffer-substring beg end))
|
|
|
- (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
|
|
|
- (if (and (not (equal stars "*")) (string-match re2 txt))
|
|
|
- (error "Region to sort contains a level above the first entry")))
|
|
|
+ (looking-at "\\(\\*+\\)")
|
|
|
+ (setq stars (match-string 1)
|
|
|
+ re (concat "^" (regexp-quote stars) " +")
|
|
|
+ re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
|
|
|
+ txt (buffer-substring beg end))
|
|
|
+ (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
|
|
|
+ (if (and (not (equal stars "*")) (string-match re2 txt))
|
|
|
+ (error "Region to sort contains a level above the first entry"))
|
|
|
|
|
|
(unless sorting-type
|
|
|
(message
|
|
|
- (if plain-list-p
|
|
|
- "Sort %s: [a]lpha [n]umeric [t]ime [f]unc A/N/T/F means reversed:"
|
|
|
- "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
|
|
|
+ "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
|
|
|
[t]ime [s]cheduled [d]eadline [c]reated
|
|
|
- A/N/T/S/D/C/P/O/F means reversed:")
|
|
|
+ A/N/T/S/D/C/P/O/F means reversed:"
|
|
|
what)
|
|
|
(setq sorting-type (read-char-exclusive))
|
|
|
|
|
|
(and (= (downcase sorting-type) ?f)
|
|
|
(setq getkey-func
|
|
|
(org-icompleting-read "Sort using function: "
|
|
|
- obarray 'fboundp t nil nil))
|
|
|
+ obarray 'fboundp t nil nil))
|
|
|
(setq getkey-func (intern getkey-func)))
|
|
|
|
|
|
(and (= (downcase sorting-type) ?r)
|
|
|
(setq property
|
|
|
(org-icompleting-read "Property: "
|
|
|
- (mapcar 'list (org-buffer-property-keys t))
|
|
|
- nil t))))
|
|
|
+ (mapcar 'list (org-buffer-property-keys t))
|
|
|
+ nil t))))
|
|
|
|
|
|
(message "Sorting entries...")
|
|
|
|
|
|
(save-restriction
|
|
|
(narrow-to-region start end)
|
|
|
-
|
|
|
(let ((dcst (downcase sorting-type))
|
|
|
(case-fold-search nil)
|
|
|
(now (current-time)))
|
|
@@ -7675,99 +7664,70 @@ WITH-CASE, the sorting considers case as well."
|
|
|
(/= dcst sorting-type)
|
|
|
;; This function moves to the beginning character of the "record" to
|
|
|
;; be sorted.
|
|
|
- (if plain-list-p
|
|
|
- (lambda nil
|
|
|
- (if (org-at-item-p) t (goto-char (point-max))))
|
|
|
- (lambda nil
|
|
|
- (if (re-search-forward re nil t)
|
|
|
- (goto-char (match-beginning 0))
|
|
|
- (goto-char (point-max)))))
|
|
|
+ (lambda nil
|
|
|
+ (if (re-search-forward re nil t)
|
|
|
+ (goto-char (match-beginning 0))
|
|
|
+ (goto-char (point-max))))
|
|
|
;; This function moves to the last character of the "record" being
|
|
|
;; sorted.
|
|
|
- (if plain-list-p
|
|
|
- 'org-end-of-item
|
|
|
- (lambda nil
|
|
|
- (save-match-data
|
|
|
- (condition-case nil
|
|
|
- (outline-forward-same-level 1)
|
|
|
- (error
|
|
|
- (goto-char (point-max)))))))
|
|
|
-
|
|
|
+ (lambda nil
|
|
|
+ (save-match-data
|
|
|
+ (condition-case nil
|
|
|
+ (outline-forward-same-level 1)
|
|
|
+ (error
|
|
|
+ (goto-char (point-max))))))
|
|
|
;; This function returns the value that gets sorted against.
|
|
|
- (if plain-list-p
|
|
|
- (lambda nil
|
|
|
- (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+")
|
|
|
- (cond
|
|
|
- ((= dcst ?n)
|
|
|
- (string-to-number (buffer-substring (match-end 0)
|
|
|
- (point-at-eol))))
|
|
|
- ((= dcst ?a)
|
|
|
- (buffer-substring (match-end 0) (point-at-eol)))
|
|
|
- ((= dcst ?t)
|
|
|
- (if (or (re-search-forward org-ts-regexp (point-at-eol) t)
|
|
|
- (re-search-forward org-ts-regexp-both
|
|
|
- (point-at-eol) t))
|
|
|
- (org-time-string-to-seconds (match-string 0))
|
|
|
- (org-float-time now)))
|
|
|
- ((= dcst ?f)
|
|
|
- (if getkey-func
|
|
|
- (progn
|
|
|
- (setq tmp (funcall getkey-func))
|
|
|
- (if (stringp tmp) (setq tmp (funcall case-func tmp)))
|
|
|
- tmp)
|
|
|
- (error "Invalid key function `%s'" getkey-func)))
|
|
|
- (t (error "Invalid sorting type `%c'" sorting-type)))))
|
|
|
- (lambda nil
|
|
|
- (cond
|
|
|
- ((= dcst ?n)
|
|
|
- (if (looking-at org-complex-heading-regexp)
|
|
|
- (string-to-number (match-string 4))
|
|
|
- nil))
|
|
|
- ((= dcst ?a)
|
|
|
- (if (looking-at org-complex-heading-regexp)
|
|
|
- (funcall case-func (match-string 4))
|
|
|
- nil))
|
|
|
- ((= dcst ?t)
|
|
|
- (let ((end (save-excursion (outline-next-heading) (point))))
|
|
|
- (if (or (re-search-forward org-ts-regexp end t)
|
|
|
- (re-search-forward org-ts-regexp-both end t))
|
|
|
- (org-time-string-to-seconds (match-string 0))
|
|
|
- (org-float-time now))))
|
|
|
- ((= dcst ?c)
|
|
|
- (let ((end (save-excursion (outline-next-heading) (point))))
|
|
|
- (if (re-search-forward
|
|
|
- (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
|
|
|
- end t)
|
|
|
- (org-time-string-to-seconds (match-string 0))
|
|
|
- (org-float-time now))))
|
|
|
- ((= dcst ?s)
|
|
|
- (let ((end (save-excursion (outline-next-heading) (point))))
|
|
|
- (if (re-search-forward org-scheduled-time-regexp end t)
|
|
|
- (org-time-string-to-seconds (match-string 1))
|
|
|
- (org-float-time now))))
|
|
|
- ((= dcst ?d)
|
|
|
- (let ((end (save-excursion (outline-next-heading) (point))))
|
|
|
- (if (re-search-forward org-deadline-time-regexp end t)
|
|
|
- (org-time-string-to-seconds (match-string 1))
|
|
|
- (org-float-time now))))
|
|
|
- ((= dcst ?p)
|
|
|
- (if (re-search-forward org-priority-regexp (point-at-eol) t)
|
|
|
- (string-to-char (match-string 2))
|
|
|
- org-default-priority))
|
|
|
- ((= dcst ?r)
|
|
|
- (or (org-entry-get nil property) ""))
|
|
|
- ((= dcst ?o)
|
|
|
- (if (looking-at org-complex-heading-regexp)
|
|
|
- (- 9999 (length (member (match-string 2)
|
|
|
- org-todo-keywords-1)))))
|
|
|
- ((= dcst ?f)
|
|
|
- (if getkey-func
|
|
|
- (progn
|
|
|
- (setq tmp (funcall getkey-func))
|
|
|
- (if (stringp tmp) (setq tmp (funcall case-func tmp)))
|
|
|
- tmp)
|
|
|
- (error "Invalid key function `%s'" getkey-func)))
|
|
|
- (t (error "Invalid sorting type `%c'" sorting-type)))))
|
|
|
+ (lambda nil
|
|
|
+ (cond
|
|
|
+ ((= dcst ?n)
|
|
|
+ (if (looking-at org-complex-heading-regexp)
|
|
|
+ (string-to-number (match-string 4))
|
|
|
+ nil))
|
|
|
+ ((= dcst ?a)
|
|
|
+ (if (looking-at org-complex-heading-regexp)
|
|
|
+ (funcall case-func (match-string 4))
|
|
|
+ nil))
|
|
|
+ ((= dcst ?t)
|
|
|
+ (let ((end (save-excursion (outline-next-heading) (point))))
|
|
|
+ (if (or (re-search-forward org-ts-regexp end t)
|
|
|
+ (re-search-forward org-ts-regexp-both end t))
|
|
|
+ (org-time-string-to-seconds (match-string 0))
|
|
|
+ (org-float-time now))))
|
|
|
+ ((= dcst ?c)
|
|
|
+ (let ((end (save-excursion (outline-next-heading) (point))))
|
|
|
+ (if (re-search-forward
|
|
|
+ (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
|
|
|
+ end t)
|
|
|
+ (org-time-string-to-seconds (match-string 0))
|
|
|
+ (org-float-time now))))
|
|
|
+ ((= dcst ?s)
|
|
|
+ (let ((end (save-excursion (outline-next-heading) (point))))
|
|
|
+ (if (re-search-forward org-scheduled-time-regexp end t)
|
|
|
+ (org-time-string-to-seconds (match-string 1))
|
|
|
+ (org-float-time now))))
|
|
|
+ ((= dcst ?d)
|
|
|
+ (let ((end (save-excursion (outline-next-heading) (point))))
|
|
|
+ (if (re-search-forward org-deadline-time-regexp end t)
|
|
|
+ (org-time-string-to-seconds (match-string 1))
|
|
|
+ (org-float-time now))))
|
|
|
+ ((= dcst ?p)
|
|
|
+ (if (re-search-forward org-priority-regexp (point-at-eol) t)
|
|
|
+ (string-to-char (match-string 2))
|
|
|
+ org-default-priority))
|
|
|
+ ((= dcst ?r)
|
|
|
+ (or (org-entry-get nil property) ""))
|
|
|
+ ((= dcst ?o)
|
|
|
+ (if (looking-at org-complex-heading-regexp)
|
|
|
+ (- 9999 (length (member (match-string 2)
|
|
|
+ org-todo-keywords-1)))))
|
|
|
+ ((= dcst ?f)
|
|
|
+ (if getkey-func
|
|
|
+ (progn
|
|
|
+ (setq tmp (funcall getkey-func))
|
|
|
+ (if (stringp tmp) (setq tmp (funcall case-func tmp)))
|
|
|
+ tmp)
|
|
|
+ (error "Invalid key function `%s'" getkey-func)))
|
|
|
+ (t (error "Invalid sorting type `%c'" sorting-type))))
|
|
|
nil
|
|
|
(cond
|
|
|
((= dcst ?a) 'string<)
|
|
@@ -11739,7 +11699,7 @@ This is done in the same way as adding a state change note."
|
|
|
|
|
|
(defvar org-property-end-re)
|
|
|
(defun org-add-log-setup (&optional purpose state prev-state
|
|
|
- findpos how &optional extra)
|
|
|
+ findpos how extra)
|
|
|
"Set up the post command hook to take a note.
|
|
|
If this is about to TODO state change, the new state is expected in STATE.
|
|
|
When FINDPOS is non-nil, find the correct position for the note in
|
|
@@ -11888,8 +11848,8 @@ EXTRA is additional text that will be inserted into the notes buffer."
|
|
|
(move-marker org-log-note-marker nil)
|
|
|
(end-of-line 1)
|
|
|
(if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
|
|
|
- (insert "- " (pop lines))
|
|
|
(org-indent-line-function)
|
|
|
+ (insert "- " (pop lines))
|
|
|
(beginning-of-line 1)
|
|
|
(looking-at "[ \t]*")
|
|
|
(setq ind (concat (match-string 0) " "))
|
|
@@ -17247,12 +17207,12 @@ This command does many different things, depending on context:
|
|
|
(org-footnote-at-definition-p))
|
|
|
(call-interactively 'org-footnote-action))
|
|
|
((org-at-item-checkbox-p)
|
|
|
+ (call-interactively 'org-list-repair)
|
|
|
(call-interactively 'org-toggle-checkbox)
|
|
|
(org-list-send-list 'maybe))
|
|
|
((org-at-item-p)
|
|
|
- (if arg
|
|
|
- (call-interactively 'org-toggle-checkbox)
|
|
|
- (call-interactively 'org-maybe-renumber-ordered-list))
|
|
|
+ (call-interactively 'org-list-repair)
|
|
|
+ (when arg (call-interactively 'org-toggle-checkbox))
|
|
|
(org-list-send-list 'maybe))
|
|
|
((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
|
|
|
;; Dynamic block
|
|
@@ -17375,21 +17335,21 @@ If the first line is normal text, add an item bullet to each line."
|
|
|
;; We already have items, de-itemize
|
|
|
(while (< (setq l (1+ l)) l2)
|
|
|
(when (org-at-item-p)
|
|
|
- (goto-char (match-beginning 2))
|
|
|
- (delete-region (match-beginning 2) (match-end 2))
|
|
|
- (and (looking-at "[ \t]+") (replace-match "")))
|
|
|
+ (skip-chars-forward " \t")
|
|
|
+ (delete-region (point) (match-end 0)))
|
|
|
(beginning-of-line 2))
|
|
|
(if (org-on-heading-p)
|
|
|
;; Headings, convert to items
|
|
|
(while (< (setq l (1+ l)) l2)
|
|
|
(if (looking-at org-outline-regexp)
|
|
|
- (replace-match "- " t t))
|
|
|
+ (replace-match (org-list-bullet-string "-") t t))
|
|
|
(beginning-of-line 2))
|
|
|
;; normal lines, turn them into items
|
|
|
(while (< (setq l (1+ l)) l2)
|
|
|
(unless (org-at-item-p)
|
|
|
(if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
|
|
|
- (replace-match "\\1- \\2")))
|
|
|
+ (replace-match
|
|
|
+ (concat "\\1" (org-list-bullet-string "-") "\\2"))))
|
|
|
(beginning-of-line 2)))))))
|
|
|
|
|
|
(defun org-toggle-heading (&optional nstars)
|
|
@@ -18272,16 +18232,23 @@ really on, so that the block visually is on the match."
|
|
|
(throw 'exit t)))
|
|
|
nil))))
|
|
|
|
|
|
-(defun org-in-regexps-block-p (start-re end-re)
|
|
|
- "Return t if the current point is between matches of START-RE and END-RE.
|
|
|
-This will also return to if point is on one of the two matches."
|
|
|
- (interactive)
|
|
|
- (let ((p (point)))
|
|
|
+(defun org-in-regexps-block-p (start-re end-re &optional bound)
|
|
|
+ "Returns t if the current point is between matches of START-RE and END-RE.
|
|
|
+This will also return t if point is on one of the two matches or
|
|
|
+in an unfinished block. END-RE can be a string or a form
|
|
|
+returning a string.
|
|
|
+
|
|
|
+An optional third argument bounds the search for START-RE. It
|
|
|
+defaults to previous heading or `point-min'."
|
|
|
+ (let ((pos (point))
|
|
|
+ (limit (or bound (save-excursion (outline-previous-heading)))))
|
|
|
(save-excursion
|
|
|
- (and (or (org-at-regexp-p start-re)
|
|
|
- (re-search-backward start-re nil t))
|
|
|
- (re-search-forward end-re nil t)
|
|
|
- (>= (point) p)))))
|
|
|
+ ;; we're on a block when point is on start-re...
|
|
|
+ (or (org-at-regexp-p start-re)
|
|
|
+ ;; ... or start-re can be found above...
|
|
|
+ (and (re-search-backward start-re limit t)
|
|
|
+ ;; ... but no end-re between start-re and point.
|
|
|
+ (not (re-search-forward (eval end-re) pos t)))))))
|
|
|
|
|
|
(defun org-occur-in-agenda-files (regexp &optional nlines)
|
|
|
"Call `multi-occur' with buffers for all agenda files."
|
|
@@ -18561,57 +18528,87 @@ which make use of the date at the cursor."
|
|
|
;; Find the previous relevant line
|
|
|
(beginning-of-line 1)
|
|
|
(cond
|
|
|
+ ;; Comments
|
|
|
((looking-at "#") (setq column 0))
|
|
|
+ ;; Headings
|
|
|
((looking-at "\\*+ ") (setq column 0))
|
|
|
+ ;; Drawers
|
|
|
((and (looking-at "[ \t]*:END:")
|
|
|
(save-excursion (re-search-backward org-drawer-regexp nil t)))
|
|
|
(save-excursion
|
|
|
(goto-char (1- (match-beginning 1)))
|
|
|
(setq column (current-column))))
|
|
|
- ((and (looking-at "[ \t]+#\\+end_\\([a-z]+\\)")
|
|
|
+ ;; Special blocks
|
|
|
+ ((and (looking-at "[ \t]*#\\+end_\\([a-z]+\\)")
|
|
|
(save-excursion
|
|
|
(re-search-backward
|
|
|
(concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
|
|
|
(setq column (org-get-indentation (match-string 0))))
|
|
|
+ ((and (not (looking-at "[ \t]*#\\+begin_"))
|
|
|
+ (org-in-regexps-block-p "^[ \t]*#\\+begin_" "[ \t]*#\\+end_"))
|
|
|
+ (save-excursion
|
|
|
+ (re-search-backward "^[ \t]*#\\+begin_\\([a-z]+\\)" nil t))
|
|
|
+ (setq column
|
|
|
+ (if (equal (downcase (match-string 1)) "src")
|
|
|
+ ;; src blocks: let `org-edit-src-exit' handle them
|
|
|
+ (org-get-indentation)
|
|
|
+ (org-get-indentation (match-string 0)))))
|
|
|
+ ;; Lists
|
|
|
+ ((org-in-item-p)
|
|
|
+ (org-beginning-of-item)
|
|
|
+ (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?")
|
|
|
+ (setq bpos (match-beginning 1) tpos (match-end 0)
|
|
|
+ bcol (progn (goto-char bpos) (current-column))
|
|
|
+ tcol (progn (goto-char tpos) (current-column))
|
|
|
+ bullet (match-string 1)
|
|
|
+ bullet-type (if (string-match "[0-9]" bullet) "n" bullet))
|
|
|
+ (if (> tcol (+ bcol org-description-max-indent))
|
|
|
+ (setq tcol (+ bcol 5)))
|
|
|
+ (if (not itemp)
|
|
|
+ (setq column tcol)
|
|
|
+ (beginning-of-line 1)
|
|
|
+ (goto-char pos)
|
|
|
+ (if (looking-at "\\S-")
|
|
|
+ (progn
|
|
|
+ (looking-at "[ \t]*\\(\\S-+\\)[ \t]*")
|
|
|
+ (setq bullet (match-string 1)
|
|
|
+ btype (if (string-match "[0-9]" bullet) "n" bullet))
|
|
|
+ (setq column (if (equal btype bullet-type) bcol tcol)))
|
|
|
+ (setq column (org-get-indentation)))))
|
|
|
+ ;; This line has nothing special, look upside to get a clue about
|
|
|
+ ;; what to do.
|
|
|
(t
|
|
|
(beginning-of-line 0)
|
|
|
(while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")
|
|
|
- (not (looking-at "[ \t]*:END:"))
|
|
|
- (not (looking-at org-drawer-regexp)))
|
|
|
- (beginning-of-line 0))
|
|
|
+ (not (looking-at "[ \t]*:END:"))
|
|
|
+ (not (looking-at org-drawer-regexp)))
|
|
|
+ (beginning-of-line 0))
|
|
|
(cond
|
|
|
+ ;; There was an heading above.
|
|
|
((looking-at "\\*+[ \t]+")
|
|
|
(if (not org-adapt-indentation)
|
|
|
(setq column 0)
|
|
|
(goto-char (match-end 0))
|
|
|
(setq column (current-column))))
|
|
|
+ ;; A drawer had started and is unfinished: indent consequently.
|
|
|
((looking-at org-drawer-regexp)
|
|
|
- (goto-char (1- (match-beginning 1)))
|
|
|
- (setq column (current-column)))
|
|
|
+ (goto-char (1- (match-beginning 1)))
|
|
|
+ (setq column (current-column)))
|
|
|
+ ;; The drawer had ended: indent like its :END: line.
|
|
|
((looking-at "\\([ \t]*\\):END:")
|
|
|
- (goto-char (match-end 1))
|
|
|
- (setq column (current-column)))
|
|
|
+ (goto-char (match-end 1))
|
|
|
+ (setq column (current-column)))
|
|
|
+ ;; There was a list that since ended: indent relatively to
|
|
|
+ ;; current heading.
|
|
|
((org-in-item-p)
|
|
|
- (org-beginning-of-item)
|
|
|
- (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?")
|
|
|
- (setq bpos (match-beginning 1) tpos (match-end 0)
|
|
|
- bcol (progn (goto-char bpos) (current-column))
|
|
|
- tcol (progn (goto-char tpos) (current-column))
|
|
|
- bullet (match-string 1)
|
|
|
- bullet-type (if (string-match "[0-9]" bullet) "n" bullet))
|
|
|
- (if (> tcol (+ bcol org-description-max-indent))
|
|
|
- (setq tcol (+ bcol 5)))
|
|
|
- (if (not itemp)
|
|
|
- (setq column tcol)
|
|
|
- (goto-char pos)
|
|
|
- (beginning-of-line 1)
|
|
|
- (if (looking-at "\\S-")
|
|
|
- (progn
|
|
|
- (looking-at "[ \t]*\\(\\S-+\\)[ \t]*")
|
|
|
- (setq bullet (match-string 1)
|
|
|
- btype (if (string-match "[0-9]" bullet) "n" bullet))
|
|
|
- (setq column (if (equal btype bullet-type) bcol tcol)))
|
|
|
- (setq column (org-get-indentation)))))
|
|
|
+ (outline-previous-heading)
|
|
|
+ (if (and org-adapt-indentation
|
|
|
+ (looking-at "\\*+[ \t]+"))
|
|
|
+ (progn
|
|
|
+ (goto-char (match-end 0))
|
|
|
+ (setq column (current-column)))
|
|
|
+ (setq column 0)))
|
|
|
+ ;; Else, nothing noticeable found: get indentation and go on.
|
|
|
(t (setq column (org-get-indentation))))))
|
|
|
(goto-char pos)
|
|
|
(if (<= (current-column) (current-indentation))
|