From 31da5dcf03e8676d64fa91d5cb872950ea0c2921 Mon Sep 17 00:00:00 2001 From: contrapunctus Date: Sun, 21 Nov 2021 00:44:18 +0530 Subject: [PATCH] [compile/org] automatically jump to Org LP from compilation-mode errors --- init.org | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/init.org b/init.org index c0f6362..0a1ab76 100644 --- a/init.org +++ b/init.org @@ -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 **