~ubuntu-branches/ubuntu/hardy/ess/hardy

« back to all changes in this revision

Viewing changes to lisp/ess-emcs.el

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2005-03-22 13:48:07 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050322134807-9mpmbb799jugf248
Tags: 5.2.6-1
* New upstream release
* chmod -R u+w on orig source

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
;;; ess-emcs.el --- simple determination of Emacs/XEmacs and version #.
2
2
 
3
 
;; Copyright (C) 2000--2001 A.J. Rossini <rossini@u.washington.edu>,
4
 
;; R.M. Heiberger <rmh@surfer.sbm.temple.edu>,
5
 
;; Martin Maechler <maechler@stat.math.ethz.ch>,
6
 
;; Kurt Hornik <hornik@ci.tuwien.ac.at>, and
7
 
;; Rodney Sparapani <rsparapa@mcw.edu>.
 
3
;; Copyright (C) 2000--2005 A.J. Rossini, Rich M. Heiberger, Martin
 
4
;;      Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
8
5
 
9
 
;; Author:  A.J. Rossini <rossini@biostat.washington.edu>
10
 
;; Maintainer: A.J. Rossini <rossini@biostat.washington.edu>
 
6
;; Original Author: A.J. Rossini <rossini@biostat.washington.edu>
11
7
;; Created: 07 June 2000
12
 
;; Modified: $Date: 2001/11/01 19:33:24 $
13
 
;; Version: $Revision: 5.14 $
14
 
;; RCS: $Id: ess-emcs.el,v 5.14 2001/11/01 19:33:24 ess Exp $
15
 
;;
 
8
;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
 
9
 
16
10
;; Keywords: start up, configuration.
17
11
 
18
12
;; This file is part of ESS
64
58
      (and (= emacs-major-version major)
65
59
           (>= emacs-minor-version minor))))
66
60
 
67
 
(defvar ess-running-xemacs (string-match "XEmacs\\|Lucid" emacs-version))
 
61
;(defvar ess-running-xemacs (string-match "XEmacs\\|Lucid" emacs-version))
68
62
 
