citre无法生成正常的tags文件

初步使用emacs阅读源码,C++项目。

用citre+universal ctags

如果我在命令行下先生成好tags文件,citre的jump/peek功能都能正常工作的;

但是我用citre-update-this-tags-file却只能生成一个空的tags文件(只有几行元数据),如下图

不知道啥情况

补充: emacs版本:GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30, cairo version 1.15.10) of 2020-09-20

citre配置用的centaur的配置:

  (use-package citre                                                                                                                              
    :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))                                                                                        
                                                                                                                                                  
    (defun citre-jump+ ()                                                                                                                         
      "Jump to the definition of the symbol at point.                                                                                             
Fallback to `xref-find-definitions'."                                                                                                             
      (interactive)                                                                                                                               
      (condition-case _                                                                                                                           
          (citre-jump)                                                                                                                            
        (error (call-interactively #'xref-find-definitions))))                                                                                    
    :config                                                                                                                                       
    (with-no-warnings                                                                                                                             
      (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."                                                                                        
        (let ((lsp-result (pcase centaur-lsp                                                                                                      
                            ('lsp-mode                                                                                                            
                             (and (fboundp #'lsp-completion-at-point)                                                                             
                                  (lsp-completion-at-point)))                                                                                     
                            ('eglot                                                                                                               
                             (and (fboundp #'eglot-completion-at-point)                                                                           
                                  (eglot-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))))

请问您生成 tags 文件时具体的操作是什么?我感觉第一行这个地方有点怪:

--languages=[C,C++]

我用 Citre 生成 Emacs 源码的 tags 文件这里是长这样的:

--languages=EmacsLisp,C

如果尝试改成

--languages=[EmacsLisp,C]

就会出现和你一样的情况。

哎呀,多谢多谢,就是这个问题。

我这命令是按照他那引导指令生成的,这个中括号,我不知道要删掉,删掉就好拉

按引导也不该生成这样的吧,我不记得 Citre 哪个地方会在语言两边加中括号。

就update ctags文件的那个指令,应该把中括号删掉的

我说的这个

主要是我对ctags也不熟

1 个赞

知道了 :rofl: 本来我是想清楚地指示「这一整块都要删掉」才加了中括号。我想想有没有更好的写法吧。

我觉得比较直观的方法就是加个例子

–languages=Add,languages,here

这样呢?

感觉加个例子可以。

或者是不是这样:

–languages=C,C++ ;; list programming languages of your project, and separate them with comma