Trying to maintain add conceals to the generated location list, but I can not figure it out.

The current workaround is to add it manually everytime through the vim commandline, like:

: set conceallevel=1
: set concealcursor=n
: call matchadd('Conceal', 'None', 10, -1, {'conceal': '∅'})

It would be less frustrating to automate the steps described above in the function below:

" function: list multiline block code as one line in a quickfix buffer
function! Overview() abort
    let bufnr = bufnr('%')
    let items = []
    while 1
        let start = search('^{', 'cW')
        if !start
        let end = search('^}', 'W')
        let lines = getline(start, end)
        let lines = map(lines, 'trim(v:val)')
        call add(items, {
            \ 'bufnr': bufnr,
            \ 'lnum': start,
            \ 'text': join(lines, ' '),
        \ })
        call sort(items, {a, b -> a["text"] == b["text"] ? 0 : a["text"] > b["text"] ? 1 : -1})
    call setloclist(winnr(), items)

Tried to add

call matchadd('Conceal', 'None', 10, -1, {'conceal': '∅'}) 

after the line

call setloclist(winnr(), items)

but this way of frankensteining the script didn't help.

Ideally, but not nessecary, it would be nice if the generated quickfix/locationlist respected the conceals assigned to the original filetype.

That would preventing me copying and maintaing conceals from the original filetype to the function. And it would make the function filetype agnostic.

  • you would need to call the matchadd() function in the window where you want to define the concealing to be defined for (as mentioned in the other answer). However you could add the window argument to the matchadd function for the dict argument. Alternatively, you could instead of defining concealing, do a substitute on the text item so that the text will be changed to the concealed characters. Then you don't need to conceal manually afterwards. – Christian Brabandt Feb 3 at 16:50
  • (too long comment, continuing here) Note, as far as I know, there is no easy way to get the definition of concealed characters for a buffer. You would need to handle this manually by parsing the output of :syn and processing the output of getmatches() – Christian Brabandt Feb 3 at 16:51
  • @ChristianBrabandt, and could I add the matchadd within the function that generates the quickfix, whereby the function presets the quickfix window with the desired conceals? Tried to add call matchadd('Conceal', 'None', 10, -1, {'conceal': '∅'}) withint the function, but that doesn't help. Thank you. – jolanda Feb 3 at 18:12
  • as I said, you need to call matchadd from within the quickfix window. So make sure to open the quickfix window first (e.g. using :copen) – Christian Brabandt Feb 4 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.