[compile/org] handle being called via literate-elisp-byte-compile-file

This commit is contained in:
contrapunctus 2021-11-21 15:22:09 +05:30
parent 31da5dcf03
commit 6623a59e04
1 changed files with 17 additions and 11 deletions

View File

@ -3818,19 +3818,25 @@ Potentially useful - https://www.draketo.de/software/emacs-javascript.html
(defun my-org-lp-goto-error (oldfn &rest args)
"Make `compile-goto-error' lead to an Org literate program."
(let (buffer position column)
(let (buffer position column tangled-file-p)
(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))))
;; `compile-goto-error' might be called from the output of
;; `literate-elisp-byte-compile-file', which means
;; `org-babel-tangle-jump-to-org' would error
(when (ignore-errors (org-babel-tangle-jump-to-org))
(setq buffer (current-buffer)
position (point)
tangled-file-p t)))
;; back to where we started - the `compilation-mode' buffer
(if tangled-file-p
(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))
(funcall oldfn))))
(advice-add 'compile-goto-error :around #'my-org-lp-goto-error)
;; (advice-remove 'compile-goto-error #'my-org-lp-goto-error)