This section gives examples of initialization code that should be put into ~/.emacs or ~/.xemacs/init.el. Since much of this code is spread over several code chunks it is probably useful to execute
notangle -Remacscode allprose.tex.nw > emacs.el
|
and then cut and paste the appropriate lines from that file.
For the use of the inverse search facility of xdvi and kdvi, it is convenient not start a new Emacs every time you click in the xdvi window. See also Section24.3.9.
Through the following code file patterns are associated with modes.
It is quite useful to load AUCTEX and syntax highlighting.
My aldor-mode supports syntax highlighting and indenting Aldor code, but consult its documentation for more details.
aldor-mode is itself a literate program, so tangle and weave it.
notangle aldor.el.nw > aldor.el
noweave aldor.el.nw > aldor.tex |
Suppose you put the file aldor.el into the directory ˜/elisp. Then you should put the following code into your ~/.emacs or ~/.xemacs/init.el and restart Emacs. See also the definition of auto-mode-alist in Section 9.3.
The aldor-mode works fine with mmm-mode.
The multiple major mode (mmm-mode) is useful for editing code and documentation of .nw files in Emacs.
Setup can be done as follows.
EMACS=/usr/bin/emacs ./configure --prefix ~/elisp/mmm
make make install |
Be careful to compile for the flavour (Emacs or XEmacs) you use, see below.
First, the setup for mmm-mode in general and its association to certain file types.
The following code is partly taken from Emacs (subr.el assoc-default), because the function assoc-default is not available in XEmacs.
It takes a string (key) and tries to string-match the car (first of a list) of an element of auto-mode-alist against key. If found, it returns the cdr (rest of the list) of the matching pair. If not found then fundamental-mode is returned.
Note that an element of auto-mode-alist can either be a dotted pair or an atom. In the latter case, this atom is returned if it matches key. (Maybe that makes not much sense here, but we did not want to deviate too much from assoc-default.
We need get-auto-mode to set the mmm-noweb-code-mode depending on the file type. Whenever mmm-mode is switched on, the hook below tests whether the filename ends in .pamphlet or .nw. This extension is removed and the filename is matched against the auto-mode-alist. From the latter we get via the function get-auto-mode the corresponding mode that will then be assigned to mmm-noweb-code-mode.
You could put
% -*- mode: latex; mmm-noweb-code-mode: makefile-mode; -*-
|
at the beginning of your file.
Or, at the end of a .nw file say something like
%EMACS Local Variables:
%EMACS mmm-noweb-code-mode: makefile-mode %EMACS End: |
where, of course, makefile-mode has to be replaced by the mode that is appropriate for the code inside the code chunks, e. g., aldor-mode.
Of course, it is undesirable to put extra Emacs specific code into a source file, since one cannot expect that everyone is using Emacs.
Unfortunately, for XEmacs the setup is not identical. First of all, you will have to say
EMACS=/usr/bin/xemacs ./configure --prefix ~/elisp/mmm
|
and the above code goes into the file ~/.xemacs/init.el.
I have not investigated the reason for the following. Additionally, I had to add the preview-latex package (version 0.7.8) into the directory ˜/.xemacs/xemacs-packages in order to make mmm-mode work.
There is not much help in case the LATEX compilation of the dvi file fails. There are, however two files that can be investigated in order to find the reason for the error. The file myalps.trace is generated via
latex projectname.tex >> projectname.trace
|
The file myalps.log is the by default generated by LATEX itself.
One suggestion is to look into these files and search backwards for the extension .nw.tex in order to figure out in which file the error occurred. Note that you should edit the corresponding .nw file, since the .nw.tex file is generated on the fly.
Here we describe the case if the compilation of the library is started from within Emacs via the command
M-x compile RET cd $RootToProject; make RET
|
and fails. Emacs provides the command next-error. Calling it via
M-x next-error RET
|
lets Emacs load the corresponding file and jump directly to the error position.
You can bind the above command to a key. For example, put the following code into the ~/.emacs or the ~/.xemacs/init.el file.
Unfortunately, the Aldor compiler (version 1.0.3) does not yet treat #line directives correctly. Currently, when the Aldor compiler reports an error, Emacs will jump to the .as file although this is not the place where the error should be corrected. Note that source files under ALLPROSE are literate programming files and have the extension .as.nw. Therefore, you must look for the corresponding .as.nw yourself. Search in the .as file for a comment of the form
--#line NUMBER "FILENAME"
|
above the error position in order to find the appropriate line number of the corresponding .as.nw file.
It follows a workaround for the Aldor compiler bug of being unable to deal properly with #line directives.
With the help and code of Clifford Yap and Jay Belanger, I could put together some lines that one has to put into the ~/.emacs or the ~/.xemacs/init.el file. Then F12 jumps correctly into the .as.nw file.
The following function calls next-error and thus loads the corresponding .as file. From the cursor position it searches backwards for a line (that is produced via ALLPROSE, see Section 33.3) that looks like
--#line 211 "myalps/arith.as.nw"
|
That information is evaluated, the corresponding .as.nw is loaded, and the cursor is placed at the error position.
The .as file is loaded by next-error and should not be removed since then pressing F12 will result in a "No more errors" message.
Since the .as file is generated, the buffer might be out of sync with the actual file on disk, we must redefine the prompt function yes-or-no-p. That avoids the question whether the .as file should be reloaded.
The following function searches backward from the current cursor position until a line matching --#line is found. The number of lines that had to be moved backwards is remembered in the variable n. It then reads the line number and file name arguments, opens the corresponding .as.nw file, and jumps to the appropriate line number.