counsel-find-file 打开 .ts 文件 minibuffer 卡住,需要 C-g 重新打开一次

各位,我使用的 purcell-emacs.d 配置

emacs 25.3.1 Fedora 28

C-x C-f (counsel-find-file) 打开 .ts 文件时 minibuffer 会 hang 住,需要 C-g 关闭 minibuffer 重新使用 C-x C-f (counsel-find-file) 再次定位 .ts 文件才能正常打开。

使用 C-x C-f (counsel-find-file) 打开 .md.html 等文件时不会 hang 住。

不知道如何调试并定位问题:是 C-x C-f (counsel-find-file) 原因还是其他问题

感谢~

用内置命令打开一次试试

诊断:

  1. M-x profiler-start 选 cpu
  2. C-x C-f (counsel-find-file),hang 一段时间,然后 C-g
  3. M-x profiler-report 看哪一步消耗资源最多

@twlz0ne

M-x profiler-report 输出如下:

Function                                                  CPU samples    %
- command-execute                                               21743  92%
 - call-interactively                                           21743  92%
  - funcall-interactively                                       21743  92%
   - counsel-find-file                                          21556  91%
    - ivy-read                                                  21556  91%
     - apply                                                    21556  91%
      - ivy-historian--nadvice/ivy-read                         21556  91%
       - apply                                                  21556  91%
        - #<compiled 0x1b571d9>                                 21556  91%
         - ivy-call                                             21405  90%
          - counsel-find-file-action                            21405  90%
           - find-file                                          21405  90%
            - find-file-noselect                                21405  90%
             - find-file-noselect-1                             21404  90%
              - after-find-file                                 21404  90%
               - normal-mode                                    21404  90%
                - set-auto-mode                                 21402  90%
                 - set-auto-mode-0                              21402  90%
                  - typescript-mode                             21390  90%
                   - run-mode-hooks                             21081  89%
                    - apply                                     21081  89%
                     - run-hooks                                21081  89%
                      - add-node-modules-path                   20702  87%
                       - expand-file-name                        4824  20%
                        - tramp-completion-file-name-handler     4565  19%
                         - tramp-completion-run-real-handler     4023  17%
                            apply                                3961  16%
                       + file-name-directory                     1707   7%
                       + directory-file-name                     1685   7%
                      + paredit-everywhere-mode                    29   0%
                      + origami-mode                               24   0%
                      + symbol-overlay-mode                         2   0%
                      + rainbow-delimiters-mode                     2   0%
                   + byte-code                                    305   1%
                + fundamental-mode                                  1   0%
             + file-truename                                        1   0%
         + read-from-minibuffer                                   150   0%
         + ivy--reset-state                                         1   0%
   + counsel-M-x                                                  187   0%
+ ...                                                            1863   7%
+ redisplay_internal (C function)                                  24   0%
  global-whitespace-cleanup-mode-check-buffers                      1   0%
+ timer-event-handler                                               1   0%

到 github 上提交了一个 issue :

C-x C-f hang 住的截图:

Imgur

M-x toggle-debug-on-quit RET 输出: http://ix.io/1alV

