Commit ad2feb08 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

(refill-adjust-ignorable-overlay): Don't hardcode pint-min == 1.

(refill-fill-paragraph-at): Use a more robust method to detect
when the paragraph is after point.  Remove unused var `fill-pfx'.
parent aba7ce77
;;; refill.el --- `auto-fill' by refilling paragraphs on changes ;;; refill.el --- `auto-fill' by refilling paragraphs on changes
;; Copyright (C) 2000 Free Software Foundation, Inc. ;; Copyright (C) 2000, 2003 Free Software Foundation, Inc.
;; Author: Dave Love <fx@gnu.org> ;; Author: Dave Love <fx@gnu.org>
;; Keywords: wp ;; Keywords: wp
...@@ -101,53 +101,49 @@ This is used to optimize refilling.") ...@@ -101,53 +101,49 @@ This is used to optimize refilling.")
(forward-line -1) (forward-line -1)
(if (<= (point) (overlay-start overlay)) (if (<= (point) (overlay-start overlay))
;; Just get OVERLAY out of the way ;; Just get OVERLAY out of the way
(move-overlay overlay 1 1) (move-overlay overlay (point-min) (point-min))
;; Make overlay contain only the region ;; Make overlay contain only the region
(move-overlay overlay (overlay-start overlay) (point)))))) (move-overlay overlay (overlay-start overlay) (point))))))
(defun refill-fill-paragraph-at (pos &optional arg) (defun refill-fill-paragraph-at (pos &optional arg)
"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."
(let (fill-pfx) (save-excursion
(save-excursion (goto-char pos)
(goto-char pos) ;; FIXME: forward-paragraph seems to disregard `use-hard-newlines',
(unless (or (and (bolp) (eolp)) ;; leading to excessive refilling and wrong choice of fill-prefix.
(save-match-data (looking-at "\n\n"))) ;; might be a bug in my paragraphs.el.
;; FIXME: forward-paragraph seems to disregard `use-hard-newlines', (forward-paragraph)
;; leading to excessive refilling and wrong choice of fill-prefix. (skip-syntax-backward "-")
;; might be a bug in my paragraphs.el. (let ((end (point))
(forward-paragraph) (beg (progn (backward-paragraph) (point)))
(skip-syntax-backward "-") (obeg (overlay-start refill-ignorable-overlay))
(let ((end (point)) (oend (overlay-end refill-ignorable-overlay)))
(beg (progn (backward-paragraph) (point))) (unless (> beg pos) ;Don't fill if point is outside the paragraph.
(obeg (overlay-start refill-ignorable-overlay)) (goto-char pos)
(oend (overlay-end refill-ignorable-overlay))) (if (and (>= beg obeg) (< beg oend))
(goto-char pos) ;; Limit filling to the modified tail of the paragraph.
(if (and (>= beg obeg) (< beg oend)) (let ( ;; When adaptive-fill-mode is enabled, the filling
;; Limit filling to the modified tail of the paragraph. ;; functions will attempt to set the fill prefix from
(let ( ;; When adaptive-fill-mode is enabled, the filling ;; the fake paragraph bounds we pass in, so set it
;; functions will attempt to set the fill prefix from ;; ourselves first, using the real paragraph bounds.
;; the fake paragraph bounds we pass in, so set it (fill-prefix
;; ourselves first, using the real paragraph bounds. (if (and adaptive-fill-mode
(fill-prefix (or (null fill-prefix) (string= fill-prefix "")))
(if (and adaptive-fill-mode (fill-context-prefix beg end)
(or (null fill-prefix) (string= fill-prefix ""))) fill-prefix))
(fill-context-prefix beg end) ;; Turn off adaptive-fill-mode temporarily
fill-prefix)) (adaptive-fill-mode nil))
;; Turn off adaptive-fill-mode temporarily (save-restriction
(adaptive-fill-mode nil)) (if use-hard-newlines
(save-restriction (fill-region oend end arg)
(if use-hard-newlines (fill-region-as-paragraph oend end arg)))
(fill-region oend end arg) (move-overlay refill-ignorable-overlay obeg (point)))
(fill-region-as-paragraph oend end arg))) ;; Fill the whole paragraph
(setq fill-pfx fill-prefix) (save-restriction
(move-overlay refill-ignorable-overlay obeg (point))) (if use-hard-newlines
;; Fill the whole paragraph (fill-region beg end arg)
(setq fill-pfx (fill-region-as-paragraph beg end arg)))
(save-restriction (move-overlay refill-ignorable-overlay beg (point)))))))
(if use-hard-newlines
(fill-region beg end arg)
(fill-region-as-paragraph beg end arg))))
(move-overlay refill-ignorable-overlay beg (point))))))))
(defun refill-fill-paragraph (arg) (defun refill-fill-paragraph (arg)
"Like `fill-paragraph' but don't delete whitespace at paragraph end." "Like `fill-paragraph' but don't delete whitespace at paragraph end."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment