~ubuntu-branches/ubuntu/raring/ess/raring-proposed

« back to all changes in this revision

Viewing changes to lisp/ess-omg-l.el

  • Committer: Package Import Robot
  • Author(s): Dirk Eddelbuettel
  • Date: 2012-05-09 08:00:38 UTC
  • mfrom: (1.2.23)
  • Revision ID: package-import@ubuntu.com-20120509080038-7an3nhbtgaj02a17
Tags: 12.04-1-1
New upstream patch version released today

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
;; Copyright (C) 1999--2001 A.J. Rossini.
4
4
;; Copyright (C) 2002--2004 A.J. Rossini, Rich M. Heiberger, Martin
5
 
;;      Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
 
5
;;      Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
6
6
 
7
 
;; Original Author: A.J. Rossini <rossini@u.washington.edu>
 
7
;; Author: A.J. Rossini <rossini@u.washington.edu>
8
8
;; Created: 15 Aug 1999
9
 
;; Maintainers: ESS-core <ESS-core@r-project.org>
 
9
;; Maintainer: ESS-core <ESS-core@r-project.org>
10
10
 
11
11
;; This file is part of ESS (Emacs Speaks Statistics).
12
12
 
43
43
  (if (looking-at "////")
44
44
      (current-column)
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)))
50
 
           comment-column))))
 
50
           comment-column))))
51
51
 
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))
56
 
        beg shift-amt
57
 
        (case-fold-search nil)
58
 
        (pos (- (point-max) (point))))
 
56
        beg shift-amt
 
57
        (case-fold-search nil)
 
58
        (pos (- (point-max) (point))))
59
59
    (beginning-of-line)
60
60
    (setq beg (point))
61
61
    (cond ((eq indent nil)
62
 
           (setq indent (current-indentation)))
63
 
          (t
64
 
           (skip-chars-forward " \t")
65
 
           (if (and ess-fancy-comments (looking-at "////"))
66
 
               (setq indent 0))
67
 
           (if (and ess-fancy-comments
68
 
                    (looking-at "//")
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)
77
 
                                   (+ ess-else-offset
78
 
                                      (current-indentation)))))
79
 
                   ((= (following-char) ?})
80
 
                    (setq indent
81
 
                          (+ indent
82
 
                             (- ess-close-brace-offset ess-indent-level))))
83
 
                   ((= (following-char) ?{)
84
 
                    (setq indent (+ indent ess-brace-offset)))))))
 
62
           (setq indent (current-indentation)))
 
63
          (t
 
64
           (skip-chars-forward " \t")
 
65
           (if (and ess-fancy-comments (looking-at "////"))
 
66
               (setq indent 0))
 
67
           (if (and ess-fancy-comments
 
68
                    (looking-at "//")
 
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)
 
77
                                   (+ ess-else-offset
 
78
                                      (current-indentation)))))
 
79
                   ((= (following-char) ?})
 
80
                    (setq indent
 
81
                          (+ indent
 
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))
91
91
      (indent-to indent)
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))))
97
97
    shift-amt))
98
98
 
99
99
 
104
104
  (save-excursion
105
105
    (beginning-of-line)
106
106
    (let ((indent-point (point))
107
 
          (case-fold-search nil)
108
 
          state
109
 
          containing-sexp)
 
107
          (case-fold-search nil)
 
108
          state
 
109
          containing-sexp)
110
110
      (if parse-start
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
119
 
             (nth 4 state))
120
 
            ((null containing-sexp)
121
 
             ;; Line is at top level.  May be data or function definition,
122
 
             (beginning-of-line)
123
 
             (if (and (/= (following-char) ?\{)
124
 
                      (save-excursion
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))))
134
 
 
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".
139
 
                      ;; modified by shiba
140
 
                      ;;(forward-sexp -1)
141
 
                      (beginning-of-line)
142
 
                      (skip-chars-forward " \t")
143
 
                      ;; End
144
 
                      (+ (current-column) ess-expression-offset))
145
 
                     ((and (numberp ess-arg-function-offset)
146
 
                           (re-search-backward
147
 
                            "=[ \t]*\\s\"*\\(\\w\\|\\s_\\)+\\s\"*[ \t]*"
148
 
                            bol
149
 
                            t))
150
 
                      (forward-sexp -1)
151
 
                      (+ (current-column) ess-arg-function-offset))
152
 
                     ;; "expression" is searched before "=".
153
 
                     ;; End
154
 
 
155
 
                     (t
156
 
                      (progn (goto-char (1+ containing-sexp))
157
 
                             (current-column))))))
