2021-03-15 09:15:29 +01:00
|
|
|
;;; refill.el --- `auto-fill' by refilling paragraphs on changes -*- lexical-binding: t -*-
|
2000-10-22 16:28:19 +00:00
|
|
|
|
2024-01-02 09:47:10 +08:00
|
|
|
;; Copyright (C) 2000-2024 Free Software Foundation, Inc.
|
2000-10-22 16:28:19 +00:00
|
|
|
|
|
|
|
;; Author: Dave Love <fx@gnu.org>
|
2003-08-20 19:00:06 +00:00
|
|
|
;; Maintainer: Miles Bader <miles@gnu.org>
|
2023-12-30 18:01:48 +01:00
|
|
|
;; Keywords: text
|
2000-10-22 16:28:19 +00:00
|
|
|
|
2001-07-13 12:59:13 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 04:34:22 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2000-10-22 16:28:19 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 04:34:22 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2001-07-13 12:59:13 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
2000-10-22 16:28:19 +00:00
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
2001-07-13 12:59:13 +00:00
|
|
|
|
2000-10-22 16:28:19 +00:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2000-10-22 16:28:19 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; Provides a mode where paragraphs are refilled after changes in them
|
2000-10-23 07:35:30 +00:00
|
|
|
;; (using `after-change-functions'). This gives something akin to typical
|
2000-10-22 16:28:19 +00:00
|
|
|
;; word processor-style filling. We restrict refilling due to
|
|
|
|
;; self-insertion to the characters which trigger auto-fill.
|
|
|
|
|
|
|
|
;; It partly satisfies a todo item in enriched.el for some value of
|
|
|
|
;; `without slowing down editing too much'. It doesn't attempt to do
|
|
|
|
;; anything (using `window-size-change-functions'?) about resizing
|
|
|
|
;; windows -- who cares?
|
|
|
|
|
|
|
|
;; This implementation is probably fragile and missing some special
|
|
|
|
;; cases -- not extensively tested. Yanking paragraph breaks, for
|
|
|
|
;; instance, won't DTRT by refilling all the relevant paragraphs.
|
|
|
|
|
|
|
|
;; You could do it a bit more efficiently (and robustly?) with just an
|
|
|
|
;; auto-fill function, but that doesn't cope with changes other than
|
|
|
|
;; through self-insertion. (Using auto-fill and after-change
|
|
|
|
;; functions together didn't seem winning.) This could probably
|
|
|
|
;; benefit from a less-general and faster `fill-paragraph-function',
|
|
|
|
;; ideally as a primitive.
|
|
|
|
|
|
|
|
;; The work is done in a local post-command hook but only if
|
|
|
|
;; `refill-doit' has been set by the after-change function. Using
|
2000-10-23 07:35:30 +00:00
|
|
|
;; `post-command-hook' ensures simply that refilling only happens
|
2000-10-22 16:28:19 +00:00
|
|
|
;; once per command.
|
|
|
|
|
|
|
|
;; [Per Abrahamsen's maniac.el does a similar thing, but operates from
|
|
|
|
;; post-command-hook. I don't understand the statement in it that
|
2000-10-23 07:35:30 +00:00
|
|
|
;; after-change-functions don't work for this purpose; perhaps there was
|
2000-10-22 16:28:19 +00:00
|
|
|
;; some Emacs bug at the time. ISTR maniac has problems with
|
|
|
|
;; whitespace at the end of paragraphs.]
|
|
|
|
|
2001-10-13 19:16:56 +00:00
|
|
|
;;; Todo/Bugs:
|
|
|
|
|
|
|
|
;; - When deleting the first word on a line, the space after that word tends
|
|
|
|
;; to become part of the fill-prefix, causing either wrong filling of the
|
|
|
|
;; remaining text, or causing the cursor to move unexpectedly. Ex:
|
|
|
|
;; Start with
|
|
|
|
;; I>< blabla
|
|
|
|
;;
|
|
|
|
;; and hit backspace. We end up with
|
|
|
|
;;
|
|
|
|
;; ><blabla
|
|
|
|
;; instead of
|
|
|
|
;; >< blabla
|
|
|
|
;;
|
|
|
|
;; Other example. Start with
|
|
|
|
;;
|
|
|
|
;; Foo bar blablabla asdgf
|
|
|
|
;; word>< asdfas dfasdfasd
|
|
|
|
;; asd asdfa sdfasd sdf
|
|
|
|
;;
|
|
|
|
;; and hit M-backspace. We end up with
|
|
|
|
;;
|
|
|
|
;; Foo bar blablabla asdgf
|
|
|
|
;; ><asdfas dfasdfasd asd
|
|
|
|
;; asdfa sdfasd sdf
|
|
|
|
|
2000-10-22 16:28:19 +00:00
|
|
|
;;; Code:
|
|
|
|
|
Prefer defvar-local in textmodes/*.el
This skips libraries that might want compatibility with Emacs 24.2.
* lisp/textmodes/artist.el (artist-curr-go)
(artist-line-char-set, artist-line-char, artist-fill-char-set)
(artist-fill-char, artist-erase-char, artist-default-fill-char)
(artist-draw-region-min-y, artist-draw-region-max-y)
(artist-borderless-shapes):
* lisp/textmodes/css-mode.el (css--at-ids, css--bang-ids)
(css--nested-selectors-allowed):
* lisp/textmodes/enriched.el (enriched-old-bindings):
* lisp/textmodes/flyspell.el (flyspell-generic-check-word-predicate)
(flyspell-consider-dash-as-word-delimiter-flag)
(flyspell-dash-dictionary, flyspell-dash-local-dictionary)
(flyspell-word-cache-start, flyspell-word-cache-end)
(flyspell-word-cache-word, flyspell-word-cache-result)
(flyspell-changes, flyspell-auto-correct-pos)
(flyspell-auto-correct-region, flyspell-auto-correct-ring)
(flyspell-auto-correct-word):
* lisp/textmodes/ispell.el (ispell-local-dictionary-overridden)
(ispell-local-pdict, ispell-buffer-session-localwords):
* lisp/textmodes/refill.el (refill-ignorable-overlay)
(refill-doit):
* lisp/textmodes/sgml-mode.el (html--buffer-classes-cache)
(html--buffer-ids-cache):
* lisp/textmodes/table.el (table-mode-indicator):
* lisp/textmodes/tex-mode.el (tex-send-command-modified-tick):
* lisp/textmodes/two-column.el (2C-autoscroll-start, 2C-mode):
Prefer defvar-local.
2021-01-31 18:45:47 +01:00
|
|
|
(defvar-local refill-ignorable-overlay nil
|
2000-11-21 01:11:49 +00:00
|
|
|
"Portion of the most recently filled paragraph not needing filling.
|
|
|
|
This is used to optimize refilling.")
|
|
|
|
|
2021-03-15 09:16:47 +01:00
|
|
|
(defun refill-adjust-ignorable-overlay (overlay afterp beg _end &optional _len)
|
2000-11-21 01:11:49 +00:00
|
|
|
"Adjust OVERLAY to not include the about-to-be-modified region."
|
|
|
|
(when (not afterp)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char beg)
|
|
|
|
(forward-line -1)
|
|
|
|
(if (<= (point) (overlay-start overlay))
|
|
|
|
;; Just get OVERLAY out of the way
|
2003-05-30 18:28:16 +00:00
|
|
|
(move-overlay overlay (point-min) (point-min))
|
2003-02-04 13:30:45 +00:00
|
|
|
;; Make overlay contain only the region
|
2000-11-21 01:11:49 +00:00
|
|
|
(move-overlay overlay (overlay-start overlay) (point))))))
|
|
|
|
|
|
|
|
(defun refill-fill-paragraph-at (pos &optional arg)
|
|
|
|
"Like `fill-paragraph' at POS, but don't delete whitespace at paragraph end."
|
2003-05-30 18:28:16 +00:00
|
|
|
(save-excursion
|
|
|
|
(goto-char pos)
|
|
|
|
;; FIXME: forward-paragraph seems to disregard `use-hard-newlines',
|
|
|
|
;; leading to excessive refilling and wrong choice of fill-prefix.
|
|
|
|
;; might be a bug in my paragraphs.el.
|
|
|
|
(forward-paragraph)
|
|
|
|
(skip-syntax-backward "-")
|
|
|
|
(let ((end (point))
|
|
|
|
(beg (progn (backward-paragraph) (point)))
|
|
|
|
(obeg (overlay-start refill-ignorable-overlay))
|
|
|
|
(oend (overlay-end refill-ignorable-overlay)))
|
|
|
|
(unless (> beg pos) ;Don't fill if point is outside the paragraph.
|
|
|
|
(goto-char pos)
|
|
|
|
(if (and (>= beg obeg) (< beg oend))
|
|
|
|
;; Limit filling to the modified tail of the paragraph.
|
|
|
|
(let ( ;; When adaptive-fill-mode is enabled, the filling
|
|
|
|
;; functions will attempt to set the fill prefix from
|
|
|
|
;; the fake paragraph bounds we pass in, so set it
|
|
|
|
;; ourselves first, using the real paragraph bounds.
|
|
|
|
(fill-prefix
|
|
|
|
(if (and adaptive-fill-mode
|
|
|
|
(or (null fill-prefix) (string= fill-prefix "")))
|
|
|
|
(fill-context-prefix beg end)
|
|
|
|
fill-prefix))
|
|
|
|
;; Turn off adaptive-fill-mode temporarily
|
|
|
|
(adaptive-fill-mode nil))
|
|
|
|
(save-restriction
|
|
|
|
(if use-hard-newlines
|
|
|
|
(fill-region oend end arg)
|
|
|
|
(fill-region-as-paragraph oend end arg)))
|
|
|
|
(move-overlay refill-ignorable-overlay obeg (point)))
|
|
|
|
;; Fill the whole paragraph
|
|
|
|
(save-restriction
|
|
|
|
(if use-hard-newlines
|
|
|
|
(fill-region beg end arg)
|
|
|
|
(fill-region-as-paragraph beg end arg)))
|
|
|
|
(move-overlay refill-ignorable-overlay beg (point)))))))
|
2000-11-21 01:11:49 +00:00
|
|
|
|
|
|
|
(defun refill-fill-paragraph (arg)
|
|
|
|
"Like `fill-paragraph' but don't delete whitespace at paragraph end."
|
|
|
|
(refill-fill-paragraph-at (point) arg))
|
2000-10-22 16:28:19 +00:00
|
|
|
|
Prefer defvar-local in textmodes/*.el
This skips libraries that might want compatibility with Emacs 24.2.
* lisp/textmodes/artist.el (artist-curr-go)
(artist-line-char-set, artist-line-char, artist-fill-char-set)
(artist-fill-char, artist-erase-char, artist-default-fill-char)
(artist-draw-region-min-y, artist-draw-region-max-y)
(artist-borderless-shapes):
* lisp/textmodes/css-mode.el (css--at-ids, css--bang-ids)
(css--nested-selectors-allowed):
* lisp/textmodes/enriched.el (enriched-old-bindings):
* lisp/textmodes/flyspell.el (flyspell-generic-check-word-predicate)
(flyspell-consider-dash-as-word-delimiter-flag)
(flyspell-dash-dictionary, flyspell-dash-local-dictionary)
(flyspell-word-cache-start, flyspell-word-cache-end)
(flyspell-word-cache-word, flyspell-word-cache-result)
(flyspell-changes, flyspell-auto-correct-pos)
(flyspell-auto-correct-region, flyspell-auto-correct-ring)
(flyspell-auto-correct-word):
* lisp/textmodes/ispell.el (ispell-local-dictionary-overridden)
(ispell-local-pdict, ispell-buffer-session-localwords):
* lisp/textmodes/refill.el (refill-ignorable-overlay)
(refill-doit):
* lisp/textmodes/sgml-mode.el (html--buffer-classes-cache)
(html--buffer-ids-cache):
* lisp/textmodes/table.el (table-mode-indicator):
* lisp/textmodes/tex-mode.el (tex-send-command-modified-tick):
* lisp/textmodes/two-column.el (2C-autoscroll-start, 2C-mode):
Prefer defvar-local.
2021-01-31 18:45:47 +01:00
|
|
|
(defvar-local refill-doit nil
|
2003-05-28 11:30:48 +00:00
|
|
|
"Non-nil tells `refill-post-command-function' to do its processing.
|
2000-10-23 07:35:30 +00:00
|
|
|
Set by `refill-after-change-function' in `after-change-functions' and
|
2000-11-21 01:11:49 +00:00
|
|
|
unset by `refill-post-command-function' in `post-command-hook', and
|
|
|
|
sometimes `refill-pre-command-function' in `pre-command-hook'. This
|
2000-10-22 16:28:19 +00:00
|
|
|
ensures refilling is only done once per command that causes a change,
|
|
|
|
regardless of the number of after-change calls from commands doing
|
|
|
|
complex processing.")
|
|
|
|
|
2021-03-15 09:16:47 +01:00
|
|
|
(defun refill-after-change-function (_beg end _len)
|
2021-09-22 20:26:40 +02:00
|
|
|
"Set `refill-doit'. Used by `after-change-functions'."
|
2000-10-22 16:28:19 +00:00
|
|
|
(unless undo-in-progress
|
2000-11-21 01:11:49 +00:00
|
|
|
(setq refill-doit end)))
|
2000-10-22 16:28:19 +00:00
|
|
|
|
|
|
|
(defun refill-post-command-function ()
|
|
|
|
"Post-command function to do refilling (conditionally)."
|
2000-11-21 01:11:49 +00:00
|
|
|
(when refill-doit ; there was a change
|
2000-10-22 16:28:19 +00:00
|
|
|
;; There's probably scope for more special cases here...
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
(pcase this-command
|
2018-11-05 01:22:15 +01:00
|
|
|
('self-insert-command
|
2005-01-23 22:01:59 +00:00
|
|
|
;; Treat self-insertion commands specially, since they don't
|
|
|
|
;; always reset `refill-doit' -- for self-insertion commands that
|
|
|
|
;; *don't* cause a refill, we want to leave it turned on so that
|
|
|
|
;; any subsequent non-modification command will cause a refill.
|
|
|
|
(when (aref auto-fill-chars (char-before))
|
|
|
|
;; Respond to the same characters as auto-fill (other than
|
|
|
|
;; newline, covered below).
|
|
|
|
(refill-fill-paragraph-at refill-doit)
|
|
|
|
(setq refill-doit nil)))
|
2018-11-05 01:22:15 +01:00
|
|
|
((or 'quoted-insert 'fill-paragraph 'fill-region) nil)
|
|
|
|
((or 'newline 'newline-and-indent 'open-line 'indent-new-comment-line
|
2019-06-27 16:57:47 +02:00
|
|
|
'default-indent-new-line 'reindent-then-newline-and-indent)
|
2005-01-23 22:01:59 +00:00
|
|
|
;; Don't zap what was just inserted.
|
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line) ; for newline-and-indent
|
|
|
|
(skip-chars-backward "\n")
|
|
|
|
(save-restriction
|
|
|
|
(narrow-to-region (point-min) (point))
|
|
|
|
(refill-fill-paragraph-at refill-doit)))
|
|
|
|
(widen)
|
|
|
|
(save-excursion
|
|
|
|
(skip-chars-forward "\n")
|
|
|
|
(save-restriction
|
|
|
|
(narrow-to-region (line-beginning-position) (point-max))
|
|
|
|
(refill-fill-paragraph-at refill-doit))))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
(_
|
2005-01-23 22:01:59 +00:00
|
|
|
(refill-fill-paragraph-at refill-doit)))
|
|
|
|
(setq refill-doit nil)))
|
2000-11-21 01:11:49 +00:00
|
|
|
|
|
|
|
(defun refill-pre-command-function ()
|
|
|
|
"Pre-command function to do refilling (conditionally)."
|
|
|
|
(when (and refill-doit (not (eq this-command 'self-insert-command)))
|
|
|
|
;; A previous setting of `refill-doit' didn't result in a refill,
|
|
|
|
;; because it was a self-insert-command. Since the next command is
|
|
|
|
;; something else, do the refill now.
|
|
|
|
(refill-fill-paragraph-at refill-doit)
|
2000-10-22 16:28:19 +00:00
|
|
|
(setq refill-doit nil)))
|
|
|
|
|
2005-01-23 22:01:59 +00:00
|
|
|
(defvar refill-saved-state nil)
|
2000-10-27 15:50:24 +00:00
|
|
|
|
2000-10-22 16:28:19 +00:00
|
|
|
;;;###autoload
|
|
|
|
(define-minor-mode refill-mode
|
2011-10-19 20:26:14 -04:00
|
|
|
"Toggle automatic refilling (Refill mode).
|
2000-10-22 16:28:19 +00:00
|
|
|
|
2011-10-19 20:26:14 -04:00
|
|
|
Refill mode is a buffer-local minor mode. When enabled, the
|
|
|
|
current paragraph is refilled as you edit. Self-inserting
|
|
|
|
characters only cause refilling if they would cause
|
|
|
|
auto-filling.
|
|
|
|
|
|
|
|
For true \"word wrap\" behavior, use `visual-line-mode' instead."
|
2013-05-15 19:55:41 -04:00
|
|
|
;; Not global, so no effect.
|
|
|
|
;;; :group 'refill
|
2005-04-04 09:29:08 +00:00
|
|
|
:lighter " Refill"
|
|
|
|
:keymap '(("\177" . backward-delete-char-untabify))
|
2001-12-22 12:25:14 +00:00
|
|
|
;; Remove old state if necessary
|
|
|
|
(when refill-ignorable-overlay
|
|
|
|
(delete-overlay refill-ignorable-overlay)
|
|
|
|
(kill-local-variable 'refill-ignorable-overlay))
|
2005-01-23 22:01:59 +00:00
|
|
|
(when (local-variable-p 'refill-saved-state)
|
|
|
|
(dolist (x refill-saved-state)
|
|
|
|
(set (make-local-variable (car x)) (cdr x)))
|
|
|
|
(kill-local-variable 'refill-saved-state))
|
2000-10-22 16:28:19 +00:00
|
|
|
(if refill-mode
|
2000-10-23 07:35:30 +00:00
|
|
|
(progn
|
* lisp/textmodes: Use lexical-binding
* lisp/textmodes/enriched.el: Use lexical-binding.
(enriched-mode): Use `delete-dups` to avoid `add-to-list` on
a local variable.
* lisp/textmodes/makeinfo.el: Use lexical-binding.
(makeinfo-region): Remove unused var `filename-or-header`.
* lisp/textmodes/refbib.el: Use lexical-binding.
(r2b-put-field): Remove unused var `multi-line`.
(r2b-barf-output): Remove unused var `match`.
* lisp/textmodes/refer.el: Use lexical-binding.
(refer-find-entry-internal): Remove unused vars `old-buffer` and `found`.
* lisp/textmodes/reftex-auc.el: Use lexical-binding.
(LaTeX-add-bibitems): Declare function.
(reftex-plug-into-AUCTeX): Use `add-function` and `advice-add` so we
can properly unplug.
* lisp/textmodes/reftex-cite.el: Use lexical-binding.
(reftex-create-bibtex-file): Remove unused var `file`.
(reftex--found-list): Declare var.
(reftex-offer-bib-menu): Rename local var to `reftex--found-list`.
* lisp/textmodes/reftex-dcr.el: Use lexical-binding.
(reftex-use-itimer-in-xemacs): Delete XEmacs-only var.
(reftex-toggle-auto-view-crossref): Delete XEmacs-only code.
(reftex-start-itimer-once): Delete XEmacs-only function.
* lisp/textmodes/reftex-global.el: Use lexical-binding.
(reftex-isearch-push-state-function): Use a closure instead of `(lambda).
* lisp/textmodes/reftex-index.el: Use lexical-binding.
(mark-active, transient-mark-mode): Delete var declarations.
(reftex-index-mode-map): Remove XEmacs-only code.
Use `mapc` so we can use closures instead of hand-built lambdas.
(reftex-index-next, reftex-index-previous): Tweak interactive spec to
remove unused prefix arg and mark it as a motion command.
(reftex-index-phrases-font-lock-keywords)
(reftex-index-phrases-font-lock-keywords): Move initialization into
declaration.
(reftex-index-initialize-phrases-buffer, reftex-index-phrases-mode)
reftex-index-phrases-apply-to-region: Remove XEmacs-only code.
(TeX-master): Remove redundant declaration.
(reftex--chars-first): Rename dynvar from `chars-first`. Adjust all uses.
* lisp/textmodes/reftex-parse.el: Use lexical-binding.
* lisp/textmodes/reftex-ref.el: Use lexical-binding.
(reftex-label): Remove always-nil var `text`.
(reftex-refstyle): Declare before first use.
(<toplevel>): Use closures rather than `eval` when building commands from
`reftex-ref-style-alist`.
* lisp/textmodes/reftex-sel.el: Use lexical-binding.
(reftex-select-label-mode-map, reftex-select-bib-mode-map):
Use `mapc` so we can use closures instead of hand-built lambdas.
(reftex-select-label-mode, reftex-select-bib-mode): Remove XEmacs-only code.
(reftex-select-data, reftex-select-prompt, reftex-refstyle):
Move declaration before first use.
(reftex--found-list, reftex--cb-flag, reftex--last-data)
(reftex--call-back, reftex--help-string): Move declaration before use,
and rename by adding `reftext--` prefix. Adjust all uses in this file.
For `reftex--found-list` adjust corresponding uses in `reftex-cite.el`.
(reftex-select-item): Explicitly let-bind them.
Remove XEmacs-only code.
* lisp/textmodes/reftex-toc.el: Use lexical-binding.
(reftex-toc-mode-map, reftex-toc-mode, reftex-toc-restore-region)
(reftex-toc-next, reftex-toc-previous, reftex-toc-next-heading)
(reftex-toc-previous-heading, reftex-toggle-auto-toc-recenter
(reftex-make-separate-toc-frame): Remove XEmacs-only code.
* lisp/textmodes/reftex-vars.el: Use lexical-binding.
* lisp/textmodes/reftex.el: Use lexical-binding.
(reftex-mode-map, reftex-mode, reftex-fontify-select-label-buffer)
(reftex-verified-face): Remove XEmacs-only code.
(reftex-region-active-p, reftex-overlay-put, reftex-move-overlay)
(reftex-make-overlay, reftex-get-buffer-visiting, reftex-delete-overlay):
Redefine as obsolete aliases. Replace all callers.
(current-message): Remove XEmacs-only definition.
* lisp/textmodes/remember.el: Use lexical-binding.
* lisp/textmodes/table.el (<toplevel>): Use closures rather than `(lambda)
to build commands.
* lisp/textmodes/texinfmt.el: Use lexical-binding.
(texinfo-example-start): Declare var.
(texinfo-format-region, texinfo-format-buffer-1): Remove unused var
`last-input-buffer`.
(texinfo-format-scan): Use `dlet` to bind `whitespace-silent`.
(texinfo-optional-braces-discard, texinfo-format-parse-line-args)
(texinfo-format-parse-args): Remove unused var `start`.
(texinfo-multitable-widths): Remove unused var `start-of-templates`.
(texinfo-multitable-item): Strength-reduce `eval` to `symbol-value`.
(texinfo-alias): Remove unused vars `start` and `args`.
(texinfo-defun-type symbol-property): Change the car to help the type
symbol rather than an expression returning it.
(texinfo-format-deffn): Remove corresponding `eval`.
(texinfo-clear): Remove unused var `value`.
(texinfo-format-ifeq): Remove unused var `end`.
* lisp/textmodes/texinfo.el: Use lexical-binding.
(tex-show-print-queue): Declare function.
* lisp/textmodes/texnfo-upd.el: Use lexical-binding.
(texinfo-start-menu-description): Remove unused var `end`.
(texinfo-insert-node-lines): Remove unused var `beginning-marker`.
(texinfo-multiple-files-update): Remove unused vars `next-node-name`
and `previous-node-name`.
* lisp/textmodes/two-column.el: Use lexical-binding.
2021-03-17 23:32:39 -04:00
|
|
|
(add-hook 'after-change-functions #'refill-after-change-function nil t)
|
|
|
|
(add-hook 'post-command-hook #'refill-post-command-function nil t)
|
|
|
|
(add-hook 'pre-command-hook #'refill-pre-command-function nil t)
|
2020-12-04 16:00:12 +01:00
|
|
|
(setq-local refill-saved-state
|
|
|
|
(mapcar (lambda (s) (cons s (symbol-value s)))
|
|
|
|
'(fill-paragraph-function auto-fill-function)))
|
2001-12-22 12:25:14 +00:00
|
|
|
;; This provides the test for recursive paragraph filling.
|
2020-12-04 16:00:12 +01:00
|
|
|
(setq-local fill-paragraph-function #'refill-fill-paragraph)
|
2001-10-13 19:16:56 +00:00
|
|
|
;; When using justification, doing DEL on 2 spaces should remove
|
|
|
|
;; both, otherwise, the subsequent refill will undo the DEL.
|
2020-12-04 16:00:12 +01:00
|
|
|
(setq-local backward-delete-char-untabify-method 'hungry)
|
2000-11-21 01:11:49 +00:00
|
|
|
(setq refill-ignorable-overlay (make-overlay 1 1 nil nil t))
|
|
|
|
(overlay-put refill-ignorable-overlay 'modification-hooks
|
|
|
|
'(refill-adjust-ignorable-overlay))
|
|
|
|
(overlay-put refill-ignorable-overlay 'insert-behind-hooks
|
|
|
|
'(refill-adjust-ignorable-overlay))
|
2000-10-23 07:35:30 +00:00
|
|
|
(auto-fill-mode 0))
|
* lisp/textmodes: Use lexical-binding
* lisp/textmodes/enriched.el: Use lexical-binding.
(enriched-mode): Use `delete-dups` to avoid `add-to-list` on
a local variable.
* lisp/textmodes/makeinfo.el: Use lexical-binding.
(makeinfo-region): Remove unused var `filename-or-header`.
* lisp/textmodes/refbib.el: Use lexical-binding.
(r2b-put-field): Remove unused var `multi-line`.
(r2b-barf-output): Remove unused var `match`.
* lisp/textmodes/refer.el: Use lexical-binding.
(refer-find-entry-internal): Remove unused vars `old-buffer` and `found`.
* lisp/textmodes/reftex-auc.el: Use lexical-binding.
(LaTeX-add-bibitems): Declare function.
(reftex-plug-into-AUCTeX): Use `add-function` and `advice-add` so we
can properly unplug.
* lisp/textmodes/reftex-cite.el: Use lexical-binding.
(reftex-create-bibtex-file): Remove unused var `file`.
(reftex--found-list): Declare var.
(reftex-offer-bib-menu): Rename local var to `reftex--found-list`.
* lisp/textmodes/reftex-dcr.el: Use lexical-binding.
(reftex-use-itimer-in-xemacs): Delete XEmacs-only var.
(reftex-toggle-auto-view-crossref): Delete XEmacs-only code.
(reftex-start-itimer-once): Delete XEmacs-only function.
* lisp/textmodes/reftex-global.el: Use lexical-binding.
(reftex-isearch-push-state-function): Use a closure instead of `(lambda).
* lisp/textmodes/reftex-index.el: Use lexical-binding.
(mark-active, transient-mark-mode): Delete var declarations.
(reftex-index-mode-map): Remove XEmacs-only code.
Use `mapc` so we can use closures instead of hand-built lambdas.
(reftex-index-next, reftex-index-previous): Tweak interactive spec to
remove unused prefix arg and mark it as a motion command.
(reftex-index-phrases-font-lock-keywords)
(reftex-index-phrases-font-lock-keywords): Move initialization into
declaration.
(reftex-index-initialize-phrases-buffer, reftex-index-phrases-mode)
reftex-index-phrases-apply-to-region: Remove XEmacs-only code.
(TeX-master): Remove redundant declaration.
(reftex--chars-first): Rename dynvar from `chars-first`. Adjust all uses.
* lisp/textmodes/reftex-parse.el: Use lexical-binding.
* lisp/textmodes/reftex-ref.el: Use lexical-binding.
(reftex-label): Remove always-nil var `text`.
(reftex-refstyle): Declare before first use.
(<toplevel>): Use closures rather than `eval` when building commands from
`reftex-ref-style-alist`.
* lisp/textmodes/reftex-sel.el: Use lexical-binding.
(reftex-select-label-mode-map, reftex-select-bib-mode-map):
Use `mapc` so we can use closures instead of hand-built lambdas.
(reftex-select-label-mode, reftex-select-bib-mode): Remove XEmacs-only code.
(reftex-select-data, reftex-select-prompt, reftex-refstyle):
Move declaration before first use.
(reftex--found-list, reftex--cb-flag, reftex--last-data)
(reftex--call-back, reftex--help-string): Move declaration before use,
and rename by adding `reftext--` prefix. Adjust all uses in this file.
For `reftex--found-list` adjust corresponding uses in `reftex-cite.el`.
(reftex-select-item): Explicitly let-bind them.
Remove XEmacs-only code.
* lisp/textmodes/reftex-toc.el: Use lexical-binding.
(reftex-toc-mode-map, reftex-toc-mode, reftex-toc-restore-region)
(reftex-toc-next, reftex-toc-previous, reftex-toc-next-heading)
(reftex-toc-previous-heading, reftex-toggle-auto-toc-recenter
(reftex-make-separate-toc-frame): Remove XEmacs-only code.
* lisp/textmodes/reftex-vars.el: Use lexical-binding.
* lisp/textmodes/reftex.el: Use lexical-binding.
(reftex-mode-map, reftex-mode, reftex-fontify-select-label-buffer)
(reftex-verified-face): Remove XEmacs-only code.
(reftex-region-active-p, reftex-overlay-put, reftex-move-overlay)
(reftex-make-overlay, reftex-get-buffer-visiting, reftex-delete-overlay):
Redefine as obsolete aliases. Replace all callers.
(current-message): Remove XEmacs-only definition.
* lisp/textmodes/remember.el: Use lexical-binding.
* lisp/textmodes/table.el (<toplevel>): Use closures rather than `(lambda)
to build commands.
* lisp/textmodes/texinfmt.el: Use lexical-binding.
(texinfo-example-start): Declare var.
(texinfo-format-region, texinfo-format-buffer-1): Remove unused var
`last-input-buffer`.
(texinfo-format-scan): Use `dlet` to bind `whitespace-silent`.
(texinfo-optional-braces-discard, texinfo-format-parse-line-args)
(texinfo-format-parse-args): Remove unused var `start`.
(texinfo-multitable-widths): Remove unused var `start-of-templates`.
(texinfo-multitable-item): Strength-reduce `eval` to `symbol-value`.
(texinfo-alias): Remove unused vars `start` and `args`.
(texinfo-defun-type symbol-property): Change the car to help the type
symbol rather than an expression returning it.
(texinfo-format-deffn): Remove corresponding `eval`.
(texinfo-clear): Remove unused var `value`.
(texinfo-format-ifeq): Remove unused var `end`.
* lisp/textmodes/texinfo.el: Use lexical-binding.
(tex-show-print-queue): Declare function.
* lisp/textmodes/texnfo-upd.el: Use lexical-binding.
(texinfo-start-menu-description): Remove unused var `end`.
(texinfo-insert-node-lines): Remove unused var `beginning-marker`.
(texinfo-multiple-files-update): Remove unused vars `next-node-name`
and `previous-node-name`.
* lisp/textmodes/two-column.el: Use lexical-binding.
2021-03-17 23:32:39 -04:00
|
|
|
(remove-hook 'after-change-functions #'refill-after-change-function t)
|
|
|
|
(remove-hook 'post-command-hook #'refill-post-command-function t)
|
2001-10-13 19:16:56 +00:00
|
|
|
(kill-local-variable 'backward-delete-char-untabify-method)))
|
2000-10-22 16:28:19 +00:00
|
|
|
|
|
|
|
(provide 'refill)
|
|
|
|
|
|
|
|
;;; refill.el ends here
|