sysrpl-mode.el 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. ;;; sysrpl-mode.el -- Major mode for the SysRPL programming language
  2. ;; Copyright (C) 2013 Paul Onions
  3. ;; Author: Paul Onions <paul.onions@acm.org>
  4. ;; Keywords: RPL, SysRPL, HP48, HP49, HP50, calculator
  5. ;; This file is free software, see the LICENCE file in this directory
  6. ;; for copying terms.
  7. ;;; Commentary:
  8. ;; A major mode for the SysRPL language, the system programming
  9. ;; language of HP48/49/50-series calculators.
  10. ;;; Code:
  11. (require 'rpl-base)
  12. (defcustom rpl-sysrpl-default-calculator :HP48G
  13. "Default calculator type for SysRPL mode."
  14. :type '(radio :HP38G :HP39G :HP48G :HP49G)
  15. :group 'rpl)
  16. (defface sysrpl-name '((t (:foreground "blue")))
  17. "Face used for displaying SysRPL names."
  18. :group 'rpl)
  19. (defvar sysrpl-syntax-table
  20. (let ((table (make-syntax-table)))
  21. (modify-syntax-entry ?: "w" table)
  22. (modify-syntax-entry ?! "w" 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. table)
  39. "The SysRPL syntax table.")
  40. (defvar sysrpl-keywords-regexp
  41. (concat "\\<" (regexp-opt rpl-sysrpl-names) "\\>")
  42. "Regular expression for SysRPL keywords.")
  43. (defvar sysrpl-keyword-face 'sysrpl-name)
  44. (defvar sysrpl-font-lock-keywords
  45. (list (cons sysrpl-keywords-regexp 'sysrpl-keyword-face)))
  46. (defvar sysrpl-selected-calculator rpl-sysrpl-default-calculator
  47. "Currently selected calculator model.")
  48. (defun sysrpl-select-hp38g ()
  49. "Set the currently selected calculator model to be the 38G."
  50. (interactive)
  51. (setq sysrpl-selected-calculator :HP38G))
  52. (defun sysrpl-select-hp39g ()
  53. "Set the currently selected calculator model to be the 39G."
  54. (interactive)
  55. (setq sysrpl-selected-calculator :HP39G))
  56. (defun sysrpl-select-hp48g ()
  57. "Set the currently selected calculator model to be the 48G."
  58. (interactive)
  59. (setq sysrpl-selected-calculator :HP48G))
  60. (defun sysrpl-select-hp49g ()
  61. "Set the currently selected calculator model to be the 49G."
  62. (interactive)
  63. (setq sysrpl-selected-calculator :HP49G))
  64. (defvar sysrpl-mode-map
  65. (let ((map (make-sparse-keymap))
  66. (menu-map (make-sparse-keymap)))
  67. (set-keymap-parent map rpl-common-keymap)
  68. ;; Menu items
  69. (define-key map [menu-bar rpl-menu] (cons "RPL" menu-map))
  70. (define-key menu-map [sysrpl-menu-separator-1]
  71. '(menu-item "--"))
  72. (define-key menu-map [sysrpl-menu-select-hp49g]
  73. '(menu-item "HP49G" sysrpl-select-hp49g
  74. :button (:radio . (eql :HP49G sysrpl-selected-calculator))))
  75. (define-key menu-map [sysrpl-menu-select-hp48g]
  76. '(menu-item "HP48G" sysrpl-select-hp48g
  77. :button (:radio . (eql :HP48G sysrpl-selected-calculator))))
  78. (define-key menu-map [sysrpl-menu-select-hp39g]
  79. '(menu-item "HP39G" sysrpl-select-hp39g
  80. :button (:radio . (eql :HP39G sysrpl-selected-calculator))))
  81. (define-key menu-map [sysrpl-menu-select-hp38g]
  82. '(menu-item "HP38G" sysrpl-select-hp38g
  83. :button (:radio . (eql :HP38G sysrpl-selected-calculator))))
  84. map)
  85. "The SysRPL mode local keymap.")
  86. (defvar sysrpl-mode-hook nil
  87. "Hook for customizing SysRPL mode.")
  88. (define-derived-mode sysrpl-mode prog-mode "SysRPL"
  89. "Major mode for the SysRPL language."
  90. :group 'rpl
  91. (setq font-lock-defaults (list sysrpl-font-lock-keywords))
  92. (setq rpl-menu-compile-file-enable t))
  93. (provide 'sysrpl-mode)