History auto complete in gnuplot

匆匆过客 提交于 2020-01-02 05:45:22

问题


In gnuplot, I type

gnuplot> set style data lines

Then I run few other lines:

gnuplot> plot "./data/traj1.dat" u 1:4, "" u 1:6, "" u 1:9, "" u 1:11, "" u 1:13, "" u 1:15
gnuplot> plot "./data/traj2.dat" u 1:4, "" u 1:6, "" u 1:9, "" u 1:11, "" u 1:13, "" u 1:15
gnuplot> plot "./data/traj3.dat" u 1:4, "" u 1:6, "" u 1:9, "" u 1:11, "" u 1:13, "" u 1:15

Now I want to change style. I start with

gnuplot> set

I want to press for example ctrl-r (http://www.bigsmoke.us/readline/shortcuts) and have the command be completed to

gnuplot> set style data lines

then I can change lines to points for example.

How do I make this auto-completion happen?


回答1:


A partial solution is indeed to compile gnuplot with readline support. You mention that this is your last option in the comments, but I think that it is your only option if not you want to code a gnuplot frontend yourself. Maybe it helps to know that it is really easy to compile gnuplot from the ubuntu sources. I just did this myself in <10 min. Simply run (in a directory of your choice) the commands

sudo apt-get purge gnuplot
sudo apt-get build-dep gnuplot
cd `mktemp -d`
apt-get source gnuplot
cd gnuplot*
./configure --with-readline=gnu
make
sudo make install

Pressing the tab-key after writing the first few letters will complete the present word and if you press tab twice it will print a list of suggestions as you know it from your gnu-shell. Unfortunately not all readline features seem to work with the current gnuplot (I know they did once). E.g. Ctrl+r for reverse search (would be very useful for gnuplot) does not work for me. Hope this helps though admittedly this is possibly only a partial solution for you.




回答2:


You can use rlwrap to get this functionality (history search with CTRL+R, filename and keyword completion) without compiling anything. If you use Ubuntu, install it from universe repositories by running:

sudo apt-get install rlwrap

Run gnuplot with:

rlwrap -a -N -c -b \' -D 2 -s 1000 gnuplot

where -a -N overrides gnuplot built-in readline support, -c gives you filename completion, -b \' lets you complete stuff like plot 'incomp[TAB]lete', -D 2 drops duplicates from history and -s 1000 increases the history size from the default 300.

Or add this line to your start-up script (i.e., .bashrc, .zshrc), so you can use gnuplot without any additional typing:

alias gnuplot="rlwrap -a -N -c -b \' -D 2 -s 1000 gnuplot"

Also, it is possible to have keyword completion by listing all keywords in a file $RLWRAP_HOME/gnuplot_completions. However, context-sensitive completion is impossible using rlwrap.

You may want to export your gnuplot command history to rlwrap (so you don't have to start from scratch), like this:

tail -n +2 ~/.gnuplot_history | while read -r; do print $REPLY; done > $RLWRAP_HOME/gnuplot_history

tail gets rid of gnuplot's header and print converts escaped characters (I wonder why gnuplot's history is stored like this).



来源:https://stackoverflow.com/questions/16492560/history-auto-complete-in-gnuplot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!