在c++-mode中,光标卡顿。

移动一次光标会卡顿一次,如果等这次卡完,下次碰到移动光标的事件,仍会卡顿。

CPU的Profile如下

- command-execute                                                1333  55%
 - call-interactively                                            1333  55%
  - funcall-interactively                                         653  27%
   - execute-extended-command                                     466  19%
    - execute-extended-command--shorter                           300  12%
     - completion-try-completion                                  300  12%
      - completion--nth-completion                                300  12%
       - completion--some                                         300  12%
        + #<compiled 0x1abe1a9>                                   300  12%
    - command-execute                                             103   4%
     - call-interactively                                         103   4%
      - funcall-interactively                                     103   4%
       + profiler-report                                          103   4%
    - sit-for                                                      63   2%
     + redisplay                                                   40   1%
       read-event                                                   6   0%
   + kill-buffer                                                   63   2%
   + delete-other-windows                                          49   2%
   + next-line                                                     45   1%
   + previous-line                                                 30   1%
  - byte-code                                                     614  25%
   - read-extended-command                                        614  25%
    - completing-read                                             614  25%
     - completing-read-default                                    614  25%
      - read-from-minibuffer                                      498  20%
       - command-execute                                          203   8%
        - call-interactively                                      203   8%
         - funcall-interactively                                  203   8%
          - minibuffer-complete                                   201   8%
           - completion-in-region                                 201   8%
            - completion--in-region                               201   8%
             + #<compiled 0x19ee851>                              201   8%
            self-insert-command                                     2   0%
       + linum-update-current                                      35   1%
       + fci-redraw-frame                                          30   1%
       + timer-event-handler                                       24   0%
       + redisplay_internal (C function)                           20   0%
  - completing-read-default                                        66   2%
   - read-from-minibuffer                                          40   1%
    + linum-update-current                                         10   0%
    + fci-redraw-frame                                              3   0%
      minibuffer-inactive-mode                                      1   0%
- ...                                                             606  25%
 - if                                                             483  20%
  - let                                                           483  20%
   - funcall                                                      483  20%
    + #<lambda 0x330422980>                                       478  19%
    + #<lambda 0x1353ce60>                                          5   0%
   Automatic GC                                                   123   5%
+ linum-update-current                                            345  14%
+ timer-event-handler                                              84   3%
+ redisplay_internal (C function)                                  35   1%
  blink-cursor-end                                                  5   0%
  lsp-ui-doc--make-request                                          3   0%

同时开启的次mode有

Enabled minor modes: Abbrev Auto-Compile-On-Save Auto-Composition
Auto-Compression Auto-Encryption Blink-Cursor Company Diff-Auto-Refine Eldoc Fci
File-Name-Shadow Flycheck Font-Lock Global-Company Global-Eldoc Global-Flycheck
Global-Font-Lock Line-Number Linum Lsp Lsp-Ui Lsp-Ui-Doc Menu-Bar Mouse-Wheel
Show-Smartparens Show-Smartparens-Global Smart-Tabs Smartparens
Smartparens-Global Tool-Bar Tooltip Transient-Mark Yas

等一下再试吧,这个要用一段时间后才有,为了写代码不卡,我刚才关了emacs,还有,我发现

这个描述错了,当时应该没卡,那只是光标闪烁的时间间隔有那么长,所以这个profile可能没反应卡的时候的真实情况,等我下次卡了再记录一次(代码写到后面确实会隔一阵卡一下,之前以为是flycheck,但把flycheck调整为save时再检查后也卡了)。

更新:还是观察到了移动光标会卡的情况。

不过不用关,有个linum-delaylinum-eager,分别设置一下就好。。。

卡还有一个原因,我之前从网上抄了动态更新linum-format的配置,那个配置每回都要读取整个文件,所以卡。

我现在改成了参数比之前计算的总行数还大时才又重新计算。

emacs26 原生行号保平安啊

26的原生行号估计是用的当前行号的宽度,而不是整个文件的长度,当然快,不过我不喜欢这么变过去变过来的。

其二是配置项比较少,我用advice-add企图获取宽度,没成功(我的锅)。

最后,行号的左右两列间隔和linum-mode反着的,不喜欢。。。

目前这样可以接受了,继续linum-mode。对了,我除了在遇到行号超过总行数再重新计算之外,还在这一次的行号比上一次小10倍时也重新计算,这样大量删除后也更新。

这种情况虽然行号较小时或向后跳转较大时更新会频繁一点,不过在这两个情况下,频繁一点可以接受,前者本来不花多少时间就能重新计算,后者本来就比较花时间。

26 原生行号如果你不想让它宽度变来变去,加上

(setq display-line-numbers-grow-only t)

就行了

我抱怨的不止这一点啊,而且这只是不收缩吧,和不变来变去有区别的。

灵活性肯定是不够,只能算勉强够用