如何定义对特定字符串使用`replace-string`的Emacs命令 [英] How to define an Emacs command that uses `replace-string` for a specific string

查看:18
本文介绍了如何定义对特定字符串使用`replace-string`的Emacs命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Emacs 中,我正在处理一个文本文档,将 unicode 纯文本转换为 LaTeX.

In Emacs, I am processing a text document, converting from unicode plaintext to LaTeX.

我想运行几组正则表达式,例如

There are a few sets of regular expressions that I want to run, for example

M-x replace-string ± RET pm RET
M-x replace-string µ RET  	extmu 

如何保存这些正则表达式以便我可以重复运行它们?

How do I save these regular expressions so that I can run them repeatedly?

谢谢

推荐答案

我通常喜欢编写自定义命令,这是您第一次替换的命令:

I generally like writing custom commands, here's the one for your first replacement:

(defun replace-plus-minus ()
  (interactive)
  (replace-string "±" "\pm" nil (point-min) (point-max)))

但是,您也可以使用键盘宏.查看 wiki文档.

But, you can also use keyboard macros. Check out the wiki and docs.

基本上,你会这样做:

C-x ( M-x replace-string ± RET pm RET C-x )

然后你可以给它命名,并将它保存到你的 .emacs 中:

Then you can name it, and save it to your .emacs:

M-x name-last-kbd-macro
M-x insert-kbd-macro

这篇关于如何定义对特定字符串使用`replace-string`的Emacs命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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