-
-
Save ludamillion/7f04ef2a153513f9bf5023fad0deaced to your computer and use it in GitHub Desktop.
Automatically updating SVG preview in emacs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; I wrote up a quick + dirty function to get me a preview of the SVG I'm editing: | |
(defun refresh-svg-preview () | |
(interactive) | |
(let ((oldbuf (current-buffer))) | |
(with-current-buffer (get-buffer-create "*svg-preview*") | |
(fundamental-mode) | |
(erase-buffer) | |
(insert-buffer-substring oldbuf) | |
(image-mode)))) | |
;; plus I've a keybinding to start/stop automatically updating the preview on save: | |
(global-set-key '[(ctrl c) (ctrl %)] | |
(lambda () | |
(interactive) | |
(if (member 'refresh-svg-preview after-save-hook) | |
(progn | |
(remove-hook 'after-save-hook 'refresh-svg-preview t) | |
(message "No longer previewing on save.")) | |
(progn | |
(add-hook 'after-save-hook 'refresh-svg-preview nil t) | |
(message "Previewing this SVG on save."))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment