Discussion:
when deleting in minibuffer, don't change kill-ring
(too old to reply)
filebat Mark
2011-10-27 16:35:08 UTC
Permalink
hi all

Any idea how to prohibit kill-ring being changed, when I press
"backspace" key in minibuffer?
--
Thanks & Regards

Denny Zhang
Drew Adams
2011-10-27 16:52:00 UTC
Permalink
Post by filebat Mark
how to prohibit kill-ring being changed, when I press
"backspace" key in minibuffer?
It is _not_ changed. Provide a recipe, starting from emacs -Q.

If you do need to change the binding of the key for some reason, then do so in
each of the minibuffer key maps. E.g.,

(define minibuffer-local-must-match-map (kbd "DEL")
'backward-delete-char)
etc.

But AFAICT, the global binding of DEL (and <backspace>) is in effect in the
minibuffer, and the global binding does not kill a char, it deletes it.
Tassilo Horn
2011-10-27 18:23:41 UTC
Permalink
Post by Drew Adams
how to prohibit kill-ring being changed, when I press "backspace" key
in minibuffer?
It is _not_ changed. Provide a recipe, starting from emacs -Q.
If you do need to change the binding of the key for some reason, then
do so in each of the minibuffer key maps. E.g.,
(define minibuffer-local-must-match-map (kbd "DEL")
'backward-delete-char)
etc.
But AFAICT, the global binding of DEL (and <backspace>) is in effect
in the minibuffer, and the global binding does not kill a char, it
deletes it.
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.

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. Isn't it possible to have buffer local
values for variables defined at the C level?

Another observation: why are there more than one minibuffers? Right
now, I have 4:

(dolist (b (buffer-list))
(when (minibufferp b)
(insert (format "%s is a minibuffer\n" b)))) ;; C-j
*Minibuf-1* is a minibuffer
*Minibuf-2* is a minibuffer
*Minibuf-3* is a minibuffer
*Minibuf-0* is a minibuffer

some minutes ago I had 5, all with just one emacs frame. And with emacs
-Q, I first have one and after the first window split, I have 2.

Bye,
Tassilo
Stefan Monnier
2011-10-28 01:06:53 UTC
Permalink
Post by Tassilo Horn
Another observation: why are there more than one minibuffers? Right
(dolist (b (buffer-list))
(when (minibufferp b)
(insert (format "%s is a minibuffer\n" b)))) ;; C-j
*Minibuf-1* is a minibuffer
*Minibuf-2* is a minibuffer
*Minibuf-3* is a minibuffer
*Minibuf-0* is a minibuffer
Usually there are 2: *Minibuf-0* (IIUC that's the buffer displayed when
the minibuffer is inactive, i.e. it's normally empty) and *Minibuf-1*
which is the main minibuffer buffer.

But you can arbitrarily more if/when you use a recursive minibuffer
(i.e. when you use a command that needs a minibuffer while the
minibuffer is already in use):

M-x toto M-x delete-backward-char RET

Usually recursive minibuffers are disallowed, so the second M-x above
would signal an error rather than jump to a new minibuffer, but you can
set enable-recursive-minibuffers, and some commands also set it temporarily.


Stefan
Peter Dyballa
2011-10-27 18:38:15 UTC
Permalink
Post by Tassilo Horn
Another observation: why are there more than one minibuffers? Right
(dolist (b (buffer-list))
(when (minibufferp b)
(insert (format "%s is a minibuffer\n" b)))) ;; C-j
*Minibuf-1* is a minibuffer
*Minibuf-2* is a minibuffer
*Minibuf-3* is a minibuffer
*Minibuf-0* is a minibuffer
Are you working on a "HDBox"? (A set-top box for digital TV reception and HD recording.) It tries to record marked TV broadcasts many times – and fails because of this!

--
Mit friedvollen Grüßen
<]
Pete o __o |__ o recumbo
___o /I -\<, |o \ -\),-% ergo sum!
___/\ /\___./ \___...O/ O____.....`-O-'-()--o_________________
Tassilo Horn
2011-10-27 19:08:02 UTC
Permalink
Post by Peter Dyballa
Post by Tassilo Horn
Another observation: why are there more than one minibuffers? Right
(dolist (b (buffer-list))
(when (minibufferp b)
(insert (format "%s is a minibuffer\n" b)))) ;; C-j
*Minibuf-1* is a minibuffer
*Minibuf-2* is a minibuffer
*Minibuf-3* is a minibuffer
*Minibuf-0* is a minibuffer
Are you working on a "HDBox"? (A set-top box for digital TV reception
and HD recording.) It tries to record marked TV broadcasts many times
– and fails because of this!
Err, I don't get you. In case it's not a joke that I don't get, no,
it's a standard GNU/Linux notebook.

Bye,
Tassilo
Drew Adams
2011-10-27 21:53:31 UTC
Permalink
Post by Tassilo Horn
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:

(defun delete-word (arg)
(interactive "p")
(delete-region (point) (progn (forward-word arg) (point))))

(defun backward-delete-word (arg)
(interactive "p")
(delete-word (- arg)))

Then, as I said, bind these in _each_ of the minibuffer keymaps. This is for
one of the maps:

(define-key minibuffer-local-must-match-map
[remap kill-word] 'delete-word)

(define-key minibuffer-local-must-match-map
[remap backward-kill-word] 'backward-delete-word)
Post by Tassilo Horn
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)))
Post by Tassilo Horn
Isn't it possible to have buffer local values for
variables defined at the C level?
Yes, AFAIK.
Tassilo Horn
2011-10-28 06:53:04 UTC
Permalink
Post by Drew Adams
Post by Tassilo Horn
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
Yes, that would be a possibility.
Post by Drew Adams
Post by Tassilo Horn
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
Johan Bockgård
2011-10-29 00:50:19 UTC
Permalink
Post by Tassilo Horn
(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)))))
This advice is obviously completely wrong in the case where the current
buffer is not a minibuffer. But I suggest that you don't use advice, and
mark the variable permanent-local instead.

And you should make `kill-ring-yank-pointer' buffer local as well, if
you want the kill rings to behave correctly.

Tassilo Horn
2011-10-28 07:10:04 UTC
Permalink
Post by Tassilo Horn
(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)))))
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.
Argh, this somehow has the weird side effect of disturbing font-lock
somehow. For example, after starting emacs with the advice above, the
comment in *scratch* is not highlighted, and the same applies to latex
buffers. Elisp buffers are highlighted, though...

Bye,
Tassilo
Loading...