diff options
| -rw-r--r-- | lisp/simple.el | 110 |
1 files changed, 58 insertions, 52 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index a676353fa56..2f5562b5faf 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -2649,60 +2649,65 @@ Setting this variable automatically makes it local to the current buffer.") | |||
| 2649 | 2649 | ||
| 2650 | (while (and (not give-up) (> (current-column) fc)) | 2650 | (while (and (not give-up) (> (current-column) fc)) |
| 2651 | ;; Determine where to split the line. | 2651 | ;; Determine where to split the line. |
| 2652 | (let ((fill-point | 2652 | (let* (after-prefix |
| 2653 | (let ((opoint (point)) | 2653 | (fill-point |
| 2654 | bounce | 2654 | (let ((opoint (point)) |
| 2655 | (first t) | 2655 | bounce |
| 2656 | after-prefix) | 2656 | (first t)) |
| 2657 | (save-excursion | 2657 | (save-excursion |
| 2658 | (beginning-of-line) | 2658 | (beginning-of-line) |
| 2659 | (setq after-prefix (point)) | 2659 | (setq after-prefix (point)) |
| 2660 | (and fill-prefix | 2660 | (and fill-prefix |
| 2661 | (looking-at (regexp-quote fill-prefix)) | 2661 | (looking-at (regexp-quote fill-prefix)) |
| 2662 | (setq after-prefix (match-end 0))) | 2662 | (setq after-prefix (match-end 0))) |
| 2663 | (move-to-column (1+ fc)) | 2663 | (move-to-column (1+ fc)) |
| 2664 | ;; Move back to the point where we can break the | 2664 | ;; Move back to the point where we can break the |
| 2665 | ;; line at. We break the line between word or | 2665 | ;; line at. We break the line between word or |
| 2666 | ;; after/before the character which has character | 2666 | ;; after/before the character which has character |
| 2667 | ;; category `|'. We search space, \c| followed by | 2667 | ;; category `|'. We search space, \c| followed by |
| 2668 | ;; a character, or \c| follwoing a character. If | 2668 | ;; a character, or \c| follwoing a character. If |
| 2669 | ;; not found, place the point at beginning of line. | 2669 | ;; not found, place the point at beginning of line. |
| 2670 | (while (or first | 2670 | (while (or first |
| 2671 | ;; If this is after period and a single space, | 2671 | ;; If this is after period and a single space, |
| 2672 | ;; move back once more--we don't want to break | 2672 | ;; move back once more--we don't want to break |
| 2673 | ;; the line there and make it look like a | 2673 | ;; the line there and make it look like a |
| 2674 | ;; sentence end. | 2674 | ;; sentence end. |
| 2675 | (and (not (bobp)) | 2675 | (and (not (bobp)) |
| 2676 | (not bounce) | 2676 | (not bounce) |
| 2677 | sentence-end-double-space | 2677 | sentence-end-double-space |
| 2678 | (save-excursion (forward-char -1) | 2678 | (save-excursion (forward-char -1) |
| 2679 | (and (looking-at "\\. ") | 2679 | (and (looking-at "\\. ") |
| 2680 | (not (looking-at "\\. ")))))) | 2680 | (not (looking-at "\\. ")))))) |
| 2681 | (setq first nil) | 2681 | (setq first nil) |
| 2682 | (re-search-backward "[ \t]\\|\\c|.\\|.\\c|\\|^") | 2682 | (re-search-backward "[ \t]\\|\\c|.\\|.\\c|\\|^") |
| 2683 | ;; If we find nowhere on the line to break it, | 2683 | ;; If we find nowhere on the line to break it, |
| 2684 | ;; break after one word. Set bounce to t | 2684 | ;; break after one word. Set bounce to t |
| 2685 | ;; so we will not keep going in this while loop. | 2685 | ;; so we will not keep going in this while loop. |
| 2686 | (if (<= (point) after-prefix) | 2686 | (if (<= (point) after-prefix) |
| 2687 | (progn | 2687 | (progn |
| 2688 | (re-search-forward "[ \t]" opoint t) | 2688 | (goto-char after-prefix) |
| 2689 | (setq bounce t)) | 2689 | (re-search-forward "[ \t]" opoint t) |
| 2690 | (if (looking-at "[ \t]") | 2690 | (setq bounce t)) |
| 2691 | ;; Break the line at word boundary. | 2691 | (if (looking-at "[ \t]") |
| 2692 | (skip-chars-backward " \t") | 2692 | ;; Break the line at word boundary. |
| 2693 | ;; Break the line after/before \c|. | 2693 | (skip-chars-backward " \t") |
| 2694 | (forward-char 1)))) | 2694 | ;; Break the line after/before \c|. |
| 2695 | (if (and enable-kinsoku enable-multibyte-characters) | 2695 | (forward-char 1)))) |
| 2696 | (kinsoku (save-excursion | 2696 | (if (and enable-kinsoku enable-multibyte-characters) |
| 2697 | (forward-line 0) (point)))) | 2697 | (kinsoku (save-excursion |
| 2698 | ;; Let fill-point be set to the place where we end up. | 2698 | (forward-line 0) (point)))) |
| 2699 | (point))))) | 2699 | ;; Let fill-point be set to the place where we end up. |
| 2700 | 2700 | (point))))) | |
| 2701 | ;; If that place is not the beginning of the line, | 2701 | |
| 2702 | ;; break the line there. | 2702 | ;; See whether the place we found is any good. |
| 2703 | (if (save-excursion | 2703 | (if (save-excursion |
| 2704 | (goto-char fill-point) | 2704 | (goto-char fill-point) |
| 2705 | (and (not (bolp)) | 2705 | (and (not (bolp)) |
| 2706 | ;; There is no use breaking at end of line. | ||
| 2707 | (not (save-excursion (skip-chars-forward " ") (eolp))) | ||
| 2708 | ;; It is futile to split at the end of the prefix | ||
| 2709 | ;; since we would just insert the prefix again. | ||
| 2710 | (not (and after-prefix (<= (point) after-prefix))) | ||
| 2706 | ;; Don't split right after a comment starter | 2711 | ;; Don't split right after a comment starter |
| 2707 | ;; since we would just make another comment starter. | 2712 | ;; since we would just make another comment starter. |
| 2708 | (not (and comment-start-skip | 2713 | (not (and comment-start-skip |
| @@ -2711,6 +2716,7 @@ Setting this variable automatically makes it local to the current buffer.") | |||
| 2711 | (and (re-search-forward comment-start-skip | 2716 | (and (re-search-forward comment-start-skip |
| 2712 | limit t) | 2717 | limit t) |
| 2713 | (eq (point) limit))))))) | 2718 | (eq (point) limit))))))) |
| 2719 | ;; Ok, we have a useful place to break the line. Do it. | ||
| 2714 | (let ((prev-column (current-column))) | 2720 | (let ((prev-column (current-column))) |
| 2715 | ;; If point is at the fill-point, do not `save-excursion'. | 2721 | ;; If point is at the fill-point, do not `save-excursion'. |
| 2716 | ;; Otherwise, if a comment prefix or fill-prefix is inserted, | 2722 | ;; Otherwise, if a comment prefix or fill-prefix is inserted, |
| @@ -2732,7 +2738,7 @@ Setting this variable automatically makes it local to the current buffer.") | |||
| 2732 | ;; trying again will not help. | 2738 | ;; trying again will not help. |
| 2733 | (if (>= (current-column) prev-column) | 2739 | (if (>= (current-column) prev-column) |
| 2734 | (setq give-up t))) | 2740 | (setq give-up t))) |
| 2735 | ;; No place to break => stop trying. | 2741 | ;; No good place to break => stop trying. |
| 2736 | (setq give-up t)))) | 2742 | (setq give-up t)))) |
| 2737 | ;; Justify last line. | 2743 | ;; Justify last line. |
| 2738 | (justify-current-line justify t t) | 2744 | (justify-current-line justify t t) |