Skip to content
forked from neovim/neovim

Commit

Permalink
terminal: Allow undo and 'modifiable'.
Browse files Browse the repository at this point in the history
Partial solution to neovim#2637. Will crash if *all* lines are deleted.

References neovim#2607
References neovim#2637
References neovim#5431
  • Loading branch information
justinmk committed Feb 24, 2017
1 parent 9752a33 commit 8a6433b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 28 deletions.
20 changes: 5 additions & 15 deletions src/nvim/buffer_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 3 additions & 5 deletions src/nvim/normal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 6 additions & 2 deletions src/nvim/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand Down
7 changes: 1 addition & 6 deletions src/nvim/undo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8a6433b

Please sign in to comment.