lang/org: improve org-edit-src-code & general org-mode popup integration

This commit is contained in:
Henrik Lissner 2017-05-13 00:12:23 +02:00
parent de3853cde5
commit 5beb74b14d
2 changed files with 18 additions and 23 deletions

View file

@ -445,41 +445,35 @@ you came from."
'(" *Agenda Commands*" :noselect t) '(" *Agenda Commands*" :noselect t)
'("^\\*Org Agenda" :regexp t :size 30) '("^\\*Org Agenda" :regexp t :size 30)
'("*Org Clock*" :noselect t) '("*Org Clock*" :noselect t)
'("^\\*Org Src" :regexp t :size 0.5 :noesc t) '("^\\*Org Src" :regexp t :size 0.35 :noesc t)
'("*Edit Formulas*" :size 10) '("*Edit Formulas*" :size 10)
'("^\\*Org-Babel" :regexp t :size 25 :noselect t) '("^\\*Org-Babel" :regexp t :size 25 :noselect t)
'("^CAPTURE.*\\.org$" :regexp t :size 20)) '("^CAPTURE.*\\.org$" :regexp t :size 20))
;; Org tries to do its own popup management, causing buffer/window config ;; Org has its own window management system with a scorched earth philosophy
;; armageddon when paired with shackle. To fix this, we must make a couple ;; I'm not fond of. i.e. it kills all windows and greedily monopolizes the
;; modifications: ;; frame. No thanks. We can do better with shackle's help.
;; Suppress `delete-other-windows' in org functions: ;; Save the emacsverse from armageddon by suppressing `delete-other-windows'
;; in org functions.
(defun doom*suppress-delete-other-windows (orig-fn &rest args) (defun doom*suppress-delete-other-windows (orig-fn &rest args)
(cl-flet (((symbol-function 'delete-other-windows) (cl-letf (((symbol-function 'delete-other-windows)
(symbol-function 'ignore))) (symbol-function 'ignore)))
(apply orig-fn args))) (apply orig-fn args)))
(advice-add #'org-add-log-note :around #'doom*suppress-delete-other-windows) (advice-add #'org-add-log-note :around #'doom*suppress-delete-other-windows)
(advice-add #'org-capture-place-template :around #'doom*suppress-delete-other-windows) (advice-add #'org-capture-place-template :around #'doom*suppress-delete-other-windows)
(advice-add #'org-export--dispatch-ui :around #'doom*suppress-delete-other-windows) (advice-add #'org-export--dispatch-ui :around #'doom*suppress-delete-other-windows)
;; Tell `org-src-edit' to open another window, which shackle can intercept. ;; `org-edit-src-code' simply clones and narrows the buffer to a src block,
(setq org-src-window-setup 'other-window) ;; so we are secretly manipulating the same buffer. Since truely killing it
;; would kill the original org buffer we've got to do things differently.
;; org-edit-src simply clones and narrows the buffer, so we are secretly (defun doom*org-src-switch-to-buffer (buffer context)
;; manipulating the same buffer. Since it never gets killed, we need to (if (eq org-src-window-setup 'switch-invisibly)
;; treat it specially and clean up after it manually. (set-buffer buffer)
(defun doom*org-src-switch-to-buffer (&rest args) (pop-to-buffer buffer)))
(let ((window (doom-popup-buffer (car args))))
(set-window-dedicated-p window nil)
(select-window window)))
(advice-add #'org-src-switch-to-buffer :override #'doom*org-src-switch-to-buffer) (advice-add #'org-src-switch-to-buffer :override #'doom*org-src-switch-to-buffer)
(defun doom*org-src-exit (&rest _) ;; Ensure todo, agenda, and other minor popups handed off to shackle.
(when doom-popup-mode (doom-popup-mode -1)))
(advice-add #'org-edit-src-exit :after #'doom*org-src-exit)
;; Ensure todo, agenda, and other popups are opened with shackle
(defun doom*org-pop-to-buffer (&rest args) (defun doom*org-pop-to-buffer (&rest args)
(let ((buf (car args))) (let ((buf (car args)))
(pop-to-buffer (pop-to-buffer
@ -494,7 +488,7 @@ you came from."
;; Hide modeline in org-agenda ;; Hide modeline in org-agenda
(add-hook 'org-agenda-finalize-hook #'doom-hide-modeline-mode) (add-hook 'org-agenda-finalize-hook #'doom-hide-modeline-mode)
;; Don't monopolize frame!
(advice-add #'org-agenda :around #'doom*suppress-delete-other-windows) (advice-add #'org-agenda :around #'doom*suppress-delete-other-windows)
(after! evil (after! evil

View file

@ -43,7 +43,8 @@
params))) params)))
;; I prefer C-c C-c for confirming over the default C-c ' ;; I prefer C-c C-c for confirming over the default C-c '
(map! :map org-src-mode-map "C-c C-c" 'org-edit-src-exit) (map! :map org-src-mode-map "C-c C-c" #'org-edit-src-exit)
;; I know the keybindings, no need for the header line ;; I know the keybindings, no need for the header line
(defun +org|src-mode-remove-header () (defun +org|src-mode-remove-header ()
(when header-line-format (setq header-line-format nil))) (when header-line-format (setq header-line-format nil)))