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

71 lines
2.4 KiB
EmacsLisp
Raw Normal View History

;;; base-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:
;; Ctags IDE on the True Editor
;; @see https://github.com/universal-ctags/citre#quick-start
(use-package citre
:defer t
:straight t
:diminish
:bind (("C-x c j" . citre-jump+)
("C-x c k" . 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
(require 'citre-config)
(setq citre-auto-enable-citre-mode-modes '(prog-mode))
:config
(with-no-warnings
2022-06-11 08:48:01 +02:00
(setq citre-readtags-program "/usr/bin/readtags"
citre-ctags-program "/usr/bin/ctags"
citre-default-create-tags-file-location 'global-cache
citre-use-project-root-when-creating-tags t
citre-prompt-language-for-ctags-command t)
(with-eval-after-load 'projectile
(setq citre-project-root-function #'projectile-project-root))
;; 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."
2022-11-19 03:56:34 +01:00
(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))
2022-06-11 08:48:01 +02:00
(add-hook 'citre-mode-hook #'enable-lsp-citre-capf-backend)
))
(provide 'base-ctags)
;;; base-ctags.el ends here