;;; -*- mode: emacs-lisp; lexical-binding: t -*- ;;; sysrpl-mode.el -- Major mode for the SysRPL programming language ;; Copyright (C) 2014 Paul Onions ;; Author: Paul Onions ;; Keywords: RPL, SysRPL, HP48, HP49, HP50, calculator ;; This file is free software, see the LICENCE file in this directory ;; for copying terms. ;;; Commentary: ;; A major mode for the SysRPL language, the system programming ;; language of HP48/49/50-series calculators. ;;; Code: (require 'cl-lib) (require 'rpl-base) (require 'rpl-edb) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Customizations ;; (defcustom rpl-sysrpl-default-calculator :48G "Default calculator type for SysRPL mode." :type '(radio :38G :39G :48G :49G) :group 'rpl) (defface sysrpl-name '((t :foreground "darkblue")) "Face used for displaying SysRPL names (e.g DROP)." :group 'rpl) (defface sysrpl-keyword '((t :foreground "purple")) "Face used for displaying SysRPL keywords (e.g. :: ;)." :group 'rpl) (defface sysrpl-comment '((t :foreground "darkgreen")) "Face used for displaying SysRPL comments." :group 'rpl) (defcustom sysrpl-font-lock-name-face 'sysrpl-name "Name of face to use for displaying SysRPL names." :type 'symbol :group 'rpl) (defcustom sysrpl-font-lock-keyword-face 'sysrpl-keyword "Name of face to use for displaying SysRPL keywords." :type 'symbol :group 'rpl) (defcustom sysrpl-font-lock-comment-face 'sysrpl-comment "Name of face to use for displaying SysRPL comments." :type 'symbol :group 'rpl) (defvar sysrpl-mode-syntax-table (let ((table (make-syntax-table prog-mode-syntax-table))) (modify-syntax-entry ?: "w" table) (modify-syntax-entry ?\; "w" table) (modify-syntax-entry ?! "w" table) (modify-syntax-entry ?@ "w" table) (modify-syntax-entry ?# "w" table) (modify-syntax-entry ?$ "w" table) (modify-syntax-entry ?% "w" table) (modify-syntax-entry ?^ "w" table) (modify-syntax-entry ?& "w" table) (modify-syntax-entry ?\? "w" table) (modify-syntax-entry ?- "w" table) (modify-syntax-entry ?_ "w" table) (modify-syntax-entry ?= "w" table) (modify-syntax-entry ?+ "w" table) (modify-syntax-entry ?* "w" table) (modify-syntax-entry ?/ "w" table) (modify-syntax-entry ?< "w" table) (modify-syntax-entry ?> "w" table) (modify-syntax-entry ?| "w" table) table) "The SysRPL syntax table.") (defun sysrpl-font-lock-compile-keywords (names) "Construct a list of keyword matcher clauses suitable for `font-lock-keywords'." (append (list (list "^\\*.*$" (list 0 'sysrpl-font-lock-comment-face)) (list "(.*)" (list 0 'sysrpl-font-lock-comment-face)) (list (concat "\\<" (regexp-opt '("::" ";")) "\\>") (list 0 'sysrpl-font-lock-keyword-face))) (mapcar (lambda (str) (list (concat "\\<" (regexp-quote str) "\\>") (list 0 'sysrpl-font-lock-name-face))) names))) (defvar sysrpl-font-lock-keywords (sysrpl-font-lock-compile-keywords (rpl-edb-all-names rpl-sysrpl-default-calculator))) (defvar sysrpl-selected-calculator rpl-sysrpl-default-calculator "Currently selected calculator model.") (defun sysrpl-select-38g () "Set the currently selected calculator model to be the 38G." (interactive) (setq sysrpl-selected-calculator :38G) (setq sysrpl-font-lock-keywords (sysrpl-font-lock-compile-keywords (rpl-edb-all-names :38G))) (sysrpl-mode)) (defun sysrpl-select-39g () "Set the currently selected calculator model to be the 39G." (interactive) (setq sysrpl-selected-calculator :39G) (setq sysrpl-font-lock-keywords (sysrpl-font-lock-compile-keywords (rpl-edb-all-names :39G))) (sysrpl-mode)) (defun sysrpl-select-48g () "Set the currently selected calculator model to be the 48G." (interactive) (setq sysrpl-selected-calculator :48G) (setq sysrpl-font-lock-keywords (sysrpl-font-lock-compile-keywords (rpl-edb-all-names :48G))) (sysrpl-mode)) (defun sysrpl-select-49g () "Set the currently selected calculator model to be the 49G." (interactive) (setq sysrpl-selected-calculator :49G) (setq sysrpl-font-lock-keywords (sysrpl-font-lock-compile-keywords (rpl-edb-all-names :49G))) (sysrpl-mode)) (defun sysrpl-show-stack-effect (name) (message (rpl-edb-get-stack-effect sysrpl-selected-calculator name))) (defun sysrpl-apropos-thing-at-point (name) "Show information about NAME in a popup buffer. When called interactively NAME defaults to the word around point." (interactive (list (completing-read "Apropos: " (rpl-edb-all-names sysrpl-selected-calculator) nil nil (thing-at-point 'word)))) (let ((bufname (format "*SysRPL: %s*" name))) (with-current-buffer (get-buffer-create bufname) (setq buffer-read-only nil) (erase-buffer) (insert (rpl-edb-get-stack-effect sysrpl-selected-calculator name)) (newline) (insert (rpl-edb-get-description sysrpl-selected-calculator name)) (newline) (insert (format "Address: %s" (rpl-edb-get-address sysrpl-selected-calculator name))) (newline) (insert (format "Flags: %s" (rpl-edb-get-flags sysrpl-selected-calculator name))) (newline) (end-of-buffer) (help-mode) (set-buffer-modified-p nil) (setq buffer-read-only t)) (fit-window-to-buffer (display-buffer bufname)))) (defvar sysrpl-mode-map (let ((map (make-sparse-keymap)) (menu-map (make-sparse-keymap))) (set-keymap-parent map rpl-common-keymap) ;; Menu items (define-key map [menu-bar rpl-menu] (cons "RPL" menu-map)) (define-key menu-map [sysrpl-menu-separator-1] '(menu-item "--")) (define-key menu-map [sysrpl-menu-select-49g] '(menu-item "HP49G" sysrpl-select-49g :button (:radio . (eql :49G sysrpl-selected-calculator)))) (define-key menu-map [sysrpl-menu-select-48g] '(menu-item "HP48G" sysrpl-select-48g :button (:radio . (eql :48G sysrpl-selected-calculator)))) (define-key menu-map [sysrpl-menu-select-39g] '(menu-item "HP39G" sysrpl-select-39g :button (:radio . (eql :39G sysrpl-selected-calculator)))) (define-key menu-map [sysrpl-menu-select-38g] '(menu-item "HP38G" sysrpl-select-38g :button (:radio . (eql :38G sysrpl-selected-calculator)))) map) "The SysRPL mode local keymap.") (defvar sysrpl-mode-hook nil "Hook for customizing SysRPL mode.") (define-derived-mode sysrpl-mode prog-mode "SysRPL" "Major mode for the SysRPL language." :group 'rpl (setq font-lock-defaults (list 'sysrpl-font-lock-keywords)) (setq rpl-menu-compile-file-enable nil)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; End of file ;; (provide 'sysrpl-mode)