On 24-Jun-15, Ben Fritz wrote:
> On Wednesday, June 24, 2015 at 8:24:51 AM UTC-5, Olaf wrote:
> >
> > No documentation in the patch, because in my understanding the current
> > docs seem to imply this behavior:
> >
> > The ":diffoff" command resets the relevant options to the values
> > they had when using |:diffsplit|, |:diffpatch| , |:diffthis|. or
> > starting Vim in diff mode. Otherwise they are set to their default
> > value:
> >
> >
> > With the patch, ':diffoff' will only restore the defaults if the window
> > has never been in a diff.
> >
>
> I agree that seems like the intent of the current documentation.
>
> > Question to the list: should ':diffoff' *ever* restore default settings?
> >
> > Maybe it is better to only restore settings that have been saved before,
> > when entering diff mode at some point, if that has happened at all.
> >
> > Because if the window was never switched to diff mode, why should
> > ':diffoff' restore settings that have never been changed by diff mode,
> > and then to some arbitrary defaults? Better leave these settings
> > untouched in that case?
> >
> >
>
> I agree; I don't see why :diffoff should affect anything at all in windows
> that have never been in diff mode to begin with. I would support such a
> change.
Thanks for your feedback! :)
With the patch below, :diffoff only restores settings when they have
been saved before. No defaults are restored.
BTW, it just occurred to me that we could also remember that we have
restored settings already. This 'already restored' state is reset by
:diffthis and friends.
Which is better?
- :diffoff restores saved settings, but only the first time after a
:diffthis or friends.
- :diffoff restores saved settings whenever it is used (after at
least one :diffthis or friend, to save settings), but only for
options that have the same value as in diff mode.
This is the behavior with the patch below.
The unpatched vim already only updates options that have the same
value as in diff mode.
(The patch below adds a check to make sure that saved settings
exist.)
---
src/diff.c | 80 ++++++++++++++++++++++++++++---------------------------------
1 file changed, 37 insertions(+), 43 deletions(-)
Index: b/src/diff.c
===================================================================
--- a/src/diff.c 2015-06-21 20:24:54.847522483 +0200
+++ b/src/diff.c 2015-06-24 18:48:37.978896390 +0200
@@ -1138,32 +1138,34 @@ diff_win_options(wp, addbuf)
curwin = old_curwin;
# endif
- wp->w_p_diff = TRUE;
-
/* Use 'scrollbind' and 'cursorbind' when available */
#ifdef FEAT_SCROLLBIND
- if (!wp->w_p_diff_saved)
+ if (!wp->w_p_diff)
wp->w_p_scb_save = wp->w_p_scb;
wp->w_p_scb = TRUE;
#endif
#ifdef FEAT_CURSORBIND
- if (!wp->w_p_diff_saved)
+ if (!wp->w_p_diff)
wp->w_p_crb_save = wp->w_p_crb;
wp->w_p_crb = TRUE;
#endif
- if (!wp->w_p_diff_saved)
+ if (!wp->w_p_diff)
wp->w_p_wrap_save = wp->w_p_wrap;
wp->w_p_wrap = FALSE;
# ifdef FEAT_FOLDING
curwin = wp;
curbuf = curwin->w_buffer;
- if (!wp->w_p_diff_saved)
+ if (!wp->w_p_diff)
+ {
+ if (wp->w_p_diff_saved)
+ free_string_option(wp->w_p_fdm_save);
wp->w_p_fdm_save = vim_strsave(wp->w_p_fdm);
+ }
set_string_option_direct((char_u *)"fdm", -1, (char_u *)"diff",
OPT_LOCAL|OPT_FREE, 0);
curwin = old_curwin;
curbuf = curwin->w_buffer;
- if (!wp->w_p_diff_saved)
+ if (!wp->w_p_diff)
{
wp->w_p_fdc_save = wp->w_p_fdc;
wp->w_p_fen_save = wp->w_p_fen;
@@ -1183,6 +1185,8 @@ diff_win_options(wp, addbuf)
/* Saved the current values, to be restored in ex_diffoff(). */
wp->w_p_diff_saved = TRUE;
+ wp->w_p_diff = TRUE;
+
if (addbuf)
diff_buf_add(wp->w_buffer);
redraw_win_later(wp, NOT_VALID);
@@ -1206,57 +1210,47 @@ ex_diffoff(eap)
{
if (eap->forceit ? wp->w_p_diff : wp == curwin)
{
- /* Set 'diff', 'scrollbind' off and 'wrap' on. If option values
- * were saved in diff_win_options() restore them. */
+ /* Set 'diff' off. If option values were saved in
+ * diff_win_options(), restore the ones whose settings seem to have
+ * been left over from diff mode. */
wp->w_p_diff = FALSE;
+ if (wp->w_p_diff_saved)
+ {
+
#ifdef FEAT_SCROLLBIND
- if (wp->w_p_scb)
- wp->w_p_scb = wp->w_p_diff_saved ? wp->w_p_scb_save : FALSE;
+ if (wp->w_p_scb)
+ wp->w_p_scb = wp->w_p_scb_save;
#endif
#ifdef FEAT_CURSORBIND
- if (wp->w_p_crb)
- wp->w_p_crb = wp->w_p_diff_saved ? wp->w_p_crb_save : FALSE;
+ if (wp->w_p_crb)
+ wp->w_p_crb = wp->w_p_crb_save;
#endif
- if (!wp->w_p_wrap)
- wp->w_p_wrap = wp->w_p_diff_saved ? wp->w_p_wrap_save : TRUE;
+ if (!wp->w_p_wrap)
+ wp->w_p_wrap = wp->w_p_wrap_save;
#ifdef FEAT_FOLDING
- curwin = wp;
- curbuf = curwin->w_buffer;
- if (wp->w_p_diff_saved)
- {
free_string_option(wp->w_p_fdm);
- wp->w_p_fdm = wp->w_p_fdm_save;
- wp->w_p_fdm_save = empty_option;
- }
- else
- set_string_option_direct((char_u *)"fdm", -1,
- (char_u *)"manual", OPT_LOCAL|OPT_FREE, 0);
- curwin = old_curwin;
- curbuf = curwin->w_buffer;
- if (wp->w_p_fdc == diff_foldcolumn)
- wp->w_p_fdc = wp->w_p_diff_saved ? wp->w_p_fdc_save : 0;
- if (wp->w_p_fdl == 0 && wp->w_p_diff_saved)
- wp->w_p_fdl = wp->w_p_fdl_save;
+ wp->w_p_fdm = vim_strsave(wp->w_p_fdm_save);
+
+ if (wp->w_p_fdc == diff_foldcolumn)
+ wp->w_p_fdc = wp->w_p_fdc_save;
+ if (wp->w_p_fdl == 0)
+ wp->w_p_fdl = wp->w_p_fdl_save;
- if (wp->w_p_fen)
- {
/* Only restore 'foldenable' when 'foldmethod' is not
* "manual", otherwise we continue to show the diff folds. */
- if (foldmethodIsManual(wp) || !wp->w_p_diff_saved)
- wp->w_p_fen = FALSE;
- else
- wp->w_p_fen = wp->w_p_fen_save;
+ if (wp->w_p_fen)
+ wp->w_p_fen = foldmethodIsManual(wp) ? FALSE
+ : wp->w_p_fen_save;
+
+ foldUpdateAll(wp);
+ /* make sure topline is not halfway a fold */
+ changed_window_setting_win(wp);
+#endif
}
- foldUpdateAll(wp);
- /* make sure topline is not halfway a fold */
- changed_window_setting_win(wp);
-#endif
/* Note: 'sbo' is not restored, it's a global option. */
diff_buf_adjust(wp);
-
- wp->w_p_diff_saved = FALSE;
}
#ifdef FEAT_SCROLLBIND
diffwin |= wp->w_p_diff;
--
Olaf Dabrunz (oda <at> fctrace.org)
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.