diff options
| author | Stefan Monnier | 2010-11-11 00:08:25 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2010-11-11 00:08:25 -0500 |
| commit | 7bea8c7a92e1fb3eaf1a4e9f2becdaf0074f64ad (patch) | |
| tree | 799b01120007f6fd7b8317fd196548cec249a8b4 | |
| parent | b010e1bafc67c58eff793c24fea0d113fd03e23b (diff) | |
| download | emacs-7bea8c7a92e1fb3eaf1a4e9f2becdaf0074f64ad.tar.gz emacs-7bea8c7a92e1fb3eaf1a4e9f2becdaf0074f64ad.zip | |
* lisp/emacs-lisp/smie.el (smie-rule-parent, smie-indent--rule):
Use smie-indent-virtual when indenting relative to an opener.
(smie-rule-separator): Use smie-rule-parent.
(smie-indent-keyword): Consult rules, even for openers at bol.
(smie-indent-comment-close): Try to align closer's content.
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/emacs-lisp/smie.el | 67 |
2 files changed, 59 insertions, 16 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index cefe89ab338..88dc22a011d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2010-11-11 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * emacs-lisp/smie.el (smie-rule-parent, smie-indent--rule): | ||
| 4 | Use smie-indent-virtual when indenting relative to an opener. | ||
| 5 | (smie-rule-separator): Use smie-rule-parent. | ||
| 6 | (smie-indent-keyword): Consult rules, even for openers at bol. | ||
| 7 | (smie-indent-comment-close): Try to align closer's content. | ||
| 8 | |||
| 1 | 2010-11-11 Glenn Morris <rgm@gnu.org> | 9 | 2010-11-11 Glenn Morris <rgm@gnu.org> |
| 2 | 10 | ||
| 3 | * ls-lisp.el (ls-lisp-dired-ignore-case): Make it an obsolete alias. | 11 | * ls-lisp.el (ls-lisp-dired-ignore-case): Make it an obsolete alias. |
diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el index 03c03126d2f..e944902f6e3 100644 --- a/lisp/emacs-lisp/smie.el +++ b/lisp/emacs-lisp/smie.el | |||
| @@ -63,6 +63,17 @@ | |||
| 63 | ;; Since then, some of that code has been beaten into submission, but the | 63 | ;; Since then, some of that code has been beaten into submission, but the |
| 64 | ;; smie-indent-keyword is still pretty obscure. | 64 | ;; smie-indent-keyword is still pretty obscure. |
| 65 | 65 | ||
| 66 | ;; Conflict resolution: | ||
| 67 | ;; | ||
| 68 | ;; - One source of conflicts is when you have: | ||
| 69 | ;; (exp ("IF" exp "ELSE" exp "END") ("CASE" cases "END")) | ||
| 70 | ;; (cases (cases "ELSE" insts) ...) | ||
| 71 | ;; The IF-rule implies ELSE=END and the CASE-rule implies ELSE>END. | ||
| 72 | ;; FIXME: we could try to resolve such conflicts automatically by changing | ||
| 73 | ;; the way BNF rules such as the IF-rule is handled. I.e. rather than | ||
| 74 | ;; IF=ELSE and ELSE=END, we could turn them into IF<ELSE and ELSE>END | ||
| 75 | ;; and IF=END, | ||
| 76 | |||
| 66 | ;;; Code: | 77 | ;;; Code: |
| 67 | 78 | ||
| 68 | ;; FIXME: I think the behavior on empty lines is wrong. It shouldn't | 79 | ;; FIXME: I think the behavior on empty lines is wrong. It shouldn't |
| @@ -155,6 +166,11 @@ one of those elements share the same precedence level and associativity." | |||
| 155 | 166 | ||
| 156 | (put 'smie-bnf->prec2 'pure t) | 167 | (put 'smie-bnf->prec2 'pure t) |
| 157 | (defun smie-bnf->prec2 (bnf &rest precs) | 168 | (defun smie-bnf->prec2 (bnf &rest precs) |
| 169 | ;; FIXME: Add repetition operator like (repeat <separator> <elems>). | ||
| 170 | ;; Maybe also add (or <elem1> <elem2>...) for things like | ||
| 171 | ;; (exp (exp (or "+" "*" "=" ..) exp)). | ||
| 172 | ;; Basically, make it EBNF (except for the specification of a separator in | ||
| 173 | ;; the repetition). | ||
| 158 | (let ((nts (mapcar 'car bnf)) ;Non-terminals | 174 | (let ((nts (mapcar 'car bnf)) ;Non-terminals |
| 159 | (first-ops-table ()) | 175 | (first-ops-table ()) |
| 160 | (last-ops-table ()) | 176 | (last-ops-table ()) |
| @@ -613,7 +629,7 @@ Possible return values: | |||
| 613 | ;; It is the last element, let's stop here. | 629 | ;; It is the last element, let's stop here. |
| 614 | (throw 'return (list nil (point) token))) | 630 | (throw 'return (list nil (point) token))) |
| 615 | ;; If the new operator is not the last in the BNF rule, | 631 | ;; If the new operator is not the last in the BNF rule, |
| 616 | ;; ans is not associative, it's one of the inner operators | 632 | ;; and is not associative, it's one of the inner operators |
| 617 | ;; (like the "in" in "let .. in .. end"), so keep looking. | 633 | ;; (like the "in" in "let .. in .. end"), so keep looking. |
| 618 | ((not (smie--associative-p toklevels)) | 634 | ((not (smie--associative-p toklevels)) |
| 619 | (push toklevels levels)) | 635 | (push toklevels levels)) |
| @@ -969,8 +985,14 @@ Only meaningful when called from within `smie-rules-function'." | |||
| 969 | (goto-char (cadr (smie-indent--parent))) | 985 | (goto-char (cadr (smie-indent--parent))) |
| 970 | (cons 'column | 986 | (cons 'column |
| 971 | (+ (or offset 0) | 987 | (+ (or offset 0) |
| 972 | (if (smie-indent--hanging-p) | 988 | ;; Use smie-indent-virtual when indenting relative to an opener: |
| 973 | (smie-indent-virtual) (current-column)))))) | 989 | ;; this will also by default use current-column unless |
| 990 | ;; that opener is hanging, but will additionally consult | ||
| 991 | ;; rules-function, so it gives it a chance to tweak | ||
| 992 | ;; indentation (e.g. by forcing indentation relative to | ||
| 993 | ;; its own parent, as in fn a => fn b => fn c =>). | ||
| 994 | (if (or (null (car smie--parent)) (smie-indent--hanging-p)) | ||
| 995 | (smie-indent-virtual) (current-column)))))) | ||
| 974 | 996 | ||
| 975 | (defvar smie-rule-separator-outdent 2) | 997 | (defvar smie-rule-separator-outdent 2) |
| 976 | 998 | ||
| @@ -1030,11 +1052,7 @@ Only meaningful when called from within `smie-rules-function'." | |||
| 1030 | ;; FIXME: Rather than consult the number of spaces, we could *set* the | 1052 | ;; FIXME: Rather than consult the number of spaces, we could *set* the |
| 1031 | ;; number of spaces so as to align the separator with the close-paren | 1053 | ;; number of spaces so as to align the separator with the close-paren |
| 1032 | ;; while aligning the content with the rest. | 1054 | ;; while aligning the content with the rest. |
| 1033 | (let ((parent-col | 1055 | (let ((parent-col (cdr (smie-rule-parent))) |
| 1034 | (save-excursion | ||
| 1035 | (goto-char (cadr smie--parent)) | ||
| 1036 | (if (smie-indent--hanging-p) | ||
| 1037 | (smie-indent-virtual) (current-column)))) | ||
| 1038 | (parent-pos-col ;FIXME: we knew this when computing smie--parent. | 1056 | (parent-pos-col ;FIXME: we knew this when computing smie--parent. |
| 1039 | (save-excursion | 1057 | (save-excursion |
| 1040 | (goto-char (cadr smie--parent)) | 1058 | (goto-char (cadr smie--parent)) |
| @@ -1083,7 +1101,16 @@ BASE-POS is the position relative to which offsets should be applied." | |||
| 1083 | (+ offset | 1101 | (+ offset |
| 1084 | (if (null base-pos) 0 | 1102 | (if (null base-pos) 0 |
| 1085 | (goto-char base-pos) | 1103 | (goto-char base-pos) |
| 1086 | (if (smie-indent--hanging-p) | 1104 | ;; Use smie-indent-virtual when indenting relative to an opener: |
| 1105 | ;; this will also by default use current-column unless | ||
| 1106 | ;; that opener is hanging, but will additionally consult | ||
| 1107 | ;; rules-function, so it gives it a chance to tweak indentation | ||
| 1108 | ;; (e.g. by forcing indentation relative to its own parent, as in | ||
| 1109 | ;; fn a => fn b => fn c =>). | ||
| 1110 | ;; When parent==nil it doesn't matter because the only case | ||
| 1111 | ;; where it's really used is when the base-pos is hanging anyway. | ||
| 1112 | (if (or (and parent (null (car parent))) | ||
| 1113 | (smie-indent--hanging-p)) | ||
| 1087 | (smie-indent-virtual) (current-column))))) | 1114 | (smie-indent-virtual) (current-column))))) |
| 1088 | (t (error "Unknown indentation offset %s" offset)))))) | 1115 | (t (error "Unknown indentation offset %s" offset)))))) |
| 1089 | 1116 | ||
| @@ -1171,12 +1198,11 @@ in order to figure out the indentation of some other (further down) point." | |||
| 1171 | ;; - middle-of-line: "trust current position". | 1198 | ;; - middle-of-line: "trust current position". |
| 1172 | (cond | 1199 | (cond |
| 1173 | ((null (cdr toklevels)) nil) ;Not a keyword. | 1200 | ((null (cdr toklevels)) nil) ;Not a keyword. |
| 1174 | ((smie-indent--bolp) | 1201 | ((smie-indent--rule :before token)) |
| 1202 | ((smie-indent--bolp) ;I.e. non-virtual indent. | ||
| 1175 | ;; For an open-paren-like thingy at BOL, always indent only | 1203 | ;; For an open-paren-like thingy at BOL, always indent only |
| 1176 | ;; based on other rules (typically smie-indent-after-keyword). | 1204 | ;; based on other rules (typically smie-indent-after-keyword). |
| 1177 | nil) | 1205 | nil) |
| 1178 | ;; We're only ever here for virtual-indent. | ||
| 1179 | ((smie-indent--rule :before token)) | ||
| 1180 | (t | 1206 | (t |
| 1181 | ;; By default use point unless we're hanging. | 1207 | ;; By default use point unless we're hanging. |
| 1182 | (unless (smie-indent--hanging-p) (current-column))))) | 1208 | (unless (smie-indent--hanging-p) (current-column))))) |
| @@ -1298,10 +1324,19 @@ in order to figure out the indentation of some other (further down) point." | |||
| 1298 | comment-end-skip | 1324 | comment-end-skip |
| 1299 | (not (looking-at " \t*$")) ;Not just a \n comment-closer. | 1325 | (not (looking-at " \t*$")) ;Not just a \n comment-closer. |
| 1300 | (looking-at comment-end-skip) | 1326 | (looking-at comment-end-skip) |
| 1301 | (nth 4 (syntax-ppss)) | 1327 | (let ((end (match-string 0))) |
| 1302 | (save-excursion | 1328 | (and (nth 4 (syntax-ppss)) |
| 1303 | (goto-char (nth 8 (syntax-ppss))) | 1329 | (save-excursion |
| 1304 | (current-column)))) | 1330 | (goto-char (nth 8 (syntax-ppss))) |
| 1331 | (and (looking-at comment-start-skip) | ||
| 1332 | (let ((start (match-string 0))) | ||
| 1333 | ;; Align the common substring between starter | ||
| 1334 | ;; and ender, if possible. | ||
| 1335 | (if (string-match "\\(.+\\).*\n\\(.*?\\)\\1" | ||
| 1336 | (concat start "\n" end)) | ||
| 1337 | (+ (current-column) (match-beginning 0) | ||
| 1338 | (- (match-beginning 2) (match-end 2))) | ||
| 1339 | (current-column))))))))) | ||
| 1305 | 1340 | ||
| 1306 | (defun smie-indent-comment-inside () | 1341 | (defun smie-indent-comment-inside () |
| 1307 | (and (nth 4 (syntax-ppss)) | 1342 | (and (nth 4 (syntax-ppss)) |