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

PATCH: cmdline editing: remove last pathname token

Expand Messages
  • Adek336
    Hi! When using TAB for filename completion sometimes you get a few levels too deep like ... so you have to use backspace to get back to ... and that is
    Message 1 of 14 , Jul 21, 2008
    • 0 Attachment
      Hi! When using TAB for filename completion sometimes you get a few
      levels too deep like
      :e /a/b/c/d/e/f-long-path-name-here/
      so you have to use backspace to get back to
      :e /a/b/c/d/e/

      and that is annoying.

      The patch below makes Ctrl-T remove the last pathname component by
      removing chars up to the first found slash or space character. I chose
      Ctrl-T very arbitraly, I don't know if this is a good choice.

      Is this feature acceptable?


      *** vim71-org/src/ex_getln.c 2007-05-07 21:47:23.000000000 +0200
      --- vim71/src/ex_getln.c 2008-07-21 13:09:41.000000000 +0200
      ***************
      *** 1411,1416 ****
      --- 1411,1427 ----
      break;
      goto cmdline_changed;

      + //+++- [ ADIPE ] {
      + case Ctrl_T:
      + if ( ccline.cmdlen )
      + do {
      + ccline.cmdlen--;
      + ccline.cmdpos--;
      + } while ( (ccline.cmdlen>0) &&
      + (ccline.cmdbuff[ccline.cmdlen]) != ' ' &&
      ccline.cmdbuff[ccline.cmdlen-1] != '/');
      + redrawcmd();
      + goto cmdline_changed;
      + //+++- [ ADIPE ] }
      case Ctrl_N: /* next match */
      case Ctrl_P: /* previous match */
      if (xpc.xp_numfiles > 0)





      *** vim71-org/cmdline.txt 2008-06-17 17:31:42.000000000 +0200
      --- vim71/cmdline.txt 2008-07-21 13:41:29.000000000 +0200
      ***************
      *** 119,124 ****
      --- 119,127 ----
      <
      Note: if the command-line becomes empty with one of
      the
      delete commands, Command-line mode is quit.
      + *c_CTRL-T*
      + CTRL-T remove the last path component; removes all characters
      up to the first found slash '/' or space character.
      +
      *c_<Insert>*
      <Insert> Toggle between insert and overstrike. {not in Vi}

      ***************

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Bram Moolenaar
      ... It can be useful, especially because CTRL-W deletes too much. I only include patches from people who give me their full name. For copyright reasons, and I
      Message 2 of 14 , Jul 21, 2008
      • 0 Attachment
        Adek336 wrote:

        > Hi! When using TAB for filename completion sometimes you get a few
        > levels too deep like
        > :e /a/b/c/d/e/f-long-path-name-here/
        > so you have to use backspace to get back to
        > :e /a/b/c/d/e/
        >
        > and that is annoying.
        >
        > The patch below makes Ctrl-T remove the last pathname component by
        > removing chars up to the first found slash or space character. I chose
        > Ctrl-T very arbitraly, I don't know if this is a good choice.
        >
        > Is this feature acceptable?

        It can be useful, especially because CTRL-W deletes too much.

        I only include patches from people who give me their full name. For
        copyright reasons, and I find it asocial to communicate with people
        whose name I don't know.

        Your patch should probably use 'isfname' and also stop at characters
        that are not included.

        The layout should be fixed to match the rest of the code.

        --
        GALAHAD: No. Look, I can tackle this lot single-handed!
        GIRLS: Yes, yes, let him Tackle us single-handed!
        "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

        /// Bram Moolenaar -- Bram@... -- 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
        -~----------~----~----~----~------~----~------~--~---
      • Craig Barkhouse
        ... Just from reading the patch, it seems like there are a couple of problems. ... Craig --~--~---------~--~----~------------~-------~--~----~ You received
        Message 3 of 14 , Jul 21, 2008
        • 0 Attachment
          Adek336 wrote:
          > The patch below makes Ctrl-T remove the last pathname component by
          > removing chars up to the first found slash or space character. I chose
          > Ctrl-T very arbitraly, I don't know if this is a good choice.


          Just from reading the patch, it seems like there are a couple of problems.

          1) It only handles forward slashes. Consider:
          :e C:\Users\Craig\Documents\

          2) Paths can have spaces in them. Using TAB completion, spaces get escaped using backslashes. Consider:
          :e C:\Program\ Files\Common\ Files\


          Craig


          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_dev" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Andy Wokula
          ... Isn t it desirable to put features in Vim scripts if possible? Here is an improved version of the Ctrl-T mapping posted to vim_use: cnoremap
          Message 4 of 14 , Jul 22, 2008
          • 0 Attachment
            Bram Moolenaar schrieb:
            >
            > Adek336 wrote:
            >
            >> Hi! When using TAB for filename completion sometimes you get a few
            >> levels too deep like
            >> :e /a/b/c/d/e/f-long-path-name-here/
            >> so you have to use backspace to get back to
            >> :e /a/b/c/d/e/
            >>
            >> and that is annoying.
            >>
            >> The patch below makes Ctrl-T remove the last pathname component by
            >> removing chars up to the first found slash or space character. I chose
            >> Ctrl-T very arbitraly, I don't know if this is a good choice.
            >>
            >> Is this feature acceptable?

            > It can be useful, especially because CTRL-W deletes too much.

            > Your patch should probably use 'isfname' and also stop at characters
            > that are not included.

            Isn't it desirable to put features in Vim scripts if possible? Here is
            an improved version of the Ctrl-T mapping posted to vim_use:


            cnoremap <C-T> <C-\>e(RemoveLastPathComponent())<cr>

            func! RemoveLastPathComponent()
            return substitute(getcmdline(), '\%(\\ \|[\\/]\@!\f\)\+[\\/]\=$\|.$', '', '')
            endfunc


            Description:
            Ctrl-T removes the last path component. It uses 'isfname' and stops at
            characters not included, except escaped spaces. At least one character
            is always removed.

            --
            Andy


            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_dev" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Adek336
            ... Indeed, scripts are better; no need for the patch, then. Simpler codebase, the better! Adrian Panasiuk
            Message 5 of 14 , Jul 22, 2008
            • 0 Attachment
              On Jul 22, 1:52 pm, Andy Wokula <anw...@...> wrote:
              > Bram Moolenaar schrieb:
              >
              >
              >
              >
              >
              > > Adek336 wrote:
              >
              > >> Hi! When using TAB for filename completion sometimes you get a few
              > >> levels too deep like
              > >> :e /a/b/c/d/e/f-long-path-name-here/
              > >> so you have to use backspace to get back to
              > >> :e /a/b/c/d/e/
              >
              > >> and that is annoying.
              >
              > >> The patch below makes Ctrl-T remove the last pathname component by
              > >> removing chars up to the first found slash or space character. I chose
              > >> Ctrl-T very arbitraly, I don't know if this is a good choice.
              >
              > >> Is this feature acceptable?
              > > It can be useful, especially because CTRL-W deletes too much.
              > > Your patch should probably use 'isfname' and also stop at characters
              > > that are not included.
              >
              > Isn't it desirable to put features in Vim scripts if possible?  Here is
              > an improved version of the Ctrl-T mapping posted to vim_use:
              >
              > cnoremap <C-T> <C-\>e(RemoveLastPathComponent())<cr>
              >
              > func! RemoveLastPathComponent()
              >     return substitute(getcmdline(), '\%(\\ \|[\\/]\@!\f\)\+[\\/]\=$\|.$', '', '')
              > endfunc
              >
              > Description:
              > Ctrl-T removes the last path component.  It uses 'isfname' and stops at
              > characters not included, except escaped spaces.  At least one character
              > is always removed.
              >
              > --
              > Andy

              Indeed, scripts are better; no need for the patch, then. Simpler
              codebase, the better!

              Adrian Panasiuk
              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_dev" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • Ag. D. Hatzimanikas
              Hi Andy, ... This is quite useful as I am using it often, thanks. On the same spirit to improve the command line vim experience, here is another function to
              Message 6 of 14 , Jul 28, 2008
              • 0 Attachment
                Hi Andy,

                On Tue, Jul 22, at 01:52 Andy Wokula wrote:
                >
                > Isn't it desirable to put features in Vim scripts if possible? Here is
                > an improved version of the Ctrl-T mapping posted to vim_use:
                >
                >
                > cnoremap <C-T> <C-\>e(RemoveLastPathComponent())<cr>
                >
                > func! RemoveLastPathComponent()
                > return substitute(getcmdline(), '\%(\\ \|[\\/]\@!\f\)\+[\\/]\=$\|.$', '', '')
                > endfunc
                >
                >
                > Description:
                > Ctrl-T removes the last path component. It uses 'isfname' and stops at
                > characters not included, except escaped spaces. At least one character
                > is always removed.
                >

                This is quite useful as I am using it often, thanks.

                On the same spirit to improve the command line vim experience, here is
                another function to complete the newest file in a given directory.

                I learned to use this feature through the wonderful zsh shell and one of its
                functions which is called the '_most_recent_file', and now ships by default
                with the distribution (at least in the development branch).

                Paste from ~/.zshrc:

                bindkey "^N" _most_recent_file
                bindkey -M vicmd "^N" _most_recent_file

                It's bind in CTRL-N, and its a part of my daily shell usage.


                And here is the vim function and the mapping (some credits also
                goes to Yuheng Xie and his CmdlineComplete plugin over the vim.org)
                http://www.vim.org/scripts/script.php?script_id=2222


                function! MostRecent()
                let cmdline = getcmdline()
                let lastspace = strridx(cmdline, ' ')
                let lastpart = strpart(cmdline, lastspace + 1)
                let command = strpart(cmdline, 0, lastspace )
                let filelist = split(glob(lastpart."*"), "\n")
                let list = []
                if !exists('s:pfile')
                let s:pfile = ''
                endif
                for file in filelist
                if !isdirectory(file)
                call add(list, getftime(file).' '.file)
                endif
                endfor
                let soreversed = reverse(sort(list))
                if !empty(soreversed)
                let new = command.' '.split(soreversed[0])[1]
                if new == cmdline
                let new = command.' '.s:pfile
                unlet s:pfile
                endif
                if len(soreversed) > 1
                let s:pfile = split(soreversed[1])[1]
                else
                let s:pfile = ''
                endif
                else
                let new = ''
                endif
                return new
                endfunction

                cnoremap <C-N> <C-\>e MostRecent()<CR>


                This will complete at least the two most recent files (otherwise, in my
                opinion, it will loose its purpose and I don't want to bloat it with more
                code when someone could use CTRL-d or <tab> to cycle over the filenames);
                consider also that you can also use the leading filename letters (to reduce
                results), so usually it will leave one or two filenames to complete.

                Note that (in this sample) it will not complete directories.

                Based on that code, one can take the opposite, the oldest filename, though
                it seems more natural to ask for the most recent file to edit/access.
                Also it can return (with a small modification) a sorted list with the last
                modification of files.

                Regards,

                Ag.

                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_dev" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • sc
                ... isn t the most recent file likely to be the swap file for the current buffer? sc --~--~---------~--~----~------------~-------~--~----~ You received this
                Message 7 of 14 , Jul 28, 2008
                • 0 Attachment
                  On Monday 28 July 2008 15:48, Ag. D. Hatzimanikas wrote:
                  >
                  > Hi Andy,
                  >
                  > On Tue, Jul 22, at 01:52 Andy Wokula wrote:
                  > >
                  > > Isn't it desirable to put features in Vim scripts if possible? Here is
                  > > an improved version of the Ctrl-T mapping posted to vim_use:
                  > >
                  > >
                  > > cnoremap <C-T> <C-\>e(RemoveLastPathComponent())<cr>
                  > >
                  > > func! RemoveLastPathComponent()
                  > > return substitute(getcmdline(), '\%(\\ \|[\\/]\@!\f\)\+[\\/]\=$\|.$', '', '')
                  > > endfunc
                  > >
                  > >
                  > > Description:
                  > > Ctrl-T removes the last path component. It uses 'isfname' and stops at
                  > > characters not included, except escaped spaces. At least one character
                  > > is always removed.
                  > >
                  >
                  > This is quite useful as I am using it often, thanks.
                  >
                  > On the same spirit to improve the command line vim experience, here is
                  > another function to complete the newest file in a given directory.
                  >
                  > I learned to use this feature through the wonderful zsh shell and one of its
                  > functions which is called the '_most_recent_file', and now ships by default
                  > with the distribution (at least in the development branch).
                  >
                  > Paste from ~/.zshrc:
                  >
                  > bindkey "^N" _most_recent_file
                  > bindkey -M vicmd "^N" _most_recent_file
                  >
                  > It's bind in CTRL-N, and its a part of my daily shell usage.
                  >
                  >
                  > And here is the vim function and the mapping (some credits also
                  > goes to Yuheng Xie and his CmdlineComplete plugin over the vim.org)
                  > http://www.vim.org/scripts/script.php?script_id=2222
                  >
                  >
                  > function! MostRecent()
                  > let cmdline = getcmdline()
                  > let lastspace = strridx(cmdline, ' ')
                  > let lastpart = strpart(cmdline, lastspace + 1)
                  > let command = strpart(cmdline, 0, lastspace )
                  > let filelist = split(glob(lastpart."*"), "\n")
                  > let list = []
                  > if !exists('s:pfile')
                  > let s:pfile = ''
                  > endif
                  > for file in filelist
                  > if !isdirectory(file)
                  > call add(list, getftime(file).' '.file)
                  > endif
                  > endfor
                  > let soreversed = reverse(sort(list))
                  > if !empty(soreversed)
                  > let new = command.' '.split(soreversed[0])[1]
                  > if new == cmdline
                  > let new = command.' '.s:pfile
                  > unlet s:pfile
                  > endif
                  > if len(soreversed) > 1
                  > let s:pfile = split(soreversed[1])[1]
                  > else
                  > let s:pfile = ''
                  > endif
                  > else
                  > let new = ''
                  > endif
                  > return new
                  > endfunction
                  >
                  > cnoremap <C-N> <C-\>e MostRecent()<CR>
                  >
                  >
                  > This will complete at least the two most recent files (otherwise, in my
                  > opinion, it will loose its purpose and I don't want to bloat it with more
                  > code when someone could use CTRL-d or <tab> to cycle over the filenames);
                  > consider also that you can also use the leading filename letters (to reduce
                  > results), so usually it will leave one or two filenames to complete.
                  >
                  > Note that (in this sample) it will not complete directories.
                  >
                  > Based on that code, one can take the opposite, the oldest filename, though
                  > it seems more natural to ask for the most recent file to edit/access.
                  > Also it can return (with a small modification) a sorted list with the last
                  > modification of files.
                  >
                  > Regards,
                  >
                  > Ag.

                  isn't the most recent file likely to be the swap file for
                  the current buffer?

                  sc



                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_dev" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • Ag. D. Hatzimanikas
                  ... Not in my case, because I place then in another directory, You can also exclude them (swap files) if you want, something like this should work if
                  Message 8 of 14 , Jul 28, 2008
                  • 0 Attachment
                    On Mon, Jul 28, at 04:12 sc wrote:
                    >
                    >
                    > isn't the most recent file likely to be the swap file for
                    > the current buffer?
                    >
                    >

                    Not in my case, because I place then in another directory,

                    You can also exclude them (swap files) if you want, something like this
                    should work

                    if !isdirectory(file) || file !~ ".swp$"

                    Regards,

                    Ag.

                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_dev" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  • sc
                    ... interesting -- i ve been trying it out and it never grabs [the most recent] swapfile -- apparently it doesn t see files whose name begins with a dot for
                    Message 9 of 14 , Jul 28, 2008
                    • 0 Attachment
                      On Monday 28 July 2008 16:29, Ag. D. Hatzimanikas wrote:
                      >
                      > On Mon, Jul 28, at 04:12 sc wrote:
                      > >
                      > >
                      > > isn't the most recent file likely to be the swap file for
                      > > the current buffer?
                      > >
                      > >
                      >
                      > Not in my case, because I place then in another directory,
                      >
                      > You can also exclude them (swap files) if you want, something like this
                      > should work
                      >
                      > if !isdirectory(file) || file !~ ".swp$"
                      >
                      > Regards,
                      >
                      > Ag.

                      interesting -- i've been trying it out and it never grabs
                      [the most recent] swapfile -- apparently it doesn't see
                      files whose name begins with a dot

                      for now, i'll be leaving it in place -- it looks useful

                      sc



                      --~--~---------~--~----~------------~-------~--~----~
                      You received this message from the "vim_dev" maillist.
                      For more information, visit http://www.vim.org/maillist.php
                      -~----------~----~----~----~------~----~------~--~---
                    • Ben Schmidt
                      ... I suspect others may find this useful too. Will someone in the discussion consider making a VimTip out of it at vim.wikia.com? Ben.
                      Message 10 of 14 , Jul 28, 2008
                      • 0 Attachment
                        sc wrote:
                        > On Monday 28 July 2008 16:29, Ag. D. Hatzimanikas wrote:
                        >> On Mon, Jul 28, at 04:12 sc wrote:
                        >>>
                        >>> isn't the most recent file likely to be the swap file for
                        >>> the current buffer?
                        >>>
                        >>>
                        >> Not in my case, because I place then in another directory,
                        >>
                        >> You can also exclude them (swap files) if you want, something like this
                        >> should work
                        >>
                        >> if !isdirectory(file) || file !~ ".swp$"
                        >>
                        >> Regards,
                        >>
                        >> Ag.
                        >
                        > interesting -- i've been trying it out and it never grabs
                        > [the most recent] swapfile -- apparently it doesn't see
                        > files whose name begins with a dot
                        >
                        > for now, i'll be leaving it in place -- it looks useful

                        I suspect others may find this useful too. Will someone in the
                        discussion consider making a VimTip out of it at vim.wikia.com?

                        Ben.



                        --~--~---------~--~----~------------~-------~--~----~
                        You received this message from the "vim_dev" maillist.
                        For more information, visit http://www.vim.org/maillist.php
                        -~----------~----~----~----~------~----~------~--~---
                      • Ag. D. Hatzimanikas
                        ... Her (fine) :) hands are on the back side of my neck (ready) to struggle me, as we going out for two days. It also needs a fix (look below). While, if you
                        Message 11 of 14 , Jul 28, 2008
                        • 0 Attachment
                          On Tue, Jul 29, at 11:17 Ben Schmidt wrote:
                          >
                          > sc wrote:
                          > > On Monday 28 July 2008 16:29, Ag. D. Hatzimanikas wrote:
                          > >> On Mon, Jul 28, at 04:12 sc wrote:
                          > >>>
                          > >>> isn't the most recent file likely to be the swap file for
                          > >>> the current buffer?
                          > >>>
                          > >>>
                          > >> Not in my case, because I place then in another directory,
                          > >>
                          > >> You can also exclude them (swap files) if you want, something like this
                          > >> should work
                          > >>
                          > >> if !isdirectory(file) || file !~ ".swp$"
                          > >>
                          > >> Regards,
                          > >>
                          > >> Ag.
                          > >
                          > > interesting -- i've been trying it out and it never grabs
                          > > [the most recent] swapfile -- apparently it doesn't see
                          > > files whose name begins with a dot
                          > >
                          > > for now, i'll be leaving it in place -- it looks useful
                          >
                          > I suspect others may find this useful too. Will someone in the
                          > discussion consider making a VimTip out of it at vim.wikia.com?
                          >

                          Her (fine) :) hands are on the back side of my neck (ready) to struggle
                          me, as we going out for two days.

                          It also needs a fix (look below).

                          While, if you do,

                          :e ~/.x[CTRL-N]

                          it pickups the two most recent hidden files that starts with .x
                          but when you do

                          :e ~/.[CTRL-N]

                          it pickups only one hidden file.

                          Also consider that I don't know if that works at all on windows
                          (although based on getftime() it should work), in which OS I don't
                          have access.

                          P.S

                          Now I noticed that if you have

                          if !isdirectory(file) || file !~ ".swp$"

                          it pickups also directories...

                          (I am dead)

                          Regar...

                          --~--~---------~--~----~------------~-------~--~----~
                          You received this message from the "vim_dev" maillist.
                          For more information, visit http://www.vim.org/maillist.php
                          -~----------~----~----~----~------~----~------~--~---
                        • sc
                          ... quirks of using glob() ... as crass and mean as it sounds, i simply don t care if it works on windows ... ah yes -- the old programmer s buggaboo: mixing
                          Message 12 of 14 , Jul 29, 2008
                          • 0 Attachment
                            On Tuesday 29 July 2008 01:12, Ag. D. Hatzimanikas wrote:
                            >
                            > On Tue, Jul 29, at 11:17 Ben Schmidt wrote:
                            > >
                            > > sc wrote:
                            > > > On Monday 28 July 2008 16:29, Ag. D. Hatzimanikas wrote:
                            > > >> On Mon, Jul 28, at 04:12 sc wrote:
                            > > >>>
                            > > >>> isn't the most recent file likely to be the swap file for
                            > > >>> the current buffer?
                            > > >>>
                            > > >>>
                            > > >> Not in my case, because I place then in another directory,
                            > > >>
                            > > >> You can also exclude them (swap files) if you want, something like this
                            > > >> should work
                            > > >>
                            > > >> if !isdirectory(file) || file !~ ".swp$"
                            > > >>
                            > > >> Regards,
                            > > >>
                            > > >> Ag.
                            > > >
                            > > > interesting -- i've been trying it out and it never grabs
                            > > > [the most recent] swapfile -- apparently it doesn't see
                            > > > files whose name begins with a dot
                            > > >
                            > > > for now, i'll be leaving it in place -- it looks useful
                            > >
                            > > I suspect others may find this useful too. Will someone in the
                            > > discussion consider making a VimTip out of it at vim.wikia.com?
                            > >
                            >
                            > Her (fine) :) hands are on the back side of my neck (ready) to struggle
                            > me, as we going out for two days.
                            >
                            > It also needs a fix (look below).
                            >
                            > While, if you do,
                            >
                            > :e ~/.x[CTRL-N]
                            >
                            > it pickups the two most recent hidden files that starts with .x
                            > but when you do
                            >
                            > :e ~/.[CTRL-N]
                            >
                            > it pickups only one hidden file.

                            quirks of using glob()

                            > Also consider that I don't know if that works at all on windows
                            > (although based on getftime() it should work), in which OS I don't
                            > have access.

                            as crass and mean as it sounds, i simply don't care if it
                            works on windows

                            > P.S
                            >
                            > Now I noticed that if you have
                            >
                            > if !isdirectory(file) || file !~ ".swp$"
                            >
                            > it pickups also directories...

                            ah yes -- the old programmer's buggaboo: mixing nots and
                            ors

                            > (I am dead)

                            a simple slip, nothing to lose sleep over -- i still like
                            it, am still leaving it in my .vimrc, at least til i look at
                            it several months from now and realize i never use it...

                            at the very least it will remain in my cluttered ~/.vim
                            directory as an example of how to do stuff

                            > Regar...

                            sc


                            --~--~---------~--~----~------------~-------~--~----~
                            You received this message from the "vim_dev" maillist.
                            For more information, visit http://www.vim.org/maillist.php
                            -~----------~----~----~----~------~----~------~--~---
                          • Tony Mechelynck
                            ... I have the following remarks about the above expression: - it uses a Vim regular expression, where the dot is a wildcard (not a Vim filename or tag
                            Message 13 of 14 , Jul 30, 2008
                            • 0 Attachment
                              On 28/07/08 23:29, Ag. D. Hatzimanikas wrote:
                              > On Mon, Jul 28, at 04:12 sc wrote:
                              >>
                              >> isn't the most recent file likely to be the swap file for
                              >> the current buffer?
                              >>
                              >>
                              >
                              > Not in my case, because I place then in another directory,
                              >
                              > You can also exclude them (swap files) if you want, something like this
                              > should work
                              >
                              > if !isdirectory(file) || file !~ ".swp$"
                              >
                              > Regards,
                              >
                              > Ag.

                              I have the following remarks about the above expression:
                              - it uses a Vim regular expression, where the dot is a wildcard (not a
                              Vim filename or tag completion expression, where the equivalent wildcard
                              would be the question mark). To match a real dot, use \. and to avoid
                              the need to backslash-escape the backslash, use single quotes.
                              - in some cases (such as when "editing anyway" after finding an existing
                              *.swp and giving an ATTENTION message), Vim will use *.swo, *.swn etc.
                              - the "or" should be "and": if (it isn't a directory) and (it isn't a
                              swapfile).
                              - filenames are usually case-sensitive on Unix but not on Windows, so
                              *.SWP will collide with a swapfile on the latter but not the former.
                              (Actually, we should test for ext2/ext3/reiser vs. FAT/NTFS filesystems,
                              but I don't know how to test that and Unix vs. Windows is close enough.)

                              Therefore I suggest

                              let save_ignorecase = &ignorecase
                              let &ignorecase = !has('unix')
                              if !isdirectory(file) && file !~ '\.sw.$'
                              ...
                              endif
                              let &ignorecase = save_ignorecase


                              Best regards,
                              Tony.
                              --
                              hundred-and-one symptoms of being an internet addict:
                              89. In addition to your e-mail address being on your business cards
                              you even have your own domain.

                              --~--~---------~--~----~------------~-------~--~----~
                              You received this message from the "vim_dev" maillist.
                              For more information, visit http://www.vim.org/maillist.php
                              -~----------~----~----~----~------~----~------~--~---
                            • Ag. D. Hatzimanikas
                              Hi Tony and thanks for the review, ... Clever. That will return 0 (noignorecase) in unix and 1 (ignorecase) in windows. ... Below are two functions, one is the
                              Message 14 of 14 , Jul 31, 2008
                              • 0 Attachment
                                Hi Tony and thanks for the review,

                                On Wed, Jul 30, at 07:16 Tony Mechelynck wrote:
                                >
                                > On 28/07/08 23:29, Ag. D. Hatzimanikas wrote:
                                > > On Mon, Jul 28, at 04:12 sc wrote:
                                > >>
                                > >> isn't the most recent file likely to be the swap file for
                                > >> the current buffer?
                                > >>
                                > >>
                                > >
                                > > Not in my case, because I place then in another directory,
                                > >
                                > > You can also exclude them (swap files) if you want, something like this
                                > > should work
                                > >
                                > > if !isdirectory(file) || file !~ ".swp$"
                                > >
                                > > Regards,
                                > >
                                > > Ag.
                                >
                                > I have the following remarks about the above expression:
                                > - it uses a Vim regular expression, where the dot is a wildcard (not a
                                > Vim filename or tag completion expression, where the equivalent wildcard
                                > would be the question mark). To match a real dot, use \. and to avoid
                                > the need to backslash-escape the backslash, use single quotes.
                                > - in some cases (such as when "editing anyway" after finding an existing
                                > *.swp and giving an ATTENTION message), Vim will use *.swo, *.swn etc.
                                > - the "or" should be "and": if (it isn't a directory) and (it isn't a
                                > swapfile).
                                > - filenames are usually case-sensitive on Unix but not on Windows, so
                                > *.SWP will collide with a swapfile on the latter but not the former.
                                > (Actually, we should test for ext2/ext3/reiser vs. FAT/NTFS filesystems,
                                > but I don't know how to test that and Unix vs. Windows is close enough.)
                                >
                                > Therefore I suggest
                                >
                                > let save_ignorecase = &ignorecase
                                > let &ignorecase = !has('unix')

                                Clever. That will return 0 (noignorecase) in unix and 1 (ignorecase)
                                in windows.

                                > if !isdirectory(file) && file !~ '\.sw.$'
                                > ...
                                > endif
                                > let &ignorecase = save_ignorecase
                                >
                                >

                                Below are two functions, one is the main loop and the second is doing
                                some filtering (files that we don't need them in the list - with three
                                examples).

                                And one generic belief.
                                I don't believe in generic solutions although the implementation can be
                                a real challenge and admirable in times. I think that the individual
                                should by his own optimize the solution to fit his needs and his style
                                and in the case of computing, the Operating System.

                                For instance I would tweak my own functions, to just use:

                                if !isdirectory(file) && file !~# '/\?v\d*'

                                avoiding to save & restore the &ignorecase variable and without any extra
                                call to another function.


                                But for the shake of completeness here are the functions.

                                function! ExcludedFiles(file)
                                let excluded = [ '/\?v\d*', '\.sw.$', '^mutt-']
                                for file in excluded
                                if a:file =~ file
                                return 1
                                endif
                                endfor
                                endfunction
                                function! MostRecent()
                                let save_ignorecase = &ignorecase
                                let &ignorecase = !has('unix')
                                let cmdline = getcmdline()
                                let lastspace = strridx(cmdline, ' ')
                                let lastpart = strpart(cmdline, lastspace + 1)
                                let command = strpart(cmdline, 0, lastspace )
                                let filelist = split(glob(lastpart."*"), "\n")
                                let list = []
                                if !exists('s:pfile')
                                let s:pfile = ''
                                endif
                                for file in filelist
                                if !isdirectory(file) && ExcludedFiles(file) != 1
                                call add(list, getftime(file).' '.file)
                                endif
                                endfor
                                let &ignorecase = save_ignorecase
                                let soreversed = reverse(sort(list))
                                if !empty(soreversed)
                                let new = command.' '.split(soreversed[0])[1]
                                if new == cmdline
                                let new = command.' '.s:pfile
                                unlet s:pfile
                                endif
                                if len(soreversed) > 1
                                let s:pfile = split(soreversed[1])[1]
                                else
                                let s:pfile = ''
                                endif
                                else
                                let new = command.' '
                                endif
                                return new
                                endfunction

                                cnoremap <C-N> <C-\>e MostRecent()<CR>

                                --~--~---------~--~----~------------~-------~--~----~
                                You received this message from the "vim_dev" maillist.
                                For more information, visit http://www.vim.org/maillist.php
                                -~----------~----~----~----~------~----~------~--~---
                              Your message has been successfully submitted and would be delivered to recipients shortly.