0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

レンタルサーバにGNU GLOBALを入れてEmacs + trampでコードリーディングする

Last updated at Posted at 2025-01-04

レンタルサーバでもコードリーディングしたい

実験場として借りているレンタルサーバでコードリーディングしたいと思いまして、以下、やってみました。

今回のレンタルサーバはエックスサーバさんです。

GNU GLOBALのインストール

レンタルサーバなので、借りているホームディレクトリにインストールします。

https://ftp.gnu.org/pub/gnu/global/ を確認して、新しいバージョンがあったら、それをwgetします。
~/binで作業します(なかったら作る)。
--disable-gtagscscopeとして、configureしないと、エラーが出てmakeできませんでした。

wget https://ftp.gnu.org/pub/gnu/global/global-6.6.14.tar.gz
tar zxf global-6.6.14.tar.gz
cd global-6.6.14
./configure --prefix=${HOME} --disable-gtagscscope
make
make install

確認

gtags --version

でバージョンが出たら成功です。

作業ディレクトリに行って、

gtags

で走査をして、以下のファイルができることを確認します。

GPATH
GRTAGS
GTAGS

globalの場所を確認

Emacsで使うので、~/bin/globalに実行ファイルがあることを確認します。

コマンドラインで使うなら、.bashrcで、export PATH=$HOME/bin:$PATHもしておくと便利だと思います。

作業ディレクトリで

global 関数/クラス名

でファイルが返ってくることを確認できたら、インストール成功です。

Emacsで使う場合

デフォルトのgtagsはtrampでうまくいかないという記事がいくらか見つかるのですが、ぼくの場合はデフォルトのgtagsでtrampでもうまく行きました(Emacsのバージョンは29.4)。

(require 'gtags)
(with-eval-after-load 'gtags
  (setq gtags-global-command "/home/YOURDIRNAME/bin/global")
  (setq gtags-auto-update t)
  (define-key gtags-mode-map (kbd "M-.") 'gtags-find-tag)
  (define-key gtags-mode-map (kbd "M-,") 'gtags-pop-stack))

カレントバッファのメソッド一覧を見る

コードリーディングにとっても便利な GNU GLOBAL と gtags.el (と anything-gtags.el) をつかおう」を拝読し、なるほど、gtags-parse-fileでカレントバッファを見られると便利と教えてもらいました。

でも、残念ながら記事内で示されているelispではうまくいかなかったので、以下のとおりにしています。

(defun gtags-parse-current-file ()
  "Show the list of tags in the current buffer's file."
  (interactive)
  (if (buffer-file-name)
      (let ((current-file (buffer-file-name)))
        (if (file-regular-p current-file)
            (let ((tagname (expand-file-name current-file)))
              (gtags-push-context)
              (gtags-goto-tag tagname "f"))
          (message "Current file is not a regular file.")))
    (message "Current buffer is not visiting a file.")))

キーバインドもこんな感じに変更。

(with-eval-after-load 'gtags
  (setq gtags-global-command "/home/YOURDIRNAME/bin/global")
  (setq gtags-auto-update t)
  (define-key gtags-mode-map (kbd "M-.") 'gtags-find-tag)
  (define-key gtags-mode-map (kbd "M->") 'gtags-find-rtag) ; M-shift-.
  (define-key gtags-mode-map (kbd "M-s-.") 'gtags-parse-current-file) ; M-super-.
  (define-key gtags-mode-map (kbd "M-,") 'gtags-pop-stack))
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?