0

TAGS ファイルを読み込もうとすると、何らかの理由で Emacs が有効なタグ ファイルではないと言い続けます。create コマンドは次のようにシンプルです。

$ ctags -e command-not-found.c

また、かなり正常に見えます。

^L
command-not-found.c,246
#define MAXSGST ^?MAXSGST^A6,80
#define MIN(^?MIN^A7,99
char** getdirlst()^?getdirlst^A9,143
void freedirlst(char **dirlst)^?freedirlst^A30,581
int levenshtein(const char *s, const char *t)^?levenshtein^A39,726
int main(int argc, char **argv)^?main^A62,1321

正確なエラー メッセージは次のとおりFile /Users/Ron/Documents/Code/command-not-found/TAGS is not a valid tags tableです。これは数日前に機能していましたが、何が問題なのか知っていますか? 過去数日間、構成をまったく変更していません。

編集: 先週動作していた既存の TAGS ファイルを使用して、今日の動作で同じことを試みましたが、同じエラーが発生しました。

EDIT 2:私がリンクしたいくつかのコードfind-file-hookが問題を引き起こしているようです。ファイルがバイナリかどうかを判断する関数を作成し、バイナリである場合は で開きますhexl-mode。どうやら emacs は TAGS ファイルが にあるときに読み取れないhexl-modeため、無効であると表示されます。これを簡単に解決するには、ファイルがタグ ファイルであるかどうかを判断し、そのままにしておきます。

;; open binaries in hexl-mode
(defun byte-plaintext-p (byte)
  "Determine whether BYTE is plaintext or not."
  (cl-case byte
    ((?\n ?\r ?\t) t)
    (otherwise (and (<= byte 126) (>= byte 32)))))
(defun file-binary-p (file)
  "Determine whether FILE is a binary file."
  (with-temp-buffer
    (insert-file-contents file)
    (cl-loop for c across
             (buffer-substring-no-properties
              1 (min 100 (buffer-size)))
             thereis (not (byte-plaintext-p c)))))
(defun file-tags-naive-p (file) ;; check if first character is '^L'
  "Determine whether FILE is a TAGS file."
  (let ((c (with-temp-buffer
             (insert-file-contents file nil 0 1) (buffer-string))))
    (if (= (aref c 0) 12) t nil)))
(add-hook 'find-file-hook
          (lambda ()
            (if (and (file-exists-p (buffer-file-name))
                     (> (buffer-size) 0)
                     (not (file-tags-naive-p (buffer-file-name))))
                (if (and (file-binary-p (buffer-file-name))
                         (string= (buffer-local-value 'major-mode
                                                      (current-buffer))
                                  "fundamental-mode"))
                    (hexl-mode)))))

これに対するより良い解決策はありますか?

4

1 に答える 1