Emacs:如何访问所有 sql 模式缓冲区并设置适当的 sql 缓冲区

发布于 2024-10-26 11:39:31 字数 360 浏览 2 评论 0原文

我在 emacs 中 sql 模式的典型用法是

:打开 foo.sql 文件并开始编辑

b.决定我想使用 sql-send-region c 的键绑定来运行它

。启动我的自定义(db-connect)函数来连接到适当的数据库并创建一个 *SQL* 缓冲区。

但是 foo.sql 不知道 *SQL* 缓冲区的存在,除非我在缓冲区中执行“mx sql-mode”以刷新其环境并检测此时存在这样的缓冲区。我想在自定义 db-connect 函数中嵌入一些代码,以使用 sql-mode 访问所有缓冲区并更新 sql-buffer 变量。我确信有几个堆栈溢出成员之前一定做过这个或类似的事情。

谢谢,

SetJmp

My typical usage of sql-mode in emacs is to:

a. open a foo.sql file and begin editing

b. decide I want to run it using the key bindings for sql-send-region

c. fire up my custom (db-connect) function to connect to an appropriate db and create a *SQL* buffer.

However the foo.sql doesn't know about the existence of the *SQL* buffer unless I perform a "m-x sql-mode" in the buffer in order to refresh its environment and detect that such a buffer exists at this point. I would like to embed some code in my custom db-connect function to visit all buffers using sql-mode and update the sql-buffer variable. I am sure several stack overflow members must have done this or something similar before.

Thanks,

SetJmp

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等待我真够勒 2024-11-02 11:39:31

快速查看 sql.el 文件会发现命令 sql-set-sqli-buffer-generally ,也许这适合您?

另一种处理方法是通过在主模式挂钩中调用 kill-local-variable 来终止 sql-buffer 的缓冲区本地变体。 (这样,效果是所有 SQL 缓冲区都会与最新的 SQL 缓冲区通信。)

免责声明:我对 SQL 或 SQL 模式一无所知,只了解 Emacs。

A quick look in the sql.el file revealed the command sql-set-sqli-buffer-generally, maybe this is something for you?

Another way you could hand this is to kill the buffer-local variant of sql-buffer by calling kill-local-variable in your major-mode hook. (That way, the effect would be that all SQL buffers would talk to the latest SQL buffer.)

Disclaimer: I don't know anything about SQL or SQL mode, only Emacs in general.

夏夜暖风 2024-11-02 11:39:31

我已经实现了这个小帮助函数来按主要模式过滤缓冲区。

(defun buffer-mode (buffer-or-name)
  (with-current-buffer buffer-or-name major-mode))


(defun filter-buffers-by-mode (mode)
  (delq nil
        (mapcar
         (lambda (x) (and (eq (buffer-mode x) mode) x))
         (buffer-list))))

您可以传递 'sql-mode 作为参数,您将获得所有打开的 sql 缓冲区的列表。

I've implemented this small helper function to filter buffers by their major-mode

(defun buffer-mode (buffer-or-name)
  (with-current-buffer buffer-or-name major-mode))


(defun filter-buffers-by-mode (mode)
  (delq nil
        (mapcar
         (lambda (x) (and (eq (buffer-mode x) mode) x))
         (buffer-list))))

You can pass 'sql-mode as the argument and you'll get a list of all open sql buffers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文