rpl-base.el 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ;;; rpl-base.el -- basic setup for the RPL tools
  2. ;; Copyright (C) 2014 Paul Onions
  3. ;; Author: Paul Onions <paul.onions@acm.org>
  4. ;; Keywords: RPL, SysRPL, HP48, HP49, HP50
  5. ;; This file is free software, see the LICENCE file in this directory
  6. ;; for copying terms.
  7. ;;; Commentary:
  8. ;; Basic setup for the RPL tools.
  9. ;;; Code:
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11. ;; Customizations
  12. ;;
  13. (defgroup rpl nil
  14. "Tools for working with the RPL calculator programming language.")
  15. (defcustom rpl-sysrpl-data-file-prefix "sysrpl-data"
  16. "Filename prefix for files from which to `read' SysRPL data."
  17. :type 'string
  18. :group 'rpl)
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;; Utility functions for generating/loading pre-computed data
  21. ;;
  22. (defun rpl-make-sysrpl-data-filename (calculator)
  23. "Make the SysRPL data filename used for CALCULATOR.
  24. Where CALCULATOR should be a keyword symbol identifying the
  25. calculator model, e.g. :48G, :49G etc."
  26. (assert (keywordp calculator))
  27. (concat rpl-sysrpl-data-file-prefix "." (substring (symbol-name calculator) 1) ".el"))
  28. (defvar rpl-tools-data-dir
  29. (and load-file-name (concat (file-name-directory load-file-name) "data/"))
  30. "RPL tools data directory.")
  31. (defun rpl-write-data-file (obj filename)
  32. "Write OBJ to FILENAME using function `print'.
  33. The directory in which to write the file defaults to the value of
  34. the variable `rpl-tools-data-dir'. This can be overridden by
  35. specifying a different path in the FILENAME string (either
  36. relative or absolute)."
  37. (let ((default-directory rpl-tools-data-dir))
  38. (with-temp-buffer
  39. (print obj (current-buffer))
  40. (write-region (point-min) (point-max) filename))))
  41. (defun rpl-read-data-file (filename)
  42. "Read a Lisp object from FILENAME using function `read'.
  43. The directory in which FILENAME resides is assumed to be the
  44. value of the variable `rpl-tools-data-dir'. This can be
  45. overridden by specifying a different path in the FILENAME
  46. string (either relative or absolute)."
  47. (let ((default-directory rpl-tools-data-dir))
  48. (with-temp-buffer
  49. (insert-file-contents filename)
  50. (goto-char (point-min))
  51. (read (current-buffer)))))
  52. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  53. ;; Load SysRPL names files
  54. ;;
  55. (message "Loading SysRPL information")
  56. (defvar rpl-sysrpl-data
  57. nil ;;(rpl-read-data-file rpl-sysrpl-data-file)
  58. "!!!TODO!!!")
  59. (defvar rpl-sysrpl-names
  60. nil ; extract from rpl-sysrpl-data
  61. "!!!TODO!!!")
  62. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  63. ;; Common keymap (including the ``RPL'' menu)
  64. ;;
  65. (defvar rpl-menu-compile-file-enable nil)
  66. (make-variable-buffer-local 'rpl-menu-compile-file-enable)
  67. (defvar rpl-common-keymap
  68. (let ((map (make-sparse-keymap "RPL"))
  69. (menu-map (make-sparse-keymap "RPL")))
  70. (set-keymap-parent map prog-mode-map)
  71. ;; Key assignments
  72. (define-key map (kbd "C-c C-k") 'rpl-compile-file)
  73. ;; Menu items
  74. (define-key map [menu-bar rpl-menu] (cons "RPL" menu-map))
  75. (define-key menu-map [rpl-menu-compile-file]
  76. '(menu-item "Compile File..." rpl-compile-file
  77. :enable rpl-menu-compile-file-enable))
  78. (define-key menu-map [rpl-menu-separator-1]
  79. '(menu-item "--"))
  80. (define-key menu-map [rpl-menu-apropos]
  81. '(menu-item "Apropos (at point)..." rpl-apropos-thing-at-point))
  82. map)
  83. "The RPL tools common keymap.")
  84. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  85. ;; Developer utils
  86. ;;
  87. (defvar rpl-debug nil)
  88. (defmacro rpl-debug-message (msg)
  89. (if rpl-debug
  90. `(message ,msg)
  91. nil))
  92. (defun rpl-force-reload ()
  93. (interactive)
  94. (load "rpl-base")
  95. (load "rpl-sysrpl-mode"))
  96. (provide 'rpl-base)