Browse Source

Added calculator selection menu items to SysRPL mode.

Paul Onions 10 years ago
parent
commit
23ee0ca3d3
3 changed files with 62 additions and 4 deletions
  1. 1 1
      rpl-base.el
  2. 15 2
      rpl-edb.el
  3. 46 1
      sysrpl-mode.el

+ 1 - 1
rpl-base.el

@@ -95,7 +95,7 @@ string (either relative or absolute)."
     (define-key menu-map [rpl-menu-compile-file]
       '(menu-item "Compile File..." rpl-compile-file
                   :enable rpl-menu-compile-file-enable))
-    (define-key menu-map [axiom-menu-separator-1]
+    (define-key menu-map [rpl-menu-separator-1]
       '(menu-item "--"))
     (define-key menu-map [rpl-menu-apropos]
       '(menu-item "Apropos (at point)..." rpl-apropos-thing-at-point))

+ 15 - 2
rpl-edb.el

@@ -40,7 +40,7 @@ As a side-effect set point to the start of the next line."
         (setq left-edge (match-end 0))))
     (mapcar (lambda (s)
               (if (string-match "\\([[:blank:]]*\\(\\\\\\)*[[:blank:]]*$\\)" s)
-                  (substring s left-edge (match-beginning 1))
+                  (substring s left-edge (max left-edge (match-beginning 1)))
                 (substring s left-edge)))
             lines)))
 
@@ -95,6 +95,13 @@ and a parameter string (to be further parsed later)."
       (setq str (substring str (match-end 1))))
     (reverse names)))
 
+(defun rpl-edb-parse-userrpl-param-str (str)
+  (let ((names nil))
+    (while (string-match "[[:blank:]]*\\([[:graph:]]+\\)" str)
+      (setq names (cons (match-string 1 str) names))
+      (setq str (substring str (match-end 1))))
+    (reverse names)))
+
 (defun rpl-edb-consume-keyword-line ()
   (let ((line (rpl-edb-get-line)))
     (cl-destructuring-bind (keyword param-str)
@@ -106,6 +113,9 @@ and a parameter string (to be further parsed later)."
             ((eql keyword :AKA)
              (let ((names (rpl-edb-parse-aka-param-str param-str)))
                (cons keyword names)))
+            ((eql keyword :UserRPL)
+             (let ((names (rpl-edb-parse-userrpl-param-str param-str)))
+               (cons keyword names)))
             (t
              (error "Illegal EDB keyword, %s" keyword))))))
 
@@ -158,6 +168,9 @@ flags for this calculator."
                (cond ((eql keyword :AKA)
                       (dolist (name params)
                         (push name entry-names)))
+                     ((eql keyword :UserRPL)
+                      (dolist (name params)
+                        (push name entry-names)))
                      (t
                       (push (cons keyword params) entry-calc-infos)))))
             (t
@@ -211,5 +224,5 @@ whose values are lists of the form:
   ""
   (interactive)
   (setq rpl-edb-entries (rpl-edb-parse-buffer))
-  (dolist (calculator '(:38G :39G :48G :49G)) ; TODO auto-find all calculator models
+  (dolist (calculator '(:38G :39G :48G :49G))
     (rpl-edb-make-calculator-data-file rpl-edb-entries calculator)))

+ 46 - 1
sysrpl-mode.el

@@ -17,6 +17,11 @@
 
 (require 'rpl-base)
 
+(defcustom rpl-sysrpl-default-calculator :HP48G
+  "Default calculator type for SysRPL mode."
+  :type '(radio :HP38G :HP39G :HP48G :HP49G)
+  :group 'rpl)
+
 (defface sysrpl-name '((t (:foreground "blue")))
   "Face used for displaying SysRPL names."
   :group 'rpl)
@@ -52,9 +57,49 @@
 (defvar sysrpl-font-lock-keywords
   (list (cons sysrpl-keywords-regexp 'sysrpl-keyword-face)))
 
+(defvar sysrpl-selected-calculator rpl-sysrpl-default-calculator
+  "Currently selected calculator model.")
+
+(defun sysrpl-select-hp38g ()
+  "Set the currently selected calculator model to be the 38G."
+  (interactive)
+  (setq sysrpl-selected-calculator :HP38G))
+
+(defun sysrpl-select-hp39g ()
+  "Set the currently selected calculator model to be the 39G."
+  (interactive)
+  (setq sysrpl-selected-calculator :HP39G))
+
+(defun sysrpl-select-hp48g ()
+  "Set the currently selected calculator model to be the 48G."
+  (interactive)
+  (setq sysrpl-selected-calculator :HP48G))
+
+(defun sysrpl-select-hp49g ()
+  "Set the currently selected calculator model to be the 49G."
+  (interactive)
+  (setq sysrpl-selected-calculator :HP49G))
+
 (defvar sysrpl-mode-map
-  (let ((map (make-sparse-keymap)))
+  (let ((map (make-sparse-keymap))
+        (menu-map (make-sparse-keymap)))
     (set-keymap-parent map rpl-common-keymap)
+    ;; Menu items
+    (define-key map [menu-bar rpl-menu] (cons "RPL" menu-map))
+    (define-key menu-map [sysrpl-menu-separator-1]
+      '(menu-item "--"))
+    (define-key menu-map [sysrpl-menu-select-hp49g]
+      '(menu-item "HP49G" sysrpl-select-hp49g
+                  :button (:radio . (eql :HP49G sysrpl-selected-calculator))))
+    (define-key menu-map [sysrpl-menu-select-hp48g]
+      '(menu-item "HP48G" sysrpl-select-hp48g
+                  :button (:radio . (eql :HP48G sysrpl-selected-calculator))))
+    (define-key menu-map [sysrpl-menu-select-hp39g]
+      '(menu-item "HP39G" sysrpl-select-hp39g
+                  :button (:radio . (eql :HP39G sysrpl-selected-calculator))))
+    (define-key menu-map [sysrpl-menu-select-hp38g]
+      '(menu-item "HP38G" sysrpl-select-hp38g
+                  :button (:radio . (eql :HP38G sysrpl-selected-calculator))))
     map)
   "The SysRPL mode local keymap.")