From 99895730e686a827176436bc38ec3313da533ace Mon Sep 17 00:00:00 2001
From: Jerome Reybert <jreybert@gmail.com>
Date: Tue, 2 Feb 2016 15:31:41 +0100
Subject: [PATCH] autoload/magit/utils.vim: add magit#utils#clear_undo function

---
 autoload/magit/utils.vim | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/autoload/magit/utils.vim b/autoload/magit/utils.vim
index 3b5dd5b..858bf38 100644
--- a/autoload/magit/utils.vim
+++ b/autoload/magit/utils.vim
@@ -35,6 +35,21 @@ function! magit#utils#lcd(dir)
 	execute s:magit_cd_cmd . a:dir
 endfunction
 
+" magit#utils#clear_undo: this function clear local undo history.
+" vimagit wants to clear undo history after each changes in vimagit buffer by
+" vimagit backend.
+" Use this function with caution: to be effective, the undo must be ack'ed
+" with a change. The hack is the line
+" exe "normal a \<BS>\<Esc>"
+" If the cursor is on a closed folding, it will open it!
+function! magit#utils#clear_undo()
+	let old_undolevels = &l:undolevels
+	setlocal undolevels=-1
+	exe "normal a \<BS>\<Esc>"
+	let &l:undolevels = old_undolevels
+	unlet old_undolevels
+endfunction
+
 " magit#utils#system: wrapper for system, which only takes String as input in vim,
 " although it can take String or List input in neovim.
 " INFO: temporarly change pwd to git top directory, then restore to previous
-- 
GitLab