Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
;; esvg-eepitch.el. -*- lexical-binding: nil; -*-
;; This file:
;;   https://anggtwu.net/elisp/esvg-eepitch.el.html
;;   https://anggtwu.net/elisp/esvg-eepitch.el
;;           (find-angg "elisp/esvg-eepitch.el")
;; Author: Eduardo Ochs <eduardoochs@gmail.com>
;;
;; This is the second lowest-level file in esvg - edrx's (REPL for) SVG.
;; This file implements a variant of eepitch that can be used as sort
;; of "a REPL for learning SVG", and binds it to <f9>.
;; See the demo at the end of this file!
;;
;; (defun e () (interactive) (find-angg "elisp/esvg-eepitch.el"))
;; (defun o () (interactive) (find-angg "elisp/2026-eepitch-svg.el"))
;;
;; «.eepitch-esvg-skip-blanks»	(to "eepitch-esvg-skip-blanks")
;; «.eepitch-esvg-this-line»	(to "eepitch-esvg-this-line")
;; «.eepitch-esvg-f9»		(to "eepitch-esvg-f9")
;; «.eeit-esvg»			(to "eeit-esvg")
;; «.demo-svg-el»		(to "demo-svg-el")
;; «.svg-el-usage-examples»	(to "svg-el-usage-examples")

(require 'eev-load)		; (find-eev "eev-load.el")
(require 'esvg-show)		; (find-angg "elisp/esvg-eepitch.el")



;; «eepitch-esvg-skip-blanks»  (to ".eepitch-esvg-skip-blanks")
;; See: (find-elnode "Rx Constructs" "Match at point")
;;      (find-elnode "Rx Constructs" "(regexp EXPR)")
;;      (find-elnode "Extending Rx" "Macro: rx-let")
;;      (find-eev "eepitch.el" "eepitch" "eepitch-regexp")
;;
(defvar eepitch-esvg-skip-blanks
  (rx-let ((blankline    (regexp  "[ \t]*\n"))
           (commentline  (regexp  "[ \t]*;[^\n]*\n"))
           (starstarline (regexp "[*][*][^\n]*\n"))
           (skiplines    (0+ (or blankline commentline starstarline)))
	   (lastleft     (seq (optional (regexp "[*] "))
			      (regexp "[ \t]*"))))
    (rx (seq point skiplines lastleft)))
  "A regexp used by `eepitch-esvg-this-line' to skip comments and some red stars.")


;; «eepitch-esvg-this-line»  (to ".eepitch-esvg-this-line")
;; Based on: (find-eevfile "eepitch.el" "(defun eepitch-this-line ")
(defun eepitch-esvg-this-line ()
  (interactive)
  (move-beginning-of-line nil)
  (let* ((before (point)))
    (re-search-forward eepitch-esvg-skip-blanks) ; skip red stars
    (let* ((end    (ee-forward-sexp))
           (start  (ee-backward-sexp))
	   (after  (progn (goto-char end) (next-line 1) (ee-bol)))
           (sexp   (buffer-substring-no-properties start end)))
      (goto-char before)
      (eeflash start end ee-highlight-spec)
      (prin1 (ee-eval (ee-read sexp)))	; may fail
      (goto-char after))))


;; «eepitch-esvg-f9»  (to ".eepitch-esvg-f9")
;; Overrides this: (find-eev "eepitch.el" "eepitch-b" "<f9>")
(define-key eev-mode-map (kbd "<f9>") 'eepitch-esvg-this-line)



;; «demo-svg-el»            (to ".demo-svg-el")
;; «svg-el-usage-examples»  (to ".svg-el-usage-examples")
;; This is the test from the "Commentary:" section
;; of svg.el, practically unchanged. See:
;;   (find-efile "svg.el" "Commentary:")
;;   (find-efile "svg.el" "Here are some usage examples:")
;;
;; ... but the version in svg.el inserts the SVG object at
;; the end of svg.el itself, and here we use `show-svg' to
;; draw it at the window at the right.
;;
;; This is demo that is called "The demo in svg.el" in:
;;   https://anggtwu.net/2026-eepitch-svg.html#the-demo-in-svg.el
;;   https://anggtwu.net/IMAGES/2026-eepitch-svg-1.png
;;   https://anggtwu.net/eev-videos/2026-eepitch-svg-1.mp4
;;
'("This is a test block for `eepitch-svg'! Use <f9>s!"

* (load (buffer-file-name))
* (setq svg (svg-create 800 800 :stroke "orange" :stroke-width 5))
* (show-svg)
  (svg-gradient  svg "gradient" 'linear '((0 . "red") (100 . "blue")))
  (svg-rectangle svg 100 100 500 500 :gradient "gradient" :id "rec1")


  ;; Note that `svg-rectangle', `svg-circle',
  ;; and friends all call `svg--append', that
  ;; calls `svg-possibly-update-image'...
  ;;
  (svg-circle    svg 500 500 100                          :id "circle1")
  (svg-ellipse   svg 100 100 50 90   :stroke "red"        :id "ellipse1")
  (svg-line      svg 100 190 50 100  :stroke "yellow"     :id "line1")
  (svg-polyline  svg '((200 . 100) (500 . 450) (80 . 100))
                                     :stroke "green"      :id "polyline1")
  (svg-polygon   svg '((100 . 100) (200 . 150) (150 . 90))
                         :fill "red" :stroke "blue"       :id "polygon1")


  ;; The two sexps below switch between a 2-window setting, that shows
  ;; only this file at the left and the "*svg*" buffer at the right,
  ;; and a 4-window setting that shows three windows at the right:
  ;; "*svg*", "*svg-pp*", and "*svg-xml*"
  ;;
  (show-svg-pp-xml)
  (show-svg)


  ;; Note that the line 2 in "*svg-pp*" has this,
  ;;   (:image . #<marker at 1 in *svg*>)
  ;; that disappears in the conversion to XML in "*svg-xml*"...
  ;; Look at the code:
  ;;   (find-efile "svg.el" "(defun svg-rectangle")
  ;;   (find-efile "svg.el" "(defun svg-rectangle" "svg--append")
  ;;   (find-efile "svg.el" "(defun svg--append")
  ;;   (find-efile "svg.el" "(defun svg--append" "svg-possibly-update-image")
  ;;   (find-efile "svg.el" "(defun svg-possibly-update-image")
  ;;
  ;; The function `svg-possibly-update-image' does something VERY
  ;; tricky. It looks at the marker in the cdr of (:image . `HERE') in
  ;; the SVG object, and if the buffer with that marker is live then
  ;; the "display" text property at the character at that position is
  ;; updated.

"--")


(provide 'esvg-eepitch)






;; Local Variables:
;; coding:  utf-8-unix
;; End: