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

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

问题描述

在Emacs中,我正在处理一个文本文档,从unicode plaintext转换为LaTeX。



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

  Mx replace-string±RET \pm RET 
Mx替换字符串μRET \textmu

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



谢谢

解决方案

我一般喜欢编写自定义命令,这是第一个替换的代码: ($)

 (defun replace-plus-minus()
(interactive)
(replace-string± \\pmnil(point-min)(point-max)))

但是,你也可以使用键盘宏。查看 wiki docs



基本上你会做的: / p>

  Cx(Mx replace-string±RET \pm RET Cx)
pre>

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

  Mx name-last-kbd-macro 
Mx insert-kbd-macro


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  \textmu 

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

Thanks

解决方案

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)))

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

Basically, you'd do:

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

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天全站免登陆