changeset 109062:d8144fe7f3f8

* bindings.el (global-map): Bind delete and DEL, the former to delete-forward-char. * mouse.el (mouse-region-delete-keys): Deleted. (mouse-show-mark): Simplify. * simple.el (delete-active-region): New option. (delete-backward-char): Implement in Lisp. (delete-forward-char): New command. * src/cmds.c (Fdelete_backward_char): Move into Lisp.
author Chong Yidong <cyd@stupidchicken.com>
date Sun, 27 Jun 2010 21:01:11 -0400
parents c05c5a981dd9
children b44ac3c3bafd 6d629fcc79e9
files etc/NEWS lisp/ChangeLog lisp/bindings.el lisp/mouse.el lisp/simple.el src/ChangeLog src/cmds.c
diffstat 7 files changed, 118 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/etc/NEWS	Sun Jun 27 14:28:51 2010 -0700
+++ b/etc/NEWS	Sun Jun 27 21:01:11 2010 -0400
@@ -144,6 +144,25 @@
 ** completion-at-point is now an alias for complete-symbol.
 
 ** mouse-region-delete-keys has been deleted.
+
+** Deletion changes
+
+*** New option `delete-active-region'.
+If non-nil, C-d, [delete], and DEL delete the region if it is active
+and no prefix argument is given.  If set to `kill', these commands
+kill instead.
+
+*** New command `delete-forward-char', bound to C-d and [delete].
+This is meant for interactive use, and obeys `delete-active-region';
+delete-char, meant for Lisp, does not obey `delete-active-region'.
+
+*** `delete-backward-char' is now a Lisp function.
+Apart from obeying `delete-active-region', its behavior is unchanged.
+However, the byte compiler now warns if it is called from Lisp; you
+should use delete-char with a negative argument instead.
+
+*** The option `mouse-region-delete-keys' has been deleted.
+
 
 * Changes in Specialized Modes and Packages in Emacs 24.1
 
--- a/lisp/ChangeLog	Sun Jun 27 14:28:51 2010 -0700
+++ b/lisp/ChangeLog	Sun Jun 27 21:01:11 2010 -0400
@@ -1,3 +1,15 @@
+2010-06-28  Chong Yidong  <cyd@stupidchicken.com>
+
+	* simple.el (delete-active-region): New option.
+	(delete-backward-char): Implement in Lisp.
+	(delete-forward-char): New command.
+
+	* mouse.el (mouse-region-delete-keys): Deleted.
+	(mouse-show-mark): Simplify.
+
+	* bindings.el (global-map): Bind delete and DEL, the former to
+	delete-forward-char.
+
 2010-01-16  Lennart Borgman  <lennart.borgman@gmail.com>
 
 	* progmodes/ruby-mode.el (ruby-mode-map): Don't bind TAB.
