8

undo-tree長い編集セッションでは、 (Cx Cu)の呼び出しがだんだん遅くなることに気づきました。その理由は、ツリーが大きくなるにつれて、解析に時間がかかるためだと思います(ファイルを開いてからのすべての編集を追跡するため)

開いているファイルの取り消しのツリーをクリアする方法はありますか?C-x C-v( )を試しfind-alternate-fileましたが、これによりファイルが再度開き、カーソルがリセットされます(org-mode リストを折りたたむなどのモードでは)

4

4 に答える 4

9

buffer-undo-treeを使用して変数をリセットしますM-: (setq buffer-undo-tree nil)。これにより、によって記録されたバッファの取り消し履歴全体が破棄されundo-tree.elます。

これをコマンドにして、次のようなコードでキーにバインドすることもできます。

(defun clear-undo-tree ()
  (interactive)
  (setq buffer-undo-tree nil))
(global-set-key [(control c) u] 'clear-undo-tree)
于 2012-10-04T20:02:37.277 に答える
4

このヒントは、最近のundo-treeバージョンでは廃止されている可能性があることに注意してください。バージョン0.6以降、undo-treeはデフォルトで「レイジーツリー描画」を使用します。これにより、表示されている部分だけを描画する(そして、ツリー内を移動するときに必要に応じて拡張する)ことで、大きな元に戻るツリーの視覚化が大幅に高速化されます。undo-tree-visualizer-lazy-drawing詳細については、変数のdocstringを参照してください。

それでも元に戻るツリー全体を破棄したい場合は、手動でに設定buffer-undo-treeすることをお勧めしnilます。長期的な解決策は、、の値を減らし、undo-limit古いundo-strong-limitデータundo-outer-limitを破棄する前に保存するUNDO履歴の量を制限することにより、UNDOツリーのサイズを制限することです。

手動で呼び出すundo-tree-discard-historyのは無意味です。元にできることに関連することを行うと、自動的に呼び出されます。

于 2012-12-04T19:47:30.537 に答える
2

バッファ/ファイルの現在のエンコーディングで表示できない文字を含むテキストを貼り付けたために、バッファの元に戻るツリーをフラッシュする必要がある場合があります。だから私は@AmelioVazquez-Reinaの機能がとても役に立ったと思いました。ただし、関数が誤って呼び出されることを望まないため、確認プロンプトと、buffer-undo-tree実際にはバッファーローカル変数であるチェックを追加しました。

(defun clean-undo-tree ()
"Clear current buffer's undo-tree.
Undo-tree can cause problems with file encoding when characters
are inserted that cannot be represented using the files current
encoding. This is even the case when characters are only
temporarily inserted, e.g. pasted from another source and then
instantly deleted. In these situations it can be necessary to
clear the buffers undo-tree before saving the file."
  (interactive)
  (let ((buff (current-buffer)))
    (if (local-variable-p 'buffer-undo-tree)
        (if (y-or-n-p "Clear buffer-undo-tree? ")
            (progn
              (setq buffer-undo-tree nil)
              (message "Cleared undo-tree of buffer: %s" (buffer-name buff)))
          (message "Cancelled clearing undo-tree of buffer: %s" (buffer-name buff)))
      (error "Buffer %s has no local binding of `buffer-undo-tree'" (buffer-name buff)))))
于 2017-12-03T22:54:12.783 に答える
1

すべてを破棄する代わりに、ツリーを剪定することができます。

undo-tree-discard-history is a compiled Lisp function in
`undo-tree.el'.

(undo-tree-discard-history)

Discard undo history until we're within memory usage limits
set by `undo-limit', `undo-strong-limit' and `undo-outer-limit'.
于 2012-10-04T22:05:17.017 に答える