Skip to content

Commit

Permalink
feat(options)!: deprecate paste, remove pastetoggle
Browse files Browse the repository at this point in the history
  • Loading branch information
ii14 committed Mar 12, 2023
1 parent e5f4394 commit 1a58910
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 231 deletions.
2 changes: 2 additions & 0 deletions runtime/doc/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ The following changes may require adaptations in user config or plugins.
- The `concat` option has been removed as it was not consistently applied.
- Invalid ranges now cause an error instead of returning `nil`.

'paste' option is now deprecated and 'pastetoggle' is removed

==============================================================================
NEW FEATURES *news-features*

Expand Down
24 changes: 0 additions & 24 deletions runtime/doc/options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4521,30 +4521,6 @@ A jump table for the options with a short description can be found at |Q_op|.
Since mapping doesn't work while 'paste' is active, you need to use
the 'pastetoggle' option to toggle the 'paste' option with some key.

*'pastetoggle'* *'pt'*
'pastetoggle' 'pt' string (default "")
global
When non-empty, specifies the key sequence that toggles the 'paste'
option. This is like specifying a mapping: >
:map {keys} :set invpaste<CR>
< Where {keys} is the value of 'pastetoggle'.
The difference is that it will work even when 'paste' is set.
'pastetoggle' works in Insert mode and Normal mode, but not in
Command-line mode.
Mappings are checked first, thus overrule 'pastetoggle'. However,
when 'paste' is on mappings are ignored in Insert mode, thus you can do
this: >
:map <F10> :set paste<CR>
:map <F11> :set nopaste<CR>
:imap <F10> <C-O>:set paste<CR>
:imap <F11> <nop>
:set pastetoggle=<F11>
< This will make <F10> start paste mode and <F11> stop paste mode.
Note that typing <F10> in paste mode inserts "<F10>", since in paste
mode everything is inserted literally, except the 'pastetoggle' key
sequence.
When the value has several bytes 'ttimeoutlen' applies.

*'pex'* *'patchexpr'*
'patchexpr' 'pex' string (default "")
global
Expand Down
1 change: 0 additions & 1 deletion runtime/doc/quickref.txt
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,6 @@ Short explanation of each option: *option-list*
'packpath' 'pp' list of directories used for packages
'paragraphs' 'para' nroff macros that separate paragraphs
'paste' allow pasting text
'pastetoggle' 'pt' key code that causes 'paste' to toggle
'patchexpr' 'pex' expression used to patch a file
'patchmode' 'pm' keep the oldest version of a file
'path' 'pa' list of directories searched with "gf" et.al.
Expand Down
1 change: 1 addition & 0 deletions runtime/doc/vim_diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ Options:
'highlight' (Names of builtin |highlight-groups| cannot be changed.)
*'hkmap'* *'hk'* use `set keymap=hebrew` instead.
*'hkmapp'* *'hkp'* use `set keymap=hebrewp` instead.
*'paste'* *'pastetoggle'* *'pt'* *'nopaste'*

*'imactivatefunc'* *'imaf'*
*'imactivatekey'* *'imak'*
Expand Down
22 changes: 1 addition & 21 deletions runtime/optwin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ func <SID>Update(lnum, line, local, thiswin)
else
let name = substitute(a:line, '^ \tset \(no\)\=\([a-z]*\).*', '\2', "")
endif
if name == "pt" && &pt =~ "\x80"
let val = <SID>PTvalue()
else
let val = escape(eval('&' . name), " \t\\\"|")
endif
let val = escape(eval('&' . name), " \t\\\"|")
if a:local
exe a:thiswin . "wincmd w"
endif
Expand Down Expand Up @@ -211,14 +207,6 @@ func <SID>Header(text)
let s:lnum = s:lnum + 1
endfunc

" Get the value of 'pastetoggle'. It could be a special key.
func <SID>PTvalue()
redir @a
silent set pt
redir END
return substitute(@a, '[^=]*=\(.*\)', '\1', "")
endfunc

" Restore the previous value of 'cpoptions' here, it's used below.
let &cpo = s:cpo_save

