about summary refs log tree commit diff stats
path: root/lisp/acdw-org.el
diff options
context:
space:
mode:
authorCase Duckworth2021-04-13 17:44:52 -0500
committerCase Duckworth2021-04-13 17:44:52 -0500
commit758048eb5798429a4f925e54fdb758e992d7fd06 (patch)
tree115a9da0d904c24ecd6dfa54548de057c23ccd87 /lisp/acdw-org.el
parentAdd a generate custom ids function for headings (diff)
downloademacs-758048eb5798429a4f925e54fdb758e992d7fd06.tar.gz
emacs-758048eb5798429a4f925e54fdb758e992d7fd06.zip
Formatting etc.
This keeps happening :/
Diffstat (limited to 'lisp/acdw-org.el')
-rw-r--r--lisp/acdw-org.el45
1 files changed, 14 insertions, 31 deletions
diff --git a/lisp/acdw-org.el b/lisp/acdw-org.el index 48760a2..7e9fecd 100644 --- a/lisp/acdw-org.el +++ b/lisp/acdw-org.el
@@ -17,49 +17,42 @@
17 17
18;;; Code: 18;;; Code:
19 19
20
20;;; unpackaged.el: https://github.com/alphapapa/unpackaged.el 21;;; unpackaged.el: https://github.com/alphapapa/unpackaged.el
21 22
22;;; ORG-RETURN-DWIM
23
24(defun unpackaged/org-element-descendant-of (type element) 23(defun unpackaged/org-element-descendant-of (type element)
25 "Return non-nil if ELEMENT is a descendant of TYPE. 24 "Return non-nil if ELEMENT is a descendant of TYPE.
26TYPE should be an element type, like `item' or `paragraph'. 25TYPE should be an element type, like `item' or `paragraph'.
27ELEMENT should be a list like that returned by 26ELEMENT should be a list like that returned by `org-element-context'."
28`org-element-context'."
29 ;; MAYBE: Use `org-element-lineage'. 27 ;; MAYBE: Use `org-element-lineage'.
30 (when-let* ((parent (org-element-property :parent element))) 28 (when-let* ((parent (org-element-property :parent element)))
31 (or (eq type (car parent)) 29 (or (eq type (car parent))
32 (unpackaged/org-element-descendant-of type parent)))) 30 (unpackaged/org-element-descendant-of type parent))))
33 31
32;;;###autoload
34(defun unpackaged/org-return-dwim (&optional default) 33(defun unpackaged/org-return-dwim (&optional default)
35 "A helpful replacement for `org-return'. With prefix, 34 "A helpful replacement for `org-return'. With prefix, call `org-return'.
36call `org-return'.
37 35
38On headings, move point to position after entry content. In 36On headings, move point to position after entry content. In
39lists, insert a new item or end the list, with checkbox if 37lists, insert a new item or end the list, with checkbox if
40appropriate. In tables, insert a new row or end the table." 38appropriate. In tables, insert a new row or end the table."
41 ;; Inspired by John Kitchin: 39 ;; Inspired by John Kitchin: http://kitchingroup.cheme.cmu.edu/blog/2017/04/09/A-better-return-in-org-mode/
42 ;; http://kitchingroup.cheme.cmu.edu/blog/2017/04/09/A-better-return-in-org-mode/
43 (interactive "P") 40 (interactive "P")
44 (if default 41 (if default
45 (org-return) 42 (org-return)
46 (cond 43 (cond
47 ;; Act depending on context around point. 44 ;; Act depending on context around point.
48 45
49 ;; NOTE: I prefer RET to not follow links, but by uncommenting 46 ;; NOTE: I prefer RET to not follow links, but by uncommenting this block, links will be
50 ;; this block, links will be followed. 47 ;; followed.
51 ;; FURTHER NOTE: Ideally, I would follow links unless point
52 ;; /appeared/ to be at the end of the line (even if it's still
53 ;; inside the link) -- when it would do `org-return'. That
54 ;; would take some /doing/, however.
55 48
56 ;; ((eq 'link (car (org-element-context))) 49 ;; ((eq 'link (car (org-element-context)))
57 ;; ;; Link: Open it. 50 ;; ;; Link: Open it.
58 ;; (org-open-at-point-global)) 51 ;; (org-open-at-point-global))
59 52
60 ((org-at-heading-p) 53 ((org-at-heading-p)
61 ;; Heading: Move to position after entry content. NOTE: This is 54 ;; Heading: Move to position after entry content.
62 ;; probably the most interesting feature of this function. 55 ;; NOTE: This is probably the most interesting feature of this function.
63 (let ((heading-start (org-entry-beginning-position))) 56 (let ((heading-start (org-entry-beginning-position)))
64 (goto-char (org-entry-end-position)) 57 (goto-char (org-entry-end-position))
65 (cond ((and (org-at-heading-p) 58 (cond ((and (org-at-heading-p)
@@ -76,13 +69,8 @@ appropriate. In tables, insert a new row or end the table."
76 (forward-line) 69 (forward-line)
77 (insert "\n") 70 (insert "\n")
78 (forward-line -1)) 71 (forward-line -1))
79 ;; FIXME: looking-back is supposed to be called with 72 ;; FIXME: looking-back is supposed to be called with more arguments.
80 ;; more arguments. 73 (while (not (looking-back (rx (repeat 3 (seq (optional blank) "\n")))))
81 (while (not (looking-back (rx
82 (repeat 3
83 (seq (optional blank)
84 "\n")))
85 nil))
86 (insert "\n")) 74 (insert "\n"))
87 (forward-line -1))))) 75 (forward-line -1)))))
88 76
@@ -120,14 +108,11 @@ appropriate. In tables, insert a new row or end the table."
120 ;; See `org-table-next-field'. 108 ;; See `org-table-next-field'.
121 (cl-loop with end = (line-end-position) 109 (cl-loop with end = (line-end-position)
122 for cell = (org-element-table-cell-parser) 110 for cell = (org-element-table-cell-parser)
123 always (equal (org-element-property 111 always (equal (org-element-property :contents-begin cell)
124 :contents-begin cell) 112 (org-element-property :contents-end cell))
125 (org-element-property
126 :contents-end cell))
127 while (re-search-forward "|" end t))) 113 while (re-search-forward "|" end t)))
128 ;; Empty row: end the table. 114 ;; Empty row: end the table.
129 (delete-region (line-beginning-position) 115 (delete-region (line-beginning-position) (line-end-position))
130 (line-end-position))
131 (org-return)) 116 (org-return))
132 (t 117 (t
133 ;; Non-empty row: call `org-return'. 118 ;; Non-empty row: call `org-return'.
@@ -136,8 +121,6 @@ appropriate. In tables, insert a new row or end the table."
136 ;; All other cases: call `org-return'. 121 ;; All other cases: call `org-return'.
137 (org-return))))) 122 (org-return)))))
138 123
139;;; ORG-FIX-BLANK-LINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
140
141(defun unpackaged/org-fix-blank-lines (&optional prefix) 124(defun unpackaged/org-fix-blank-lines (&optional prefix)
142 "Ensure that blank lines exist between headings and 125 "Ensure that blank lines exist between headings and
143 between headings and their contents. With prefix, operate on 126 between headings and their contents. With prefix, operate on