summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorGlenn Morris <rgm@gnu.org>2012-04-16 20:06:56 -0700
committerGlenn Morris <rgm@gnu.org>2012-04-16 20:06:56 -0700
commit2311d8e5a62b8b6dd7dde45b4b8059d443e2abac (patch)
tree9e526bc6f88f88c2925e05db797570cbc5ad7ee2 /lisp/emacs-lisp
parentfc72b15c777af496e9dcbc240f424135379ba955 (diff)
parent699c782b7668c44d0fa4446331b0590a6d5dac82 (diff)
downloademacs-2311d8e5a62b8b6dd7dde45b4b8059d443e2abac.tar.gz
emacs-2311d8e5a62b8b6dd7dde45b4b8059d443e2abac.tar.bz2
emacs-2311d8e5a62b8b6dd7dde45b4b8059d443e2abac.zip
Merge from pending; try to fix-up suboptimal ses ChangeLog.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/smie.el33
1 files changed, 33 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el
index 2a12f03e514..5382e601e67 100644
--- a/lisp/emacs-lisp/smie.el
+++ b/lisp/emacs-lisp/smie.el
@@ -1602,6 +1602,38 @@ to which that point should be aligned, if we were to reindent it.")
(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'.
@@ -1612,6 +1644,7 @@ KEYWORDS are additional arguments, which can use the following keywords:
(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