How to define an Emacs command that uses `replace-string` to replace a specific string [duplicate]

寵の児 提交于 2020-01-06 14:16:13

问题


I need to remove ascii character 0253 and add a carriage return in it's place. In emacs I do

M-x replace-string ý RET C-q C-j

C-q C-j adds a carriage return. I do this often enough that I creating a custom defun would be much better.

Here is what I have so far

(defun remove-253 ()
   "Removes ASCII Character 0253 and adds a carriage return in it's place"
   (interactive)
   (replace-string "ý" .... not sure what to do next )
)

Your thoughts?

Thanks,

Norm


回答1:


This worked for me:

(replace-string "ý" "\n")



回答2:


`repeat-complex-command' (C-x escape escape) should also help you in future problems like this. It shows you the Emacs Lisp form that represents your last complex operation, so you can paste the form directly into a defun and off you go.

In this case, you would see:

(replace-string "ý" "\n" nil (if (and transient-mark-mode mark-active) (region-beginning)) (if (and transient-mark-mode mark-active) (region-end)))




回答3:


Sounds like a job for keyboard macros. :-)



来源:https://stackoverflow.com/questions/7446913/how-to-define-an-emacs-command-that-uses-replace-string-to-replace-a-specific

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!