unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Will <schimpanski@gmx.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Saving the selection before killing
Date: Fri, 13 Jul 2007 09:23:35 +0200	[thread overview]
Message-ID: <5fongrF3chc47U1@mid.individual.net> (raw)
In-Reply-To: <jwvmyy1qskp.fsf-monnier+gnu.emacs.help@gnu.org>

Hi, Stefan,

thanks for helping. However, I couldn't make your code work. I saved 
it an extra library and loaded it with "require" after adding some 
missing brackets, provide command etc.

When I evaluate

    (if (> (length string) 0)
        (if yank-handler
  	  (put-text-property 0 (length string)  )))

it still get errors like:

Debugger entered--Lisp error: (void-variable string)
   (length string)
   (> (length string) 0)
   (if (> (length string) 0) (if yank-handler (put-text-property 0 ...)))
   eval((if (> (length string) 0) (if yank-handler (put-text-property 0 
...))))
   eval-last-sexp-1(nil)
   eval-last-sexp(nil)
   call-interactively(eval-last-sexp)

Best,

Will

Stefan Monnier skrev:
>>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:
>>> From: Will <schimpanski@gmx.de>
>>> Newsgroups: gnu.emacs.help
>>> Date: Thu, 12 Jul 2007 14:14:01 +0200
>>>
>>> I'd like to copy text from external applications (e.g. web browser) to 
>>> an Emacs buffer. Often before I paste the text into an Emacs buffer I'd 
>>> like to delete text in the this buffer _without_ it being copied to the 
>>> kill-ring, because then the text from the external application gets lost.
>>>
>>> => How do I switch off that hightlighted text is copied automatially 
>>> into the kill-ring?
>>> => How do I delete a region without it getting copied into the 
>>> kill-ring, e.g. by highlighting the text and pressing <delete>?
> 
>> Try "M-x delete-selection-mode RET".  Is this what you want?
> 
> I bump into the OP's problem every once in a while, but I don't like
> delete-selection-mode for some reason, so I use the patch below instead.
> What it does is that when you kill text, before doing the kill (which will
> replace the current X-selection with the killed text), we save the current
> selection on the kill-ring (only if it doesn't come from us, of course
> since otherwise it's already in the kill-ring).  So I can simply do my kill
> and then C-y (which re-inserts what I just killed) and M-y (which replaces
> the text with the previous X-selection).
> 
> This feature is pretty unnoticeable, so I'm tempted to install it just like
> that, but maybe people want yet-another-config-var to control it?
> 
> 
>         Stefan
> 
> 
> --- orig/lisp/simple.el
> +++ mod/lisp/simple.el
> @@ -2479,6 +2536,20 @@
>  argument is not used by `insert-for-yank'.  However, since Lisp code
>  may access and use elements from the kill ring directly, the STRING
>  argument should still be a \"useful\" string for such uses."
> +  ;; To better pretend that X-selection = head-of-kill-ring, we copy other
> +  ;; application's X-selection to the kill-ring.  This comes in handy when
> +  ;; you do something like:
> +  ;; - copy a piece of text in your web-browser.
> +  ;; - have to do some editing (including killing) before you can yank
> +  ;;   that text.
> +  ;; Note: this piece of code inspired from current-kill.
> +  (let ((paste (and interprogram-paste-function
> +                    (funcall interprogram-paste-function))))
> +    (when paste
> +      (let ((interprogram-cut-function nil)
> +            (interprogram-paste-function nil))
> +        (kill-new paste))))
> +  ;; The actual kill-new functionality.
>    (if (> (length string) 0)
>        (if yank-handler
>  	  (put-text-property 0 (length string)

      parent reply	other threads:[~2007-07-13  7:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-12 12:14 Selection not to be copied into kill-ring Will
2007-07-12 12:29 ` weber
2007-07-12 12:53 ` Eli Zaretskii
2007-07-12 15:21 ` Peter Dyballa
     [not found] ` <mailman.3386.1184244752.32220.help-gnu-emacs@gnu.org>
2007-07-12 20:31   ` Saving the selection before killing (was: Selection not to be copied into kill-ring) Stefan Monnier
     [not found]   ` <jwvmyy1qskp.fsf-monnier+gnu.emacs.help@gnu.org>
2007-07-12 20:45     ` Saving the selection before killing David Kastrup
2007-07-13  7:23     ` Will [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5fongrF3chc47U1@mid.individual.net \
    --to=schimpanski@gmx.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).