Monday, February 19, 2024

Re: matchbufline and ignorecase/smartcase


On Mon, Feb 19, 2024 at 12:11 PM Salman Halim <salmanhalim@gmail.com> wrote:
>
> Hello,
>
> I'm using 64-bit GVim 9.1 patches 1-95 on Windows 10.
>
> Is it possible to have matchbufline() observe 'ignorecase' and 'smartcase'? Currently, if I have 'ignorecase' and 'smartcase' set, it behaves as if only 'ignorecase' were on and gives me results that regular search, for example, don't:
>

The matchbufline() function currently only supports the 'ignorecase'
option setting and
ignores the 'smartcase' setting.

Regards,
Yegappan

Okay. I wasn't sure if it was in the plan. Thank you for explaining.

I wrote this function that does the job, but with a few defaults that I like:

1. Defaults to the current buffer
2. Uses the current search pattern if none is provided
3. Starts on line 1
4. Ends on the last line in the file (basically, defaults to the whole file)

If both ignorecase and smartcase are on and the pattern contains any uppercase letter, it temporarily turns off ignorecase to force the function to match case.

The function:

export def g:MatchBufLine( buf: any = bufnr(), pat: string = @/, lnum: any = 1, end: any = '$', dict: dict<any> = {} ): list<dict<any>>
  var matchCase: bool = false

  if ( &ignorecase && &smartcase && pat =~# '[A-Z]' )
    matchCase = true

    set noignorecase
  endif

  var result: list<dict<any>> = matchbufline( buf, pat, lnum, end, dict )

  if ( matchCase )
    set ignorecase
  endif

  return result
enddef

Hope someone else finds it useful.

Salman

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEeVwKfhMKHhChk2zFNZrkLcPLMfbawwd0fbXFPkqQKVfQ%40mail.gmail.com.

No comments:

Post a Comment