【求助】key macro两次以后就失败了。

Last macro: C-s font-family RET C-a 2*C-k

这是我定义的一个宏,在文件t.css里,isearch 查找 font-family,光标到行首,删除本行。 执行几次总是报错:

[08:37:46] 
Keyboard macro defined
[08:37:51] (Type e to repeat macro)
[08:37:52] (Type e to repeat macro)
After 0 kbd macro iterations: funcall-interactively: Wrong type argument: number-or-marker-p, nil

下面是t.css:

.calibre {
    display: block;
    font-size: 1em;
    padding-left: 0;
    padding-right: 0;
    margin: 0 5pt
    }
.calibre1 {
    display: block
    }
.calibre2 {
    display: block;
    font-size: 2em;
    font-weight: bold;
    line-height: 1.2;
    margin: 0.67em 0
    }
.calibre3 {
    color: rgb(0, 0, 0);
    font-family: "PingFang SC";
    font-size: 0.70833em;
    font-weight: bold;
    line-height: 1.2
    }
.calibre4 {
    font-weight: bold;
    line-height: 1.2
    }
.calibre5 {
    font-size: 0.79412em;
    line-height: 1.2;
    vertical-align: super
    }
.calibre6 {
    display: block;
    margin: 1em 0
    }
.calibre7 {
    display: block;
    font-family: "FZKai-Z03";
    font-size: 1em;
    text-align: right
    }
.calibre8 {
    font-family: "PingFang SC";
    font-size: 1em
    }
.calibre9 {
    color: rgb(0, 0, 0);
    font-family: "FZFangSong-Z02";
    font-size: 1em
    }
.calibre10 {
    font-size: 0.75em;
    line-height: normal;
    vertical-align: super
    }
.calibre11 {
    color: rgb(0, 0, 0);
    display: block;
    font-family: "FZFangSong-Z02";
    font-size: 1em;
    text-align: center
    }
.calibre12 {
    font-family: "FZKai-Z03";
    font-size: 1em
    }
.calibre13 {
    display: block;
    text-align: right
    }
.calibre14 {
    height: auto;
    width: 9px
    }
.calibre15 {
    font-family: "Microsoft YaHei";
    font-size: 1em
    }
.calibre16 {
    color: rgb(0, 0, 0);
    font-family: "PingFang SC";
    font-size: 1em
    }
.calibre17 {
    color: rgb(0, 0, 0);
    font-family: "PingFang SC";
    font-size: 0.5em;
    font-weight: bold
    }
.calibre18 {
    font-weight: bold
    }
.calibre19 {
    display: block;
    text-align: center
    }
.calibre20 {
    height: auto;
    width: 900px
    }
.calibre21 {
    height: auto;
    width: 14px
    }
.calibre22 {
    font-family: "PingFang SC";
    font-size: 1em;
    font-weight: bold
    }
.calibre23 {
    display: block;
    font-family: "PingFang SC";
    font-size: 1em;
    text-align: center
    }
.calibre24 {
    color: rgb(0, 0, 0);
    font-family: "PingFang SC";
    font-size: 1.125em;
    font-weight: bold;
    line-height: 1.2
    }
.calibre25 {
    font-size: 0.88889em;
    line-height: normal;
    vertical-align: super
    }
.calibre26 {
    color: rgb(0, 0, 0);
    font-family: "PingFang SC";
    font-size: 0.5625em;
    line-height: 1.2
    }
.calibre27 {
    color: rgb(0, 0, 0);
    font-family: "PingFang SC";
    font-size: 0.5625em;
    font-weight: bold;
    line-height: 1.2
    }
.calibre28 {
    color: rgb(0, 0, 0);
    font-family: "PingFang SC";
    font-size: 1.125em;
    line-height: 1.2
    }
.calibre29 {
    height: auto;
    width: 795px
    }
.calibre30 {
    height: auto;
    width: 796px
    }

C-s 没找到

您这功能应当用regexp实现

M-x replace-regexp

.*font-family.* -> 空

多谢。 替换确实是个好方法。 如果宏操作里面有一步是isearch ( C-s ), C-u 10 C-x e这样多次宏操作就会弹出这个错误。咋解决呢?

复现不了这个错误,可能和其他设置有关?

找到原因了,两个:

  1. desktop冲突
  2. '(global-visual-line-mode 1) 冲突 去掉这两个配置了。 也很奇怪,这两行配置用了十几年了都没有问题。

我测试了一下,是和 visual-line-mode 有关。开启 visual-line-mode 后,运行 6*C-n 2*C-k 之类的宏就会报错。这应该是 emacs 的 bug

是不是M-x flush-lines就可以实现这个功能

这个功能很多方法都可以。 我是想找出宏失败的原因。