org: add (in|de)dent-or-(next|prev)-field functions
This commit is contained in:
parent
43121747a9
commit
40b7e4de5e
1 changed files with 41 additions and 19 deletions
|
@ -28,29 +28,53 @@
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/org-indent ()
|
(defun doom/org-indent ()
|
||||||
|
"Indent the current item (header or item). Otherwise, forward to
|
||||||
|
`self-insert-command'."
|
||||||
(interactive)
|
(interactive)
|
||||||
(cond
|
(cond ((org-at-item-p)
|
||||||
((and (org-on-heading-p)
|
(org-indent-item-tree))
|
||||||
(looking-back "^\\*+ +" (line-beginning-position)))
|
((and (org-on-heading-p)
|
||||||
(ignore-errors
|
(looking-back "^\\*+ +.*" (line-beginning-position)))
|
||||||
(org-demote)))
|
(ignore-errors (org-demote)))
|
||||||
(t (call-interactively 'self-insert-command))))
|
(t (call-interactively 'self-insert-command))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom/org-indent-or-next-field ()
|
||||||
|
"Depending on the context either indent the current item or go the next table field."
|
||||||
|
(interactive)
|
||||||
|
(call-interactively (if (org-at-table-p) 'org-table-next-field 'doom/org-indent)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/org-dedent ()
|
(defun doom/org-dedent ()
|
||||||
|
"Dedent the current item (header or item). Otherwise, forward to
|
||||||
|
`self-insert-command'."
|
||||||
(interactive)
|
(interactive)
|
||||||
(cond
|
(cond ((org-at-item-p)
|
||||||
((and (org-on-heading-p)
|
(let ((struct (if (org-region-active-p)
|
||||||
(looking-back "^\\*+ +" (line-beginning-position)))
|
(save-excursion (goto-char (region-beginning))
|
||||||
(ignore-errors
|
(org-list-struct))
|
||||||
(org-promote)))
|
(org-list-struct))))
|
||||||
(t (call-interactively 'self-insert-command))))
|
(org-list-indent-item-generic -1 nil struct)))
|
||||||
|
((and (org-on-heading-p)
|
||||||
|
(looking-back "^\\*+ +.*" (line-beginning-position)))
|
||||||
|
(ignore-errors
|
||||||
|
(org-promote)))
|
||||||
|
(t (call-interactively 'self-insert-command))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom/org-dedent-or-prev-field ()
|
||||||
|
"Depending on the context either dedent the current item or go the previous table field."
|
||||||
|
(interactive)
|
||||||
|
(call-interactively (if (org-at-table-p) 'org-table-previous-field 'doom/org-dedent)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/org-insert-item (direction)
|
(defun doom/org-insert-item (direction)
|
||||||
"Inserts a new heading or item, depending on the context. I use this instead of
|
"Inserts a new heading, table cell or item, depending on the context.
|
||||||
`org-insert-item' or `org-insert-heading' because they try to do too much and end up doing
|
DIRECTION can be 'above or 'below.
|
||||||
this otherwise simple task wrong (e.g. whitespace in the wrong places)."
|
|
||||||
|
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)."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((context (org-element-lineage
|
(let* ((context (org-element-lineage
|
||||||
(org-element-context)
|
(org-element-context)
|
||||||
|
@ -71,10 +95,8 @@ this otherwise simple task wrong (e.g. whitespace in the wrong places)."
|
||||||
(insert "[ ] ")))
|
(insert "[ ] ")))
|
||||||
((memq type '(table table-row))
|
((memq type '(table table-row))
|
||||||
(cl-case direction
|
(cl-case direction
|
||||||
('below
|
('below (org-table-insert-row t))
|
||||||
(org-table-insert-row))
|
('above (doom/org-table-prepend-row-or-shift-up))))
|
||||||
('above
|
|
||||||
(doom/org-table-prepend-row-or-shift-up))))
|
|
||||||
(t
|
(t
|
||||||
(let ((level (save-excursion
|
(let ((level (save-excursion
|
||||||
(org-back-to-heading)
|
(org-back-to-heading)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue