parent
29bbc0faa6
commit
758048eb57
|
@ -17,49 +17,42 @@
|
|||
|
||||
;;; Code:
|
||||
|
||||
|
||||
;;; unpackaged.el: https://github.com/alphapapa/unpackaged.el
|
||||
|
||||
;;; ORG-RETURN-DWIM
|
||||
|
||||
(defun unpackaged/org-element-descendant-of (type element)
|
||||
"Return non-nil if ELEMENT is a descendant of TYPE.
|
||||
TYPE should be an element type, like `item' or `paragraph'.
|
||||
ELEMENT should be a list like that returned by
|
||||
`org-element-context'."
|
||||
ELEMENT should be a list like that returned by `org-element-context'."
|
||||
;; MAYBE: Use `org-element-lineage'.
|
||||
(when-let* ((parent (org-element-property :parent element)))
|
||||
(or (eq type (car parent))
|
||||
(unpackaged/org-element-descendant-of type parent))))
|
||||
|
||||
;;;###autoload
|
||||
(defun unpackaged/org-return-dwim (&optional default)
|
||||
"A helpful replacement for `org-return'. With prefix,
|
||||
call `org-return'.
|
||||
"A helpful replacement for `org-return'. With prefix, call `org-return'.
|
||||
|
||||
On headings, move point to position after entry content. In
|
||||
lists, insert a new item or end the list, with checkbox if
|
||||
appropriate. In tables, insert a new row or end the table."
|
||||
;; Inspired by John Kitchin:
|
||||
;; http://kitchingroup.cheme.cmu.edu/blog/2017/04/09/A-better-return-in-org-mode/
|
||||
;; Inspired by John Kitchin: http://kitchingroup.cheme.cmu.edu/blog/2017/04/09/A-better-return-in-org-mode/
|
||||
(interactive "P")
|
||||
(if default
|
||||
(org-return)
|
||||
(cond
|
||||
;; Act depending on context around point.
|
||||
|
||||
;; NOTE: I prefer RET to not follow links, but by uncommenting
|
||||
;; this block, links will be followed.
|
||||
;; FURTHER NOTE: Ideally, I would follow links unless point
|
||||
;; /appeared/ to be at the end of the line (even if it's still
|
||||
;; inside the link) -- when it would do `org-return'. That
|
||||
;; would take some /doing/, however.
|
||||
;; NOTE: I prefer RET to not follow links, but by uncommenting this block, links will be
|
||||
;; followed.
|
||||
|
||||
;; ((eq 'link (car (org-element-context)))
|
||||
;; ;; Link: Open it.
|
||||
;; (org-open-at-point-global))
|
||||
|
||||
((org-at-heading-p)
|
||||
;; Heading: Move to position after entry content. NOTE: This is
|
||||
;; probably the most interesting feature of this function.
|
||||
;; Heading: Move to position after entry content.
|
||||
;; NOTE: This is probably the most interesting feature of this function.
|
||||
(let ((heading-start (org-entry-beginning-position)))
|
||||
(goto-char (org-entry-end-position))
|
||||
(cond ((and (org-at-heading-p)
|
||||
|
@ -76,13 +69,8 @@ appropriate. In tables, insert a new row or end the table."
|
|||
(forward-line)
|
||||
(insert "\n")
|
||||
(forward-line -1))
|
||||
;; FIXME: looking-back is supposed to be called with
|
||||
;; more arguments.
|
||||
(while (not (looking-back (rx
|
||||
(repeat 3
|
||||
(seq (optional blank)
|
||||
"\n")))
|
||||
nil))
|
||||
;; FIXME: looking-back is supposed to be called with more arguments.
|
||||
(while (not (looking-back (rx (repeat 3 (seq (optional blank) "\n")))))
|
||||
(insert "\n"))
|
||||
(forward-line -1)))))
|
||||
|
||||
|
@ -120,14 +108,11 @@ appropriate. In tables, insert a new row or end the table."
|
|||
;; See `org-table-next-field'.
|
||||
(cl-loop with end = (line-end-position)
|
||||
for cell = (org-element-table-cell-parser)
|
||||
always (equal (org-element-property
|
||||
:contents-begin cell)
|
||||
(org-element-property
|
||||
:contents-end cell))
|
||||
always (equal (org-element-property :contents-begin cell)
|
||||
(org-element-property :contents-end cell))
|
||||
while (re-search-forward "|" end t)))
|
||||
;; Empty row: end the table.
|
||||
(delete-region (line-beginning-position)
|
||||
(line-end-position))
|
||||
(delete-region (line-beginning-position) (line-end-position))
|
||||
(org-return))
|
||||
(t
|
||||
;; Non-empty row: call `org-return'.
|
||||
|
@ -136,8 +121,6 @@ appropriate. In tables, insert a new row or end the table."
|
|||
;; All other cases: call `org-return'.
|
||||
(org-return)))))
|
||||
|
||||
;;; ORG-FIX-BLANK-LINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun unpackaged/org-fix-blank-lines (&optional prefix)
|
||||
"Ensure that blank lines exist between headings and
|
||||
between headings and their contents. With prefix, operate on
|
||||
|
|
Loading…
Reference in New Issue