【问题标题】:How to use elisp to create a sqlite specific shell?如何使用 elisp 创建一个 sqlite 特定的 shell?
【发布时间】:2013-12-03 13:18:25
【问题描述】:

我正在尝试学习如何使用 elisp 来自定义我的开发环境。我已经包含以下函数来创建命令M-x ipython,它会打开一个 IPython shell:

(defun ipython ()
  (interactive)
  (ansi-term "/usr/bin/ipython" "ipython"))

我在一个项目中使用 sqlite,我想让在 emacs 中打开 sqlite 命令 shell 变得更容易。这与上面的示例类似,但需要注意的是我需要指定一个数据库文件。如果我将上面的内容修改如下:

(defun sqlite3 (filename)
  (interactive "FDB file name: \n")
  (ansi-term "/usr/bin/sqlite3" "sqlite3")) ;; Oops, what do I do with the file name?

我卡住了,因为 ansi-term 函数只接受两个参数,一个是要运行的程序,另一个是重命名 shell 的可选名称。

有没有一种简单的方法来创建一个函数,让我可以轻松地打开一个 sqlite shell 并有机会提供要传递给 sqlite 的文件参数?

【问题讨论】:

  • 由于您已经在使用 IPython,您可以将其用作带有 ipython-sql 的 SQL shell:pypi.python.org/pypi/ipython-sql
  • @jpkotta 知道ipython-sql 存在很有趣,但作为sqlite shell 的替代品似乎很尴尬。

标签: sqlite shell emacs elisp


【解决方案1】:

代码如下:

(defun sqlite3 (file)
  (interactive "fDB file name:\n")
  (term-send-string
   (ansi-term "bash" "sqlite3")
   (format "sqlite3 %s\n" file)))

【讨论】:

  • 这段代码没有做的一件事(我希望)是将缓冲区重命名为sqlite3。所以我编辑了你的答案。
猜你喜欢
  • 2012-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多