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