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

Toggle 'modified' flag

Expand Messages
  • Klaus Bosau
    Hello, I d like to toggle the modified flag of a buffer from within a function. Unfortunately adding a line :set nomod to the function body didn t work
    Message 1 of 13 , Dec 17, 2002
    • 0 Attachment
      Hello,

      I'd like to toggle the 'modified' flag of a buffer from within a
      function. Unfortunately adding a line ':set nomod' to the function body
      didn't work though doing the same thing by typing the command on the
      keyboard works. Does anybody know why this fails when done in a
      script-function?

      Thanks,

      Klaus
    • Gary Holloway
      Because it s ambiguous (nomodeline modifieable modified); be more specific. se nomodified or let &modified = 0 -gary / FROM: Klaus Bosau , Dec
      Message 2 of 13 , Dec 18, 2002
      • 0 Attachment
        Because it's ambiguous (nomodeline modifieable modified); be more specific.

        se nomodified

        or

        let &modified = 0


        -gary

        / FROM: Klaus Bosau <kbosau@...>, Dec 18 6:30 2002
        | ABOUT: Toggle 'modified' flag
        |
        | Hello,
        |
        | I'd like to toggle the 'modified' flag of a buffer from within a
        | function. Unfortunately adding a line ':set nomod' to the function body
        | didn't work though doing the same thing by typing the command on the
        | keyboard works. Does anybody know why this fails when done in a
        | script-function?
        |
        | Thanks,
        |
        | Klaus
        |
        \ END: Klaus Bosau
      • Klaus Bosau
        ... Hi Gary, thanks for your reply! I tried both, but the result s been the same. It s the last line of the last executed function in the script, but the
        Message 3 of 13 , Dec 18, 2002
        • 0 Attachment
          On Wed, 18 Dec 2002, Gary Holloway wrote:

          > Because it's ambiguous (nomodeline modifieable modified); be more
          > specific.
          >
          > se nomodified
          >
          > or
          >
          > let &modified = 0

          Hi Gary,

          thanks for your reply! I tried both, but the result's been the same.
          It's the last line of the last executed function in the script, but the
          'modified' flag of the current buffer still remains unchanged. When
          typed by hand however after the script is done this works properly.
          Both commands... I don't know why.

          Thanks anyway!

          Klaus
        • Bram Moolenaar
          ... There should be no difference between typing :set nomod and using the same command in a script. Check for other things that matter (also consider the
          Message 4 of 13 , Dec 29, 2002
          • 0 Attachment
            Klaus Bosau wrote:

            > I'd like to toggle the 'modified' flag of a buffer from within a
            > function. Unfortunately adding a line ':set nomod' to the function body
            > didn't work though doing the same thing by typing the command on the
            > keyboard works. Does anybody know why this fails when done in a
            > script-function?

            There should be no difference between typing ":set nomod" and using the
            same command in a script. Check for other things that matter (also
            consider the value of 'fileformat' and 'fileencoding').

            --
            hundred-and-one symptoms of being an internet addict:
            195. Your cat has its own home page.

            /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
            /// Creator of Vim - Vi IMproved -- http://www.vim.org \\\
            \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
            \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///
          • Antoine J. Mechelynck
            ... [...] Note also (Klaus) that setting nomodified can be dangerous. The changes that are thus negated should not be vital ones because if after you set
            Message 5 of 13 , Dec 29, 2002
            • 0 Attachment
              Bram Moolenaar <Bram@...> wrote:
              > Klaus Bosau wrote:
              >
              > > I'd like to toggle the 'modified' flag of a buffer from within a
              > > function. Unfortunately adding a line ':set nomod' to the function body
              > > didn't work though doing the same thing by typing the command on the
              > > keyboard works. Does anybody know why this fails when done in a
              > > script-function?
              >
              > There should be no difference between typing ":set nomod" and using the
              > same command in a script. Check for other things that matter (also
              > consider the value of 'fileformat' and 'fileencoding').
              [...]

              Note also (Klaus) that setting 'nomodified' can be dangerous. The changes
              that are thus "negated" should not be vital ones because if after you set
              nomod you do :xa, you will exit vim without saving the changes made to the
              file just before setting nomodified on it. (Unless of course you then
              proceeded to make more changes, resulting in again marking the file as
              'modified'.)

              (I do have a few files with modelines that, among other things, set
              nomodified, but I don't do it lightly.)

              Just my 0.02 EUR
              Tony.
            • Klaus Bosau
              ... Hi, of course you re right, but the buffer referred to isn t changed at all, Antoine - in fact it s empty. This is the buffer list when the script is
              Message 6 of 13 , Dec 29, 2002
              • 0 Attachment
                On Sun, 29 Dec 2002, Antoine J. Mechelynck wrote:

                > [...]
                >
                > Note also (Klaus) that setting 'nomodified' can be dangerous. The
                > changes that are thus "negated" should not be vital ones because if
                > after you set nomod you do :xa, you will exit vim without saving the
                > changes made to the file just before setting nomodified on it. (Unless
                > of course you then proceeded to make more changes, resulting in again
                > marking the file as 'modified'.)
                >
                > (I do have a few files with modelines that, among other things, set
                > nomodified, but I don't do it lightly.)
                >
                > Just my 0.02 EUR Tony.

                Hi,

                of course you're right, but the buffer referred to isn't changed at all,
                Antoine - in fact it's empty. This is the buffer list when the script is
                source'd

                | 3 %a "[No File]" line 1

                and this is the buffer list after source'ing plugins, scripts and so on
                has ended

                | 3 %a + "[No File]" line 1

                The problem is that I can't control what happens after the script is
                done. Is there a way to set the buffer number back to one prior to
                exiting?

                Happy new year!

                Klaus
              • Klaus Bosau
                ... Hi Bram, thanks a lot for your reply! I found out that it s less a problem of the script referred to, but (maybe) a problem of a plugin sourced after mine
                Message 7 of 13 , Dec 29, 2002
                • 0 Attachment
                  On Sun, 29 Dec 2002, Bram Moolenaar wrote:

                  > There should be no difference between typing ":set nomod" and using
                  > the same command in a script. Check for other things that matter (also
                  > consider the value of 'fileformat' and 'fileencoding').

                  Hi Bram,

                  thanks a lot for your reply! I found out that it's less a problem of the
                  script referred to, but (maybe) a problem of a plugin sourced after mine
                  on start-up. The script I wrote - I usually keep it in the plugin
                  directory - creates two temporary buffers and therefore the number of
                  the current buffer when exiting isn't the same as on start-up. This
                  seems to interfere with the default behaviour of another script source'd
                  after mine. So unsetting the modified flag within the script couldn't
                  help, avoiding to put it in the plugin directory however, that's to say
                  source'ing it by hand, indeed could. This is not what I wanted, but
                  changing a buffer's number obviously isn't possible. Is this true?

                  Kind regards,

                  Klaus
                • Bram Moolenaar
                  Klaus Bosau wrote: [...] ... You cannot change the number of a buffer. Well, you could wipeout the buffer and load the file again, that results in a new
                  Message 8 of 13 , Dec 29, 2002
                  • 0 Attachment
                    Klaus Bosau wrote:

                    [...]
                    > source'ing it by hand, indeed could. This is not what I wanted, but
                    > changing a buffer's number obviously isn't possible. Is this true?

                    You cannot change the number of a buffer. Well, you could wipeout the
                    buffer and load the file again, that results in a new buffer number.
                    But that's probably not what you want.

                    --
                    hundred-and-one symptoms of being an internet addict:
                    212. Your Internet group window has more icons than your Accessories window.

                    /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
                    /// Creator of Vim - Vi IMproved -- http://www.vim.org \\\
                    \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
                    \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///
                  • Klaus Bosau
                    ... This wouldn t change the buffer s number, Bram. The script source d after mine however seems to expect the buffer number to show its usual default value
                    Message 9 of 13 , Dec 29, 2002
                    • 0 Attachment
                      On Sun, 29 Dec 2002, Bram Moolenaar wrote:

                      > > source'ing it by hand, indeed could. This is not what I wanted, but
                      > > changing a buffer's number obviously isn't possible. Is this true?
                      >
                      > You cannot change the number of a buffer. Well, you could wipeout the
                      > buffer and load the file again, that results in a new buffer number.
                      > But that's probably not what you want.

                      This wouldn't change the buffer's number, Bram. The script source'd
                      after mine however seems to expect the buffer number to show its usual
                      default value (of one), otherwise, for any reason I don't know (maybe a
                      bug), it turns on the modified flag. And this flag is then preserved
                      'til all source'ing due within the usual start-up proceeding has been
                      done. It will be present even if Vim should be lauched with an emtpy
                      file by just typing "vim" on the command-line for instance. And this is
                      what I actually wanted to avoid. The buffer should show up in its usual
                      state on start-up. Of course I could find out which one of the scripts
                      being source'd too is responsible for this, but I don't think that this
                      kind of information, despite its relevance in this special case, would
                      be a great gain for other Vim users... ;-)

                      Thanks anyway!

                      Klaus
                    • Antoine J. Mechelynck
                      Klaus Bosau wrote: [...] ... If you want to have buffer 3 become buffer 1, a recent discussion in this ML told us, from highest authority :-),
                      Message 10 of 13 , Dec 29, 2002
                      • 0 Attachment
                        Klaus Bosau <kbosau@...> wrote:
                        [...]
                        > Hi,
                        >
                        > of course you're right, but the buffer referred to isn't changed at all,
                        > Antoine - in fact it's empty. This is the buffer list when the script is
                        > source'd
                        >
                        > > 3 %a "[No File]" line 1
                        >
                        > and this is the buffer list after source'ing plugins, scripts and so on
                        > has ended
                        >
                        > > 3 %a + "[No File]" line 1
                        >
                        > The problem is that I can't control what happens after the script is
                        > done. Is there a way to set the buffer number back to one prior to
                        > exiting?
                        >
                        > Happy new year!
                        >
                        > Klaus

                        If you want to have buffer 3 become buffer 1, a recent discussion in this ML
                        told us, from highest authority :-), that it wasn't possible. Note that :ls
                        doesn't show 'unlisted' buffers, but :ls! does. What you show means that
                        initialization has opened three buffers and delisted or wiped the first two
                        (or maybe opened more than three and delisted or wiped all of them except
                        number 3). I wonder wat caused buffer 3 (the current [NoFile] buffer) to be
                        marked as modified. To see where it comes from, it might be instructive to
                        do

                        :verbose setlocal modified?

                        in the buffer in question, with the question mark

                        see
                        :help 'unlisted'
                        :help :ls!
                        :help :bw
                        :help :verbose

                        Happy new year to you too

                        HTH,
                        Tony.
                      • Klaus Bosau
                        ... Hi Antoine, sorry for the delay! The buffers in question are wiped out afterwards, thus they didn t show up in the buffer listing. (To create the buffer
                        Message 11 of 13 , Jan 1, 2003
                        • 0 Attachment
                          On Mon, 30 Dec 2002, Antoine J. Mechelynck wrote:

                          > If you want to have buffer 3 become buffer 1, a recent discussion in
                          > this ML told us, from highest authority :-), that it wasn't possible.
                          > Note that :ls doesn't show 'unlisted' buffers, but :ls! does. What you
                          > show means that initialization has opened three buffers and delisted
                          > or wiped the first two (or maybe opened more than three and delisted
                          > or wiped all of them except number 3).

                          Hi Antoine,

                          sorry for the delay! The buffers in question are wiped out afterwards,
                          thus they didn't show up in the buffer listing. (To create the buffer
                          listing I used ":ls!".)

                          > I wonder wat caused buffer 3 (the current [NoFile] buffer) to be
                          > marked as modified. To see where it comes from, it might be
                          > instructive to do
                          >
                          > :verbose setlocal modified?
                          >
                          > in the buffer in question, with the question mark

                          I entered

                          set nomodified
                          verbose setlocal modified? (resp. set verbose=20)
                          redir! > c:\vim\log

                          at the very bottom of the script, but 'log' didn't show any buffer
                          related information. The buffer in question however again has been
                          marked 'modified'.

                          In the meantime I found out that scripts residing in the plugin/
                          directory (it's the default collection) cannot be responsible for this.
                          So I'm looking for a new candidate now. ":scrip" told me that it might
                          be one of these: "filetype.vim", "menu.vim", "syntax.vim",
                          "synload.vim", "syncolor.vim", "mail.vim"

                          What do you think?

                          Klaus
                        • Antoine J. Mechelynck
                          ... [...] ... I meant you to type :verbose setlocal modified? yourself as a Vim command, not enter it into a script; and if you put it before the redir
                          Message 12 of 13 , Jan 1, 2003
                          • 0 Attachment
                            Klaus Bosau <kbosau@...> wrote:
                            > On Mon, 30 Dec 2002, Antoine J. Mechelynck wrote:
                            [...]
                            > > I wonder wat caused buffer 3 (the current [NoFile] buffer) to be
                            > > marked as modified. To see where it comes from, it might be
                            > > instructive to do
                            > >
                            > > :verbose setlocal modified?
                            > >
                            > > in the buffer in question, with the question mark
                            >
                            > I entered
                            >
                            > set nomodified
                            > verbose setlocal modified? (resp. set verbose=20)
                            > redir! > c:\vim\log
                            >
                            > at the very bottom of the script, but 'log' didn't show any buffer
                            > related information. The buffer in question however again has been
                            > marked 'modified'.

                            I meant you to type :verbose setlocal modified? yourself as a Vim command,
                            not enter it into a script; and if you put it before the redir command, it
                            won't be redirected, but its output (if any) will appear on the
                            command-line. But apparently even if you get an answer it might be for a
                            different buffer.
                            >
                            > In the meantime I found out that scripts residing in the plugin/
                            > directory (it's the default collection) cannot be responsible for this.
                            > So I'm looking for a new candidate now. ":scrip" told me that it might
                            > be one of these: "filetype.vim", "menu.vim", "syntax.vim",
                            > "synload.vim", "syncolor.vim", "mail.vim"
                            >
                            > What do you think?
                            >
                            > Klaus

                            I'm not sure what I should think. Maybe there is something pertinent to your
                            case under :help local-options, just before the *:setl* helptag.

                            Tony.
                          • Klaus Bosau
                            ... Sorry, maybe I misunderstood. I thought you wanted me to trace what happens after the script referred to is done. ... Of course you re right. Must have
                            Message 13 of 13 , Jan 1, 2003
                            • 0 Attachment
                              On Wed, 1 Jan 2003, Antoine J. Mechelynck wrote:

                              > I meant you to type :verbose setlocal modified? yourself as a Vim
                              > command, not enter it into a script;

                              Sorry, maybe I misunderstood. I thought you wanted me to trace what
                              happens after the script referred to is done.

                              > and if you put it before the redir command, it won't be redirected,
                              > but its output (if any) will appear on the command-line.

                              Of course you're right. Must have messed it up when writing it down
                              again. I took a look a few moments ago but the script showed me the
                              right order... Sorry!

                              > But apparently even if you get an answer it might be for a different
                              > buffer.

                              Well, I was interested in any kind of information related to this also
                              cause I realized that restricting the answer on buffer related topics
                              might be too strong.

                              > I'm not sure what I should think. Maybe there is something pertinent
                              > to your case under :help local-options, just before the *:setl*
                              > helptag.

                              Thanks! I'll take a look...

                              Klaus
                            Your message has been successfully submitted and would be delivered to recipients shortly.