Add a {\} marker to disable markup processing

This commit is contained in:
Maxime Coste 2019-11-28 20:22:40 +11:00
parent fc9e0e8c6a
commit 2904d13420
4 changed files with 21 additions and 5 deletions

View File

@ -156,3 +156,14 @@ echo -markup 'default {Error}error{Default} default'
Inside a markup string, a literal `{` character is written `\{`, and a
literal backslash (`\`) that precedes a '{' character is escaped as well
(`\\`).
The `{\}` string disables markup processing for the rest of the line,
and can be used to avoid having to escape text that might be mistaken
for markup instructions.
For example this will prevent any '{' in the current buffer name from
being incorrectly interpreted as markup instructions.
----
echo -markup "{Information}name:{\} %val{bufname}"
----

View File

@ -44,20 +44,20 @@ define-command -params ..1 \
/^!TAGROOT\t/ { tagroot=$2 }
/[^\t]+\t[^\t]+\t\/\^.*\$?\// {
line = $0; sub(".*\t/\\^", "", line); sub("\\$?/$", "", line);
menu_info = line; gsub("!", "!!", menu_info); gsub(/^[\t ]+/, "", menu_info); gsub("{", "\\{", menu_info); gsub(/\t/, " ", menu_info);
menu_info = line; gsub("!", "!!", menu_info); gsub(/^[\t ]+/, "", menu_info); gsub(/\t/, " ", menu_info);
keys = line; gsub(/</, "<lt>", keys); gsub(/\t/, "<c-v><c-i>", keys); gsub("!", "!!", keys); gsub("&", "&&", keys); gsub("#", "##", keys); gsub("\\|", "||", keys); gsub("\\\\/", "/", keys);
menu_item = $2; gsub("!", "!!", menu_item);
edit_path = path($2); gsub("&", "&&", edit_path); gsub("#", "##", edit_path); gsub("\\|", "||", edit_path);
select = $1; gsub(/</, "<lt>", select); gsub(/\t/, "<c-v><c-i>", select); gsub("!", "!!", select); gsub("&", "&&", select); gsub("#", "##", select); gsub("\\|", "||", select);
out = out "%!" menu_item ": {MenuInfo}" menu_info "! %!evaluate-commands %# try %& edit -existing %|" edit_path "|; execute-keys %|/\\Q" keys "<ret>vc| & catch %& fail unable to find tag &; try %& execute-keys %|s\\Q" select "<ret>| & # !"
out = out "%!" menu_item ": {MenuInfo}{\\}" menu_info "! %!evaluate-commands %# try %& edit -existing %|" edit_path "|; execute-keys %|/\\Q" keys "<ret>vc| & catch %& fail unable to find tag &; try %& execute-keys %|s\\Q" select "<ret>| & # !"
}
/[^\t]+\t[^\t]+\t[0-9]+/ {
menu_item = $2; gsub("!", "!!", menu_item);
select = $1; gsub(/</, "<lt>", select); gsub(/\t/, "<c-v><c-i>", select); gsub("!", "!!", select); gsub("&", "&&", select); gsub("#", "##", select); gsub("\\|", "||", select);
menu_info = $3; gsub("!", "!!", menu_info); gsub("{", "\\{", menu_info);
menu_info = $3; gsub("!", "!!", menu_info);
edit_path = path($2); gsub("!", "!!", edit_path); gsub("#", "##", edit_path); gsub("&", "&&", edit_path); gsub("\\|", "||", edit_path);
line_number = $3;
out = out "%!" menu_item ": {MenuInfo}" menu_info "! %!evaluate-commands %# try %& edit -existing %|" edit_path "|; execute-keys %|" line_number "gx| & catch %& fail unable to find tag &; try %& execute-keys %|s\\Q" select "<ret>| & # !"
out = out "%!" menu_item ": {MenuInfo}{\}" menu_info "! %!evaluate-commands %# try %& edit -existing %|" edit_path "|; execute-keys %|" line_number "gx| & catch %& fail unable to find tag &; try %& execute-keys %|s\\Q" select "<ret>| & # !"
}
END { print ( length(out) == 0 ? "fail no such tag " ENVIRON["tagname"] : "menu -markup -auto-single " out ) }
# Ensure x is an absolute file path, by prepending with tagroot

View File

@ -44,7 +44,7 @@ declare-option -docstring "name of the client in which all source code jumps wil
define-command -hidden make-open-error -params 4 %{
evaluate-commands -try-client %opt{jumpclient} %{
edit -existing "%arg{1}" %arg{2} %arg{3}
echo -markup "{Information}%arg{4}"
echo -markup "{Information}{\}%arg{4}"
try %{ focus }
}
}

View File

@ -280,6 +280,11 @@ DisplayLine parse_display_line(StringView line, const FaceRegistry& faces, const
// closing is now at the first char of "}}", advance it to the second
++closing;
}
else if (closing == it+2 and *(it+1) == '\\')
{
pos = closing + 1;
break;
}
else
face = faces[{it+1, closing}];
it = closing;