;;; simple.el --- basic editing commands for Emacs
-;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 98, 99, 2000
+;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 98, 99, 2000, 2001
;; Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
(interactive "*p")
(let* ((do-fill-prefix (and fill-prefix (bolp)))
(do-left-margin (and (bolp) (> (current-left-margin) 0)))
- (loc (point)))
+ (loc (point))
+ ;; Don't expand an abbrev before point.
+ (abbrev-mode nil))
(newline arg)
(goto-char loc)
(while (> arg 0)
(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)))
+ ;; Don't delete formfeeds, even if they are considered whitespace.
+ (if (looking-at ".*\f")
+ (goto-char (match-end 0)))
+ (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)
`all' -- delete all whitespace, including tabs, spaces and newlines;
nil -- just delete one character."
:type '(choice (const untabify) (const hungry) (const all) (const nil))
+ :version "20.3"
:group 'killing)
(defun backward-delete-char-untabify (arg &optional killp)
Changing the buffer \"deactivates\" the mark.
So do certain other operations that set the mark
but whose main purpose is something else--for example,
-incremental search, \\[beginning-of-buffer], and \\[end-of-buffer]."
+incremental search, \\[beginning-of-buffer], and \\[end-of-buffer].
+
+Many commands change their behavior when Transient Mark mode is in effect
+and the mark is active, by acting on the region instead of their usual
+default part of the buffer's text. Examples of such commands include
+\\[comment-dwim], \\[flush-lines], \\[ispell], \\[keep-lines],
+\\[query-replace], \\[query-replace-regexp], and \\[undo]. Invoke
+\\[apropos-documentation] and type \"transient\" or \"mark.*active\" at
+the prompt, to see the documentation of commands which are sensitive to
+the Transient Mark mode."
(interactive "P")
(setq transient-mark-mode
(if (null arg)
(defcustom next-line-add-newlines nil
"*If non-nil, `next-line' inserts newline to avoid `end of buffer' error."
:type 'boolean
+ :version "21.1"
:group 'editing-basics)
(defun next-line (arg)
and more reliable (no dependence on goal column, etc.)."
(interactive "p")
(if (and next-line-add-newlines (= arg 1))
- (let ((opoint (point)))
- (end-of-line)
- (if (eobp)
- (newline 1)
- (goto-char opoint)
- (line-move arg)))
+ (if (save-excursion (end-of-line) (eobp))
+ ;; When adding a newline, don't expand an abbrev.
+ (let ((abbrev-mode nil))
+ (end-of-line)
+ (insert "\n"))
+ (line-move arg))
(if (interactive-p)
(condition-case nil
(line-move arg)
(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"
(unless (widget-apply type :match val)
(error "Value `%S' does not match type %S of %S"
val (car type) var))))
- (set var val))
+ (set var val)
+
+ ;; Force a thorough redisplay for the case that the variable
+ ;; has an effect on the display, like `tab-width' has.
+ (force-mode-line-update))
;; Define the major mode for lists of completions.
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.
+
+Setting this variable with setq doesn't take effect. Programmatically,
+call `delete-key-deleted-forward-mode' instead."
+ :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)))
+ (let ((bindings
+ `(([C-delete] [C-backspace] kill-word backward-kill-word)
+ ([M-delete] [M-backspace] kill-word backward-kill-word)
+ ([C-M-delete] [C-M-backspace] kill-sexp backward-kill-sexp)
+ (,esc-map
+ [C-delete] [C-backspace]
+ kill-sexp backward-kill-sexp))))
+
+ (if delete-key-deletes-forward
+ (progn
+ (define-key function-key-map [delete] [?\C-d])
+ (define-key function-key-map [kp-delete] [?\C-d])
+ (define-key function-key-map [backspace] [?\C-?]))
+ (define-key function-key-map [delete] [?\C-?])
+ (define-key function-key-map [kp-delete] [?\C-?])
+ (define-key function-key-map [backspace] [?\C-?]))
+
+ (dolist (binding bindings)
+ (let ((map global-map))
+ (when (keymapp (car binding))
+ (setq map (car binding) binding (cdr binding)))
+ (let ((key1 (nth 0 binding))
+ (key2 (nth 1 binding))
+ (binding1 (nth 2 binding))
+ (binding2 (nth 3 binding)))
+ (unless delete-key-deletes-forward
+ (let ((temp binding1))
+ (setq binding1 binding2 binding2 temp)))
+ (define-key map key1 binding1)
+ (define-key map key2 binding2))))))
+ (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 ()