terminal: Allow undo and 'modifiable'.

Partial step towards #2637. Will crash if *all* lines are deleted.

Closes #2607
References #5431
This commit is contained in:
Justin M. Keyes 2017-02-19 03:48:20 +01:00
parent 7ea81fe443
commit fedb8443d5
4 changed files with 15 additions and 28 deletions

View File

@ -36,7 +36,7 @@ typedef struct {
// for Map(K, V)
#include "nvim/map.h"
#define MODIFIABLE(buf) (!buf->terminal && buf->b_p_ma)
#define MODIFIABLE(buf) (buf->b_p_ma)
/*
* Flags for w_valid.
@ -91,32 +91,22 @@ typedef struct frame_S frame_T;
// for struct memline (it needs memfile_T)
#include "nvim/memline_defs.h"
// for struct memfile, bhdr_T, blocknr_T... (it needs buf_T)
#include "nvim/memfile_defs.h"
/*
* This is here because regexp_defs.h needs win_T and buf_T. regprog_T is
* used below.
*/
// for regprog_T. Needs win_T and buf_T.
#include "nvim/regexp_defs.h"
// for synstate_T (needs reg_extmatch_T, win_T and buf_T)
// for synstate_T (needs reg_extmatch_T, win_T, buf_T)
#include "nvim/syntax_defs.h"
// for signlist_T
#include "nvim/sign_defs.h"
// for bufhl_*_T
#include "nvim/bufhl_defs.h"
typedef Map(linenr_T, bufhl_vec_T) bufhl_info_T;
// for FileID
#include "nvim/os/fs_defs.h"
// for Terminal
#include "nvim/terminal.h"
#include "nvim/os/fs_defs.h" // for FileID
#include "nvim/terminal.h" // for Terminal
/*
* The taggy struct is used to store the information about a :tag command.

View File

@ -7435,12 +7435,10 @@ static void nv_edit(cmdarg_T *cap)
/* in Visual mode and after an operator "a" and "i" are for text objects */
else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i')
&& (cap->oap->op_type != OP_NOP
|| VIsual_active
)) {
&& (cap->oap->op_type != OP_NOP || VIsual_active)) {
nv_object(cap);
} else if (!curbuf->b_p_ma && !p_im) {
/* Only give this error when 'insertmode' is off. */
} else if (!curbuf->b_p_ma && !p_im && !curbuf->terminal) {
// Only give this error when 'insertmode' is off.
EMSG(_(e_modifiable));
clearop(cap->oap);
} else if (!checkclearopq(cap->oap)) {

View File

@ -237,12 +237,16 @@ Terminal *terminal_open(TerminalOptions opts)
rv->invalid_end = opts.height;
refresh_screen(rv, curbuf);
set_option_value((uint8_t *)"buftype", 0, (uint8_t *)"terminal", OPT_LOCAL);
// some sane settings for terminal buffers
curbuf->b_p_ma = false; // 'nomodifiable'
curbuf->b_p_ul = -1; // disable undo
set_option_value((uint8_t *)"wrap", false, NULL, OPT_LOCAL);
set_option_value((uint8_t *)"number", false, NULL, OPT_LOCAL);
set_option_value((uint8_t *)"relativenumber", false, NULL, OPT_LOCAL);
buf_set_term_title(curbuf, (char *)curbuf->b_ffname);
RESET_BINDING(curwin);
// Apply TermOpen autocmds so the user can configure the terminal
apply_autocmds(EVENT_TERMOPEN, NULL, NULL, false, curbuf);
@ -958,7 +962,7 @@ static void refresh_terminal(Terminal *term)
buf_T *buf = handle_get_buffer(term->buf_handle);
bool valid = true;
if (!buf || !(valid = buf_valid(buf))) {
// destroyed by `close_buffer`. Dont do anything else
// Destroyed by `close_buffer`. Do not do anything else.
if (!valid) {
term->buf_handle = 0;
}
@ -1039,7 +1043,7 @@ static void refresh_scrollback(Terminal *term, buf_T *buf)
}
}
// Refresh the screen(visible part of the buffer when the terminal is
// Refresh the screen (visible part of the buffer when the terminal is
// focused) of a invalidated terminal
static void refresh_screen(Terminal *term, buf_T *buf)
{

View File

@ -305,14 +305,9 @@ bool undo_allowed(void)
return true;
}
/*
* Get the undolevle value for the current buffer.
*/
/// Get the 'undolevels' value for the current buffer.
static long get_undolevel(void)
{
if (curbuf->terminal) {
return -1;
}
if (curbuf->b_p_ul == NO_LOCAL_UNDOLEVEL)
return p_ul;
return curbuf->b_p_ul;