From 1d4b11bf9619c5a83f28bac1872f82f9a15ff1f0 Mon Sep 17 00:00:00 2001 From: Gerd Moellmann Date: Thu, 14 Dec 2000 13:36:59 +0000 Subject: [PATCH] (delete-key-deletes-forward): New user-option. (delete-key-deletes-forward-mode): New function. --- lisp/simple.el | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/lisp/simple.el b/lisp/simple.el index 4fb7c03220f..ed642184d8f 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -4012,6 +4012,69 @@ can be used as value of a `syntax-table' property. 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 () -- 2.39.2