rpl-base.el 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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-buffer-enable nil)
  48. (make-variable-buffer-local 'rpl-menu-compile-buffer-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-buffer)
  55. (define-key map (kbd "C-c C-a") 'rpl-apropos-thing-at-point)
  56. ;; Menu items
  57. (define-key map [menu-bar rpl-menu] (cons "RPL" menu-map))
  58. (define-key menu-map [rpl-menu-compile-buffer]
  59. '(menu-item "Compile Buffer" rpl-compile-buffer
  60. :enable rpl-menu-compile-buffer-enable))
  61. (define-key menu-map [rpl-menu-separator-1]
  62. '(menu-item "--"))
  63. (define-key menu-map [rpl-menu-apropos]
  64. '(menu-item "Apropos..." rpl-apropos-thing-at-point))
  65. map)
  66. "The RPL tools common keymap.")
  67. (defun rpl-apropos-thing-at-point ()
  68. "Call the appropriate apropos command, depending on major mode."
  69. (interactive)
  70. (cond ((eql major-mode 'sysrpl-mode)
  71. (call-interactively 'sysrpl-apropos-thing-at-point))))
  72. (defun rpl-compile-buffer ()
  73. "Call the appropriate compile-buffer command, depending on major mode."
  74. (interactive)
  75. (cond ((eql major-mode 'sysrpl-mode)
  76. (call-interactively 'sysrpl-compile-buffer))
  77. ((eql major-mode 'sasm-mode)
  78. (call-interactively 'sasm-compile-buffer))))
  79. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  80. ;; Developer utils
  81. ;;
  82. (defvar rpl-debug nil)
  83. (defmacro rpl-debug-message (msg)
  84. (if rpl-debug
  85. `(message ,msg)
  86. nil))
  87. (defun rpl-force-reload ()
  88. (interactive)
  89. (load "rpl-base")
  90. (load "sysrpl-mode"))
  91. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  92. ;; End of file
  93. ;;
  94. (provide 'rpl-base)