~ubuntu-branches/ubuntu/edgy/ess/edgy

« back to all changes in this revision

Viewing changes to lisp/ess-mode.el

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-11-11 00:51:43 UTC
  • mfrom: (1.1.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20041111005143-wv1cih1h04xyrxrb
Tags: 5.2.3-3
* repair broken replace-regexp-in-string -> ess-replace-regexp-in-string
  patch
* expand autoload functionality in emacsen-startup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
;;; ess-mode.el --- Support for editing ESS source code
2
2
 
3
3
;; Copyright (C) 1989-1994 Doug Bates, Ed Kademan, Frank Ritter, David Smith.
4
 
;; Copyright (C) 1997-1999 Richard M. Heiberger <rmh@fisher.stat.temple.edu>
5
 
;;                      Kurt Hornik <hornik@ci.tuwien.ac.at>
6
 
;;                      Martin Maechler <maechler@stat.math.ethz.ch>
7
 
;;                      A.J. (Tony) Rossini <rossini@u.washington.edu>
 
4
;; Copyright (C) 1997--2004 A.J. Rossini, Rich M. Heiberger, Martin
 
5
;;      Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
8
6
 
9
 
;; Author: David Smith <dsmith@stats.adelaide.edu.au>
10
 
;; Maintainer: A.J. Rossini <rossini@u.washington.edu>
 
7
;; Original Author: David Smith <dsmith@stats.adelaide.edu.au>
11
8
;; Created: 7 Jan 1994
12
 
;; Modified: $Date: 2002/06/20 21:52:06 $
13
 
;; Version: $Revision: 5.21 $
14
 
;; RCS: $Id: ess-mode.el,v 5.21 2002/06/20 21:52:06 rsparapa Exp $
 
9
;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
15
10
 
16
11
;; This file is part of ESS
17
12
 
22
17
 
23
18
;; This file is distributed in the hope that it will be useful,
24
19
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
21
;; GNU General Public License for more details.
27
22
 
28
23
;; You should have received a copy of the GNU General Public License
29
 
;; along with GNU Emacs; see the file COPYING.  If not, write to
 
24
;; along with GNU Emacs; see the file COPYING.  If not, write to
30
25
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
31
26
 
32
27
;;; Commentary:
40
35
(require 'ess)
41
36
 
42
37
;;; AJR: THIS IS GROSS AND DISGUSTING (but I wrote it).
43
 
;;; MM:  and I had to add all other 'ess-eval-*** ...
 
38
;;; MM:  and I had to add all other 'ess-eval-*** ...
44
39
;;; >>> why not just do the obvious instead of all these ? Namely,
45
40
;;; (require 'ess-inf)
46
41
;;; ------------------ ?
47
42
;;; AJR: The reason is that we ONLY need to load ess-inf for the
48
 
;;; functions which are interactive in nature.   We don't want to load
 
43
;;; functions which are interactive in nature.   We don't want to load
49
44
;;; it when we are only editing.
50
45
 
51
46
(autoload 'ess-mode-minibuffer-map      "ess-inf" "" nil 'keymap)
172
167
 ess-mode-menu ess-mode-map
173
168
 "Menu for use in `ess-mode'."
174
169
 '("ESS" ; ESS-mode
175
 
   ["What is this? (beta)"    ess-mouse-me                      t]
 
170
   ["What is this? (beta)"    ess-mouse-me                      t]
176
171
   ["Load file"  ess-load-file t]
177
172
   ("Eval and Go"
178
173
    ["Eval buffer"      ess-eval-buffer-and-go            t]
198
193
    ["Edit new object"          ess-dump-object-into-edit-buffer t]
199
194
    ["Goto end of ESS buffer"   ess-switch-to-end-of-ESS        t]
200
195
    ["Switch to ESS buffer"     ess-switch-to-ESS               t]
 
196
    ["Beginning of function"    ess-beginning-of-function       t]
201
197
    ["End of function"          ess-end-of-function             t]
202
 
    ["Beginning of function"    ess-beginning-of-function       t])
 
198
    )
203
199
   ("ESS list..."
204
200
    ["Backward list"            backward-list                   t]
205
201
    ["Forward list"             forward-list                    t]
219
215
    ["Undo"              undo                                   t]
220
216
    ["About"             (ess-goto-info "Edit buffer")          t]
221
217
    )
 
218
   ("Start Process"
 
219
    ;; SJE - :help not yet recognised in XEmacs.
 
220
    ["R"     R   t] ;; :help "Start a new R process" :active t
 
221
    ["S"     S   t] ;; :help "Start a new S process" :active t
 
222
    ["Sqpe" Sqpe ess-microsoft-p] ;; :help "Start a new Sqpe process" :active t
 
223
    ["S+6-exisiting" S+6-existing ess-microsoft-p] ;; :help "Access an existing S process" :active t
 
224
    ["SAS"   SAS-menu t] ;;  :help "Start a new SAS process" :active t
 
225
    ;; The following menu item "Other" is a place-holder that will
 
226
    ;; be replaced with the other versions of R and Sqpe that can be run.
 
227
    ;; See `ess-r-versions-create' and ess-site.el
 
228
    ("Other"
 
229
     ["No other R or Sqpe versions" nil nil])
 
230
    ["About"
 
231
     (ess-goto-info "Starting up") t]
 
232
     ;; :help "Read about starting a new ESS process" :active t]
 
233
    )
222
234
   ["Switch Process"    ess-switch-process              t]
223
235
   "------"
224
236
   ["Describe"          describe-mode                   t]
225
 
   ["About"             (ess-goto-info "Editing")       t]
 
237
   ["About editing" (ess-goto-info "Editing")   t]
 
238
   ["Read ESS info" (ess-goto-info "") t]
226
239
   ["Send bug report"   ess-submit-bug-report           t]
227
240
   ))
228
241
 
 
242
(defun SAS-menu ()
 
243
  "Start SAS from the menu."
 
244
  (interactive)
 
245
  (if ess-microsoft-p
 
246
      ;; replace with other choices for starting SAS under XEmacs?
 
247
      (error "SAS cannot be started this way in ESS on Windows.")
 
248
    (SAS)))
 
249
 
229
250
(defun ess-mode-xemacs-menu ()
230
251
  "Hook to install `ess-mode' menu for XEmacs (w/ easymenu)."
231
252
  (if 'ess-mode
232
 
        (easy-menu-add ess-mode-menu)
 
253
        (easy-menu-add ess-mode-menu)
233
254
    (easy-menu-remove ess-mode-menu)))
234
255
 
235
256
(if (featurep 'xemacs)
242
263
 
243
264
\\{ess-mode-map}
244
265
 
245
 
Extra binding to note:  'ESC C-\\' indent-region.
 
266
Extra binding to note:  'ESC C-\\' indent-region.
246
267
 
247
268
Entry to this mode runs the hooks in ess-mode-hook.
248
269
 
253
274
    `ess-eval-function' sends the current function to the ESS process.
254
275
    `ess-eval-line' sends the current line to the ESS process.
255
276
    `ess-beginning-of-function' and `ess-end-of-function' move the point to
256
 
        the beginning and end of the current ESS function.
 
277
        the beginning and end of the current ESS function.
257
278
    `ess-switch-to-ESS' switches the current buffer to the ESS process buffer.
258
279
    `ess-switch-to-end-of-ESS' switches the current buffer to the ESS process
259
 
        buffer and puts point at the end of it.
 
280
        buffer and puts point at the end of it.
260
281
 
261
282
    `ess-eval-region-and-go', `ess-eval-buffer-and-go',
262
 
        `ess-eval-function-and-go', and `ess-eval-line-and-go' switch to the S
263
 
        process buffer after sending their text.
 
283
        `ess-eval-function-and-go', and `ess-eval-line-and-go' switch to the S
 
284
        process buffer after sending their text.
264
285
 
265
286
    `ess-load-file' sources a file of commands to the ESS process.
266
287
 
267
288
\\[ess-indent-command] indents for ESS code.
268
289
\\[backward-delete-char-untabify] converts tabs to spaces as it moves back.
269
290
Comments are indented in a similar way to Emacs-lisp mode:
270
 
       `###'     beginning of line
271
 
       `##'      the same level of indentation as the code
272
 
       `#'       the same column on the right, or to the right of such a
273
 
                 column if that is not possible.(default value 40).
274
 
                 \\[indent-for-comment] command automatically inserts such a
275
 
                 `#' in the right place, or aligns such a comment if it is
276
 
                 already inserted.
 
291
       `###'     beginning of line
 
292
       `##'      the same level of indentation as the code
 
293
       `#'       the same column on the right, or to the right of such a
 
294
                 column if that is not possible.(default value 40).
 
295
                 \\[indent-for-comment] command automatically inserts such a
 
296
                 `#' in the right place, or aligns such a comment if it is
 
297
                 already inserted.
277
298
\\[ess-indent-exp] command indents each line of the ESS grouping following point.
278
299
 
279
300
Variables controlling indentation style:
320
341
`CLB' (quoted from C language style)."
321
342
  (interactive)
322
343
  (kill-all-local-variables) ;; NOTICE THIS!
323
 
  (ess-setq-vars-local alist (current-buffer))
 
344
  (ess-setq-vars-local alist)
324
345
  (ess-write-to-dribble-buffer
325
346
   (format "(ess-mode-1): ess-language=%s, ess-dialect=%s buf=%s \n"
326
347
           ess-language
338
359
  (ess-write-to-dribble-buffer
339
360
   (format "(ess-mode-1.6): editing-alist=%s \n"
340
361
           ess-mode-editing-alist))
341
 
  (ess-setq-vars-local ess-mode-editing-alist (current-buffer))
 
362
  (ess-setq-vars-local ess-mode-editing-alist)
342
363
 
343
364
  (use-local-map ess-mode-map)
344
365
  (set-syntax-table ess-mode-syntax-table)
394
415
  "Leave (and return) the point at the beginning of the current ESS function."
395
416
  (interactive)
396
417
  (let ((init-point (point))
397
 
        beg end done)
 
418
        beg end done)
398
419
    ;;DBG (ess-write-to-dribble-buffer "ess-BEG-of-fun:")
399
420
    ;; in case we're sitting in a function header:
400
421
    (if (search-forward "(" (ess-line-end-position 2) t); at most end of next line
401
422
        (forward-char 1))
402
423
    (while (not done)
403
424
      (if (re-search-backward ess-function-pattern (point-min) t)
404
 
          nil
405
 
        (goto-char init-point)
406
 
        (error "Point is not in a function."))
 
425
          nil
 
426
        (goto-char init-point)
 
427
        (error "Point is not in a function."))
407
428
 
408
429
      (setq beg (point))
409
430
      ;;DBG (ess-write-to-dribble-buffer
726
747
            ;; Adjust line indentation according to its contents
727
748
            (if (= (following-char) ?})
728
749
                ;;(setq this-indent (- this-indent ess-indent-level)))
729
 
                (setq this-indent (+ this-indent
730
 
                                     (- ess-close-brace-offset ess-indent-level))))
 
750
                (setq this-indent (+ this-indent
 
751
                                     (- ess-close-brace-offset ess-indent-level))))
731
752
            (if (= (following-char) ?{)
732
753
                (setq this-indent (+ this-indent ess-brace-offset)))
733
754
            ;; Put chosen indentation into effect.
999
1020
                       "Set ESS mode indentation style (default %s): "
1000
1021
                       ess-default-style)
1001
1022
                      (vconcat ess-styles)
1002
 
                      (function (lambda (arg) (memq arg ess-styles)))
1003
 
                      )))
 
1023
                      (function (lambda (arg) (memq arg ess-styles))))))
