Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim.vim: Opt out of vimSearch* #14423

Open
zzzyxwvut opened this issue Apr 5, 2024 · 2 comments
Open

vim.vim: Opt out of vimSearch* #14423

zzzyxwvut opened this issue Apr 5, 2024 · 2 comments
Assignees
Labels

Comments

@zzzyxwvut
Copy link
Contributor

Steps to reproduce

With mostly automatic vim9-line-continuation support for
Vim9 scripts, backslashes are typically not required at the
start of each line for a multi-line ternary operator ?:.

For example,

vim9script
# VIM_TEST_SETUP let b:vimsyn_nosearch = 1

const truthy: number = false
    ? (0
    )
    : (1
    )
echo truthy

Currently, vimSearch* would claim lines matching ^\s*?.

Expected behaviour

Can we introduce a new variable, say, b:vimsyn_nosearch and
have the syntax file query for its presence before deciding
whether to define vimSearch* matches. In addition, for Vim
scripts that may have both [?/] commands and ?: operators
in the same file, can we compromise a little by recognising
parentheses in vimSearch (for functions and arithmetic).

Something along the lines of,

diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim
index 5b956703b..55178096a 100644
--- a/runtime/syntax/vim.vim
+++ b/runtime/syntax/vim.vim
@@ -826,8 +826,10 @@ syn match	vimCommentTitleLeader	'"\s\+'ms=s+1	contained
 
 " Searches And Globals: {{{2
 " ====================
-syn match	vimSearch	'^\s*[/?].*'		contains=vimSearchDelim
-syn match	vimSearchDelim	'^\s*\zs[/?]\|[/?]$'	contained
+if !exists("b:vimsyn_nosearch")
+ syn match	vimSearch	'^\s*[/?].*'		contains=vimSearchDelim,vimOperParen
+ syn match	vimSearchDelim	'^\s*\zs[/?]\|[/?]$'	contained
+endif
 syn region	vimGlobal	matchgroup=Statement start='\<g\%[lobal]!\=/'  skip='\\.' end='/'	skipwhite nextgroup=vimSubst1
 syn region	vimGlobal	matchgroup=Statement start='\<v\%[global]!\=/' skip='\\.' end='/'	skipwhite nextgroup=vimSubst1

@dkearns?

Version of Vim

v9.1.0263

Environment

GNU/Linux Debian (testing/trixie)

Logs and stack traces

No response

@zzzyxwvut zzzyxwvut added the bug label Apr 5, 2024
@dkearns dkearns self-assigned this Apr 5, 2024
@dkearns
Copy link
Contributor

dkearns commented Apr 5, 2024

In Vim9 script the search commands require a colon prefix, so when we get around to improving the Vim9 support the ? in your example can only match the ternary operator.

I'd generally prefer to avoid adding this sort of heuristic kludge unless strictly necessary.

I'll start committing some of the Vim 9 fixes I have this week and then we can look at fixing these things.

@zzzyxwvut
Copy link
Contributor Author

I see. In Vim9 syntax:

vim9script

:?truthy
const truthy: number = false
    ? (0
    )
    : (1
    )
echo truthy

and in legacy Vim syntax:

?truthy
let truthy = 0
\   ? (0
\   )
\   : (1
\   )
echo truthy

And a definition for the ternary operator, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants