43
43
(if (looking-at "////")
45
45
(if (looking-at "///")
46
(let ((tem (ess-calculate-indent)))
47
(if (listp tem) (car tem) tem))
46
(let ((tem (ess-calculate-indent)))
47
(if (listp tem) (car tem) tem))
48
48
(skip-chars-backward " \t")
49
49
(max (if (bolp) 0 (1+ (current-column)))
52
52
(defun OMG-indent-line ()
53
53
"Indent current line as Omega code.
54
54
Return the amount the indentation changed by."
55
55
(let ((indent (ess-calculate-indent nil))
57
(case-fold-search nil)
58
(pos (- (point-max) (point))))
57
(case-fold-search nil)
58
(pos (- (point-max) (point))))
59
59
(beginning-of-line)
61
61
(cond ((eq indent nil)
62
(setq indent (current-indentation)))
64
(skip-chars-forward " \t")
65
(if (and ess-fancy-comments (looking-at "////"))
67
(if (and ess-fancy-comments
69
(not (looking-at "///")))
70
(setq indent comment-column)
71
(if (eq indent t) (setq indent 0))
72
(if (listp indent) (setq indent (car indent)))
73
(cond ((and (looking-at "else\\b")
74
(not (looking-at "else\\s_")))
75
(setq indent (save-excursion
76
(ess-backward-to-start-of-if)
78
(current-indentation)))))
79
((= (following-char) ?})
82
(- ess-close-brace-offset ess-indent-level))))
83
((= (following-char) ?{)
84
(setq indent (+ indent ess-brace-offset)))))))
62
(setq indent (current-indentation)))
64
(skip-chars-forward " \t")
65
(if (and ess-fancy-comments (looking-at "////"))
67
(if (and ess-fancy-comments
69
(not (looking-at "///")))
70
(setq indent comment-column)
71
(if (eq indent t) (setq indent 0))
72
(if (listp indent) (setq indent (car indent)))
73
(cond ((and (looking-at "else\\b")
74
(not (looking-at "else\\s_")))
75
(setq indent (save-excursion
76
(ess-backward-to-start-of-if)
78
(current-indentation)))))
79
((= (following-char) ?})
82
(- ess-close-brace-offset ess-indent-level))))
83
((= (following-char) ?{)
84
(setq indent (+ indent ess-brace-offset)))))))
85
85
(skip-chars-forward " \t")
86
86
(setq shift-amt (- indent (current-column)))
87
87
(if (zerop shift-amt)
88
(if (> (- (point-max) pos) (point))
89
(goto-char (- (point-max) pos)))
88
(if (> (- (point-max) pos) (point))
89
(goto-char (- (point-max) pos)))
90
90
(delete-region beg (point))
92
92
;; If initial point was within line's indentation,
93
93
;; position after the indentation.
94
94
;; Else stay at same point in text.
95
95
(if (> (- (point-max) pos) (point))
96
(goto-char (- (point-max) pos))))
96
(goto-char (- (point-max) pos))))
105
105
(beginning-of-line)
106
106
(let ((indent-point (point))
107
(case-fold-search nil)
107
(case-fold-search nil)
111
(goto-char parse-start)
112
(beginning-of-defun))
111
(goto-char parse-start)
112
(beginning-of-defun))
113
113
(while (< (point) indent-point)
114
(setq parse-start (point))
115
(setq state (parse-partial-sexp (point) indent-point 0))
116
(setq containing-sexp (car (cdr state))))
114
(setq parse-start (point))
115
(setq state (parse-partial-sexp (point) indent-point 0))
116
(setq containing-sexp (car (cdr state))))
117
117
(cond ((or (nth 3 state) (nth 4 state))
118
;; return nil or t if should not change this line
120
((null containing-sexp)
121
;; Line is at top level. May be data or function definition,
123
(if (and (/= (following-char) ?\{)
125
(ess-backward-to-noncomment (point-min))
126
(ess-continued-statement-p)))
127
ess-continued-statement-offset
128
0)) ; Unless it starts a function body
129
((/= (char-after containing-sexp) ?{)
130
;; line is expression, not statement:
131
;; indent to just after the surrounding open.
132
(goto-char containing-sexp)
133
(let ((bol (save-excursion (beginning-of-line) (point))))
135
;; modified by shiba@isac 7.3.1992
136
(cond ((and (numberp ess-expression-offset)
137
(re-search-backward "[ \t]*expression[ \t]*" bol t))
138
;; This regexp match every "expression".
142
(skip-chars-forward " \t")
144
(+ (current-column) ess-expression-offset))
145
((and (numberp ess-arg-function-offset)
147
"=[ \t]*\\s\"*\\(\\w\\|\\s_\\)+\\s\"*[ \t]*"
151
(+ (current-column) ess-arg-function-offset))
152
;; "expression" is searched before "=".
156
(progn (goto-char (1+ containing-sexp))
157
(current-column))))))
159
;; Statement level. Is it a continuation or a new statement?
160
;; Find previous non-comment character.
161
(goto-char indent-point)
162
(ess-backward-to-noncomment containing-sexp)
163
;; Back up over label lines, since they don't
164
;; affect whether our line is a continuation.
165
(while (eq (preceding-char) ?\,)
166
(ess-backward-to-start-of-continued-exp containing-sexp)
168
(ess-backward-to-noncomment containing-sexp))
169
;; Now we get the answer.
170
(if (ess-continued-statement-p)
171
;; This line is continuation of preceding line's statement;
172
;; indent ess-continued-statement-offset more than the
173
;; previous line of the statement.
175
(ess-backward-to-start-of-continued-exp containing-sexp)
176
(+ ess-continued-statement-offset (current-column)
177
(if (save-excursion (goto-char indent-point)
178
(skip-chars-forward " \t")
179
(eq (following-char) ?{))
180
ess-continued-brace-offset 0)))
181
;; This line starts a new statement.
182
;; Position following last unclosed open.
183
(goto-char containing-sexp)
184
;; Is line first statement after an open-brace?
186
;; If no, find that first statement and indent like it.
189
(while (progn (skip-chars-forward " \t\n")
191
;; Skip over comments following openbrace.
193
;; The first following code counts
194
;; if it is before the line we want to indent.
195
(and (< (point) indent-point)
197
;; If no previous statement,
198
;; indent it relative to line brace is on.
199
;; For open brace in column zero, don't let statement
200
;; start there too. If ess-indent-level is zero,
201
;; use ess-brace-offset + ess-continued-statement-offset instead.
202
;; For open-braces not the first thing in a line,
203
;; add in ess-brace-imaginary-offset.
204
(+ (if (and (bolp) (zerop ess-indent-level))
205
(+ ess-brace-offset ess-continued-statement-offset)
207
;; Move back over whitespace before the openbrace.
208
;; If openbrace is not first nonwhite thing on the line,
209
;; add the ess-brace-imaginary-offset.
210
(progn (skip-chars-backward " \t")
211
(if (bolp) 0 ess-brace-imaginary-offset))
212
;; If the openbrace is preceded by a parenthesized exp,
213
;; move to the beginning of that;
214
;; possibly a different line
216
(if (eq (preceding-char) ?\))
218
;; Get initial indentation of the line we are on.
219
(current-indentation))))))))))
118
;; return nil or t if should not change this line
120
((null containing-sexp)
121
;; Line is at top level. May be data or function definition,
123
(if (and (/= (following-char) ?\{)
125
(ess-backward-to-noncomment (point-min))
126
(ess-continued-statement-p)))
127
ess-continued-statement-offset
128
0)) ; Unless it starts a function body
129
((/= (char-after containing-sexp) ?{)
130
;; line is expression, not statement:
131
;; indent to just after the surrounding open.
132
(goto-char containing-sexp)
133
(let ((bol (save-excursion (beginning-of-line) (point))))
135
;; modified by shiba@isac 7.3.1992
136
(cond ((and (numberp ess-expression-offset)
137
(re-search-backward "[ \t]*expression[ \t]*" bol t))
138
;; This regexp match every "expression".
142
(skip-chars-forward " \t")
144
(+ (current-column) ess-expression-offset))
145
((and (numberp ess-arg-function-offset)
147
"=[ \t]*\\s\"*\\(\\w\\|\\s_\\)+\\s\"*[ \t]*"
151
(+ (current-column) ess-arg-function-offset))
152
;; "expression" is searched before "=".
156
(progn (goto-char (1+ containing-sexp))
157
(current-column))))))
159
;; Statement level. Is it a continuation or a new statement?
160
;; Find previous non-comment character.
161
(goto-char indent-point)
162
(ess-backward-to-noncomment containing-sexp)
163
;; Back up over label lines, since they don't
164
;; affect whether our line is a continuation.
165
(while (eq (preceding-char) ?\,)
166
(ess-backward-to-start-of-continued-exp containing-sexp)
168
(ess-backward-to-noncomment containing-sexp))
169
;; Now we get the answer.
170
(if (ess-continued-statement-p)
171
;; This line is continuation of preceding line's statement;
172
;; indent ess-continued-statement-offset more than the
173
;; previous line of the statement.
175
(ess-backward-to-start-of-continued-exp containing-sexp)
176
(+ ess-continued-statement-offset (current-column)
177
(if (save-excursion (goto-char indent-point)
178
(skip-chars-forward " \t")
179
(eq (following-char) ?{))
180
ess-continued-brace-offset 0)))
181
;; This line starts a new statement.
182
;; Position following last unclosed open.
183
(goto-char containing-sexp)
184
;; Is line first statement after an open-brace?
186
;; If no, find that first statement and indent like it.
189
(while (progn (skip-chars-forward " \t\n")
191
;; Skip over comments following openbrace.
193
;; The first following code counts
194
;; if it is before the line we want to indent.
195
(and (< (point) indent-point)
197
;; If no previous statement,
198
;; indent it relative to line brace is on.
199
;; For open brace in column zero, don't let statement
200
;; start there too. If ess-indent-level is zero,
201
;; use ess-brace-offset + ess-continued-statement-offset instead.
202
;; For open-braces not the first thing in a line,
203
;; add in ess-brace-imaginary-offset.
204
(+ (if (and (bolp) (zerop ess-indent-level))
205
(+ ess-brace-offset ess-continued-statement-offset)
207
;; Move back over whitespace before the openbrace.
208
;; If openbrace is not first nonwhite thing on the line,
209
;; add the ess-brace-imaginary-offset.
210
(progn (skip-chars-backward " \t")
211
(if (bolp) 0 ess-brace-imaginary-offset))
212
;; If the openbrace is preceded by a parenthesized exp,
213
;; move to the beginning of that;
214
;; possibly a different line
216
(if (eq (preceding-char) ?\))
218
;; Get initial indentation of the line we are on.
219
(current-indentation))))))))))