返回顶部
e

emacs-controlEmacs控制

Control Emacs. Search, edit, navigate, and pair programming with user

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 0.1.0
安全检测
已通过
90
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

emacs-control

Emacs 控制技能

使用 emacsctl 与正在运行的 Emacs 交互。

命令行用法

emacsctl [选项]... [参数]...

选项:
-i, --insert 执行插入操作
-r, --replace 执行替换操作
-b, --buffer BUFFER 指定插入或替换的缓冲区,默认为当前缓冲区
-s, --save 在插入或替换后保存缓冲区
-p, --position INSERT_POSITION
-l, --line INSERT_LINE
-c, --column INSERT_COLUMN
--start-position REPLACESTARTPOSITION
--end-position REPLACEENDPOSITION
--start-line REPLACESTARTLINE
--end-line REPLACEENDLINE
-h, --help

emacsctl 需要在代理端和 Emacs 端都进行配置。请查看 https://github.com/calsys456/emacsctl 了解正确的设置方法,并在 emacsctl 未找到或返回连接失败时尽可能通知用户

求值

基本上,emacsctl 从第一个参数或 stdin 获取一个 S-表达式字符串,然后在 Emacs 内部使用 progn 进行 read 和 eval,并打印最后一个表达式的返回值。

bash
emacsctl (emacs-version)

使用管道


echo (emacs-version) | emacsctl

=> GNU Emacs XX.X.XX

使用 HEREDOC 进行多行输入或包含引号的输入

注意 HEREDOC 末尾有换行符

emacsctl <=> return-to-me

注意交互式或阻塞函数(如 read-string、y-or-n-p)会导致挂起。

当发生错误时,建议用户撤销或回退。只有在没有重要内容或你有信心处理时,才自行撤销(例如 emacsctl (undo))。

求值时请务必小心

插入

当指定 -i 时,emacsctl 将使用给定的字符串、文件或 stdin 执行插入操作:

bash

在缓冲区 emacsctl.el 的第 50 行第 15 列插入 Hello


emacsctl -i -b emacsctl.el -l 50 -c 15 -p 100 Hello

在当前缓冲区的第 100 个位置插入你的代码

emacsctl -i -p 100 < EOF

将 ~/gpl-3.0.txt 的内容插入到当前缓冲区的当前位置,并保存缓冲区

emacsctl -i -s ~/gpl-3.0.txt

替换

当指定 -r 时,emacsctl 可以以两种方式执行缓冲区内容替换:替换范围或替换特定文本。

替换范围

指定 --start-position 和 --end-position,或 --start-line 和 --end-line 来替换一个范围:

bash

将缓冲区 emacsctl.el 的前 5 个字符替换为 XXXXX


emacsctl -r -b emacsctl.el --start-position 1 --end-position 5 XXXXX

将当前缓冲区的第 50-100 行替换为你的代码,并保存缓冲区

emacsctl -r --start-line 50 --end-line 100 -s < EOF

替换特定文本

提供两个字符串或文件,将第一个(旧文本)替换为第二个(新文本):

bash

将缓冲区 emacsctl.el 中最近的 (require function) 形式替换为 ~/function.el 的内容


emacsctl -r -b emacsctl.el (require function) ~/function.el

将当前缓冲区中的 to-be-refined 函数替换为 refined 函数

emacsctl -r <(cat <如果旧文本出现多次,只会替换距离当前点最近的那一处。对于批量替换或基于正则表达式的替换,请编写 ELisp 代码。

接口

以下是一些专门为代理使用设计的 ELisp 函数,以 emacsctl- 开头,并返回信息丰富的 Lisp plist。尽可能使用 Eval 调用它们。

点和标记

使用 (emacsctl-point-info &optional (surrounding 2)) 和 (emacsctl-mark-info &optional (surrounding 2)) 获取点和标记的信息及周围内容。

当前点用 █ 标记,当前标记用 ▄ 标记。

缓冲区

使用 (emacsctl-buffer-info &optional (buffer (current-buffer))) 获取缓冲区状态和元数据。

使用 (emacsctl-buffer-imenu &optional (buffer (current-buffer))) 获取缓冲区概览。

使用 (emacsctl-buffer-list &optional match) 模糊匹配普通缓冲区。类似地,使用 (emacsctl-hidden-buffer-list &optional match) 获取隐藏缓冲区。

搜索缓冲区

使用 (emacsctl-grep pattern &optional (buffer (current-buffer))) 搜索缓冲区内容。它将返回匹配结果及周围内容。

使用 Emacs 特定的正则表达式。如果遇到困难,尝试使用 rx 或 regexp-* 函数构建正则表达式。

读取缓冲区

函数:
(emacsctl-read-buffer &key (buffer (current-buffer))
line (start-line line) (end-line line)
position (start-position (or position (point-min))) (end-position (or position (point-max)))
(surrounding 2)
full-p)

示例:

elisp
;; 读取一个区域
(emacsctl-read-buffer :start-position <点编号> :end-position <点编号>)
;; 读取行
(emacsctl-read-buffer :start-line <行号> :end-line <行号>)
;; 获取行周围的区域
(emacsctl-read-buffer :line <行号> :surrounding 20)
;; 获取缓冲区的完整内容(谨慎使用)
(emacsctl-read-buffer :buffer <缓冲区> :full-p t)

窗口

使用 (emacsctl-query-window) 查看当前框架的窗口布局。使用 (emacsctl-select-window <索引>) 根据查询返回的索引切换到某个窗口。

剪贴环(粘贴板)

使用 (emacsctl-query-kill-ring) 简要查看剪贴环。编写 ELisp 代码进行详细搜索。

环境查询

搜索符号使用 (emacsctl-search-symbol <模式>);搜索命令使用 (emacsctl-search-command <模式>);搜索函数使用 (emacsctl-search-function <模式>);搜索变量使用 (emacsctl-search-variable <模式>)。它们将返回有用的信息。

模式会按破折号拆分并进行子字符串匹配。精确查询将获得更详细的结果。

提示

emacs 控制技能并非用于替代其他工具调用。Emacs 是为有身体的人类设计的,而不是为你。使用其他基于文件的工具进行高效工作,仅在确实需要或用户要求时才使用 emacsctl。

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 emacs-control-1776012542 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 emacs-control-1776012542 技能

通过命令行安装

skillhub install emacs-control-1776012542

下载

⬇ 下载 emacs-control v0.1.0(免费)

文件大小: 3.05 KB | 发布时间: 2026-4-13 10:09

v0.1.0 最新 2026-4-13 10:09
Initial release of emacs-control skill.

- Enables programmatic control of a running Emacs instance via the `emacsctl` command-line utility.
- Supports insertion and replacement of text, buffer navigation, saving, and buffer selection.
- Provides CLI options for precise positioning, line/column selection, and range replacements.
- Documents special Emacs Lisp helper functions for interacting with point, mark, buffer info, windows, kill-ring, and environment inquiries.
- Warns users to use this skill judiciously, preferring file-based tools unless Emacs interaction is specifically needed or requested.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部