minad / cape

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

Cape wrapper for docstrings #96

Closed LemonBreezes closed 8 months ago

LemonBreezes commented 8 months ago

Hi. It would be nice if we had a cape wrapper for when the point is inside a docstring. Maybe with tree-sitter-hl-face:doc and font-lock-dock-face. Then we could write emojis in docs!

LemonBreezes commented 8 months ago

Actually, I just realized I can use cape-capf-predicate.

LemonBreezes commented 8 months ago

Oh wait, it's more performant to make a real wrapper. XD

LemonBreezes commented 8 months ago
  (defun doom-point-in-docstring-or-comment-p ()
    "Check if the point is in a docstring or comment."
    (let ((faces (get-text-property (point) 'face)))
      (pcase faces
        ((or 'tree-sitter-hl-face:doc 'font-lock-doc-face) t)
        ((pred listp) (or (memq 'tree-sitter-hl-face:doc faces)
                          (memq 'font-lock-doc-face faces)))
        (_ (doom-point-in-comment-p)))))

  (defun cape-wrap-inside-docstring-or-comment (capf)
    (and (doom-point-in-docstring-or-comment-p) (funcall capf)))
minad commented 8 months ago

I think a more general cape-capf-inside-faces would be nice to have. It could take a list of faces as rest argument.