changeset 34553:bd89ec7640bb

(delete-key-deletes-forward): New user-option. (delete-key-deletes-forward-mode): New function.
author Gerd Moellmann <gerd@gnu.org>
date Thu, 14 Dec 2000 13:36:59 +0000
parents f1e35f98c453
children 1aefbb8d68d8
files lisp/simple.el
diffstat 1 files changed, 63 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/simple.el	Thu Dec 14 13:36:34 2000 +0000
+++ b/lisp/simple.el	Thu Dec 14 13:36:59 2000 +0000
@@ -4012,6 +4012,69 @@
 DESCRIPTION is the descriptive string for the syntax.")
 
 
+;;; Handling of Backspace and Delete keys.
+
+(defcustom delete-key-deletes-forward nil
+  "Whether the Delete key should delete forward or not.
+
+On window systems, the default value of this option is chosen
+according to the keyboard used.  If the keyboard has both a Backspace
+key and a Delete key, and both are mapped to their usual meanings, the
+option's default value is set to t, so that Backspace can be used to
+delete backward, and Delete can be used used to delete forward
+
+If not running under a window system, setting this option accomplishes
+a similar effect by mapping C-h, which is usually generated by the
+Backspace key, to DEL, and by mapping DEL to C-d via
+`keyboard-translate'.  The former functionality of C-h is available on
+the F1 key.  You should probably not use this setting if you don't
+have both Backspace, Delete and F1 keys."
+  :type 'boolean
+  :group 'editing-basics
+  :version "21.1"
+  :set (lambda (symbol value)
+	 ;; The fboundp is because of a problem with :set when
+	 ;; dumping Emacs.  It doesn't really matter.
+	 (if (fboundp 'delete-key-deletes-forward-mode)
+	     (delete-key-deletes-forward-mode (or value 0))
+	   (set-default symbol value))))
+
+
+(defun delete-key-deletes-forward-mode (&optional arg)
+  "Toggle Delete key deleting forward or backward.
+With numeric arg, turn the mode on if and only iff ARG is positive.
+For more details, see `delete-key-deleted-forward'."
+  (interactive "P")
+  (setq delete-key-deletes-forward
+	(if arg
+	    (> (prefix-numeric-value arg) 0)
+	  (not delete-key-deletes-forward)))
+
+  (cond ((memq window-system '(x w32 mac))
+	 (if delete-key-deletes-forward
+	     (progn
+	       (define-key global-map [delete] 'delete-char)
+	       (define-key global-map [C-delete] 'kill-word)
+	       (define-key esc-map [C-delete] 'kill-sexp)
+	       (define-key global-map [C-M-delete] 'kill-sexp))
+	   (define-key esc-map [C-delete] 'backward-kill-sexp)
+	   (define-key global-map [C-M-delete] 'backward-kill-sexp)
+	   (define-key global-map [C-delete] 'backward-kill-word)
+	   (define-key global-map [delete] 'delete-backward-char)))
+	 (t
+	  (if delete-key-deletes-forward
+	      (progn
+		(keyboard-translate ?\C-h ?\C-?)
+		(keyboard-translate ?\C-? ?\C-d))
+	    (keyboard-translate ?\C-h ?\C-h)
+	    (keyboard-translate ?\C-? ?\C-?))))
+
+  (run-hooks 'delete-key-deletes-forward-hook)
+  (if (interactive-p)
+      (message "Delete key deletes %s" 
+	       (if delete-key-deletes-forward "forward" "backward"))))
+
+  
 ;;; Misc
 
 (defun byte-compiling-files-p ()