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 22:46:49 -0700 (PDT) [thread overview]
Message-ID: <58ef0b19-cbc4-42df-86e4-6407ef77752f@default> (raw)
In-Reply-To: <874kor9wk4.fsf@ebih.ebihd>
> > (put 'insert-char 'delete-selection t)
>
> OK, so that's the syntax. This must be a very arcane
> way of configuration. I did use `put' but only to
> enable and disable, as in
>
> (put 'help-for-help 'disabled t)
>
> But, what are properties and how do I know what
> properties a function has?
https://www.gnu.org/software/emacs/manual/html_node/elisp/Symbol-Properties.html
Ask Emacs: `C-h i m Elisp i symbol property'
A Lisp symbol is an object of sorts. It has a name
and possibly other properties/attributes:
* a name - `symbol-name'
* a function value - `symbol-function'
* a variable value - `symbol-value'
* a property list - `symbol-plist'
And you can add any other properties you like.
Enjoy.
> And how do I write a function with properties? (I
> don't think I want to, in general, but I always want
> to do things I didn't do, at least once...)
As I think I said before, it's not really the function
that has properties. It's the function symbol - the
symbol whose `symbol-function' is the function named
with the function's name (which is also the symbol's
name).
(defun foo ...)
(symbol-function 'foo) => foo ; symbol with name "foo"
(setq foo 42)
(symbol-value 'foo) => 42
See also `C-h f symbol-plist'.
> > 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)
>
> `insert-char'? Sure, that's ONE way to insert, but
> there are many other ways to insert things, and not
> just a single char,
It was an _example_. A command whose `delete-selection'
property is defined to kill, not delete. To show that
you can change the behavior to kill instead of only
delete.
> and then (if you desire this
> functionality to begin with, that is) then you
> _always_ want the selection to be killed, I think is
> the objective here?
It presumably is your objective, if you use `kill'.
Again, an _example_ of getting kill behavior. Do I
think you'd likely really prefer to have `insert-char'
kill instead of delete? No. But you might. Or some
library might.
> Anyway, I don't get it to work:
>
> (delete-selection-mode) ; t
> (put 'insert-char 'delete-selection 'kill) ; kill
> I type this
> set-mark-command
> beginning-of-line
> set-mark-command
> s ("I type this" disappears, the letter s appears)
> yank
> "I type this" does NOT appear
In your example, the kill behavior applies to
`insert-char', not to `self-insert-command', which
is what `s' is bound to. So don't expect that when
you type `s' to replace the active region you can
then yank what was deleted.
If you instead select some text and use
`C-x 8 RET' `LATIN CAPITAL LETTER M', then the
selected text is replaced by `M', AND it's put in
the kill ring.
Maybe using `insert-char' to illustrate wasn't the
best choice. I did so because it was the first one
in `delsel.el' after `self-insert-command' (which
is a special case).
> Here is a 19-liner how to do it:
> (delete-selection-mode)
> (defun delete-selection-pre-hook ()
> (when (and delete-selection-mode
> (use-region-p)
> (not buffer-read-only) )
> (if (member this-command '(self-insert-command insert-char insert) )
> (delete-selection-helper 'kill)
> (delete-selection-helper
> (and (symbolp this-command)
> (get this-command 'delete-selection) )))))
You don't need to redefine `delete-selection-pre-hook'.
You typically need only put a `delete-selection'
property on a command's symbol, to get the behavior
you want for it, which is just delete-the-selection
in most cases, i.e., value `t'.
And most people will never need to do even that.
They'll just use the out-of-the-box behavior.
People who add commands that insert or do some
other things might want to configure them to take
advantage of `delete-selection-mode'. And even
then, they mostly just use `t': delete.
You didn't ask how to use `delete-selection-mode'.
I think you asked about its various behaviors and
configuring them by putting properties on command
symbols. It can do more than your average "select
and type to replace".
next prev parent reply other threads:[~2020-08-25 5:46 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
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 [this message]
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=58ef0b19-cbc4-42df-86e4-6407ef77752f@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).