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

Save file w/ orig mtime?

Expand Messages
  • Soren Andersen
    Hello, I dare to ask for a favor, cut-and-dried. If this doesn t exist yet, would somebody please write it for (me|us): A user command to save the current
    Message 1 of 5 , Jun 29, 2002
    • 0 Attachment
      Hello,

      I dare to ask for a favor, cut-and-dried. If this doesn't exist yet,
      would somebody please write it for (me|us):

      A user command to save the current buffer to the file _without updating
      the filesystem timestamp_ (on Win32 and elsewhere, i guess that's the C
      library's 'mtime', but there's considerable confusion [in my mind]
      regarding *nix 'inode time' because win32 doesn't have such an
      animal...). What I want is that the file can be edited but when saved,
      it's got the same 'last modified time' as it did before.

      Thank You!
      Soren Andersen

      --
      http://fastmail.fm - Click it, you'll feel better
    • Rimon Barr
      Hi everyone, I am looking for some help in creating a syntax and indentation file for a new language (and open-source project) that I developed called Spyce.
      Message 2 of 5 , Jun 29, 2002
      • 0 Attachment
        Hi everyone,

        I am looking for some help in creating a syntax and indentation file for a
        new language (and open-source project) that I developed called Spyce.
        Here's the blurb about Spyce:

        SPYCE is a drop-in Apache plugin that supports simple and efficient
        Python-based dynamic HTML scripting. Those who like Python and are
        familiar with JSP, or PHP, or ASP, should have a look at this engine.
        It allows one to generate dynamic HTML content just as easily, using
        Python for the dynamic parts. Its modular design makes it very flexible
        and extensible. It can also be used as a command-line utility for HTML
        pre-processing.

        You can have a look at Spyce at:
        http://spyce.sourceforge.net.

        Now, let me describe Spyce as it pertains to syntax highlighting and
        indentation. Both the syntax highlighting and the indentation are a
        mixture of HTML and Python, both of which already have syntax and
        indentation files. I just need to merge them somehow! :) I've never
        written a syntax file before, and I'm sure there are more than a few here
        that have. So, I'm looking for help and advice in designing this beast.

        The basic idea... A Spyce file starts in HTML mode. Everything (syntax
        highlighting and indentation) should work just like when one is editing
        straight HTML. Embedded in the HTML are special Spyce tags... one of the
        following four tag types:

        - [[python code]]
        - [[=python expression ]]
        - [[.spyce directive ]]
        - [[--spyce comment--]]

        That's it. Here's an example file, taken from the Spyce examples on the
        website.

        [[.module name=session]]
        [[ session.setHandler('dir', '/tmp').autoSession(10) ]]

        <html><body>
        [[-- count visits --]]
        [[ if not session.auto: {
        session.auto = 1
        }
        else: {
        session.auto = session.auto + 1
        }
        ]]
        [[-- output --]]
        You have visited this page [[=session.auto]] time(s)<br>
        Your autosession ID is: [[=session.autoID]]<br>
        Autosession expiration = 10 seconds.<br>
        </body></html>

        I want Python code to be highlighted like regular Python, and Python
        expressions should be coloured like Python code as well. Maybe the
        delimeters themselves can be a special colour. I don't know. If they are
        marked as a different class, then the user has the option to choose, but
        if it's too difficult, nevermind. Spyce directives basically have the same
        content as HTML tags. They have a tag name at the beginning (right now,
        there are three directives: include, compact and module), and then this is
        followed by some attribute=value pairs. The attr=value pairs can be quoted
        if there is a space in the value - same rules as in HTML tags. Spyce
        comments don't nest. If you want to get fancy, then in the HTML portion,
        you can escape the [[ as \[[ and the [[-- as \[[--, etc., and they will be
        considered plain text, rather than the beginning of some Spyce tag.
        Alsio, you can't nest any of these modes. You are either in HTML mode, or
        in one of the others. There you have it... That's the whole language!

        As for indentation... It's the same as HTML for the HTML portions. Inside
        Python code, we don't have regular Python code, but braced Python code.
        You indent based on open braces ({) and close braces (}), however not on
        EVERY open and close brace. Braces can also be used as Python
        dictionaries. We only want the ones that open and close code blocks. The
        way you can tell which is which is as follows. A brace "counts" if it
        comes after a colon (:). Perhaps this is not the best algorithm to use for
        indentation. I don't know. But that's it for the indentation part.

        If you've read up to this point, thank you. As you can see, it's not very
        much, for someone who has made syntax and indentation files before. I'm
        just getting stuck in all the options and details. I don't have a bird's
        eye view of the problem and the way that syntax files work. Can anyone
        help? Below, is what I have so far, and I've already spotten some problems
        with it. For example, the tag names are highlighted not only at the
        beginning of a Spyce directive, but even if that word appears anywhere in
        the directive, even as an attribute name or value. Lots of little things
        like that... If you are interested, there are lots of sample Spyce files
        on the website (http://spyce.sourceforge.net). Thank you.

        All the best,
        Rimon.
        --
        * Rimon Barr Ph.D. candidate, Computer Science, Cornell University
        | barr@... - http://www.cs.cornell.edu/barr - Y!IM: batripler
        |
        | Understanding is a kind of ecstasy.
        +---- -- Carl Sagan


        " Vim syntax file
        " Language: SPYCE
        " Maintainer: Rimon Barr <barr+spyce@...>
        " URL: http://www.cs.cornell.edu/barr
        " Last Change: 19 May 2002

        " For version 5.x: Clear all syntax items
        " For version 6.x: Quit when a syntax file was already loaded
        if version < 600
        syntax clear
        elseif exists("b:current_syntax")
        finish
        endif

        " we define it here so that included files can test for it
        if !exists("main_syntax")
        let main_syntax='spyce'
        endif

        " Read the HTML syntax to start with
        if version < 600
        so <sfile>:p:h/html.vim
        else
        runtime! syntax/html.vim
        unlet b:current_syntax
        endif

        " include python
        syn include @Python <sfile>:p:h/python.vim

        " spyce definitions
        syn keyword spyceKeywords include function contained

        syn match spyceBeginError ,\[\[, contained
        syn match spyceEndError ,\]\],

        syn region spycePython matchgroup=spyceDelim start=,\[\[, end=,\]\], contains=@Python,spyceBeginError keepend
        syn region spyceSpecial matchgroup=spyceDelim start=,\[\[\., end=,\]\], contains=spyceBeginError,spyceKeywords keepend
        syn region spycePythonEval matchgroup=spyceDelim start=,\[\[=, end=,\]\], contains=@Python,spyceBeginError keepend
        syn region spyceComment matchgroup=spyceCommentDelim start=,\[\[\--, end=,--\]\],
        syn match spyceNonBegin ,\\\[\[,
        syn match spyceNonEnd ,\\\]\],

        hi link spyceComment Comment
        hi link spyceCommentDelim Special
        hi link spyceBeginError Error
        hi link spyceEndError Error
        hi link spyceDelim PreProc
        hi link spyceKeywords PreProc

        let b:current_syntax = "spyce"
        if main_syntax == 'spyce'
        unlet main_syntax
        endif
      • Colin Keith
        ... Doesn t that rather defeat the purpose of a last modified time ? Still let see, this works on UNIX. Although you do get the this file has been modified
        Message 3 of 5 , Jun 29, 2002
        • 0 Attachment
          On Sat, Jun 29, 2002 at 06:58:14PM +0000, Soren Andersen wrote:
          > it's got the same 'last modified time' as it did before.

          Doesn't that rather defeat the purpose of a 'last modified time' ?
          Still let see, this works on UNIX. Although you do get the "this
          file has been modified since you last saved it" on subsequent
          saves, but I'm sure you can fix it if it bothers you:

          " Cause the last modified time 'not to be changed'
          " when saving a file. Actually snapshots the mtime
          " before saving, then resets after saving.
          " Needs +perl.
          " - sed bob.
          "
          if(has('perl'))
          augroup NoLastModified
          autocmd BufWritePre * call GetMtime()
          autocmd BufWritePost * call ResetMtime()
          augroup END
          :endif

          function GetMtime()
          if(!has('perl'))
          echoerr("You must have +perl to clal GetMtime()");
          return
          endif

          :perl <<__EOF__
          my $fn = VIM::Eval('expand("<afile>")');
          $mtime = (stat($fn))[9];
          __EOF__
          :endfunction

          function ResetMtime()
          if(!has('perl'))
          echoerr("You must have +perl to clal GetMtime()");
          return
          endif

          " Note the defined() as we might have edited a file
          " with an mtime of 0. Unlike, but it is possible :p
          :perl <<__EOF__
          if(defined($mtime)){
          my $fn = VIM::Eval('expand("<afile>")');
          utime($mtime, $mtime, $fn);
          }
          __EOF__
          :endfunction

          ----
          Par example:

          openbox% ls -lt header.js
          -rw-r--r-- 1 colin staff 745 Jun 11 04:27 header.js
          openbox% tail -1 header.js
          }
          openbox% vim header.js -c 'so ~/vim/mtime.vim|call append("$", "//Test")|wq'
          [blank lines snipped]
          "header.js" 25L, 745C
          "header.js" 26L, 752C written
          openbox% !ls
          ls -lt header.js
          -rw-r--r-- 1 colin staff 752 Jun 11 04:27 header.js
          openbox% tail -2 header.js
          }
          //Test
          openbox%

          Ta Da!


          --
          Then graphics games came along and the computer using portion of the human race
          forgot all about 500,000 years of language evolution and went straight back to
          the electronic equivalent of banging rocks together - the point'n'click game
          - http://www.douglasadams.com/creations/infocomjava.html
        • Soren Andersen
          ... Well, of course it does. But the example for testing that you chose is the counter-case to why I would want this, i.e. you are appending new text but I
          Message 4 of 5 , Jun 30, 2002
          • 0 Attachment
            On Sat, 29 Jun 2002, Colin Keith wrote:

            > On Sat, Jun 29, 2002 at 06:58:14PM +0000, Soren Andersen wrote:
            > : it's got the same 'last modified time' as it did before.

            > Doesn't that rather defeat the purpose of a 'last modified time' ?

            Well, of course it does. But the example for testing that you chose is
            the counter-case to why I would want this, i.e. you are appending new
            text but I would not be. I would typically be wanting to be
            (re)formatting some textfile (say, a news or email posting saved to my
            hard disk in the past) but not changing anything but wrapping /
            whitespace, therefore. In that case I'll find it very helpful not to
            have the 'mtime' updated in a way that truly would be misleading as to
            when the human-meaningful _content_ of the file was last changed.
            That's "why".

            > Still let see, this works on UNIX. Although you do get the "this file
            > has been modified since you last saved it" on subsequent saves, but I'm
            > sure you can fix it if it bothers you:

            " Cause the last modified time 'not to be changed'
            " when saving a file. Actually snapshots the mtime
            " before saving, then resets after saving.
            " Needs +perl.
            " - sed bob.

            Thank you very much for the work you put in. I have to admit I am
            puzzled by some of it. Who or what is "- sed bob" anyway? Is that a
            nickname of someone, or a reference to something about VIM?
            [... boy there are so many distractions going on around me right now
            ...]

            If I understood correctly this code can be saved as a file named
            'mtime.vim' (and you saved it under the user home directory, in
            "~/vim/mtime.vim"). Then if I ':source [pathtothisfile]mtime.vim' I
            will be able to do... something ...

            > Par example:
            openbox% ls -lt header.js
            -rw-r--r-- 1 colin staff 745 Jun 11 04:27 header.js
            openbox% tail -1 header.js
            }
            openbox% vim header.js -c 'so ~/vim/mtime.vim|call append("$", "//Test")|wq'
            [blank lines snipped]
            "header.js" 25L, 745C
            "header.js" 26L, 752C written
            openbox% !ls
            ls -lt header.js
            -rw-r--r-- 1 colin staff 752 Jun 11 04:27 header.js
            openbox% tail -2 header.js
            }
            //Test
            openbox%

            Sorry but the commands are pretty opaque to me. OK ... My understanding
            is that you are in a manner typical of an expert user, combining
            several things into a very concise (and obfuscated) form: sourcing
            (':so') the new 'mtime.vim' file and calling ('call') the func 'append'
            to add the line '//Test' then issuing command ':wq!' all in one
            compound command. OK, good enough. I will play with this and see. Will
            the mtime.vim code affect other buffers that might be open at the same
            time, because I use GVIM and usually have split windows? Will there be
            anything 'global' I have to watch out for or will only the file I've
            opened with the ':so[urce]' command be affected by the directive to
            "save with no change in mtime"?

            Thanks Again,
            Soren Andersen {'perlspinr'}


            --
            Access all of your messages and folders wherever you are!
            http://fastmail.fm - Get your mail using the web or your email software
          • Colin Keith
            ... *nod* Makes sense. ... Ignore it, its meaningless :) ... Correct. ... On this line I m opening the file and executing the commands: source mtime.vim
            Message 5 of 5 , Jul 1 3:49 AM
            • 0 Attachment
              On Mon, Jul 01, 2002 at 01:57:31AM +0000, Soren Andersen wrote:
              > text but I would not be. I would typically be wanting to be
              > (re)formatting some textfile (say, a news or email posting saved to my

              *nod* Makes sense.
              > Thank you very much for the work you put in. I have to admit I am
              > puzzled by some of it. Who or what is "- sed bob" anyway? Is that a

              Ignore it, its meaningless :)

              > "~/vim/mtime.vim"). Then if I ':source [pathtothisfile]mtime.vim' I
              > will be able to do... something ...

              Correct.

              > openbox% vim header.js -c 'so ~/vim/mtime.vim|call append("$", "//Test")|wq'

              On this line I'm opening the file and executing the commands:
              source mtime.vim " load the instructions
              call append( ... ) " Do something to change the file
              wq " Save and quit as normal.

              This is just because I could show it on the command line.

              > Sorry but the commands are pretty opaque to me. OK ... My understanding
              > is that you are in a manner typical of an expert user, combining

              heh.

              > several things into a very concise (and obfuscated) form: sourcing
              > (':so') the new 'mtime.vim' file and calling ('call') the func 'append'
              > to add the line '//Test' then issuing command ':wq!' all in one
              > compound command. OK, good enough. I will play with this and see. Will

              That's completely correct. It was just a compact way to say "look this was
              the last modification time, and the last line of the file, now I do something
              to the file and the last 2 lines are this, but the last modification time
              hasn't changed"

              > the mtime.vim code affect other buffers that might be open at the same
              > time, because I use GVIM and usually have split windows? Will there be
              > anything 'global' I have to watch out for or will only the file I've
              > opened with the ':so[urce]' command be affected by the directive to
              > "save with no change in mtime"?

              Yes it will affect all saves. If you wanted to restrict it, change the
              autocmd pattern match from * to something else. If you only wanted it to
              apply to files in your mail directory (for example) you could replace the
              * with a directory to match. See the help for "autocmd" for details on this.

              Colin.

              --
              Then graphics games came along and the computer using portion of the human race
              forgot all about 500,000 years of language evolution and went straight back to
              the electronic equivalent of banging rocks together - the point'n'click game
              - http://www.douglasadams.com/creations/infocomjava.html
            Your message has been successfully submitted and would be delivered to recipients shortly.