diff options
| author | Stefan Monnier | 2001-10-31 00:57:04 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2001-10-31 00:57:04 +0000 |
| commit | e1e0435051164de90725bf500ece3fc23445b8ea (patch) | |
| tree | 25d93881e08a45ae3f09922f8d173bbe63c36b4a | |
| parent | 5e905a57375bfb8b1579c3404d40554adb2d7a9d (diff) | |
| download | emacs-e1e0435051164de90725bf500ece3fc23445b8ea.tar.gz emacs-e1e0435051164de90725bf500ece3fc23445b8ea.zip | |
(reindent-then-newline-and-indent): Insert the newline
before indenting the first line.
(undo-get-state, undo-revert-to-state): New funs.
(shell-command): Don't kill the buffer even if empty.
(transpose-subr-start1, transpose-subr-start2, transpose-subr-end1)
(transpose-subr-end2): Remove.
(transpose-subr): Add `special' arg and simplify.
(transpose-subr-1): Rewrite.
(do-auto-fill): Use fill-indent-according-to-mode and fill-nobreak-p.
(rfc822-goto-eoh): Simplify.
| -rw-r--r-- | lisp/simple.el | 226 |
1 files changed, 113 insertions, 113 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index 0374a0aca57..5af9a187091 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -263,11 +263,15 @@ In programming language modes, this is the same as TAB. | |||
| 263 | In some text modes, where TAB inserts a tab, this indents to the | 263 | In some text modes, where TAB inserts a tab, this indents to the |
| 264 | column specified by the function `current-left-margin'." | 264 | column specified by the function `current-left-margin'." |
| 265 | (interactive "*") | 265 | (interactive "*") |
| 266 | (save-excursion | 266 | (delete-horizontal-space t) |
| 267 | (delete-horizontal-space t) | 267 | (let ((pos (point))) |
| 268 | (indent-according-to-mode)) | 268 | ;; Be careful to insert the newline before indenting the line. |
| 269 | (newline) | 269 | ;; Otherwise, the indentation might be wrong. |
| 270 | (indent-according-to-mode)) | 270 | (newline) |
| 271 | (save-excursion | ||
| 272 | (goto-char pos) | ||
| 273 | (indent-according-to-mode)) | ||
| 274 | (indent-according-to-mode))) | ||
| 271 | 275 | ||
| 272 | (defun quoted-insert (arg) | 276 | (defun quoted-insert (arg) |
| 273 | "Read next input character and insert it. | 277 | "Read next input character and insert it. |
| @@ -771,8 +775,8 @@ See also `minibuffer-history-case-insensitive-variables'." | |||
| 771 | (delete-minibuffer-contents) | 775 | (delete-minibuffer-contents) |
| 772 | (insert match-string) | 776 | (insert match-string) |
| 773 | (goto-char (+ (minibuffer-prompt-end) match-offset)))) | 777 | (goto-char (+ (minibuffer-prompt-end) match-offset)))) |
| 774 | (if (or (eq (car (car command-history)) 'previous-matching-history-element) | 778 | (if (memq (car (car command-history)) '(previous-matching-history-element |
| 775 | (eq (car (car command-history)) 'next-matching-history-element)) | 779 | next-matching-history-element)) |
| 776 | (setq command-history (cdr command-history)))) | 780 | (setq command-history (cdr command-history)))) |
| 777 | 781 | ||
| 778 | (defun next-matching-history-element (regexp n) | 782 | (defun next-matching-history-element (regexp n) |
| @@ -817,8 +821,8 @@ makes the search case-sensitive." | |||
| 817 | (error "End of history; no default available"))) | 821 | (error "End of history; no default available"))) |
| 818 | (if (> narg (length (symbol-value minibuffer-history-variable))) | 822 | (if (> narg (length (symbol-value minibuffer-history-variable))) |
| 819 | (error "Beginning of history; no preceding item")) | 823 | (error "Beginning of history; no preceding item")) |
| 820 | (unless (or (eq last-command 'next-history-element) | 824 | (unless (memq last-command '(next-history-element |
| 821 | (eq last-command 'previous-history-element)) | 825 | previous-history-element)) |
| 822 | (let ((prompt-end (minibuffer-prompt-end))) | 826 | (let ((prompt-end (minibuffer-prompt-end))) |
| 823 | (set (make-local-variable 'minibuffer-temporary-goal-position) | 827 | (set (make-local-variable 'minibuffer-temporary-goal-position) |
| 824 | (cond ((<= (point) prompt-end) prompt-end) | 828 | (cond ((<= (point) prompt-end) prompt-end) |
| @@ -1012,11 +1016,12 @@ we stop and ignore all further elements." | |||
| 1012 | (let ((position (car delta)) | 1016 | (let ((position (car delta)) |
| 1013 | (offset (cdr delta))) | 1017 | (offset (cdr delta))) |
| 1014 | 1018 | ||
| 1015 | ;; Loop down the earlier events adjusting their buffer positions | 1019 | ;; Loop down the earlier events adjusting their buffer |
| 1016 | ;; to reflect the fact that a change to the buffer isn't being | 1020 | ;; positions to reflect the fact that a change to the buffer |
| 1017 | ;; undone. We only need to process those element types which | 1021 | ;; isn't being undone. We only need to process those element |
| 1018 | ;; undo-elt-in-region will return as being in the region since | 1022 | ;; types which undo-elt-in-region will return as being in |
| 1019 | ;; only those types can ever get into the output | 1023 | ;; the region since only those types can ever get into the |
| 1024 | ;; output | ||
| 1020 | 1025 | ||
| 1021 | (while temp-undo-list | 1026 | (while temp-undo-list |
| 1022 | (setq undo-elt (car temp-undo-list)) | 1027 | (setq undo-elt (car temp-undo-list)) |
| @@ -1112,6 +1117,34 @@ is not *inside* the region START...END." | |||
| 1112 | '(0 . 0))) | 1117 | '(0 . 0))) |
| 1113 | '(0 . 0))) | 1118 | '(0 . 0))) |
| 1114 | 1119 | ||
| 1120 | (defun undo-get-state () | ||
| 1121 | "Return a handler for the current state to which we might want to undo. | ||
| 1122 | The returned handler can then be passed to `undo-revert-to-handle'." | ||
| 1123 | (unless (eq buffer-undo-list t) | ||
| 1124 | buffer-undo-list)) | ||
| 1125 | |||
| 1126 | (defun undo-revert-to-state (handle) | ||
| 1127 | "Revert to the state HANDLE earlier grabbed with `undo-get-handle'. | ||
| 1128 | This undoing is not itself undoable (aka redoable)." | ||
| 1129 | (unless (eq buffer-undo-list t) | ||
| 1130 | (let ((new-undo-list (cons (car handle) (cdr handle)))) | ||
| 1131 | ;; Truncate the undo log at `handle'. | ||
| 1132 | (when handle | ||
| 1133 | (setcar handle nil) (setcdr handle nil)) | ||
| 1134 | (unless (eq last-command 'undo) (undo-start)) | ||
| 1135 | ;; Make sure there's no confusion. | ||
| 1136 | (when (and handle (not (eq handle (last pending-undo-list)))) | ||
| 1137 | (error "Undoing to some unrelated state")) | ||
| 1138 | ;; Undo it all. | ||
| 1139 | (while pending-undo-list (undo-more 1)) | ||
| 1140 | ;; Reset the modified cons cell to its original content. | ||
| 1141 | (when handle | ||
| 1142 | (setcar handle (car new-undo-list)) | ||
| 1143 | (setcdr handle (cdr new-undo-list))) | ||
| 1144 | ;; Revert the undo info to what it was when we grabbed the state. | ||
| 1145 | (setq buffer-undo-list handle)))) | ||
| 1146 | |||
| 1147 | |||
| 1115 | (defvar shell-command-history nil | 1148 | (defvar shell-command-history nil |
| 1116 | "History list for some commands that read shell commands.") | 1149 | "History list for some commands that read shell commands.") |
| 1117 | 1150 | ||
| @@ -1137,9 +1170,7 @@ the buffer `*Shell Command Output*'. If the output is short enough to | |||
| 1137 | display in the echo area (which is determined by the variables | 1170 | display in the echo area (which is determined by the variables |
| 1138 | `resize-mini-windows' and `max-mini-window-height'), it is shown | 1171 | `resize-mini-windows' and `max-mini-window-height'), it is shown |
| 1139 | there, but it is nonetheless available in buffer `*Shell Command | 1172 | there, but it is nonetheless available in buffer `*Shell Command |
| 1140 | Output*' even though that buffer is not automatically displayed. If | 1173 | Output*' even though that buffer is not automatically displayed. |
| 1141 | there is no output, or if output is inserted in the current buffer, | ||
| 1142 | then `*Shell Command Output*' is deleted. | ||
| 1143 | 1174 | ||
| 1144 | To specify a coding system for converting non-ASCII characters | 1175 | To specify a coding system for converting non-ASCII characters |
| 1145 | in the shell command output, use \\[universal-coding-system-argument] | 1176 | in the shell command output, use \\[universal-coding-system-argument] |
| @@ -1397,10 +1428,10 @@ specifies the value of ERROR-BUFFER." | |||
| 1397 | (list t error-file) | 1428 | (list t error-file) |
| 1398 | t) | 1429 | t) |
| 1399 | nil shell-command-switch command)) | 1430 | nil shell-command-switch command)) |
| 1400 | ;;; It is rude to delete a buffer which the command is not using. | 1431 | ;; It is rude to delete a buffer which the command is not using. |
| 1401 | ;;; (let ((shell-buffer (get-buffer "*Shell Command Output*"))) | 1432 | ;; (let ((shell-buffer (get-buffer "*Shell Command Output*"))) |
| 1402 | ;;; (and shell-buffer (not (eq shell-buffer (current-buffer))) | 1433 | ;; (and shell-buffer (not (eq shell-buffer (current-buffer))) |
| 1403 | ;;; (kill-buffer shell-buffer))) | 1434 | ;; (kill-buffer shell-buffer))) |
| 1404 | ;; Don't muck with mark unless REPLACE says we should. | 1435 | ;; Don't muck with mark unless REPLACE says we should. |
| 1405 | (and replace swap (exchange-point-and-mark))) | 1436 | (and replace swap (exchange-point-and-mark))) |
| 1406 | ;; No prefix argument: put the output in a temp buffer, | 1437 | ;; No prefix argument: put the output in a temp buffer, |
| @@ -1449,7 +1480,10 @@ specifies the value of ERROR-BUFFER." | |||
| 1449 | (< 0 (nth 7 (file-attributes error-file)))) | 1480 | (< 0 (nth 7 (file-attributes error-file)))) |
| 1450 | "(Shell command %sed with some error output)" | 1481 | "(Shell command %sed with some error output)" |
| 1451 | "(Shell command %sed with no output)") | 1482 | "(Shell command %sed with no output)") |
| 1452 | (if (equal 0 exit-status) "succeed" "fail")))))) | 1483 | (if (equal 0 exit-status) "succeed" "fail")) |
| 1484 | ;; Don't kill: there might be useful info in the undo-log. | ||
| 1485 | ;; (kill-buffer buffer) | ||
| 1486 | )))) | ||
| 1453 | 1487 | ||
| 1454 | (when (and error-file (file-exists-p error-file)) | 1488 | (when (and error-file (file-exists-p error-file)) |
| 1455 | (if (< 0 (nth 7 (file-attributes error-file))) | 1489 | (if (< 0 (nth 7 (file-attributes error-file))) |
| @@ -2685,67 +2719,42 @@ With argument 0, interchanges line point is in with line mark is in." | |||
| 2685 | (forward-line arg)))) | 2719 | (forward-line arg)))) |
| 2686 | arg)) | 2720 | arg)) |
| 2687 | 2721 | ||
| 2688 | (defvar transpose-subr-start1) | 2722 | (defun transpose-subr (mover arg &optional special) |
| 2689 | (defvar transpose-subr-start2) | 2723 | (let ((aux (if special mover |
| 2690 | (defvar transpose-subr-end1) | 2724 | (lambda (x) |
| 2691 | (defvar transpose-subr-end2) | 2725 | (cons (progn (funcall mover x) (point)) |
| 2692 | 2726 | (progn (funcall mover (- x)) (point)))))) | |
| 2693 | (defun transpose-subr (mover arg) | 2727 | pos1 pos2) |
| 2694 | (let (transpose-subr-start1 | 2728 | (cond |
| 2695 | transpose-subr-end1 | 2729 | ((= arg 0) |
| 2696 | transpose-subr-start2 | 2730 | (save-excursion |
| 2697 | transpose-subr-end2) | 2731 | (setq pos1 (funcall aux 1)) |
| 2698 | (if (= arg 0) | 2732 | (goto-char (mark)) |
| 2699 | (progn | 2733 | (setq pos2 (funcall aux 1)) |
| 2700 | (save-excursion | 2734 | (transpose-subr-1 pos1 pos2)) |
| 2701 | (funcall mover 1) | 2735 | (exchange-point-and-mark)) |
| 2702 | (setq transpose-subr-end2 (point)) | 2736 | ((> arg 0) |
| 2703 | (funcall mover -1) | 2737 | (setq pos1 (funcall aux -1)) |
| 2704 | (setq transpose-subr-start2 (point)) | 2738 | (setq pos2 (funcall aux arg)) |
| 2705 | (goto-char (mark)) | 2739 | (transpose-subr-1 pos1 pos2) |
| 2706 | (funcall mover 1) | 2740 | (goto-char (car pos2))) |
| 2707 | (setq transpose-subr-end1 (point)) | 2741 | (t |
| 2708 | (funcall mover -1) | 2742 | (setq pos1 (funcall aux -1)) |
| 2709 | (setq transpose-subr-start1 (point)) | 2743 | (goto-char (car pos1)) |
| 2710 | (transpose-subr-1)) | 2744 | (setq pos2 (funcall aux arg)) |
| 2711 | (exchange-point-and-mark)) | 2745 | (transpose-subr-1 pos1 pos2))))) |
| 2712 | (if (> arg 0) | 2746 | |
| 2713 | (progn | 2747 | (defun transpose-subr-1 (pos1 pos2) |
| 2714 | (funcall mover -1) | 2748 | (when (> (car pos1) (cdr pos1)) (setq pos1 (cons (cdr pos1) (car pos1)))) |
| 2715 | (setq transpose-subr-start1 (point)) | 2749 | (when (> (car pos2) (cdr pos2)) (setq pos2 (cons (cdr pos2) (car pos2)))) |
| 2716 | (funcall mover 1) | 2750 | (when (> (car pos1) (car pos2)) |
| 2717 | (setq transpose-subr-end1 (point)) | 2751 | (let ((swap pos1)) |
| 2718 | (funcall mover arg) | 2752 | (setq pos1 pos2 pos2 swap))) |
| 2719 | (setq transpose-subr-end2 (point)) | 2753 | (if (> (cdr pos1) (car pos2)) (error "Don't have two things to transpose")) |
| 2720 | (funcall mover (- arg)) | 2754 | (let ((word2 (delete-and-extract-region (car pos2) (cdr pos2)))) |
| 2721 | (setq transpose-subr-start2 (point)) | 2755 | (goto-char (car pos2)) |
| 2722 | (transpose-subr-1) | 2756 | (insert (delete-and-extract-region (car pos1) (cdr pos1))) |
| 2723 | (goto-char transpose-subr-end2)) | 2757 | (goto-char (car pos1)) |
| 2724 | (funcall mover -1) | ||
| 2725 | (setq transpose-subr-start2 (point)) | ||
| 2726 | (funcall mover 1) | ||
| 2727 | (setq transpose-subr-end2 (point)) | ||
| 2728 | (funcall mover (1- arg)) | ||
| 2729 | (setq transpose-subr-start1 (point)) | ||
| 2730 | (funcall mover (- arg)) | ||
| 2731 | (setq transpose-subr-end1 (point)) | ||
| 2732 | (transpose-subr-1))))) | ||
| 2733 | |||
| 2734 | (defun transpose-subr-1 () | ||
| 2735 | (if (> (min transpose-subr-end1 transpose-subr-end2) | ||
| 2736 | (max transpose-subr-start1 transpose-subr-start2)) | ||
| 2737 | (error "Don't have two things to transpose")) | ||
| 2738 | (let* ((word1 (buffer-substring transpose-subr-start1 transpose-subr-end1)) | ||
| 2739 | (len1 (length word1)) | ||
| 2740 | (word2 (buffer-substring transpose-subr-start2 transpose-subr-end2)) | ||
| 2741 | (len2 (length word2))) | ||
| 2742 | (delete-region transpose-subr-start2 transpose-subr-end2) | ||
| 2743 | (goto-char transpose-subr-start2) | ||
| 2744 | (insert word1) | ||
| 2745 | (goto-char (if (< transpose-subr-start1 transpose-subr-start2) | ||
| 2746 | transpose-subr-start1 | ||
| 2747 | (+ transpose-subr-start1 (- len1 len2)))) | ||
| 2748 | (delete-region (point) (+ (point) len1)) | ||
| 2749 | (insert word2))) | 2758 | (insert word2))) |
| 2750 | 2759 | ||
| 2751 | (defun backward-word (arg) | 2760 | (defun backward-word (arg) |
| @@ -2809,8 +2818,7 @@ or adjacent to a word." | |||
| 2809 | (buffer-substring-no-properties start end))))) | 2818 | (buffer-substring-no-properties start end))))) |
| 2810 | 2819 | ||
| 2811 | (defcustom fill-prefix nil | 2820 | (defcustom fill-prefix nil |
| 2812 | "*String for filling to insert at front of new line, or nil for none. | 2821 | "*String for filling to insert at front of new line, or nil for none." |
| 2813 | Setting this variable automatically makes it local to the current buffer." | ||
| 2814 | :type '(choice (const :tag "None" nil) | 2822 | :type '(choice (const :tag "None" nil) |
| 2815 | string) | 2823 | string) |
| 2816 | :group 'fill) | 2824 | :group 'fill) |
| @@ -2852,15 +2860,18 @@ Setting this variable automatically makes it local to the current buffer.") | |||
| 2852 | (save-excursion (unjustify-current-line))) | 2860 | (save-excursion (unjustify-current-line))) |
| 2853 | 2861 | ||
| 2854 | ;; Choose a fill-prefix automatically. | 2862 | ;; Choose a fill-prefix automatically. |
| 2855 | (if (and adaptive-fill-mode | 2863 | (when (and adaptive-fill-mode |
| 2856 | (or (null fill-prefix) (string= fill-prefix ""))) | 2864 | (or (null fill-prefix) (string= fill-prefix ""))) |
| 2857 | (let ((prefix | 2865 | (let ((prefix |
| 2858 | (fill-context-prefix | 2866 | (fill-context-prefix |
| 2859 | (save-excursion (backward-paragraph 1) (point)) | 2867 | (save-excursion (backward-paragraph 1) (point)) |
| 2860 | (save-excursion (forward-paragraph 1) (point))))) | 2868 | (save-excursion (forward-paragraph 1) (point))))) |
| 2861 | (and prefix (not (equal prefix "")) | 2869 | (and prefix (not (equal prefix "")) |
| 2862 | (setq fill-prefix prefix)))) | 2870 | ;; Use auto-indentation rather than a guessed empty prefix. |
| 2863 | 2871 | (not (and fill-indent-according-to-mode | |
| 2872 | (string-match "[ \t]*" prefix))) | ||
| 2873 | (setq fill-prefix prefix)))) | ||
| 2874 | |||
| 2864 | (while (and (not give-up) (> (current-column) fc)) | 2875 | (while (and (not give-up) (> (current-column) fc)) |
| 2865 | ;; Determine where to split the line. | 2876 | ;; Determine where to split the line. |
| 2866 | (let* (after-prefix | 2877 | (let* (after-prefix |
| @@ -2882,20 +2893,9 @@ Setting this variable automatically makes it local to the current buffer.") | |||
| 2882 | ;; a character, or \c| following a character. If | 2893 | ;; a character, or \c| following a character. If |
| 2883 | ;; not found, place the point at beginning of line. | 2894 | ;; not found, place the point at beginning of line. |
| 2884 | (while (or first | 2895 | (while (or first |
| 2885 | ;; If this is after period and a single space, | ||
| 2886 | ;; move back once more--we don't want to break | ||
| 2887 | ;; the line there and make it look like a | ||
| 2888 | ;; sentence end. | ||
| 2889 | (and (not (bobp)) | ||
| 2890 | (not bounce) | ||
| 2891 | sentence-end-double-space | ||
| 2892 | (save-excursion (forward-char -1) | ||
| 2893 | (and (looking-at "\\. ") | ||
| 2894 | (not (looking-at "\\. "))))) | ||
| 2895 | (and (not (bobp)) | 2896 | (and (not (bobp)) |
| 2896 | (not bounce) | 2897 | (not bounce) |
| 2897 | fill-nobreak-predicate | 2898 | (fill-nobreak-p))) |
| 2898 | (funcall fill-nobreak-predicate))) | ||
| 2899 | (setq first nil) | 2899 | (setq first nil) |
| 2900 | (re-search-backward "[ \t]\\|\\c|.\\|.\\c|\\|^") | 2900 | (re-search-backward "[ \t]\\|\\c|.\\|.\\c|\\|^") |
| 2901 | ;; If we find nowhere on the line to break it, | 2901 | ;; If we find nowhere on the line to break it, |
| @@ -2958,8 +2958,8 @@ Setting this variable automatically makes it local to the current buffer.") | |||
| 2958 | ;; Now do justification, if required | 2958 | ;; Now do justification, if required |
| 2959 | (if (not (eq justify 'left)) | 2959 | (if (not (eq justify 'left)) |
| 2960 | (save-excursion | 2960 | (save-excursion |
| 2961 | (end-of-line 0) | 2961 | (end-of-line 0) |
| 2962 | (justify-current-line justify nil t))) | 2962 | (justify-current-line justify nil t))) |
| 2963 | ;; If making the new line didn't reduce the hpos of | 2963 | ;; If making the new line didn't reduce the hpos of |
| 2964 | ;; the end of the line, then give up now; | 2964 | ;; the end of the line, then give up now; |
| 2965 | ;; trying again will not help. | 2965 | ;; trying again will not help. |
| @@ -3371,9 +3371,9 @@ The properties used on SYMBOL are `composefunc', `sendfunc', | |||
| 3371 | (defun rfc822-goto-eoh () | 3371 | (defun rfc822-goto-eoh () |
| 3372 | ;; Go to header delimiter line in a mail message, following RFC822 rules | 3372 | ;; Go to header delimiter line in a mail message, following RFC822 rules |
| 3373 | (goto-char (point-min)) | 3373 | (goto-char (point-min)) |
| 3374 | (while (looking-at "^[^: \n]+:\\|^[ \t]") | 3374 | (when (re-search-forward |
| 3375 | (forward-line 1)) | 3375 | "^\\([:\n]\\|[^: \t\n]+[ \t\n]\\)" nil 'move) |
| 3376 | (point)) | 3376 | (goto-char (match-beginning 0)))) |
| 3377 | 3377 | ||
| 3378 | (defun sendmail-user-agent-compose (&optional to subject other-headers continue | 3378 | (defun sendmail-user-agent-compose (&optional to subject other-headers continue |
| 3379 | switch-function yank-action | 3379 | switch-function yank-action |
| @@ -3832,7 +3832,7 @@ PREFIX is the string that represents this modifier in an event type symbol." | |||
| 3832 | ;;; bindings. | 3832 | ;;; bindings. |
| 3833 | 3833 | ||
| 3834 | ;; Also tell read-char how to handle these keys. | 3834 | ;; Also tell read-char how to handle these keys. |
| 3835 | (mapcar | 3835 | (mapc |
| 3836 | (lambda (keypad-normal) | 3836 | (lambda (keypad-normal) |
| 3837 | (let ((keypad (nth 0 keypad-normal)) | 3837 | (let ((keypad (nth 0 keypad-normal)) |
| 3838 | (normal (nth 1 keypad-normal))) | 3838 | (normal (nth 1 keypad-normal))) |
| @@ -4137,7 +4137,7 @@ See also `normal-erase-is-backspace'." | |||
| 4137 | (stringp byte-compile-current-file))) | 4137 | (stringp byte-compile-current-file))) |
| 4138 | 4138 | ||
| 4139 | 4139 | ||
| 4140 | ;;; Minibuffer prompt stuff. | 4140 | ;; Minibuffer prompt stuff. |
| 4141 | 4141 | ||
| 4142 | ;(defun minibuffer-prompt-modification (start end) | 4142 | ;(defun minibuffer-prompt-modification (start end) |
| 4143 | ; (error "You cannot modify the prompt")) | 4143 | ; (error "You cannot modify the prompt")) |