diff options
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/emacs-lisp/smie.el | 33 |
2 files changed, 39 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 29cb0334fb0..581ddc3788e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2012-02-15 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * emacs-lisp/smie.el: Provide smarter auto-filling. | ||
| 4 | (smie-auto-fill): New function. | ||
| 5 | (smie-setup): Use it. | ||
| 6 | |||
| 1 | 2011-12-27 Vincent Belaïche <vincentb1@users.sourceforge.net> | 7 | 2011-12-27 Vincent Belaïche <vincentb1@users.sourceforge.net> |
| 2 | 8 | ||
| 3 | * ses.el: The overall change is to add cell renaming, that is | 9 | * ses.el: The overall change is to add cell renaming, that is |
diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el index cad7c8419b2..49ee051e62d 100644 --- a/lisp/emacs-lisp/smie.el +++ b/lisp/emacs-lisp/smie.el | |||
| @@ -1539,6 +1539,38 @@ to which that point should be aligned, if we were to reindent it.") | |||
| 1539 | (save-excursion (indent-line-to indent)) | 1539 | (save-excursion (indent-line-to indent)) |
| 1540 | (indent-line-to indent))))) | 1540 | (indent-line-to indent))))) |
| 1541 | 1541 | ||
| 1542 | (defun smie-auto-fill () | ||
| 1543 | (let ((fc (current-fill-column)) | ||
| 1544 | (try-again nil)) | ||
| 1545 | (while (and fc (> (current-column) fc)) | ||
| 1546 | (cond | ||
| 1547 | ((not (or (nth 8 (save-excursion | ||
| 1548 | (syntax-ppss (line-beginning-position)))) | ||
| 1549 | (nth 8 (syntax-ppss)))) | ||
| 1550 | (save-excursion | ||
| 1551 | (beginning-of-line) | ||
| 1552 | (smie-indent-forward-token) | ||
| 1553 | (let ((bsf (point)) | ||
| 1554 | (gain 0) | ||
| 1555 | curcol) | ||
| 1556 | (while (<= (setq curcol (current-column)) fc) | ||
| 1557 | ;; FIXME? `smie-indent-calculate' can (and often will) | ||
| 1558 | ;; return a result that actually depends on the presence/absence | ||
| 1559 | ;; of a newline, so the gain computed here may not be accurate, | ||
| 1560 | ;; but in practice it seems to works well enough. | ||
| 1561 | (let* ((newcol (smie-indent-calculate)) | ||
| 1562 | (newgain (- curcol newcol))) | ||
| 1563 | (when (> newgain gain) | ||
| 1564 | (setq gain newgain) | ||
| 1565 | (setq bsf (point)))) | ||
| 1566 | (smie-indent-forward-token)) | ||
| 1567 | (when (> gain 0) | ||
| 1568 | (setq try-again) | ||
| 1569 | (goto-char bsf) | ||
| 1570 | (newline-and-indent))))) | ||
| 1571 | (t (do-auto-fill)))))) | ||
| 1572 | |||
| 1573 | |||
| 1542 | (defun smie-setup (grammar rules-function &rest keywords) | 1574 | (defun smie-setup (grammar rules-function &rest keywords) |
| 1543 | "Setup SMIE navigation and indentation. | 1575 | "Setup SMIE navigation and indentation. |
| 1544 | GRAMMAR is a grammar table generated by `smie-prec2->grammar'. | 1576 | GRAMMAR is a grammar table generated by `smie-prec2->grammar'. |
| @@ -1549,6 +1581,7 @@ KEYWORDS are additional arguments, which can use the following keywords: | |||
| 1549 | (set (make-local-variable 'smie-rules-function) rules-function) | 1581 | (set (make-local-variable 'smie-rules-function) rules-function) |
| 1550 | (set (make-local-variable 'smie-grammar) grammar) | 1582 | (set (make-local-variable 'smie-grammar) grammar) |
| 1551 | (set (make-local-variable 'indent-line-function) 'smie-indent-line) | 1583 | (set (make-local-variable 'indent-line-function) 'smie-indent-line) |
| 1584 | (set (make-local-variable 'normal-auto-fill-function) 'smie-auto-fill) | ||
| 1552 | (set (make-local-variable 'forward-sexp-function) | 1585 | (set (make-local-variable 'forward-sexp-function) |
| 1553 | 'smie-forward-sexp-command) | 1586 | 'smie-forward-sexp-command) |
| 1554 | (while keywords | 1587 | (while keywords |