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

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

RE: Another Emacs incompatibilty


From: Drew Adams
Subject: RE: Another Emacs incompatibilty
Date: Mon, 24 Aug 2020 21:09:50 -0700 (PDT)

[Sending again, explicitly ccing help-gnu-emacs@gnu.org
this time.  I need to remember that "Reply All" to you
doesn't work, at least not with my mail client (Outlook).]


> >> Is it currently possible, if d-s-m is active, to
> >> easily retrieve the deleted/replaced item?
> >
> > Yes, on a per-command basis.
> 
> OK, I have an idea for a rule guys, whenever someone
> asks if something is possible, please do not just
> answer "yes" whenever it is, also show how one is
> suppose to actually do it :)

FWIW, I didn't only offer that one-liner in that msg.
And another message of mine in this thread cited how
it's done, quoting what `delsel.el' says about it.

 ;; Commands which will delete the selection need
 ;; a `delete-selection' property on their symbols...

https://lists.gnu.org/archive/html/help-gnu-emacs/2020-08/msg00105.html

But OK.  Someone asked _how_ to put that property
on a command's symbol, or perhaps the question
was also what a command's _symbol_ is.

How is described in the Commentary of library
`delsel.el'.  (Old-school: doc in the file itself.)

Anyway, here's what you do:

To make command `insert-char' first delete the
selection (active region), before performing its
action (which is to insert one or more chars),
put property `delete-selection' on the symbol
`insert-char' - the symbol whose `symbol-function'
is the function name "insert-char".  Give the
property the value `t'.

 (put 'insert-char 'delete-selection t)

That's all.  Without that property, i.e., if
(get 'insert-char 'delete-selection) is nil,
`delete-selection-mode' has no effect on the
given command (`insert-char') - the command
just does its normal thing.

`insert-char is already set up that way for
`delete-selection-mode' (it deletes the
selection first), in `delsel.el'.

But if you want `insert-char' to do nothing
besides insert its arg chars, i.e., not kill
and not delete the selection first, do this,
to override its default behavior in
`delete-selection-mode':

  (put 'insert-char 'delete-selection nil)

Or if you instead want `insert-char' to kill
the selected text (so you can later yank it)
instead of just deleting it, add this to your
init file, to override the default behavior:

  (put 'insert-char 'delete-selection 'kill)

That gives you the same effect as using `C-w'
when the region's active, before using the
command in question (`insert-char', here).

(But unlike `C-w', it has no effect if the
region is not active - which is the case when
`transient-mark-mode' is off.)

And if you have your own command `foo', which
does <whatever>, and you want it to first
delete the active region, then do this:

  (put 'foo 'delete-selection t)

And if you want to override the normal behavior
of your command `tata' and ONLY delete the
active region, then do this:

  (put 'tata 'delete-selection 'supersede)

And if you want your command `titi' to delete
the selection sometimes, and kill it other
times, before it does whatever else it does
normally, then do this:

  (put 'titi 'delete-selection 'titi-kill/del)

where `titi-kill/del' is a function that DTRT
to the active region: kill, delete, or nothing
at all, according to the current context -
phase of the moon, your pulse rate, the number
of kilometers you've ridden your bike so far
today, roll of phantom dice...

Does this help?  If not, just try it - try
various `delete-selection' values for a few
commands.

The default `delete-selection' behavior (value
`t') is the "select-and-type-to-replace"
behavior that's fairly common outside Emacs.



reply via email to

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