However, this works only when the command is called by a keyboard,
not by M-x.
This appears to be a bug?
Example for reproduction:
(defun insert-date () "Insert current date." (interactive)
(insert (format-time-string "%Y-%m-%d"))
)
(put 'insert-date 'delete-selection t)
then call M-x insert-date, and it'll not replace text selection.
(PS thanks to Drew Adams and Chetan on gnu.emacs.help)
Xah
∑ http://xahlee.org/
☄
However, this works only when the command is called by a keyboard,
not by M-x.
This appears to be a bug?
It's intentional. This feature implements expectations that users
have for single-character editing operations in other editors,
where those commands don't have names and there's nothing like M-x.
So there's no reason why M-x should delete the region.
It is better for M-x just to call the function.
For elisp programers who wish to write extentions where the command's
behaviors change depending on whether user has delete-selection-mode
on, what should they do? Check for mark-active and delete-selection-
mode before any call to the insert function?
also, the current behavior seems to introduce a complexity, where
command behaves differently depending on whether it is invoked by a
keybinding or by M-x.
Xah
∑ http://xahlee.org/
☄
☄
If you really want to make behavior depend on those variables,
you need to check them. Whether you check them before or after
calling `insert' is up to you.
But that seems like a strange thing to do.