lang/org: realign/recalculate tables on exit evil replace mode

This commit is contained in:
Henrik Lissner 2018-05-30 01:45:35 +02:00
parent c63cd0a688
commit 49f16f681c
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 14 additions and 5 deletions

View file

@ -307,9 +307,16 @@ wrong places)."
(defun +org|realign-table-maybe () (defun +org|realign-table-maybe ()
"Auto-align table under cursor and re-calculate formulas." "Auto-align table under cursor and re-calculate formulas."
(when (and (org-at-table-p) org-table-may-need-update) (when (and (org-at-table-p) org-table-may-need-update)
(quiet! (save-excursion
(org-table-recalculate) (quiet!
(if org-table-may-need-update (org-table-align))))) (org-table-recalculate)
(if org-table-may-need-update (org-table-align))))))
;;;###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 ;;;###autoload
(defun +org|update-cookies () (defun +org|update-cookies ()

View file

@ -99,9 +99,11 @@ unfold to point on startup."
(sp-local-pair "=" nil :unless '(:add sp-point-before-word-p))))) (sp-local-pair "=" nil :unless '(:add sp-point-before-word-p)))))
(defun +org|enable-auto-reformat-tables () (defun +org|enable-auto-reformat-tables ()
"Realign tables exiting insert mode (`evil-mode')." "Realign tables & update formulas when exiting insert mode (`evil-mode')."
(when (featurep 'evil) (when (featurep 'evil)
(add-hook 'evil-insert-state-exit-hook #'+org|realign-table-maybe nil t))) (add-hook 'evil-insert-state-exit-hook #'+org|realign-table-maybe nil t)
(add-hook 'evil-replace-state-exit-hook #'+org|realign-table-maybe nil t)
(advice-add #'evil-replace :after #'+org*realign-table-maybe)))
(defun +org|enable-auto-update-cookies () (defun +org|enable-auto-update-cookies ()
"Update statistics cookies when saving or exiting insert mode (`evil-mode')." "Update statistics cookies when saving or exiting insert mode (`evil-mode')."