保存Calc跟踪以供以后使用


12

是否可以保存Emacs Calculator Trail(作为文件)并在以后还原?如果没有,应该具有功能吗?

例如,当我有一个不完整的计算但必须关闭我的Emacs时,如果以后我可以继续下去,那就太好了。

第二种情况:我进行了一些计算,并且想要存储我的操作方式,以便稍后检查我是否正确执行或需要对其进行修改。

第二个原因是为什么我很少使用MATLAB(我知道太多),只是为了恢复它们。但是我只想使用Emacs Calc!

感谢您的回答


1
也许嵌入式模式是您想要的?
npostavs

我知道Calc与键盘宏很好地集成在一起,甚至扩展了它们。我不明白为什么您不能将它们保存为常规kmacros。您还尝试过GNU Octave吗?它应该主要与Matlab兼容,并带有emacs模式。
凯文·霍尔姆斯

1
我相信,针对calc的Org的src块(除嵌入式模式外)将是必经之路,尤其是对于第二种情况。不幸的是,src块代码还不够复杂,不能满足基本需求。请看一下:home.fnal.gov/~neilsen/notebook/orgExamples/…– Dieter.Wilhelm
2015年

@estownya-请发布一些示例calc代码,并附上calc返回的答案。
Melioratus

好吧,Calc Trail是一个像其他缓冲区一样的缓冲区。您可以切换到它并C-x C-w写出来。我认为要重新加载时,没有任何简单的方法可以重建所有Calc状态。
MAP

Answers:


0

由于calc跟踪的处理是基于文本的,因此基本上可以使用write-regioninsert-file-contents

但是,必须考虑一些细节。以下Elisp代码使您可以使用来将当前calc-trail缓冲区写入磁盘,C-x C-s并可以使用来在当前光标位置读回这些内容C-x i

之后,您可以使用calc-trail-mode绑定来评估部分读入calc命令。

(defvar-local calc-trail-buffer-file-name nil
  "Like `buffer-file-name' for calc-trail buffers.")

(defun calc-trail-save (&optional filename)
  "Save current calc trail buffer.
To be used in `write-contents-functions'.
Append with current prefix arg."
  (interactive "FCalc Trail File: ")
  (unless filename
    (setq calc-trail-buffer-file-name
      (expand-file-name (setq filename
                  (read-file-name "Calc Trail File: " nil calc-trail-buffer-file-name)))))
    (when (null (derived-mode-p 'calc-trail-mode))
    (user-error "Saving calc trail buffers requires calc-trail-mode"))
  (save-point
   (save-restriction
     (widen)
     (let* ((b-trail (progn (goto-char 1) (1+ (line-end-position))))
        (b (progn (goto-char (max (or (and (use-region-p) (region-beginning)) (point-min)) b-trail))
              (line-beginning-position)))
        (e (progn (goto-char (max (or (and (use-region-p) (region-end)) (point-max)) b-trail))
              (line-end-position))))
       (write-region b e filename current-prefix-arg)))))

(defun calc-insert-file (filename)
  "Insert calc-trail file FILENAME at point."
  (interactive "FCalc trail file: ")
  (when (= (line-beginning-position) 1)
    (goto-char (1+ (line-end-position))))
  (goto-char (line-beginning-position
          (if (looking-at "[[:space:]]*$")
          2
        1)))
  (let ((inhibit-read-only t))
    (insert-file-contents filename)
    (when (and (null (looking-at "[[:space:]]*$"))
           (null (looking-back "^[[:space:]]*" (line-beginning-position))))
      (insert "\n"))))

(defun calc-trail-install-save ()
  "Install `calc-trail-save' in `write-contents-functions' of `calc-trail-mode' buffers."
  (push #'calc-trail-save write-contents-functions)
  (local-set-key (kbd "C-x i") #'calc-insert-file))

(add-hook 'calc-trail-mode-hook #'calc-trail-install-save)

-1

您可以使用s p表示(calc-permanent-variable &optional VAR)将所有变量保存到~/.emacs.d/calc.elcalc-settings-file


2
但这只会保存当前值,而不是保存计算历史记录。
Andrew Swann
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.