Emacs:有没有办法使用Emacs创建交互式脚本? [英] Emacs: Is there a way to create a interactive script using Emacs?

查看:144
本文介绍了Emacs:有没有办法使用Emacs创建交互式脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的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:啊,还有一个想法。使用 YASnippet 这个类似的东西可能更简单一些的方法(看看截图页面)。


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创建交互式脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