diff options
| author | Lars Magne Ingebrigtsen | 2016-03-28 19:08:33 +0200 |
|---|---|---|
| committer | Lars Magne Ingebrigtsen | 2016-03-28 19:08:50 +0200 |
| commit | 742bf8243ca8155a1a139e90bcb654232513d8a9 (patch) | |
| tree | a7d9510e7e6912271562de1f0760039091be470b /lisp | |
| parent | 15357f6d1f90b03719f650823ac6531a305a9818 (diff) | |
| download | emacs-742bf8243ca8155a1a139e90bcb654232513d8a9.tar.gz emacs-742bf8243ca8155a1a139e90bcb654232513d8a9.zip | |
Have `M-q' not mark buffers are changed when they haven't
* lisp/textmodes/fill.el (fill-paragraph): Use `buffer-hash'
to avoid marking buffers as changed when they haven't.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/textmodes/fill.el | 128 |
1 files changed, 69 insertions, 59 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el index 100e2a24367..173d1c9d196 100644 --- a/lisp/textmodes/fill.el +++ b/lisp/textmodes/fill.el | |||
| @@ -804,65 +804,75 @@ region, instead of just filling the current paragraph." | |||
| 804 | (interactive (progn | 804 | (interactive (progn |
| 805 | (barf-if-buffer-read-only) | 805 | (barf-if-buffer-read-only) |
| 806 | (list (if current-prefix-arg 'full) t))) | 806 | (list (if current-prefix-arg 'full) t))) |
| 807 | (or | 807 | (let ((hash (and (not (buffer-modified-p)) |
| 808 | ;; 1. Fill the region if it is active when called interactively. | 808 | (buffer-hash)))) |
| 809 | (and region transient-mark-mode mark-active | 809 | (prog1 |
| 810 | (not (eq (region-beginning) (region-end))) | 810 | (or |
| 811 | (or (fill-region (region-beginning) (region-end) justify) t)) | 811 | ;; 1. Fill the region if it is active when called interactively. |
| 812 | ;; 2. Try fill-paragraph-function. | 812 | (and region transient-mark-mode mark-active |
| 813 | (and (not (eq fill-paragraph-function t)) | 813 | (not (eq (region-beginning) (region-end))) |
| 814 | (or fill-paragraph-function | 814 | (or (fill-region (region-beginning) (region-end) justify) t)) |
| 815 | (and (minibufferp (current-buffer)) | 815 | ;; 2. Try fill-paragraph-function. |
| 816 | (= 1 (point-min)))) | 816 | (and (not (eq fill-paragraph-function t)) |
| 817 | (let ((function (or fill-paragraph-function | 817 | (or fill-paragraph-function |
| 818 | ;; In the minibuffer, don't count the width | 818 | (and (minibufferp (current-buffer)) |
| 819 | ;; of the prompt. | 819 | (= 1 (point-min)))) |
| 820 | 'fill-minibuffer-function)) | 820 | (let ((function (or fill-paragraph-function |
| 821 | ;; If fill-paragraph-function is set, it probably takes care | 821 | ;; In the minibuffer, don't count |
| 822 | ;; of comments and stuff. If not, it will have to set | 822 | ;; the width of the prompt. |
| 823 | ;; fill-paragraph-handle-comment back to t explicitly or | 823 | 'fill-minibuffer-function)) |
| 824 | ;; return nil. | 824 | ;; If fill-paragraph-function is set, it probably |
| 825 | (fill-paragraph-handle-comment nil) | 825 | ;; takes care of comments and stuff. If not, it |
| 826 | (fill-paragraph-function t)) | 826 | ;; will have to set fill-paragraph-handle-comment |
| 827 | (funcall function justify))) | 827 | ;; back to t explicitly or return nil. |
| 828 | ;; 3. Try our syntax-aware filling code. | 828 | (fill-paragraph-handle-comment nil) |
| 829 | (and fill-paragraph-handle-comment | 829 | (fill-paragraph-function t)) |
| 830 | ;; Our code only handles \n-terminated comments right now. | 830 | (funcall function justify))) |
| 831 | comment-start (equal comment-end "") | 831 | ;; 3. Try our syntax-aware filling code. |
| 832 | (let ((fill-paragraph-handle-comment nil)) | 832 | (and fill-paragraph-handle-comment |
| 833 | (fill-comment-paragraph justify))) | 833 | ;; Our code only handles \n-terminated comments right now. |
| 834 | ;; 4. If it all fails, default to the good ol' text paragraph filling. | 834 | comment-start (equal comment-end "") |
| 835 | (let ((before (point)) | 835 | (let ((fill-paragraph-handle-comment nil)) |
| 836 | (paragraph-start paragraph-start) | 836 | (fill-comment-paragraph justify))) |
| 837 | ;; Fill prefix used for filling the paragraph. | 837 | ;; 4. If it all fails, default to the good ol' text paragraph filling. |
| 838 | fill-pfx) | 838 | (let ((before (point)) |
| 839 | ;; Try to prevent code sections and comment sections from being | 839 | (paragraph-start paragraph-start) |
| 840 | ;; filled together. | 840 | ;; Fill prefix used for filling the paragraph. |
| 841 | (when (and fill-paragraph-handle-comment comment-start-skip) | 841 | fill-pfx) |
| 842 | (setq paragraph-start | 842 | ;; Try to prevent code sections and comment sections from being |
| 843 | (concat paragraph-start "\\|[ \t]*\\(?:" | 843 | ;; filled together. |
| 844 | comment-start-skip "\\)"))) | 844 | (when (and fill-paragraph-handle-comment comment-start-skip) |
| 845 | (save-excursion | 845 | (setq paragraph-start |
| 846 | ;; To make sure the return value of forward-paragraph is meaningful, | 846 | (concat paragraph-start "\\|[ \t]*\\(?:" |
| 847 | ;; we have to start from the beginning of line, otherwise skipping | 847 | comment-start-skip "\\)"))) |
| 848 | ;; past the last few chars of a paragraph-separator would count as | 848 | (save-excursion |
| 849 | ;; a paragraph (and not skipping any chars at EOB would not count | 849 | ;; To make sure the return value of forward-paragraph is |
| 850 | ;; as a paragraph even if it is). | 850 | ;; meaningful, we have to start from the beginning of |
| 851 | (move-to-left-margin) | 851 | ;; line, otherwise skipping past the last few chars of a |
| 852 | (if (not (zerop (fill-forward-paragraph 1))) | 852 | ;; paragraph-separator would count as a paragraph (and |
| 853 | ;; There's no paragraph at or after point: give up. | 853 | ;; not skipping any chars at EOB would not count as a |
| 854 | (setq fill-pfx "") | 854 | ;; paragraph even if it is). |
| 855 | (let ((end (point)) | 855 | (move-to-left-margin) |
| 856 | (beg (progn (fill-forward-paragraph -1) (point)))) | 856 | (if (not (zerop (fill-forward-paragraph 1))) |
| 857 | (goto-char before) | 857 | ;; There's no paragraph at or after point: give up. |
| 858 | (setq fill-pfx | 858 | (setq fill-pfx "") |
| 859 | (if use-hard-newlines | 859 | (let ((end (point)) |
| 860 | ;; Can't use fill-region-as-paragraph, since this | 860 | (beg (progn (fill-forward-paragraph -1) (point)))) |
| 861 | ;; paragraph may still contain hard newlines. See | 861 | (goto-char before) |
| 862 | ;; fill-region. | 862 | (setq fill-pfx |
| 863 | (fill-region beg end justify) | 863 | (if use-hard-newlines |
| 864 | (fill-region-as-paragraph beg end justify)))))) | 864 | ;; Can't use fill-region-as-paragraph, since this |
| 865 | fill-pfx))) | 865 | ;; paragraph may still contain hard newlines. See |
| 866 | ;; fill-region. | ||
| 867 | (fill-region beg end justify) | ||
| 868 | (fill-region-as-paragraph beg end justify)))))) | ||
| 869 | fill-pfx)) | ||
| 870 | ;; If we didn't change anything in the buffer (and the buffer | ||
| 871 | ;; was previously unmodified), then flip the modification status | ||
| 872 | ;; back to "unchanged". | ||
| 873 | (when (and hash | ||
| 874 | (equal hash (buffer-hash))) | ||
| 875 | (set-buffer-modified-p nil))))) | ||
| 866 | 876 | ||
| 867 | (declare-function comment-search-forward "newcomment" (limit &optional noerror)) | 877 | (declare-function comment-search-forward "newcomment" (limit &optional noerror)) |
| 868 | (declare-function comment-string-strip "newcomment" (str beforep afterp)) | 878 | (declare-function comment-string-strip "newcomment" (str beforep afterp)) |