Evil: Yank/Paste with System Clipboard and Evil in New Buffers

Haroogan haroogan at gmail.com
Thu Jun 27 21:53:48 CEST 2013


Hello,

Question #1:

(defun  haroogan/evil-paste-from-clipboard  ()
   "Paste text from system clipboard."
   (interactive)
   (evil-paste-from-register  ?+))

(evil-define-operator  haroogan/evil-yank-to-clipboard  (beg  end  type  yank-handler)
   "Yank text to system clipboard."
   :move-point  nil
   :repeat  nil
   (interactive  "<x><y>")
   (evil-yank  beg  end  type  ?+  yank-handler))

Paste works as intended. Yank works partly:

  * after yanking I can paste this text into other applications;
  * but I cannot paste it into the Emacs itself, i.e. by
    using|haroogan/evil-paste-from-clipboard|- it says that
    the|kill-ring|is empty; how come?
  * furthermore, bell rings when I'm yanking with this function - like
    if it was an error - that's very strange too.

For the reference, in my|.vimrc|I have the following:

" Cut to the system clipboard.
nnoremap  <C-x>  "+x
vnoremap  <C-x>  "+x
cnoremap<C-x>  "+x

" Yank to the system clipboard.
nnoremap  <C-y>  "+y
vnoremap  <C-y>  "+y
cnoremap<C-y>  "+y

" Paste from the system clipboard.
nnoremap  <C-p>  "+p
vnoremap  <C-p>  "+p
cnoremap<C-p>  "+p

What's the best way to replicate this with Evil?

Question #2:

Evil provides the following function:

(evil-define-command  evil-window-new  (count  file)
   "Splits the current window horizontally
and opens a new buffer or edits a certain FILE."
   :repeat  nil
   (interactive  "P<f>")
   (split-window  (selected-window)  count)
   (if  file
       (evil-edit  file)
     (let  ((buffer  (generate-new-buffer  "*new*")))
       (set-window-buffer  (selected-window)  buffer)
       (with-current-buffer  buffer
         (evil-normal-state)))))


In my opinion the last line reveals a huge flaw.

First of all, recently I've been writing a tiling window manager for Emacs.
Of course when I create new windows there, I create buffers as well with 
the same

generate-new-buffer

function.

And of course as suggested by the

evil-window-new

function presented above, one has to call

(with-current-buffer  buffer  (evil-normal-state))

so that Evil does not break here and works properly in this newly 
created buffer.

That's incredibly annoying for 2 reasons.
First, now, for instance, my tiling window manager has to depend on the 
Evil package just to make this little hack for those who wish to use 
Evil with my tiling window manager (including myself).
Second, you have already probably noticed that such buffers as Emacs 
Help and friends do not work with Evil properly.
And I suspect that the reason for that is the same simply because in 
case of Emacs Help buffer you could no longer inject this hackish call:

(with-current-buffer  buffer  (evil-normal-state))


I might be wrong with my implications, and I wish you could prove that I am.
I'm nowhere near an Emacs hacker, just learning (migrating from Vim), 
but may I say that defadvice to me seems to be a remedy to this problem?
Anyway, please, share your thoughts on this topic, I really hope that 
this can somehow be reimplemented in more robust way, so that Evil has 
more seamless and natural integration with the whole Emacs environment.

Kind regards,
Haroogan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ourproject.org/pipermail/implementations-list/attachments/20130627/ef70c25c/attachment.htm 


More information about the implementations-list mailing list