(save-match-data
(save-excursion
(goto-char (point-min))
- (while (re-search-forward "\\s-+$" nil t)
- (delete-region (match-beginning 0) (match-end 0))))))
+ (while (re-search-forward "\\s-$" nil t)
+ (skip-syntax-backward "-" (save-excursion (forward-line 0) (point)))
+ (delete-region (point) (match-end 0))))))
(defun newline-and-indent ()
"Insert a newline, then indent according to major mode.
In some text modes, where TAB inserts a tab, this command indents to the
column specified by the function `current-left-margin'."
(interactive "*")
- (delete-region (point) (progn (skip-chars-backward " \t") (point)))
+ (delete-horizontal-space t)
(newline)
(indent-according-to-mode))
column specified by the function `current-left-margin'."
(interactive "*")
(save-excursion
- (delete-region (point) (progn (skip-chars-backward " \t") (point)))
+ (delete-horizontal-space t)
(indent-according-to-mode))
(newline)
(indent-according-to-mode))
nil
(insert ?\ ))))
-(defun delete-horizontal-space ()
- "Delete all spaces and tabs around point."
+(defun delete-horizontal-space (&optional backward-only)
+ "Delete all spaces and tabs around point.
+If BACKWARD-ONLY is non-nil, only delete spaces before point."
(interactive "*")
- (skip-chars-backward " \t" (field-beginning))
- (delete-region (point) (progn (skip-chars-forward " \t") (point))))
+ (delete-region
+ (if backward-only
+ (point)
+ (progn
+ (skip-chars-forward " \t" (field-end))
+ (point)))
+ (progn
+ (skip-chars-backward " \t" (field-beginning nil t))
+ (point))))
(defun just-one-space ()
"Delete all spaces and tabs around point, leaving one space."
(interactive "*")
- (skip-chars-backward " \t")
+ (skip-chars-backward " \t" (field-beginning))
(if (= (following-char) ? )
(forward-char 1)
(insert ? ))
- (delete-region (point) (progn (skip-chars-forward " \t") (point))))
-
+ (delete-region
+ (point)
+ (progn
+ (skip-chars-forward " \t" (field-end nil t))
+ (point))))
(defun beginning-of-buffer (&optional arg)
"Move point to the beginning of the buffer; leave mark at previous position.
the front of the kill ring, rather than being added to the list."
(and (fboundp 'menu-bar-update-yank-menu)
(menu-bar-update-yank-menu string (and replace (car kill-ring))))
- (if replace
+ (if (and replace kill-ring)
(setcar kill-ring string)
(setq kill-ring (cons string kill-ring))
(if (> (length kill-ring) kill-ring-max)
(define-key global-map "\e\e\e" 'keyboard-escape-quit)
-(defcustom input-mode-8-bit t
- "Control acceptance of 8-bit keyboard input.
-This may be useful for inputting non-ASCII characters if your keyboard
-can generate them. It is not necessary to change this under a window
-system which can distinguish 8-bit characters and Meta keys.
-Setting this variable directly does not take effect;
-use either M-x customize or the function `set-input-mode'."
- :set (lambda (symbol value)
- (let ((mode (current-input-mode)))
- (set-input-mode (nth 0 mode) (nth 1 mode) value)))
- :initialize 'custom-initialize-default
- :type '(choice (const :tag "8-bit input for a Meta key" t)
- (const :tag "Direct 8-bit character input" 0)
- (const :tag "Assume top bit is parity and ignore" nil))
- :version "21.1"
- :link '(custom-manual "Single-Byte European Support")
- :group 'keyboard)
-
(defcustom read-mail-command 'rmail
"*Your preference for a mail reading package.
This is used by some keybindings which support reading mail.
archiving.
Additional valid symbols may be available; check with the author of
-your package for details.
+your package for details. The function should return non-nil if it
+succeeds.
See also `read-mail-command' concerning reading mail."
:type '(radio (function-item :tag "Default Emacs mail"
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-deletes-forward'."
+ (interactive "P")
+ (setq delete-key-deletes-forward
+ (if arg
+ (> (prefix-numeric-value arg) 0)
+ (not delete-key-deletes-forward)))
+
+ (cond ((or (memq window-system '(x w32 mac pc))
+ (memq system-type '(ms-dos windows-nt)))
+ (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 ()