Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2701 views
1
;;; ess-omg-l.el --- Support for editing Omega source code
2
3
;; Copyright (C) 1999--2001 A.J. Rossini.
4
;; Copyright (C) 2002--2004 A.J. Rossini, Richard M. Heiberger, Martin
5
;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
6
7
;; Author: A.J. Rossini <[email protected]>
8
;; Created: 15 Aug 1999
9
;; Maintainer: ESS-core <[email protected]>
10
11
;; This file is part of ESS (Emacs Speaks Statistics).
12
13
;; This file is free software; you can redistribute it and/or modify
14
;; it under the terms of the GNU General Public License as published by
15
;; the Free Software Foundation; either version 2, or (at your option)
16
;; any later version.
17
18
;; This file is distributed in the hope that it will be useful,
19
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
;; GNU General Public License for more details.
22
23
;; A copy of the GNU General Public License is available at
24
;; http://www.r-project.org/Licenses/
25
26
;;; Commentary:
27
28
;; Code for general editing Omega source code. This is initially
29
;; based upon the similarities between Omega and S, but will need to
30
;; diverge to incorporate the use of Java-style coding.
31
32
;;; Code:
33
34
; Requires and autoloads
35
36
37
; Specialized functions
38
39
(defun OMG-comment-indent ()
40
"Indentation for Omega comments."
41
42
(if (looking-at "////")
43
(current-column)
44
(if (looking-at "///")
45
(let ((tem (ess-calculate-indent)))
46
(if (listp tem) (car tem) tem))
47
(skip-chars-backward " \t")
48
(max (if (bolp) 0 (1+ (current-column)))
49
comment-column))))
50
51
;; (defun OMG-indent-line ()
52
;; "Indent current line as Omega code.
53
;; Return the amount the indentation changed by."
54
;; (let ((indent (ess-calculate-indent nil))
55
;; beg shift-amt
56
;; (case-fold-search nil)
57
;; (pos (- (point-max) (point))))
58
;; (beginning-of-line)
59
;; (setq beg (point))
60
;; (cond ((eq indent nil)
61
;; (setq indent (current-indentation)))
62
;; (t
63
;; (skip-chars-forward " \t")
64
;; (if (and ess-fancy-comments (looking-at "////"))
65
;; (setq indent 0))
66
;; (if (and ess-fancy-comments
67
;; (looking-at "//")
68
;; (not (looking-at "///")))
69
;; (setq indent comment-column)
70
;; (if (eq indent t) (setq indent 0))
71
;; (if (listp indent) (setq indent (car indent)))
72
;; (cond ((and (looking-at "else\\b")
73
;; (not (looking-at "else\\s_")))
74
;; (setq indent (save-excursion
75
;; (ess-backward-to-start-of-if)
76
;; (+ ess-else-offset
77
;; (current-indentation)))))
78
;; ((= (following-char) ?})
79
;; (setq indent
80
;; (+ indent
81
;; (- ess-close-brace-offset ess-indent-level))))
82
;; ((= (following-char) ?{)
83
;; (setq indent (+ indent ess-brace-offset)))))))
84
;; (skip-chars-forward " \t")
85
;; (setq shift-amt (- indent (current-column)))
86
;; (if (zerop shift-amt)
87
;; (if (> (- (point-max) pos) (point))
88
;; (goto-char (- (point-max) pos)))
89
;; (delete-region beg (point))
90
;; (indent-to indent)
91
;; ;; If initial point was within line's indentation,
92
;; ;; position after the indentation.
93
;; ;; Else stay at same point in text.
94
;; (if (> (- (point-max) pos) (point))
95
;; (goto-char (- (point-max) pos))))
96
;; shift-amt))
97
98
99
;; (defun OMG-calculate-indent (&optional parse-start)
100
;; "Return appropriate indentation for current line as Omega code.
101
;; In usual case returns an integer: the column to indent to.
102
;; Returns nil if line starts inside a string, t if in a comment."
103
;; (save-excursion
104
;; (beginning-of-line)
105
;; (let ((indent-point (point))
106
;; (case-fold-search nil)
107
;; state
108
;; containing-sexp)
109
;; (if parse-start
110
;; (goto-char parse-start)
111
;; (beginning-of-defun))
112
;; (while (< (point) indent-point)
113
;; (setq parse-start (point))
114
;; (setq state (parse-partial-sexp (point) indent-point 0))
115
;; (setq containing-sexp (car (cdr state))))
116
;; (cond ((or (nth 3 state) (nth 4 state))
117
;; ;; return nil or t if should not change this line
118
;; (nth 4 state))
119
;; ((null containing-sexp)
120
;; ;; Line is at top level. May be data or function definition,
121
;; (beginning-of-line)
122
;; (if (and (/= (following-char) ?\{)
123
;; (save-excursion
124
;; (ess-backward-to-noncomment (point-min))
125
;; (ess-continued-statement-p)))
126
;; ess-continued-statement-offset
127
;; 0)) ; Unless it starts a function body
128
;; ((/= (char-after containing-sexp) ?{)
129
;; ;; line is expression, not statement:
130
;; ;; indent to just after the surrounding open.
131
;; (goto-char containing-sexp)
132
;; (let ((bol (save-excursion (beginning-of-line) (point))))
133
134
;; ;; modified by shiba@isac 7.3.1992
135
;; (cond ((and (numberp ess-expression-offset)
136
;; (re-search-backward "[ \t]*expression[ \t]*" bol t))
137
;; ;; This regexp match every "expression".
138
;; ;; modified by shiba
139
;; ;;(forward-sexp -1)
140
;; (beginning-of-line)
141
;; (skip-chars-forward " \t")
142
;; ;; End
143
;; (+ (current-column) ess-expression-offset))
144
;; ((and (numberp ess-arg-function-offset)
145
;; (re-search-backward
146
;; "=[ \t]*\\s\"*\\(\\w\\|\\s_\\)+\\s\"*[ \t]*"
147
;; bol
148
;; t))
149
;; (forward-sexp -1)
150
;; (+ (current-column) ess-arg-function-offset))
151
;; ;; "expression" is searched before "=".
152
;; ;; End
153
154
;; (t
155
;; (progn (goto-char (1+ containing-sexp))
156
;; (current-column))))))
157
;; (t
158
;; ;; Statement level. Is it a continuation or a new statement?
159
;; ;; Find previous non-comment character.
160
;; (goto-char indent-point)
161
;; (ess-backward-to-noncomment containing-sexp)
162
;; ;; Back up over label lines, since they don't
163
;; ;; affect whether our line is a continuation.
164
;; (while (eq (preceding-char) ?\,)
165
;; (ess-backward-to-start-of-continued-exp containing-sexp)
166
;; (beginning-of-line)
167
;; (ess-backward-to-noncomment containing-sexp))
168
;; ;; Now we get the answer.
169
;; (if (ess-continued-statement-p)
170
;; ;; This line is continuation of preceding line's statement;
171
;; ;; indent ess-continued-statement-offset more than the
172
;; ;; previous line of the statement.
173
;; (progn
174
;; (ess-backward-to-start-of-continued-exp containing-sexp)
175
;; (+ ess-continued-statement-offset (current-column)
176
;; (if (save-excursion (goto-char indent-point)
177
;; (skip-chars-forward " \t")
178
;; (eq (following-char) ?{))
179
;; ess-continued-brace-offset 0)))
180
;; ;; This line starts a new statement.
181
;; ;; Position following last unclosed open.
182
;; (goto-char containing-sexp)
183
;; ;; Is line first statement after an open-brace?
184
;; (or
185
;; ;; If no, find that first statement and indent like it.
186
;; (save-excursion
187
;; (forward-char 1)
188
;; (while (progn (skip-chars-forward " \t\n")
189
;; (looking-at "//"))
190
;; ;; Skip over comments following openbrace.
191
;; (forward-line 1))
192
;; ;; The first following code counts
193
;; ;; if it is before the line we want to indent.
194
;; (and (< (point) indent-point)
195
;; (current-column)))
196
;; ;; If no previous statement,
197
;; ;; indent it relative to line brace is on.
198
;; ;; For open brace in column zero, don't let statement
199
;; ;; start there too. If ess-indent-level is zero,
200
;; ;; use ess-brace-offset + ess-continued-statement-offset instead.
201
;; ;; For open-braces not the first thing in a line,
202
;; ;; add in ess-brace-imaginary-offset.
203
;; (+ (if (and (bolp) (zerop ess-indent-level))
204
;; (+ ess-brace-offset ess-continued-statement-offset)
205
;; ess-indent-level)
206
;; ;; Move back over whitespace before the openbrace.
207
;; ;; If openbrace is not first nonwhite thing on the line,
208
;; ;; add the ess-brace-imaginary-offset.
209
;; (progn (skip-chars-backward " \t")
210
;; (if (bolp) 0 ess-brace-imaginary-offset))
211
;; ;; If the openbrace is preceded by a parenthesized exp,
212
;; ;; move to the beginning of that;
213
;; ;; possibly a different line
214
;; (progn
215
;; (if (eq (preceding-char) ?\))
216
;; (forward-sexp -1))
217
;; ;; Get initial indentation of the line we are on.
218
;; (current-indentation))))))))))
219
220
221
222
223
(defvar OMG-syntax-table nil "Syntax table for Omegahat code.")
224
(if S-syntax-table
225
nil
226
(setq S-syntax-table (make-syntax-table))
227
(modify-syntax-entry ?\\ "\\" S-syntax-table)
228
(modify-syntax-entry ?+ "." S-syntax-table)
229
(modify-syntax-entry ?- "." S-syntax-table)
230
(modify-syntax-entry ?= "." S-syntax-table)
231
(modify-syntax-entry ?% "." S-syntax-table)
232
(modify-syntax-entry ?< "." S-syntax-table)
233
(modify-syntax-entry ?> "." S-syntax-table)
234
(modify-syntax-entry ?& "." S-syntax-table)
235
(modify-syntax-entry ?| "." S-syntax-table)
236
(modify-syntax-entry ?\' "\"" S-syntax-table)
237
;;FIXME: This fails (warning in compilation):
238
;;F "//" are 2 characters; ?// is invalid
239
;;F NEXT LINE IS BOGUS IN XEMACS, AJR
240
;;F (modify-syntax-entry ?// "<" S-syntax-table) ; open comment
241
;;F (modify-syntax-entry ?\n ">" S-syntax-table) ; close comment
242
;;(modify-syntax-entry ?. "w" S-syntax-table) ; "." used in S obj names
243
(modify-syntax-entry ?. "_" S-syntax-table) ; see above/below,
244
; plus consider separation.
245
(modify-syntax-entry ?$ "_" S-syntax-table) ; foo.bar$hack is 1 symbol
246
(modify-syntax-entry ?_ "." S-syntax-table)
247
(modify-syntax-entry ?* "." S-syntax-table)
248
(modify-syntax-entry ?< "." S-syntax-table)
249
(modify-syntax-entry ?> "." S-syntax-table)
250
(modify-syntax-entry ?/ "." S-syntax-table))
251
252
253
(defvar OMG-editing-alist
254
'((paragraph-start . (concat "^$\\|" page-delimiter))
255
(paragraph-separate . (concat "^$\\|" page-delimiter))
256
(paragraph-ignore-fill-prefix . t)
257
(require-final-newline . mode-require-final-newline)
258
(comment-start . "//")
259
(comment-start-skip . "//+ *")
260
(comment-column . 40)
261
;;(comment-indent-function . 'S-comment-indent)
262
;;(ess-comment-indent . 'S-comment-indent)
263
;;(ess-indent-line . 'S-indent-line)
264
;;(ess-calculate-indent . 'ess-calculate-indent)
265
(indent-line-function . 'ess-indent-line)
266
(parse-sexp-ignore-comments . t)
267
(ess-style . ess-default-style)
268
(ess-local-process-name . nil)
269
;;(ess-keep-dump-files . 'ask)
270
(ess-mode-syntax-table . S-syntax-table)
271
(font-lock-defaults . '(ess-OMG-font-lock-defaults
272
nil nil ((?\. . "w")))))
273
"General options for Omegahat source files.")
274
275
(defvar ess-OMG-font-lock-defaults
276
(append (list
277
(cons "\\b[0-9]+\\b" 'font-lock-type-face) ; numbers
278
(cons (concat "\\<" (regexp-opt ess-S-keywords 'enc-paren) "\\>")
279
'font-lock-keyword-face))
280
(list
281
(cons (regexp-opt ess-S-assign-ops)
282
'font-lock-constant-face) ; assign
283
(cons (concat "\\<" (regexp-opt ess-S-constants 'enc-paren) "\\>")
284
'font-lock-type-face) ; constants
285
(cons (concat "\\<" (regexp-opt ess-S-modifyiers 'enc-paren) "\\>")
286
'font-lock-constant-face) ; modify search list or source
287
288
(cons ess-S-function-name-regexp
289
'(1 font-lock-function-name-face keep))
290
; function name
291
(cons "\\s.\\|\\s(\\|\\s)" 'font-lock-function-name-face)
292
;punctuation and parents (same as function not to cause vidual disturbance)
293
)) ; keywords
294
"Font-lock patterns used in `OMG' buffers.")
295
296
297
;;; Changes from S to S-PLUS 3.x. (standard S3 should be in ess-s-l.el !).
298
299
(defconst OMG-help-sec-keys-alist
300
'((?a . "ARGUMENTS:")
301
(?b . "BACKGROUND:")
302
(?B . "BUGS:")
303
(?d . "DESCRIPTION:")
304
(?D . "DETAILS:")
305
(?e . "EXAMPLES:")
306
(?n . "NOTE:")
307
(?O . "OPTIONAL ARGUMENTS:")
308
(?R . "REQUIRED ARGUMENTS:")
309
(?r . "REFERENCES:")
310
(?s . "SEE ALSO:")
311
(?S . "SIDE EFFECTS:")
312
(?u . "USAGE:")
313
(?v . "VALUE:"))
314
"Alist of (key . string) pairs for use in section searching.")
315
;;; `key' indicates the keystroke to use to search for the section heading
316
;;; `string' in an S help file. `string' is used as part of a
317
;;; regexp-search, and so specials should be quoted.
318
319
(defconst ess-help-OMG-sec-regex "^[A-Z. ---]+:$"
320
"Reg(ular) Ex(pression) of section headers in help file")
321
322
;;; S-mode extras of Martin Maechler, Statistik, ETH Zurich.
323
324
;;>> Moved things into --> ./ess-utils.el
325
326
(provide 'ess-omg-l)
327
328
; Local variables section
329
330
;;; This file is automatically placed in Outline minor mode.
331
;;; The file is structured as follows:
332
;;; Chapters: ^L ;
333
;;; Sections: ;;*;;
334
;;; Subsections: ;;;*;;;
335
;;; Components: defuns, defvars, defconsts
336
;;; Random code beginning with a ;;;;* comment
337
338
;;; Local variables:
339
;;; mode: emacs-lisp
340
;;; outline-minor-mode: nil
341
;;; mode: outline-minor
342
;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
343
;;; End:
344
345
;;; ess-omg-l.el ends here
346
347