What is the fastest way to detect modifications to any listed buffer?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

What is the fastest way to detect modifications to any listed buffer?

jrfranklin
I would like an indicator in my 'titlestring' that informs me if ANY changes are present in ANY listed buffer.  This would be more like a global indicator for the 'modified' setting.  What is the most efficient way to do this?

Currently, I've taken the naive approach:

function! g:ChangesExist()
    let l:bufferList = filter(range(1, bufnr('$')), 'buflisted(v:val)')

    for l:bufferNumber in l:bufferList
       
        if getbufvar(l:bufferNumber, '&modified')
            return 1
        endif
    endfor

    return 0
endfunction


This seems like the most direct method, but I'm wondering if there's some simple option or function call that I'm missing...

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: What is the fastest way to detect modifications to any listed buffer?

Luc Hermitte
Hi,

> I would like an indicator in my 'titlestring' that informs me if ANY
> changes are present in ANY listed buffer.  This would be more like a
> global indicator for the 'modified' setting.  What is the most
> efficient way to do this?
>
> Currently, I've taken the naive approach:
>
> function! g:ChangesExist()
>     let l:bufferList = filter(range(1, bufnr('$')), 'buflisted(v:val)')
>     for l:bufferNumber in l:bufferList
>        
>         if getbufvar(l:bufferNumber, '&modified')
>             return 1
>         endif
>     endfor
>     return 0
> endfunction
>
>
> This seems like the most direct method, but I'm wondering if there's
> some simple option or function call that I'm missing...

If speed is really that important, get rid of the loop and use something like

   return !empty(filter(bufferList, "getbufvar(v:val, '&modified')"))

or, in a single step:

   return !empty(filter(range(1, bufnr('$')), "buflisted(v:val) && getbufvar(v:val, '&modified')"))

--
Luc Hermitte

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: What is the fastest way to detect modifications to any listed buffer?

jrfranklin
Luc,

Thanks for the reply!  Looks like doing it in one step is preferable because we're already having to filter the buffers anyway.

----------------------------------------
Jason R. Franklin
Associate Systems Software Developer
Enterprise Technology Solutions


Georgia Southern University
P.O. Box 8088
Statesboro, GA 30460
912.478.5639


On Thu, Dec 7, 2017 at 9:22 AM, Luc Hermitte <[hidden email]> wrote:
Hi,

> I would like an indicator in my 'titlestring' that informs me if ANY
> changes are present in ANY listed buffer.  This would be more like a
> global indicator for the 'modified' setting.  What is the most
> efficient way to do this?
>
> Currently, I've taken the naive approach:
>
> function! g:ChangesExist()
>     let l:bufferList = filter(range(1, bufnr('$')), 'buflisted(v:val)')
>     for l:bufferNumber in l:bufferList
>
>         if getbufvar(l:bufferNumber, '&modified')
>             return 1
>         endif
>     endfor
>     return 0
> endfunction
>
>
> This seems like the most direct method, but I'm wondering if there's
> some simple option or function call that I'm missing...

If speed is really that important, get rid of the loop and use something like

   return !empty(filter(bufferList, "getbufvar(v:val, '&modified')"))

or, in a single step:

   return !empty(filter(range(1, bufnr('$')), "buflisted(v:val) && getbufvar(v:val, '&modified')"))

--
Luc Hermitte

--
--
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 a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/rW6up-ngGLc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: What is the fastest way to detect modifications to any listed buffer?

Christian Brabandt
In reply to this post by jrfranklin

On Do, 07 Dez 2017, Jason Franklin wrote:

> I would like an indicator in my 'titlestring' that informs me if ANY changes are present in ANY listed buffer.  This would be more like a global indicator for the 'modified' setting.  What is the most efficient way to do this?
>
> Currently, I've taken the naive approach:
>
> function! g:ChangesExist()
>     let l:bufferList = filter(range(1, bufnr('$')), 'buflisted(v:val)')
>
>     for l:bufferNumber in l:bufferList
>        
>         if getbufvar(l:bufferNumber, '&modified')
>             return 1
>         endif
>     endfor
>
>     return 0
> endfunction
>
>
> This seems like the most direct method, but I'm wondering if there's some simple option or function call that I'm missing...

If you have a recent enough Vim version, you can use the getbufinfo()
function and check the changed attribute.


Christian
--
Vaterland nennt sich dieser Staat immer dann,
wenn er sich anschickt, auf Menschenmord zu gehen.
                -- Kurt Tucholsky

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: What is the fastest way to detect modifications to any listed buffer?

jrfranklin
Thanks, Christian.  I have various versions of Vim running on a lot of machines, so its best if I keep with older methods.

Will keep this in mind going forward, though!

----------------------------------------
Jason R. Franklin
Associate Systems Software Developer
Enterprise Technology Solutions


Georgia Southern University
P.O. Box 8088
Statesboro, GA 30460
912.478.5639


On Thu, Dec 7, 2017 at 9:56 AM, Christian Brabandt <[hidden email]> wrote:

On Do, 07 Dez 2017, Jason Franklin wrote:

> I would like an indicator in my 'titlestring' that informs me if ANY changes are present in ANY listed buffer.  This would be more like a global indicator for the 'modified' setting.  What is the most efficient way to do this?
>
> Currently, I've taken the naive approach:
>
> function! g:ChangesExist()
>     let l:bufferList = filter(range(1, bufnr('$')), 'buflisted(v:val)')
>
>     for l:bufferNumber in l:bufferList
>
>         if getbufvar(l:bufferNumber, '&modified')
>             return 1
>         endif
>     endfor
>
>     return 0
> endfunction
>
>
> This seems like the most direct method, but I'm wondering if there's some simple option or function call that I'm missing...

If you have a recent enough Vim version, you can use the getbufinfo()
function and check the changed attribute.


Christian
--
Vaterland nennt sich dieser Staat immer dann,
wenn er sich anschickt, auf Menschenmord zu gehen.
                -- Kurt Tucholsky

--
--
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 a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/rW6up-ngGLc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.