Skip to content

Instantly share code, notes, and snippets.

@jackrusher
Created February 19, 2016 11:53
Show Gist options
  • Save jackrusher/2cf35221ce718c73298c to your computer and use it in GitHub Desktop.
Save jackrusher/2cf35221ce718c73298c to your computer and use it in GitHub Desktop.
Automatically updating SVG preview in emacs
;; 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