From: Chong Yidong <cyd@stupidchicken.com>
To: emacs-devel@gnu.org
Subject: Updated proposal for DEL to delete active region
Date: Sat, 22 May 2010 13:44:58 -0400 [thread overview]
Message-ID: <87ljbbbzl1.fsf@stupidchicken.com> (raw)
Here is an updated proposal, which binds C-d and DEL to new Lisp
commands `delete-forward' and `delete-backward', which delete the active
region if `delete-deletes-active-region' is non-nil.
It removes the variable `mouse-region-delete-keys', removing the special
handling of mouse selections. It also simplifies delete-backward-char,
moving the special overwrite-mode untabification into delete-backward.
Comments?
=== modified file 'etc/NEWS'
*** etc/NEWS 2010-05-20 22:16:19 +0000
--- etc/NEWS 2010-05-22 17:39:16 +0000
***************
*** 119,124 ****
--- 119,135 ----
** If delete-file is called with a prefix argument, it really deletes,
regardless of the value of `delete-by-moving-to-trash'.
+ ** New commands delete-forward and delete-backward.
+ C-d and DEL are now bound to these commands, instead of delete-char
+ and delete-backward-char.
+
+ *** New option `delete-deletes-active-region', if non-nil, means C-d
+ and DEL delete the region if `delete-deletes-active-region' is
+ non-nil. If set to `kill', these commands kill instead.
+
+ The option replaces `mouse-region-delete-keys', which has been
+ removed.
+
\f
* Changes in Specialized Modes and Packages in Emacs 24.1
***************
*** 226,231 ****
--- 237,248 ----
\f
* Incompatible Lisp Changes in Emacs 24.1
+ ** mouse-region-delete-keys has been removed.
+
+ ** delete-backward-char no longer untabifies in overwrite mode.
+ The new command `delete-backward', which is intended for interactive
+ use, does so.
+
** Test for special mode-class was moved from view-file to view-buffer.
** Passing a nil argument to a minor mode function now turns the mode
=== modified file 'lisp/bindings.el'
*** lisp/bindings.el 2010-05-15 13:23:48 +0000
--- lisp/bindings.el 2010-05-22 17:17:43 +0000
***************
*** 765,770 ****
--- 765,773 ----
(setq i (1+ i))))
(define-key global-map [?\C-\M--] 'negative-argument)
+ (define-key global-map "\177" 'delete-backward)
+ (define-key global-map "\C-d" 'delete-forward)
+
(define-key global-map "\C-k" 'kill-line)
(define-key global-map "\C-w" 'kill-region)
(define-key esc-map "w" 'kill-ring-save)
=== modified file 'lisp/mouse.el'
*** lisp/mouse.el 2010-01-13 08:35:10 +0000
--- lisp/mouse.el 2010-05-22 17:17:43 +0000
***************
*** 1263,1273 ****
;; Momentarily show where the mark is, if highlighting doesn't show it.
- (defcustom mouse-region-delete-keys '([delete] [deletechar] [backspace])
- "List of keys that should cause the mouse region to be deleted."
- :group 'mouse
- :type '(repeat key-sequence))
-
(defun mouse-show-mark ()
(let ((inhibit-quit t)
(echo-keystrokes 0)
--- 1263,1268 ----
***************
*** 1297,1304 ****
'vertical-scroll-bar))
(and (memq 'down (event-modifiers event))
(not (key-binding key))
! (not (mouse-undouble-last-event events))
! (not (member key mouse-region-delete-keys)))))
(and (consp event)
(or (eq (car event) 'switch-frame)
(eq (posn-point (event-end event))
--- 1292,1298 ----
'vertical-scroll-bar))
(and (memq 'down (event-modifiers event))
(not (key-binding key))
! (not (mouse-undouble-last-event events)))))
(and (consp event)
(or (eq (car event) 'switch-frame)
(eq (posn-point (event-end event))
***************
*** 1311,1332 ****
(setq events nil)))))))
;; If we lost the selection, just turn off the highlighting.
(unless ignore
! ;; For certain special keys, delete the region.
! (if (member key mouse-region-delete-keys)
! (progn
! ;; Since notionally this is a separate command,
! ;; run all the hooks that would be run if it were
! ;; executed separately.
! (run-hooks 'post-command-hook)
! (setq last-command this-command)
! (setq this-original-command 'delete-region)
! (setq this-command (or (command-remapping this-original-command)
! this-original-command))
! (run-hooks 'pre-command-hook)
! (call-interactively this-command))
! ;; Otherwise, unread the key so it gets executed normally.
! (setq unread-command-events
! (nconc events unread-command-events))))
(setq quit-flag nil)
(unless transient-mark-mode
(delete-overlay mouse-drag-overlay))))
--- 1305,1313 ----
(setq events nil)))))))
;; If we lost the selection, just turn off the highlighting.
(unless ignore
! ;; Unread the key so it gets executed normally.
! (setq unread-command-events
! (nconc events unread-command-events)))
(setq quit-flag nil)
(unless transient-mark-mode
(delete-overlay mouse-drag-overlay))))
=== modified file 'lisp/simple.el'
*** lisp/simple.el 2010-05-19 17:16:07 +0000
--- lisp/simple.el 2010-05-22 17:23:41 +0000
***************
*** 844,849 ****
--- 844,917 ----
(overlay-recenter (point))
(recenter -3))))
+ (defcustom delete-deletes-active-region t
+ "Whether `delete-forward' and `delete-backward' delete active regions.
+ This has an effect only when Transient Mark mode is enabled.
+ If the value is the symbol `kill', `delete-backward-char' kills
+ the active region instead of deleting it."
+ :type '(choice (const :tag "Delete region" t)
+ (const :tag "Kill region" kill)
+ (const :tag "Do not delete region" nil))
+ :group 'editing
+ :version "24.1")
+
+ (defun delete-backward (n &optional killflag)
+ "Delete the previous N characters (following if N is negative).
+ If Transient Mark mode is enabled, the mark is active, and N is 1,
+ delete the text in the region and deactivate the mark instead.
+ To disable this, set `delete-deletes-region' to nil.
+
+ Optional second arg KILLFLAG, if non-nil, means to kill (save in
+ kill ring) instead of delete. Interactively, N is the prefix
+ arg, and KILLFLAG is set if N is explicitly specified."
+ (interactive "p\nP")
+ (unless (integerp n)
+ (signal 'wrong-type-argument (list 'integerp n)))
+ (cond ((and (use-region-p)
+ delete-deletes-region
+ (= n 1))
+ ;; If a region is active, kill or delete it.
+ (if (eq delete-deletes-region 'kill)
+ (kill-region (region-beginning) (region-end))
+ (delete-region (region-beginning) (region-end))))
+ ;; In overwrite mode, back over columns while clearing them
+ ;; out, unless at end of line.
+ ((and overwrite-mode
+ (> n 0)
+ (null (memq (char-before) '(?\t ?\n)))
+ (null (eobp))
+ (null (eq (char-after) ?\n)))
+ (let* ((ocol (current-column))
+ (val (delete-char (- n) killflag)))
+ (save-excursion
+ (insert-char ?\s (- ocol (current-column)) nil))))
+ ;; Otherwise, just call `delete-backward-char'.
+ (t
+ (delete-backward-char n killflag))))
+
+ (defun delete-forward (n &optional killflag)
+ "Delete the previous N characters (following if N is negative).
+ If Transient Mark mode is enabled, the mark is active, and N is 1,
+ delete the text in the region and deactivate the mark instead.
+ To disable this, set `delete-deletes-active-region' to nil.
+
+ Optional second arg KILLFLAG non-nil means to kill (save in kill
+ ring) instead of delete. Interactively, N is the prefix arg, and
+ KILLFLAG is set if N was explicitly specified."
+ (interactive "p\nP")
+ (unless (integerp n)
+ (signal 'wrong-type-argument (list 'integerp n)))
+ (cond ((not (and (use-region-p)
+ delete-deletes-active-region
+ (= n 1)))
+ ;; With no region active, call `delete-char'.
+ (delete-char n killflag))
+ ;; Otherwise, kill or delete the region.
+ ((eq delete-deletes-active-region 'kill)
+ (kill-region (region-beginning) (region-end)))
+ (t
+ (delete-region (region-beginning) (region-end)))))
+
(defun mark-whole-buffer ()
"Put point at beginning and mark at end of buffer.
You probably should not use this function in Lisp programs;
***************
*** 3276,3282 ****
(delete-char 1)))
(forward-char -1)
(setq count (1- count))))))
! (delete-backward-char
(let ((skip (cond ((eq backward-delete-char-untabify-method 'hungry) " \t")
((eq backward-delete-char-untabify-method 'all)
" \t\n\r"))))
--- 3344,3350 ----
(delete-char 1)))
(forward-char -1)
(setq count (1- count))))))
! (delete-backward
(let ((skip (cond ((eq backward-delete-char-untabify-method 'hungry) " \t")
((eq backward-delete-char-untabify-method 'all)
" \t\n\r"))))
=== modified file 'src/cmds.c'
*** src/cmds.c 2010-05-15 13:23:48 +0000
--- src/cmds.c 2010-05-22 17:28:52 +0000
***************
*** 240,246 ****
doc: /* Delete the following N characters (previous if N is negative).
Optional second arg KILLFLAG non-nil means kill instead (save in kill ring).
Interactively, N is the prefix arg, and KILLFLAG is set if
! N was explicitly specified. */)
(n, killflag)
Lisp_Object n, killflag;
{
--- 240,248 ----
doc: /* Delete the following N characters (previous if N is negative).
Optional second arg KILLFLAG non-nil means kill instead (save in kill ring).
Interactively, N is the prefix arg, and KILLFLAG is set if
! N was explicitly specified.
!
! The command `delete-forward' is more suitable for interactive use. */)
(n, killflag)
Lisp_Object n, killflag;
{
***************
*** 278,328 ****
doc: /* Delete the previous N characters (following if N is negative).
Optional second arg KILLFLAG non-nil means kill instead (save in kill ring).
Interactively, N is the prefix arg, and KILLFLAG is set if
! N was explicitly specified. */)
(n, killflag)
Lisp_Object n, killflag;
{
- Lisp_Object value;
- int deleted_special = 0;
- int pos, pos_byte, i;
-
CHECK_NUMBER (n);
!
! /* See if we are about to delete a tab or newline backwards. */
! pos = PT;
! pos_byte = PT_BYTE;
! for (i = 0; i < XINT (n) && pos_byte > BEGV_BYTE; i++)
! {
! int c;
!
! DEC_BOTH (pos, pos_byte);
! c = FETCH_BYTE (pos_byte);
! if (c == '\t' || c == '\n')
! {
! deleted_special = 1;
! break;
! }
! }
!
! /* In overwrite mode, back over columns while clearing them out,
! unless at end of line. */
! if (XINT (n) > 0
! && ! NILP (current_buffer->overwrite_mode)
! && ! deleted_special
! && ! (PT == ZV || FETCH_BYTE (PT_BYTE) == '\n'))
! {
! int column = (int) current_column (); /* iftc */
!
! value = Fdelete_char (make_number (-XINT (n)), killflag);
! i = column - (int) current_column (); /* iftc */
! Finsert_char (make_number (' '), make_number (i), Qnil);
! /* Whitespace chars are ASCII chars, so we can simply subtract. */
! SET_PT_BOTH (PT - i, PT_BYTE - i);
! }
! else
! value = Fdelete_char (make_number (-XINT (n)), killflag);
!
! return value;
}
static int nonundocount;
--- 280,293 ----
doc: /* Delete the previous N characters (following if N is negative).
Optional second arg KILLFLAG non-nil means kill instead (save in kill ring).
Interactively, N is the prefix arg, and KILLFLAG is set if
! N was explicitly specified.
!
! The command `delete-backward' is more suitable for interactive use. */)
(n, killflag)
Lisp_Object n, killflag;
{
CHECK_NUMBER (n);
! return Fdelete_char (make_number (-XINT (n)), killflag);
}
static int nonundocount;
***************
*** 656,665 ****
initial_define_key (global_map, Ctl ('A'), "beginning-of-line");
initial_define_key (global_map, Ctl ('B'), "backward-char");
- initial_define_key (global_map, Ctl ('D'), "delete-char");
initial_define_key (global_map, Ctl ('E'), "end-of-line");
initial_define_key (global_map, Ctl ('F'), "forward-char");
- initial_define_key (global_map, 0177, "delete-backward-char");
}
/* arch-tag: 022ba3cd-67f9-4978-9c5d-7d2b18d8644e
--- 621,628 ----
next reply other threads:[~2010-05-22 17:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-22 17:44 Chong Yidong [this message]
2010-05-22 18:37 ` Updated proposal for DEL to delete active region Drew Adams
2010-05-22 19:02 ` Eli Zaretskii
2010-05-22 20:43 ` Drew Adams
2010-05-22 21:39 ` David Kastrup
2010-05-22 22:14 ` Drew Adams
2010-05-22 21:37 ` David Kastrup
2010-05-22 23:40 ` Chong Yidong
2010-05-23 0:30 ` Drew Adams
2010-05-23 17:10 ` Andreas Schwab
2010-05-24 21:03 ` Stefan Monnier
2010-05-23 1:33 ` Stefan Monnier
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=87ljbbbzl1.fsf@stupidchicken.com \
--to=cyd@stupidchicken.com \
--cc=emacs-devel@gnu.org \
/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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).