X-Git-Url: https://git.korewanetadesu.com/?p=pico8.git;a=blobdiff_plain;f=pico8.el;h=7600345ef7d7e4d440def660b68c96d4904dc336;hp=e8431dcd4962e3144da0cb4902415ef774127f0d;hb=862c75c9e7c2d4f1d0b448efba49825c8fc73733;hpb=55ce0999377418e6a7d9c751972d9e1c5d9c0ee7 diff --git a/pico8.el b/pico8.el index e8431dc..7600345 100644 --- a/pico8.el +++ b/pico8.el @@ -25,6 +25,7 @@ (require 'lua-mode) (require 'thingatpt) (require 'dash) +(require 'calc-bin) (defgroup pico8 nil @@ -256,15 +257,40 @@ Make sure it is installed, and present in ‘pico8-executable-paths’"))) (col (current-column))) (+ (* 128 row) (/ col 2))))) +(defun pico8-gff-eldoc () + "Show information about the flag under the point." + (save-excursion + (when (cl-oddp (current-column)) + (backward-char)) + (when (looking-at "..") + (let* ((hex (substring-no-properties (match-string 0))) + (int (string-to-number hex 16))) + (format "%08d %3d %02x" + (let ((calc-number-radix 2)) + (string-to-number (math-format-radix int))) + int int))))) + +(defconst pico8-gff-font-lock-keywords + '(("..\n?" 0 + (prog1 nil + ;; TODO: Lots of work to do here… + (let ((pdl (or (car (overlays-at (match-beginning 0))) + (make-overlay (match-beginning 0) (match-end 0))))) + (overlay-put pdl 'after-string " ")))))) + + (define-derived-mode pico8-gff-mode pico8-data-mode '(:eval (format "Flag[%d]" (pico8-gff-lighter))) - "Major mode for editing flags in PICO-8 cartridges.") + "Major mode for editing flags in PICO-8 cartridges." + (font-lock-add-keywords nil pico8-gff-font-lock-keywords) + (setq-local eldoc-documentation-function #'pico8-gff-eldoc)) (defun pico8-gff-offset-of-flag (flag) "Calculate the offset of of flag number FLAG." (unless (<= 0 flag 255) (error "Valid flag numbers are 0 to 255, inclusive")) (+ (* 2 flag) (if (> flag 128) 1 0))) + (defface pico8-pixel '((t (:inherit pico8-data :height 100))) @@ -279,7 +305,7 @@ Make sure it is installed, and present in ‘pico8-executable-paths’"))) (-map-indexed (lambda (i c) `(,(format "%x+" i) - 0 '(:inherit pico8-pixel :foreground ,c))) + 0 '(face (:inherit pico8-pixel :foreground ,c)))) pico8-colors)))