Mercurial > dotfiles
annotate .elisp/settings/80.fill-paragraph.el @ 422:94a92c65299a
rust: drop RUST_SRC_PATH now that rustup handles rust stdlib sources
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Tue, 29 Nov 2016 13:22:42 -0500 |
parents | 887566d21cd8 |
children |
rev | line source |
---|---|
383
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
1 (defun kf-fill-paragraph (&optional justify) |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
2 "Like fill-paragraph, but don't mark the buffer as modified if no change. |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
3 |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
4 Emacs's native fill-paragraph is like the burglar who breaks into |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
5 your house, rearranges all your furniture exactly as it was, and |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
6 departs: even if the result of the fill is to leave the buffer in |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
7 exactly the same state, it still marks the buffer as modified so you |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
8 know you've been broken into. |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
9 |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
10 Note: to get this accepted into Emacs, it should watch the md5sum for |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
11 just the affected region rather than the entire buffer. See |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
12 `fill-region' and `fill-region-as-paragraph' in textmodes/fill.el. |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
13 The elegant solution would be a new macro, '(detect-buffer-unmodified |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
14 from to)' or something, that just wraps the relevant body of code in |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
15 those two functions. Then it could be used by other fill functions |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
16 easily too." |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
17 (interactive "P") |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
18 (let ((orig-md5sum (md5 (current-buffer))) |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
19 (was-modified-before-fill (buffer-modified-p))) |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
20 (fill-paragraph justify) |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
21 (let ((new-md5sum (md5 (current-buffer)))) |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
22 (when (string-equal orig-md5sum new-md5sum) |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
23 (set-buffer-modified-p was-modified-before-fill))))) |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
24 |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
25 (if (eq (key-binding "\M-q") 'fill-paragraph) |
887566d21cd8
fill-paragraph: steal kf-fill-paragraph from kfogel
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
26 (global-set-key "\M-q" 'kf-fill-paragraph)) |