fix(corfu): improve detection of comments
Due to https://github.com/minad/cape/pull/109, we cannot rely on only faces to detect comments.
This commit is contained in:
parent
b96778497b
commit
d0127025a0
2 changed files with 18 additions and 9 deletions
|
@ -49,3 +49,18 @@
|
||||||
;; Without this corfu quits immediately.
|
;; Without this corfu quits immediately.
|
||||||
(setq this-command #'corfu-insert-separator)
|
(setq this-command #'corfu-insert-separator)
|
||||||
(call-interactively #'corfu-insert-separator))))
|
(call-interactively #'corfu-insert-separator))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +corfu-in-doc-or-comment-p (_sym)
|
||||||
|
"Return non-nil if point is in a docstring or comment."
|
||||||
|
(or (nth 4 (syntax-ppss))
|
||||||
|
(when-let ((faces '(font-lock-comment-face
|
||||||
|
font-lock-doc-face
|
||||||
|
tree-sitter-hl-face:doc
|
||||||
|
tree-sitter-hl-face:comment))
|
||||||
|
(fs (get-text-property (point) 'face)))
|
||||||
|
(if (listp fs)
|
||||||
|
(cl-loop for f in fs
|
||||||
|
if (memq f faces)
|
||||||
|
return t)
|
||||||
|
(memq fs faces)))))
|
||||||
|
|
|
@ -104,11 +104,8 @@
|
||||||
(add-hook! (prog-mode conf-mode)
|
(add-hook! (prog-mode conf-mode)
|
||||||
(defun +corfu-add-cape-emoji-h ()
|
(defun +corfu-add-cape-emoji-h ()
|
||||||
(add-hook 'completion-at-point-functions
|
(add-hook 'completion-at-point-functions
|
||||||
(cape-capf-inside-faces
|
(cape-capf-predicate (cape-capf-prefix-length #'cape-emoji 1)
|
||||||
(cape-capf-prefix-length #'cape-emoji 1)
|
#'+corfu-in-doc-or-comment-p)
|
||||||
;; Only call inside comments and docstrings.
|
|
||||||
'tree-sitter-hl-face:doc 'font-lock-doc-face
|
|
||||||
'font-lock-comment-face 'tree-sitter-hl-face:comment)
|
|
||||||
10 t)))
|
10 t)))
|
||||||
(add-hook! text-mode
|
(add-hook! text-mode
|
||||||
(defun +corfu-add-cape-emoji-text-h ()
|
(defun +corfu-add-cape-emoji-text-h ()
|
||||||
|
@ -119,10 +116,7 @@
|
||||||
(add-hook! (prog-mode conf-mode)
|
(add-hook! (prog-mode conf-mode)
|
||||||
(defun +corfu-add-cape-dict-h ()
|
(defun +corfu-add-cape-dict-h ()
|
||||||
(add-hook 'completion-at-point-functions
|
(add-hook 'completion-at-point-functions
|
||||||
(cape-capf-inside-faces
|
(cape-capf-predicate #'+corfu-in-doc-or-comment-p #'cape-dict)
|
||||||
;; Only call inside comments and docstrings.
|
|
||||||
#'cape-dict 'tree-sitter-hl-face:doc 'font-lock-doc-face
|
|
||||||
'font-lock-comment-face 'tree-sitter-hl-face:comment)
|
|
||||||
40 t)))
|
40 t)))
|
||||||
(add-hook! text-mode
|
(add-hook! text-mode
|
||||||
(defun +corfu-add-cape-dict-text-h ()
|
(defun +corfu-add-cape-dict-text-h ()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue