minad / cape

🦸cape.el - Completion At Point Extensions
GNU General Public License v3.0
608 stars 22 forks source link

Cape hangs Emacs #49

Closed velppa closed 2 years ago

velppa commented 2 years ago

Hi Daniel, thanks for Cape and other packages (especially Consult).

I use the following configuration of Cape with Emacs 28.1 on macOS with native compilation:

(use-package cape
  :init
  ;; Add `completion-at-point-functions', used by `completion-at-point'.
  (add-to-list 'completion-at-point-functions #'cape-file)
  ;;(add-to-list 'completion-at-point-functions #'cape-tex)
  (add-to-list 'completion-at-point-functions #'cape-dabbrev)
  (add-to-list 'completion-at-point-functions #'cape-keyword)
  ;;(add-to-list 'completion-at-point-functions #'cape-sgml)
  (add-to-list 'completion-at-point-functions #'cape-rfc1345)
  (add-to-list 'completion-at-point-functions #'cape-abbrev)
  ;;(add-to-list 'completion-at-point-functions #'cape-ispell)
  (add-to-list 'completion-at-point-functions #'cape-dict)
  (add-to-list 'completion-at-point-functions #'cape-symbol)
  (add-to-list 'completion-at-point-functions #'cape-line)
  :config
  (setq my-cape-keymap (make-sparse-keymap))
  (let ((map my-cape-keymap))
    (define-key map (kbd "p") 'completion-at-point)
    (define-key map (kbd "t") 'complete-tag)
    (define-key map (kbd "d") 'cape-dabbrev)
    (define-key map (kbd "f") 'cape-file)
    (define-key map (kbd "k") 'cape-keyword)
    (define-key map (kbd "s") 'cape-symbol)
    (define-key map (kbd "a") 'cape-abbrev)
    (define-key map (kbd "i") 'cape-ispell)
    (define-key map (kbd "l") 'cape-line)
    (define-key map (kbd "w") 'cape-dict)
    (define-key map (kbd "\\") 'cape-tex)
    (define-key map (kbd "_") 'cape-tex)
    (define-key map (kbd "^") 'cape-tex)
    (define-key map (kbd "&") 'cape-sgml)
    (define-key map (kbd "r") 'cape-rfc1345)
    t)
  :bind-keymap
  ("C-c t" . my-cape-keymap))

When I edit a Ledger-mode source block in Org Mode in the posting that has computations, and press TAB (mostly accidentally, like C-i), Emacs hangs. I figured out that it is Cape that causes it, after disabling the above block Emacs works fine (says "No completions").

Example of Org Mode document, where | marks the cursor position:

* Heading
#+begin_src ledger :tangle no
2022/01/01 test
    Expenses   (1 USD| * 0.5)
    Equity

#+end_src

Org Babel has ledger language enabled using ob-ledger.el.

I checked what TAB is bound to, org-cycle, then I checked what TAB is globally-bound to, indent-for-tab-command, checked variable completion-at-point-functions:

Its value is
(org-roam-complete-everywhere org-roam-complete-link-at-point pcomplete-completions-at-point t)
Local in buffer my_ledger.org; global value is 
(cape-line cape-symbol cape-dict cape-abbrev cape-rfc1345 cape-keyword cape-dabbrev cape-file tags-completion-at-point-function)

So I have no idea why Cape hangs Emacs ;-(

I tried to debug by killing Emacs with pkill -SIGUSR2 emacs, but it doesn't work on macOS.

Could you suggest how to narrow down the root cause of this?

minad commented 2 years ago

I recommend to disable all Cape completion-at-point-functions and then turn them on one by one until you find the issue. Also take a look at the recommended configuration from the README. It is better to not add to many functions by default - instead trigger them manually using the explicit key, since this makes sure that you get the desired completion backend.

(use-package cape
  :init
  ;; Add `completion-at-point-functions', used by `completion-at-point'.
  ;;(add-to-list 'completion-at-point-functions #'cape-file)
  ;;(add-to-list 'completion-at-point-functions #'cape-tex)
  ;;(add-to-list 'completion-at-point-functions #'cape-dabbrev)
  ;;(add-to-list 'completion-at-point-functions #'cape-keyword)
  ;;(add-to-list 'completion-at-point-functions #'cape-sgml)
  ;;(add-to-list 'completion-at-point-functions #'cape-rfc1345)
  ;;(add-to-list 'completion-at-point-functions #'cape-abbrev)
  ;;(add-to-list 'completion-at-point-functions #'cape-ispell)
  ;;(add-to-list 'completion-at-point-functions #'cape-dict)
  ;;(add-to-list 'completion-at-point-functions #'cape-symbol)
  ;;(add-to-list 'completion-at-point-functions #'cape-line)
  :config
  (setq my-cape-keymap (make-sparse-keymap))
  (let ((map my-cape-keymap))
    (define-key map (kbd "p") 'completion-at-point)
    (define-key map (kbd "t") 'complete-tag)
    (define-key map (kbd "d") 'cape-dabbrev)
    (define-key map (kbd "f") 'cape-file)
    (define-key map (kbd "k") 'cape-keyword)
    (define-key map (kbd "s") 'cape-symbol)
    (define-key map (kbd "a") 'cape-abbrev)
    (define-key map (kbd "i") 'cape-ispell)
    (define-key map (kbd "l") 'cape-line)
    (define-key map (kbd "w") 'cape-dict)
    (define-key map (kbd "\\") 'cape-tex)
    (define-key map (kbd "_") 'cape-tex)
    (define-key map (kbd "^") 'cape-tex)
    (define-key map (kbd "&") 'cape-sgml)
    (define-key map (kbd "r") 'cape-rfc1345)
    t)
  :bind-keymap
  ("C-c t" . my-cape-keymap))