updated for version 7.0020
diff --git a/src/undo.c b/src/undo.c
index 6efcffa..bdba903 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -185,10 +185,18 @@
      * Netbeans defines areas that cannot be modified.  Bail out here when
      * trying to change text in a guarded area.
      */
-    if (usingNetbeans && netbeans_is_guarded(top, bot))
+    if (usingNetbeans)
     {
-	EMSG(_(e_guarded));
-	return FAIL;
+	if (netbeans_is_guarded(top, bot))
+	{
+	    EMSG(_(e_guarded));
+	    return FAIL;
+	}
+	if (curbuf->b_p_ro)
+	{
+	    EMSG(_(e_nbreadonly));
+	    return FAIL;
+	}
     }
 #endif
 
@@ -693,6 +701,10 @@
     if (old_flags & UH_CHANGED)
 	changed();
     else
+#ifdef FEAT_NETBEANS_INTG
+	/* per netbeans undo rules, keep it as modified */
+	if (!isNetbeansModified(curbuf))
+#endif
 	unchanged(curbuf, FALSE);
 
     /*