1004
1024
                (if (string-equal "" style-string)
1005
1025
                    ess-default-style
1006
1026
                  (intern style-string)))))
1055
1075
        (error "Directory %s does not exist." dirname)))
1056
1076
 
1057
1077
    ;; Three options:
1058
 
    ;;  (1) Pop to an existing buffer containing the file in question
1059
 
    ;;  (2) Find an existing file
1060
 
    ;;  (3) Create a new file by issuing a dump() command to S
 
1078
    ;;  (1) Pop to an existing buffer containing the file in question
 
1079
    ;;  (2) Find an existing file
 
1080
    ;;  (3) Create a new file by issuing a dump() command to S
1061
1081
    ;; Force option (3) if there is a prefix arg
1062
1082
 
1063
1083
    (if current-prefix-arg
1149
1169
 
1150
1170
;;; This file is automatically placed in Outline minor mode.
1151
1171
;;; The file is structured as follows:
1152
 
;;; Chapters:     ^L ;
1153
 
;;; Sections:    ;;*;;
 
1172
;;; Chapters:     ^L ;
 
1173
;;; Sections:    ;;*;;
1154
1174
;;; Subsections: ;;;*;;;
1155
 
;;; Components:  defuns, defvars, defconsts
1156
 
;;;              Random code beginning with a ;;;;* comment
 
1175
;;; Components:  defuns, defvars, defconsts
 
1176
;;;              Random code beginning with a ;;;;* comment
1157
1177
 
1158
1178
;;; Local variables:
1159
1179
;;; mode: emacs-lisp