From 862c75c9e7c2d4f1d0b448efba49825c8fc73733 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Tue, 19 Sep 2017 23:44:08 +0200 Subject: [PATCH] Eldoc and start of keywords for gff section. --- pico8.el | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pico8.el b/pico8.el index 0bb0d19..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))) -- 2.30.2