LoginSignup
3
4

More than 5 years have passed since last update.

Windows+Emacs+auto-complete+"//" → 固まる

Last updated at Posted at 2013-06-24

正しくは、固まるのではなくて数分後に //usr //dev などの候補が表示されます。
このことから、ファイル名の補完が変なのでは?と思い、ちょっと調べました。

原因

重くなっている処理は ac-source-filename でした。// が入力されると「ファイル名補完だ!」と判断して、
ac-source-filename で定義している ac-filename-candidate を実行します。

(defun ac-filename-candidate ()
  (unless (file-regular-p ac-prefix)
    (ignore-errors
      (loop with dir = (file-name-directory ac-prefix)
            with files = (or (assoc-default dir ac-filename-cache)
                             (let ((files (directory-files dir nil "^[^.]")))
                               (push (cons dir files) ac-filename-cache)
                               files))
            for file in files
            for path = (concat dir file)
            collect (if (file-directory-p path)
                        (concat path "/")
                      path)))))

loop の中の dir には、 "//" がセットされます。 files にはルートディレクトリから取得したファイル名、ディレクトリ名がセットされます。
その両方を concat した値を file-directory-p にかけています。こんな値がわたっていき、もちろん nil が返ります。

(file-directory-p "//bin")
-> nil

Windows環境だと // は \\ と同じらしく、 \\bin というネットワーク上のサーバを探しに行っているようです。
ここで時間を食っていました。そしてルートディレクトリにあるファイルの数分、この検査をループするため、
固まっているように見えていました。

対処

scratch バッファ等で ac-sources の中身を参照し、そこから ac-source-filename をはずすことで対処しました。
~/.emacs や ~/.emacs.d./init.el で (ac-config-default) した後に、 ac-sources を上書きしています。

(setq ac-sources '(ac-source-functions
                   ac-source-yasnippet
                   ac-source-variables
                   ac-source-symbols
                   ac-source-features
                   ac-source-abbrev
                   ac-source-words-in-same-mode-buffers
                   ac-source-dictionary))

これで安心して1行コメントを書くことができます。

3
4
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
3
4