rpl-base.el 3.1 KB

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