autocommand when changing/setting option ?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

autocommand when changing/setting option ?

iler.ml
We do not have autocommand that fires when option is set/changed, right ?
vim 8 maybe ? Can this be added to do todo ?

For example, when I do 'set tw=70' I want automatically
execute "match Error /\%>70v/".

I realize I can make a custom command or function to
change two things together. But if this was a good method, then vim
never had autocommands in the first place.

Yakov


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: autocommand when changing/setting option ?

Tony Mechelynck

On 17/06/08 16:40, Yakov Lerner wrote:

> We do not have autocommand that fires when option is set/changed, right ?
> vim 8 maybe ? Can this be added to do todo ?
>
> For example, when I do 'set tw=70' I want automatically
> execute "match Error /\%>70v/".
>
> I realize I can make a custom command or function to
> change two things together. But if this was a good method, then vim
> never had autocommands in the first place.
>
> Yakov

You can define an autocommand on some other event(s) (CursorMoved and
CursorMovedI, maybe) to highlight whatever gets after the 'textwidth'.
Here's an example:

        :au CursorMoved  * exe 'match Error /\%>' . &tw . 'v/'
        :au CursorMovedI * exe 'match Error /\%>' . &tw . 'v/'

These events are already used by the matchparen.vim plugin, so you're in
good company.

Best regards,
Tony.
--
Somewhere, just out of sight, the unicorns are gathering.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: autocommand when changing/setting option ?

Bram Moolenaar
In reply to this post by iler.ml


Yakov Lerner wrote:

> We do not have autocommand that fires when option is set/changed, right ?
> vim 8 maybe ? Can this be added to do todo ?
>
> For example, when I do 'set tw=70' I want automatically
> execute "match Error /\%>70v/".
>
> I realize I can make a custom command or function to
> change two things together. But if this was a good method, then vim
> never had autocommands in the first place.

The main problem with this is that it's difficult to make this work
correctly.  Options are set in many places, where the side effects of
executing autocommands can break things.  E.g., when an option is set
from a modeline the autocommands changes buffer (or delete it!).
There have been many bugs like that in the past.

--
Change is inevitable, except from a vending machine.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: autocommand when changing/setting option ?

iler.ml
In reply to this post by Tony Mechelynck
On Tue, Jun 17, 2008 at 6:43 PM, Tony Mechelynck <[hidden email]> wrote:

On 17/06/08 16:40, Yakov Lerner wrote:
> We do not have autocommand that fires when option is set/changed, right ?
> vim 8 maybe ? Can this be added to do todo ?
>
> For example, when I do 'set tw=70' I want automatically
> execute "match Error /\%>70v/".
>
> I realize I can make a custom command or function to
> change two things together. But if this was a good method, then vim
> never had autocommands in the first place.
>
> Yakov

You can define an autocommand on some other event(s) (CursorMoved and
CursorMovedI, maybe) to highlight whatever gets after the 'textwidth'.
Here's an example:

       :au CursorMoved  * exe 'match Error /\%>' . &tw . 'v/'
       :au CursorMovedI * exe 'match Error /\%>' . &tw . 'v/'

These events are already used by the matchparen.vim plugin, so you're in
good company.


I am thinking about making use of CursorHold/CursorHoldI event. Remeber old
option value, compare it to the current value, detect option change,
handle. I have very low 'updatetime'  value anyway (200 milli).

Yakov

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---