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: Proposal for DEL to delete the active region Date: Fri, 30 Apr 2010 23:23:22 -0400 Message-ID: <87iq78uwyd.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 1272684225 3153 80.91.229.12 (1 May 2010 03:23:45 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 1 May 2010 03:23:45 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 01 05:23:44 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 1O83Is-0001wn-JS for ged-emacs-devel@m.gmane.org; Sat, 01 May 2010 05:23:43 +0200 Original-Received: from localhost ([127.0.0.1]:40101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O83Ir-0000q4-Aj for ged-emacs-devel@m.gmane.org; Fri, 30 Apr 2010 23:23:41 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O83Im-0000pz-V1 for emacs-devel@gnu.org; Fri, 30 Apr 2010 23:23:36 -0400 Original-Received: from [140.186.70.92] (port=40159 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O83Ik-0000pp-90 for emacs-devel@gnu.org; Fri, 30 Apr 2010 23:23:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O83Ii-0003Vu-1n for emacs-devel@gnu.org; Fri, 30 Apr 2010 23:23:34 -0400 Original-Received: from pantheon-po33.its.yale.edu ([130.132.50.94]:36704) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O83Ih-0003Vl-M9 for emacs-devel@gnu.org; Fri, 30 Apr 2010 23:23:31 -0400 Original-Received: from furry (adsl-99-75-106-162.dsl.wlfrct.sbcglobal.net [99.75.106.162]) (authenticated bits=0) by pantheon-po33.its.yale.edu (8.12.11.20060308/8.12.11) with ESMTP id o413NT6F006493 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 30 Apr 2010 23:23:30 -0400 Original-Received: by furry (Postfix, from userid 1000) id BEC1DC055; Fri, 30 Apr 2010 23:23:22 -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:124381 Archived-At: Here is a proposal for DEL to delete the region when transient-mark-mode is enabled. DEL already does this in delete-selection-mode; the idea here is to move this behavior into transient-mark-mode proper. This involves getting rid of `mouse-region-delete-keys', moving `delete-backward-char' from C to Lisp, and introducing a new variable `delete-backward-char-delete-region'. Its default value, t, means that `delete-backward-char' will delete the active region. Conceptually, this puts `delete-backward-char-delete-region' on the same footing as other user commands that "act on the region" under Transient Mark mode. The additional benefit is getting rid of the `mouse-region-delete-keys' hack, so that DEL does the same thing for all active regions. Something similar would be done with delete-char (not shown in this patch), so that [delete] deletes active regions too. Comments, and suggestions for different approaches, welcome. *** lisp/simple.el 2010-04-28 15:18:37 +0000 --- lisp/simple.el 2010-05-01 03:12:28 +0000 *************** *** 837,842 **** --- 837,891 ---- (overlay-recenter (point)) (recenter -3)))) + (defcustom delete-backward-char-delete-region t + "If non-nil, `delete-backward-char' deletes 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-char (n killflag) + "Delete the previous N characters (following if N is negative). + KILLFLAG, if non-nil, means kill instead (save in kill ring). + Interactively, N is the prefix arg, and KILLFLAG is set if N is + explicitly specified. + + 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-backward-char-delete-region' to nil." + (interactive "p\nP") + (unless (integerp n) + (signal 'wrong-type-argument (list 'integerp n))) + (cond ((and (use-region-p) + delete-backward-char-delete-region + (= n 1)) + (if (eq delete-backward-char-delete-region 'kill) + (kill-region (region-beginning) (region-end)) + (delete-region (region-beginning) (region-end)))) + ((and overwrite-mode + (> n 0) + (null (memq (char-before) '(?\t ?\n))) + (null (eobp)) + (null (eq (char-after) ?\n))) + ;; In overwrite mode, back over columns while clearing them + ;; out, unless at end of line. + (let* ((ocol (current-column)) + (val (delete-char (- n) killflag))) + (save-excursion + (insert-char ?\s (- ocol (current-column)) nil)))) + (killflag + (kill-backward-chars n)) + ((< (min (point) (- (point) n)) (point-min)) + (signal 'beginning-of-buffer nil)) + ((> (max (point) (- (point) n)) (point-max)) + (signal 'beginning-of-buffer nil)) + (t + (delete-region (- (point) n) (point))))) + (defun mark-whole-buffer () "Put point at beginning and mark at end of buffer. You probably should not use this function in Lisp programs; *** src/cmds.c 2010-03-31 04:14:08 +0000 --- src/cmds.c 2010-05-01 00:06:40 +0000 *************** *** 265,322 **** 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. */) - (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 --- 265,270 ---- *************** *** 625,631 **** defsubr (&Send_of_line); defsubr (&Sdelete_char); - defsubr (&Sdelete_backward_char); defsubr (&Sself_insert_command); } --- 573,578 ---- *** lisp/mouse.el 2010-01-13 08:35:10 +0000 --- lisp/mouse.el 2010-04-30 23:30:48 +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))))