问题描述
我是新来的emacs,但震惊了我真正可以做的和多少时间节省(宏节省了大量的时间)。但是我想知道是否有可能创建基于步骤的脚本,在该脚本中要求用户输入并执行代码。例如,也许我想创建一个SQL查询,所以它会提示如下: >表名称?
myTable
>查询类型(select,insert,update,delete)
选择
>字段以获取
名称,id
>结果查询是来自myTable的select(name,id)
这只是一个想法的大纲但我很奇怪,因为像这样的东西是有用的。有人提到AWK脚本,但我不知道那是否是正确的树。我在Windows上,但我不认为这很重要。
我绝对赞赏任何这方面的信息,谢谢
请参阅emacswiki上的这个小黑客:。否则,您可以随时暂停一个宏,并在定义期间向您提供 Cx q
的点插入文本执行,请参阅。最后,您可以定义一个功能,并使用获取所需的参数,即:
(defun my-build-query(表类型字段)
(交互式sTable名称:\\\
sType查询:\\\
sFields获取:)
(来自%s的消息%s(%s)type fields table)
)
您可以将此函数放在〜/ .emacs
并执行它与 Mx:my-build-query
。
希望这给你一些指针开始!
PS:啊,还有一个想法。使用这个类似的东西可能更简单一些的方法(看看截图页面)。
I am new to emacs, but shocked at what I can really do and how much time it saves (Macros save A LOT of time). But I was wondering it was possible to create step based scripts where it asks the user for input and executes code based on that. For example maybe I want to create a SQL query so it would prompt something like:
>table name?
myTable
>type of query (select, insert, update, delete)
select
>fields to get
name, id
>Result query is "select (name, id) from myTable"
This is just an outline of an idea but I was wonder because something like this would be useful to have. Someone mentioned AWK scripts but I wasn't sure if that was the right tree to bark up or not. I am on Windows but I don't think that matters a whole lot.
I definitely appreciate any info on this, Thanks
see this little hack on emacswiki: Prompting During Keyboard Macro Execution. Otherwise you can always pause a macro and insert you text execution at the points where you give C-x q
during definition, see Executing Macros with Variations. Finally you can define a function and use interactive to get the required parameters, i.e.:
(defun my-build-query (table type field)
(interactive "sTable name: \nsType of query: \nsFields to get: ")
(message "%s (%s) from %s" type fields table)
)
You could put this function in your ~/.emacs
and execute it with M-x: my-build-query
.
Hope this gives you some pointers to get started!
P.S.: Ahh, and one more idea. The probably easier approach for this kind of stuff is to use YASnippet (have a look at the screencast on the page).
这篇关于Emacs:有没有办法使用Emacs创建交互式脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!