From 0a9560255c7f5f5e95b9437f764a4ad69c45714a Mon Sep 17 00:00:00 2001 From: Ryan Kavanagh Date: Tue, 5 Sep 2017 12:31:26 -0400 Subject: Fix paragraph filling in latex/auctex --- .emacs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/.emacs b/.emacs index 06a5822..c48d79f 100644 --- a/.emacs +++ b/.emacs @@ -246,8 +246,35 @@ convoluted. We use part of it --- skip comment par we are in." (unless (bolp) (LaTeX-newline)))))) + +;; http://www.cs.au.dk/~abizjak/emacs/2016/03/06/latex-fill-paragraph.html +(defun ales/fill-paragraph (&optional P) + "When called with prefix argument call `fill-paragraph'. +Otherwise split the current paragraph into one sentence per line." + (interactive "P") + (if (not P) + (save-excursion + (let ((fill-column 12345678)) ;; relies on dynamic binding + (fill-paragraph) ;; this will not work correctly if the paragraph is + ;; longer than 12345678 characters (in which case the + ;; file must be at least 12MB long. This is unlikely.) + (let ((end (save-excursion + (forward-paragraph 1) + (backward-sentence) + (point-marker)))) ;; remember where to stop + (beginning-of-line) + (while (progn (forward-sentence) + (<= (point) (marker-position end))) + (just-one-space) ;; leaves only one space, point is after it + (delete-char -1) ;; delete the space + (newline) ;; and insert a newline + (LaTeX-indent-line) ;; I only use this in combination with late, so this makes sense + )))) + ;; otherwise do ordinary fill paragraph + (fill-paragraph P))) + (eval-after-load "latex" - '(define-key LaTeX-mode-map (kbd "C-M-q") 'my-fill-latex-paragraph)) + '(define-key LaTeX-mode-map (kbd "M-q") 'ales/fill-paragraph)) (windmove-default-keybindings) (setq windmove-wrap-around t) -- cgit v1.2.3