我制作了一个小的 elisp 代码来处理环境模块(http://modules.sourceforge.net/),如下所示:
(defun Modules-module (command)
"foo"
(interactive (list (read-string "Module cmd: " nil nil)))
;; clear cmd buffer, log buffer is replaced below
(setq cmd-buffer (get-buffer-create "*modules-cmd*"))
(setq log-buffer (get-buffer-create "*modules-log*"))
(set-buffer cmd-buffer)
(delete-region (point-min) (point-max))
(set-buffer log-buffer)
(delete-region (point-min) (point-max))
;; (start-process "Module" cmd-buffer "/usr/bin/tclsh" "/usr/share/Modules/default/libexec/modulecmd.tcl" "lisp" command)
(make-process :name "Module" :buffer cmd-buffer :command (list "/usr/bin/tclsh" "/usr/share/Modules/default/libexec/modulecmd.tcl" "lisp" command) :stderr log-buffer)
(set-buffer cmd-buffer)
(beginning-of-buffer)
(delete-matching-lines "Process")
(set-buffer cmd-buffer)
(if (> (buffer-size) 0)
(eval-buffer)
)
)
结果已成功插入 cmd-buffer,但缓冲区在缓冲区末尾有消息“处理模块完成”,如下所示:
(setenv "LOADEDMODULES" "gcc/6.2.1")
(setenv "CXX" "g++")
(setenv "COMPILER_TYPE" "gcc")
(setenv "COMPILER_OF_TYPE" "Gcc")
(setenv "FC" "gfortran")
(setenv "COMPILER" "gnu")
(setenv "LOADEDMODULES_modshare" "gcc/6.2.1:1")
(setenv "FORTRAN_TYPE" "gfortran")
Process Module finished
由于“处理模块完成”,(eval-buffer)不起作用。
我添加了 (set-buffer cmd-buffer) (beginning-of-buffer) (delete-matching-lines "Process")
在 (eval-buffer) 语句之前但失败了。
我的想法是 1. 通过使用 (eval-region) 从缓冲区的开头到 Process 完成行之前的行。或 2. 删除 Process finished 行并使用 (eval-buffer)
任何建议都将不胜感激。