Debugger entered--Lisp error: (quit)
  file-directory-p("/node_modules/.bin/")
  add-node-modules-path()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook typescript-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook typescript-mode-hook))
  run-mode-hooks(typescript-mode-hook)
  typescript-mode()
  set-auto-mode-0(typescript-mode nil)
  set-auto-mode()
  normal-mode(t)
  after-find-file(nil t)
  find-file-noselect-1(#<buffer app.module.ts> "/home/py/code/django/zerone/angular/zerone/src/app/app.module.ts" nil nil "/home/py/code/django/zerone/angular/zerone/src/app/app.module.ts" (1076405032 2050))
  find-file-noselect("/home/py/code/django/zerone/angular/zerone/src/app/app.module.ts" nil nil nil)
  find-file("/home/py/code/django/zerone/angular/zerone/src/app/app.module.ts")
  counsel-find-file-action("/home/py/code/django/zerone/angular/zerone/src/app/app.module.ts")
  ivy-call()
  #[642 "\306\307\"A@\306\310\"A@\306\311\"A@\306\312\"A@\306\313\"A@\306\314\"A@\306a\315\"A@\306\316\"A@\306	\317\"A@\306\n\320\"A@\306\321\"A@C\306\f\322\"A@\306
\323\"A@\306\324\"A@\306\325\"A@\211\203\222�\211@\326>\203z�\211AA\262\202g�\327>A@\203\211�\330\262\202g�\331\332@\"\210\202g�\210\333\334\335\336\"\335	\"\335\"#!\211\203\322�\337a!\203\274�\340\341\342BBBB\202\320�\204\311�\340\343BB\202\320�\333\334\"!\262a\210\335\n\"\211\203\n\330\211\211\203\211@\211\344\232\203\361�\211B\202\377�\211A\204\377�\211@@ DBA\266\202\202\336�\210\202\f\345\210\346 \205\f\335
\206\"\337!\205\"\"\347 ?\205:@\206:A\236\2069\336A\236A\203S\350B\"\211\203L\211A\202NC\262\202UC@D\351\352\353 \354 p\330\242Ee\330&&\355\f!\210\356\357\360\361\351
!\362\"\363$\216\364\330C\211\356\357\365\361\351aa\"\366\"\367$\240\210\356\357\370\361\351!\371\"\367$\216\372\373\242\"\210\206\313\374FGC\375 \203\337\330\202\352H\204\350\376\202\352HHI\203 JG\340U\203 \f\357HK>\204
\377\201Q�\201R�\fD\"\210\f\211\201S�J@I\266\201T�L\202H\201U�\f\357HK>\2049\377\201Q�\201R�\fD\"\210\f\363H\201V�M\"\330%\210L\201T�=\203\223N\203r\f\357HK>\204j\377\201Q�\201R�\fD\"\210\f\201S�H\202tO\211\201W�\232\204\222\201X�\201Y�P#\201Z�JA\"BL\210\210\f\357HK>\204\247\377\201Q�\201R�\fD\"\210\f\201S�H,\262)\266\202)\201[� \210\f\357HK>\204\314\377\201Q�\201R�\fD\"\210\f\201S�HG\357V\203\372\201\\�\357\340\201]�\f\357HK>\204\363\377\201Q�\201R�\fD\"\210\f\201S�H$\210*\266\204\207" [ivy--actions-list this-command ivy--sources-list ivy--extra-candidates ivy-last ivy--display-transformers-list plist-member :predicate :require-match :initial-input :history :preselect :def :keymap :update-fn :sort :action :unwind :re-builder :matcher :dynamic-collection :caller (:predicate :require-match :initial-input :history :preselect :def :keymap :update-fn :sort :action :unwind :re-builder :matcher :dynamic-collection :caller :allow-other-keys) :allow-other-keys nil error "Keyword argument %s not one of (:predicate :require-match :initial-input :history :preselect :def :keymap :update-fn :sort :action :unwind :re-builder :matcher :dynamic-collection :caller)" delete-dups append plist-get t functionp 1 "o" ("default") ("o" identity "default") (original-source) ((original-source)) active-minibuffer-window window-minibuffer-p assoc vector cl-struct-ivy-state selected-frame selected-window ivy--reset-state make-byte-code 0 "\304\305\306\"\210\307\310!\311!\203�\211 \210\210\300	\312H\n>\204\"�\313\314\315	D\"\210	\316H\240\203-�\300\242 \210\317=?\2056�\320 \207" vconcat ...] 48 ("/root/.emacs.d/elpa-25.3/ivy-20180513.1037/ivy.elc" . 75464)]("Find file: " read-file-name-internal :matcher counsel--find-file-matcher :initial-input nil :action counsel-find-file-action :preselect nil :require-match confirm-after-completion :history file-name-history :keymap (keymap (27 keymap (25 . counsel-yank-directory)) (C-backspace . counsel-up-directory) (67108991 . counsel-up-directory)) :caller counsel-find-file)
  apply(#[642 "\306\307\"A@\306\310\"A@\306\311\"A@\306\312\"A@\306\313\"A@\306\314\"A@\306a\315\"A@\306\316\"A@\306	\317\"A@\306\n\320\"A@\306\321\"A@C\306\f\322\"A@\306
\323\"A@\306\324\"A@\306\325\"A@\211\203\222�\211@\326>\203z�\211AA\262\202g�\327>A@\203\211�\330\262\202g�\331\332@\"\210\202g�\210\333\334\335\336\"\335	\"\335\"#!\211\203\322�\337a!\203\274�\340\341\342BBBB\202\320�\204\311�\340\343BB\202\320�\333\334\"!\262a\210\335\n\"\211\203\n\330\211\211\203\211@\211\344\232\203\361�\211B\202\377�\211A\204\377�\211@@ DBA\266\202\202\336�\210\202\f\345\210\346 \205\f\335
\206\"\337!\205\"\"\347 ?\205:@\206:A\236\2069\336A\236A\203S\350B\"\211\203L\211A\202NC\262\202UC@D\351\352\353 \354 p\330\242Ee\330&&\355\f!\210\356\357\360\361\351
!\362\"\363$\216\364\330C\211\356\357\365\361\351aa\"\366\"\367$\240\210\356\357\370\361\351!\371\"\367$\216\372\373\242\"\210\206\313\374FGC\375 \203\337\330\202\352H\204\350\376\202\352HHI\203 JG\340U\203 \f\357HK>\204
\377\201Q�\201R�\fD\"\210\f\211\201S�J@I\266\201T�L\202H\201U�\f\357HK>\2049\377\201Q�\201R�\fD\"\210\f\363H\201V�M\"\330%\210L\201T�=\203\223N\203r\f\357HK>\204j\377\201Q�\201R�\fD\"\210\f\201S�H\202tO\211\201W�\232\204\222\201X�\201Y�P#\201Z�JA\"BL\210\210\f\357HK>\204\247\377\201Q�\201R�\fD\"\210\f\201S�H,\262)\266\202)\201[� \210\f\357HK>\204\314\377\201Q�\201R�\fD\"\210\f\201S�HG\357V\203\372\201\\�\357\340\201]�\f\357HK>\204\363\377\201Q�\201R�\fD\"\210\f\201S�H$\210*\266\204\207" [ivy--actions-list this-command ivy--sources-list ivy--extra-candidates ivy-last ivy--display-transformers-list plist-member :predicate :require-match :initial-input :history :preselect :def :keymap :update-fn :sort :action :unwind :re-builder :matcher :dynamic-collection :caller (:predicate :require-match :initial-input :history :preselect :def :keymap :update-fn :sort :action :unwind :re-builder :matcher :dynamic-collection :caller :allow-other-keys) :allow-other-keys nil error "Keyword argument %s not one of (:predicate :require-match :initial-input :history :preselect :def :keymap :update-fn :sort :action :unwind :re-builder :matcher :dynamic-collection :caller)" delete-dups append plist-get t functionp 1 "o" ("default") ("o" identity "default") (original-source) ((original-source)) active-minibuffer-window window-minibuffer-p assoc vector cl-struct-ivy-state selected-frame selected-window ivy--reset-state make-byte-code 0 "\304\305\306\"\210\307\310!\311!\203�\211 \210\210\300	\312H\n>\204\"�\313\314\315	D\"\210	\316H\240\203-�\300\242 \210\317=?\2056�\320 \207" vconcat ...] 48 ("/root/.emacs.d/elpa-25.3/ivy-20180513.1037/ivy.elc" . 75464)] ("Find file: " read-file-name-internal :matcher counsel--find-file-matcher :initial-input nil :action counsel-find-file-action :preselect nil :require-match confirm-after-completion :history file-name-history :keymap (keymap (27 keymap (25 . counsel-yank-directory)) (C-backspace . counsel-up-directory) (67108991 . counsel-up-directory)) :caller counsel-find-file))
  ivy-historian--nadvice/ivy-read(#[642 "\306\307\"A@\306\310\"A@\306\311\"A@\306\312\"A@\306\313\"A@\306\314\"A@\306a\315\"A@\306\316\"A@\306	\317\"A@\306\n\320\"A@\306\321\"A@C\306\f\322\"A@\306
\323\"A@\306\324\"A@\306\325\"A@\211\203\222�\211@\326>\203z�\211AA\262\202g�\327>A@\203\211�\330\262\202g�\331\332@\"\210\202g�\210\333\334\335\336\"\335	\"\335\"#!\211\203\322�\337a!\203\274�\340\341\342BBBB\202\320�\204\311�\340\343BB\202\320�\333\334\"!\262a\210\335\n\"\211\203\n\330\211\211\203\211@\211\344\232\203\361�\211B\202\377�\211A\204\377�\211@@ DBA\266\202\202\336�\210\202\f\345\210\346 \205\f\335
\206\"\337!\205\"\"\347 ?\205:@\206:A\236\2069\336A\236A\203S\350B\"\211\203L\211A\202NC\262\202UC@D\351\352\353 \354 p\330\242Ee\330&&\355\f!\210\356\357\360\361\351
!\362\"\363$\216\364\330C\211\356\357\365\361\351aa\"\366\"\367$\240\210\356\357\370\361\351!\371\"\367$\216\372\373\242\"\210\206\313\374FGC\375 \203\337\330\202\352H\204\350\376\202\352HHI\203 JG\340U\203 \f\357HK>\204
\377\201Q�\201R�\fD\"\210\f\211\201S�J@I\266\201T�L\202H\201U�\f\357HK>\2049\377\201Q�\201R�\fD\"\210\f\363H\201V�M\"\330%\210L\201T�=\203\223N\203r\f\357HK>\204j\377\201Q�\201R�\fD\"\210\f\201S�H\202tO\211\201W�\232\204\222\201X�\201Y�P#\201Z�JA\"BL\210\210\f\357HK>\204\247\377\201Q�\201R�\fD\"\210\f\201S�H,\262)\266\202)\201[� \210\f\357HK>\204\314\377\201Q�\201R�\fD\"\210\f\201S�HG\357V\203\372\201\\�\357\340\201]�\f\357HK>\204\363\377\201Q�\201R�\fD\"\210\f\201S�H$\210*\266\204\207" [ivy--actions-list this-command ivy--sources-list ivy--extra-candidates ivy-last ivy--display-transformers-list plist-member :predicate :require-match :initial-input :history :preselect :def :keymap :update-fn :sort :action :unwind :re-builder :matcher :dynamic-collection :caller (:predicate :require-match :initial-input :history :preselect :def :keymap :update-fn :sort :action :unwind :re-builder :matcher :dynamic-collection :caller :allow-other-keys) :allow-other-keys nil error "Keyword argument %s not one of (:predicate :require-match :initial-input :history :preselect :def :keymap :update-fn :sort :action :unwind :re-builder :matcher :dynamic-collection :caller)" delete-dups append plist-get t functionp 1 "o" ("default") ("o" identity "default") (original-source) ((original-source)) active-minibuffer-window window-minibuffer-p assoc vector cl-struct-ivy-state selected-frame selected-window ivy--reset-state make-byte-code 0 "\304\305\306\"\210\307\310!\311!\203�\211 \210\210\300	\312H\n>\204\"�\313\314\315	D\"\210	\316H\240\203-�\300\242 \210\317=?\2056�\320 \207" vconcat ...] 48 ("/root/.emacs.d/elpa-25.3/ivy-20180513.1037/ivy.elc" . 75464)] "Find file: " read-file-name-internal :matcher counsel--find-file-matcher :initial-input nil :action counsel-find-file-action :preselect nil :require-match confirm-after-completion :history file-name-history :keymap (keymap (27 keymap (25 . counsel-yank-directory)) (C-backspace . counsel-up-directory) (67108991 . counsel-up-directory)) :caller counsel-find-file)
  apply(ivy-historian--nadvice/ivy-read #[642 "\306\307\"A@\306\310\"A@\306\311\"A@\306\312\"A@\306\313\"A@\306\314\"A@\306a\315\"A@\306\316\"A@\306	\317\"A@\306\n\320\"A@\306\321\"A@C\306\f\322\"A@\306
\323\"A@\306\324\"A@\306\325\"A@\211\203\222�\211@\326>\203z�\211AA\262\202g�\327>A@\203\211�\330\262\202g�\331\332@\"\210\202g�\210\333\334\335\336\"\335	\"\335\"#!\211\203\322�\337a!\203\274�\340\341\342BBBB\202\320�\204\311�\340\343BB\202\320�\333\334\"!\262a\210\335\n\"\211\203\n\330\211\211\203\211@\211\344\232\203\361�\211B\202\377�\211A\204\377�\211@@ DBA\266\202\202\336�\210\202\f\345\210\346 \205\f\335
\206\"\337!\205\"\"\347 ?\205:@\206:A\236\2069\336A\236A\203S\350B\"\211\203L\211A\202NC\262\202UC@D\351\352\353 \354 p\330\242Ee\330&&\355\f!\210\356\357\360\361\351
!\362\"\363$\216\364\330C\211\356\357\365\361\351aa\"\366\"\367$\240\210\356\357\370\361\351!\371\"\367$\216\372\373\242\"\210\206\313\374FGC\375 \203\337\330\202\352H\204\350\376\202\352HHI\203 JG\340U\203 \f\357HK>\204
\377\201Q�\201R�\fD\"\210\f\211\201S�J@I\266\201T�L\202H\201U�\f\357HK>\2049\377\201Q�\201R�\fD\"\210\f\363H\201V�M\"\330%\210L\201T�=\203\223N\203r\f\357HK>\204j\377\201Q�\201R�\fD\"\210\f\201S�H\202tO\211\201W�\232\204\222\201X�\201Y�P#\201Z�JA\"BL\210\210\f\357HK>\204\247\377\201Q�\201R�\fD\"\210\f\201S�H,\262)\266\202)\201[� \210\f\357HK>\204\314\377\201Q�\201R�\fD\"\210\f\201S�HG\357V\203\372\201\\�\357\340\201]�\f\357HK>\204\363\377\201Q�\201R�\fD\"\210\f\201S�H$\210*\266\204\207" [ivy--actions-list this-command ivy--sources-list ivy--extra-candidates ivy-last ivy--display-transformers-list plist-member :predicate :require-match :initial-input :history :preselect :def :keymap :update-fn :sort :action :unwind :re-builder :matcher :dynamic-collection :caller (:predicate :require-match :initial-input :history :preselect :def :keymap :update-fn :sort :action :unwind :re-builder :matcher :dynamic-collection :caller :allow-other-keys) :allow-other-keys nil error "Keyword argument %s not one of (:predicate :require-match :initial-input :history :preselect :def :keymap :update-fn :sort :action :unwind :re-builder :matcher :dynamic-collection :caller)" delete-dups append plist-get t functionp 1 "o" ("default") ("o" identity "default") (original-source) ((original-source)) active-minibuffer-window window-minibuffer-p assoc vector cl-struct-ivy-state selected-frame selected-window ivy--reset-state make-byte-code 0 "\304\305\306\"\210\307\310!\311!\203�\211 \210\210\300	\312H\n>\204\"�\313\314\315	D\"\210	\316H\240\203-�\300\242 \210\317=?\2056�\320 \207" vconcat ...] 48 ("/root/.emacs.d/elpa-25.3/ivy-20180513.1037/ivy.elc" . 75464)] ("Find file: " read-file-name-internal :matcher counsel--find-file-matcher :initial-input nil :action counsel-find-file-action :preselect nil :require-match confirm-after-completion :history file-name-history :keymap (keymap (27 keymap (25 . counsel-yank-directory)) (C-backspace . counsel-up-directory) (67108991 . counsel-up-directory)) :caller counsel-find-file))
  ivy-read("Find file: " read-file-name-internal :matcher counsel--find-file-matcher :initial-input nil :action counsel-find-file-action :preselect nil :require-match confirm-after-completion :history file-name-history :keymap (keymap (27 keymap (25 . counsel-yank-directory)) (C-backspace . counsel-up-directory) (67108991 . counsel-up-directory)) :caller counsel-find-file)
  counsel-find-file()
  funcall-interactively(counsel-find-file)
  call-interactively(counsel-find-file nil nil)
  command-execute(counsel-find-file)
1 个赞

内置 fine-file 没有这个问题。

我测试默认配置,手动安装 counselng2-mode 也没有出现 hang 住问题。