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
|
;;; defuns-org.el
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/org-cycle-hide-drawers (state)
|
(defun narf/org-insert-item (direction)
|
||||||
"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 ()
|
|
||||||
"Inserts a new heading or item, depending on the context."
|
"Inserts a new heading or item, depending on the context."
|
||||||
(interactive)
|
(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)
|
(org-end-of-line)
|
||||||
(cond ((org-at-item-checkbox-p)
|
|
||||||
(org-insert-heading)
|
|
||||||
(insert "[ ] "))
|
|
||||||
((narf--org-in-list-p)
|
|
||||||
(org-insert-heading))
|
(org-insert-heading))
|
||||||
((org-on-heading-p)
|
('above
|
||||||
(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)
|
|
||||||
(evil-first-non-blank)
|
(evil-first-non-blank)
|
||||||
(cond ((org-at-item-checkbox-p)
|
(org-insert-heading)))
|
||||||
(org-insert-heading)
|
(when (org-element-property :checkbox context)
|
||||||
(insert "[ ] "))
|
(insert "[ ] ")))
|
||||||
((narf--org-in-list-p)
|
((memq type '(table table-row))
|
||||||
(org-insert-heading))
|
(cl-case direction
|
||||||
(t (org-insert-heading)))
|
('below
|
||||||
(evil-insert-state))
|
(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
|
;;;###autoload
|
||||||
(defun narf/org-toggle-checkbox ()
|
(defun narf/org-toggle-checkbox ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(save-excursion
|
(let ((context (org-element-lineage (org-element-context) '(item) t)))
|
||||||
|
(when context
|
||||||
(org-end-of-line)
|
(org-end-of-line)
|
||||||
(cond ((org-in-item-p)
|
(org-beginning-of-line)
|
||||||
(if (search-backward-regexp "\\[[ +-]\\]" (line-beginning-position) t)
|
(if (org-element-property :checkbox context)
|
||||||
(delete-char 4)
|
(when (search-backward-regexp "\\[[ +-]\\]" (line-beginning-position) t)
|
||||||
(org-beginning-of-line)))
|
(delete-char 4))
|
||||||
(t (org-insert-heading)))
|
(insert "[ ] ")))))
|
||||||
(insert "[ ] ")))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/org-execute-at-point ()
|
(defun narf/org-dwim-at-point ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((context (org-element-lineage
|
(let* ((scroll-pt (window-start))
|
||||||
|
(context (org-element-lineage
|
||||||
(org-element-context)
|
(org-element-context)
|
||||||
'(table table-row clock comment comment-block footnote-definition
|
'(table table-row clock comment comment-block footnote-definition
|
||||||
footnote-reference headline inlinetask keyword link
|
footnote-reference headline inlinetask keyword link
|
||||||
|
@ -95,9 +83,15 @@
|
||||||
|
|
||||||
((and (memq type '(headline))
|
((and (memq type '(headline))
|
||||||
(org-element-property :todo-type context))
|
(org-element-property :todo-type context))
|
||||||
(if (eq (org-element-property :todo-type context) 'done)
|
(org-todo
|
||||||
(org-todo 'todo)
|
(if (eq (org-element-property :todo-type context) 'done) 'todo 'done)))
|
||||||
(org-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))
|
((memq type '(babel-call))
|
||||||
(org-babel-lob-execute-maybe))
|
(org-babel-lob-execute-maybe))
|
||||||
|
@ -111,14 +105,18 @@
|
||||||
((memq type '(link))
|
((memq type '(link))
|
||||||
(org-open-at-point))
|
(org-open-at-point))
|
||||||
|
|
||||||
(t (org-toggle-inline-images)))))
|
(t (narf/org-refresh-inline-images)))
|
||||||
|
(set-window-start nil scroll-pt)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/org-toggle-inline-images-at-point ()
|
(defun narf/org-refresh-inline-images ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(if (> (length org-inline-image-overlays) 0)
|
(if (> (length org-inline-image-overlays) 0)
|
||||||
(org-remove-inline-images)
|
(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
|
;; Formatting shortcuts
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -291,26 +289,26 @@ COUNT-FOOTNOTES? is non-nil."
|
||||||
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/org-table-append-row-or-shift-right ()
|
(defun narf/org-table-append-field-or-shift-right ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(org-shiftmetaright)
|
(org-shiftmetaright)
|
||||||
(when (org-at-table-p) (org-metaright)))
|
(when (org-at-table-p) (org-metaright)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/org-table-prepend-row-or-shift-left ()
|
(defun narf/org-table-prepend-field-or-shift-left ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(if (org-at-table-p)
|
(if (org-at-table-p)
|
||||||
(org-shiftmetaright)
|
(org-shiftmetaright)
|
||||||
(org-shiftmetaleft)))
|
(org-shiftmetaleft)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/org-table-append-field-or-shift-down ()
|
(defun narf/org-table-append-row-or-shift-down ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(org-shiftmetadown)
|
(org-shiftmetadown)
|
||||||
(when (org-at-table-p) (org-metadown)))
|
(when (org-at-table-p) (org-metadown)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/org-table-prepend-field-or-shift-up ()
|
(defun narf/org-table-prepend-row-or-shift-up ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(if (org-at-table-p)
|
(if (org-at-table-p)
|
||||||
(org-shiftmetadown)
|
(org-shiftmetadown)
|
||||||
|
|
|
@ -397,13 +397,11 @@
|
||||||
(define-text-object! "=" "=" "=")
|
(define-text-object! "=" "=" "=")
|
||||||
(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
|
;; Keybinds
|
||||||
(bind!
|
(bind! (:map org-mode-map
|
||||||
(:map org-mode-map
|
|
||||||
"RET" nil
|
|
||||||
"C-j" nil
|
|
||||||
"C-k" nil
|
|
||||||
|
|
||||||
:i [remap narf/inflate-space-maybe] 'org-self-insert-command
|
:i [remap narf/inflate-space-maybe] 'org-self-insert-command
|
||||||
:i "RET" 'org-return-indent)
|
:i "RET" 'org-return-indent)
|
||||||
|
|
||||||
|
@ -413,10 +411,10 @@
|
||||||
:ni "A-k" 'org-metaup
|
:ni "A-k" 'org-metaup
|
||||||
:ni "A-j" 'org-metadown
|
:ni "A-j" 'org-metadown
|
||||||
;; Expand tables (or shiftmeta move)
|
;; Expand tables (or shiftmeta move)
|
||||||
:ni "A-L" 'narf/org-table-append-row-or-shift-right
|
:ni "A-L" 'narf/org-table-append-field-or-shift-right
|
||||||
:ni "A-H" 'narf/org-table-prepend-row-or-shift-left
|
:ni "A-H" 'narf/org-table-prepend-field-or-shift-left
|
||||||
:ni "A-K" 'narf/org-table-prepend-field-or-shift-up
|
:ni "A-K" 'narf/org-table-prepend-row-or-shift-up
|
||||||
:ni "A-J" 'narf/org-table-append-field-or-shift-down
|
:ni "A-J" 'narf/org-table-append-row-or-shift-down
|
||||||
|
|
||||||
:i "C-L" 'narf/org-table-next-field
|
:i "C-L" 'narf/org-table-next-field
|
||||||
:i "C-H" 'narf/org-table-previous-field
|
:i "C-H" 'narf/org-table-previous-field
|
||||||
|
@ -434,8 +432,8 @@
|
||||||
:n "M-a" 'org-mark-element
|
:n "M-a" 'org-mark-element
|
||||||
:v "M-a" 'mark-whole-buffer
|
:v "M-a" 'mark-whole-buffer
|
||||||
|
|
||||||
:i "<M-return>" 'narf/org-insert-item-after
|
:i "<M-return>" (λ (narf/org-insert-item 'below))
|
||||||
:i "<S-M-return>" 'narf/org-insert-item-before
|
:i "<S-M-return>" (λ (narf/org-insert-item 'above))
|
||||||
|
|
||||||
:i "M-b" (λ (narf/org-surround "*")) ; bold
|
:i "M-b" (λ (narf/org-surround "*")) ; bold
|
||||||
:i "M-u" (λ (narf/org-surround "_")) ; underline
|
:i "M-u" (λ (narf/org-surround "_")) ; underline
|
||||||
|
@ -449,7 +447,8 @@
|
||||||
|
|
||||||
:n ",;" 'helm-org-in-buffer-headings
|
:n ",;" 'helm-org-in-buffer-headings
|
||||||
:nv ",l" 'org-insert-link
|
: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 ",=" 'org-align-all-tags
|
||||||
:n ",f" 'org-sparse-tree
|
:n ",f" 'org-sparse-tree
|
||||||
:n ",?" 'org-tags-view
|
:n ",?" 'org-tags-view
|
||||||
|
@ -462,8 +461,8 @@
|
||||||
:n ",d" 'org-time-stamp
|
:n ",d" 'org-time-stamp
|
||||||
:n ",r" 'org-refile
|
:n ",r" 'org-refile
|
||||||
:n ",s" 'org-schedule
|
:n ",s" 'org-schedule
|
||||||
:n ",SPC" 'narf/org-toggle-checkbox
|
:n ", SPC" 'narf/org-toggle-checkbox
|
||||||
:n ",<return>" 'org-archive-subtree
|
:n ", RET" 'org-archive-subtree
|
||||||
|
|
||||||
:n "za" 'org-cycle
|
:n "za" 'org-cycle
|
||||||
:n "zA" 'org-shifttab
|
:n "zA" 'org-shifttab
|
||||||
|
@ -479,7 +478,7 @@
|
||||||
:m "]l" 'org-next-link
|
:m "]l" 'org-next-link
|
||||||
:m "[l" 'org-previous-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 "gh" 'outline-up-heading
|
||||||
:m "gj" (λ (hide-subtree) (call-interactively 'org-forward-heading-same-level) (show-children))
|
: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-n" 'org-agenda-next-item
|
||||||
:e "C-p" 'org-agenda-previous-item)))
|
:e "C-p" 'org-agenda-previous-item)))
|
||||||
|
|
||||||
|
|
||||||
(progn ;; Org hacks
|
(progn ;; Org hacks
|
||||||
;; Redefining this function so it doesn't open that "links" help buffer
|
;; Redefining this function so it doesn't open that "links" help buffer
|
||||||
(defun org-insert-link (&optional complete-file link-location default-description)
|
(defun org-insert-link (&optional complete-file link-location default-description)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue