Update to new Polymode API
[pico8.git] / pico8.el
index 7600345..dabe69b 100644 (file)
--- a/pico8.el
+++ b/pico8.el
@@ -245,14 +245,14 @@ Make sure it is installed, and present in ‘pico8-executable-paths’")))
 \f
 (defun pico8-gff-current-position ()
   "Calculate the flag position of the cursor."
 \f
 (defun pico8-gff-current-position ()
   "Calculate the flag position of the cursor."
-  (pm-with-narrowed-to-span (pm-get-innermost-span)
+  (pm-with-narrowed-to-span (pm-innermost-span)
     (let ((row (1- (line-number-at-pos)))
           (col (min 255 (current-column))))
       (+ (/ col 2) (* row 128)))))
 
 (defun pico8-gff-lighter ()
   "Calculate the flag under the cursor."
     (let ((row (1- (line-number-at-pos)))
           (col (min 255 (current-column))))
       (+ (/ col 2) (* row 128)))))
 
 (defun pico8-gff-lighter ()
   "Calculate the flag under the cursor."
-  (pm-with-narrowed-to-span (pm-get-innermost-span)
+  (pm-with-narrowed-to-span (pm-innermost-span)
     (let ((row (1- (line-number-at-pos)))
           (col (current-column)))
       (+ (* 128 row) (/ col 2)))))
     (let ((row (1- (line-number-at-pos)))
           (col (current-column)))
       (+ (* 128 row) (/ col 2)))))
@@ -312,7 +312,7 @@ Make sure it is installed, and present in ‘pico8-executable-paths’")))
 (defun pico8-gfx-current-position ()
   "Calculate the sprite and in-sprite position of the cursor."
   ;; FIXME: Ensure the span we got was actually the gfx one.
 (defun pico8-gfx-current-position ()
   "Calculate the sprite and in-sprite position of the cursor."
   ;; FIXME: Ensure the span we got was actually the gfx one.
-  (pm-with-narrowed-to-span (pm-get-innermost-span)
+  (pm-with-narrowed-to-span (pm-innermost-span)
     (let ((row (1- (line-number-at-pos)))
           (col (min 127 (current-column))))
       (list (+ (* 16 (/ row 8)) (/ col 8))
     (let ((row (1- (line-number-at-pos)))
           (col (min 127 (current-column))))
       (list (+ (* 16 (/ row 8)) (/ col 8))
@@ -327,7 +327,7 @@ Make sure it is installed, and present in ‘pico8-executable-paths’")))
                  (% (+ 256 n (nth 0 current)) 256)
                  (nth 1 current)
                  (nth 2 current))))
                  (% (+ 256 n (nth 0 current)) 256)
                  (nth 1 current)
                  (nth 2 current))))
-    (pm-with-narrowed-to-span (pm-get-innermost-span)
+    (pm-with-narrowed-to-span (pm-innermost-span)
       (goto-char (+ (point-min) offset)))))
 
 (defun pico8-backward-sprite (n)
       (goto-char (+ (point-min) offset)))))
 
 (defun pico8-backward-sprite (n)
@@ -376,7 +376,7 @@ Make sure it is installed, and present in ‘pico8-executable-paths’")))
 
 (defun pico8-map-lighter ()
   "Calculate the map tile under the cursor."
 
 (defun pico8-map-lighter ()
   "Calculate the map tile under the cursor."
-  (pm-with-narrowed-to-span (pm-get-innermost-span)
+  (pm-with-narrowed-to-span (pm-innermost-span)
     (let ((row (- (line-number-at-pos) 1))
           (col (current-column)))
       ;; TODO: Show sprite number and flags value
     (let ((row (- (line-number-at-pos) 1))
           (col (current-column)))
       ;; TODO: Show sprite number and flags value
@@ -389,7 +389,7 @@ Make sure it is installed, and present in ‘pico8-executable-paths’")))
 \f
 (defun pico8-sfx-lighter ()
   "Calculate the sound effect under the cursor."
 \f
 (defun pico8-sfx-lighter ()
   "Calculate the sound effect under the cursor."
-  (pm-with-narrowed-to-span (pm-get-innermost-span)
+  (pm-with-narrowed-to-span (pm-innermost-span)
     (let ((row (- (line-number-at-pos) 1)))
       (format "%d" row))))
 
     (let ((row (- (line-number-at-pos) 1)))
       (format "%d" row))))
 
@@ -399,7 +399,7 @@ Make sure it is installed, and present in ‘pico8-executable-paths’")))
 \f
 (defun pico8-music-lighter ()
   "Calculate the map tile under the cursor."
 \f
 (defun pico8-music-lighter ()
   "Calculate the map tile under the cursor."
-  (pm-with-narrowed-to-span (pm-get-innermost-span)
+  (pm-with-narrowed-to-span (pm-innermost-span)
     (let ((row (- (line-number-at-pos) 1)))
       (format "%d" row))))
 
     (let ((row (- (line-number-at-pos) 1)))
       (format "%d" row))))
 
@@ -575,27 +575,28 @@ See URL ‘https://github.com/mpeterv/luacheck’."
 (defmacro pico8--defchunkmode (name)
   "Define a PICO-8 polymode chunk for section NAME."
   `(defconst ,(intern (concat "pico8--pm-inner-" name))
 (defmacro pico8--defchunkmode (name)
   "Define a PICO-8 polymode chunk for section NAME."
   `(defconst ,(intern (concat "pico8--pm-inner-" name))
-     (pm-hbtchunkmode :mode ',(intern (format "pico8-%s-mode" name))
-                      :head-mode 'host
-                      :head-reg ,(format "^__%s__\n" name)
-                      :tail-reg "^__[a-z]\\{3,5\\}__\n\\|^\n\\'")))
-
-(defconst pico8--pm-poly
-  (pm-polymode-multi
-   :hostmode
-   (defconst pico8--pm-host
-     (pm-bchunkmode :mode 'pico8-cartridge-mode))
+     (pm-inner-chunkmode
+      :name ,name
+      :mode ',(intern (format "pico8-%s-mode" name))
+      :head-mode 'host
+      :head-matcher ,(format "^__%s__\n" name)
+      :tail-matcher "^__[a-z]\\{3,5\\}__\n\\|^\n\\'")))
+
+
+(defconst pico8--pm-host
+  (pm-host-chunkmode :name "PICO-8" :mode 'pico8-cartridge-mode))
+
+(define-polymode pico8-mode
+   :hostmode 'pico8--pm-host
    :innermodes (list
                 (pico8--defchunkmode "lua")
                 (pico8--defchunkmode "gfx")
                 (pico8--defchunkmode "gff")
                 (pico8--defchunkmode "map")
                 (pico8--defchunkmode "sfx")
    :innermodes (list
                 (pico8--defchunkmode "lua")
                 (pico8--defchunkmode "gfx")
                 (pico8--defchunkmode "gff")
                 (pico8--defchunkmode "map")
                 (pico8--defchunkmode "sfx")
-                (pico8--defchunkmode "music"))))
-
-(define-polymode pico8-mode pico8--pm-poly
-  :lighter "P8"
-  :keymap '(("\C-c\C-r" . pico8-run-cartridge)
+                (pico8--defchunkmode "music"))
+   :lighter "P8"
+   :keymap '(("\C-c\C-r" . pico8-run-cartridge)
             ("\C-c\C-e" . pico8-load-cartridge)
             ("\M-gs" . pico8-goto-sprite)
             ("\M-gS" . pico8-goto-sprite-relevant-to-point)
             ("\C-c\C-e" . pico8-load-cartridge)
             ("\M-gs" . pico8-goto-sprite)
             ("\M-gS" . pico8-goto-sprite-relevant-to-point)