1 ;;; ess-install.el --- Automatic installation of ESS.
2 ;; Auto-install procedure. EXPERIMENTAL!
4 ;; Copyright (C) 2006 A.J. Rossini, Rich M. Heiberger, Martin
5 ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
7 ;; Original Author: Stephen Eglen
9 ;; This file is part of ESS
11 ;; This file is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; This file is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 ;; In short: you may use this code any way you like, as long as you
26 ;; don't charge more than a distribution fee for it, do distribute the
27 ;; source with any binaries, remove this notice, or hold anyone liable
33 ;; Although installing ESS is relatively simple, sometimes people get
34 ;; confused as to what to add to their init files, or even where their
35 ;; init files are located. The following procedure should be a bit
36 ;; simpler, as Emacs will add the necessary start-up lines itself.
37 ;; (The instructions below assume you have downloaded ess as a zip
38 ;; package, but it will work also for the .tar.gz version of ESS as
39 ;; long as you know how to unpack a .tar.gz in step 3.)
41 ;; Installing ESS for the first time.
43 ;; 1. Create a folder (e.g C:/emacs) where you will store ESS. We will
44 ;; assume that you are installing ESS into C:/emacs (unix users can use
47 ;; 2. Download ess-5.2.12.zip and store it in the folder you created.
49 ;; 3. Unpack the files from the zip archive, e.g. by right-clicking on it
50 ;; within Windows explorer and selecting "Extract all". On unix, use
51 ;; "unzip ess-5.2.12.zip".
53 ;; 4. Start a new emacs (or xemacs).
55 ;; 5. In the new emacs, you need to open the file "ess-install.el" which
56 ;; is part of ESS. To do this, type:
58 ;; C-x C-f c:/emacs/ess-5.2.12/lisp/ess-install.el RET
60 ;; You should now see a lisp file with the top line:
61 ;; ;;; ess-install.el --- Automatic installation of ESS.
63 ;; 6. Type M-x eval-buffer RET
65 ;; What does this do? This will find your emacs initialisation file, and
66 ;; it will add the following two lines to the end of the file:
68 ;; ;;; ESS setup for version 5.2.12
69 ;; (load "c:/emacs/ess-5.2.12/lisp/ess-site")
71 ;; Do not edit those two lines! They are useful if later you come to
74 ;; 7. Start a new Emacs and you should find then that ESS is loaded. For
75 ;; example, create a new file called "foo.R" and check that it opens
76 ;; in R mode by looking at the mode line and menubar.
78 ;; Upgrading your version of ESS.
80 ;; If (and only if) you use the above instructions for installing ESS,
81 ;; when a new version of ESS is released, you can use the same method to
82 ;; install the new version. Repeat steps 2-7 for the new release of ESS,
83 ;; and this time in step 6, if emacs finds that you already have the
84 ;; special line ";;; ESS setup for version 5.2.12", it will highlight
85 ;; those lines, and query whether you want to replace those two lines
86 ;; with the new setup code.
88 ;; If you do upgrade ESS this way, bear in mind that your old version
89 ;; will not be deleted from your filespace -- you will have to delete it
92 ;; TODO: possibly add a call to (byte-recompile-directory ess-lisp-dir
93 ;; 0) so that lisp files are byte compiled.
95 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
96 ;; Location where the new lisp files are stored.
97 (defvar ess-lisp-dir
(file-name-directory
98 (abbreviate-file-name buffer-file-name
))
99 "Location where the new lisp files are stored.")
101 (defvar ess-site-file
(concat ess-lisp-dir
"ess-site")
102 "Full path to the new ess-site file.
103 Do not include .el extension in case there is also a .elc around.")
105 (defvar ess-new-version nil
106 "Version number of new ESS to be installed.")
108 (defvar ess-installed nil
)
111 (defun ess-install-byte-compile ()
112 "Byte compile the ESS files.
113 This will probably generate warnings, but they can hopefully be
115 ;; To do byte compilation, XEmacs seems to want the files on its
116 ;; load-path so that it can do the (require 'xyz) statements.
117 (add-to-list 'load-path ess-lisp-dir
)
118 (byte-recompile-directory ess-lisp-dir
0))
120 ;; Check that ess-site-file is written using unix directory separators.
121 ;; i.e. need to change c:\\some\\dir\\ess-site.el to
122 ;; c:/some/dir/ess-site.el
123 ;; To do this, we have to load in ess-replace-in-string, from
124 ;; the file ess-inf.el
126 (save-window-excursion
127 (find-file (concat ess-lisp-dir
"ess-inf.el"))
128 (goto-char (point-min))
129 (search-forward-regexp "^(defun ess-replace-in-string " nil t
)
132 (ess-replace-in-string ess-site-file
"\\\\" "/" t
))
136 ;; Get the version number of the new software. Open the file
137 ;; ess-cust.el and then find the definition of the variable
139 (save-window-excursion
141 (find-file (concat ess-lisp-dir
"ess-cust.el"))
142 ;; go back to start, just in case file was previously open.
143 (goto-char (point-min))
144 (search-forward "defvar ess-version \"")
146 (search-forward "\"")
147 (setq ess-new-version
(buffer-substring beg
(1- (point))))))
149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
150 ;;; Highlighting (copied from reftex.el -- cheers Carsten!)
151 ;; Only one highlight region is needed, whereas two are provided here,
152 ;; so this code could be simplified. But we may want it again later.
154 ;; Highlighting uses overlays. If this is for XEmacs, we need to load
155 ;; the overlay library, available in version 19.15
156 (and (not (fboundp 'make-overlay
))
160 (error "Fm needs overlay emulation (available in XEmacs 19.15)"))))
162 ;; We keep a vector with several different overlays to do our highlighting.
163 (defvar ess-highlight-overlays
[nil nil
])
165 ;; Initialize the overlays (here we provide two overlays)
166 (aset ess-highlight-overlays
0 (make-overlay 1 1))
167 (overlay-put (aref ess-highlight-overlays
0) 'face
'highlight
)
168 (aset ess-highlight-overlays
1 (make-overlay 1 1))
169 (overlay-put (aref ess-highlight-overlays
1) 'face
'highlight
)
171 ;; Two functions for activating and deactivation highlight overlays
172 (defun ess-highlight (index begin end
&optional buffer
)
173 "Highlight a region with overlay INDEX."
174 (move-overlay (aref ess-highlight-overlays index
)
175 begin end
(or buffer
(current-buffer))))
176 (defun ess-unhighlight (index)
177 "Detatch overlay INDEX."
178 (delete-overlay (aref ess-highlight-overlays index
)))
180 ;;; End of highlighting code.
181 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
183 ;; Try to find the .emacs init file and edit it.
184 (save-window-excursion
186 ;; Try to find the init file if one already exists,
187 ;; or create a new one if we can't find any.
188 (if (stringp user-init-file
)
189 (find-file user-init-file
)
190 ;; else, let's guess that the init file should be called ".emacs"
191 ;; and the tilde will be resolved okay.
192 (find-file "~/.emacs"))
193 (goto-char (point-min))
196 (concat "\n;;; ESS setup for version " ess-new-version
"\n"
197 "(load \"" ess-site-file
"\")\n"))
200 (if (search-forward ";;; ESS setup for version " nil t
)
202 (message "You already have ESS installed.")
204 (buffer-substring (point)
205 (save-excursion (end-of-line) (point))))
209 ;; We assume the next line contains a sexp that loads the
210 ;; the ess-site; this sexp can be multiple lines.
213 (ess-highlight 0 beg
(point))
217 (concat "Replace ESS version " ess-installed
219 ess-new-version
"? ")))
221 (kill-region beg
(point))
222 (insert ess-commands
)
224 (ess-install-byte-compile)
225 (message (concat "ESS updated to version " ess-new-version
))
227 ;; else, just insert commands at end.
228 (goto-char (point-max))
229 (insert ess-commands
)
231 (ess-install-byte-compile)
232 (message (concat "ESS version "ess-new-version
" installed."))