unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Proposal for DEL to delete the active region
@ 2010-05-01  3:23 Chong Yidong
  2010-05-02  2:54 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Chong Yidong @ 2010-05-01  3:23 UTC (permalink / raw)
  To: emacs-devel

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))))




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Proposal for DEL to delete the active region
  2010-05-01  3:23 Proposal for DEL to delete the active region Chong Yidong
@ 2010-05-02  2:54 ` Stefan Monnier
  2010-05-02  6:04   ` Thierry Volpiatto
  2010-05-02 14:34   ` Chong Yidong
  0 siblings, 2 replies; 6+ messages in thread
From: Stefan Monnier @ 2010-05-02  2:54 UTC (permalink / raw)
  To: Chong Yidong; +Cc: emacs-devel

> 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.

The proposal has the property of being straightforward.  I like that.

> + (defcustom delete-backward-char-delete-region t

But this doesn't seem right: we're not going to have one such variable
for delete-backward-char, delete-char, delete-backward-char-untabify,
and the handful of other commands that

   grep "'delete-selection 'supersede" lisp/**/*.el

indicate will want a similar treatment.

> + (defun delete-backward-char (n killflag)
[...]
> +   (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))

the other problem here is that this change also affects calls from Lisp
rather than only interactive calls.


        Stefan


PS: We will want to remove mouse-region-delete-keys and related code
ASAP since it is at the root of various known bugs (mostly due to the
fact that it delays the end of the mouse-selection commands to the
beginning of the next command, so post-command-hooks don't get run at
the expected time).




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Proposal for DEL to delete the active region
  2010-05-02  2:54 ` Stefan Monnier
@ 2010-05-02  6:04   ` Thierry Volpiatto
  2010-05-02 14:34   ` Chong Yidong
  1 sibling, 0 replies; 6+ messages in thread
From: Thierry Volpiatto @ 2010-05-02  6:04 UTC (permalink / raw)
  To: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> 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.
>
> The proposal has the property of being straightforward.  I like that.
>
>> + (defcustom delete-backward-char-delete-region t
>
> But this doesn't seem right: we're not going to have one such variable
> for delete-backward-char, delete-char, delete-backward-char-untabify,
> and the handful of other commands that
>
>    grep "'delete-selection 'supersede" lisp/**/*.el
>
> indicate will want a similar treatment.
>
>> + (defun delete-backward-char (n killflag)
> [...]
>> +   (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))
>
> the other problem here is that this change also affects calls from Lisp
> rather than only interactive calls.
>
>
>         Stefan
>
>
> PS: We will want to remove mouse-region-delete-keys and related code
> ASAP since it is at the root of various known bugs (mostly due to the
> fact that it delays the end of the mouse-selection commands to the
> beginning of the next command, so post-command-hooks don't get run at
> the expected time).

Why instead not using C-d to delete region with simple thing like that:

(defun tv-delete-char (arg beg end)
  (interactive "p\nr")
  (if (region-active-p)
      (delete-region beg end)
      (delete-char arg)))

-- 
Thierry Volpiatto
Gpg key: http://pgp.mit.edu/





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Proposal for DEL to delete the active region
  2010-05-02  2:54 ` Stefan Monnier
  2010-05-02  6:04   ` Thierry Volpiatto
@ 2010-05-02 14:34   ` Chong Yidong
  2010-05-03  6:00     ` Richard Stallman
  2010-05-03 17:12     ` Stefan Monnier
  1 sibling, 2 replies; 6+ messages in thread
From: Chong Yidong @ 2010-05-02 14:34 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> + (defcustom delete-backward-char-delete-region t
>
> But this doesn't seem right: we're not going to have one such variable
> for delete-backward-char, delete-char, delete-backward-char-untabify,
> and the handful of other commands that
>
>    grep "'delete-selection 'supersede" lisp/**/*.el
>
> indicate will want a similar treatment.

I count ten such commands, all variants of delete-char or
delete-backward-char.  I think these should all obey the same two
variables.  For instance, `c-electric-backspace' should obey
`delete-backward-char-delete-region', and `org-delete-char' should obey
`delete-char-delete-region'.

>> + (defun delete-backward-char (n killflag)
> [...]
>> +   (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))
>
> the other problem here is that this change also affects calls from Lisp
> rather than only interactive calls.

Good point.  How about splitting up the functions, similar to next-line
vs forward-line?

So, we'd leave delete-backward-char unchanged, and create a new command
`delete-backward' which is the default binding for [DEL].  Similarly, a
new function `delete-forward', which is the default binding for
[delete].




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Proposal for DEL to delete the active region
  2010-05-02 14:34   ` Chong Yidong
@ 2010-05-03  6:00     ` Richard Stallman
  2010-05-03 17:12     ` Stefan Monnier
  1 sibling, 0 replies; 6+ messages in thread
From: Richard Stallman @ 2010-05-03  6:00 UTC (permalink / raw)
  To: Chong Yidong; +Cc: monnier, emacs-devel

If you are thinking of making DEL delete the region
whenever it is active, please implement it as an
optional mode first.  Then people can try it
and report whether it is a real pain.  Currently we
can only guess how much of a pain it would be.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Proposal for DEL to delete the active region
  2010-05-02 14:34   ` Chong Yidong
  2010-05-03  6:00     ` Richard Stallman
@ 2010-05-03 17:12     ` Stefan Monnier
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2010-05-03 17:12 UTC (permalink / raw)
  To: Chong Yidong; +Cc: emacs-devel

> I count ten such commands, all variants of delete-char or
> delete-backward-char.  I think these should all obey the same two
> variables.  For instance, `c-electric-backspace' should obey
> `delete-backward-char-delete-region', and `org-delete-char' should obey
> `delete-char-delete-region'.

My point is that we should go with a single option, like
`delete-deletes-active-region'.

> Good point.  How about splitting up the functions, similar to next-line
> vs forward-line?

> So, we'd leave delete-backward-char unchanged, and create a new command
> `delete-backward' which is the default binding for [DEL].  Similarly, a
> new function `delete-forward', which is the default binding for
> [delete].

Sounds fine for these functions.  Don't know about the (org|c)-*
commands, tho.


        Stefan




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-05-03 17:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-01  3:23 Proposal for DEL to delete the active region Chong Yidong
2010-05-02  2:54 ` Stefan Monnier
2010-05-02  6:04   ` Thierry Volpiatto
2010-05-02 14:34   ` Chong Yidong
2010-05-03  6:00     ` Richard Stallman
2010-05-03 17:12     ` Stefan Monnier

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).