Rename awp-mode since we're not bound to 8+3.
[emacs/old-mirror.git] / packages / adaptive-wrap-prefix / adaptive-wrap-prefix.el
blob3890fd65fde0033eac0a32563e710f67998eda69
1 ;;; adaptive-wrap-prefix.el --- Perform smart line-wrapping with wrap-prefix
3 ;; Copyright (C) 2011 Stefan Monnier
5 ;; Author: Stephen Berman <stephen.berman@gmx.net>
6 ;; Stefan Monnier <monnier@iro.umontreal.ca>
7 ;; Version: 0.1
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; Set the wrap-prefix property on the fly so that single-long-line paragraphs
25 ;; get word-wrapped in a way similar to what you'd get with M-q using
26 ;; adaptive-fill-mode, but without actually changing the buffer's text.
28 ;;; Code:
30 (defun adaptive-wrap-prefix-function (beg end)
31 "Indent the region between BEG and END with adaptive filling."
32 (goto-char beg)
33 (while (< (point) end)
34 (let ((blp (line-beginning-position)))
35 (put-text-property (point)
36 (progn (search-forward "\n" end 'move) (point))
37 'wrap-prefix
38 (fill-context-prefix blp (point))))))
40 ;;;###autoload
41 (define-minor-mode adaptive-wrap-prefix-mode
42 "Wrap the buffer text with adaptive filling."
43 :lighter ""
44 (if adaptive-wrap-prefix-mode
45 (jit-lock-register #'adaptive-wrap-prefix-function)
46 (jit-lock-unregister #'adaptive-wrap-prefix-function)
47 (with-silent-modifications
48 (save-restriction
49 (widen)
50 (remove-text-properties (point-min) (point-max) '(wrap-prefix nil))))))
53 (provide 'adaptive-wrap-prefix)
54 ;;; adaptive-wrap-prefix.el ends here