1 |
;;; refill.el --- `auto-fill' by refilling paragraphs on changes |
;;; refill.el --- `auto-fill' by refilling paragraphs on changes |
2 |
|
|
3 |
;; Copyright (C) 2000 Free Software Foundation, Inc. |
;; Copyright (C) 2000, 2003 Free Software Foundation, Inc. |
4 |
|
|
5 |
;; Author: Dave Love <fx@gnu.org> |
;; Author: Dave Love <fx@gnu.org> |
6 |
|
;; Maintainer: Miles Bader <miles@gnu.org> |
7 |
;; Keywords: wp |
;; Keywords: wp |
8 |
|
|
9 |
;; This file is part of GNU Emacs. |
;; This file is part of GNU Emacs. |
102 |
(forward-line -1) |
(forward-line -1) |
103 |
(if (<= (point) (overlay-start overlay)) |
(if (<= (point) (overlay-start overlay)) |
104 |
;; Just get OVERLAY out of the way |
;; Just get OVERLAY out of the way |
105 |
(move-overlay overlay 1 1) |
(move-overlay overlay (point-min) (point-min)) |
106 |
;; Make overlay contain only the region |
;; Make overlay contain only the region |
107 |
(move-overlay overlay (overlay-start overlay) (point)))))) |
(move-overlay overlay (overlay-start overlay) (point)))))) |
108 |
|
|
109 |
(defun refill-fill-paragraph-at (pos &optional arg) |
(defun refill-fill-paragraph-at (pos &optional arg) |
110 |
"Like `fill-paragraph' at POS, but don't delete whitespace at paragraph end." |
"Like `fill-paragraph' at POS, but don't delete whitespace at paragraph end." |
111 |
(let (fill-pfx) |
(save-excursion |
112 |
(save-excursion |
(goto-char pos) |
113 |
(goto-char pos) |
;; FIXME: forward-paragraph seems to disregard `use-hard-newlines', |
114 |
;; FIXME: forward-paragraph seems to disregard `use-hard-newlines', |
;; leading to excessive refilling and wrong choice of fill-prefix. |
115 |
;; leading to excessive refilling and wrong choice of fill-prefix. |
;; might be a bug in my paragraphs.el. |
116 |
;; might be a bug in my paragraphs.el. |
(forward-paragraph) |
117 |
(forward-paragraph) |
(skip-syntax-backward "-") |
118 |
(let ((end (point)) |
(let ((end (point)) |
119 |
(beg (progn (backward-paragraph) (point))) |
(beg (progn (backward-paragraph) (point))) |
120 |
(obeg (overlay-start refill-ignorable-overlay)) |
(obeg (overlay-start refill-ignorable-overlay)) |
121 |
(oend (overlay-end refill-ignorable-overlay))) |
(oend (overlay-end refill-ignorable-overlay))) |
122 |
|
(unless (> beg pos) ;Don't fill if point is outside the paragraph. |
123 |
(goto-char pos) |
(goto-char pos) |
124 |
(if (and (>= beg obeg) (< beg oend)) |
(if (and (>= beg obeg) (< beg oend)) |
125 |
;; Limit filling to the modified tail of the paragraph. |
;; Limit filling to the modified tail of the paragraph. |
126 |
(let (;; When adaptive-fill-mode is enabled, the filling |
(let ( ;; When adaptive-fill-mode is enabled, the filling |
127 |
;; functions will attempt to set the fill prefix from |
;; functions will attempt to set the fill prefix from |
128 |
;; the fake paragraph bounds we pass in, so set it |
;; the fake paragraph bounds we pass in, so set it |
129 |
;; ourselves first, using the real paragraph bounds. |
;; ourselves first, using the real paragraph bounds. |
138 |
(if use-hard-newlines |
(if use-hard-newlines |
139 |
(fill-region oend end arg) |
(fill-region oend end arg) |
140 |
(fill-region-as-paragraph oend end arg))) |
(fill-region-as-paragraph oend end arg))) |
|
(setq fill-pfx fill-prefix) |
|
141 |
(move-overlay refill-ignorable-overlay obeg (point))) |
(move-overlay refill-ignorable-overlay obeg (point))) |
142 |
;; Fill the whole paragraph |
;; Fill the whole paragraph |
143 |
(setq fill-pfx |
(save-restriction |
144 |
(save-restriction |
(if use-hard-newlines |
145 |
(if use-hard-newlines |
(fill-region beg end arg) |
146 |
(fill-region beg end arg) |
(fill-region-as-paragraph beg end arg))) |
147 |
(fill-region-as-paragraph beg end arg)))) |
(move-overlay refill-ignorable-overlay beg (point))))))) |
|
(move-overlay refill-ignorable-overlay beg (point))))) |
|
|
(skip-line-prefix fill-pfx))) |
|
148 |
|
|
149 |
(defun refill-fill-paragraph (arg) |
(defun refill-fill-paragraph (arg) |
150 |
"Like `fill-paragraph' but don't delete whitespace at paragraph end." |
"Like `fill-paragraph' but don't delete whitespace at paragraph end." |
151 |
(refill-fill-paragraph-at (point) arg)) |
(refill-fill-paragraph-at (point) arg)) |
152 |
|
|
153 |
(defvar refill-doit nil |
(defvar refill-doit nil |
154 |
"Non-nil means that `refill-post-command-function' does its processing. |
"Non-nil tells `refill-post-command-function' to do its processing. |
155 |
Set by `refill-after-change-function' in `after-change-functions' and |
Set by `refill-after-change-function' in `after-change-functions' and |
156 |
unset by `refill-post-command-function' in `post-command-hook', and |
unset by `refill-post-command-function' in `post-command-hook', and |
157 |
sometimes `refill-pre-command-function' in `pre-command-hook'. This |
sometimes `refill-pre-command-function' in `pre-command-hook'. This |
257 |
|
|
258 |
(provide 'refill) |
(provide 'refill) |
259 |
|
|
260 |
|
;;; arch-tag: 2c4ce9e8-1daa-4a3b-b6f8-fd6ac5bf6138 |
261 |
;;; refill.el ends here |
;;; refill.el ends here |