help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: when deleting in minibuffer, don't change kill-ring


From: Tassilo Horn
Subject: Re: when deleting in minibuffer, don't change kill-ring
Date: Fri, 28 Oct 2011 08:53:04 +0200
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.90 (gnu/linux)

"Drew Adams" <drew.adams@oracle.com> writes:

>> I guess the OP means `backward-kill-word' (<M-backspace>) and
>> friends.  I'm also interested in something like that.  I want to use
>> the word, line, and region editing commands in the minibuffer, but I
>> don't want to have the killed text in the global kill-ring.
>
> I think you need deleting (non-killing) commands to remap the killing
> commands to:

Yes, that would be a possibility.

>> What I'd really like to have is a separate kill-ring for the
>> minibuffers.  I've tried
>> (dolist (b (buffer-list))
>>   (when (minibufferp b)
>>     (set-buffer b)
>>     (make-local-variable 'kill-ring)))
>> or entering a recursive edit
>>   M-: M-: (make-local-variable 'kill-ring) RET C-g,
>> but that doesn't have an effect. 
>
> Try doing it on `minibuffer-setup-hook' instead.
>
> (add-hook 'minibuffer-setup-hook
>           (lambda ()
>             (make-local-variable 'kill-ring)))

It doesn't work completely.  The good thing is that the kills I make in
the minibuffer are not in the global kill-ring anymore.  But when
reentering the minibuffer again, its value is again the global
kill-ring.

That looks to me as if on entering the minibuffer
`minibuffer-setup-hook' makes kill-ring buffer-local, but when the
minibuffer is left again, the buffer local variable is killed.

And in fact, advising `kill-all-local-variables' like so

--8<---------------cut here---------------start------------->8---
  (defadvice kill-all-local-variables (before bla activate)
    (message "killing all local vars of %s" (current-buffer)))
--8<---------------cut here---------------end--------------->8---

I get

  killing all local vars of  *Minibuf-1*
  killing all local vars of  *Minibuf-0*
  killing all local vars of  *Minibuf-1*

when leaving the minibuffer.

Using this advice, I think I finally got the intended behavior:

--8<---------------cut here---------------start------------->8---
(defadvice kill-all-local-variables (around th-keep-minibuffer-kill-ring 
activate)
  (let ((b (current-buffer)))
    (when (minibufferp b)
      (let ((kr kill-ring))
        ad-do-it
        (set (make-local-variable 'kill-ring) kr)))))
--8<---------------cut here---------------end--------------->8---

Now, when reentering the minibuffer I can yank the stuff I killed in
previous minibuffer sessions, and those kills don't show up in the
global kill-ring.

But why are the buffer-local variables of minibuffers forcefully killed,
anyway?

Bye,
Tassilo



reply via email to

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