🚧 This is a work-in-progress version of seed7-mode, a major mode for the Seed7 programming language.
A lot of features are implemented but there's still some areas that need improvements or fixes, mainly for the complete support of .s7i files. Please create a bug report for any problem you detect.
Note: While the seed7-mode code is a stand-alone major mode and can be installed on plain-vanilla Emacs as described in the installation section titled How To Install seed7-mode with plain vanilla Emacs, another of my projects, the PEL project supports several Emacs extensions that can be useful when programming in Seed7 and simplifies installation and upgrades (see sections How to install and use seed7-mode with PEL and How to Update Seed7-Mode with PEL).
- PEL also provides a large set of specialized information PDFs.
- The PEL Seed7 PDF provides more information. This document also provides links to other relevant PEL PDFs. PEL is absolutely not required to use seed7-mode. PEL just provides some useful information and commands that complement what Emacs provides and what seed7-mode can provide while staying independent from PEL (and it is).
- These PEL PDF files are best viewed with a browser that can render them online (instead of downloading each one separately) because these PDF files hold a large number of hyperlinks to Emacs documentation, package and project website pages.
The seed7-mode-version command, bound to C-c v in seed7-mode buffers,
display the version UTC time stamp of the file in the message area, at bottom
of the screen. Use this to verify the version of the seed7-mode.el code you
are using.
Please include this information in bug reports.
Several features of the seed7-mode are customizable.
Use the seed7-mode-customize command, bound to C-c C to quickly open the
seed7-mode customization buffer.
The command is also accessible from the top menu as can be see here. Once issued it opens the seed7-mode customization buffer.
Use the customization buffer to view or change one or several customizable user-option variables.
Since these control the behaviour of the seed7-mode the changes will only
apply to buffers that are then opened in seed7-mode. If you already have
a buffer using the mode, change to fundamental-mode and then back to
seed7-mode for the changes to take effect.
Font lock syntax highlighting for Seed7 supports different faces for different Seed7 syntactic elements, including various faces for different types of numbers and warning font to identify some syntactic errors in the code, but not all.
See the following example screenshots:
| Screenshot | Description |
|---|---|
| Terminal-mode Emacs | Shows the default highlighting of Seed7 code on Emacs running in a macOS Terminal. |
| Graphical Emacs | Shows the default highlighting of Seed7 code on a basic GUI Emacs running in a macOS with the default scheme. |
| PEL Ref: | PEL Outline PDF |
|---|
The seed7-mode supports the Emacs outline minor mode: collapse and expansion of blocks, where heading is the first line of a declaration block. This allows navigation and code manipulation by headings (blocks).
| Screenshot | Description |
|---|---|
| bas.sd7 outline all collapsed | The prg/bas.sd7 file shown with outline-minor-mode
active after executing outline-hide-sublevels |
| bas.sd7 outline with 2 expanded | The same prg/bas.sd7 file shown with outline-minor-mode
active after expanding 2 outlines with outline-show-entry
at lines 154 and 369. |
By default, Emacs has no special key bindings to activate the Emacs outline minor mode but you can execute the outline-minor-mode command to turn it on or off. The following table shows some of the important key bindings that are available in the Emacs outline minor mode. These are also shown in the PEL Outline PDF along with PEL specific key bindings.
| . | Function | Key Binding | Description |
|---|---|---|---|
| . | outline-minor-mode | Toggle (activate/de-activate) the Emacs outline minor mode.
|
|
| . | Commands available in outline minor mode: | ||
| . | outline-hide-body | C-c @ C-t |
Collapse the body of all blocks, leaving the first line visible. |
| . | outline-show-all | C-c @ C-a |
Show all: expand the body of all blocks. |
| . | |||
| . | outline-hide-leaves | C-c @ C-l |
Collapse body of current block. |
| . | outline-show-subtree | C-c @ C-s |
Expand the body of the current block. |
| . | |||
| . | outline-hide-other | C-c @ C-o |
Collapse everything except the current block. |
| PEL Ref: | PEL Menu & iMenu PDF |
|---|
Provides a Seed7 top level menu entry which provides access to the commands. Here's some examples:
| Screenshot | Description |
|---|---|
| Terminal menu 1 | Using the top menu to access Seed7 code browsing inside a terminal Emacs. |
| Terminal menu 2 | The selecting the Seed7 item as a second step in the menu using a terminal Emacs. |
| GUI Emacs menu | Using macOS GUI Emacs with iMenu to list the functions is the Seed7 file. Unlike Windows and most Linux desktops, the Emacs menu shows up inside the macOS top screen menu by default but it's also possible to make it show inside the Emacs frame as the next screen captures show. |
| Navigation to structure menu | The menu can be opened inside the frame
explicitly with the menu-bar-open
command. Here it is showing the
navigation listing the structures
declared inside prg/bas.sd7 |
| Comments menu | The comments-specific commands. |
| Align commands menu | The align commands. Note that the key bindings shown are the ones provided by PEL alignment command support (see PEL align PDF). |
| Template insertion menu | The template insertion commands.
These can be expanded easily with
<TAB>
as described in the
Code Template Insertion
section. |
- Support Emacs imenu mode and Emacs Speedbar for:
- Seed7 procedures,
- Seed7 functions,
- Seed7 interfaces,
- Seed7 structures,
- Seed7 enums.
See the following example screenshots:
| Screenshot | Description |
|---|---|
| Terminal Emacs Speedbar | Using Emacs Speedbar to navigate the Seed7/pgm directory, listing function, procedures, structures, etc... |
| GUI Emacs Speedbar | Using macOS GUI Emacs with Speedbar in a separate GUI frame showing beside the local instance of the PEL Speedbar PDF. |
| GUI Emacs menu | Using macOS GUI Emacs with iMenu to list the functions is the Seed7 file. Unlike Windows and most Linux desktops, the Emacs menu shows up inside the macOS top screen menu. |
| Terminal menu 1 | Using the top menu to access Seed7 code browsing inside a terminal Emacs. |
| Terminal menu 2 | The selecting the Seed7 item as a second step in the menu using a terminal Emacs. |
| Terminal Ivy prompt | Instead of using the menu, using a prompt with completion driven by ivy to search and select Seed7 element. Shown inside a terminal Emacs. |
Automatic code indentation is enabled by default in seed7-mode buffers and is
performed when the <return> key is pressed and when the <tab> key is
pressed, unless point follows one of the pre-defined template insertion
identifier keywords (listed in the Code Template Insertion sections).
To indent, you can press the <tab> key from anywhere on the line.
The auto-fill mode is supported.
The following commands and key bindings are specialized for Seed7 code.
| . | Function | Key Binding | Description |
|---|---|---|---|
| . | seed7-complete-statement-or-indent | <tab> |
If point is after one of the Seed7 keywords supported by the Code Template Insertion the command expands the corresponding code template . If point is anywhere on the line and not after such a keyword, the command re-indents the current block. If the current block is a statement block it indents that. If the block is a complete function, procedure, structure or similar construct it indents the entire block, regardless of point position inside that block. If point was at the beginning of the line, the command leaves point at the indentation. If point was inside the line of code, the command leaves point at the same relative position in the code. |
| . | seed7-indent-block | C-M-q |
Re-indent the current block of code. Does not move point relative to the code. |
| . | seed7-fill | M-q |
If point is inside a comment or a string, the command fill and justify the current paragraph. If point is inside code, it re-indent the current block of code. |
The following customizable user-option variables control Seed7 code indentation.
| . | Variable | Purpose |
|---|---|---|
| . | seed7-auto-indent | Control whether auto-indentation of Seed7 code is active.
|
| . | seed7-indent-width | Number of columns used for each indentation level of Seed7 code. Defaults to 2. |
| . | indent-tabs-mode | Control whether Emacs inserts ASCII hard TAB characters when indenting. If set to nil Emacs will only use ASCII SPACE characters. If active (set to T or any non-nil value) Emacs will insert ASCII hard TAB character to fill indentation according to the number of columns of indentation required and the number of columns used to render a hard tab (as specified by tab-width). For Seed7 code, the convention is to avoid hard TAB characters in the code, therefore the indent-tab-mode should be turned off to prevent seed7-mode auto-indentation to insert hard TAB characters. Use the untabify command to replace all hard TAB characters in the buffer by the equivalent number of SPACE characters. |
| . | tab-width | Controls the the column width of a hard TAB on display. |
Notes:
- One aspect of the auto indentation logic is that it checks (and extracts) the name of procedure and functions and the return type of the function. The auto-indentation will only work properly once these are identified. This acts as a reminder to fill in the missing parts.
- 🚧 As this code is still under early development please report any problem you may encounter.
Seed7 code templates are inserted at point when the <tab> key is pressed
after one of the supported code identifier keywords under specific
constraints:
- When point is following one of the keywords from the first group and that is the only word on the current line, or
- when point is following one of the keywords of the second group and is
located just before a
)character (with or without a space between point and the closing parenthesis. The second group holds keywords for argument declarations.
After successfully expanding the Seed7 code template, point is located at the
first location that must be filled. This location, and the following
locations that must be filled, are internally identified
by Emacs tempo markers. You can use the tempo-forward-mark and
tempo-backward-mark to move point to these markers. The seed7-mode
keyboard map binds the <backtab> key to the tempo-forward-mark
command. So after expanding a code template, fill the first field and then
press <backtab> to move point to the next field.
As mentioned above there are two groups of keywords, listed in the following tables.
Expand the following keywords when point is located just after any of these keywords, with the keyword being the only word on the current line.
| Keyword | Expansion |
|---|---|
| inc | include statement |
| const | constant declaration |
| var | variable declaration |
| . | |
| proc | procedure declaration |
| func | function declaration |
| funcs | short function declaration |
| . | |
| enum | enum type declaration |
| struct | struct type declaration |
| . | |
| case | case statement |
| if | if statement |
| ife | if statement with an else clause |
| ifei | if statement with an elsif clause |
| ifeie | if statement with an elsif and an else clause |
| repeat | repeat - until statement |
| while | while statement |
| for | for statement |
| foru | for-until statement |
| fors | for-step statement |
| fore | for-each statement |
| foreu | for-each statement combined with an until condition |
| forek | for-each-key statement |
| foreku | for-each-key statement combined with an until condition |
| fork | for-key statement |
| forku | for-key statement combined with an until condition |
| . | |
| bl | Exception handler block |
| gl | global - end global block. |
Expand the following keywords with <tab> when point is located just after
any of these keywords and before the closing parenthesis of a parameter list.
| Keyword | Expansion |
|---|---|
| in | Declaration of an in-parameter. |
| inout | Declaration of an inout-parameter. |
| invar | Declaration of an in-var-parameter. |
| callbn | Declaration of a call-by-name parameter. |
| ref | Declaration of a reference-parameter. |
| val | Declaration of a value-parameter. |
| Ref: | Abbrevs @ Emacs Manual |
|---|---|
| Ref: | Abbrev Concepts |
| Ref: | Examining and Editing Abbrevs |
| PEL Ref: | PEL abbreviation PDF |
By default, the seed7-support-abbrev-mode user-option is on (non-nil). This makes seed7-mode support Seed7-specific abbreviations that can be automatically expanded when the abbrev-mode is active.
With Emacs and seed7-mode you can:
- expand a Seed7 keywords by typing its (system) abbreviation followed by a word-separating
character such as
<space>,<RET>` or ``;and others.- All Seed7 system abbreviations are short mnemonic character sequences
that start with
;.
- All Seed7 system abbreviations are short mnemonic character sequences
that start with
- Dynamically enable or disable the
abbrev-modewith theM-x abbrev-modecommand. - List the abbreviations with
M-x list-abbrevs. - Create other abbreviations and edit them with
M-x edit-abbrevs. - Change all Seed7 system abbreviations via customization, but
not dynamically via the abbrev command as you can for other abbreviations.
- The Seed7 system abbreviations are seed7-abbreviations customizable user-options.
- Create your own abbreviations via the abbrev mode commands to complement what is provided by seed7-mode.
While abbrev-mode is active, you can explicitly prevent expansion of the
keyword type C-q after the keyword before any white-space or punctuation
character.
To prevent expansion of Seed7-specific system abbreviations< do the following:
- Change the customization of this user-variable with
M-x customize-option RET seed7-support-abbrev-modeturning it off. - Click or hit return on Apply and Save button to save the customization: the setting will persist across Emacs sessions. It takes effect when the seed7-mode is activated for a buffer.
Note that this will take effect the next time you start Emacs or open a new Seed7 file. To activate it in the current seed7-mode buffer, do the following:
- Change the major mode of the current buffer to
fundamental-mode(by typingM-x fundamental-mode), - Re-activate seed7-mode (by typing
M-x seed7-mode).
The list of default supported abbreviations is controlled by the seed7-abbreviations customizable user-option. You can modify the keyword or the expansion of any entry and add or delete entries these via customization. The new values are activated the next time a buffer starts the seed7-mode.
The default seed7-mode abbreviations are shown inside the 8 following tables:
- Abbreviations for pragmas
- Abbreviations for in-statement keywords
- Abbreviations for in-middle statement keywords
- Abbreviations for block clause keywords
- Abbreviations for predefined types
- Abbreviations for predefined constants
- Abbreviations for predefined variables
- Abbreviations for errinfo values
| Abbreviation | Expansion |
|---|---|
;de |
decls |
;in |
info |
;li |
library |
;msg |
message |
;na |
names |
;syn |
syntax |
;sys |
system |
;tr |
trace |
Meant to follow the is keyword (but not imposed):
| Abbreviation | Expansion |
|---|---|
;fo |
forward |
;n |
new |
;u |
sub |
Others:
| Abbreviation | Expansion |
|---|---|
;no |
noop |
;ra |
raise |
;rt |
return |
| Abbreviation | Expansion |
|---|---|
;dt |
downto |
;exc |
exception |
;lo |
local |
;pa |
param |
;rg |
range |
;rs |
result |
;st |
step |
| Abbreviation | Expansion |
|---|---|
;ct |
catch |
;e |
else |
;ei |
elsif |
;o |
otherwise |
;w |
when |
| Abbreviation | Expansion |
|---|---|
;a |
array |
;bi |
bigInteger |
;br |
bigRational |
;b3 |
bin32 |
;b6 |
bin64 |
;bt |
bitset |
;bo |
boolean |
;bs |
bstring |
;ca |
category |
;c |
char |
;cf |
clib_file |
;co |
color |
;cx |
complex |
;db |
database |
;du |
duration |
;en |
enum |
;ex |
expr |
;fi |
file |
;fs |
fileSys |
;fl |
float |
;h |
hash |
;i |
integer |
;l |
listener |
;ob |
object |
;pd |
pollData |
;pro |
process |
;pr |
program |
;rat |
rational |
;rf |
reference |
;rfl |
ref_list |
;s |
set |
;sq |
sqlStatement |
;sti |
string |
;stu |
struct |
;tx |
text |
;ti |
time |
;ty |
type |
;v |
void |
;pw |
PRIMITIVE_WINDOW |
| Abbreviation | Expansion |
|---|---|
;em |
empty |
;f |
FALSE |
;inf |
Infinity |
;t |
TRUE |
| Abbreviation | Expansion |
|---|---|
;ck |
CONSOLE_KEYBOARD |
;gk |
GRAPH_KEYBOARD |
;kb |
KEYBOARD |
;sc |
STD_CONSOLE |
;se |
STD_ERR |
;si |
STD_IN |
;sn |
STD_NULL |
;so |
STD_OUT |
| Abbreviation | Expansion |
|---|---|
;ok |
OKAY_NO_ERROR |
;ae |
ACTION_ERROR |
;ce |
COPY_ERROR |
;cre |
CREATE_ERROR |
;dbe |
DATABASE_ERROR |
;dse |
DESTROY_ERROR |
;fe |
FILE_ERROR |
;ge |
GRAPHIC_ERROR |
;ie |
INDEX_ERROR |
;ine |
IN_ERROR |
;me |
MEMORY_ERROR |
;ne |
NUMERIC_ERROR |
;oe |
OVERFLOW_ERROR |
;re |
RANGE_ERROR |
| PEL Ref: | PEL align PDF |
|---|
The seed7-mode activates code alignment rules for the following Seed7 code constructs:
- Constant and variable declaration/initialization statements aligning on the
iskeyword. - Assignment statements: align the predefined assignment operators and the code that follows them.
The predefined assignment operators are:
:=,+:=,-:=,*:=,/:=,<<:=,>>:=,&:=,|:=,><:=and@:=.
To align code, select the lines then execute Emacs align command with
M-x align or by typing its key binding.
For example, select the following lines of code:
var float: lastRandomNumber is 0.0;
var integer: screenMode is 0;
var integer: currX is 0;
var integer: currY is 0;
var integer: foreground_color is 0;
var integer: background_color is 0;
var bitmapFont: currentFont is bitmapFont.value;The align command align these variable initialization lines to:
var float: lastRandomNumber is 0.0;
var integer: screenMode is 0;
var integer: currX is 0;
var integer: currY is 0;
var integer: foreground_color is 0;
var integer: background_color is 0;
var bitmapFont: currentFont is bitmapFont.value;It also aligns the following assignment statements from:
begin
start_time := time(NOW);
seconds := trunc(secs);
micro_seconds := round((secs - float(seconds)) * 1000000.0);
await(start_time + seconds . SECONDS + micro_seconds . MICRO_SECONDS);
end func;to:
begin
start_time := time(NOW);
seconds := trunc(secs);
micro_seconds := round((secs - float(seconds)) * 1000000.0);
await(start_time + seconds . SECONDS + micro_seconds . MICRO_SECONDS);
end func;The alignment groups statements to their smallest contiguous groups. For example, if the entire following function (taken from Seed7 prg/bas7.sd7) is selected:
const proc: addDoLoopHeader (in integer: tailLine, in integer: tailColumn,
in integer: headLine, in integer: headColumn) is func
begin
if tailLine in doLoopHeaders then
if tailColumn not in doLoopHeaders[tailLine] then
doLoopHeaders[tailLine] @:= [tailColumn] doLoopDescrType.value;
end if;
else
doLoopHeaders @:= [tailLine] doLoopHeaderInColumn.value;
doLoopHeaders[tailLine] @:= [tailColumn] doLoopDescrType.value;
end if;
doLoopHeaders[tailLine][tailColumn].headLine := headLine;
doLoopHeaders[tailLine][tailColumn].headColumn := headColumn;
end func;executing align on it produces:
const proc: addDoLoopHeader (in integer: tailLine, in integer: tailColumn,
in integer: headLine, in integer: headColumn) is func
begin
if tailLine in doLoopHeaders then
if tailColumn not in doLoopHeaders[tailLine] then
doLoopHeaders[tailLine] @:= [tailColumn] doLoopDescrType.value;
end if;
else
doLoopHeaders @:= [tailLine] doLoopHeaderInColumn.value;
doLoopHeaders[tailLine] @:= [tailColumn] doLoopDescrType.value;
end if;
doLoopHeaders[tailLine][tailColumn].headLine := headLine;
doLoopHeaders[tailLine][tailColumn].headColumn := headColumn;
end func;The supported alignment rules do not allow alignment of every code formats.
Use the align-regexp command to perform other form of text alignment.
| PEL Ref: | PEL Navigation PDF |
|---|
Some of the commands have a built-in key binding in the seed7-key-map but not all of them. The PEL Seed7 support provides more key bindings using function keys.
| . | Function | Key Binding | Description |
|---|---|---|---|
| . | seed7-beg-of-defun | C-M-a |
Move point backward to beginning of function or procedure. With optional repeat argument. |
| . | seed7-end-of-defun | C-M-e |
Move point backward to beginning of function or procedure. With optional repeat argument. |
| . | seed7-beg-of-next-defun | C-c C-n |
Move point forward to beginning of next function or procedure. With optional repeat argument. |
| . | seed7-to-block-forward | C-c C-e |
Move point forward to the end line of the matching statement:
If none is found move to the end of the function or procedure. |
| . | seed7-to-block-backward | C-c C-a |
Move point backward to the beginning line of the matching block or statement (listed above). |
| . | seed7-to-top-of-block | C-c C-t |
Move point to the top of the current outer block: the beginning of the current function, procedure, struct, enum, array, set. |
Note that when issuing the seed7-end-of-defun or seed7-to-block-forward
command from the end of a procedure or function moves the point to the end of
the next function or procedure if there is one. Issuing the
seed7-end-of-defun or seed7-to-block-backward from the beginning of a
function or procedure moves the point to the beginning of the previous
function or procedure if there is one. This is only true for function and
procedures (the commands do not try to find the next array for instance).
| PEL Ref: | PEL xref PDF |
|---|
The seed7-mode supports Emacs xref framework supports:
Searches in the current buffer to find the definition of local variables and constants, and file global variables and constants.
Searches of all program or library identifiers defined in the same file or the library files used by the current file. This includes global functions, procedures, types, variables and constants defined in the current file or library files. That also includes all operators and special operators.
The seed7-mode uses Seed7 compile-time reflectivity to build a cross-reference table automatically by running the supplied s7xref.sd7 Seed7 program; it analyzes all Seed7 files used by the visited file and produces a cross reference table listing all identifiers, operators and special operators accessible to the program.
No other software (such as CTags for instance) is required to provide cross reference for Seed7 code.
The seed7-xref user option identifies the program that should be used to
parse the visited Seed7 file and extract information about all identifiers and
operators used by the Seed7n program or library file. See the seed7-xref
docstring for more information. It defaults to s7 path/to/s7xref.sd7,
where the path is adjusted to the location where the s7xref.sd7 file is
stored. This uses the s7 Seed7 interpreter.
It's also possible to compile the s7xref.sd7 program and
refer to its compiled executable, but using the interpreter is preferred here:
it allows you to update the Seed7 system and continue to use the cross
reference system without having to re-compile s7xref.sd7.
With seed7-xref properly setup, you can use the following xref commands to navigate in Seed7 code.
| . | Function | Key Binding | Description |
|---|---|---|---|
| . | xref-find-definitions | M-. |
Find the definition of the identifier at point. Move point to it if there is only one candidate. If there are several candidates, display the list with the currently active xref front-end. You can then select the appropriate candidate to jump to its code. |
| . | xref-go-back | M-, |
Go back to the previous position in xref history. |
In Seed7 buffers, the seed7-mode implementation supports identification of local and file defined global variables and constants.
- When issuing the xref-find-definitions command over an identifier, the implementation first looks inside the local block. If it is not found it looks into the table built by the s7xref program for the current file. If nothing is found there it looks into the current file.
- When issuing the xref-find-definitions command over any Seed7 keyword, it only looks into the table built by the s7xref program for the current file.
If there are multiple candidates found for the searched identifier, the signature of each found entry is shown in a selection list.
You can use the etags-c-seed7 shell script to build an Emacs-compliant TAGS file for all Seed7 C source code and the C compiler header files. This script uses the etags-c that is part of the PEL package (but can be used without PEL being installed or used). Create the TAGS file and then use Emacs xref cross-reference system to navigate through C code just as you can with Seed7 code with the same xref-find-definitions and xref-go-back commands.
To use etags-c-seed7, put etags-c-seed7 and etags-c inside a
directory that is in your PATH. In a shell, cd to the root of your Seed7
repository and issue the etags-c-seed7 command from it. The command will
create a TAGS file in the directory. It will also create a the file
.etags-c-files.txt which lists all C source code files that have been indexed.
See the PEL ⅀ Xref PDF for more information of Emacs native cross reference.
| PEL Ref: | PEL Marking PDF |
|---|
| . | Function | Key Binding | Description |
|---|---|---|---|
| . | seed7-mark-defun | C-M-h |
Mark the current function or procedure. With point between two; mark the next one. |
| . | Function | Key Binding | Description |
|---|---|---|---|
| . | seed7-compile | Static check Seed7 file visited in current buffer. With optional argument compile it. All resulting warning or errors are shown in a compile-mode buffer. |
- The static checking and compilation commands are identified in customizable user options.
- The static checking defaults to
s7checkand the compilation tos7c. - To perform static checking of Seed7 files, compile the s7check.sd7 part of seed7 program examples and use the generated executable.
| PEL Ref: | PEL Comment PDF |
|---|
| . | Function | Key Binding | Description |
|---|---|---|---|
| . | comment-dwim | M-; |
Insert a comment using the current comment style.
|
| . | seed7-toggle-comment-style | C-c ; |
Toggle between comments to line-end and block comments.
|
The seed7-mode is compatible with:
- Emacs 26 and later.
- Emacs comment-dwim command. The recommended key binding for it is
M-; - Emacs which-function-mode, when active shows the name of the current Seed7 function or procedure in the mode line. It also works with Seed7 actions and forward declarations.
- The iedit package that allows selecting variables inside a specific block, function or procedure.
- The expand-region package to quickly select the current word, block, function/procedure.
- Drew Adam's hide-comnt package which provides the hide/show-comments-toggle command to hide or show all comments.
- The smart-dash-mode is quite useful for typing those pesky underscore characters. With this minor mode active just type a dash (easier type than underscore on most keyboards) and it will insert a underscore inside words or symbols and a dash otherwise.
More commands will be implemented.
| Reference: | The Emacs Initialization File |
|---|
Emacs can and will use a user initialization file, init.el if it finds one.
- Emacs looks for the init.el file inside the directory identified by
the user-emacs-directory variable, one of many variable controls Emacs behaviour.
- Emacs looks for the following files, in the following order by default:
~/.emacs~/.emacs.el~/.emacs.d/init.el~.config/emacs/init.el
- Emacs looks for the following files, in the following order by default:
- Once started the name of the Emacs init file is stored inside the value of the user-init-file variable.
- It also stores the name of the Emacs directory inside the user-emacs-directory variable.
Inside Emacs you can see the current value of the above variables by typing the C-h o
followed by the name of the variable. For example:
- Type
C-h o user-emacs-directory RET; that will open a buffer describing the purpose of this variable and show it's current value. It also has a link to the Emacs Lisp code that defines it (which is part of Emacs and you should not modify). - Type
C-h o user-init-fileto show the value of this variable.
The user-emacs-directory identifies the directory where Emacs looks for the init.el file. In Unix-like OS installations it is often set to "~/.emacs.d/". Under Windows it will be located somewhere else.
Changing from ~/.emacs to ~/.emacs.d/init.el
If you have used Emacs default you may be using the ~/.emacs file for your
Emacs init file.
- Using a complete directory to hold your Emacs initialization file and other Emacs related files, like the downloaded packages, your spelling dictionaries, your persistent customization, etc...
- To get Emacs use the
~/.emacs.d/init.elfile instead:- Create the
~/.emacs.ddirectory, - Move your
~/.emacsor~/.emacs.elfile to~/.emacs.d/init.el. - When you restart Emacs, check the value of user-emacs-directory and user-init-file; they should reflect the new location.
- Create the
Make sure your Emacs initialization file is stored inside the ~/.emacs.d
directory and is ~/.emacs.d/init.el. If this is not the case read the
previous section. Once this is done proceed with the following:
1: Create the utils sub-directory to store stand-alone utilities Emacs lisp files like seed7-mode.el. That directory should be located inside the directory identified by Emacs user-emacs-directory:
- Under Unix-like OS, for example, you would normally create the ~/.emacs.d/utils directory.
2: Create the init.el file if it does not exists:
- Emacs user-emacs-directory identifies the directory where the init.el
file should be located.
- Under Unix-like OS, the file is normally ~/.emacs.d/init.el
- Create the file if it does not already exist.
- Emacs user-emacs-directory identifies the directory where the init.el
file should be located.
3: Update init.el: write code to find files in utils and auto-load seed7-mode
- Inside your init.el file, write the following code:
;;; -*-lexical-binding: t; -*- (push (expand-file-name "utils" user-emacs-directory) load-path) (autoload 'seed7-mode "seed7-mode" nil :interactive) (add-to-list 'auto-mode-alist '("\\.s\\(d7\\|7i\\)\\'" . seed7-mode))
- The first line activates lexical-binding. It must be the very first line of the file.
- The other lines can be anywhere, but must be executed (in case you have some conditional logic).
4: Download seed7_mode.el file and copy it in the utils directory
- The utils directory is the one you created above.
5: Download the s7xref.sd7 file and copy it in the utils/tools directory
- The utils directory is the one you created above.
- If the utils/tools sub-directory does not exists, create it.
- The
s7xref.sd7is a short Seed7 program that analyses a Seed7 source code file and creates a cross reference list of all identifiers defined in that file. This program is used by the cross reference support ofseed7-mode.
6: Byte compile seed7-mode.el
- Open Emacs and edit (visit) the seed7-mode.el file located in your utils directory.
- Byte compile it by typing the following command: M-x emacs-lisp-byte-compile-and-load
Byte compiling is not absolutely necessary but it will verify that everything is ok inside the file and will also speed up Emacs startup. Just remember to byte-compile that file every time you modify it, otherwise Emacs will complain that it's using a byte-compile file that is older than the source file.
To update to a later revision,
- Erase the following files from the utils directory where you stored them:
- seed7-mode.el
- seed7-mode.elc
- s7xref.sd7
- Download the new revision of the same files, and store them in the same directories they previously were located.
- Byte-compile the new
seed7-mode.elfile as described in the previous section.
You can also use my PEL Emacs project which deals with all installation and control details of several packages including this seed7-mode.
- First install PEL as described in the PEL manual
- To activate the installation and activation of the seed7-mode package you
must set the PEL user-option for Seed7: pel-use-seed7 to the value
t(which is one of the possible true values in Emacs Lisp).- Once PEL is installed, use the
C-h o pel-use-seed7 RETkey sequence to open the customization buffer to set this user option. Then close Emacs and restart it. PEL will download and install the file in your~/.emacs.d/utilsdirectory. - Open a Seed7 file, PEL provides extra command key bindings for Seed7 under
the
F12key prefix.- See the PEL Seed7 PDF for more information about PEL Seed7 Support.
- The PEL Index PDF has links to several other PDF files on various Emacs-specific topics.
- Once PEL is installed, use the
With PEL, updating is a little simpler:
just delete your ~/.emacs.d/utils/seed7-mode.* and
~/.emacs.d/utils/tools/s7xref.sd7 files and restart Emacs;
it will download the new version of the files and byte-compile seed7-mode.el.
Once this code is stable I will add the logic to make it an elpa-compliant Emacs package and probably will include it under MELPA. But the code is not yet ready for that.
Any help, questions, suggestions are welcome!