lang/org: minor refactor/reformatting

Also reduce internal use of map! (toward eventual switch to general)
This commit is contained in:
Henrik Lissner 2018-06-03 12:22:39 +02:00
parent ae86498a41
commit f9be8887fb
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 76 additions and 76 deletions

View file

@ -313,12 +313,6 @@ wrong places)."
(if org-table-may-need-update (org-table-align)))
(goto-char pt))))
;;;###autoload
(defun +org*realign-table-maybe (&rest _)
"Auto-align table under cursor and re-calculate formulas."
(when (eq major-mode 'org-mode)
(+org|realign-table-maybe)))
;;;###autoload
(defun +org|update-cookies ()
"Update counts in headlines (aka \"cookies\")."
@ -329,9 +323,8 @@ wrong places)."
(defun +org|yas-expand-maybe ()
"Tries to expand a yasnippet snippet, if one is available. Made for
`org-tab-first-hook'."
(when (and (if (bound-and-true-p evil-mode)
(eq evil-state 'insert)
t)
(when (and (or (not (bound-and-true-p evil-mode))
(eq evil-state 'insert))
(bound-and-true-p yas-minor-mode)
(yas--templates-for-key-at-point))
(call-interactively #'yas-expand)
@ -354,6 +347,13 @@ with `org-cycle')."
;;;###autoload
(defalias #'+org/toggle-fold #'+org|toggle-only-current-fold)
;;;###autoload
(defun +org|remove-occur-highlights ()
"Remove org occur highlights on ESC in normal mode."
(when org-occur-highlights
(org-remove-occur-highlights)
t))
;;
;; Advice
@ -365,3 +365,9 @@ with `org-cycle')."
(when (org-in-src-block-p t)
(org-babel-do-in-edit-buffer
(call-interactively #'indent-for-tab-command))))
;;;###autoload
(defun +org*realign-table-maybe (&rest _)
"Auto-align table under cursor and re-calculate formulas."
(when (eq major-mode 'org-mode)
(+org|realign-table-maybe)))

View file

@ -245,84 +245,80 @@ unfold to point on startup."
(defun +org|setup-keybinds ()
"Sets up org-mode and evil keybindings. Tries to fix the idiosyncrasies
between the two."
(defun +org|remove-occur-highlights ()
"Remove org occur highlights on ESC in normal mode."
(when org-occur-highlights
(org-remove-occur-highlights)
t))
(add-hook 'doom-escape-hook #'+org|remove-occur-highlights)
;; C-a & C-e act like `doom/backward-to-bol-or-indent' and
;; `doom/forward-to-last-non-comment-or-eol', but with more org awareness.
(setq org-special-ctrl-a/e t)
;; Try indenting normally or expanding snippets on TAB
(add-hook! 'org-tab-first-hook #'(+org|indent-maybe +org|yas-expand-maybe))
;; Tell `doom/delete-backward-char' to respect org tables
(add-hook 'doom-delete-backward-functions #'+org|delete-backward-char)
(map! :map org-mode-map
"C-c C-S-l" #'+org/remove-link
"C-c C-i" #'org-toggle-inline-images
;; Custom keybinds
(define-key! org-mode-map
(kbd "C-c C-S-l") #'+org/remove-link
(kbd "C-c C-i") #'org-toggle-inline-images
[remap doom/backward-to-bol-or-indent] #'org-beginning-of-line
[remap doom/forward-to-last-non-comment-or-eol] #'org-end-of-line))
(defun +org|setup-evil ()
(require 'evil-org)
;; By default, TAB cycles the visibility of all children under the current
;; tree between three states. I want to toggle the tree between two states,
;; without affecting its children.
(add-hook 'org-tab-first-hook #'+org|toggle-only-current-fold t)
;; Fix newline-and-indent behavior in src blocks
(advice-add #'org-return-indent :after #'+org*return-indent-in-src-blocks)
(map! :map outline-mode-map
:n "^" nil
:n [backtab] nil
:n "C-j" nil
:n "C-k" nil
:n "]" nil
:n "[" nil
:map evil-org-mode-map
:i [backtab] #'+org/dedent
;; Undo `evil-collection-outline'
(evil-define-key* 'normal outline-mode-map
"^" nil
[backtab] nil
"\C-j" nil "\C-k" nil
"]" nil "[" nil)
(evil-define-key* 'insert evil-org-mode-map
;; dedent with shift-tab in insert mode
[backtab] #'+org/dedent
;; navigate table cells (from insert-mode)
:i "C-l" #'+org/table-next-field
:i "C-h" #'+org/table-previous-field
:i "C-k" #'+org/table-previous-row
:i "C-j" #'+org/table-next-row
;; expand tables (or shiftmeta move)
:ni "C-S-l" #'+org/table-append-field-or-shift-right
:ni "C-S-h" #'+org/table-prepend-field-or-shift-left
:ni "C-S-k" #'org-metaup
:ni "C-S-j" #'org-metadown
"\C-l" #'+org/table-next-field
"\C-h" #'+org/table-previous-field
"\C-k" #'+org/table-previous-row
"\C-j" #'+org/table-next-row)
;; expand tables or move fields
(evil-define-key* '(insert normal) evil-org-mode-map
(kbd "C-S-l") #'+org/table-append-field-or-shift-right
(kbd "C-S-h") #'+org/table-prepend-field-or-shift-left
(kbd "C-S-k") #'org-metaup
(kbd "C-S-j") #'org-metadown)
;; more intuitive RET keybinds
:i "RET" #'org-return-indent
:n "RET" #'+org/dwim-at-point
:ni [M-return] (λ! (+org/insert-item 'below))
:ni [S-M-return] (λ! (+org/insert-item 'above))
;; more org-ish vim motion keys
:m "]]" (λ! (org-forward-heading-same-level nil) (org-beginning-of-line))
:m "[[" (λ! (org-backward-heading-same-level nil) (org-beginning-of-line))
:m "]h" #'org-next-visible-heading
:m "[h" #'org-previous-visible-heading
:m "]l" #'org-next-link
:m "[l" #'org-previous-link
:m "]s" #'org-babel-next-src-block
:m "[s" #'org-babel-previous-src-block
:m "^" #'evil-org-beginning-of-line
:m "0" (λ! (let ((visual-line-mode)) (org-beginning-of-line)))
:n "gQ" #'org-fill-paragraph
;; sensible code-folding vim keybinds
:n "za" #'+org/toggle-fold
:n "zA" #'org-shifttab
:n "zc" #'outline-hide-subtree
:n "zC" (λ! (outline-hide-sublevels 1))
:n "zd" (lambda (&optional arg) (interactive "p") (outline-hide-sublevels (or arg 3)))
:n "zm" (λ! (outline-hide-sublevels 1))
:n "zo" #'outline-show-subtree
:n "zO" #'outline-show-all
:n "zr" #'outline-show-all
(evil-define-key* 'insert evil-org-mode-map
[return] #'org-return-indent)
(evil-define-key* '(insert normal) evil-org-mode-map
[M-return] (λ! (+org/insert-item 'below))
[S-M-return] (λ! (+org/insert-item 'above)))
;; more vim-esque org motion keys
(evil-define-key* 'motion evil-org-mode-map
"]]" (λ! (org-forward-heading-same-level nil) (org-beginning-of-line))
"[[" (λ! (org-backward-heading-same-level nil) (org-beginning-of-line))
"]h" #'org-next-visible-heading
"[h" #'org-previous-visible-heading
"]l" #'org-next-link
"[l" #'org-previous-link
"]s" #'org-babel-next-src-block
"[s" #'org-babel-previous-src-block
"^" #'evil-org-beginning-of-line
"0" (λ! (let (visual-line-mode) (org-beginning-of-line))))
;; sensible vim-esque folding keybinds
(evil-define-key* 'normal evil-org-mode-map
"za" #'+org/toggle-fold
"zA" #'org-shifttab
"zc" #'outline-hide-subtree
"zC" (λ! (outline-hide-sublevels 1))
"zd" (lambda (&optional arg) (interactive "p") (outline-hide-sublevels (or arg 3)))
"zm" (λ! (outline-hide-sublevels 1))
"zo" #'outline-show-subtree
"zO" #'outline-show-all
"zr" #'outline-show-all)
;; <localleader>
(map! :map evil-org-mode-map
:localleader
:n "d" #'org-deadline
:n "t" #'org-todo
@ -337,7 +333,6 @@ between the two."
"Getting org to behave."
;; Don't open separate windows
(map-put org-link-frame-setup 'file #'find-file)
;; Let OS decide what to do with files when opened
(setq org-file-apps
`(("pdf" . default)
@ -346,7 +341,6 @@ between the two."
(directory . emacs)
(t . ,(cond (IS-MAC "open -R \"%s\"")
(IS-LINUX "xdg-open \"%s\"")))))
;; Don't clobber recentf or current workspace with agenda files
(defun +org|exclude-agenda-buffers-from-workspace ()
(let (persp-autokill-buffer-on-remove)