confi-emacs-actual/configs/init-ctags.el

70 lines
2.4 KiB
EmacsLisp

;;; init-ctags.el --- Configuracíón de TAGS -*- lexical-binding: t -*-
;; Author: kj <webmaster@outcontrol.net>
;; URL: https://git.kj2.me/kj/confi-emacs-actual
;;; Commentary:
;;; Code:
;; En esta sección está la configuración para ctags.
;; Quizá con la aparición de lsp sea menos necesaria,
;; pero dado a que sigue teniendo potencial para aportar
;; además de tener un rendimiento muy bueno es mejor
;; no dejarla de lado.
;; Ctags IDE on the True Editor
;; @see https://github.com/universal-ctags/citre#quick-start
(use-package citre
:defer t
:ensure t
:diminish
:bind (("C-x c ." . citre-jump)
("C-x c ," . citre-jump-back)
("C-x c p" . citre-peek)
("C-x c a" . citre-ace-peek)
("C-x c u" . citre-update-this-tags-file))
:init
(setq citre-auto-enable-citre-mode-modes '(prog-mode)
citre-default-create-tags-file-location 'global-cache
citre-prompt-language-for-ctags-command t)
:config
(with-no-warnings
;; Integrate with `lsp-mode' and `eglot'
(define-advice xref--create-fetcher (:around (fn &rest args) fallback)
(let ((fetcher (apply fn args))
(citre-fetcher
(let ((xref-backend-functions '(citre-xref-backend t)))
(ignore xref-backend-functions)
(apply fn args))))
(lambda ()
(or (with-demoted-errors "%s, fallback to citre"
(funcall fetcher))
(funcall citre-fetcher)))))
(defun lsp-citre-capf-function ()
"A capf backend that tries lsp first, then Citre."
(let ((lsp-result (if (fboundp #'eglot-completion-at-point)
(eglot-completion-at-point)
(when (fboundp #'lsp-completion-at-point)
(lsp-completion-at-point)))))
(if (and lsp-result
(try-completion
(buffer-substring (nth 0 lsp-result)
(nth 1 lsp-result))
(nth 2 lsp-result)))
lsp-result
(citre-completion-at-point))))
(defun enable-lsp-citre-capf-backend ()
"Enable the lsp + Citre capf backend in current buffer."
(add-hook 'completion-at-point-functions #'lsp-citre-capf-function nil t))
(add-hook 'citre-mode-hook #'enable-lsp-citre-capf-backend)
))
(provide 'init-ctags)
;;; init-ctags.el ends here