From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Updated proposal for DEL to delete active region Date: Sat, 22 May 2010 13:44:58 -0400 Message-ID: <87ljbbbzl1.fsf@stupidchicken.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1274550318 27573 80.91.229.12 (22 May 2010 17:45:18 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 22 May 2010 17:45:18 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 22 19:45:16 2010 connect(): No such file or directory Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OFsl7-0004Be-Pe for ged-emacs-devel@m.gmane.org; Sat, 22 May 2010 19:45:15 +0200 Original-Received: from localhost ([127.0.0.1]:60646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OFsl6-0004d4-Dq for ged-emacs-devel@m.gmane.org; Sat, 22 May 2010 13:45:12 -0400 Original-Received: from [140.186.70.92] (port=42069 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OFskx-0004WL-Q2 for emacs-devel@gnu.org; Sat, 22 May 2010 13:45:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OFsku-0000ON-HG for emacs-devel@gnu.org; Sat, 22 May 2010 13:45:03 -0400 Original-Received: from pantheon-po41.its.yale.edu ([130.132.50.98]:45963) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OFsku-0000O9-DD for emacs-devel@gnu.org; Sat, 22 May 2010 13:45:00 -0400 Original-Received: from furry (173-14-147-246-NewEngland.hfc.comcastbusiness.net [173.14.147.246]) (authenticated bits=0) by pantheon-po41.its.yale.edu (8.12.11.20060308/8.12.11) with ESMTP id o4MHiwNq000522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sat, 22 May 2010 13:44:58 -0400 Original-Received: by furry (Postfix, from userid 1000) id 87D86C057; Sat, 22 May 2010 13:44:58 -0400 (EDT) X-YaleITSMailFilter: Version 1.2c (attachment(s) not renamed) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:125078 Archived-At: 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. + * Changes in Specialized Modes and Packages in Emacs 24.1 *************** *** 226,231 **** --- 237,248 ---- * 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 ----