158
 
            (t
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)
167
 
               (beginning-of-line)
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.
174
 
                 (progn
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?
185
 
               (or
186
 
                 ;; If no, find that first statement and indent like it.
187
 
                 (save-excursion
188
 
                   (forward-char 1)
189
 
                   (while (progn (skip-chars-forward " \t\n")
190
 
                                 (looking-at "//"))
191
 
                     ;; Skip over comments following openbrace.
192
 
                     (forward-line 1))
193
 
                   ;; The first following code counts
194
 
                   ;; if it is before the line we want to indent.
195
 
                   (and (< (point) indent-point)
196
 
                        (current-column)))
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)
206
 
                      ess-indent-level)
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
215
 
                    (progn
216
 
                      (if (eq (preceding-char) ?\))
217
 
                          (forward-sexp -1))
218
 
                      ;; Get initial indentation of the line we are on.
219
 
                      (current-indentation))))))))))
 
118
             ;; return nil or t if should not change this line
 
119
             (nth 4 state))
 
120
            ((null containing-sexp)
 
121
             ;; Line is at top level.  May be data or function definition,
 
122
             (beginning-of-line)
 
123
             (if (and (/= (following-char) ?\{)
 
124
                      (save-excursion
 
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))))
 
134
 
 
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".
 
139
                      ;; modified by shiba
 
140
                      ;;(forward-sexp -1)
 
141
                      (beginning-of-line)
 
142
                      (skip-chars-forward " \t")
 
143
                      ;; End
 
144
                      (+ (current-column) ess-expression-offset))
 
145
                     ((and (numberp ess-arg-function-offset)
 
146
                           (re-search-backward
 
147
                            "=[ \t]*\\s\"*\\(\\w\\|\\s_\\)+\\s\"*[ \t]*"
 
148
                            bol
 
149
                            t))
 
150
                      (forward-sexp -1)
 
151
                      (+ (current-column) ess-arg-function-offset))
 
152
                     ;; "expression" is searched before "=".
 
153
                     ;; End
 
154
 
 
155
                     (t
 
156
                      (progn (goto-char (1+ containing-sexp))
 
157
                             (current-column))))))
 
158
            (t
 
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)
 
167
               (beginning-of-line)
 
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.
 
174
                 (progn
 
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?
 
185
               (or
 
186
                ;; If no, find that first statement and indent like it.
 
187
                (save-excursion
 
188
                  (forward-char 1)
 
189
                  (while (progn (skip-chars-forward " \t\n")
 
190
                                (looking-at "//"))
 
191
                    ;; Skip over comments following openbrace.
 
192
                    (forward-line 1))
 
193
                  ;; The first following code counts
 
194
                  ;; if it is before the line we want to indent.
 
195
                  (and (< (point) indent-point)
 
196
                       (current-column)))
 
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)
 
206
                     ess-indent-level)
 
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
 
215
                   (progn
 
216
                     (if (eq (preceding-char) ?\))
 
217
                         (forward-sexp -1))
 
218
                     ;; Get initial indentation of the line we are on.
 
219
                     (current-indentation))))))))))
220
220
 
221
221
 
222
222
 
242
242
  ;;F (modify-syntax-entry ?\n ">"  S-syntax-table) ; close comment
243
243
  ;;(modify-syntax-entry ?.  "w"  S-syntax-table) ; "." used in S obj names
244
244
  (modify-syntax-entry ?.  "_"  S-syntax-table) ; see above/below,
245
 
                                        ; plus consider separation.
 
245
                                        ; plus consider separation.
246
246
  (modify-syntax-entry ?$  "_"  S-syntax-table) ; foo.bar$hack is 1 symbol
247
247
  (modify-syntax-entry ?_  "."  S-syntax-table)
248
248
  (modify-syntax-entry ?*  "."  S-syntax-table)
270
270
    ;;(ess-keep-dump-files          . 'ask)
271
271
    (ess-mode-syntax-table        . S-syntax-table)
272
272
    (font-lock-defaults           . '(ess-S-mode-font-lock-keywords
273
 
                                      nil nil ((?\. . "w")))))
 
273
                                      nil nil ((?\. . "w")))))
274
274
  "General options for Omegahat source files.")
275
275
 
276
276
 
323
323
;;; End:
324
324
 
325
325
;;; ess-omg-l.el ends here
326