buffer: Move b_p_ma(modifiable) checks into the MODIFIABLE macro

This commit is contained in:
Thiago de Arruda
2015-03-05 18:07:15 -03:00
parent 8b6b06c2e0
commit b16c5bf5e6
10 changed files with 21 additions and 18 deletions

View File

@@ -2145,7 +2145,7 @@ void buflist_list(exarg_T *eap)
(curwin->w_alt_fnum == buf->b_fnum ? '#' : ' '), (curwin->w_alt_fnum == buf->b_fnum ? '#' : ' '),
buf->b_ml.ml_mfp == NULL ? ' ' : buf->b_ml.ml_mfp == NULL ? ' ' :
(buf->b_nwindows == 0 ? 'h' : 'a'), (buf->b_nwindows == 0 ? 'h' : 'a'),
!buf->b_p_ma ? '-' : (buf->b_p_ro ? '=' : ' '), !MODIFIABLE(buf) ? '-' : (buf->b_p_ro ? '=' : ' '),
(buf->b_flags & BF_READERR) ? 'x' (buf->b_flags & BF_READERR) ? 'x'
: (bufIsChanged(buf) ? '+' : ' '), : (bufIsChanged(buf) ? '+' : ' '),
NameBuff); NameBuff);
@@ -2623,7 +2623,7 @@ void maketitle(void)
switch (bufIsChanged(curbuf) switch (bufIsChanged(curbuf)
+ (curbuf->b_p_ro * 2) + (curbuf->b_p_ro * 2)
+ (!curbuf->b_p_ma * 4)) { + (!MODIFIABLE(curbuf) * 4)) {
case 1: STRCAT(buf, " +"); break; case 1: STRCAT(buf, " +"); break;
case 2: STRCAT(buf, " ="); break; case 2: STRCAT(buf, " ="); break;
case 3: STRCAT(buf, " =+"); break; case 3: STRCAT(buf, " =+"); break;
@@ -3250,7 +3250,7 @@ build_stl_str_hl (
itemisflag = TRUE; itemisflag = TRUE;
switch ((opt == STL_MODIFIED_ALT) switch ((opt == STL_MODIFIED_ALT)
+ bufIsChanged(wp->w_buffer) * 2 + bufIsChanged(wp->w_buffer) * 2
+ (!wp->w_buffer->b_p_ma) * 4) { + (!MODIFIABLE(wp->w_buffer)) * 4) {
case 2: str = (char_u *)"[+]"; break; case 2: str = (char_u *)"[+]"; break;
case 3: str = (char_u *)",+"; break; case 3: str = (char_u *)",+"; break;
case 4: str = (char_u *)"[-]"; break; case 4: str = (char_u *)"[-]"; break;

View File

@@ -27,6 +27,8 @@
// for String // for String
#include "nvim/api/private/defs.h" #include "nvim/api/private/defs.h"
#define MODIFIABLE(buf) (buf->b_p_ma)
/* /*
* Flags for w_valid. * Flags for w_valid.
* These are set when something in a window structure becomes invalid, except * These are set when something in a window structure becomes invalid, except

View File

@@ -2078,7 +2078,7 @@ void ex_diffgetput(exarg_T *eap)
if ((curtab->tp_diffbuf[idx_other] != curbuf) if ((curtab->tp_diffbuf[idx_other] != curbuf)
&& (curtab->tp_diffbuf[idx_other] != NULL)) { && (curtab->tp_diffbuf[idx_other] != NULL)) {
if ((eap->cmdidx != CMD_diffput) if ((eap->cmdidx != CMD_diffput)
|| curtab->tp_diffbuf[idx_other]->b_p_ma) { || MODIFIABLE(curtab->tp_diffbuf[idx_other])) {
break; break;
} }
found_not_ma = TRUE; found_not_ma = TRUE;
@@ -2098,7 +2098,8 @@ void ex_diffgetput(exarg_T *eap)
for (i = idx_other + 1; i < DB_COUNT; ++i) { for (i = idx_other + 1; i < DB_COUNT; ++i) {
if ((curtab->tp_diffbuf[i] != curbuf) if ((curtab->tp_diffbuf[i] != curbuf)
&& (curtab->tp_diffbuf[i] != NULL) && (curtab->tp_diffbuf[i] != NULL)
&& ((eap->cmdidx != CMD_diffput) || curtab->tp_diffbuf[i]->b_p_ma)) { && ((eap->cmdidx != CMD_diffput)
|| MODIFIABLE(curtab->tp_diffbuf[i]))) {
EMSG(_("E101: More than two buffers in diff mode, don't know " EMSG(_("E101: More than two buffers in diff mode, don't know "
"which one to use")); "which one to use"));
return; return;

View File

@@ -3656,7 +3656,7 @@ void do_sub(exarg_T *eap)
if (eap->skip) /* not executing commands, only parsing */ if (eap->skip) /* not executing commands, only parsing */
return; return;
if (!do_count && !curbuf->b_p_ma) { if (!do_count && !MODIFIABLE(curbuf)) {
/* Substitution is not allowed in non-'modifiable' buffer */ /* Substitution is not allowed in non-'modifiable' buffer */
EMSG(_(e_modifiable)); EMSG(_(e_modifiable));
return; return;

View File

@@ -1510,7 +1510,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
errormsg = (char_u *)_(e_sandbox); errormsg = (char_u *)_(e_sandbox);
goto doend; goto doend;
} }
if (!curbuf->b_p_ma && (ea.argt & MODIFY)) { if (!MODIFIABLE(curbuf) && (ea.argt & MODIFY)) {
/* Command not allowed in non-'modifiable' buffer */ /* Command not allowed in non-'modifiable' buffer */
errormsg = (char_u *)_(e_modifiable); errormsg = (char_u *)_(e_modifiable);
goto doend; goto doend;

View File

@@ -1563,7 +1563,7 @@ static void setSmallMaybe(garray_T *gap)
*/ */
static void foldCreateMarkers(linenr_T start, linenr_T end) static void foldCreateMarkers(linenr_T start, linenr_T end)
{ {
if (!curbuf->b_p_ma) { if (!MODIFIABLE(curbuf)) {
EMSG(_(e_modifiable)); EMSG(_(e_modifiable));
return; return;
} }

View File

@@ -1465,7 +1465,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
/* Force a redraw when operating on an empty Visual region, when /* Force a redraw when operating on an empty Visual region, when
* 'modifiable is off or creating a fold. */ * 'modifiable is off or creating a fold. */
if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma if (oap->is_VIsual && (oap->empty || !MODIFIABLE(curbuf)
|| oap->op_type == OP_FOLD || oap->op_type == OP_FOLD
)) ))
redraw_curbuf_later(INVERTED); redraw_curbuf_later(INVERTED);
@@ -5513,9 +5513,9 @@ static void nv_Replace(cmdarg_T *cap)
VIsual_mode = 'V'; VIsual_mode = 'V';
nv_operator(cap); nv_operator(cap);
} else if (!checkclearopq(cap->oap)) { } else if (!checkclearopq(cap->oap)) {
if (!curbuf->b_p_ma) if (!MODIFIABLE(curbuf)) {
EMSG(_(e_modifiable)); EMSG(_(e_modifiable));
else { } else {
if (virtual_active()) if (virtual_active())
coladvance(getviscol()); coladvance(getviscol());
invoke_edit(cap, false, cap->arg ? 'V' : 'R', false); invoke_edit(cap, false, cap->arg ? 'V' : 'R', false);
@@ -5533,9 +5533,9 @@ static void nv_vreplace(cmdarg_T *cap)
cap->nchar = cap->extra_char; cap->nchar = cap->extra_char;
nv_replace(cap); /* Do same as "r" in Visual mode for now */ nv_replace(cap); /* Do same as "r" in Visual mode for now */
} else if (!checkclearopq(cap->oap)) { } else if (!checkclearopq(cap->oap)) {
if (!curbuf->b_p_ma) if (!MODIFIABLE(curbuf)) {
EMSG(_(e_modifiable)); EMSG(_(e_modifiable));
else { } else {
if (cap->extra_char == Ctrl_V) /* get another character */ if (cap->extra_char == Ctrl_V) /* get another character */
cap->extra_char = get_literal(); cap->extra_char = get_literal();
stuffcharReadbuff(cap->extra_char); stuffcharReadbuff(cap->extra_char);

View File

@@ -583,7 +583,7 @@ void op_reindent(oparg_T *oap, Indenter how)
linenr_T start_lnum = curwin->w_cursor.lnum; linenr_T start_lnum = curwin->w_cursor.lnum;
/* Don't even try when 'modifiable' is off. */ /* Don't even try when 'modifiable' is off. */
if (!curbuf->b_p_ma) { if (!MODIFIABLE(curbuf)) {
EMSG(_(e_modifiable)); EMSG(_(e_modifiable));
return; return;
} }
@@ -1329,7 +1329,7 @@ int op_delete(oparg_T *oap)
if (oap->empty) if (oap->empty)
return u_save_cursor(); return u_save_cursor();
if (!curbuf->b_p_ma) { if (!MODIFIABLE(curbuf)) {
EMSG(_(e_modifiable)); EMSG(_(e_modifiable));
return FAIL; return FAIL;
} }

View File

@@ -3748,7 +3748,7 @@ did_set_string_option (
/* 'encoding' and 'fileencoding' */ /* 'encoding' and 'fileencoding' */
else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc) { else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc) {
if (gvarp == &p_fenc) { if (gvarp == &p_fenc) {
if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL) if (!MODIFIABLE(curbuf) && opt_flags != OPT_GLOBAL)
errmsg = e_modifiable; errmsg = e_modifiable;
else if (vim_strchr(*varp, ',') != NULL) else if (vim_strchr(*varp, ',') != NULL)
/* No comma allowed in 'fileencoding'; catches confusing it /* No comma allowed in 'fileencoding'; catches confusing it
@@ -3819,7 +3819,7 @@ did_set_string_option (
} }
/* 'fileformat' */ /* 'fileformat' */
else if (gvarp == &p_ff) { else if (gvarp == &p_ff) {
if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL)) if (!MODIFIABLE(curbuf) && !(opt_flags & OPT_GLOBAL))
errmsg = e_modifiable; errmsg = e_modifiable;
else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK) else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
errmsg = e_invarg; errmsg = e_invarg;

View File

@@ -289,7 +289,7 @@ int u_savedel(linenr_T lnum, long nlines)
int undo_allowed(void) int undo_allowed(void)
{ {
/* Don't allow changes when 'modifiable' is off. */ /* Don't allow changes when 'modifiable' is off. */
if (!curbuf->b_p_ma) { if (!MODIFIABLE(curbuf)) {
EMSG(_(e_modifiable)); EMSG(_(e_modifiable));
return FALSE; return FALSE;
} }