aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2010-08-18 14:10:30 +0200
committerStefan Monnier2010-08-18 14:10:30 +0200
commit710a7f464c853263ada4f2cf62453bac4d84772a (patch)
tree0f5fd981c2963baf7570b9fba6ee67f82b948d7f
parentb3a8fe90e79d93e432c633b598f127ec7a1f4930 (diff)
downloademacs-710a7f464c853263ada4f2cf62453bac4d84772a.tar.gz
emacs-710a7f464c853263ada4f2cf62453bac4d84772a.zip
Reindent smie.el
-rw-r--r--lisp/emacs-lisp/smie.el114
1 files changed, 57 insertions, 57 deletions
diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el
index ee25551e102..2fbf0628dbe 100644
--- a/lisp/emacs-lisp/smie.el
+++ b/lisp/emacs-lisp/smie.el
@@ -158,9 +158,9 @@ one of those elements share the same precedence level and associativity."
158 (if (not (member (car shr) nts)) 158 (if (not (member (car shr) nts))
159 (pushnew (car shr) last-ops) 159 (pushnew (car shr) last-ops)
160 (pushnew (car shr) last-nts) 160 (pushnew (car shr) last-nts)
161 (when (consp (cdr shr)) 161 (when (consp (cdr shr))
162 (assert (not (member (cadr shr) nts))) 162 (assert (not (member (cadr shr) nts)))
163 (pushnew (cadr shr) last-ops))))) 163 (pushnew (cadr shr) last-ops)))))
164 (push (cons nt first-ops) first-ops-table) 164 (push (cons nt first-ops) first-ops-table)
165 (push (cons nt last-ops) last-ops-table) 165 (push (cons nt last-ops) last-ops-table)
166 (push (cons nt first-nts) first-nts-table) 166 (push (cons nt first-nts) first-nts-table)
@@ -282,7 +282,7 @@ PREC2 is a table as returned by `smie-precs-precedence-table' or
282 ;; distinguish associative operators (which will have 282 ;; distinguish associative operators (which will have
283 ;; left = right). 283 ;; left = right).
284 (unless (caar cst) 284 (unless (caar cst)
285 (setcar (car cst) i) 285 (setcar (car cst) i)
286 (incf i)) 286 (incf i))
287 (setq csts (delq cst csts)))) 287 (setq csts (delq cst csts))))
288 (unless progress 288 (unless progress
@@ -386,8 +386,8 @@ Possible return values:
386 (cond 386 (cond
387 ((null toklevels) 387 ((null toklevels)
388 (when (zerop (length token)) 388 (when (zerop (length token))
389 (condition-case err 389 (condition-case err
390 (progn (goto-char pos) (funcall next-sexp 1) nil) 390 (progn (goto-char pos) (funcall next-sexp 1) nil)
391 (scan-error (throw 'return 391 (scan-error (throw 'return
392 (list t (caddr err) 392 (list t (caddr err)
393 (buffer-substring-no-properties 393 (buffer-substring-no-properties
@@ -417,10 +417,10 @@ Possible return values:
417 (let ((lastlevels levels)) 417 (let ((lastlevels levels))
418 (if (and levels (= (funcall op-back toklevels) 418 (if (and levels (= (funcall op-back toklevels)
419 (funcall op-forw (car levels)))) 419 (funcall op-forw (car levels))))
420 (setq levels (cdr levels))) 420 (setq levels (cdr levels)))
421 ;; We may have found a match for the previously pending 421 ;; We may have found a match for the previously pending
422 ;; operator. Is this the end? 422 ;; operator. Is this the end?
423 (cond 423 (cond
424 ;; Keep looking as long as we haven't matched the 424 ;; Keep looking as long as we haven't matched the
425 ;; topmost operator. 425 ;; topmost operator.
426 (levels 426 (levels
@@ -462,11 +462,11 @@ Possible return values:
462 (t POS TOKEN): same thing but for an open-paren or the beginning of buffer. 462 (t POS TOKEN): same thing but for an open-paren or the beginning of buffer.
463 (nil POS TOKEN): we skipped over a paren-like pair. 463 (nil POS TOKEN): we skipped over a paren-like pair.
464 nil: we skipped over an identifier, matched parentheses, ..." 464 nil: we skipped over an identifier, matched parentheses, ..."
465 (smie-next-sexp 465 (smie-next-sexp
466 (indirect-function smie-backward-token-function) 466 (indirect-function smie-backward-token-function)
467 (indirect-function 'backward-sexp) 467 (indirect-function 'backward-sexp)
468 (indirect-function 'smie-op-left) 468 (indirect-function 'smie-op-left)
469 (indirect-function 'smie-op-right) 469 (indirect-function 'smie-op-right)
470 halfsexp)) 470 halfsexp))
471 471
472(defun smie-forward-sexp (&optional halfsexp) 472(defun smie-forward-sexp (&optional halfsexp)
@@ -480,11 +480,11 @@ Possible return values:
480 (t POS TOKEN): same thing but for an open-paren or the beginning of buffer. 480 (t POS TOKEN): same thing but for an open-paren or the beginning of buffer.
481 (nil POS TOKEN): we skipped over a paren-like pair. 481 (nil POS TOKEN): we skipped over a paren-like pair.
482 nil: we skipped over an identifier, matched parentheses, ..." 482 nil: we skipped over an identifier, matched parentheses, ..."
483 (smie-next-sexp 483 (smie-next-sexp
484 (indirect-function smie-forward-token-function) 484 (indirect-function smie-forward-token-function)
485 (indirect-function 'forward-sexp) 485 (indirect-function 'forward-sexp)
486 (indirect-function 'smie-op-right) 486 (indirect-function 'smie-op-right)
487 (indirect-function 'smie-op-left) 487 (indirect-function 'smie-op-left)
488 halfsexp)) 488 halfsexp))
489 489
490;;; Miscellanous commands using the precedence parser. 490;;; Miscellanous commands using the precedence parser.
@@ -501,14 +501,14 @@ Possible return values:
501 (forward-sexp-function nil)) 501 (forward-sexp-function nil))
502 (while (/= n 0) 502 (while (/= n 0)
503 (setq n (- n (if forw 1 -1))) 503 (setq n (- n (if forw 1 -1)))
504 (let ((pos (point)) 504 (let ((pos (point))
505 (res (if forw 505 (res (if forw
506 (smie-forward-sexp 'halfsexp) 506 (smie-forward-sexp 'halfsexp)
507 (smie-backward-sexp 'halfsexp)))) 507 (smie-backward-sexp 'halfsexp))))
508 (if (and (car res) (= pos (point)) (not (if forw (eobp) (bobp)))) 508 (if (and (car res) (= pos (point)) (not (if forw (eobp) (bobp))))
509 (signal 'scan-error 509 (signal 'scan-error
510 (list "Containing expression ends prematurely" 510 (list "Containing expression ends prematurely"
511 (cadr res) (cadr res))) 511 (cadr res) (cadr res)))
512 nil))))) 512 nil)))))
513 513
514(defvar smie-closer-alist nil 514(defvar smie-closer-alist nil
@@ -764,13 +764,13 @@ in order to figure out the indentation of some other (further down) point."
764 ;; Obey the `fixindent' special comment. 764 ;; Obey the `fixindent' special comment.
765 (and (smie-bolp) 765 (and (smie-bolp)
766 (save-excursion 766 (save-excursion
767 (comment-normalize-vars) 767 (comment-normalize-vars)
768 (re-search-forward (concat comment-start-skip 768 (re-search-forward (concat comment-start-skip
769 "fixindent" 769 "fixindent"
770 comment-end-skip) 770 comment-end-skip)
771 ;; 1+ to account for the \n comment termination. 771 ;; 1+ to account for the \n comment termination.
772 (1+ (line-end-position)) t)) 772 (1+ (line-end-position)) t))
773 (current-column))) 773 (current-column)))
774 774
775(defun smie-indent-bob () 775(defun smie-indent-bob ()
776 ;; Start the file at column 0. 776 ;; Start the file at column 0.
@@ -802,26 +802,26 @@ in order to figure out the indentation of some other (further down) point."
802 (save-excursion 802 (save-excursion
803 (goto-char pos) 803 (goto-char pos)
804 ;; Different cases: 804 ;; Different cases:
805 ;; - smie-bolp: "indent according to others". 805 ;; - smie-bolp: "indent according to others".
806 ;; - common hanging: "indent according to others". 806 ;; - common hanging: "indent according to others".
807 ;; - SML-let hanging: "indent like parent". 807 ;; - SML-let hanging: "indent like parent".
808 ;; - if-after-else: "indent-like parent". 808 ;; - if-after-else: "indent-like parent".
809 ;; - middle-of-line: "trust current position". 809 ;; - middle-of-line: "trust current position".
810 (cond 810 (cond
811 ((null (cdr toklevels)) nil) ;Not a keyword. 811 ((null (cdr toklevels)) nil) ;Not a keyword.
812 ((smie-bolp) 812 ((smie-bolp)
813 ;; For an open-paren-like thingy at BOL, always indent only 813 ;; For an open-paren-like thingy at BOL, always indent only
814 ;; based on other rules (typically smie-indent-after-keyword). 814 ;; based on other rules (typically smie-indent-after-keyword).
815 nil) 815 nil)
816 (t 816 (t
817 ;; We're only ever here for virtual-indent, which is why 817 ;; We're only ever here for virtual-indent, which is why
818 ;; we can use (current-column) as answer for `point'. 818 ;; we can use (current-column) as answer for `point'.
819 (let* ((tokinfo (or (assoc (cons :before token) 819 (let* ((tokinfo (or (assoc (cons :before token)
820 smie-indent-rules) 820 smie-indent-rules)
821 ;; By default use point unless we're hanging. 821 ;; By default use point unless we're hanging.
822 `((:before . ,token) (:hanging nil) point))) 822 `((:before . ,token) (:hanging nil) point)))
823 ;; (after (prog1 (point) (goto-char pos))) 823 ;; (after (prog1 (point) (goto-char pos)))
824 (offset (smie-indent-offset-rule tokinfo))) 824 (offset (smie-indent-offset-rule tokinfo)))
825 (smie-indent-column offset))))) 825 (smie-indent-column offset)))))
826 826
827 ;; FIXME: This still looks too much like black magic!! 827 ;; FIXME: This still looks too much like black magic!!
@@ -896,17 +896,17 @@ in order to figure out the indentation of some other (further down) point."
896 ;; affect the indentation of the "end". 896 ;; affect the indentation of the "end".
897 (current-column) 897 (current-column)
898 (goto-char (cadr parent)) 898 (goto-char (cadr parent))
899 ;; Don't use (smie-indent-virtual :not-hanging) here, because we 899 ;; Don't use (smie-indent-virtual :not-hanging) here, because we
900 ;; want to jump back over a sequence of same-level ops such as 900 ;; want to jump back over a sequence of same-level ops such as
901 ;; a -> b -> c 901 ;; a -> b -> c
902 ;; -> d 902 ;; -> d
903 ;; So as to align with the earliest appropriate place. 903 ;; So as to align with the earliest appropriate place.
904 (smie-indent-virtual))) 904 (smie-indent-virtual)))
905 (tokinfo 905 (tokinfo
906 (if (and (= (point) pos) (smie-bolp) 906 (if (and (= (point) pos) (smie-bolp)
907 (or (eq offset 'point) 907 (or (eq offset 'point)
908 (and (consp offset) (memq 'point offset)))) 908 (and (consp offset) (memq 'point offset))))
909 ;; Since we started at BOL, we're not computing a virtual 909 ;; Since we started at BOL, we're not computing a virtual
910 ;; indentation, and we're still at the starting point, so 910 ;; indentation, and we're still at the starting point, so
911 ;; we can't use `current-column' which would cause 911 ;; we can't use `current-column' which would cause
912 ;; indentation to depend on itself. 912 ;; indentation to depend on itself.
@@ -934,12 +934,12 @@ in order to figure out the indentation of some other (further down) point."
934 (comment-string-strip comment-continue t t)))) 934 (comment-string-strip comment-continue t t))))
935 (and (< 0 (length continue)) 935 (and (< 0 (length continue))
936 (looking-at (regexp-quote continue)) (nth 4 (syntax-ppss)) 936 (looking-at (regexp-quote continue)) (nth 4 (syntax-ppss))
937 (let ((ppss (syntax-ppss))) 937 (let ((ppss (syntax-ppss)))
938 (save-excursion 938 (save-excursion
939 (forward-line -1) 939 (forward-line -1)
940 (if (<= (point) (nth 8 ppss)) 940 (if (<= (point) (nth 8 ppss))
941 (progn (goto-char (1+ (nth 8 ppss))) (current-column)) 941 (progn (goto-char (1+ (nth 8 ppss))) (current-column))
942 (skip-chars-forward " \t") 942 (skip-chars-forward " \t")
943 (if (looking-at (regexp-quote continue)) 943 (if (looking-at (regexp-quote continue))
944 (current-column)))))))) 944 (current-column))))))))
945 945
@@ -1024,8 +1024,8 @@ in order to figure out the indentation of some other (further down) point."
1024 1024
1025(defvar smie-indent-functions 1025(defvar smie-indent-functions
1026 '(smie-indent-fixindent smie-indent-bob smie-indent-close smie-indent-comment 1026 '(smie-indent-fixindent smie-indent-bob smie-indent-close smie-indent-comment
1027 smie-indent-comment-continue smie-indent-keyword smie-indent-after-keyword 1027 smie-indent-comment-continue smie-indent-keyword smie-indent-after-keyword
1028 smie-indent-exps) 1028 smie-indent-exps)
1029 "Functions to compute the indentation. 1029 "Functions to compute the indentation.
1030Each function is called with no argument, shouldn't move point, and should 1030Each function is called with no argument, shouldn't move point, and should
1031return either nil if it has no opinion, or an integer representing the column 1031return either nil if it has no opinion, or an integer representing the column