diff lisp/prim/simple.el @ 153:25f70ba0133c r20-3b3

Import from CVS: tag r20-3b3
author cvs
date Mon, 13 Aug 2007 09:38:25 +0200
parents 538048ae2ab8
children 43dd3413c7c7
line wrap: on
line diff
--- a/lisp/prim/simple.el	Mon Aug 13 09:37:21 2007 +0200
+++ b/lisp/prim/simple.el	Mon Aug 13 09:38:25 2007 +0200
@@ -353,6 +353,35 @@
   (and overwrite-mode (not (eolp))
        (save-excursion (insert-char ?\  arg))))
 
+(defcustom delete-erases-forward nil
+  "If non-nil, the DEL key will erase one character forwards.
+If nil, the DEL key will erase one character backwards."
+  :type 'boolean
+  :group 'editing-basics)
+
+(defcustom backspace-or-delete-hook nil
+  "Hook that is run prior to executing the backspace-or-delete function.
+Return a non-nil value to indicate that the editing chore has been
+handled and the backspace-or-delete function will exit without doing
+anything else."
+  :type 'hook)
+  
+(defun backspace-or-delete (arg)
+  "Delete either one character backwards or one character forwards.
+Controlled by the state of `delete-erases-forward' and whether the
+BackSpace keysym even exists on your keyboard.  If you don't have a
+BackSpace keysym, the delete key should always delete one character
+backwards."
+  (interactive "*P")
+  (unless (run-hook-with-args 'backspace-or-delete-hook arg)
+    (if zmacs-region-active-p
+	(kill-region (point) (mark))
+      (if (and delete-erases-forward
+	       (or (eq 'tty (device-type))
+		   (x-keysym-on-keyboard-p "BackSpace")))
+	  (delete-char (prefix-numeric-value arg))
+	(delete-backward-char (prefix-numeric-value arg))))))
+
 (defun zap-to-char (arg char)
   "Kill up to and including ARG'th occurrence of CHAR.
 Goes backward if ARG is negative; error if CHAR not found."