Commits

Ahmad Khayyat committed 9295ee9

emacs: fill-sentence in LaTeX mode

  • Participants
  • Parent commits becda4d

Comments (0)

Files changed (1)

 (setq TeX-view-program-selection '((output-pdf "Evince")))
 ;;(setq TeX-source-correlate-start-server t)
 
+;; Fill sentences in latex documents. Line per sentence.
+(defun auto-fill-by-sentences ()
+  (if (looking-back (sentence-end))
+      ;; Break at a sentence
+      (progn
+        (LaTeX-newline)
+        t)
+    ;; Fall back to the default
+    (do-auto-fill)))
+(add-hook 'LaTeX-mode-hook (lambda () (setq auto-fill-function 'auto-fill-by-sentences)))
+
+(defadvice LaTeX-fill-region-as-paragraph (around LaTeX-sentence-filling)
+  "Start each sentence on a new line."
+  (let ((from (ad-get-arg 0))
+        (to-marker (set-marker (make-marker) (ad-get-arg 1)))
+        tmp-end)
+    (while (< from (marker-position to-marker))
+      (forward-sentence)
+      ;; might have gone beyond to-marker --- use whichever is smaller:
+      (ad-set-arg 1 (setq tmp-end (min (point) (marker-position to-marker))))
+      ad-do-it
+      (ad-set-arg 0 (setq from (point)))
+      (unless (or
+               (bolp)
+               (looking-at "\\s *$"))
+        (LaTeX-newline)))
+    (set-marker to-marker nil)))
+(ad-activate 'LaTeX-fill-region-as-paragraph)
+
 ;; VHDL-mode
 (setq vhdl-clock-edge-condition (quote function))
 (setq vhdl-standard (quote (93 nil)))