Klimi's new dotfiles with stow.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

66 rader
2.2 KiB

4 år sedan
  1. ;;; haskell-svg.el --- SVG Rendering -*- lexical-binding: t -*-
  2. ;; Copyright (c) 2018 Federico Beffa. All rights reserved.
  3. ;; This file is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation; either version 3, or (at your option)
  6. ;; any later version.
  7. ;; This file is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. (defcustom haskell-svg-render-images nil
  15. "Replace SVG image text with actual images."
  16. :group 'haskell-interactive
  17. :type 'boolean)
  18. (defconst haskell-svg-supported (image-type-available-p 'svg)
  19. "Defines if SVG images are supported by this instance of Emacs.")
  20. (defun haskell-svg-render-images-p ()
  21. "Shall we render SVG images?"
  22. (and haskell-svg-supported (display-images-p) haskell-svg-render-images))
  23. (defun haskell-svg-maybe-render-images (text)
  24. "Render SVG images if desired and supported, or terurn the
  25. input unmodified."
  26. (if (haskell-svg-render-images-p)
  27. (haskell-svg-render-images text)
  28. text))
  29. (defun haskell-svg-render-images (text)
  30. "Replace an SVG image text with an actual image."
  31. (with-temp-buffer
  32. (insert text)
  33. (goto-char (point-min))
  34. (when (re-search-forward
  35. "\"?<\\?xml\\(.\\|\n\\|\r\\)* PUBLIC \"-//W3C//DTD SVG [0-9]\.[0-9]//EN\\(.\\|\n\\|\r\\)*</svg>\"?"
  36. nil t)
  37. (let ((svg-string (match-string 0))
  38. (begin (match-beginning 0))
  39. (end (match-end 0)))
  40. (delete-region begin end)
  41. (goto-char begin)
  42. (insert-image (create-image svg-string nil t) "SVG image")))
  43. (buffer-substring (point-min) (point-max))))
  44. (defun haskell-svg-toggle-render-images ()
  45. "Toggle rendering of SVG images at the REPL output."
  46. (interactive)
  47. (setq haskell-svg-render-images (not haskell-svg-render-images)))
  48. (provide 'haskell-svg)
  49. ;;; haskell-svg.el ends here