From: Drew Adams <drew.adams@oracle.com>
To: Emanuel Berg <moasenwood@zoho.eu>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: RE: Another Emacs incompatibilty
Date: Mon, 24 Aug 2020 21:09:50 -0700 (PDT) [thread overview]
Message-ID: <a300921e-356c-4db8-9f92-a7c141c93061@default> (raw)
In-Reply-To: <87ft8bmxuq.fsf@ebih.ebihd>
[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.
next prev parent reply other threads:[~2020-08-25 4:09 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-16 20:57 Another Emacs incompatibilty Torbjörn Granlund
2020-08-16 21:17 ` Stefan Monnier
2020-08-16 23:02 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-17 8:12 ` On the rate of change [was: Another Emacs incompatibilty] tomas
2020-08-17 14:21 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-17 15:20 ` tomas
2020-08-17 17:44 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-17 15:14 ` Another Emacs incompatibilty Torbjörn Granlund
2020-08-17 15:54 ` Robert Pluim
2020-08-17 16:08 ` Eli Zaretskii
2020-08-17 20:16 ` Torbjörn Granlund
2020-08-17 20:42 ` Stefan Monnier
2020-08-17 21:22 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-17 22:00 ` Gregory Heytings via Users list for the GNU Emacs text editor
2020-08-17 22:18 ` Eric Abrahamsen
2020-08-17 23:00 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-18 0:25 ` Eric Abrahamsen
2020-08-18 4:16 ` Stefan Monnier
2020-08-18 4:47 ` Eli Zaretskii
2020-08-18 5:27 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-18 5:36 ` Eli Zaretskii
2020-08-23 20:10 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-24 6:43 ` Alan Davis
2020-08-24 6:55 ` Eli Zaretskii
2020-08-24 23:21 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-24 14:31 ` Drew Adams
2020-08-24 23:24 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-25 0:53 ` Alan Davis
2020-08-25 4:09 ` Drew Adams [this message]
2020-08-25 4:14 ` Drew Adams
2020-08-25 4:30 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-25 5:04 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-25 5:46 ` Drew Adams
2020-08-25 6:07 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-25 5:51 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-24 15:31 ` Stefan Monnier
2020-08-24 23:14 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-18 15:47 ` Drew Adams
2020-08-18 16:45 ` Eric Abrahamsen
2020-08-18 16:52 ` Drew Adams
2020-08-18 17:50 ` Eric Abrahamsen
2020-08-18 17:10 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-17 16:31 ` Gregory Heytings via Users list for the GNU Emacs text editor
2020-08-17 16:49 ` Perry Smith
2020-08-17 16:54 ` Gregory Heytings via Users list for the GNU Emacs text editor
2020-08-17 17:22 ` Eli Zaretskii
2020-08-17 17:28 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-08-17 17:11 ` Eli Zaretskii
2020-08-17 17:16 ` Emanuel Berg via Users list for the GNU Emacs text editor
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=a300921e-356c-4db8-9f92-a7c141c93061@default \
--to=drew.adams@oracle.com \
--cc=help-gnu-emacs@gnu.org \
--cc=moasenwood@zoho.eu \
/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).