Skip to content

Commit 321c7c9

Browse files
committed
vim: Fix handling of newline characters
Restores the previous behavior.
1 parent 670aa0d commit 321c7c9

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

vim/merlin/autoload/merlin.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def vim_value(v):
9090
if isinstance(v, int):
9191
return str(v)
9292
if isinstance(v, str):
93-
return "'%s'" % v.replace("'", "''")
93+
return "'%s'" % v.replace("'", "''").replace("\n", "'.\"\\n\".'")
9494
raise Exception("Failed to convert into a vim value: %s" % str(v))
9595

9696
# Format a dictionnary containing integer and string values into a Vim record.
@@ -362,27 +362,29 @@ def command_holes():
362362

363363
######## VIM FRONTEND
364364

365-
def vim_complete_prepare(str):
366-
return re.sub(re_wspaces, " ", str).replace("'", "''").strip()
367-
368-
# Turns Merlin's search-by-polarity or complete-prefix entries into a Vim's completion-item list
365+
# Turns Merlin's search-by-polarity or complete-prefix entries into a Vim's completion-item list (:h complete-items)
369366
def vim_fillentries(entries, vimvar):
367+
def prep(s):
368+
return re.sub(re_wspaces, " ", s).strip()
369+
def prep_nl(s):
370+
return re.sub(re_spaces_around_nl, "\n", re.sub(re_spaces, " ", s)).strip()
370371
for prop in entries:
371372
vim.command("let tmp = " + vim_record({
372-
"word": prop["name"],
373-
"menu": prop["desc"],
374-
"info": prop["info"],
373+
"word": prep(prop["name"]),
374+
"menu": prep(prop["desc"]),
375+
"info": prep_nl(prop["info"]),
375376
"kind": prop["kind"][:1]
376377
}))
377378
vim.command("call add(%s, tmp)" % vimvar)
378379

379380
# Complete
380381
def vim_complete_cursor(base, suffix, vimvar):
382+
def prep(str):
383+
return re.sub(re_wspaces, " ", str).replace("'", "''").strip()
381384
vim.command("let %s = []" % vimvar)
382385
try:
383386
completions = command_complete_cursor(base,vim.current.window.cursor)
384387
nb_entries = len(completions['entries'])
385-
prep = vim_complete_prepare
386388
if completions['context'] and completions['context'][0] == 'application':
387389
app = completions['context'][1]
388390
if not base or base == suffix:

0 commit comments

Comments
 (0)