2012-10-04 8 views
5

長い編集セッションでは、undo-tree(C-x C-u)の呼び出しが遅くなり、遅くなることに気付きました。私は、木が大きくなるにつれて、それを解析するのに時間がかかります(私がファイルを開いて以来のすべての編集を追跡するので)。Emacs:元に戻すツリーのクリーンアップ

ファイルを開く?私は(find-alternate-fileC-x C-vを試してみましたが、この

答えて

6

M-: (setq buffer-undo-tree nil)を使用してbuffer-undo-tree変数をリセットし、カーソルをリセットし、ファイルを再オープンします(とorg-modeのようなモードで自分のリストを崩壊します)。これにより、バッファの元に戻す履歴がすべて破棄され、undo-tree.elと記録されます。

(defun clear-undo-tree() 
    (interactive) 
    (setq buffer-undo-tree nil)) 
(global-set-key [(control c) u] 'clear-undo-tree) 
+0

ありがとう:しかし、私は、関数が事故によって呼び出されるので、確認プロンプトとbuffer-undo-treeが本当にバッファローカル変数であることを確認を追加する必要はありません。あなたの答えと@npostavsの違いは何ですか? –

+1

違いは、 'undo-tree-discard-history'は、' undo-limit'、 'undo-strong-limit'、' undo-outer-limit'の変数に従って履歴を削除しようとしています。全体の元に戻す履歴。さらに重要なことに、 'undo-tree-discard-history'は、すべてのUndo/Redo/Switch-Branch操作で自動的に呼び出されるため、明らかに動作しません。 – user4815162342

+0

ありがとう!あなたの答えを受け入れるつもりだった –

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'. 
+0

'(undo-tree-discard-history)関数を呼び出すと'(buffer-undo-tree) 'を' nil'に設定する違いは何ですか? (@ user4815162342の回答のように) –

+1

@ user273158:user4815162342のコメントごとに完全に削除を減らしてください。私は、すべての元に戻す/やり直しと呼ばれていたことに気付かなかった。おそらく、より効果的にするために限界を下げることができます。 – npostavs

3

注ことこれはまたをコマンド化して、このようなコードを持つキーにバインドすることができ

このヒントは最近のUndo-Treeバージョンでは廃止される可能性があります。バージョン0.6以降では、undo-treeはデフォルトで "lazy tree-drawing"を使用します。これにより、目に見える部分を描画するだけで(そしてツリーの周りを移動するときに必要に応じて拡張する)、大きなUndoツリーの視覚化が大幅に高速化されます。詳細については、undo-tree-visualizer-lazy-drawing変数のドキュメントストリングを参照してください。

それでもやはり元に戻すツリーを破棄したい場合は、手動でbuffer-undo-treenilに設定するのが良いワンオフソリューションです。長期的な解決方法は、元のデータを破棄する前に元に戻す履歴をどれだけ保存するかを制限することによって、undo-limit,undo-strong-limit、およびundo-outer-limitの値を減らして、元に戻すツリーのサイズを制限することです。

undo-tree-discard-historyを手動で呼び出すのは無意味です。元に戻すのに何かをすると自動的に呼び出されます。

1

バッファ/ファイルの現在のエンコーディングでは表示できない文字を含むテキストを貼り付けたため、時にはバッファのUNDOツリーをフラッシュする必要があります。だから私は@ Amelio Vazquez-Reinaの機能が非常に役に立ちました。

(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)))))