如何使用emacs在长gnuplot命令中允许注释?

如何使用emacs在长gnuplot命令中允许注释?,emacs,elisp,gnuplot,interactive,Emacs,Elisp,Gnuplot,Interactive,我最近经常使用Gnuplot,经常遇到 以下挫折:无法注释出零件 对于多行打印命令,如果执行此操作,将获得一个函数 应打印错误。下面是一个例子*: plot \ "datafile1.dat" u 1:2 w lp,\ # "datafile2.dat" u 1:2 w lp,\ <---- ERROR! cannot comment here "datafile3.dat" u 1:2 w lp,\ "dummy" u 1:2 我想可以编写一个函

我最近经常使用Gnuplot,经常遇到 以下挫折:无法注释出零件 对于多行打印命令,如果执行此操作,将获得一个
函数
应打印错误
。下面是一个例子*:

plot \
     "datafile1.dat" u 1:2 w lp,\
     # "datafile2.dat" u 1:2 w lp,\ <---- ERROR! cannot comment here
     "datafile3.dat" u 1:2 w lp,\
     "dummy" u 1:2
我想可以编写一个函数,将脚本复制到 临时缓冲区,但删除注释行(或可能只是注释 然后在此基础上调用
gnuplot run buffer
临时缓冲区。我的elisp不太好,所以我需要一段时间才能恢复 弄清楚如何很好地实现这一点,我认为这会很有用 尽管如此,我还是发布了这个问题

*最后一行在那里,所以我不必删除尾随 最后一行的反斜杠。
dummy
文件不存在,因此
只是被忽略而没有打印。

以下建议删除注释行。如果注释掉最后一条打印线,则不考虑多余的逗号。但是,你写道你不介意

(defadvice gnuplot-send-string-to-gnuplot (before ignore-comments activate)
  "Ignore lines starting with #."
  (setq string (with-temp-buffer
         (insert string)
         (goto-char (point-min))
         (delete-matching-lines "^[[:blank:]]*#")
         (buffer-string))))

您还可以使用多个
replot
命令,而不是使用多行
plot
plot x;回复x**2;replot x**3
。您可以通过添加
lw 0
进行欺骗,但这仍然不是一个好的解决方案。我从未找到令人满意的解决方案。@Christoph谢谢,这对于使用默认终端进行快速工作非常有用,不幸的是,当我使用pdfcairo终端进行最终打印时,每个replot命令实际上会在输出中引入一个新页面,因为使用工具
pdftk
可以很容易地纠正输出,所以这并不是很不方便。例如,要获取最后一个图形(完成所有
replot
命令并显示在同一个图形上的图形),可以执行以下操作:
pdftk multipage.pdf cat end output singlepage.pdf
(defadvice gnuplot-send-string-to-gnuplot (before ignore-comments activate)
  "Ignore lines starting with #."
  (setq string (with-temp-buffer
         (insert string)
         (goto-char (point-min))
         (delete-matching-lines "^[[:blank:]]*#")
         (buffer-string))))