--- a/lisp/bindings.el	Sun Jun 27 14:28:51 2010 -0700
+++ b/lisp/bindings.el	Sun Jun 27 21:01:11 2010 -0400
@@ -822,6 +822,9 @@
     (setq i (1+ i))))
 (define-key global-map [?\C-\M--] 'negative-argument)
 
+(define-key global-map "\177" 'delete-backward-char)
+(define-key global-map "\C-d" 'delete-forward-char)
+
 (define-key global-map "\C-k" 'kill-line)
 (define-key global-map "\C-w" 'kill-region)
 (define-key esc-map "w" 'kill-ring-save)
--- a/lisp/mouse.el	Sun Jun 27 14:28:51 2010 -0700
+++ b/lisp/mouse.el	Sun Jun 27 21:01:11 2010 -0400
@@ -929,7 +929,7 @@
   (mouse-minibuffer-check start-event)
   (setq mouse-selection-click-count-buffer (current-buffer))
   ;; We must call deactivate-mark before repositioning point.
-  ;; Otherwise, for select-active-regions non-nil, we get the wrong
+  ;; Otherwise, for `select-active-regions' non-nil, we get the wrong
   ;; selection if the user drags a region, clicks elsewhere to
   ;; reposition point, then middle-clicks to paste the selection.
   (deactivate-mark)
@@ -1263,11 +1263,6 @@
 
 ;; 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)
@@ -1297,8 +1292,7 @@
 				 '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)))))
+			     (not (mouse-undouble-last-event events)))))
 	(and (consp event)
 	     (or (eq (car event) 'switch-frame)
 		 (eq (posn-point (event-end event))
@@ -1311,22 +1305,9 @@
 		      (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))))
+      ;; 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))))
--- a/lisp/simple.el	Sun Jun 27 14:28:51 2010 -0700
+++ b/lisp/simple.el	Sun Jun 27 21:01:11 2010 -0400
@@ -844,6 +844,78 @@
 	 (overlay-recenter (point))
 	 (recenter -3))))
 
+(defcustom delete-active-region t
+  "Whether single-char deletion commands delete an active region.
+This has an effect only if Transient Mark mode is enabled, and
+affects `delete-forward-char' and `delete-backward-char', though
+not `delete-char'.
+
+If the value is the symbol `kill', the active region is killed
+instead of deleted."
+  :type '(choice (const :tag "Delete active region" t)
+                 (const :tag "Kill active region" kill)
+                 (const :tag "Do ordinary deletion" nil))
+  :group 'editing
+  :version "24.1")
+
+(defun delete-backward-char (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-active-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.
+
+In Overwrite mode, single character backward deletion may replace
+tabs with spaces so as to back over columns, unless point is at
+the end of the line."
+  (interactive "p\nP")
+  (unless (integerp n)
+    (signal 'wrong-type-argument (list 'integerp n)))
+  (cond ((and (use-region-p)
+	      delete-active-region
+	      (= n 1))
+	 ;; If a region is active, kill or delete it.
+	 (if (eq delete-active-region 'kill)
+	     (kill-region (region-beginning) (region-end))
+	   (delete-region (region-beginning) (region-end))))
+	;; In Overwrite mode, maybe untabify while deleting
+	((null (or (null overwrite-mode)
+		   (<= n 0)
+		   (memq (char-before) '(?\t ?\n))
+		   (eobp)
+		   (eq (char-after) ?\n)))
+	 (let* ((ocol (current-column))
+		(val (delete-char (- n) killflag)))
+	   (save-excursion
+	     (insert-char ?\s (- ocol (current-column)) nil))))
+	;; Otherwise, do simple deletion.
+	(t (delete-char (- n) killflag))))
+
+(defun delete-forward-char (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-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 ((and (use-region-p)
+	      delete-active-region
+	      (= n 1))
+	 ;; If a region is active, kill or delete it.
+	 (if (eq delete-active-region 'kill)
+	     (kill-region (region-beginning) (region-end))
+	   (delete-region (region-beginning) (region-end))))
+	;; Otherwise, do simple deletion.
+	(t (delete-char n killflag))))
+
 (defun mark-whole-buffer ()
   "Put point at beginning and mark at end of buffer.
 You probably should not use this function in Lisp programs;
--- a/src/ChangeLog	Sun Jun 27 14:28:51 2010 -0700
+++ b/src/ChangeLog	Sun Jun 27 21:01:11 2010 -0400
@@ -1,3 +1,7 @@
+2010-06-28  Chong Yidong  <cyd@stupidchicken.com>
+
+	* cmds.c (Fdelete_backward_char): Move into Lisp.
+
 2010-06-27  Dan Nicolaescu  <dann@ics.uci.edu>
 
 	* s/freebsd.h (BSD4_2): Remove redundant definition.
--- a/src/cmds.c	Sun Jun 27 14:28:51 2010 -0700
+++ b/src/cmds.c	Sun Jun 27 21:01:11 2010 -0400
@@ -240,7 +240,9 @@
        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 was explicitly specified.
+
+The command `delete-forward' is preferable for interactive use.  */)
      (n, killflag)
      Lisp_Object n, killflag;
 {
@@ -273,60 +275,6 @@
   return Qnil;
 }
 
-DEFUN ("delete-backward-char", Fdelete_backward_char, Sdelete_backward_char,
-       1, 2, "p\nP",
-       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.
-This is meant for interactive use only; from Lisp, better use `delete-char'
-with a negated argument.  */)
-     (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;
 
 /* Note that there's code in command_loop_1 which typically avoids
@@ -635,8 +583,6 @@
   defsubr (&Send_of_line);
 
   defsubr (&Sdelete_char);
-  defsubr (&Sdelete_backward_char);
-
   defsubr (&Sself_insert_command);
 }
 
@@ -658,10 +604,8 @@
 
   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