emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/pending r105054: * lisp/emacs-lisp/smie.el:


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/pending r105054: * lisp/emacs-lisp/smie.el: Provide smarter auto-filling.
Date: Wed, 15 Feb 2012 09:38:21 -0500
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 105054
committer: Stefan Monnier <address@hidden>
branch nick: pending
timestamp: Wed 2012-02-15 09:38:21 -0500
message:
  * lisp/emacs-lisp/smie.el: Provide smarter auto-filling.
  (smie-auto-fill): New function.
  (smie-setup): Use it.
modified:
  lisp/ChangeLog
  lisp/emacs-lisp/smie.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-12-27 19:30:39 +0000
+++ b/lisp/ChangeLog    2012-02-15 14:38:21 +0000
@@ -1,3 +1,9 @@
+2012-02-15  Stefan Monnier  <address@hidden>
+
+       * emacs-lisp/smie.el: Provide smarter auto-filling.
+       (smie-auto-fill): New function.
+       (smie-setup): Use it.
+
 2011-12-27  Vincent Belaïche  <address@hidden>
 
        * ses.el: The overall change is to add cell renaming, that is

=== modified file 'lisp/emacs-lisp/smie.el'
--- a/lisp/emacs-lisp/smie.el   2011-06-26 08:43:52 +0000
+++ b/lisp/emacs-lisp/smie.el   2012-02-15 14:38:21 +0000
@@ -1539,6 +1539,38 @@
           (save-excursion (indent-line-to indent))
         (indent-line-to indent)))))
 
+(defun smie-auto-fill ()
+  (let ((fc (current-fill-column))
+        (try-again nil))
+    (while (and fc (> (current-column) fc))
+      (cond
+       ((not (or (nth 8 (save-excursion
+                          (syntax-ppss (line-beginning-position))))
+                 (nth 8 (syntax-ppss))))
+        (save-excursion
+          (beginning-of-line)
+          (smie-indent-forward-token)
+          (let ((bsf (point))
+                (gain 0)
+                curcol)
+            (while (<= (setq curcol (current-column)) fc)
+              ;; FIXME?  `smie-indent-calculate' can (and often will)
+              ;; return a result that actually depends on the presence/absence
+              ;; of a newline, so the gain computed here may not be accurate,
+              ;; but in practice it seems to works well enough.
+              (let* ((newcol (smie-indent-calculate))
+                     (newgain (- curcol newcol)))
+                (when (> newgain gain)
+                  (setq gain newgain)
+                  (setq bsf (point))))
+              (smie-indent-forward-token))
+            (when (> gain 0)
+              (setq try-again)
+              (goto-char bsf)
+              (newline-and-indent)))))
+       (t (do-auto-fill))))))
+
+
 (defun smie-setup (grammar rules-function &rest keywords)
   "Setup SMIE navigation and indentation.
 GRAMMAR is a grammar table generated by `smie-prec2->grammar'.
@@ -1549,6 +1581,7 @@
   (set (make-local-variable 'smie-rules-function) rules-function)
   (set (make-local-variable 'smie-grammar) grammar)
   (set (make-local-variable 'indent-line-function) 'smie-indent-line)
+  (set (make-local-variable 'normal-auto-fill-function) 'smie-auto-fill)
   (set (make-local-variable 'forward-sexp-function)
        'smie-forward-sexp-command)
   (while keywords


reply via email to

[Prev in Thread] Current Thread [Next in Thread]