[compile/org] automatically jump to Org LP from compilation-mode errors

This commit is contained in:
contrapunctus 2021-11-21 00:44:18 +05:30
parent 073d7ce234
commit 31da5dcf03
1 changed files with 22 additions and 0 deletions

View File

@ -3813,6 +3813,28 @@ Potentially useful - https://www.draketo.de/software/emacs-javascript.html
;; (delete-other-windows)))
(setq compilation-always-kill t))
;; The first attempt - this works, but results in the window configuration changing each time you jump to an error, and leaves the buffer visiting the tangled source lying around...
;; (advice-add 'compile-goto-error :after (lambda (&rest args) (org-babel-tangle-jump-to-org)))
(defun my-org-lp-goto-error (oldfn &rest args)
"Make `compile-goto-error' lead to an Org literate program."
(let (buffer position column)
(save-window-excursion
(funcall oldfn)
(setq column (- (point) (point-at-bol)))
(org-babel-tangle-jump-to-org)
(setq buffer (current-buffer)
position (point)))
(let ((org-window (get-buffer-window buffer)))
;; if the Org buffer is visible, switch to its window
(if (window-live-p org-window)
(select-window org-window)
(switch-to-buffer buffer)))
(goto-char (+ position column))))
(advice-add 'compile-goto-error :around #'my-org-lp-goto-error)
;; (advice-remove 'compile-goto-error #'my-org-lp-goto-error)
#+END_SRC
**