Redo lib/defuns-org.el and org-mode keybindings
This commit is contained in:
parent
7c4c9ea5da
commit
ab8fad93e7
2 changed files with 170 additions and 172 deletions
|
@ -1,81 +1,69 @@
|
|||
;;; defuns-org.el
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-cycle-hide-drawers (state)
|
||||
"Re-hide all drawers after a visibility state change. Hides properties permanently."
|
||||
(when (and (derived-mode-p 'org-mode)
|
||||
(not (memq state '(overview folded contents))))
|
||||
(save-excursion
|
||||
(let* ((globalp (memq state '(contents all)))
|
||||
(beg (if globalp (point-min) (point)))
|
||||
(end (if globalp (point-max)
|
||||
(if (eq state 'children)
|
||||
(save-excursion (outline-next-heading) (point))
|
||||
(org-end-of-subtree t)))))
|
||||
(goto-char beg)
|
||||
(while (re-search-forward org-drawer-regexp end t)
|
||||
(save-excursion
|
||||
(beginning-of-line 1)
|
||||
(backward-char 1)
|
||||
(let ((b (point)))
|
||||
(if (re-search-forward
|
||||
"^[ \t]*:END:"
|
||||
(save-excursion (outline-next-heading) (point)) t)
|
||||
(outline-flag-region b (point-at-eol) t)
|
||||
(user-error ":END: line missing at position %s" b)))))))))
|
||||
|
||||
(defun narf--org-in-list-p ()
|
||||
(and (save-excursion (search-backward-regexp "^ *\\([0-9]+[\.)]\\|[-*+]\\) "
|
||||
(line-beginning-position) t))
|
||||
(org-in-item-p)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-insert-item-after ()
|
||||
(defun narf/org-insert-item (direction)
|
||||
"Inserts a new heading or item, depending on the context."
|
||||
(interactive)
|
||||
(let* ((context (org-element-lineage
|
||||
(org-element-context)
|
||||
'(table table-row headline inlinetask
|
||||
item plain-list)
|
||||
t))
|
||||
(type (org-element-type context)))
|
||||
(cond ((eq type 'item)
|
||||
(cl-case direction
|
||||
('below
|
||||
(org-end-of-line)
|
||||
(cond ((org-at-item-checkbox-p)
|
||||
(org-insert-heading)
|
||||
(insert "[ ] "))
|
||||
((narf--org-in-list-p)
|
||||
(org-insert-heading))
|
||||
((org-on-heading-p)
|
||||
(org-insert-heading-respect-content))
|
||||
(t
|
||||
(org-insert-heading-after-current)
|
||||
(delete-char 1)))
|
||||
(evil-insert-state))
|
||||
|
||||
;; TODO Check if this and -forward can be combined
|
||||
;;;###autoload
|
||||
(defun narf/org-insert-item-before ()
|
||||
"Inserts a new heading or item, depending on the context."
|
||||
(interactive)
|
||||
('above
|
||||
(evil-first-non-blank)
|
||||
(cond ((org-at-item-checkbox-p)
|
||||
(org-insert-heading)
|
||||
(insert "[ ] "))
|
||||
((narf--org-in-list-p)
|
||||
(org-insert-heading))
|
||||
(t (org-insert-heading)))
|
||||
(evil-insert-state))
|
||||
(org-insert-heading)))
|
||||
(when (org-element-property :checkbox context)
|
||||
(insert "[ ] ")))
|
||||
((memq type '(table table-row))
|
||||
(cl-case direction
|
||||
('below
|
||||
(org-table-insert-row))
|
||||
('above
|
||||
(narf/org-table-prepend-row-or-shift-up))))
|
||||
(t
|
||||
(org-back-to-heading)
|
||||
(let ((first-p (org-first-sibling-p))
|
||||
(orig-char (point)))
|
||||
(cl-case direction
|
||||
('below
|
||||
(org-insert-heading-after-current)
|
||||
(unless first-p
|
||||
(save-excursion
|
||||
(goto-char orig-char)
|
||||
(evil-insert-newline-above)))
|
||||
(save-excursion
|
||||
(evil-insert-newline-below)))
|
||||
('above
|
||||
(save-excursion
|
||||
(evil-insert-newline-below))
|
||||
(unless first-p
|
||||
(save-excursion
|
||||
(evil-insert-newline-above))))))))
|
||||
(evil-append-line 1)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-toggle-checkbox ()
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(let ((context (org-element-lineage (org-element-context) '(item) t)))
|
||||
(when context
|
||||
(org-end-of-line)
|
||||
(cond ((org-in-item-p)
|
||||
(if (search-backward-regexp "\\[[ +-]\\]" (line-beginning-position) t)
|
||||
(delete-char 4)
|
||||
(org-beginning-of-line)))
|
||||
(t (org-insert-heading)))
|
||||
(insert "[ ] ")))
|
||||
(org-beginning-of-line)
|
||||
(if (org-element-property :checkbox context)
|
||||
(when (search-backward-regexp "\\[[ +-]\\]" (line-beginning-position) t)
|
||||
(delete-char 4))
|
||||
(insert "[ ] ")))))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-execute-at-point ()
|
||||
(defun narf/org-dwim-at-point ()
|
||||
(interactive)
|
||||
(let* ((context (org-element-lineage
|
||||
(let* ((scroll-pt (window-start))
|
||||
(context (org-element-lineage
|
||||
(org-element-context)
|
||||
'(table table-row clock comment comment-block footnote-definition
|
||||
footnote-reference headline inlinetask keyword link
|
||||
|
@ -95,9 +83,15 @@
|
|||
|
||||
((and (memq type '(headline))
|
||||
(org-element-property :todo-type context))
|
||||
(if (eq (org-element-property :todo-type context) 'done)
|
||||
(org-todo 'todo)
|
||||
(org-todo 'done)))
|
||||
(org-todo
|
||||
(if (eq (org-element-property :todo-type context) 'done) 'todo 'done)))
|
||||
|
||||
((memq type '(headline))
|
||||
(org-remove-latex-fragment-image-overlays
|
||||
(save-excursion (org-beginning-of-line) (point))
|
||||
(save-excursion (org-end-of-subtree) (point)))
|
||||
(org-map-entries 'org-toggle-latex-fragment t 'tree)
|
||||
(narf/org-refresh-inline-images))
|
||||
|
||||
((memq type '(babel-call))
|
||||
(org-babel-lob-execute-maybe))
|
||||
|
@ -111,14 +105,18 @@
|
|||
((memq type '(link))
|
||||
(org-open-at-point))
|
||||
|
||||
(t (org-toggle-inline-images)))))
|
||||
(t (narf/org-refresh-inline-images)))
|
||||
(set-window-start nil scroll-pt)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-toggle-inline-images-at-point ()
|
||||
(defun narf/org-refresh-inline-images ()
|
||||
(interactive)
|
||||
(if (> (length org-inline-image-overlays) 0)
|
||||
(org-remove-inline-images)
|
||||
(org-display-inline-images nil t (line-beginning-position) (line-end-position))))
|
||||
(org-display-inline-images
|
||||
nil t
|
||||
(save-excursion (org-back-to-heading) (point))
|
||||
(save-excursion (org-end-of-subtree) (point)))))
|
||||
|
||||
;; Formatting shortcuts
|
||||
;;;###autoload
|
||||
|
@ -291,26 +289,26 @@ COUNT-FOOTNOTES? is non-nil."
|
|||
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-table-append-row-or-shift-right ()
|
||||
(defun narf/org-table-append-field-or-shift-right ()
|
||||
(interactive)
|
||||
(org-shiftmetaright)
|
||||
(when (org-at-table-p) (org-metaright)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-table-prepend-row-or-shift-left ()
|
||||
(defun narf/org-table-prepend-field-or-shift-left ()
|
||||
(interactive)
|
||||
(if (org-at-table-p)
|
||||
(org-shiftmetaright)
|
||||
(org-shiftmetaleft)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-table-append-field-or-shift-down ()
|
||||
(defun narf/org-table-append-row-or-shift-down ()
|
||||
(interactive)
|
||||
(org-shiftmetadown)
|
||||
(when (org-at-table-p) (org-metadown)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-table-prepend-field-or-shift-up ()
|
||||
(defun narf/org-table-prepend-row-or-shift-up ()
|
||||
(interactive)
|
||||
(if (org-at-table-p)
|
||||
(org-shiftmetadown)
|
||||
|
|
|
@ -397,13 +397,11 @@
|
|||
(define-text-object! "=" "=" "=")
|
||||
(define-text-object! "~" "~" "~")
|
||||
|
||||
(define-key org-mode-map (kbd "RET") nil)
|
||||
(define-key org-mode-map (kbd "C-j") nil)
|
||||
(define-key org-mode-map (kbd "C-k") nil)
|
||||
;; Keybinds
|
||||
(bind!
|
||||
(:map org-mode-map
|
||||
"RET" nil
|
||||
"C-j" nil
|
||||
"C-k" nil
|
||||
|
||||
(bind! (:map org-mode-map
|
||||
:i [remap narf/inflate-space-maybe] 'org-self-insert-command
|
||||
:i "RET" 'org-return-indent)
|
||||
|
||||
|
@ -413,10 +411,10 @@
|
|||
:ni "A-k" 'org-metaup
|
||||
:ni "A-j" 'org-metadown
|
||||
;; Expand tables (or shiftmeta move)
|
||||
:ni "A-L" 'narf/org-table-append-row-or-shift-right
|
||||
:ni "A-H" 'narf/org-table-prepend-row-or-shift-left
|
||||
:ni "A-K" 'narf/org-table-prepend-field-or-shift-up
|
||||
:ni "A-J" 'narf/org-table-append-field-or-shift-down
|
||||
:ni "A-L" 'narf/org-table-append-field-or-shift-right
|
||||
:ni "A-H" 'narf/org-table-prepend-field-or-shift-left
|
||||
:ni "A-K" 'narf/org-table-prepend-row-or-shift-up
|
||||
:ni "A-J" 'narf/org-table-append-row-or-shift-down
|
||||
|
||||
:i "C-L" 'narf/org-table-next-field
|
||||
:i "C-H" 'narf/org-table-previous-field
|
||||
|
@ -434,8 +432,8 @@
|
|||
:n "M-a" 'org-mark-element
|
||||
:v "M-a" 'mark-whole-buffer
|
||||
|
||||
:i "<M-return>" 'narf/org-insert-item-after
|
||||
:i "<S-M-return>" 'narf/org-insert-item-before
|
||||
:i "<M-return>" (λ (narf/org-insert-item 'below))
|
||||
:i "<S-M-return>" (λ (narf/org-insert-item 'above))
|
||||
|
||||
:i "M-b" (λ (narf/org-surround "*")) ; bold
|
||||
:i "M-u" (λ (narf/org-surround "_")) ; underline
|
||||
|
@ -449,7 +447,8 @@
|
|||
|
||||
:n ",;" 'helm-org-in-buffer-headings
|
||||
:nv ",l" 'org-insert-link
|
||||
:nv ",L" 'narf/org-replace-link-by-link-description
|
||||
:n ",L" 'org-store-link
|
||||
;; TODO narf/org-replace-link-by-link-description
|
||||
:n ",=" 'org-align-all-tags
|
||||
:n ",f" 'org-sparse-tree
|
||||
:n ",?" 'org-tags-view
|
||||
|
@ -463,7 +462,7 @@
|
|||
:n ",r" 'org-refile
|
||||
:n ",s" 'org-schedule
|
||||
:n ", SPC" 'narf/org-toggle-checkbox
|
||||
:n ",<return>" 'org-archive-subtree
|
||||
:n ", RET" 'org-archive-subtree
|
||||
|
||||
:n "za" 'org-cycle
|
||||
:n "zA" 'org-shifttab
|
||||
|
@ -479,7 +478,7 @@
|
|||
:m "]l" 'org-next-link
|
||||
:m "[l" 'org-previous-link
|
||||
|
||||
:n "RET" 'narf/org-execute-at-point
|
||||
:n "RET" 'narf/org-dwim-at-point
|
||||
|
||||
:m "gh" 'outline-up-heading
|
||||
:m "gj" (λ (hide-subtree) (call-interactively 'org-forward-heading-same-level) (show-children))
|
||||
|
@ -512,6 +511,7 @@
|
|||
:e "C-n" 'org-agenda-next-item
|
||||
:e "C-p" 'org-agenda-previous-item)))
|
||||
|
||||
|
||||
(progn ;; Org hacks
|
||||
;; Redefining this function so it doesn't open that "links" help buffer
|
||||
(defun org-insert-link (&optional complete-file link-location default-description)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue