Mac で GTAGS for Python & Emacs

自分用メモ

brew install global
cp /opt/homebrew/share/gtags/gtags.conf ~/.globalrc

.globalrcに対して、

common:\ :skip= ...

の最後に

mypy_cache/,ruff_cache/,*.pyc,venv/:

など、タグづけにあたりスキップしたいディレクトリや拡張子を追記

pythonファイルにタグ付けするためにPygmentsをインストールしておく

pip install Pygments

タグ付け

gtags --gtagslabel=pygments

gtags-modeのために以下を評価

https://github.com/Ergus/gtags-mode

(with-eval-after-load 'gtags-mode
  (setq gtags-mode-update-args "--gtagslabel=pygments")
  (defun gtags-mode--imenu-advice ()
    "Make imenu use Global."
    (when (and buffer-file-name (gtags-mode--local-plist default-directory))
      (gtags-mode--filter-find-symbol
       '("--file") (buffer-file-name)
       (lambda (name _code _file line)
         (list name line #'gtags-mode--imenu-goto-function))))))