-
Notifications
You must be signed in to change notification settings - Fork 83
Editor integration
varkor edited this page Jul 31, 2023
·
1 revision
quiver does not have native editor support. However, for some editors there exist extensions that make working with quiver diagrams more convenient.
Note that the following extensions are third-party, and no guarantees are made regarding their behaviour. It is your responsibility to inspect their behaviour before invoking them.
The following extension selects the entirety of the LaTeX code associated to a quiver diagram under the cursor and opens a browser window with the corresponding quiver diagram URL, to facilitate convenient editing of existing diagrams.
This extension was contributed by https://github.com/nullst.
(defun replace-quiver-diagram ()
"Extracts the quiver URL from the diagram under cursor and runs it in browser. Selects the diagram."
(interactive)
(let ((start 0)
(end 0)
(url-start 0)
(url-end 0)
(url ""))
(save-excursion
(save-excursion
(re-search-backward "% https://q.uiver.app" nil)
(setq url-start (+ 2 (point)))
(beginning-of-line)
(setq start (point))
(save-excursion
(re-search-forward "\\\\end{tikzcd}" nil)
(setq end (point)))
(save-excursion
(goto-char url-start)
(re-search-forward "\n" nil)
(setq url-end (- (point) 1))
(skip-chars-forward " ")
;; If the next two symbols after new line, up to whitespace,
;; are "\[", modify the `end` value to be after \].
(when (string= "[" (string (char-after (+ 1 (point)))))
(setq end (+ 2 end))))
(setq url (buffer-substring-no-properties url-start url-end))
(start-process "" nil
;; Edit this line to change the browser.
"flatpak" "run" "org.chromium.Chromium" url)))
(goto-char start)
(push-mark end t t)))
(add-hook 'TeX-mode-hook (lambda ()
(interactive)
(define-key TeX-mode-map (kbd "C-x q") 'replace-quiver-diagram)))