Expand All @@ -230,14 +218,6 @@ call <SID>AddOption("compatible", gettext("behave very Vi compatible (not advisa
call <SID>BinOptionG("cp", &cp)
call <SID>AddOption("cpoptions", gettext("list of flags to specify Vi compatibility"))
call <SID>OptionG("cpo", &cpo)
call <SID>AddOption("paste", gettext("paste mode, insert typed text literally"))
call <SID>BinOptionG("paste", &paste)
call <SID>AddOption("pastetoggle", gettext("key sequence to toggle paste mode"))
if &pt =~ "\x80"
call append("$", " \tset pt=" . <SID>PTvalue())
else
call <SID>OptionG("pt", &pt)
endif
call <SID>AddOption("runtimepath", gettext("list of directories used for runtime files and plugins"))
call <SID>OptionG("rtp", &rtp)
call <SID>AddOption("packpath", gettext("list of directories used for plugin packages"))
Expand Down
45 changes: 0 additions & 45 deletions src/nvim/getchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2073,39 +2073,6 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
}
}

// Check for match with 'pastetoggle'
if (*p_pt != NUL && mp == NULL && (State & (MODE_INSERT | MODE_NORMAL))) {
bool match = typebuf_match_len((uint8_t *)p_pt, &mlen);
if (match) {
// write chars to script file(s)
if (mlen > typebuf.tb_maplen) {
gotchars(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_maplen,
(size_t)(mlen - typebuf.tb_maplen));
}

del_typebuf(mlen, 0); // remove the chars
set_option_value_give_err("paste", !p_paste, NULL, 0);
if (!(State & MODE_INSERT)) {
msg_col = 0;
msg_row = Rows - 1;
msg_clr_eos(); // clear ruler
}
status_redraw_all();
redraw_statuslines();
showmode();
setcursor();
*keylenp = keylen;
return map_result_retry;
}
// Need more chars for partly match.
if (mlen == typebuf.tb_len) {
keylen = KEYLEN_PART_KEY;
} else if (max_mlen < mlen) {
// no match, may have to check for termcode at next character
max_mlen = mlen + 1;
}
}

if ((mp == NULL || max_mlen > mp_match_len) && keylen != KEYLEN_PART_MAP) {
// When no matching mapping found or found a non-matching mapping that
// matches at least what the matching mapping matched:
Expand Down Expand Up @@ -2923,18 +2890,6 @@ int fix_input_buffer(uint8_t *buf, int len)
return len;
}

static bool typebuf_match_len(const uint8_t *str, int *mlen)
{
int i;
for (i = 0; i < typebuf.tb_len && str[i]; i++) {
if (str[i] != typebuf.tb_buf[typebuf.tb_off + i]) {
break;
}
}
*mlen = i;
return str[i] == NUL; // matched the whole string
}

/// Get command argument for <Cmd> key
char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat)
{
Expand Down
4 changes: 1 addition & 3 deletions src/nvim/insexpand.c
Original file line number Diff line number Diff line change
Expand Up @@ -3055,9 +3055,7 @@ static char *ins_compl_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_po
return NULL;
}
ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false);
if (!p_paste) {
ptr = skipwhite(ptr);
}
ptr = skipwhite(ptr);
}
len = (int)strlen(ptr);
} else {
Expand Down
21 changes: 2 additions & 19 deletions src/nvim/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -2918,11 +2918,7 @@ getoption_T get_option_value(const char *name, long *numval, char **stringval, u
return gov_hidden_string;
}
if (stringval != NULL) {
if ((char **)varp == &p_pt) { // 'pastetoggle'
*stringval = str2special_save(*(char **)(varp), false, false);
} else {
*stringval = xstrdup(*(char **)(varp));
}
*stringval = xstrdup(*(char **)(varp));
}
return gov_string;
}
Expand Down Expand Up @@ -3532,17 +3528,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_
char_u *part = NULL;

