sysrpl-mode.el 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ;;; -*- mode: emacs-lisp; lexical-binding: t -*-
  2. ;;; sysrpl-mode.el -- Major mode for the SysRPL programming language
  3. ;; Copyright (C) 2014 Paul Onions
  4. ;; Author: Paul Onions <paul.onions@acm.org>
  5. ;; Keywords: RPL, SysRPL, HP48, HP49, HP50, calculator
  6. ;; This file is free software, see the LICENCE file in this directory
  7. ;; for copying terms.
  8. ;;; Commentary:
  9. ;; A major mode for the SysRPL language, the system programming
  10. ;; language of HP48/49/50-series calculators.
  11. ;;; Code:
  12. (require 'cl-lib)
  13. (require 'rpl-base)
  14. (defcustom rpl-sysrpl-default-calculator :48G
  15. "Default calculator type for SysRPL mode."
  16. :type '(radio :38G :39G :48G :49G)
  17. :group 'rpl)
  18. (defface sysrpl-name '((t (:foreground "blue")))
  19. "Face used for displaying SysRPL names."
  20. :group 'rpl)
  21. (defvar sysrpl-mode-syntax-table
  22. (let ((table (make-syntax-table prog-mode-syntax-table)))
  23. (modify-syntax-entry ?: "w" table)
  24. (modify-syntax-entry ?! "w" table)
  25. (modify-syntax-entry ?@ "w" table)
  26. (modify-syntax-entry ?# "w" table)
  27. (modify-syntax-entry ?$ "w" table)
  28. (modify-syntax-entry ?% "w" table)
  29. (modify-syntax-entry ?^ "w" table)
  30. (modify-syntax-entry ?& "w" table)
  31. (modify-syntax-entry ?\? "w" table)
  32. (modify-syntax-entry ?- "w" table)
  33. (modify-syntax-entry ?_ "w" table)
  34. (modify-syntax-entry ?= "w" table)
  35. (modify-syntax-entry ?+ "w" table)
  36. (modify-syntax-entry ?* "w" table)
  37. (modify-syntax-entry ?/ "w" table)
  38. (modify-syntax-entry ?< "w" table)
  39. (modify-syntax-entry ?> "w" table)
  40. (modify-syntax-entry ?| "w" table)
  41. table)
  42. "The SysRPL syntax table.")
  43. (defvar sysrpl-keyword-face 'sysrpl-name)
  44. (defun sysrpl-font-lock-compile-keywords (names)
  45. "Construct a list of keyword matcher clauses suitable for ``font-lock-keywords''."
  46. (mapcar (lambda (str) (list (concat "\\<" (regexp-quote str) "\\>")
  47. (list 0 'sysrpl-keyword-face)))
  48. names))
  49. (defvar sysrpl-font-lock-keywords
  50. (sysrpl-font-lock-compile-keywords (rpl-sysrpl-names rpl-sysrpl-default-calculator)))
  51. (defvar sysrpl-selected-calculator rpl-sysrpl-default-calculator
  52. "Currently selected calculator model.")
  53. (defun sysrpl-select-38g ()
  54. "Set the currently selected calculator model to be the 38G."
  55. (interactive)
  56. (setq sysrpl-selected-calculator :38G)
  57. (setq sysrpl-font-lock-keywords (sysrpl-font-lock-compile-keywords (rpl-sysrpl-names :38G)))
  58. (sysrpl-mode))
  59. (defun sysrpl-select-39g ()
  60. "Set the currently selected calculator model to be the 39G."
  61. (interactive)
  62. (setq sysrpl-selected-calculator :39G)
  63. (setq sysrpl-font-lock-keywords (sysrpl-font-lock-compile-keywords (rpl-sysrpl-names :39G)))
  64. (sysrpl-mode))
  65. (defun sysrpl-select-48g ()
  66. "Set the currently selected calculator model to be the 48G."
  67. (interactive)
  68. (setq sysrpl-selected-calculator :48G)
  69. (setq sysrpl-font-lock-keywords (sysrpl-font-lock-compile-keywords (rpl-sysrpl-names :48G)))
  70. (sysrpl-mode))
  71. (defun sysrpl-select-49g ()
  72. "Set the currently selected calculator model to be the 49G."
  73. (interactive)
  74. (setq sysrpl-selected-calculator :49G)
  75. (setq sysrpl-font-lock-keywords (sysrpl-font-lock-compile-keywords (rpl-sysrpl-names :49G)))
  76. (sysrpl-mode))
  77. (defvar sysrpl-mode-map
  78. (let ((map (make-sparse-keymap))
  79. (menu-map (make-sparse-keymap)))
  80. (set-keymap-parent map rpl-common-keymap)
  81. ;; Menu items
  82. (define-key map [menu-bar rpl-menu] (cons "RPL" menu-map))
  83. (define-key menu-map [sysrpl-menu-separator-1]
  84. '(menu-item "--"))
  85. (define-key menu-map [sysrpl-menu-select-49g]
  86. '(menu-item "HP49G" sysrpl-select-49g
  87. :button (:radio . (eql :49G sysrpl-selected-calculator))))
  88. (define-key menu-map [sysrpl-menu-select-48g]
  89. '(menu-item "HP48G" sysrpl-select-48g
  90. :button (:radio . (eql :48G sysrpl-selected-calculator))))
  91. (define-key menu-map [sysrpl-menu-select-39g]
  92. '(menu-item "HP39G" sysrpl-select-39g
  93. :button (:radio . (eql :39G sysrpl-selected-calculator))))
  94. (define-key menu-map [sysrpl-menu-select-38g]
  95. '(menu-item "HP38G" sysrpl-select-38g
  96. :button (:radio . (eql :38G sysrpl-selected-calculator))))
  97. map)
  98. "The SysRPL mode local keymap.")
  99. (defvar sysrpl-mode-hook nil
  100. "Hook for customizing SysRPL mode.")
  101. (define-derived-mode sysrpl-mode prog-mode "SysRPL"
  102. "Major mode for the SysRPL language."
  103. :group 'rpl
  104. (setq font-lock-defaults (list 'sysrpl-font-lock-keywords))
  105. (setq rpl-menu-compile-file-enable nil))
  106. (provide 'sysrpl-mode)