]> code.delx.au - gnu-emacs/blobdiff - lisp/simple.el
(next-line): Goto end-of-line before inserting a newline.
[gnu-emacs] / lisp / simple.el
index 4fb7c03220fcf09db0f9e29459f4c6b492795df0..d04a3b0091e33475524fb3b07ced30b45442a656 100644 (file)
@@ -1,6 +1,6 @@
 ;;; 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.
@@ -141,7 +141,9 @@ With arg N, insert N newlines."
   (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)
@@ -232,11 +234,13 @@ This respects narrowing, created by \\[narrow-to-region] and friends."
   (interactive "*")
   (save-match-data
     (save-excursion
-      (let (eol bol)         
       (goto-char (point-min))
       (while (re-search-forward "\\s-$" nil t)
        (skip-syntax-backward "-" (save-excursion (forward-line 0) (point)))
-       (delete-region (point) (match-end 0)))))))
+       ;; 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.
@@ -1936,6 +1940,7 @@ Can be `untabify' -- turn a tab to many spaces, then delete one space;
        `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)
@@ -2332,7 +2337,16 @@ In Transient Mark mode, when the mark is active, the region is highlighted.
 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)
@@ -2366,6 +2380,7 @@ incremental search, \\[beginning-of-buffer], and \\[end-of-buffer]."
 (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)
@@ -2390,12 +2405,12 @@ using `forward-line' instead.  It is usually easier to use
 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)
@@ -3273,24 +3288,6 @@ or go back to just one window (by deleting all but the selected window)."
 
 (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.
@@ -3321,7 +3318,8 @@ Valid values include:
                            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"
@@ -3509,7 +3507,11 @@ in the definition is used to check that VALUE is valid."
       (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.
 
@@ -4012,6 +4014,93 @@ 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.
+
+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 ()