namespace caching breaks updating namespace name

オープン
#480 コメント 5 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
emacs-lisp
領域
tooling

調査の方向性

まず clojure-update-ns と clojure-find-ns を読み、特に cached ブランチと replace-match で使用される match データを確認してください。namespace の更新中に clojure-cache-ns を有効にして、失敗を再現してください。namespace の更新が成功し、キャッシュされた namespace が一貫して更新されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug enhancement
 (defun clojure-update-ns ()
      "Update the namespace of the current buffer.
    Useful if a file has been renamed."
      (interactive)
      (let ((nsname (funcall clojure-expected-ns-function)))
        (when nsname
          (save-excursion
            (save-match-data
              (if (clojure-find-ns)
                  (progn
                    (replace-match nsname nil nil nil 4)
                    (message "ns form updated to `%s'" nsname)
                    (setq clojure-cached-ns nsname))
                (error "Namespace not found")))))))

This is the helpful function to update the namespace and reset the cache for namespaces. Unfortunately it relies on the replace match generated in clojure-find-ns. The problem is that this match does not happen if namespace caching is enbled.

    (defun clojure-find-ns ()
      "Return the namespace of the current Clojure buffer.
    Return the namespace closest to point and above it.  If there are
    no namespaces above point, return the first one in the buffer.

    The results will be cac(match-string-no-properties 4)hed if `clojure-cache-ns' is set to t."
      (if (and clojure-cache-ns clojure-cached-ns)
          clojure-cached-ns
        (let ((ns (save-excursion
                    (save-restriction
                      (widen)

                      ;; Move to top-level to avoid searching from inside ns
                      (ignore-errors (while t (up-list nil t t)))

                      ;; The closest ns form above point.
                      (when (or (re-search-backward clojure-namespace-name-regex nil t)
                                ;; Or any form at all.
                                (and (goto-char (point-min))
                                     (re-search-forward clojure-namespace-name-regex nil t)))
                        (match-string-no-properties 4))))))
          (setq clojure-cached-ns ns)
          ns)))

Note the top level bails if the cache is already set and therefore does not call (match-string-no-properties 4) yielding an error.

This leaves an unfortunate catch-22: if you use the cache, you need to update it with update-ns. If you update the ns with the cache on, it doesn't create the match to update the cache.

主要言語
Emacs Lisp
スター
1k
フォーク
249
平均マージ
1日 6時間
マージ済み PR(30日)
6

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

clojure-emacs/clojure-mode のほかの issue

clojure-emacs/clojure-mode の issue をすべて見る

似ている issue

DevTools の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。