Loading ...
Sorry, an error occurred while loading the content.

Re: Way to cancel the change that prompts FileChangedRO event?

Expand Messages
  • Antoine J. Mechelynck
    ... [...] gvim 6.2 (release) has indeed a :stopinsert command (command-line completion on :stopi finds it), but there is no help tag for it (:help :stopinsert
    Message 1 of 11 , Jun 1, 2003
    • 0 Attachment
      Stahlman Family <stahlmana@...> wrote:
      > Benji,
      > Thanks. I tried :undo as well. The problem is that Vim doesn't
      > apply the changes to the text until after the autocommands for
      > FileChangedRO have completed, and there is no way to tell Vim from
      > within the autocommand to skip making the changes. I didn't see the
      > stopinsert command in help. Oh well... I guess if I unwittingly
      > attempt to change a version-controlled file that I don't really want
      > to check out, it's not too much to ask that I do an undo once I have
      > realized my mistake...
      >
      > Thanks,
      > Brett S.

      [...]

      gvim 6.2 (release) has indeed a :stopinsert command (command-line completion
      on :stopi finds it), but there is no help tag for it (:help :stopinsert
      gives an error, even after :helptags $VIMRUNTIME/doc). The help for
      :stopinsert is located in insert.txt, immediately after the help for
      :startinsert, but it lacks a line above it saying *:stopi* *:stopinsert*
      (that additional line should come immediately before line 948 in my version
      of insert.txt, dated 2003 May 20 "for version 6.2").

      Regards,
      Tony.
    • Hari Krishna Dara
      ... skip ... If there is a way to make Vim believe that a change was never attempted on this file, it will be more useful, because once you undo, you can t
      Message 2 of 11 , Jun 2, 2003
      • 0 Attachment
        On Sun, 1 Jun 2003 at 10:25pm, Stahlman Family wrote:

        > Benji,
        > Thanks. I tried :undo as well. The problem is that Vim doesn't apply the
        > changes to the text until after the autocommands for FileChangedRO have
        > completed, and there is no way to tell Vim from within the autocommand to
        skip
        > making the changes. I didn't see the stopinsert command in help. Oh well... I
        > guess if I unwittingly attempt to change a version-controlled file that I
        > don't really want to check out, it's not too much to ask that I do an undo
        > once I have realized my mistake...
        >
        > Thanks,
        > Brett S.
        >

        If there is a way to make Vim believe that a change was never attempted
        on this file, it will be more useful, because once you undo, you can't
        expect to get the FileChangedRO autocommand again even when you make a
        genuine attempt to edit it later on.

        For the original question, there is probably no direct way of doing it.
        As you said, the change is not attempted by Vim until the autocommand is
        completed. We need to have an autocommand triggered right after the
        change attempt is completed. I can only think of CursorHold which can
        work in this case. How about something like this (untested):


        let s:_updatetime = &updatetime
        set updatetime=1 " Let it be triggered as soon as possible.
        aug CancelChanges
        au!
        let bufName = substitute(bufname('%'), "\\\\", '/', 'g')
        let bufName = escape(bufName, '[,{ ')
        exec 'au CursorHold ' . bufName . ' :call <SID>CancelChanges()'
        aug END


        function! s:CancelChanges()
        let updatetime = s:_updatetime
        aug CancelChanges
        au!
        aug END

        stopinsert " Vim 6.2
        undo
        endfunction


        If there are other CursorHold autocommands defined, then they will also
        get triggered, but I can't imagine that to be harmful.

        HTH,
        Hari


        __________________________________
        Do you Yahoo!?
        Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
        http://calendar.yahoo.com
      • Stahlman Family
        Hari, Thanks. I was thinking along these lines yesterday, but wasn t sure what the granularity was on the CursorHold event - i.e., how sure I could be that it
        Message 3 of 11 , Jun 2, 2003
        • 0 Attachment
          Hari,
          Thanks. I was thinking along these lines yesterday, but wasn't sure what
          the granularity was on the CursorHold event - i.e., how sure I could be that
          it would fire immediately after the change was made. I see that you've set it
          to 1ms, which I'm guessing may really be 55 ms or so on a Windows system, but
          even then, the delay would not be noticeable (provided the user is not
          frantically pressing keys or moving the mouse in an attempt to undo the change
          :-), so this would probably be a perfectly good solution. Thanks for the
          implementation code,

          Brett S.

          ----- Original Message -----
          From: "Hari Krishna Dara" <hari_vim@...>
          To: "Stahlman Family" <stahlmana@...>
          Cc: "Benji Fisher" <benji@...>; <vim@...>
          Sent: Monday, June 02, 2003 1:03 PM
          Subject: Re: Way to cancel the change that prompts FileChangedRO event?


          >
          > On Sun, 1 Jun 2003 at 10:25pm, Stahlman Family wrote:
          >
          > > Benji,
          > > Thanks. I tried :undo as well. The problem is that Vim doesn't apply
          the
          > > changes to the text until after the autocommands for FileChangedRO have
          > > completed, and there is no way to tell Vim from within the autocommand to
          > skip
          > > making the changes. I didn't see the stopinsert command in help. Oh
          well... I
          > > guess if I unwittingly attempt to change a version-controlled file that I
          > > don't really want to check out, it's not too much to ask that I do an undo
          > > once I have realized my mistake...
          > >
          > > Thanks,
          > > Brett S.
          > >
          >
          > If there is a way to make Vim believe that a change was never attempted
          > on this file, it will be more useful, because once you undo, you can't
          > expect to get the FileChangedRO autocommand again even when you make a
          > genuine attempt to edit it later on.
          >
          > For the original question, there is probably no direct way of doing it.
          > As you said, the change is not attempted by Vim until the autocommand is
          > completed. We need to have an autocommand triggered right after the
          > change attempt is completed. I can only think of CursorHold which can
          > work in this case. How about something like this (untested):
          >
          >
          > let s:_updatetime = &updatetime
          > set updatetime=1 " Let it be triggered as soon as possible.
          > aug CancelChanges
          > au!
          > let bufName = substitute(bufname('%'), "\\\\", '/', 'g')
          > let bufName = escape(bufName, '[,{ ')
          > exec 'au CursorHold ' . bufName . ' :call <SID>CancelChanges()'
          > aug END
          >
          >
          > function! s:CancelChanges()
          > let updatetime = s:_updatetime
          > aug CancelChanges
          > au!
          > aug END
          >
          > stopinsert " Vim 6.2
          > undo
          > endfunction
          >
          >
          > If there are other CursorHold autocommands defined, then they will also
          > get triggered, but I can't imagine that to be harmful.
          >
          > HTH,
          > Hari
          >
          >
          > __________________________________
          > Do you Yahoo!?
          > Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
          > http://calendar.yahoo.com
          >
          >
        • Hari Krishna Dara
          ... change ... and when you get this working, I would appreciate if you post the working version here. I would like to use it for my Perforce plugin as well :)
          Message 4 of 11 , Jun 3, 2003
          • 0 Attachment
            On Mon, 2 Jun 2003 at 10:40pm, Stahlman Family wrote:

            > Hari,
            > Thanks. I was thinking along these lines yesterday, but wasn't sure what
            > the granularity was on the CursorHold event - i.e., how sure I could be that
            > it would fire immediately after the change was made. I see that you've set it
            > to 1ms, which I'm guessing may really be 55 ms or so on a Windows system, but
            > even then, the delay would not be noticeable (provided the user is not
            > frantically pressing keys or moving the mouse in an attempt to undo the
            change
            > :-), so this would probably be a perfectly good solution. Thanks for the
            > implementation code,
            >
            > Brett S.

            and when you get this working, I would appreciate if you post the
            working version here. I would like to use it for my Perforce plugin as
            well :)

            BTW, anyone has any tricks to make Vim continue to fire FileChangedRO
            event after cancelling the attempt to modify the file? Added to the
            other workaround, the combo will make it an ideal feature to have in any
            SCM plugin.

            Thanks,
            Hari

            __________________________________
            Do you Yahoo!?
            Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
            http://calendar.yahoo.com
          • Benji Fisher
            ... Does :doautocmd not work? HTH --Benji Fisher
            Message 5 of 11 , Jun 3, 2003
            • 0 Attachment
              Hari Krishna Dara wrote:

              > BTW, anyone has any tricks to make Vim continue to fire FileChangedRO
              > event after cancelling the attempt to modify the file? Added to the
              > other workaround, the combo will make it an ideal feature to have in any
              > SCM plugin.

              Does :doautocmd not work?

              HTH --Benji Fisher
            • Hari Krishna Dara
              ... I am not sure what you mean, when exactly would you execute :doautocmd here? The intention is to know when the user first starts modifying a readonly file,
              Message 6 of 11 , Jun 3, 2003
              • 0 Attachment
                On Tue, 3 Jun 2003 at 2:55pm, Benji Fisher wrote:

                > Hari Krishna Dara wrote:
                >
                > > BTW, anyone has any tricks to make Vim continue to fire FileChangedRO
                > > event after cancelling the attempt to modify the file? Added to the
                > > other workaround, the combo will make it an ideal feature to have in any
                > > SCM plugin.
                >
                > Does :doautocmd not work?
                >
                > HTH --Benji Fisher
                >

                I am not sure what you mean, when exactly would you execute :doautocmd
                here? The intention is to know when the user first starts modifying a
                readonly file, and currently there is only one way of doing this, ie
                through FileChangedRO autocommand. Currently Vim fires this even only
                the first time you attempt and if you can cancel that change and try
                again subsequently, the event is not fired again (even if you reload the
                file etc.).

                Thanks,
                Hari

                __________________________________
                Do you Yahoo!?
                Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
                http://calendar.yahoo.com
              • Benji Fisher
                ... Sorry, I misunderstood the question. I suppose you have already tried setting nomodified and nomodifiable and readonly etc.? I do not have any
                Message 7 of 11 , Jun 3, 2003
                • 0 Attachment
                  Hari Krishna Dara wrote:
                  > On Tue, 3 Jun 2003 at 2:55pm, Benji Fisher wrote:
                  >
                  >
                  >>Hari Krishna Dara wrote:
                  >>
                  >>
                  >>>BTW, anyone has any tricks to make Vim continue to fire FileChangedRO
                  >>>event after cancelling the attempt to modify the file? Added to the
                  >>>other workaround, the combo will make it an ideal feature to have in any
                  >>>SCM plugin.
                  >>
                  >> Does :doautocmd not work?
                  >>
                  >>HTH --Benji Fisher
                  >>
                  >
                  >
                  > I am not sure what you mean, when exactly would you execute :doautocmd
                  > here? The intention is to know when the user first starts modifying a
                  > readonly file, and currently there is only one way of doing this, ie
                  > through FileChangedRO autocommand. Currently Vim fires this even only
                  > the first time you attempt and if you can cancel that change and try
                  > again subsequently, the event is not fired again (even if you reload the
                  > file etc.).

                  Sorry, I misunderstood the question. I suppose you have already tried
                  setting 'nomodified' and 'nomodifiable' and 'readonly' etc.? I do not have any
                  better suggestions.

                  --Benji Fisher
                • Hari Krishna Dara
                  ... any ... Yes, setting those will not help. Vim must be registering the fact that this event has been already fired, so the trick would probably work towards
                  Message 8 of 11 , Jun 3, 2003
                  • 0 Attachment
                    On Tue, 3 Jun 2003 at 4:14pm, Benji Fisher wrote:
                    > >
                    > >
                    > > I am not sure what you mean, when exactly would you execute :doautocmd
                    > > here? The intention is to know when the user first starts modifying a
                    > > readonly file, and currently there is only one way of doing this, ie
                    > > through FileChangedRO autocommand. Currently Vim fires this even only
                    > > the first time you attempt and if you can cancel that change and try
                    > > again subsequently, the event is not fired again (even if you reload the
                    > > file etc.).
                    >
                    > Sorry, I misunderstood the question. I suppose you have already tried
                    > setting 'nomodified' and 'nomodifiable' and 'readonly' etc.? I do not have
                    any
                    > better suggestions.
                    >
                    > --Benji Fisher

                    Yes, setting those will not help. Vim must be registering the fact that
                    this event has been already fired, so the trick would probably work
                    towards clearing it. I am not familar with the code, so I don't know if
                    it is possible at all.

                    Thank you,
                    Hari

                    __________________________________
                    Do you Yahoo!?
                    Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
                    http://calendar.yahoo.com
                  Your message has been successfully submitted and would be delivered to recipients shortly.