Skip to content

Commit

Permalink
vim: Fix handling of newline characters
Browse files Browse the repository at this point in the history
Restores the previous behavior.
  • Loading branch information
Julow committed Oct 9, 2024
1 parent 670aa0d commit 321c7c9
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions vim/merlin/autoload/merlin.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def vim_value(v):
if isinstance(v, int):
return str(v)
if isinstance(v, str):
return "'%s'" % v.replace("'", "''")
return "'%s'" % v.replace("'", "''").replace("\n", "'.\"\\n\".'")
raise Exception("Failed to convert into a vim value: %s" % str(v))

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

######## VIM FRONTEND

def vim_complete_prepare(str):
return re.sub(re_wspaces, " ", str).replace("'", "''").strip()

# Turns Merlin's search-by-polarity or complete-prefix entries into a Vim's completion-item list
# Turns Merlin's search-by-polarity or complete-prefix entries into a Vim's completion-item list (:h complete-items)
def vim_fillentries(entries, vimvar):
def prep(s):
return re.sub(re_wspaces, " ", s).strip()
def prep_nl(s):
return re.sub(re_spaces_around_nl, "\n", re.sub(re_spaces, " ", s)).strip()
for prop in entries:
vim.command("let tmp = " + vim_record({
"word": prop["name"],
"menu": prop["desc"],
"info": prop["info"],
"word": prep(prop["name"]),
"menu": prep(prop["desc"]),
"info": prep_nl(prop["info"]),
"kind": prop["kind"][:1]
}))
vim.command("call add(%s, tmp)" % vimvar)

# Complete
def vim_complete_cursor(base, suffix, vimvar):
def prep(str):
return re.sub(re_wspaces, " ", str).replace("'", "''").strip()
vim.command("let %s = []" % vimvar)
try:
completions = command_complete_cursor(base,vim.current.window.cursor)
nb_entries = len(completions['entries'])
prep = vim_complete_prepare
if completions['context'] and completions['context'][0] == 'application':
app = completions['context'][1]
if not base or base == suffix:
Expand Down

0 comments on commit 321c7c9

Please sign in to comment.