diff options
| author | Lars Ingebrigtsen | 2019-07-12 15:48:34 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-07-12 15:48:34 +0200 |
| commit | 4438459eaa6cccdac2cfcc8f7d5f248bfe8d1edf (patch) | |
| tree | c27964fd802ef038874eef5dd38a773f61dee16c /lisp | |
| parent | c281b9a121a251b19e3e90b67ca85fbe834b3bc2 (diff) | |
| download | emacs-4438459eaa6cccdac2cfcc8f7d5f248bfe8d1edf.tar.gz emacs-4438459eaa6cccdac2cfcc8f7d5f248bfe8d1edf.zip | |
Refactor rfc2047-fold-region slightly and add a couple of tests
* lisp/mail/rfc2047.el (rfc2047--break-line): Refactor out to
avoid code repetition...
(rfc2047-fold-region): ... from this function.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/mail/rfc2047.el | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/lisp/mail/rfc2047.el b/lisp/mail/rfc2047.el index 5f2abc435d1..9de6f02edfb 100644 --- a/lisp/mail/rfc2047.el +++ b/lisp/mail/rfc2047.el | |||
| @@ -743,18 +743,9 @@ Point moves to the end of the region." | |||
| 743 | (> (- (point) bol) 76)) | 743 | (> (- (point) bol) 76)) |
| 744 | ;; We have a line longer than 76 characters, so break the | 744 | ;; We have a line longer than 76 characters, so break the |
| 745 | ;; line. | 745 | ;; line. |
| 746 | (goto-char (or break qword-break)) | 746 | (setq bol (rfc2047--break-line break qword-break) |
| 747 | (setq break nil | 747 | break nil |
| 748 | qword-break nil) | 748 | qword-break nil)) |
| 749 | (skip-chars-backward " \t") | ||
| 750 | (if (looking-at "[ \t]") | ||
| 751 | (insert ?\n) | ||
| 752 | (insert "\n ")) | ||
| 753 | (setq bol (1- (point))) | ||
| 754 | ;; Don't break before the first non-LWSP characters. | ||
| 755 | (skip-chars-forward " \t") | ||
| 756 | (unless (eobp) | ||
| 757 | (forward-char 1))) | ||
| 758 | ;; See whether we're at a point where we can break the line | 749 | ;; See whether we're at a point where we can break the line |
| 759 | ;; (if it turns out to be too long). | 750 | ;; (if it turns out to be too long). |
| 760 | (cond | 751 | (cond |
| @@ -791,22 +782,25 @@ Point moves to the end of the region." | |||
| 791 | (t | 782 | (t |
| 792 | (skip-chars-forward "^ \t\n\r"))) | 783 | (skip-chars-forward "^ \t\n\r"))) |
| 793 | (setq first nil)) | 784 | (setq first nil)) |
| 794 | ;; Finally, after the loop, we have a line longer than 76 | ||
| 795 | ;; characters, so break the line. | ||
| 796 | (when (and (or break qword-break) | 785 | (when (and (or break qword-break) |
| 797 | (> (- (point) bol) 76)) | 786 | (> (- (point) bol) 76)) |
| 798 | (goto-char (or break qword-break)) | 787 | ;; Finally, after the loop, we have a line longer than 76 |
| 799 | (setq break nil | 788 | ;; characters, so break the line. |
| 800 | qword-break nil) | 789 | (rfc2047--break-line break qword-break))))) |
| 801 | (if (or (> 0 (skip-chars-backward " \t")) | 790 | |
| 802 | (looking-at "[ \t]")) | 791 | (defun rfc2047--break-line (break qword-break) |
| 803 | (insert ?\n) | 792 | (goto-char (or break qword-break)) |
| 804 | (insert "\n ")) | 793 | (skip-chars-backward " \t") |
| 805 | (setq bol (1- (point))) | 794 | (if (looking-at "[ \t]") |
| 806 | ;; Don't break before the first non-LWSP characters. | 795 | (insert ?\n) |
| 807 | (skip-chars-forward " \t") | 796 | (insert "\n ")) |
| 808 | (unless (eobp) | 797 | (prog1 |
| 809 | (forward-char 1)))))) | 798 | ;; Return beginning-of-line. |
| 799 | (1- (point)) | ||
| 800 | ;; Don't break before the first non-LWSP characters. | ||
| 801 | (skip-chars-forward " \t") | ||
| 802 | (unless (eobp) | ||
| 803 | (forward-char 1)))) | ||
| 810 | 804 | ||
| 811 | (defun rfc2047-unfold-field () | 805 | (defun rfc2047-unfold-field () |
| 812 | "Fold the current line." | 806 | "Fold the current line." |