emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Improving X selection?


From: David De La Harpe Golden
Subject: Re: Improving X selection?
Date: Wed, 17 Oct 2007 02:05:45 +0100

If you've done the stuff in my previous mail, another IMHO useful
change (that I use but I didn't include in the previous mail because
it is a little more confusing if you don't expect it) is to make
current-kill propagate its return back out via
interprogram-cut-function if  N  > zero, and do-not-move is nil, and
interprogram-cut-function is set.

Then, emacs acts a bit like a clipboard history manager or pigeonholes
- you can cut/copy in another X11 application A, C-y into emacs,
cut/copy in another X11 application B, C-y into emacs, (etc... ).
Then, in emacs cycle between the various cuts now in the emacs kill
ring with M-y, then when you find the right one, it can be pasted back
into an external X11 application directly since it's already in
CLIPBOARD (assuming previous mail). Not too different in end result to
just copying to a scratch buffer from the various apps and then
selectively copying back out from it, but hey.

e.g.

; based on simple.el/current-kill

(defun current-kill (n &optional do-not-move)
  "Rotate the yanking point by N places, and then return that kill.
If N is zero, `interprogram-paste-function' is set, and calling it
returns a string, then that string is added to the front of the
kill ring and returned as the latest kill.

If N > zero, `interprogram-cut-function' is set, and do-not-move
is nil, then also call the `interprogram-cut-function' with the
latest kill - i.e. propagate it back out to the host environment
clipboard.

If optional arg DO-NOT-MOVE is non-nil, then don't actually move the
yanking point; just return the Nth kill forward."
  (let ((interprogram-paste (and (= n 0)
                                 interprogram-paste-function
                                 (funcall interprogram-paste-function))))
    (if interprogram-paste
        (progn
          ;; Disable the interprogram cut function when we add the new
          ;; text to the kill ring, so Emacs doesn't try to own the
          ;; selection, with identical text.
          (let ((interprogram-cut-function nil))
            (kill-new interprogram-paste))
          interprogram-paste)
      (or kill-ring (error "Kill ring is empty"))
      (let ((ARGth-kill-element
             (nthcdr (mod (- n (length kill-ring-yank-pointer))
                          (length kill-ring))
                     kill-ring)))
        (unless do-not-move
            (setq kill-ring-yank-pointer ARGth-kill-element)
            (when (and (> n 0) interprogram-cut-function)
                (funcall interprogram-cut-function (car ARGth-kill-element))))
        (car ARGth-kill-element)))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]