69
63
(defvar ess-local-custom-available (featurep 'custom)
70
64
  "Value is nil if custom.el not available, t if available.
71
65
Only a concern with earlier versions of Emacs.")
72
66
 
 
67
;; FIXME:  When emacs is started from Cygwin shell in Windows,
 
68
;;         we have (equal window-system 'x) -and should use "--ess" in *d-r.el
73
69
(defvar ess-microsoft-p (or (equal window-system 'w32)
74
70
                            ;; XEmacs only...
75
71
;;;                         (equal (console-type) 'pc)
88
84
;; XEmacs 20.x needs this
89
85
(if (not (fboundp 'find-buffer-visiting))
90
86
    (fset 'find-buffer-visiting 'get-file-buffer))
91
 
 
92
 
;; XEmacs 21.x need this
 
87
;; XEmacs <= 21.4.15 needs this
 
88
(if (not (fboundp 'line-beginning-position))
 
89
    (defalias 'line-beginning-position 'point-at-bol))
 
90
 
 
91
(if (and (not (featurep 'xemacs))
 
92
         (string-match "XEmacs\\|Lucid" emacs-version))
 
93
    (provide 'xemacs))
 
94
 
 
95
;; XEmacs 21.x and Emacs 20.x need this
 
96
(cond ((fboundp 'replace-regexp-in-string)
 
97
       (defalias 'ess-replace-regexp-in-string 'replace-regexp-in-string))
 
98
      ((featurep 'xemacs)
 
99
        (defun ess-replace-regexp-in-string(regexp replace string)
 
100
          "Mimic GNU Emacs function replace-regexp-in-string with XEmacs' replace-in-string"
 
101
          (replace-in-string string regexp replace)))
 
102
 
 
103
      ;; GNU emacs <= 20 -- take Emacs' 21(.3)'s definition:
 
104
      (t (defun ess-replace-regexp-in-string (regexp rep string &optional
 
105
                                              fixedcase literal subexp start)
 
106
        "Replace all matches for REGEXP with REP in STRING.
 
107
 
 
108
Return a new string containing the replacements.
 
109
 
 
110
Optional arguments FIXEDCASE, LITERAL and SUBEXP are like the
 
111
arguments with the same names of function `replace-match'.  If START
 
112
is non-nil, start replacements at that index in STRING.
 
113
 
 
114
REP is either a string used as the NEWTEXT arg of `replace-match' or a
 
115
function.  If it is a function it is applied to each match to generate
 
116
the replacement passed to `replace-match'; the match-data at this
 
117
point are such that match 0 is the function's argument.
 
118
 
 
119
To replace only the first match (if any), make REGEXP match up to \\'
 
120
and replace a sub-expression, e.g.
 
121
  (ess-replace-regexp-in-string \"\\(foo\\).*\\'\" \"bar\" \" foo foo\" nil nil 1)
 
122
    => \" bar foo\"
 
123
"
 
124
 
 
125
        ;; To avoid excessive consing from multiple matches in long strings,
 
126
        ;; don't just call `replace-match' continually.  Walk down the
 
127
        ;; string looking for matches of REGEXP and building up a (reversed)
 
128
        ;; list MATCHES.  This comprises segments of STRING which weren't
 
129
        ;; matched interspersed with replacements for segments that were.
 
130
        ;; [For a `large' number of replacments it's more efficient to
 
131
        ;; operate in a temporary buffer; we can't tell from the function's
 
132
        ;; args whether to choose the buffer-based implementation, though it
 
133
        ;; might be reasonable to do so for long enough STRING.]
 
134
        (let ((l (length string))
 
135
              (start (or start 0))
 
136
              matches str mb me)
 
137
          (save-match-data
 
138
            (while (and (< start l) (string-match regexp string start))
 
139
              (setq mb (match-beginning 0)
 
140
                    me (match-end 0))
 
141
              ;; If we matched the empty string, make sure we advance by one char
 
142
              (when (= me mb) (setq me (min l (1+ mb))))
 
143
              ;; Generate a replacement for the matched substring.
 
144
              ;; Operate only on the substring to minimize string consing.
 
145
              ;; Set up match data for the substring for replacement;
 
146
              ;; presumably this is likely to be faster than munging the
 
147
              ;; match data directly in Lisp.
 
148
              (string-match regexp (setq str (substring string mb me)))
 
149
              (setq matches
 
150
                    (cons (replace-match (if (stringp rep)
 
151
                                             rep
 
152
                                           (funcall rep (match-string 0 str)))
 
153
                                         fixedcase literal str subexp)
 
154
                          (cons (substring string start mb) ; unmatched prefix
 
155
                                matches)))
 
156
              (setq start me))
 
157
            ;; Reconstruct a string from the pieces.
 
158
            (setq matches (cons (substring string start l) matches)) ; leftover
 
159
            (apply #'concat (nreverse matches)))))
 
160
      )
 
161
)
 
162
 
 
163
;; remassoc exists as a built-in function in xemacs, but
 
164
;; not in GNU emacs
 
165
;;
 
166
(if (not (functionp 'remassoc))
 
167
    (defun remassoc (key a)
 
168
      "remove an association pair from an alist"
 
169
      (if a
 
170
          (let ((pair (car a)))
 
171
            (if (equal (car pair) key)
 
172
                (cdr a)
 
173
                (cons pair (remassoc key (cdr a))))))))
 
174
 
93
175
(if (not (fboundp 'w32-using-nt))
94
176
(defun w32-using-nt ()
95
177
  "Return non-nil if literally running on Windows NT (i.e., not Windows 9X)."
96
178
  (and (eq system-type 'windows-nt) (getenv "SystemRoot"))))
97
179
 
 
180
(if (and (featurep 'xemacs)
 
181
         (fboundp 'extent-at)
 
182
         (fboundp 'make-extent)
 
183
         (fboundp 'set-extent-property))
 
184
  (defun ess-xemacs-insert-glyph (gl)
 
185
     "Insert a glyph at the left edge of point."
 
186
     (let ((prop 'myimage) ;; myimage is an arbitrary name, chosen to
 
187
           ;;                 (hopefully) not conflict with any other
 
188
           ;;                 properties. Change it if necessary.
 
189
            extent)
 
190
       ;; First, check to see if one of our extents already exists at
 
191
       ;; point.  For ease-of-programming, we are creating and using our
 
192
       ;; own extents (multiple extents are allowed to exist/overlap at the
 
193
       ;; same point, and it's quite possible for other applications to
 
194
       ;; embed extents in the current buffer without your knowledge).
 
195
       ;; Basically, if an extent, with the property stored in "prop",
 
196
       ;; exists at point, we assume that it is one of ours, and we re-use
 
197
       ;; it (this is why it is important for the property stored in "prop"
 
198
       ;; to be unique, and only used by us).
 
199
       (if (not (setq extent (extent-at (point) (current-buffer) prop)))
 
200
         (progn
 
201
           ;; If an extent does not already exist, create a zero-length
 
202
           ;; extent, and give it our special property.
 
203
           (setq extent (make-extent (point) (point) (current-buffer)))
 
204
           (set-extent-property extent prop t)
 
205
           ))
 
206
       ;; Display the glyph by storing it as the extent's "begin-glyph".
 
207
       (set-extent-property extent 'begin-glyph gl))))
 
208
 
98
209
;; XEmacs and NTemacs 19.x need these
99
210
(if (not (boundp 'w32-system-shells))
100
211
      (defvar w32-system-shells '("cmd" "cmd.exe" "command" "command.com"
129
240
           (w32-system-shell-p (getenv "COMSPEC")))))
130
241
)
131
242
 
 
243
;; XEmacs on Windows needs this
 
244
(if (and ess-microsoft-p
 
245
         (not (fboundp 'w32-short-file-name)))
 
246
    (fset 'w32-short-file-name 'win32-short-file-name))
 
247
 
132
248
(provide 'ess-emcs)
133
249
 
134
250
 ; Local variables section