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

[PATCH] added TextDeleted and TextYanked events

Expand Messages
  • Philippe Vaucher
    Hello, I added TextDelete and TextYank events. This necessity appeared because of the small delete register getting in our way in order to implement a proper
    Message 1 of 34 , May 23, 2011
      Hello,

      I added TextDelete and TextYank events.

      This necessity appeared because of the small delete register getting
      in our way in order to implement a proper killring. There exists a
      plugin that tries to address it (YankRing.vim) but then other things
      break down, like macros with counts, not to mention the plugin is
      heavy.

      This issue was raised on irc by the-isz and myself after we realised
      we couldn't have a nice flow about editing some file like this:

      delete a word (dw), remove some trailing spaces (xxx), go to end of
      line ($), paste word (arg, dw didn't put word in registers 1-9, need
      to undo, put word in explicit register, etc)

      With this patch, we can now make a very simple "YankRing" plugin which
      only stores Yanked/Deleted texts by listening on those events, without
      interfering with all the vim commands like the original YankRing
      plugin does.

      You can test it with:

      autocmd TextDeleted * echom 'Deleted: ' . @"
      autocmd TextYanked * echom 'Yanked: ' . @"

      Tell me what you think.

      Philippe


      From f82fa9037bf6bd2013742e9502ffcdea903e8401 Mon Sep 17 00:00:00 2001
      From: Philippe Vaucher <philippe.vaucher@...>
      Date: Mon, 23 May 2011 17:08:51 +0200
      Subject: [PATCH] Added TextDeleted and TextYanked events

      ---
      runtime/doc/autocmd.txt | 13 +++++++++++++
      src/fileio.c | 2 ++
      src/ops.c | 2 ++
      src/vim.h | 2 ++
      4 files changed, 19 insertions(+), 0 deletions(-)

      diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
      index 145ecf6..057db21 100644
      --- a/runtime/doc/autocmd.txt
      +++ b/runtime/doc/autocmd.txt
      @@ -302,6 +302,9 @@ Name triggered by ~
      |InsertCharPre| when a character was typed in Insert mode, before
      inserting it

      +|TextDeleted| when some text is deleted (dw, dd, D)
      +|TextYanked| when some text is yanked (yw, yd, Y)
      +
      |ColorScheme| after loading a color scheme

      |RemoteReply| a reply from a server Vim was received
      @@ -670,6 +673,16 @@ InsertCharPre When a character is typed in
      Insert mode,
      It is not allowed to change the text |textlock|.
      The event is not triggered when 'paste' is
      set.
      + *TextDeleted*
      +TextDeleted Just after a delete (|d|) command is issued.
      + You can inspect the @" variable to
      know
      + about the deleted text.
      +
      + *TextYanked*
      +TextYanked Just after a |yank| (|y|) command is issued.
      + You can inspect the @" variable to
      know
      + about the deleted text.
      +
      *InsertEnter*
      InsertEnter Just before starting Insert mode. Also for
      Replace mode and Virtual Replace mode. The
      diff --git a/src/fileio.c b/src/fileio.c
      index 6355c79..81b09e2 100644
      --- a/src/fileio.c
      +++ b/src/fileio.c
      @@ -7688,6 +7688,8 @@ static struct event_name
      {"WinEnter", EVENT_WINENTER},
      {"WinLeave", EVENT_WINLEAVE},
      {"VimResized", EVENT_VIMRESIZED},
      + {"TextDeleted", EVENT_TEXTDELETED},
      + {"TextYanked", EVENT_TEXTYANKED},
      {NULL, (event_T)0}
      };

      diff --git a/src/ops.c b/src/ops.c
      index c41f844..375e629 100644
      --- a/src/ops.c
      +++ b/src/ops.c
      @@ -3160,6 +3160,8 @@ op_yank(oap, deleting, mess)
      # endif
      #endif

      + apply_autocmds(deleting ? EVENT_TEXTDELETED : EVENT_TEXTYANKED,
      NULL, NULL, FALSE, curbuf);
      +
      return OK;

      fail: /* free the allocated lines */
      diff --git a/src/vim.h b/src/vim.h
      index 1f4f17b..5473a21 100644
      --- a/src/vim.h
      +++ b/src/vim.h
      @@ -1290,6 +1290,8 @@ enum auto_event
      EVENT_TABENTER, /* after entering a tab page */
      EVENT_SHELLCMDPOST, /* after ":!cmd" */
      EVENT_SHELLFILTERPOST, /* after ":1,2!cmd", ":w !cmd", ":r !cmd".
      */
      + EVENT_TEXTDELETED, /* after a delete command was done (dd, dw,
      D) */
      + EVENT_TEXTYANKED, /* after a yank command was done (yy, yw, Y)
      */
      NUM_EVENTS /* MUST be the last one */
      };

      --
      1.7.4.msysgit.0

      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Bram Moolenaar
      ... Yes, in a quite clumsy way. Especially the way arguments are passed to the commands being executed. And how state needs to be saved and restored. I have
      Message 34 of 34 , Mar 6
        Ben Fritz wrote:

        > On Saturday, March 4, 2017 at 6:47:33 AM UTC-6, Bram Moolenaar wrote:
        > > Philippe Vaucher wrote:
        > >
        > > > On Monday, February 29, 2016 at 4:13:31 PM UTC+1, Björn Linse wrote:
        > > > > For the record, a version of this was merged into neovim:
        > > > > https://github.com/neovim/neovim/pull/4304
        > > >
        > > > Hehe, I just noticed that!
        > > >
        > > > Thanks :-)
        > > >
        > > > Sooooo reguarding vim, 6 years ago this was put in the TODO in the "As
        > > > soon as possible" section. Today this patch still sits there...
        > > > maybe... just maybe... is there some kind of problems with the patch
        > > > submission process? *wink wink*
        > >
        > > I don't recall anyone asking for this feature in the past six years.
        > > If there was a discussion about how this is useful for more than one
        > > user, it would have been moved up in the todo list.
        > >
        > > Including just every patch available leads to a mess. Also,
        > > autocommands are a clumsy mechanism, thus I hesitate to add more of it.
        > >
        > > I had a brief look at the comments, and it appears the functionality
        > > would be better done with some kind of callback.
        > >
        >
        > Aren't autocmds basically Vim's way of doing callbacks?

        Yes, in a quite clumsy way. Especially the way arguments are passed to
        the commands being executed. And how state needs to be saved and
        restored. I have often wondered what would be a proper solution, but I
        don't have a concrete proposal.

        Another problem with autocommands is that the caller can do anything.
        Such as a BufReadPre could open a new window. Thus the Vim code
        triggering the autocommand has to be extremely careful about assuming
        the current state. And need to abort the command sometimes. Anyway,
        using a callback mechanism probably won't solve that. But the point
        where it is called could help.

        > I don't personally feel the need for one, but I know many people would
        > like a "yank ring" style of plugin or other sort of clipboard
        > management which this patch would enable.

        Each problem usually has several ways of dealing with it. Just taking
        the first solution that comes to mind is often wrong, it may lead to the
        need for another solution later, when it turns out that the first
        solution doesn't cover all use cases.

        --
        hundred-and-one symptoms of being an internet addict:
        71. You wonder how people walk

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ an exciting new programming language -- http://www.Zimbu.org ///
        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

        --
        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
        For more options, visit https://groups.google.com/d/optout.
      Your message has been successfully submitted and would be delivered to recipients shortly.