From: Aaron Ecay <aaronecay@gmail.com>
To: Uwe Brauer <oub@mat.ucm.es>, emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: fill paragraph: break after sentence.
Date: Tue, 06 Sep 2016 11:38:56 +0100 [thread overview]
Message-ID: <87d1khz51b.fsf@gmail.com> (raw)
In-Reply-To: <874m5t308p.fsf@mat.ucm.es>
Hi Uwe,
The following code is what I use. It uses filladapt mode, but doesn’t
work with auto-fill (I manually refill paragraphs with M-q as I’m
writing). I wrote the code a long time ago, it works for me, YMMV,
etc. Hope it is helpful.
#+BEGIN_SRC emacs-lisp
(defun awe-org-fill-paragraph-function (&rest ignore)
(let ((bounds (cons (save-excursion (backward-paragraph) (point))
(save-excursion (forward-paragraph) (point))))
beg end end-marker)
(save-excursion
(goto-char (cdr bounds))
(skip-chars-backward "\n")
(setq end-marker (point-marker))
(setq end (make-marker))
(goto-char (car bounds))
(skip-chars-forward "\n")
(catch 'exit
(while t
(setq beg (point))
(forward-sentence)
(move-marker end (point))
(save-excursion
(goto-char beg)
(when (and fill-prefix
(not (looking-at-p (regexp-quote fill-prefix))))
(insert fill-prefix))
(while (re-search-forward "\n *" end t)
(replace-match " ")))
(setq beg (point))
(skip-chars-forward " \n")
(move-marker end (point))
(when (>= (point) end-marker)
(throw 'exit t))
(when (/= beg end)
(delete-region beg end))
(insert "\n"))))
(set-marker end-marker nil)
(set-marker end nil)))
(defun awe-org-setup-fill-hook ()
(setq-local sentence-end-base
(rx (any ".?!")
(? "[fn:" (+ (any "0-9" "a-f")) "]")
(* (any "]\"'”)}"))))
(when (featurep 'filladapt)
(setq-local fill-paragraph-function #'awe-org-fill-paragraph-function)
(make-local-variable 'filladapt-token-table)
(make-local-variable 'filladapt-token-match-table)
(make-local-variable 'filladapt-token-conversion-table)
(cl-pushnew `(,(rx "#+" (or "caption" "CAPTION") ": ") org-caption)
filladapt-token-table :test #'equal)
(cl-pushnew '(org-caption org-caption)
filladapt-token-match-table :test #'equal)
(cl-pushnew '(org-caption . exact)
filladapt-token-conversion-table :test #'equal))
(visual-line-mode 1)
(auto-fill-mode 0))
(add-hook 'org-mode-hook #'awe-org-setup-fill-hook)
#+END_SRC
--
Aaron Ecay
next prev parent reply other threads:[~2016-09-06 10:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-06 8:23 fill paragraph: break after sentence Uwe Brauer
2016-09-06 10:38 ` Aaron Ecay [this message]
2016-09-06 12:06 ` Uwe Brauer
2016-09-06 15:52 ` Nicolas Goaziou
2016-09-06 19:30 ` Uwe Brauer
2016-09-09 11:27 ` Andreas Röhler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87d1khz51b.fsf@gmail.com \
--to=aaronecay@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=oub@mat.ucm.es \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).