if (*valuep != NULL) {
// Output 'pastetoggle' as key names. For other
// options some characters have to be escaped with
// CTRL-V or backslash
if (valuep == &p_pt) {
char_u *s = (char_u *)(*valuep);
while (*s != NUL) {
if (put_escstr(fd, (char *)str2special((const char **)&s, false, false), 2) == FAIL) {
return FAIL;
}
}
} else if ((flags & P_EXPAND) != 0) {
if ((flags & P_EXPAND) != 0) {
size_t size = (size_t)strlen(*valuep) + 1;

// replace home directory in the whole option value into "buf"
Expand Down Expand Up @@ -4990,9 +4976,6 @@ static void option_value2string(vimoption_T *opp, int scope)
NameBuff[0] = NUL;
} else if (opp->flags & P_EXPAND) {
home_replace(NULL, varp, NameBuff, MAXPATHL, false);
// Translate 'pastetoggle' into special key names.
} else if ((char **)opp->var == &p_pt) {
str2specialbuf((const char *)p_pt, NameBuff, MAXPATHL);
} else {
xstrlcpy(NameBuff, varp, MAXPATHL);
}
Expand Down
1 change: 0 additions & 1 deletion src/nvim/option_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@ EXTERN char *p_nf; ///< 'nrformats'
EXTERN char *p_opfunc; // 'operatorfunc'
EXTERN char *p_para; // 'paragraphs'
EXTERN int p_paste; // 'paste'
EXTERN char *p_pt; // 'pastetoggle'
EXTERN char *p_pex; // 'patchexpr'
EXTERN char *p_pm; // 'patchmode'
EXTERN char *p_path; // 'path'
Expand Down
3 changes: 1 addition & 2 deletions src/nvim/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1685,9 +1685,8 @@ return {
},
{
full_name='pastetoggle', abbreviation='pt',
short_desc=N_("key code that causes 'paste' to toggle"),
short_desc=N_("No description"),
type='string', scope={'global'},
varname='p_pt',
defaults={if_true=""}
},
{
Expand Down
18 changes: 0 additions & 18 deletions src/nvim/optionstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1306,22 +1306,6 @@ static void did_set_foldcolumn(char **varp, char **errmsg)
}
}

static void did_set_pastetoggle(void)
{
// 'pastetoggle': translate key codes like in a mapping
if (*p_pt) {
char *p = NULL;
(void)replace_termcodes(p_pt,
strlen(p_pt),
&p, REPTERM_FROM_PART | REPTERM_DO_LT, NULL,
CPO_TO_CPO_FLAGS);
if (p != NULL) {
free_string_option(p_pt);
p_pt = p;
}
}
}

static void did_set_backspace(char **errmsg)
{
if (ascii_isdigit(*p_bs)) {
Expand Down Expand Up @@ -1778,8 +1762,6 @@ static char *did_set_string_option_for(buf_T *buf, win_T *win, int opt_idx, char
did_set_opt_strings(*varp, p_sloc_values, false, &errmsg);
} else if (gvarp == &win->w_allbuf_opt.wo_fdc) { // 'foldcolumn'
did_set_foldcolumn(varp, &errmsg);
} else if (varp == &p_pt) { // 'pastetoggle'
did_set_pastetoggle();
} else if (varp == &p_bs) { // 'backspace'
did_set_backspace(&errmsg);
} else if (varp == &p_bo) {
Expand Down
3 changes: 0 additions & 3 deletions src/nvim/textformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ static bool did_add_space = false; ///< auto_format() added an extra space
bool has_format_option(int x)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
if (p_paste) {
return false;
}
return vim_strchr(curbuf->b_p_fo, x) != NULL;
}

Expand Down
90 changes: 0 additions & 90 deletions test/functional/options/pastetoggle_spec.lua

This file was deleted.

7 changes: 4 additions & 3 deletions test/old/testdir/test_mksession.vim
Original file line number Diff line number Diff line change
Expand Up @@ -943,15 +943,16 @@ func Test_mkvimrc()

" the 'pastetoggle', 'wildchar' and 'wildcharm' option values should be
" stored as key names in the vimrc file
set pastetoggle=<F5>
" set pastetoggle=<F5>
set wildchar=<F6>
set wildcharm=<F7>
call assert_fails('mkvimrc Xtestvimrc')
mkvimrc! Xtestvimrc
call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set pastetoggle=<F5>'))
" call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set pastetoggle=<F5>'))
call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set wildchar=<F6>'))
call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set wildcharm=<F7>'))
set pastetoggle& wildchar& wildcharm&
" set pastetoggle& wildchar& wildcharm&
set wildchar& wildcharm&

call delete('Xtestvimrc')
endfunc
Expand Down
2 changes: 2 additions & 0 deletions test/old/testdir/test_options.vim
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ endfunc

" Test for getting the value of 'pastetoggle'
func Test_pastetoggle()
" 'pastetoggle' is removed from neovim
return
" character with K_SPECIAL byte
let &pastetoggle = ''
call assert_equal('', &pastetoggle)
Expand Down

0 comments on commit 1a58910

Please sign in to comment.