简体   繁体   English

用Ecicles搜索和替换Emacs

[英]Search and Replace in Emacs with Icicles

I've been using Emacs for a while now and am trying out Icicles. 我一直在使用Emacs一段时间,我正在尝试冰柱。 When I run the sequence of commands 当我运行命令序列时

Cc ` \\([az]*\\) 抄送 ` \\([az]*\\)

S-TAB

C-| C- | x\\1y

it transforms the scratch buffer from 它转换了临时缓冲区

;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.

to

;; Xy xy xy xy xy xy xy'xy xy xy xy, xy xy Xy xy.
;; Xy xy xy xy xy xy xy, xy xy xy xy XY-xy XY-xy,
;; xy xy xy xy xy xy xy'xy xy xy.

My understanding is that it should instead attach an 'x' to the start of each word and a 'y' to the end of each word. 我的理解是它应该在每个单词的开头加上'x',在每个单词的末尾加上'y'。 What am I doing wrong here? 我在这做错了什么? I have tried this with emacs -Q and gotten the same results. 我用emacs -Q尝试了这个并得到了相同的结果。 Also, icicle-search-replace-literally-flag is unchanged from its default value of nil . 此外, icicle-search-replace-literally-flag与其默认值nil保持不变。 What am I doing wrong? 我究竟做错了什么? Thanks! 谢谢!

Edit: Sorry, I omitted the group in the regexp in the original post; 编辑:对不起,我在原帖中的regexp中省略了该组; however, I did use it in the test and still get the same result. 但是,我确实在测试中使用它并仍然得到相同的结果。

I do not use icicles but the effect is reproducible with the ordinary query-replace-regexp . 我不使用冰柱,但使用普通的query-replace-regexp可以重现效果。

The problem is that you just do not define any group in your regular expression which you refer to in the replacement. 问题是您只是不在正则表达式中定义您在替换中引用的任何组。 Therefore the group reference \\1 in the replacement string is empty. 因此,替换字符串中的组引用\\1为空。

Furthermore, you should use [az]+ instead of [az]* since [az]* also matches the empty string what you probably do not want. 此外,您应该使用[az]+而不是[az]*因为[az]*也匹配您可能不想要的空字符串。

To put the stuff you want to refer to into a group wrap it by paranthesis \\(\\) . 将你想要引用的东西放入一个组中,用paranthesis \\(\\)包装它。 In your example the regular expression would look like \\([az]+\\) . 在您的示例中,正则表达式看起来像\\([az]+\\) With this regular expression you can directly use your replacement string. 使用此正则表达式,您可以直接使用替换字符串。

The alternative is to leave the regular expression as it is and refer to the whole match with \\& instead of \\1 in your replacement string. 另一种方法是保留正则表达式,并在替换字符串中用\\&而不是\\1引用整个匹配。

Be sure that your version of file icicles-cmd2.el is dated after 2013-12-10. 请确保您的文件版本icicles-cmd2.el在2013-12-10之后的日期。 I fixed a bug wrt \\N replacements on that date. 我在那个日期修复了一个错误的\\N替换。

Other suggestions: 其他建议:

  • Proceed slowly, rather than immediately jumping into complex replacements etc. Icicles search and replacement are different from what you might be used to or expect. 慢慢地进行,而不是立即跳入复杂的替换等。 冰柱搜索和替换与您可能习惯或期望的不同。

  • Check the current values of all of the user options that affect Icicles search and replacement . 检查影响Icicles 搜索和替换的所有用户选项的当前值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM