Find file
Fetching contributors…
Cannot retrieve contributors at this time
5937 lines (5151 sloc) 204 KB
</
;; erlang.el --- Major modes for editing and running Erlang
;; Copyright (C) 1995-1998,2000 Ericsson Telecom AB
;; Copyright (C) 2004 Free Software Foundation, Inc.
;; Author: Anders Lindgren
;; Version: 2.5.4
;; Keywords: erlang, languages, processes
;; Date: 2000-09-11
;; The contents of this file are subject to the Erlang Public License,
;; Version 1.1, (the "License"); you may not use this file except in
;; compliance with the License. You should have received a copy of the
;; Erlang Public License along with this software. If not, it can be
;; retrieved via the world wide web at http://www.erlang.org/.
;; Software distributed under the License is distributed on an "AS IS"
;; basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
;; the License for the specific language governing rights and limitations
;; under the License.
;; The Initial Developer of the Original Code is Ericsson Utvecklings AB.
;; All Rights Reserved.
;; Lars Thorsén's modifications of 2000-06-07 included.
;; The original version of this package was written by Robert Virding.
;;
;; Most skeletons have been written at Ericsson Telecom by
;; magnus@erix.ericsson.se and janne@erix.ericsson.se
;;; Commentary:
;; Introduction:
;; ------------
;;
;; This package provides support for the programming language Erlang.
;; The package provides an editing mode with lots of bells and
;; whistles, compilation support, and it makes it possible for the
;; user to start Erlang shells that run inside Emacs.
;;
;; See the Erlang distribution for full documentation of this package.
;; Installation:
;; ------------
;;
;; Place this file in Emacs load path, byte-compile it, and add the
;; following line to the appropriate init file:
;;
;; (require 'erlang-start)
;;
;; The full documentation contains much more extensive description of
;; the installation procedure.
;; Reporting Bugs:
;; --------------
;;
;; Please send bug reports to the following email address:
;; erlang-bugs@erlang.org
;; or if you have a patch suggestion to:
;; erlang-patches@erlang.org
;; Please state as exactly as possible:
;; - Version number of Erlang Mode (see the menu), Emacs, Erlang,
;; and of any other relevant software.
;; - What the expected result was.
;; - What you did, preferably in a repeatable step-by-step form.
;; - A description of the unexpected result.
;; - Relevant pieces of Erlang code causing the problem.
;; - Personal Emacs customisations, if any.
;;
;; Should the Emacs generate an error, please set the Emacs variable
;; `debug-on-error' to `t'. Repeat the error and enclose the debug
;; information in your bug-report.
;;
;; To set the variable you can use the following command:
;; M-x set-variable RET debug-on-error RET t RET
;;; Code:
;; Variables:
(defconst erlang-version "2.5.4"
"The version number of Erlang mode.")
(defvar erlang-root-dir nil
"The directory where the Erlang system is installed.
The name should not contain the trailing slash.
Should this variable be nil, no manual pages will show up in the
Erlang mode menu.")
(defvar erlang-menu-items '(erlang-menu-base-items
erlang-menu-skel-items
erlang-menu-shell-items
erlang-menu-compile-items
erlang-menu-man-items
erlang-menu-personal-items
erlang-menu-version-items)
"*List of menu item list to combine to create Erlang mode menu.
External programs which temporarily add menu items to the Erlang mode
menu may use this variable. Please use the function `add-hook' to add
items.
Please call the function `erlang-menu-init' after every change to this
variable.")
(defvar erlang-menu-base-items
'(("Indent"
(("Indent Line" erlang-indent-command)
("Indent Region " erlang-indent-region
(if erlang-xemacs-p (mark) mark-active))
("Indent Clause" erlang-indent-clause)
("Indent Function" erlang-indent-function)
("Indent Buffer" erlang-indent-current-buffer)))
("Edit"
(("Fill Comment" erlang-fill-paragraph)
("Comment Region" comment-region
(if erlang-xemacs-p (mark) mark-active))
("Uncomment Region" erlang-uncomment-region
(if erlang-xemacs-p (mark) mark-active))
nil
("Beginning of Function" erlang-beginning-of-function)
("End of Function" erlang-end-of-function)
("Mark Function" erlang-mark-function)
nil
("Beginning of Clause" erlang-beginning-of-clause)
("End of Clause" erlang-end-of-clause)
("Mark Clause" erlang-mark-clause)
nil
("New Clause" erlang-generate-new-clause)
("Clone Arguments" erlang-clone-arguments)
nil
("Align Arrows" erlang-align-arrows)))
("Syntax Highlighting"
(("Level 3" erlang-font-lock-level-3)
("Level 2" erlang-font-lock-level-2)
("Level 1" erlang-font-lock-level-1)
("Off" erlang-font-lock-level-0)))
("TAGS"
(("Find Tag" find-tag)
("Find Next Tag" erlang-find-next-tag)
;("Find Regexp" find-tag-regexp)
("Complete Word" erlang-complete-tag)
("Tags Apropos" tags-apropos)
("Search Files" tags-search))))
"Description of menu used in Erlang mode.
This variable must be a list. The elements are either nil representing
a horizontal line or a list with two or three elements. The first is
the name of the menu item, the second is the function to call, or a
submenu, on the same same form as ITEMS. The third optional argument
is an expression which is evaluated every time the menu is displayed.
Should the expression evaluate to nil the menu item is ghosted.
Example:
'((\"Func1\" function-one)
(\"SubItem\"
((\"Yellow\" function-yellow)
(\"Blue\" function-blue)))
nil
(\"Region Function\" spook-function midnight-variable))
Call the function `erlang-menu-init' after modifying this variable.")
(defvar erlang-menu-shell-items
'(nil
("Shell"
(("Start New Shell" erlang-shell)
("Display Shell" erlang-shell-display))))
"Description of the Shell menu used by Erlang mode.
Please see the documentation of `erlang-menu-base-items'.")
(defvar erlang-menu-compile-items
'(("Compile"
(("Compile Buffer" erlang-compile)
("Display Result" erlang-compile-display)
("Next Error" erlang-next-error))))
"Description of the Compile menu used by Erlang mode.
Please see the documentation of `erlang-menu-base-items'.")
(defvar erlang-menu-version-items
'(nil
("Version" erlang-version))
"Description of the version menu used in Erlang mode.")
(defvar erlang-menu-personal-items nil
"Description of personal menu items used in Erlang mode.
Please see the variable `erlang-menu-base-items' for a description
of the format.")
(defvar erlang-menu-man-items nil
"The menu containing man pages.
The format of the menu should be compatible with `erlang-menu-base-items'.
This variable is added to the list of Erlang menus stored in
`erlang-menu-items'.")
(defvar erlang-menu-skel-items '()
"Description of the menu containing the skeleton entries.
The menu is in the form described by the variable `erlang-menu-base-items'.")
(defvar erlang-mode-hook nil
"*Functions to run when Erlang mode is activated.
This hook is used to change the behaviour of Erlang mode. It is
normally used by the user to personalise the programming environment.
When used in a site init file, it could be used to customise Erlang
mode for all users on the system.
The functions added to this hook are run every time Erlang mode is
started. See also `erlang-load-hook', a hook which is run once,
when Erlang mode is loaded into Emacs, and `erlang-shell-mode-hook'
which is run every time a new inferior Erlang shell is started.
To use a hook, create an Emacs lisp function to perform your actions
and add the function to the hook by calling `add-hook'.
The following example binds the key sequence C-c C-c to the command
`erlang-compile' (normally bound to C-c C-k). The example also
activates Font Lock mode to fontify the buffer and adds a menu
containing all functions defined in the current buffer.
To use the example, copy the following lines to your `~/.emacs' file:
(add-hook 'erlang-mode-hook 'my-erlang-mode-hook)
(defun my-erlang-mode-hook ()
(local-set-key \"\\C-c\\C-c\" 'erlang-compile)
(if window-system
(progn
(setq font-lock-maximum-decoration t)
(font-lock-mode 1)))
(if (and window-system (fboundp 'imenu-add-to-menubar))
(imenu-add-to-menubar \"Imenu\")))")
(defvar erlang-load-hook nil
"*Functions to run when Erlang mode is loaded.
This hook is used to change the behaviour of Erlang mode. It is
normally used by the user to personalise the programming environment.
When used in a site init file, it could be used to customize Erlang
mode for all users on the system.
The difference between this hook and `erlang-mode-hook' and
`erlang-shell-mode-hook' is that the functions in this hook
is only called once, when the Erlang mode is loaded into Emacs
the first time.
Natural actions for the functions added to this hook are actions which
only should be performed once, and actions which should be performed
before starting Erlang mode. For example, a number of variables are
used by Erlang mode before `erlang-mode-hook' is run.
The following example sets the variable `erlang-root-dir' so that the
manual pages can be retrieved (note that you must set the value of
`erlang-root-dir' to match the location of Erlang on your system):
(add-hook 'erlang-load-hook 'my-erlang-load-hook)
(defun my-erlang-load-hook ()
(setq erlang-root-dir \"/usr/local/erlang\"))")
(defvar erlang-new-file-hook nil
"Functions to run when a new Erlang source file is being edited.
A useful function is `tempo-template-erlang-normal-header'.
\(This function only exists when the `tempo' package is available.)")
(defvar erlang-check-module-name 'ask
"*Non-nil means check that module name and file name agrees when saving.
If the value of this variable is the atom `ask', the user is
prompted. If the value is t the source is silently changed.")
(defvar erlang-electric-commands
'(erlang-electric-comma
erlang-electric-semicolon
erlang-electric-gt)
"*List of activated electric commands.
The list should contain the electric commands which should be active.
Currently, the available electric commands are:
`erlang-electric-comma'
`erlang-electric-semicolon'
`erlang-electric-gt'
`erlang-electric-newline'
Should the variable be bound to t, all electric commands
are activated.
To deactivate all electric commands, set this variable to nil.")
(defvar erlang-electric-newline-inhibit t
"*Set to non-nil to inhibit newline after electric command.
This is useful since a lot of people press return after executing an
electric command.
In order to work, the command must also be in the
list `erlang-electric-newline-inhibit-list'.
Note that commands in this list are required to set the variable
`erlang-electric-newline-inhibit' to nil when the newline shouldn't be
inhibited.")
(defvar erlang-electric-newline-inhibit-list
'(erlang-electric-semicolon
erlang-electric-comma
erlang-electric-gt)
"*Commands which can inhibit the next newline.")
(defvar erlang-electric-semicolon-insert-blank-lines nil
"*Number of blank lines inserted before header, or nil.
This variable controls the behaviour of `erlang-electric-semicolon'
when a new function header is generated. When nil, no blank line is
inserted between the current line and the new header. When bound to a
number it represents the number of blank lines which should be
inserted.")
(defvar erlang-electric-semicolon-criteria
'(erlang-next-lines-empty-p
erlang-at-keyword-end-p
erlang-at-end-of-function-p)
"*List of functions controlling `erlang-electric-semicolon'.
The functions in this list are called, in order, whenever a semicolon
is typed. Each function in the list is called with no arguments,
and should return one of the following values:
nil -- no determination made, continue checking
'stop -- do not create prototype for next line
(anything else) -- insert prototype, and stop checking
If every function in the list is called with no determination made,
then no prototype is inserted.
The test is performed by the function `erlang-test-criteria-list'.")
(defvar erlang-electric-comma-criteria
'(erlang-stop-when-inside-argument-list
erlang-stop-when-at-guard
erlang-next-lines-empty-p
erlang-at-keyword-end-p
erlang-at-end-of-function-p)
"*List of functions controlling `erlang-electric-comma'.
The functions in this list are called, in order, whenever a comma
is typed. Each function in the list is called with no arguments,
and should return one of the following values:
nil -- no determination made, continue checking
'stop -- do not create prototype for next line
(anything else) -- insert prototype, and stop checking
If every function in the list is called with no determination made,
then no prototype is inserted.
The test is performed by the function `erlang-test-criteria-list'.")
(defvar erlang-electric-arrow-criteria
'(erlang-next-lines-empty-p
erlang-at-end-of-function-p)
"*List of functions controlling the arrow aspect of `erlang-electric-gt'.
The functions in this list are called, in order, whenever a `>'
is typed. Each function in the list is called with no arguments,
and should return one of the following values:
nil -- no determination made, continue checking
'stop -- do not create prototype for next line
(anything else) -- insert prototype, and stop checking
If every function in the list is called with no determination made,
then no prototype is inserted.
The test is performed by the function `erlang-test-criteria-list'.")
(defvar erlang-electric-newline-criteria
'(t)
"*List of functions controlling `erlang-electric-newline'.
The electric newline commands indents the next line. Should the
current line begin with a comment the comment start is copied to
the newly created line.
The functions in this list are called, in order, whenever a comma
is typed. Each function in the list is called with no arguments,
and should return one of the following values:
nil -- no determination made, continue checking
'stop -- do not create prototype for next line
(anything else) -- trigger the electric command.
If every function in the list is called with no determination made,
then no prototype is inserted. Should the atom t be a member of the
list, it is treated as a function triggering the electric command.
The test is performed by the function `erlang-test-criteria-list'.")
(defvar erlang-next-lines-empty-threshold 2
"*Number of blank lines required to activate an electric command.
Actually, this value controls the behaviour of the function
`erlang-next-lines-empty-p' which normally is a member of the
criteria lists controlling the electric commands. (Please see
the variables `erlang-electric-semicolon-criteria' and
`erlang-electric-comma-criteria'.)
The variable is bound to a threshold value, a number, representing the
number of lines which must be empty.
Setting this variable to zero, electric commands will always be
triggered by `erlang-next-lines-empty-p', unless inhibited by other
rules.
Should this variable be nil, `erlang-next-lines-empty-p' will never
trigger an electric command. The same effect would be reached if the
function `erlang-next-lines-empty-p' would be removed from the criteria
lists.
Note that even if `erlang-next-lines-empty-p' should not trigger an
electric command, other functions in the criteria list could.")
(defvar erlang-new-clause-with-arguments nil
"*Non-nil means that the arguments are cloned when a clause is generated.
A new function header can be generated by calls to the function
`erlang-generate-new-clause' and by use of the electric semicolon.")
(defvar erlang-compile-use-outdir t
"*When nil, go to the directory containing source file when compiling.
This is a workaround for a bug in the `outdir' option of compile. If the
outdir is not in the current load path, Erlang doesn't load the object
module after it has been compiled.
To activate the workaround, place the following in your `~/.emacs' file:
(setq erlang-compile-use-outdir nil)")
(defvar erlang-indent-level 4
"*Indentation of Erlang calls/clauses within blocks.")
(defvar erlang-indent-guard 2
"*Indentation of Erlang guards.")
(defvar erlang-argument-indent 2
"*Indentation of the first argument in a function call.
When nil, indent to the column after the `(' of the
function.")
(defvar erlang-tab-always-indent t
"*Non-nil means TAB in Erlang mode should always re-indent the current line,
regardless of where in the line point is when the TAB command is used.")
(defvar erlang-error-regexp-alist
'(("^\\([^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)[:) \t]" . (1 2)))
"*Patterns for matching Erlang errors.")
(defvar erlang-man-inhibit (eq system-type 'windows-nt)
"Inhibit the creation of the Erlang Manual Pages menu.
The Windows distribution of Erlang does not include man pages, hence
there is no attempt to create the menu.")
(defvar erlang-man-dirs
'(("Man - Commands" "/man/man1" t)
("Man - Modules" "/man/man3" t)
("Man - Files" "/man/man4" t)
("Man - Applications" "/man/man6" t))
"*The man directories displayed in the Erlang menu.
Each item in the list should be a list with three elements, the first
the name of the menu, the second the directory, and the last a flag.
Should the flag the nil, the directory is absolute, should it be non-nil
the directory is relative to the variable `erlang-root-dir'.")
(defvar erlang-man-max-menu-size 20
"*The maximum number of menu items in one menu allowed.")
(defvar erlang-man-display-function 'erlang-man-display
"*Function used to display man page.
The function is called with one argument, the name of the file
containing the man page. Use this variable when the default
function, `erlang-man-display', does not work on your system.")
(eval-and-compile
(defconst erlang-atom-regexp "\\([a-z][a-zA-Z0-9_]*\\|'[^\n']*[^\\]'\\)"
"Regexp which should match an Erlang atom.
The regexp must be surrounded with a pair of regexp parentheses."))
(defconst erlang-atom-regexp-matches 1
"Number of regexp parenthesis pairs in `erlang-atom-regexp'.
This is used to determine parenthesis matches in complex regexps which
contains `erlang-atom-regexp'.")
(defconst erlang-variable-regexp "\\([A-Z_][a-zA-Z0-9_]*\\)"
"Regexp which should match an Erlang variable.
The regexp must be surrounded with a pair of regexp parentheses.")
(defconst erlang-variable-regexp-matches 1
"Number of regexp parenthesis pairs in `erlang-variable-regexp'.
This is used to determine matches in complex regexps which contains
`erlang-variable-regexp'.")
(defvar erlang-defun-prompt-regexp (concat "^" erlang-atom-regexp "\\s *(")
"Regexp which should match beginning of a clause.")
(defvar erlang-file-name-extension-regexp "\\.[eh]rl$"
"*Regexp which should match an Erlang file name.
This regexp is used when an Erlang module name is extracted from the
name of an Erlang source file.
The regexp should only match the section of the file name which should
be excluded from the module name.
To match all files set this variable to \"\\\\(\\\\..*\\\\|\\\\)$\".
The matches all except the extension. This is useful if the Erlang
tags system should interpret tags on the form `module:tag' for
files written in other languages than Erlang.")
(defvar erlang-mode-map nil
"*Keymap used in Erlang mode.")
(defvar erlang-mode-abbrev-table nil
"Abbrev table in use in Erlang-mode buffers.")
(defvar erlang-mode-syntax-table nil
"Syntax table in use in Erlang-mode buffers.")
(defconst erlang-emacs-major-version
(if (boundp 'emacs-major-version)
emacs-major-version
(string-match "\\([0-9]+\\)\\.\\([0-9]+\\)" emacs-version)
(string-to-int (substring emacs-version
(match-beginning 1) (match-end 1))))
"Major version number of Emacs.")
(defconst erlang-emacs-minor-version
(if (boundp 'emacs-minor-version)
emacs-minor-version
(string-match "\\([0-9]+\\)\\.\\([0-9]+\\)" emacs-version)
(string-to-int (substring emacs-version
(match-beginning 2) (match-end 2))))
"Minor version number of Emacs.")
(defconst erlang-xemacs-p (string-match "Lucid\\|XEmacs" emacs-version)
"Non-nil when running under XEmacs or Lucid Emacs.")
(defvar erlang-xemacs-popup-menu '("Erlang Mode Commands" . nil)
"Common popup menu for all buffers in Erlang mode.
This variable is destructively modified every time the Erlang menu
is modified. The effect is that all changes take effect in all
buffers in Erlang mode, just like under GNU Emacs.
Never EVER set this variable!")
(defconst inferior-erlang-use-cmm (boundp 'minor-mode-overriding-map-alist)
"Non-nil means use `compilation-minor-mode' in Erlang shell.")
;; Tempo skeleton templates:
(defvar erlang-skel
'(("If" "if" erlang-skel-if)
("Case" "case" erlang-skel-case)
("Receive" "receive" erlang-skel-receive)
("Receive After" "after" erlang-skel-receive-after)
("Receive Loop" "loop" erlang-skel-receive-loop)
("Module" "module" erlang-skel-module)
("Author" "author" erlang-skel-author)
()
("Small Header" "small-header"
erlang-skel-small-header erlang-skel-header)
("Normal Header" "normal-header"
erlang-skel-normal-header erlang-skel-header)
("Large Header" "large-header"
erlang-skel-large-header erlang-skel-header)
()
("Small Server" "small-server"
erlang-skel-small-server erlang-skel-header)
()
("Application" "application"
erlang-skel-application erlang-skel-header)
("Supervisor" "supervisor"
erlang-skel-supervisor erlang-skel-header)
("supervisor_bridge" "supervisor-bridge"
erlang-skel-supervisor-bridge erlang-skel-header)
("gen_server" "generic-server"
erlang-skel-generic-server erlang-skel-header)
("gen_event" "gen-event"
erlang-skel-gen-event erlang-skel-header)
("gen_fsm" "gen-fsm"
erlang-skel-gen-fsm erlang-skel-header)
("Library module" "gen-lib"
erlang-skel-lib erlang-skel-header)
("Corba callback" "gen-corba-cb"
erlang-skel-corba-callback erlang-skel-header)
("Erlang test suite TS frontend" "ts-test-suite"
erlang-skel-ts-test-suite erlang-skel-header)
("Erlang test suite CT frontend" "ct-test-suite"
erlang-skel-ct-test-suite erlang-skel-header)
)
"*Description of all skeleton templates.
Both functions and menu entries will be created.
Each entry in `erlang-skel' should be a list with three or four
elements, or the empty list.
The first element is the name which shows up in the menu. The second
is the `tempo' identifier (The string \"erlang-\" will be added in
front of it). The third is the skeleton descriptor, a variable
containing `tempo' attributes as described in the function
`tempo-define-template'. The optional fourth elements denotes a
function which should be called when the menu is selected.
Functions corresponding to every template will be created. The name
of the function will be `tempo-template-erlang-X' where `X' is the
tempo identifier as specified in the second argument of the elements
in this list.
A list with zero elements means that the a horizontal line should
be placed in the menu.")
;; In XEmacs `user-mail-address' returns "x@y.z (Foo Bar)" ARGH!
;; What's wrong with that? RFC 822 says it's legal. [sverkerw]
;; This needs to use the customized value. If that's not sane, things like
;; add-log will lose anyhow. Avoid it if there _is_ a paren.
(defvar erlang-skel-mail-address
(if (or (not user-mail-address) (string-match "(" user-mail-address))
(concat (user-login-name) "@"
(or (and (boundp 'mail-host-address)
mail-host-address)
(system-name)))
user-mail-address)
"Mail address of the user.")
;; Expression templates:
(defvar erlang-skel-case
'((erlang-skel-skip-blank) o >
"case " p " of" n> p "_ ->" n> p "ok" n> "end" p)
"*The skeleton of a `case' expression.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-if
'((erlang-skel-skip-blank) o >
"if" n> p " ->" n> p "ok" n> "end" p)
"The skeleton of an `if' expression.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-receive
'((erlang-skel-skip-blank) o >
"receive" n> p "_ ->" n> p "ok" n> "end" p)
"*The skeleton of a `receive' expression.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-receive-after
'((erlang-skel-skip-blank) o >
"receive" n> p "_ ->" n> p "ok" n> "after " p "T ->" n>
p "ok" n> "end" p)
"*The skeleton of a `receive' expression with an `after' clause.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-receive-loop
'(& o "loop(" p ") ->" n> "receive" n> p "_ ->" n>
"loop(" p ")" n> "end.")
"*The skeleton of a simple `receive' loop.
Please see the function `tempo-define-template'.")
;; Attribute templates
(defvar erlang-skel-module
'(& "-module("
(erlang-add-quotes-if-needed (erlang-get-module-from-file-name))
")." n)
"*The skeleton of a `module' attribute.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-author
'(& "-author('" erlang-skel-mail-address "')." n)
"*The skeleton of a `author' attribute.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-vc nil
"*The skeleton template to generate a version control attribute.
The default is to insert nothing. Example of usage:
(setq erlang-skel-vc '(& \"-rcs(\\\"$\Id: $ \\\").\") n)
Please see the function `tempo-define-template'.")
(defvar erlang-skel-export
'(& "-export([" n> "])." n)
"*The skeleton of an `export' attribute.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-import
'(& "%%-import(Module, [Function/Arity, ...])." n)
"*The skeleton of an `import' attribute.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-compile nil
;; '(& "%%-compile(export_all)." n)
"*The skeleton of a `compile' attribute.
Please see the function `tempo-define-template'.")
;; Comment templates.
(defvar erlang-skel-date-function 'erlang-skel-dd-mmm-yyyy
"*Function which returns date string.
Look in the module `time-stamp' for a battery of functions.")
(defvar erlang-skel-copyright-comment '()
"*The template for a copyright line in the header, normally empty.
This variable should be bound to a `tempo' template, for example:
'(& \"%%% Copyright (C) 2000, Yoyodyne, Inc.\" n)
Please see the function `tempo-define-template'.")
(defvar erlang-skel-created-comment
'(& "%%% Created : " (funcall erlang-skel-date-function) " by "
(user-full-name) " <" erlang-skel-mail-address ">" n)
"*The template for the \"Created:\" comment line.")
(defvar erlang-skel-author-comment
'(& "%%% Author : " (user-full-name) " <" erlang-skel-mail-address ">" n)
"*The template for creating the \"Author:\" line in the header.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-file-comment
'(& "%%% File : " (file-name-nondirectory buffer-file-name) n)
"*The template for creating the \"Module:\" line in the header.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-small-header
'(o (erlang-skel-include erlang-skel-module)
;; erlang-skel-author)
n
(erlang-skel-include erlang-skel-compile
;; erlang-skel-export
erlang-skel-vc))
"*The template of a small header without any comments.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-normal-header
'(o (erlang-skel-include erlang-skel-copyright-comment
erlang-skel-file-comment
erlang-skel-author-comment)
"%%% Description : " p n
(erlang-skel-include erlang-skel-created-comment) n
(erlang-skel-include erlang-skel-small-header) n)
"*The template of a normal header.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-large-header
'(o (erlang-skel-separator)
(erlang-skel-include erlang-skel-copyright-comment
erlang-skel-file-comment
erlang-skel-author-comment)
"%%% Description : " p n
"%%%" n
(erlang-skel-include erlang-skel-created-comment)
(erlang-skel-separator)
(erlang-skel-include erlang-skel-small-header) )
"*The template of a large header.
Please see the function `tempo-define-template'.")
;; Server templates.
(defvar erlang-skel-small-server
'((erlang-skel-include erlang-skel-large-header)
"-export([start/0,init/1])." n n n
"start() ->" n> "spawn(" (erlang-get-module-from-file-name)
", init, [self()])." n n
"init(From) ->" n>
"loop(From)." n n
"loop(From) ->" n>
"receive" n>
p "_ ->" n>
"loop(From)" n>
"end."
)
"*Template of a small server.
Please see the function `tempo-define-template'.")
;; Behaviour templates.
(defvar erlang-skel-application
'((erlang-skel-include erlang-skel-large-header)
"-behaviour(application)." n n
"%% Application callbacks" n
"-export([start/2, stop/1])." n n
(erlang-skel-double-separator 2)
"%% Application callbacks" n
(erlang-skel-double-separator 2)
(erlang-skel-separator 2)
"%% Function: start(Type, StartArgs) -> {ok, Pid} |" n
"%% {ok, Pid, State} |" n
"%% {error, Reason}" n
"%% Description: This function is called whenever an application " n
"%% is started using application:start/1,2, and should start the processes" n
"%% of the application. If the application is structured according to the" n
"%% OTP design principles as a supervision tree, this means starting the" n
"%% top supervisor of the tree." n
(erlang-skel-separator 2)
"start(_Type, StartArgs) ->" n>
"case 'TopSupervisor':start_link(StartArgs) of" n>
"{ok, Pid} -> " n>
"{ok, Pid};" n>
"Error ->" n>
"Error" n>
"end." n
n
(erlang-skel-separator 2)
"%% Function: stop(State) -> void()" n
"%% Description: This function is called whenever an application" n
"%% has stopped. It is intended to be the opposite of Module:start/2 and" n
"%% should do any necessary cleaning up. The return value is ignored. "n
(erlang-skel-separator 2)
"stop(_State) ->" n>
"ok." n
n
(erlang-skel-double-separator 2)
"%% Internal functions" n
(erlang-skel-double-separator 2)
)
"*The template of an application behaviour.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-supervisor
'((erlang-skel-include erlang-skel-large-header)
"-behaviour(supervisor)." n n
"%% API" n
"-export([start_link/0])." n n
"%% Supervisor callbacks" n
"-export([init/1])." n n
"-define(SERVER, ?MODULE)." n n
(erlang-skel-double-separator 2)
"%% API functions" n
(erlang-skel-double-separator 2)
(erlang-skel-separator 2)
"%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}" n
"%% Description: Starts the supervisor" n
(erlang-skel-separator 2)
"start_link() ->" n>
"supervisor:start_link({local, ?SERVER}, ?MODULE, [])." n
n
(erlang-skel-double-separator 2)
"%% Supervisor callbacks" n
(erlang-skel-double-separator 2)
(erlang-skel-separator 2)
"%% Func: init(Args) -> {ok, {SupFlags, [ChildSpec]}} |" n
"%% ignore |" n
"%% {error, Reason}" n
"%% Description: Whenever a supervisor is started using "n
"%% supervisor:start_link/[2,3], this function is called by the new process "n
"%% to find out about restart strategy, maximum restart frequency and child "n
"%% specifications." n
(erlang-skel-separator 2)
"init([]) ->" n>
"AChild = {'AName',{'AModule',start_link,[]}," n>
"permanent,2000,worker,['AModule']}," n>
"{ok,{{one_for_all,0,1}, [AChild]}}." n
n
(erlang-skel-double-separator 2)
"%% Internal functions" n
(erlang-skel-double-separator 2)
)
"*The template of an supervisor behaviour.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-supervisor-bridge
'((erlang-skel-include erlang-skel-large-header)
"-behaviour(supervisor_bridge)." n n
"%% API" n
"-export([start_link/0])." n n
"%% supervisor_bridge callbacks" n
"-export([init/1, terminate/2])." n n
"-define(SERVER, ?MODULE)." n n
"-record(state, {})." n n
(erlang-skel-double-separator 2)
"%% API" n
(erlang-skel-double-separator 2)
(erlang-skel-separator 2)
"%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}" n
"%% Description: Starts the supervisor bridge" n
(erlang-skel-separator 2)
"start_link() ->" n>
"supervisor_bridge:start_link({local, ?SERVER}, ?MODULE, [])." n
n
(erlang-skel-double-separator 2)
"%% supervisor_bridge callbacks" n
(erlang-skel-double-separator 2)
(erlang-skel-separator 2)
"%% Funcion: init(Args) -> {ok, Pid, State} |" n
"%% ignore |" n
"%% {error, Reason} " n
"%% Description:Creates a supervisor_bridge process, linked to the calling" n
"%% process, which calls Module:init/1 to start the subsystem. To ensure a" n
"%% synchronized start-up procedure, this function does not return until" n
"%% Module:init/1 has returned. " n
(erlang-skel-separator 2)
"init([]) ->" n>
"case 'AModule':start_link() of" n>
"{ok, Pid} ->" n>
"{ok, Pid, #state{}};" n>
"Error ->" n>
"Error" n>
"end." n
n
(erlang-skel-separator 2)
"%% Func: terminate(Reason, State) -> void()" n
"%% Description:This function is called by the supervisor_bridge when it is"n
"%% about to terminate. It should be the opposite of Module:init/1 and stop"n
"%% the subsystem and do any necessary cleaning up.The return value is ignored."
(erlang-skel-separator 2)
"terminate(Reason, State) ->" n>
"'AModule':stop()," n>
"ok." n
n
(erlang-skel-double-separator 2)
"%% Internal functions" n
(erlang-skel-double-separator 2)
)
"*The template of an supervisor_bridge behaviour.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-generic-server
'((erlang-skel-include erlang-skel-large-header)
"-behaviour(gen_server)." n n
"%% API" n
"-export([start_link/0])." n n
"%% gen_server callbacks" n
"-export([init/1, handle_call/3, handle_cast/2, "
"handle_info/2," n>
"terminate/2, code_change/3])." n n
"-record(state, {})." n n
(erlang-skel-double-separator 2)
"%% API" n
(erlang-skel-double-separator 2)
(erlang-skel-separator 2)
"%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}" n
"%% Description: Starts the server" n
(erlang-skel-separator 2)
"start_link() ->" n>
"gen_server:start_link({local, ?SERVER}, ?MODULE, [], [])." n
n
(erlang-skel-double-separator 2)
"%% gen_server callbacks" n
(erlang-skel-double-separator 2)
n
(erlang-skel-separator 2)
"%% Function: init(Args) -> {ok, State} |" n
"%% {ok, State, Timeout} |" n
"%% ignore |" n
"%% {stop, Reason}" n
"%% Description: Initiates the server" n
(erlang-skel-separator 2)
"init([]) ->" n>
"{ok, #state{}}." n
n
(erlang-skel-separator 2)
"%% Function: "
"%% handle_call(Request, From, State) -> {reply, Reply, State} |" n
"%% {reply, Reply, State, Timeout} |" n
"%% {noreply, State} |" n
"%% {noreply, State, Timeout} |" n
"%% {stop, Reason, Reply, State} |" n
"%% {stop, Reason, State}" n
"%% Description: Handling call messages" n
(erlang-skel-separator 2)
"handle_call(_Request, _From, State) ->" n>
"Reply = ok," n>
"{reply, Reply, State}." n
n
(erlang-skel-separator 2)
"%% Function: handle_cast(Msg, State) -> {noreply, State} |" n
"%% {noreply, State, Timeout} |" n
"%% {stop, Reason, State}" n
"%% Description: Handling cast messages" n
(erlang-skel-separator 2)
"handle_cast(_Msg, State) ->" n>
"{noreply, State}." n
n
(erlang-skel-separator 2)
"%% Function: handle_info(Info, State) -> {noreply, State} |" n
"%% {noreply, State, Timeout} |" n
"%% {stop, Reason, State}" n
"%% Description: Handling all non call/cast messages" n
(erlang-skel-separator 2)
"handle_info(_Info, State) ->" n>
"{noreply, State}." n
n
(erlang-skel-separator 2)
"%% Function: terminate(Reason, State) -> void()" n
"%% Description: This function is called by a gen_server when it is about to"n
"%% terminate. It should be the opposite of Module:init/1 and do any necessary"n
"%% cleaning up. When it returns, the gen_server terminates with Reason." n
"%% The return value is ignored." n
(erlang-skel-separator 2)
"terminate(_Reason, _State) ->" n>
"ok." n
n
(erlang-skel-separator 2)
"%% Func: code_change(OldVsn, State, Extra) -> {ok, NewState}" n
"%% Description: Convert process state when code is changed" n
(erlang-skel-separator 2)
"code_change(_OldVsn, State, _Extra) ->" n>
"{ok, State}." n
n
(erlang-skel-separator 2)
"%%% Internal functions" n
(erlang-skel-separator 2)
)
"*The template of a generic server.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-gen-event
'((erlang-skel-include erlang-skel-large-header)
"-behaviour(gen_event)." n
"%% API" n
"-export([start_link/0, add_handler/0])." n n
"%% gen_event callbacks" n
"-export([init/1, handle_event/2, handle_call/2, " n>
"handle_info/2, terminate/2, code_change/3])." n n
"-record(state, {})." n n
(erlang-skel-double-separator 2)
"%% gen_event callbacks" n
(erlang-skel-double-separator 2)
(erlang-skel-separator 2)
"%% Function: start_link() -> {ok,Pid} | {error,Error} " n
"%% Description: Creates an event manager." n
(erlang-skel-separator 2)
"start_link() ->" n>
"gen_event:start_link({local, ?SERVER}). " n
n
(erlang-skel-separator 2)
"%% Function: add_handler() -> ok | {'EXIT',Reason} | term()" n
"%% Description: Adds an event handler" n
(erlang-skel-separator 2)
"add_handler() ->" n>
"gen_event:add_handler(?SERVER, ?MODULE, [])." n
n
(erlang-skel-double-separator 2)
"%% gen_event callbacks" n
(erlang-skel-double-separator 2)
(erlang-skel-separator 2)
"%% Function: init(Args) -> {ok, State}" n
"%% Description: Whenever a new event handler is added to an event manager,"n
"%% this function is called to initialize the event handler." n
(erlang-skel-separator 2)
"init([]) ->" n>
"{ok, #state{}}." n
n
(erlang-skel-separator 2)
"%% Function: "n
"%% handle_event(Event, State) -> {ok, State} |" n
"%% {swap_handler, Args1, State1, Mod2, Args2} |"n
"%% remove_handler" n
"%% Description:Whenever an event manager receives an event sent using"n
"%% gen_event:notify/2 or gen_event:sync_notify/2, this function is called for"n
"%% each installed event handler to handle the event. "n
(erlang-skel-separator 2)
"handle_event(_Event, State) ->" n>
"{ok, State}." n
n
(erlang-skel-separator 2)
"%% Function: " n
"%% handle_call(Request, State) -> {ok, Reply, State} |" n
"%% {swap_handler, Reply, Args1, State1, "n
"%% Mod2, Args2} |" n
"%% {remove_handler, Reply}" n
"%% Description: Whenever an event manager receives a request sent using"n
"%% gen_event:call/3,4, this function is called for the specified event "n
"%% handler to handle the request."n
(erlang-skel-separator 2)
"handle_call(_Request, State) ->" n>
"Reply = ok," n>
"{ok, Reply, State}." n
n
(erlang-skel-separator 2)
"%% Function: " n
"%% handle_info(Info, State) -> {ok, State} |" n
"%% {swap_handler, Args1, State1, Mod2, Args2} |" n
"%% remove_handler" n
"%% Description: This function is called for each installed event handler when"n
"%% an event manager receives any other message than an event or a synchronous"n
"%% request (or a system message)."n
(erlang-skel-separator 2)
"handle_info(_Info, State) ->" n>
"{ok, State}." n
n
(erlang-skel-separator 2)
"%% Function: terminate(Reason, State) -> void()" n
"%% Description:Whenever an event handler is deleted from an event manager,"n
"%% this function is called. It should be the opposite of Module:init/1 and "n
"%% do any necessary cleaning up. " n
(erlang-skel-separator 2)
"terminate(_Reason, _State) ->" n>
"ok." n
n
(erlang-skel-separator 2)
"%% Function: code_change(OldVsn, State, Extra) -> {ok, NewState} " n
"%% Description: Convert process state when code is changed" n
(erlang-skel-separator 2)
"code_change(_OldVsn, State, _Extra) ->" n>
"{ok, State}." n
n
(erlang-skel-separator 2)
"%%% Internal functions" n
(erlang-skel-separator 2)
)
"*The template of a gen_event.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-gen-fsm
'((erlang-skel-include erlang-skel-large-header)
"-behaviour(gen_fsm)." n n
"%% API" n
"-export([start_link/0])." n n
"%% gen_fsm callbacks" n
"-export([init/1, state_name/2, state_name/3, handle_event/3," n>
"handle_sync_event/4, handle_info/3, terminate/3, code_change/4])." n n
"-record(state, {})." n n
(erlang-skel-double-separator 2)
"%% API" n
(erlang-skel-double-separator 2)
(erlang-skel-separator 2)
"%% Function: start_link() -> ok,Pid} | ignore | {error,Error}" n
"%% Description:Creates a gen_fsm process which calls Module:init/1 to"n
"%% initialize. To ensure a synchronized start-up procedure, this function" n
"%% does not return until Module:init/1 has returned. " n
(erlang-skel-separator 2)
"start_link() ->" n>
"gen_fsm:start_link({local, ?SERVER}, ?MODULE, [], [])." n
n
(erlang-skel-double-separator 2)
"%% gen_fsm callbacks" n
(erlang-skel-double-separator 2)
(erlang-skel-separator 2)
"%% Function: init(Args) -> {ok, StateName, State} |" n
"%% {ok, StateName, State, Timeout} |" n
"%% ignore |" n
"%% {stop, StopReason} " n
"%% Description:Whenever a gen_fsm is started using gen_fsm:start/[3,4] or"n
"%% gen_fsm:start_link/3,4, this function is called by the new process to "n
"%% initialize. " n
(erlang-skel-separator 2)
"init([]) ->" n>
"{ok, state_name, #state{}}." n
n
(erlang-skel-separator 2)
"%% Function: "n
"%% state_name(Event, State) -> {next_state, NextStateName, NextState}|" n
"%% {next_state, NextStateName, " n
"%% NextState, Timeout} |" n
"%% {stop, Reason, NewState}" n
"%% Description:There should be one instance of this function for each possible"n
"%% state name. Whenever a gen_fsm receives an event sent using" n
"%% gen_fsm:send_event/2, the instance of this function with the same name as"n
"%% the current state name StateName is called to handle the event. It is also "n
"%% called if a timeout occurs. " n
(erlang-skel-separator 2)
"state_name(_Event, State) ->" n>
"{next_state, state_name, State}." n
n
(erlang-skel-separator 2)
"%% Function:" n
"%% state_name(Event, From, State) -> {next_state, NextStateName, NextState} |"n
"%% {next_state, NextStateName, " n
"%% NextState, Timeout} |" n
"%% {reply, Reply, NextStateName, NextState}|"n
"%% {reply, Reply, NextStateName, " n
"%% NextState, Timeout} |" n
"%% {stop, Reason, NewState}|" n
"%% {stop, Reason, Reply, NewState}" n
"%% Description: There should be one instance of this function for each" n
"%% possible state name. Whenever a gen_fsm receives an event sent using" n
"%% gen_fsm:sync_send_event/2,3, the instance of this function with the same"n
"%% name as the current state name StateName is called to handle the event." n
(erlang-skel-separator 2)
"state_name(_Event, _From, State) ->" n>
"Reply = ok," n>
"{reply, Reply, state_name, State}." n
n
(erlang-skel-separator 2)
"%% Function: " n
"%% handle_event(Event, StateName, State) -> {next_state, NextStateName, "n
"%% NextState} |" n
"%% {next_state, NextStateName, "n
"%% NextState, Timeout} |" n
"%% {stop, Reason, NewState}" n
"%% Description: Whenever a gen_fsm receives an event sent using"n
"%% gen_fsm:send_all_state_event/2, this function is called to handle"n
"%% the event." n
(erlang-skel-separator 2)
"handle_event(_Event, StateName, State) ->" n>
"{next_state, StateName, State}." n
n
(erlang-skel-separator 2)
"%% Function: " n
"%% handle_sync_event(Event, From, StateName, "n
"%% State) -> {next_state, NextStateName, NextState} |" n
"%% {next_state, NextStateName, NextState, " n
"%% Timeout} |" n
"%% {reply, Reply, NextStateName, NextState}|" n
"%% {reply, Reply, NextStateName, NextState, " n
"%% Timeout} |" n
"%% {stop, Reason, NewState} |" n
"%% {stop, Reason, Reply, NewState}" n
"%% Description: Whenever a gen_fsm receives an event sent using"n
"%% gen_fsm:sync_send_all_state_event/2,3, this function is called to handle"n
"%% the event."n
(erlang-skel-separator 2)
"handle_sync_event(Event, From, StateName, State) ->" n>
"Reply = ok," n>
"{reply, Reply, StateName, State}." n
n
(erlang-skel-separator 2)
"%% Function: " n
"%% handle_info(Info,StateName,State)-> {next_state, NextStateName, NextState}|" n
"%% {next_state, NextStateName, NextState, "n
"%% Timeout} |" n
"%% {stop, Reason, NewState}" n
"%% Description: This function is called by a gen_fsm when it receives any"n
"%% other message than a synchronous or asynchronous event"n
"%% (or a system message)." n
(erlang-skel-separator 2)
"handle_info(_Info, StateName, State) ->" n>
"{next_state, StateName, State}." n
n
(erlang-skel-separator 2)
"%% Function: terminate(Reason, StateName, State) -> void()" n
"%% Description:This function is called by a gen_fsm when it is about"n
"%% to terminate. It should be the opposite of Module:init/1 and do any"n
"%% necessary cleaning up. When it returns, the gen_fsm terminates with"n
"%% Reason. The return value is ignored." n
(erlang-skel-separator 2)
"terminate(_Reason, _StateName, _State) ->" n>
"ok." n
n
(erlang-skel-separator 2)
"%% Function:" n
"%% code_change(OldVsn, StateName, State, Extra) -> {ok, StateName, NewState}" n
"%% Description: Convert process state when code is changed" n
(erlang-skel-separator 2)
"code_change(_OldVsn, StateName, State, _Extra) ->" n>
"{ok, StateName, State}." n
n
(erlang-skel-separator 2)
"%%% Internal functions" n
(erlang-skel-separator 2)
)
"*The template of a gen_fsm.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-lib
'((erlang-skel-include erlang-skel-large-header)
"%% API" n
"-export([])." n n
(erlang-skel-double-separator 2)
"%% API" n
(erlang-skel-double-separator 2)
(erlang-skel-separator 2)
"%% Function: " n
"%% Description:" n
(erlang-skel-separator 2)
n
(erlang-skel-double-separator 2)
"%% Internal functions" n
(erlang-skel-double-separator 2)
)
"*The template of a library module.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-corba-callback
'((erlang-skel-include erlang-skel-large-header)
"%% Include files" n n
"%% API" n
"-export([])." n n
"%% Corba callbacks" n
"-export([init/1, terminate/2, code_change/3])." n n
"-record(state, {})." n n
(erlang-skel-double-separator 2)
"%% Corba callbacks" n
(erlang-skel-double-separator 2)
(erlang-skel-separator 2)
"%% Function: init(Args) -> {ok, State} |" n
"%% {ok, State, Timeout} |" n
"%% ignore |" n
"%% {stop, Reason}" n
"%% Description: Initiates the server" n
(erlang-skel-separator 2)
"init([]) ->" n>
"{ok, #state{}}." n
n
(erlang-skel-separator 2)
"%% Function: terminate(Reason, State) -> void()" n
"%% Description: Shutdown the server" n
(erlang-skel-separator 2)
"terminate(_Reason, _State) ->" n>
"ok." n
n
(erlang-skel-separator 2)
"%% Function: code_change(OldVsn, State, Extra) -> {ok, NewState} " n
"%% Description: Convert process state when code is changed" n
(erlang-skel-separator 2)
"code_change(_OldVsn, State, _Extra) ->" n>
"{ok, State}." n
n
(erlang-skel-double-separator 2)
"%% Internal functions" n
(erlang-skel-double-separator 2)
)
"*The template of a library module.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-ts-test-suite
'((erlang-skel-include erlang-skel-large-header)
"%% Note: This directive should only be used in test suites." n
"-compile(export_all)." n n
"-include(\"test_server.hrl\")." n n
(erlang-skel-separator 2)
"%% TEST SERVER CALLBACK FUNCTIONS" n
(erlang-skel-separator 2)
n
(erlang-skel-separator 2)
"%% Function: init_per_suite(Config0) -> Config1 | {skip,Reason}" n
"%%" n
"%% Config0 = Config1 = [tuple()]" n
"%% A list of key/value pairs, holding the test case configuration." n
"%% Reason = term()" n
"%% The reason for skipping the suite." n
"%%" n
"%% Description: Initialization before the suite." n
"%%" n
"%% Note: This function is free to add any key/value pairs to the Config" n
"%% variable, but should NOT alter/remove any existing entries." n
(erlang-skel-separator 2)
"init_per_suite(Config) ->" n >
"Config." n n
(erlang-skel-separator 2)
"%% Function: end_per_suite(Config) -> void()" n
"%%" n
"%% Config = [tuple()]" n
"%% A list of key/value pairs, holding the test case configuration." n
"%%" n
"%% Description: Cleanup after the suite." n
(erlang-skel-separator 2)
"end_per_suite(_Config) ->" n >
"ok." n n
(erlang-skel-separator 2)
"%% Function: init_per_testcase(TestCase, Config0) -> Config1 |" n
"%% {skip,Reason}" n
"%% TestCase = atom()" n
"%% Name of the test case that is about to run." n
"%% Config0 = Config1 = [tuple()]" n
"%% A list of key/value pairs, holding the test case configuration." n
"%% Reason = term()" n
"%% The reason for skipping the test case." n
"%%" n
"%% Description: Initialization before each test case." n
"%%" n
"%% Note: This function is free to add any key/value pairs to the Config" n
"%% variable, but should NOT alter/remove any existing entries." n
(erlang-skel-separator 2)
"init_per_testcase(_TestCase, Config) ->" n >
"Config." n n
(erlang-skel-separator 2)
"%% Function: end_per_testcase(TestCase, Config) -> void()" n
"%%" n
"%% TestCase = atom()" n
"%% Name of the test case that is finished." n
"%% Config = [tuple()]" n
"%% A list of key/value pairs, holding the test case configuration." n
"%%" n
"%% Description: Cleanup after each test case." n
(erlang-skel-separator 2)
"end_per_testcase(_TestCase, _Config) ->" n >
"ok."n n
(erlang-skel-separator 2)
"%% Function: all(Clause) -> Descr | TestCases | {skip,Reason}" n
"%%" n
"%% Clause = doc | suite" n
"%% Indicates expected return value." n
"%% Descr = [string()] | []" n
"%% String that describes the test suite." n
"%% TestCases = [TestCase] " n
"%% TestCase = atom()" n
"%% Name of a test case." n
"%% Reason = term()" n
"%% The reason for skipping the test suite." n
"%%" n
"%% Description: Returns a description of the test suite (doc) and a" n
"%% list of all test cases in the suite (suite)." n
(erlang-skel-separator 2)
"all(doc) -> " n >
"[\"Describe the main purpose of this suite\"];" n n
"all(suite) -> " n >
"[a_test_case]." n n
n
(erlang-skel-separator 2)
"%% TEST CASES" n
(erlang-skel-separator 2)
n
(erlang-skel-separator 2)
"%% Function: TestCase(Arg) -> Descr | Spec | ok | exit() | {skip,Reason}" n
"%%" n
"%% Arg = doc | suite | Config" n
"%% Indicates expected behaviour and return value." n
"%% Config = [tuple()]" n
"%% A list of key/value pairs, holding the test case configuration." n
"%% Descr = [string()] | []" n
"%% String that describes the test case." n
"%% Spec = [tuple()] | []" n
"%% A test specification." n
"%% Reason = term()" n
"%% The reason for skipping the test case." n
"%%" n
"%% Description: Test case function. Returns a description of the test" n
"%% case (doc), then returns a test specification (suite)," n
"%% or performs the actual test (Config)." n
(erlang-skel-separator 2)
"a_test_case(doc) -> " n >
"[\"Describe the main purpose of this test case\"];" n n
"a_test_case(suite) -> " n >
"[];" n n
"a_test_case(Config) when is_list(Config) -> " n >
"ok." n
)
"*The template of a library module.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-ct-test-suite
'((erlang-skel-include erlang-skel-large-header)
"%% Note: This directive should only be used in test suites." n
"-compile(export_all)." n n
"-include(\"ct.hrl\")." n n
(erlang-skel-separator 2)
"%% COMMON TEST CALLBACK FUNCTIONS" n
(erlang-skel-separator 2)
n
(erlang-skel-separator 2)
"%% Function: suite() -> Info" n
"%%" n
"%% Info = [tuple()]" n
"%% List of key/value pairs." n
"%%" n
"%% Description: Returns list of tuples to set default properties" n
"%% for the suite." n
"%%" n
"%% Note: The suite/0 function is only meant to be used to return" n
"%% default data values, not perform any other operations." n
(erlang-skel-separator 2)
"suite() ->" n >
"[{timetrap,{minutes,10}}]." n n
(erlang-skel-separator 2)
"%% Function: init_per_suite(Config0) ->" n
"%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
"%%" n
"%% Config0 = Config1 = [tuple()]" n
"%% A list of key/value pairs, holding the test case configuration." n
"%% Reason = term()" n
"%% The reason for skipping the suite." n
"%%" n
"%% Description: Initialization before the suite." n
"%%" n
"%% Note: This function is free to add any key/value pairs to the Config" n
"%% variable, but should NOT alter/remove any existing entries." n
(erlang-skel-separator 2)
"init_per_suite(Config) ->" n >
"Config." n n
(erlang-skel-separator 2)
"%% Function: end_per_suite(Config0) -> void() | {save_config,Config1}" n
"%%" n
"%% Config0 = Config1 = [tuple()]" n
"%% A list of key/value pairs, holding the test case configuration." n
"%%" n
"%% Description: Cleanup after the suite." n
(erlang-skel-separator 2)
"end_per_suite(_Config) ->" n >
"ok." n n
(erlang-skel-separator 2)
"%% Function: init_per_testcase(TestCase, Config0) ->" n
"%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
"%%" n
"%% TestCase = atom()" n
"%% Name of the test case that is about to run." n
"%% Config0 = Config1 = [tuple()]" n
"%% A list of key/value pairs, holding the test case configuration." n
"%% Reason = term()" n
"%% The reason for skipping the test case." n
"%%" n
"%% Description: Initialization before each test case." n
"%%" n
"%% Note: This function is free to add any key/value pairs to the Config" n
"%% variable, but should NOT alter/remove any existing entries." n
(erlang-skel-separator 2)
"init_per_testcase(_TestCase, Config) ->" n >
"Config." n n
(erlang-skel-separator 2)
"%% Function: end_per_testcase(TestCase, Config0) ->" n
"%% void() | {save_config,Config1}" n
"%%" n
"%% TestCase = atom()" n
"%% Name of the test case that is finished." n
"%% Config0 = Config1 = [tuple()]" n
"%% A list of key/value pairs, holding the test case configuration." n
"%%" n
"%% Description: Cleanup after each test case." n
(erlang-skel-separator 2)
"end_per_testcase(_TestCase, _Config) ->" n >
"ok."n n
(erlang-skel-separator 2)
"%% Function: sequences() -> Sequences" n
"%%" n
"%% Sequences = [{SeqName,TestCases}]" n
"%% SeqName = atom()" n
"%% Name of a sequence." n
"%% TestCases = [atom()]" n
"%% List of test cases that are part of the sequence" n
"%%" n
"%% Description: Specifies test case sequences." n
(erlang-skel-separator 2)
"sequences() -> " n >
"[]." n n
(erlang-skel-separator 2)
"%% Function: all() -> TestCases | {skip,Reason}" n
"%%" n
"%% TestCases = [TestCase | {sequence,SeqName}]" n
"%% TestCase = atom()" n
"%% Name of a test case." n
"%% SeqName = atom()" n
"%% Name of a test case sequence." n
"%% Reason = term()" n
"%% The reason for skipping all test cases." n
"%%" n
"%% Description: Returns the list of test cases that are to be executed." n
(erlang-skel-separator 2)
"all() -> " n >
"[a_test_case]." n n
n
(erlang-skel-separator 2)
"%% TEST CASES" n
(erlang-skel-separator 2)
n
(erlang-skel-separator 2)
"%% Function: TestCase() -> Info" n
"%%" n
"%% Info = [tuple()]" n
"%% List of key/value pairs." n
"%%" n
"%% Description: Test case info function - returns list of tuples to set" n
"%% properties for the test case." n
"%%" n
"%% Note: This function is only meant to be used to return a list of" n
"%% values, not perform any other operations." n
(erlang-skel-separator 2)
"a_test_case() -> " n >
"[]." n n
(erlang-skel-separator 2)
"%% Function: TestCase(Config0) ->" n
"%% ok | exit() | {skip,Reason} | {comment,Comment} |" n
"%% {save_config,Config1} | {skip_and_save,Reason,Config1}" n
"%%" n
"%% Config0 = Config1 = [tuple()]" n
"%% A list of key/value pairs, holding the test case configuration." n
"%% Reason = term()" n
"%% The reason for skipping the test case." n
"%% Comment = term()" n
"%% A comment about the test case that will be printed in the html log." n
"%%" n
"%% Description: Test case function. (The name of it must be specified in" n
"%% the all/0 list for the test case to be executed)." n
(erlang-skel-separator 2)
"a_test_case(Config) -> " n >
"ok." n
)
"*The template of a library module.
Please see the function `tempo-define-template'.")
;; Font-lock variables
(defvar erlang-font-lock-modern-p
(cond ((>= erlang-emacs-major-version 20) t)
(erlang-xemacs-p (>= erlang-emacs-minor-version 14))
((= erlang-emacs-major-version 19) (>= erlang-emacs-minor-version 29))
(t nil))
"Non-nil when this version of Emacs uses a modern version of Font Lock.
This is determined by checking the version of Emacs used, the actual
font-lock code is not loaded.")
;; The next few variables define different Erlang font-lock patterns.
;; They could be appended to form a custom font-lock appearance.
;;
;; The function `erlang-font-lock-set-face' could be used to change
;; the face of a pattern.
;;
;; Note that Erlang strings and atoms are highlighted with using
;; syntactic analysis.
(defvar erlang-font-lock-keywords-func
(list
(list (concat "^" erlang-atom-regexp "\\s *(")
1 'font-lock-function-name-face t))
"Font lock keyword highlighting a function header.")
(defvar erlang-font-lock-keywords-dollar
(list
(list "\\(\\$\\([^\\]\\|\\\\\\([^0-7^\n]\\|[0-7]+\\|\\^[a-zA-Z]\\)\\)\\)"
1 'font-lock-string-face))
"Font lock keyword highlighting numbers in ASCII form (e.g. $A).")
(defvar erlang-font-lock-keywords-arrow
(list
(list "\\(->\\|:-\\)\\(\\s \\|$\\)" 2 'font-lock-function-name-face))
"Font lock keyword highlighting clause arrow.")
(defvar erlang-font-lock-keywords-lc
(list
(list "\\(<-\\)\\(\\s \\|$\\)" 1 'font-lock-keyword-face)
(list "\\(||\\)\\(\\s \\|$\\)" 1 'font-lock-keyword-face))
"Font lock keyword highlighting list comprehension operators.")
(defvar erlang-font-lock-keywords-keywords
(list
(list (concat "\\<\\(a\\(fter\\|ndalso\\)\\|begin\\|c\\(atch\\|ase\\)"
"\\|end\\|fun\\|if\\|o\\(f\\|relse\\)\\|receive\\|try\\|when"
"\\|query\\)\\([^a-zA-Z0-9_]\\|$\\)")
1 'font-lock-keyword-face))
"Font lock keyword highlighting Erlang keywords.")
(defvar erlang-font-lock-keywords-attr
(list
(list (concat "^\\(-" erlang-atom-regexp "\\)\\s *\\(\\.\\|(\\)")
1 'font-lock-function-name-face))
"Font lock keyword highlighting attributes.")
(defvar erlang-font-lock-keywords-quotes
(list
(list "`\\([-+a-zA-Z0-9_:*][-+a-zA-Z0-9_:*]+\\)'"
1
(if erlang-font-lock-modern-p
'font-lock-reference-face
'font-lock-keyword-face)
t))
"Font lock keyword highlighting words in single quotes in comments.
This is not the highlighting of Erlang strings and atoms, which
are highlighted by syntactic analysis.")
;; Note: The guard `float' collides with the bif `float'.
(defvar erlang-font-lock-keywords-guards
(list
(list
(concat "\\<\\("
"\\(is_\\)*\\(atom\\|boolean\\|function\\|binary\\|constant"
"\\|float\\|integer\\|list\\|number\\|p\\(id\\|ort\\)\\|"
"re\\(ference\\|cord\\)\\|tuple"
"\\)\\)\\s *(")
1
(if erlang-font-lock-modern-p
'font-lock-reference-face
'font-lock-keyword-face)))
"Font lock keyword highlighting guards.")
(defvar erlang-font-lock-keywords-bifs
(list
(list
(concat
"\\<\\("
"a\\(bs\\|live\\|pply\\|tom_to_list\\)\\|"
"binary_to_\\(list\\|term\\)\\|"
"concat_binary\\|d\\(ate\\|isconnect_node\\)\\|"
"e\\(lement\\|rase\\|xit\\)\\|"
"float\\(\\|_to_list\\)\\|"
"g\\(arbage_collect\\|et\\(\\|_keys\\)\\|roup_leader\\)\\|"
"h\\(alt\\|d\\)\\|"
"i\\(nte\\(ger_to_list\\|rnal_bif\\)\\|s_alive\\)\\|"
"l\\(ength\\|i\\(nk\\|st_to_\\(atom\\|binary\\|float\\|integer"
"\\|pid\\|tuple\\)\\)\\)\\|"
"make_ref\\|no\\(de\\(\\|_\\(link\\|unlink\\)\\|s\\)\\|talive\\)\\|"
"open_port\\|"
"p\\(id_to_list\\|rocess\\(_\\(flag\\|info\\)\\|es\\)\\|ut\\)\\|"
"r\\(egister\\(\\|ed\\)\\|ound\\)\\|"
"s\\(e\\(lf\\|telement\\)\\|ize\\|"
"p\\(awn\\(\\|_link\\)\\|lit_binary\\)\\|tatistics\\)\\|"
"t\\(erm_to_binary\\|hrow\\|ime\\|l\\|"
"r\\(ace\\|unc\\)\\|uple_to_list\\)\\|"
"un\\(link\\|register\\)\\|whereis"
"\\)\\s *(")
1
'font-lock-keyword-face))
"Font lock keyword highlighting built in functions.")
(defvar erlang-font-lock-keywords-macros
(list
(list (concat "?\\s *\\(" erlang-atom-regexp
"\\|" erlang-variable-regexp "\\)\\>")
1 (if erlang-font-lock-modern-p
'font-lock-reference-face
'font-lock-type-face))
(list (concat "^-\\(define\\|ifn?def\\)\\s *(\\s *\\(" erlang-atom-regexp
"\\|" erlang-variable-regexp "\\)\\>")
2 (if erlang-font-lock-modern-p
'font-lock-reference-face
'font-lock-type-face)))
"Font lock keyword highlighting macros.
This must be placed in front of `erlang-font-lock-keywords-vars'.")
(defvar erlang-font-lock-keywords-records
(list
(list (concat "#\\s *" erlang-atom-regexp "\\>")
1 'font-lock-type-face)
;; Don't highlight numerical constants.
(list "\\<[0-9][0-9]?#\\([0-9a-fA_F]+\\)\\>"
1 nil t)
(list (concat "^-record(\\s *" erlang-atom-regexp "\\>")
1 'font-lock-type-face))
"Font lock keyword highlighting Erlang records.
This must be placed in front of `erlang-font-lock-keywords-vars'.")
(defvar erlang-font-lock-keywords-vars
(list
(list (concat "\\<" erlang-variable-regexp "\\>")
1 (if erlang-font-lock-modern-p
'font-lock-variable-name-face
'font-lock-type-face)))
"Font lock keyword highlighting Erlang variables.
Must be preceded by `erlang-font-lock-keywords-macros' and `-records'
to work properly.")
(defvar erlang-font-lock-keywords-1
(append erlang-font-lock-keywords-func
erlang-font-lock-keywords-dollar
erlang-font-lock-keywords-arrow
erlang-font-lock-keywords-keywords)
;; DocStringOrig: erlang-font-lock-keywords
"Font-lock keywords used by Erlang Mode.
There exists three levels of Font Lock keywords for Erlang:
`erlang-font-lock-keywords-1' - Function headers and reserved keywords.
`erlang-font-lock-keywords-2' - Bifs, guards and `single quotes'.
`erlang-font-lock-keywords-3' - Variables, macros and records.
To use a specific level, please set the variable
`font-lock-maximum-decoration' to the appropriate level. Note that the
variable must be set before Erlang mode is activated.
Example:
(setq font-lock-maximum-decoration 2)")
(defvar erlang-font-lock-keywords-2
(append erlang-font-lock-keywords-1
erlang-font-lock-keywords-attr
erlang-font-lock-keywords-quotes
erlang-font-lock-keywords-guards
erlang-font-lock-keywords-bifs)
;; DocStringCopy: erlang-font-lock-keywords
"Font-lock keywords used by Erlang Mode.
There exists three levels of Font Lock keywords for Erlang:
`erlang-font-lock-keywords-1' - Function headers and reserved keywords.
`erlang-font-lock-keywords-2' - Bifs, guards and `single quotes'.
`erlang-font-lock-keywords-3' - Variables, macros and records.
To use a specific level, please set the variable
`font-lock-maximum-decoration' to the appropriate level. Note that the
variable must be set before Erlang mode is activated.
Example:
(setq font-lock-maximum-decoration 2)")
(defvar erlang-font-lock-keywords-3
(append erlang-font-lock-keywords-2
erlang-font-lock-keywords-macros
erlang-font-lock-keywords-records
erlang-font-lock-keywords-vars)
;; DocStringCopy: erlang-font-lock-keywords
"Font-lock keywords used by Erlang Mode.
There exists three levels of Font Lock keywords for Erlang:
`erlang-font-lock-keywords-1' - Function headers and reserved keywords.
`erlang-font-lock-keywords-2' - Bifs, guards and `single quotes'.
`erlang-font-lock-keywords-3' - Variables, macros and records.
To use a specific level, please set the variable
`font-lock-maximum-decoration' to the appropriate level. Note that the
variable must be set before Erlang mode is activated.
Example:
(setq font-lock-maximum-decoration 2)")
(defvar erlang-font-lock-keywords erlang-font-lock-keywords-3
;; DocStringCopy: erlang-font-lock-keywords
"Font-lock keywords used by Erlang Mode.
There exists three levels of Font Lock keywords for Erlang:
`erlang-font-lock-keywords-1' - Function headers and reserved keywords.
`erlang-font-lock-keywords-2' - Bifs, guards and `single quotes'.
`erlang-font-lock-keywords-3' - Variables, macros and records.
To use a specific level, please set the variable
`font-lock-maximum-decoration' to the appropriate level. Note that the
variable must be set before Erlang mode is activated.
Example:
(setq font-lock-maximum-decoration 2)")
(defvar erlang-font-lock-syntax-table nil
"Syntax table used by Font Lock mode.
The difference between this and the standard Erlang Mode
syntax table is that `_' is treated as part of words by
this syntax table.
Unfortunately, XEmacs hasn't got support for a special Font
Lock syntax table. The effect is that `apply' in the atom
`foo_apply' will be highlighted as a bif.")
;;; Avoid errors while compiling this file.
;; `eval-when-compile' is not defined in Emacs 18. We define it as a
;; no-op.
(or (fboundp 'eval-when-compile)
(defmacro eval-when-compile (&rest rest) nil))
;; These umm...functions are new in Emacs 20. And, yes, until version
;; 19.27 Emacs backquotes were this ugly.
(or (fboundp 'unless)
(defmacro unless (condition &rest body)
"(unless CONDITION BODY...): If CONDITION is false, do BODY, else return nil."
(` (if (, condition)
nil
(,@ body)))))
(or (fboundp 'when)
(defmacro when (condition &rest body)
"(when CONDITION BODY...): If CONDITION is true, do BODY, else return nil."
(` (if (, condition)
(progn (,@ body))
nil))))
(or (fboundp 'char-before)
(defmacro char-before (&optional pos)
"Return the character in the current buffer just before POS."
(` (char-after (1- (or (, pos) (point)))))))
(eval-when-compile
(if (or (featurep 'bytecomp)
(featurep 'byte-compile))
(progn
(cond ((string-match "Lucid\\|XEmacs" emacs-version)
(put 'comment-indent-hook 'byte-obsolete-variable nil)
;; Do not warn for unused variables
;; when compiling under XEmacs.
(setq byte-compile-warnings
'(free-vars unresolved callargs redefine))))
(require 'comint)
(require 'compile))))
(defun erlang-version ()
"Return the current version of Erlang mode."
(interactive)
(if (interactive-p)
(message "Erlang mode version %s, written by Anders Lindgren"
erlang-version))
erlang-version)
;;;###autoload
(defun erlang-mode ()
"Major mode for editing Erlang source files in Emacs.
It knows about syntax and comment, it can indent code, it is capable
of fontifying the source file, the TAGS commands are aware of Erlang
modules, and the Erlang man pages can be accessed.
Should this module, \"erlang.el\", be installed properly, Erlang mode
is activated whenever an Erlang source or header file is loaded into
Emacs. To indicate this, the mode line should contain the word
\"Erlang\".
The main feature of Erlang mode is indentation, press TAB and the
current line will be indented correctly.
Comments starting with only one `%' are indented to the column stored
in the variable `comment-column'. Comments starting with two `%':s
are indented with the same indentation as code. Comments starting
with at least three `%':s are indented to the first column.
However, Erlang mode contains much more, this is a list of the most
useful commands:
TAB - Indent the line.
C-c C-q - Indent current function.
M-; - Create a comment at the end of the line.
M-q - Fill a comment, i.e. wrap lines so that they (hopefully)
will look better.
M-a - Goto the beginning of an Erlang clause.
M-C-a - Ditto for function.
M-e - Goto the end of an Erlang clause.
M-C-e - Ditto for function.
M-h - Mark current Erlang clause.
M-C-h - Ditto for function.
C-c C-z - Start, or switch to, an inferior Erlang shell.
C-c C-k - Compile current file.
C-x ` - Next error.
, - Electric comma.
; - Electric semicolon.
Erlang mode check the name of the file against the module name when
saving, whenever a mismatch occurs Erlang mode offers to modify the
source.
The variable `erlang-electric-commands' controls the electric
commands. To deactivate all of them, set it to nil.
There exists a large number of commands and variables in the Erlang
module. Please press `M-x apropos RET erlang RET' to see a complete
list. Press `C-h f name-of-function RET' and `C-h v name-of-variable
RET'to see the full description of functions and variables,
respectively.
On entry to this mode the contents of the hook `erlang-mode-hook' is
executed.
Please see the beginning of the file `erlang.el' for more information
and examples of hooks.
Other commands:
\\{erlang-mode-map}"
(interactive)
(kill-all-local-variables)
(setq major-mode 'erlang-mode)
(setq mode-name "Erlang")
(erlang-syntax-table-init)
(erlang-keymap-init)
(erlang-electric-init)
(erlang-menu-init)
(erlang-mode-variables)
(erlang-check-module-name-init)
(erlang-add-compilation-alist erlang-error-regexp-alist)
(erlang-man-init)
(erlang-tags-init)
(erlang-font-lock-init)
(erlang-skel-init)
(run-hooks 'erlang-mode-hook)
(if (zerop (buffer-size))
(run-hooks 'erlang-new-file-hook)))
(defun erlang-syntax-table-init ()
(if (null erlang-mode-syntax-table)
(let ((table (make-syntax-table)))
(modify-syntax-entry ?\n ">" table)
(modify-syntax-entry ?\" "\"" table)
(modify-syntax-entry ?# "." table)
(modify-syntax-entry ?$ "'" table)
(modify-syntax-entry ?% "<" table)
(modify-syntax-entry ?& "." table)
(modify-syntax-entry ?\' "\"" table)
(modify-syntax-entry ?* "." table)
(modify-syntax-entry ?+ "." table)
(modify-syntax-entry ?- "." table)
(modify-syntax-entry ?/ "." table)
(modify-syntax-entry ?: "." table)
(modify-syntax-entry ?< "." table)
(modify-syntax-entry ?= "." table)
(modify-syntax-entry ?> "." table)
(modify-syntax-entry ?\\ "\\" table)
(modify-syntax-entry ?_ "_" table)
(modify-syntax-entry ?| "." table)
(modify-syntax-entry ?^ "'" table)
;; Pseudo bit-syntax: Latin1 double angle quotes as parens.
;;(modify-syntax-entry ?\253 "(?\273" table)
;;(modify-syntax-entry ?\273 ")?\253" table)
(setq erlang-mode-syntax-table table)))
(set-syntax-table erlang-mode-syntax-table))
(defun erlang-keymap-init ()
(if erlang-mode-map
nil
(setq erlang-mode-map (make-sparse-keymap))
(erlang-mode-commands erlang-mode-map))
(use-local-map erlang-mode-map))
(defun erlang-mode-commands (map)
(unless (boundp 'indent-line-function)
(define-key map "\t" 'erlang-indent-command))
(define-key map ";" 'erlang-electric-semicolon)
(define-key map "," 'erlang-electric-comma)
(define-key map "<" 'erlang-electric-lt)
(define-key map ">" 'erlang-electric-gt)
(define-key map "\C-m" 'erlang-electric-newline)
(if erlang-xemacs-p
(define-key map [(backspace)] 'backward-delete-char-untabify)
(define-key map "\177" 'backward-delete-char-untabify))
;;(unless (boundp 'fill-paragraph-function)
(define-key map "\M-q" 'erlang-fill-paragraph)
(unless (boundp 'beginning-of-defun-function)
(define-key map "\M-\C-a" 'erlang-beginning-of-function)
(define-key map "\M-\C-e" 'erlang-end-of-function)
(define-key map "\M-\C-h" 'erlang-mark-function))
(define-key map "\M-\t" 'erlang-complete-tag)
(define-key map "\C-c\M-\t" 'tempo-complete-tag)
(define-key map "\M-+" 'erlang-find-next-tag)
(define-key map "\C-c\M-a" 'erlang-beginning-of-clause)
(define-key map "\C-c\M-b" 'tempo-backward-mark)
(define-key map "\C-c\M-e" 'erlang-end-of-clause)
(define-key map "\C-c\M-f" 'tempo-forward-mark)
(define-key map "\C-c\M-h" 'erlang-mark-clause)
(define-key map "\C-c\C-c" 'comment-region)
(define-key map "\C-c\C-j" 'erlang-generate-new-clause)
(define-key map "\C-c\C-k" 'erlang-compile)
(define-key map "\C-c\C-l" 'erlang-compile-display)
(define-key map "\C-c\C-s" 'erlang-show-syntactic-information)
(define-key map "\C-c\C-q" 'erlang-indent-function)
(define-key map "\C-c\C-u" 'erlang-uncomment-region)
(define-key map "\C-c\C-y" 'erlang-clone-arguments)
(define-key map "\C-c\C-a" 'erlang-align-arrows)
(define-key map "\C-c\C-z" 'erlang-shell-display)
(unless inferior-erlang-use-cmm
(define-key map "\C-x`" 'erlang-next-error)))
(defun erlang-electric-init ()
;; Set up electric character functions to work with
;; delsel/pending-del mode. Also, set up text properties for bit
;; syntax handling.
(mapcar #'(lambda (cmd)
(put cmd 'delete-selection t) ;for delsel (Emacs)
(put cmd 'pending-delete t)) ;for pending-del (XEmacs)
'(erlang-electric-semicolon
erlang-electric-comma
erlang-electric-gt))
(put 'bitsyntax-open-outer 'syntax-table '(4 . ?>))
(put 'bitsyntax-open-outer 'rear-nonsticky '(category))
(put 'bitsyntax-open-inner 'rear-nonsticky '(category))
(put 'bitsyntax-close-inner 'rear-nonsticky '(category))
(put 'bitsyntax-close-outer 'syntax-table '(5 . ?<))
(put 'bitsyntax-close-outer 'rear-nonsticky '(category))
(make-local-variable 'parse-sexp-lookup-properties)
(setq parse-sexp-lookup-properties 't))
(defun erlang-mode-variables ()
(or erlang-mode-abbrev-table
(define-abbrev-table 'erlang-mode-abbrev-table ()))
(setq local-abbrev-table erlang-mode-abbrev-table)
(make-local-variable 'paragraph-start)
(setq paragraph-start (concat "^$\\|" page-delimiter))
(make-local-variable 'paragraph-separate)
(setq paragraph-separate paragraph-start)
(make-local-variable 'paragraph-ignore-fill-prefix)
(setq paragraph-ignore-fill-prefix t)
(make-local-variable 'require-final-newline)
(setq require-final-newline t)
(make-local-variable 'defun-prompt-regexp)
(setq defun-prompt-regexp erlang-defun-prompt-regexp)
(make-local-variable 'comment-start)
(setq comment-start "%")
(make-local-variable 'comment-start-skip)
(setq comment-start-skip "%+\\s *")
(make-local-variable 'comment-column)
(setq comment-column 48)
(make-local-variable 'indent-line-function)
(setq indent-line-function 'erlang-indent-command)
(make-local-variable 'indent-region-function)
(setq indent-region-function 'erlang-indent-region)
(set (make-local-variable 'comment-indent-function) 'erlang-comment-indent)
(if (<= erlang-emacs-major-version 18)
(set (make-local-variable 'comment-indent-hook) 'erlang-comment-indent))
(set (make-local-variable 'parse-sexp-ignore-comments) t)
(set (make-local-variable 'dabbrev-case-fold-search) nil)
(set (make-local-variable 'imenu-prev-index-position-function)
'erlang-beginning-of-function)
(set (make-local-variable 'imenu-extract-index-name-function)
'erlang-get-function-name)
(set (make-local-variable 'tempo-match-finder)
"[^-a-zA-Z0-9_]\\([-a-zA-Z0-9_]*\\)\\=")
(set (make-local-variable 'beginning-of-defun-function)
'erlang-beginning-of-function)
(set (make-local-variable 'end-of-defun-function) 'erlang-end-of-function)
(set (make-local-variable 'open-paren-in-column-0-is-defun-start) nil)
(set (make-local-variable 'fill-paragraph-function) 'erlang-fill-paragraph)
(set (make-local-variable 'comment-add) 1)
(set (make-local-variable 'outline-regexp) "[[:lower:]0-9_]+ *(.*) *-> *$")
(set (make-local-variable 'outline-level) (lambda () 1))
(set (make-local-variable 'add-log-current-defun-function)
'erlang-current-defun))
;; Compilation.
;;
;; The following code is compatible with the standard package `compilation',
;; making it possible to go to errors using `erlang-next-error' (or just
;; `next-error' in Emacs 21).
;;
;; The normal `compile' command works of course. For best result, please
;; execute `make' with the `-w' flag.
;;
;; Please see the variables named `compiling-..' above.
(defun erlang-add-compilation-alist (alist)
(require 'compile)
(cond ((boundp 'compilation-error-regexp-alist) ; Emacs 19
(while alist
(or (assoc (car (car alist)) compilation-error-regexp-alist)
(setq compilation-error-regexp-alist
(cons (car alist) compilation-error-regexp-alist)))
(setq alist (cdr alist))))
((boundp 'compilation-error-regexp)
;; Emacs 18, Only one regexp is allowed.
(funcall (symbol-function 'set)
'compilation-error-regexp (car (car alist))))))
(defun erlang-font-lock-init ()
"Initialize Font Lock for Erlang mode."
(or erlang-font-lock-syntax-table
(setq erlang-font-lock-syntax-table
(let ((table (copy-syntax-table erlang-mode-syntax-table)))
(modify-syntax-entry ?_ "w" table)
table)))
(set (make-local-variable 'font-lock-syntax-table)
erlang-font-lock-syntax-table)
(set (make-local-variable 'font-lock-beginning-of-syntax-function)
'erlang-beginning-of-clause)
(make-local-variable 'font-lock-keywords)
(let ((level (cond ((boundp 'font-lock-maximum-decoration)
(symbol-value 'font-lock-maximum-decoration))
((boundp 'font-lock-use-maximal-decoration)
(symbol-value 'font-lock-use-maximal-decoration))
(t nil))))
(if (consp level)
(setq level (cdr-safe (or (assq 'erlang-mode level)
(assq t level)))))
;; `level' can here be:
;; A number - The fontification level
;; nil - Use the default
;; t - Use maximum
(cond ((eq level nil)
(set 'font-lock-keywords erlang-font-lock-keywords))
((eq level 1)
(set 'font-lock-keywords erlang-font-lock-keywords-1))
((eq level 2)
(set 'font-lock-keywords erlang-font-lock-keywords-2))
(t
(set 'font-lock-keywords erlang-font-lock-keywords-3))))
;; Modern font-locks can handle the above much more elegantly:
(set (make-local-variable 'font-lock-defaults)
'((erlang-font-lock-keywords erlang-font-lock-keywords-1
erlang-font-lock-keywords-2 erlang-font-lock-keywords-3)
nil nil ((?_ . "w")) erlang-beginning-of-clause
(font-lock-mark-block-function . erlang-mark-clause))))
;; Useful when defining your own keywords.
(defun erlang-font-lock-set-face (ks &rest faces)
"Replace the face components in a list of keywords.
The first argument, KS, is a list of keywords. The rest of the
arguments are expressions to replace the face information with. The
first expression replaces the face of the first keyword, the second
expression the second keyword etc.
Should an expression be nil, the face of the corresponding keyword is
not changed.
Should fewer expressions than keywords be given, the last expression
is used for all remaining keywords.
Normally, the expressions are just atoms representing the new face.
They could however be more complex, returning different faces in
different situations.
This function only handles keywords with elements on the forms:
(REGEXP NUMBER FACE)
(REGEXP NUMBER FACE OVERWRITE)
This could be used when defining your own special font-lock setup, e.g:
\(setq my-font-lock-keywords
(append erlang-font-lock-keywords-func
erlang-font-lock-keywords-dollar
(erlang-font-lock-set-face
erlang-font-lock-keywords-macros 'my-neon-green-face)
(erlang-font-lock-set-face
erlang-font-lock-keywords-lc 'my-deep-red 'my-light-red)
erlang-font-lock-keywords-attr))
For a more elaborate example, please see the beginning of the file
`erlang.el'."
(let ((res '()))
(while ks
(let* ((regexp (car (car ks)))
(number (car (cdr (car ks))))
(new-face (if (and faces (car faces))
(car faces)
(car (cdr (cdr (car ks))))))
(overwrite (car (cdr (cdr (cdr (car ks))))))
(new-keyword (list regexp number new-face)))
(if overwrite (nconc new-keyword (list overwrite)))
(setq res (cons new-keyword res))
(setq ks (cdr ks))
(if (and faces (cdr faces))
(setq faces (cdr faces)))))
(nreverse res)))
(defun erlang-font-lock-level-0 ()
;; DocStringOrig: font-cmd
"Unfontify current buffer."
(interactive)
(font-lock-mode 0))
(defun erlang-font-lock-level-1 ()
;; DocStringCopy: font-cmd
"Fontify current buffer at level 1.
This highlights function headers, reserved keywords, strings and comments."
(interactive)
(require 'font-lock)
(set 'font-lock-keywords erlang-font-lock-keywords-1)
(font-lock-mode 1)
(funcall (symbol-function 'font-lock-fontify-buffer)))
(defun erlang-font-lock-level-2 ()
;; DocStringCopy: font-cmd
"Fontify current buffer at level 2.
This highlights level 1 features (see `erlang-font-lock-level-1')
plus bifs, guards and `single quotes'."
(interactive)
(require 'font-lock)
(set 'font-lock-keywords erlang-font-lock-keywords-2)
(font-lock-mode 1)
(funcall (symbol-function 'font-lock-fontify-buffer)))
(defun erlang-font-lock-level-3 ()
;; DocStringCopy: font-cmd
"Fontify current buffer at level 3.
This highlights level 2 features (see `erlang-font-lock-level-2')
plus variables, macros and records."
(interactive)
(require 'font-lock)
(set 'font-lock-keywords erlang-font-lock-keywords-3)
(font-lock-mode 1)
(funcall (symbol-function 'font-lock-fontify-buffer)))
(defun erlang-menu-init ()
"Init menus for Erlang mode.
The variable `erlang-menu-items' contain a description of the Erlang
mode menu. Normally, the list contains atoms, representing variables
bound to pieces of the menu.
Personal extensions could be added to `erlang-menu-personal-items'.
This function should be called if any variable describing the
menu configuration is changed."
(erlang-menu-install "Erlang" erlang-menu-items erlang-mode-map t))
(defun erlang-menu-install (name items keymap &optional popup)
"Install a menu in Emacs or XEmacs based on an abstract description.
NAME is the name of the menu.
ITEMS is a list. The elements are either nil representing a horizontal
line or a list with two or three elements. The first is the name of
the menu item, the second the function to call, or a submenu, on the
same same form as ITEMS. The third optional element is an expression
which is evaluated every time the menu is displayed. Should the
expression evaluate to nil the menu item is ghosted.
KEYMAP is the keymap to add to menu to. (When using XEmacs, the menu
will only be visible when this menu is the global, the local, or an
activate minor mode keymap.)
If POPUP is non-nil, the menu is bound to the XEmacs `mode-popup-menu'
variable, i.e. it will popup when pressing the right mouse button.
Please see the variable `erlang-menu-base-items'."
(cond (erlang-xemacs-p
(let ((menu (erlang-menu-xemacs name items keymap)))
;; We add the menu to the global menubar.
;;(funcall (symbol-function 'set-buffer-menubar)
;; (symbol-value 'current-menubar))
(funcall (symbol-function 'add-submenu) nil menu)
(setcdr erlang-xemacs-popup-menu (cdr menu))
(if (and popup (boundp 'mode-popup-menu))
(funcall (symbol-function 'set)
'mode-popup-menu erlang-xemacs-popup-menu))))
((>= erlang-emacs-major-version 19)
(define-key keymap (vector 'menu-bar (intern name))
(erlang-menu-make-keymap name items)))
(t nil)))
(defun erlang-menu-make-keymap (name items)
"Build a menu for Emacs 19."
(let ((menumap (funcall (symbol-function 'make-sparse-keymap)
name))
(count 0)
id def first second third)
(setq items (reverse items))
(while items
;; Replace any occurrence of atoms by their value.
(while (and items (atom (car items)) (not (null (car items))))
(if (and (boundp (car items))
(listp (symbol-value (car items))))
(setq items (append (reverse (symbol-value (car items)))
(cdr items)))
(setq items (cdr items))))
(setq first (car-safe (car items)))
(setq second (car-safe (cdr-safe (car items))))
(setq third (car-safe (cdr-safe (cdr-safe (car items)))))
(cond ((null first)
(setq count (+ count 1))
(setq id (intern (format "separator-%d" count)))
(setq def '("--" . nil)))
((and (consp second) (eq (car second) 'lambda))
(setq count (+ count 1))
(setq id (intern (format "lambda-%d" count)))
(setq def (cons first second)))
((symbolp second)
(setq id second)
(setq def (cons first second)))
(t
(setq count (+ count 1))
(setq id (intern (format "submenu-%d" count)))
(setq def (erlang-menu-make-keymap first second))))
(define-key menumap (vector id) def)
(if third
(put id 'menu-enable third))
(setq items (cdr items)))
(cons name menumap)))
(defun erlang-menu-xemacs (name items &optional keymap)
"Build a menu for XEmacs."
(let ((res '())
first second third entry)
(while items
;; Replace any occurrence of atoms by their value.
(while (and items (atom (car items)) (not (null (car items))))
(if (and (boundp (car items))
(listp (symbol-value (car items))))
(setq items (append (reverse (symbol-value (car items)))
(cdr items)))
(setq items (cdr items))))
(setq first (car-safe (car items)))
(setq second (car-safe (cdr-safe (car items))))
(setq third (car-safe (cdr-safe (cdr-safe (car items)))))
(cond ((null first)
(setq res (cons "------" res)))
((symbolp second)
(setq res (cons (vector first second (or third t)) res)))
((and (consp second) (eq (car second) 'lambda))
(setq res (cons (vector first (list 'call-interactively second)
(or third t)) res)))
(t
(setq res (cons (cons first
(cdr (erlang-menu-xemacs
first second)))
res))))
(setq items (cdr items)))
(setq res (reverse res))
;; When adding a menu to a minor-mode keymap under Emacs,
;; it disappears when the mode is disabled. The expression
;; generated below imitates this behaviour.
;; (This could be expressed much clearer using backquotes,
;; but I don't want to pull in every package.)
(if keymap
(let ((expr (list 'or
(list 'eq keymap 'global-map)
(list 'eq keymap (list 'current-local-map))
(list 'symbol-value
(list 'car-safe
(list 'rassq
keymap
'minor-mode-map-alist))))))
(setq res (cons ':included (cons expr res)))))
(cons name res)))
(defun erlang-menu-substitute (items alist)
"Substitute functions in menu described by ITEMS.
The menu ITEMS is updated destructively.
ALIST is list of pairs where the car is the old function and cdr the new."
(let (first second pair)
(while items
(setq first (car-safe (car items)))
(setq second (car-safe (cdr-safe (car items))))
(cond ((null first))
((symbolp second)
(setq pair (and second (assq second alist)))
(if pair
(setcar (cdr (car items)) (cdr pair))))
((and (consp second) (eq (car second) 'lambda)))
(t
(erlang-menu-substitute second alist)))
(setq items (cdr items)))))
(defun erlang-menu-add-above (entry above items)
"Add menu ENTRY above menu entry ABOVE in menu ITEMS.
Do nothing if the items already should be in the menu.
Should ABOVE not be in the list, the entry is added at
the bottom of the menu.
The new menu is returned. No guarantee is given that the original
menu is left unchanged.
The equality test is performed by `eq'.
Example: (erlang-menu-add-above 'my-erlang-menu-items
'erlang-menu-man-items)"
(erlang-menu-add-below entry above items t))
(defun erlang-menu-add-below (entry below items &optional above-p)
"Add menu ENTRY below menu items BELOW in the Erlang menu.
Do nothing if the items already should be in the menu.
Should BELOW not be in the list, items is added at the bottom
of the menu.
The new menu is returned. No guarantee is given that the original
menu is left unchanged.
The equality test is performed by `eq'.
Example:
\(setq erlang-menu-items
(erlang-menu-add-below 'my-erlang-menu-items
'erlang-menu-base-items
erlang-menu-items))"
(if (memq entry items)
items ; Return the original menu.
(let ((head '())
(done nil)
res)
(while (not done)
(cond ((null items)
(setq res (append head (list entry)))
(setq done t))
((eq below (car items))
(setq res
(if above-p
(append head (cons entry items))
(append head (cons (car items)
(cons entry (cdr items))))))
(setq done t))
(t
(setq head (append head (list (car items))))
(setq items (cdr items)))))
res)))
(defun erlang-menu-delete (entry items)
"Delete ENTRY from menu ITEMS.
The new menu is returned. No guarantee is given that the original
menu is left unchanged."
(delq entry items))
;; Man code:
(defun erlang-man-init ()
"Add menus containing the manual pages of the Erlang.
The variable `erlang-man-dirs' contains entries describing
the location of the manual pages."
(interactive)
(if erlang-man-inhibit
()
(setq erlang-menu-man-items
'(nil
("Man - Function" erlang-man-function)))
(if erlang-man-dirs
(setq erlang-menu-man-items
(append erlang-menu-man-items
(erlang-man-make-top-menu erlang-man-dirs))))
(setq erlang-menu-items
(erlang-menu-add-above 'erlang-menu-man-items
'erlang-menu-version-items
erlang-menu-items))
(erlang-menu-init)))
(defun erlang-man-uninstall ()
"Remove the man pages from the Erlang mode."
(interactive)
(setq erlang-menu-items
(erlang-menu-delete 'erlang-menu-man-items erlang-menu-items))
(erlang-menu-init))
;; The man menu is a hierarchal structure, with the manual sections
;; at the top, described by `erlang-man-dirs'. The next level could
;; either be the manual pages if not to many, otherwise it is an index
;; menu whose submenus will contain up to `erlang-man-max-menu-size'
;; manual pages.
(defun erlang-man-make-top-menu (dir-list)
"Create one menu entry per element of DIR-LIST.
The format is described in the documentation of `erlang-man-dirs'."
(let ((menu '())
dir)
(while dir-list
(setq dir (cond ((nth 2 (car dir-list))
;; Relative to `erlang-root-dir'.
(and (stringp erlang-root-dir)
(concat erlang-root-dir (nth 1 (car dir-list)))))
(t
;; Absolute
(nth 1 (car dir-list)))))
(if (and dir
(file-readable-p dir))
(setq menu (cons (list (car (car dir-list))
(erlang-man-make-middle-menu
(erlang-man-get-files dir)))
menu)))
(setq dir-list (cdr dir-list)))
;; Should no menus be found, generate a menu item which
;; will display a help text, when selected.
(if menu
(nreverse menu)
'(("Man Pages"
(("Error! Why?" erlang-man-describe-error)))))))
;; Should the menu be to long, let's split it into a number of
;; smaller menus. Warning, this code contains beautiful
;; destructive operations!
(defun erlang-man-make-middle-menu (filelist)
"Create the second level menu from FILELIST.
Should the list be longer than `erlang-man-max-menu-size', a tree of
menus is created."
(if (<= (length filelist) erlang-man-max-menu-size)
(erlang-man-make-menu filelist)
(let ((menu '())
(filelist (copy-sequence filelist))
segment submenu pair)
(while filelist
(setq pair (nthcdr (- erlang-man-max-menu-size 1) filelist))
(setq segment filelist)
(if (null pair)
(setq filelist nil)
(setq filelist (cdr pair))
(setcdr pair nil))
(setq submenu (erlang-man-make-menu segment))
(setq menu (cons (list (concat (car (car submenu))
" -- "
(car (car (reverse submenu))))
submenu)
menu)))
(nreverse menu))))
(defun erlang-man-make-menu (filelist)
"Make a leaf menu based on FILELIST."
(let ((menu '())
item)
(while filelist
(setq item (erlang-man-make-menu-item (car filelist)))
(if item
(setq menu (cons item menu)))
(setq filelist (cdr filelist)))
(nreverse menu)))
(defun erlang-man-make-menu-item (file)
"Create a menu item containing the name of the man page."
(and (string-match ".*/\\([^/]+\\)\\.[^.]$" file)
(let ((page (substring file (match-beginning 1) (match-end 1))))
(list (capitalize page)
(list 'lambda '()
'(interactive)
(list 'funcall 'erlang-man-display-function
file))))))
(defun erlang-man-get-files (dir)
"Return files in directory DIR."
(directory-files dir t ".*\\.[0-9]\\'"))
(defun erlang-man-module (&optional module)
"Find manual page for MODULE, defaults to module of function under point.
This function is aware of imported functions."
(interactive
(list (let* ((mod (car-safe (erlang-get-function-under-point)))
(input (read-string
(format "Manual entry for module%s: "
(if (or (null mod) (string= mod ""))
""
(format " (default %s)" mod))))))
(if (string= input "")
mod
input))))
(or module (setq module (car (erlang-get-function-under-point))))
(if (or (null module) (string= module ""))
(error "No Erlang module name given"))
(let ((dir-list erlang-man-dirs)
(pat (concat "/" (regexp-quote module) "\\.[^.]$"))
(file nil)
file-list)
(while (and dir-list (null file))
(setq file-list (erlang-man-get-files
(if (nth 2 (car dir-list))
(concat erlang-root-dir (nth 1 (car dir-list)))
(nth 1 (car dir-list)))))
(while (and file-list (null file))
(if (string-match pat (car file-list))
(setq file (car file-list)))
(setq file-list (cdr file-list)))
(setq dir-list (cdr dir-list)))
(if file
(funcall erlang-man-display-function file)
(error "No manual page for module %s found" module))))
;; Warning, the function `erlang-man-function' is a hack!
;; It links itself into the man code in a non-clean way. I have
;; chosen to keep it since it provides a very useful functionality
;; which is not possible to achieve using a clean approach.
;; / AndersL
(defvar erlang-man-function-name nil
"Name of function for last `erlang-man-function' call.
Used for communication between `erlang-man-function' and the
patch to `Man-notify-when-ready'.")
(defun erlang-man-function (&optional name)
"Find manual page for NAME, where NAME is module:function.
The entry for `function' is displayed.
This function is aware of imported functions."
(interactive
(list (let* ((mod-func (erlang-get-function-under-point))
(mod (car-safe mod-func))
(func (nth 1 mod-func))
(input (read-string
(format
"Manual entry for `module:func' or `module'%s: "
(if (or (null mod) (string= mod ""))
""
(format " (default %s:%s)" mod func))))))
(if (string= input "")
(if (and mod func)
(concat mod ":" func)
mod)
input))))
;; Emacs 18 doesn't provide `man'...
(condition-case nil
(require 'man)
(error nil))
(let ((modname nil)
(funcname nil))
(cond ((null name)
(let ((mod-func (erlang-get-function-under-point)))
(setq modname (car-safe mod-func))
(setq funcname (nth 1 mod-func))))
((string-match ":" name)
(setq modname (substring name 0 (match-beginning 0)))
(setq funcname (substring name (match-end 0) nil)))
((stringp name)
(setq modname name)))
(if (or (null modname) (string= modname ""))
(error "No Erlang module name given"))
(cond ((fboundp 'Man-notify-when-ready)
;; Emacs 19: The man command could possibly start an
;; asynchronous process, i.e. we must hook ourselves into
;; the system to be activated when the man-process
;; terminates.
(if (null funcname)
()
(erlang-man-patch-notify)
(setq erlang-man-function-name funcname))
(condition-case nil
(erlang-man-module modname)
(error (setq erlang-man-function-name nil))))
(t
(erlang-man-module modname)
(if funcname
(erlang-man-find-function
(or (get-buffer "*Manual Entry*") ; Emacs 18
(current-buffer)) ; XEmacs
funcname))))))
;; Should the defadvice be at the top level, the package `advice' would
;; be required. Now it is only required when this functionality
;; is used. (Emacs 19 specific.)
(defun erlang-man-patch-notify ()
"Patch the function `Man-notify-when-ready' to search for function.
The variable `erlang-man-function-name' is assumed to be bound to
the function name, or to nil.
The reason for patching a function is that under Emacs 19, the man
command is executed asynchronously."
(condition-case nil
(require 'advice)
;; This should never happened since this is only called when
;; running under Emacs 19.
(error (error (concat "This command needs the package `advice', "
"please upgrade your Emacs."))))
(require 'man)
(defadvice Man-notify-when-ready
(after erlang-Man-notify-when-ready activate)
"Set point at the documentation of the function name in
`erlang-man-function-name' when the man page is displayed."
(if erlang-man-function-name
(erlang-man-find-function (ad-get-arg 0) erlang-man-function-name))
(setq erlang-man-function-name nil)))
(defun erlang-man-find-function (buf func)
"Find manual page for function in `erlang-man-function-name' in buffer BUF."
(if func
(let ((win (get-buffer-window buf)))
(if win
(progn
(set-buffer buf)
(goto-char (point-min))
(if (re-search-forward
(concat "^[ \t]+" func " ?(")
(point-max) t)
(progn
(forward-word -1)
(set-window-point win (point)))
(message "Could not find function `%s'" func)))))))
(defun erlang-man-display (file)
"Display FILE as a `man' file.
This is the default manual page display function.
The variables `erlang-man-display-function' contains the function
to be used."
;; Emacs 18 doesn't `provide' man.
(condition-case nil
(require 'man)
(error nil))
(if file
(let ((process-environment (copy-sequence process-environment)))
(if (string-match "\\(.*\\)/man[^/]*/\\([^/]+\\)\\.[^.]$" file)
(let ((dir (substring file (match-beginning 1) (match-end 1)))
(page (substring file (match-beginning 2) (match-end 2))))
(if (fboundp 'setenv)
(setenv "MANPATH" dir)
;; Emacs 18
(setq process-environment (cons (concat "MANPATH=" dir)
process-environment)))
(cond ((not (and (not erlang-xemacs-p)
(= erlang-emacs-major-version 19)
(< erlang-emacs-minor-version 29)))
(manual-entry page))
(t
;; Emacs 19.28 and earlier versions of 19:
;; The manual-entry command unconditionally prompts
;; the user :-(
(funcall (symbol-function 'Man-getpage-in-background)
page))))
(error "Can't find man page for %s\n" file)))))
(defun erlang-man-describe-error ()
"Describe why the manual pages weren't found."
(interactive)
(with-output-to-temp-buffer "*Erlang Man Error*"
(princ "Normally, this menu should contain Erlang manual pages.
In order to find the manual pages, the variable `erlang-root-dir'
should be bound to the name of the directory containing the Erlang
installation. The name should not include the final slash.
Practically, you should add a line on the following form to
your ~/.emacs, or ask your system administrator to add it to
the site init file:
(setq erlang-root-dir \"/the/erlang/root/dir/goes/here\")
For example:
(setq erlang-root-dir \"/usr/local/erlang\")
After installing the line, kill and restart Emacs, or restart Erlang
mode with the command `M-x erlang-mode RET'.")))
;; Skeleton code:
;; This code is based on the package `tempo' which is part of modern
;; Emacsen. (GNU Emacs 19.25 (?) and XEmacs 19.14.)
(defun erlang-skel-init ()
"Generate the skeleton functions and menu items.
The variable `erlang-skel' contains the name and descriptions of
all skeletons.
The skeleton routines are based on the `tempo' package. Should this
package not be present, this function does nothing."
(interactive)
(condition-case nil
(require 'tempo)
(error t))
(if (featurep 'tempo)
(let ((skel erlang-skel)
(menu '()))
(while skel
(cond ((null (car skel))
(setq menu (cons nil menu)))
(t
(funcall (symbol-function 'tempo-define-template)
(concat "erlang-" (nth 1 (car skel)))
;; The tempo template used contains an `include'
;; function call only, hence changes to the
;; variables describing the templates take effect
;; immdiately.
(list (list 'erlang-skel-include (nth 2 (car skel))))
(nth 1 (car skel)))
(setq menu (cons (erlang-skel-make-menu-item
(car skel)) menu))))
(setq skel (cdr skel)))
(setq erlang-menu-skel-items
(list nil (list "Skeletons" (nreverse menu))))
(setq erlang-menu-items
(erlang-menu-add-above 'erlang-menu-skel-items
'erlang-menu-version-items
erlang-menu-items))
(erlang-menu-init))))
(defun erlang-skel-make-menu-item (skel)
(let ((func (intern (concat "tempo-template-erlang-" (nth 1 skel)))))
(cond ((null (nth 3 skel))
(list (car skel) func))
(t
(list (car skel)
(list 'lambda '()
'(interactive)
(list 'funcall
(list 'quote (nth 3 skel))
(list 'quote func))))))))
;; Functions designed to be added to the skeleton menu.
;; (Not normally used)
(defun erlang-skel-insert (func)
"Insert skeleton generated by FUNC and goto first tempo mark."
(save-excursion (funcall func))
(funcall (symbol-function 'tempo-forward-mark)))
(defun erlang-skel-header (func)
"Insert the header generated by FUNC at the beginning of the buffer."
(goto-char (point-min))
(save-excursion (funcall func))
(funcall (symbol-function 'tempo-forward-mark)))
;; Functions used inside the skeleton descriptions.
(defun erlang-skel-skip-blank ()
(skip-chars-backward " \t")
nil)
(defun erlang-skel-include (&rest args)
"Include a template inside another template.
Example of use, assuming that `erlang-skel-func' is defined:
(defvar foo-skeleton '(\"%%% New function:\"
(erlang-skel-include erlang-skel-func)))
Technically, this function returns the `tempo' attribute`(l ...)' which
can contain other `tempo' attributes. Please see the function
`tempo-define-template' for a description of the `(l ...)' attribute."
(let ((res '())
entry)
(while args
(setq entry (car args))
(while entry
(setq res (cons (car entry) res))
(setq entry (cdr entry)))
(setq args (cdr args)))
(cons 'l (nreverse res))))
(defun erlang-skel-separator (&optional percent)
"Return a comment separator."
(let ((percent (or percent 3)))
(concat (make-string percent ?%)
(make-string (- 70 percent) ?-)
"\n")))
(defun erlang-skel-double-separator (&optional percent)
"Return a comment separator."
(let ((percent (or percent 3)))
(concat (make-string percent ?%)
(make-string (- 70 percent) ?=)
"\n")))
(defun erlang-skel-dd-mmm-yyyy ()
"Return the current date as a string in \"DD Mon YYYY\" form.
The first character of DD is space if the value is less than 10."
(let ((date (current-time-string)))
(format "%2d %s %s"
(string-to-int (substring date 8 10))
(substring date 4 7)
(substring date -4))))
;; Indentation code:
(defun erlang-indent-command (&optional whole-exp)
"Indent current line as Erlang code.
With argument, indent any additional lines of the same clause
rigidly along with this one."
(interactive "P")
(if whole-exp
;; If arg, always indent this line as Erlang
;; and shift remaining lines of clause the same amount.
(let ((shift-amt (erlang-indent-line))
beg end)
(save-excursion
(if erlang-tab-always-indent
(beginning-of-line))
(setq beg (point))
(erlang-end-of-clause 1)
(setq end (point))
(goto-char beg)
(forward-line 1)
(setq beg (point)))
(if (> end beg)
(indent-code-rigidly beg end shift-amt "\n")))
(if (and (not erlang-tab-always-indent)
(save-excursion
(skip-chars-backward " \t")
(not (bolp))))
(insert-tab)
(erlang-indent-line))))
(defun erlang-indent-line ()
"Indent current line as Erlang code.
Return the amount the indentation changed by."
(let ((pos (- (point-max) (point)))
indent beg
shift-amt)
(beginning-of-line 1)
(setq beg (point))
(skip-chars-forward " \t")
(cond ((looking-at "%")
(setq indent (funcall comment-indent-function))
(setq shift-amt (- indent (current-column))))
(t
(setq indent (erlang-calculate-indent))
(cond ((null indent)
(setq indent (current-indentation)))
((eq indent t)
;; This should never occur here.
(error "Erlang mode error"))
((= (char-syntax (following-char)) ?\))
(setq indent (1- indent))))
(setq shift-amt (- indent (current-column)))))
(if (zerop shift-amt)
nil
(delete-region beg (point))
(indent-to indent))
;; If initial point was within line's indentation, position
;; after the indentation. Else stay at same point in text.
(if (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))
shift-amt))
(defun erlang-indent-region (beg end)
"Indent region of Erlang code.
This is automagically called by the user level function `indent-region'."
(interactive "r")
(save-excursion
(let ((case-fold-search nil)
(continue t)
(from-end (- (point-max) end))
indent-point;; The beginning of the current line
indent;; The indent amount
state)
(goto-char beg)
(beginning-of-line)
(setq indent-point (point))
(erlang-beginning-of-clause)
;; Parse the Erlang code from the beginning of the clause to
;; the beginning of the region.
(while (< (point) indent-point)
(setq state (erlang-partial-parse (point) indent-point state)))
;; Indent every line in the region
(while continue
(goto-char indent-point)
(skip-chars-forward " \t")
(cond ((looking-at "%")
;; Do not use our stack to help the user to customize
;; comment indentation.
(setq indent (funcall comment-indent-function)))
((looking-at "$")
;; Don't indent empty lines.
(setq indent 0))
(t
(setq indent
(save-excursion
(erlang-calculate-stack-indent (point) state)))
(cond ((null indent)
(setq indent (current-indentation)))
((eq indent t)
;; This should never occur here.
(error "Erlang mode error"))
((= (char-syntax (following-char)) ?\))
(setq indent (1- indent))))))
(if (zerop (- indent (current-column)))
nil
(delete-region indent-point (point))
(indent-to indent))
;; Find the next line in the region
(goto-char indent-point)
(save-excursion
(forward-line 1)
(setq indent-point (point)))
(if (>= from-end (- (point-max) indent-point))
(setq continue nil)
(while (< (point) indent-point)
(setq state (erlang-partial-parse
(point) indent-point state))))))))
(defun erlang-indent-current-buffer ()
"Indent current buffer as Erlang code."
(interactive)
(save-excursion
(save-restriction
(widen)
(erlang-indent-region (point-min) (point-max)))))
(defun erlang-indent-function ()
"Indent current Erlang function."
(interactive)
(save-excursion
(let ((end (progn (erlang-end-of-function 1) (point)))
(beg (progn (erlang-beginning-of-function 1) (point))))
(erlang-indent-region beg end))))
(defun erlang-indent-clause ()
"Indent current Erlang clause."
(interactive)
(save-excursion
(let ((end (progn (erlang-end-of-clause 1) (point)))
(beg (progn (erlang-beginning-of-clause 1) (point))))
(erlang-indent-region beg end))))
(defmacro erlang-push (x stack) (list 'setq stack (list 'cons x stack)))
(defmacro erlang-pop (stack) (list 'setq stack (list 'cdr stack)))
;; Would much prefer to make caddr a macro but this clashes.
(defun erlang-caddr (x) (car (cdr (cdr x))))
(defun erlang-calculate-indent (&optional parse-start)
"Compute appropriate indentation for current line as Erlang code.
Return nil if line starts inside string, t if in a comment."
(save-excursion
(let ((indent-point (point))
(case-fold-search nil)
(state nil))
(if parse-start
(goto-char parse-start)
(erlang-beginning-of-clause))
(while (< (point) indent-point)
(setq state (erlang-partial-parse (point) indent-point state)))
(erlang-calculate-stack-indent indent-point state))))
(defun erlang-show-syntactic-information ()
"Show syntactic information for current line."
(interactive)
(save-excursion
(let ((starting-point (point))
(case-fold-search nil)
(state nil))
(erlang-beginning-of-clause)
(while (< (point) starting-point)
(setq state (erlang-partial-parse (point) starting-point state)))
(message "%S" state))))
(defun erlang-partial-parse (from to &optional state)
"Parse Erlang syntax starting at FROM until TO, with an optional STATE.
Value is list (stack token-start token-type in-what)."
(goto-char from) ; Start at the beginning
(erlang-skip-blank to)
(let ((cs (char-syntax (following-char)))
(stack (car state))
(token (point))
in-what)
(cond
;; Done: Return previous state.
((>= token to)
(setq token (nth 1 state))
(setq cs (nth 2 state))
(setq in-what (nth 3 state)))
;; Word constituent: check and handle keywords.
((= cs ?w)
(cond ((looking-at "\\(end\\|after\\)[^_a-zA-Z0-9]")
;; Must pop top icr layer, `after' will push a new
;; layer next.
(progn
(while (and stack (eq (car (car stack)) '->))
(erlang-pop stack))
(if (and stack (memq (car (car stack)) '(icr begin)))
(erlang-pop stack))))
((looking-at "catch[^,\n\\of]*\n")
;; Must pop top icr layer, `catch' in try/catch
;;will push a new layer next.
(progn
(while (and stack (eq (car (car stack)) '->))
(erlang-pop stack))
(if (and stack (memq (car (car stack)) '(icr begin)))
(erlang-pop stack))))
;;((looking-at "^of$")
;; Must pop top icr layer, `of' in try/catch
;;will push a new layer next.
;; (progn
;; (while (and stack (eq (car (car stack)) '->))
;; (erlang-pop stack))
;; (if (and stack (memq (car (car stack)) '(icr begin)))
;; (erlang-pop stack))))
)
(cond ((looking-at "\\(if\\|case\\|receive\\|try\\)[^_a-zA-Z0-9]")
;; Must push a new icr (if/case/receive) layer.
(erlang-push (list 'icr token (current-column)) stack))
((looking-at "\\(fun\\)[^_a-zA-Z0-9]")
;; Push a new icr layer if we are defining a `fun'
;; expression, not when we are refering an existing
;; function.
(if (save-excursion
(goto-char (match-end 1))
(erlang-skip-blank to)
(eq (following-char) ?\())
(erlang-push (list 'icr token (current-column)) stack)))
((looking-at "\\(begin\\|query\\)[^_a-zA-Z0-9]")
(erlang-push (list 'begin token (current-column)) stack))
;; In test suites you may want to do something like
;; ?match(Mem when integer(Mem), mnesia:table_info(Tab,
;; memory)), and then the following if/case/receive
;; statement will mess up the indentation by fooling the
;; erlang mode to think the 'when' in the argument is a
;; "real" when. The following three clauses will avoid
;; this problem.
((looking-at "when[^->\.]*if[^->\.]*->"))
((looking-at "when[^->\.]*case[^->\.]*->"))
((looking-at "when[^->\.]*receive[^->\.]*->"))
;; Normal when case
((looking-at "when [^->\.]*->")
(erlang-push (list 'when token (current-column)) stack))
((looking-at "after[.]+->")
(erlang-push (list 'icr token (current-column)) stack))
((looking-at "after[^_a-zA-Z0-9->]")
;; Probably in try-statment, fake "->" to get right
;; indentation in erlang-calculate-stack-indent. If it
;; was an ordinary catch without try, these entries will
;; be popped of the stack at a later ocaccion.
(erlang-push (list 'icr token (current-column)) stack)
(erlang-push (list '-> token (current-column)) stack))
((looking-at "catch[^,\n\\of]*\n")
(erlang-push (list 'icr token (current-column)) stack)
(erlang-push (list '-> token (current-column)) stack))
;;((looking-at "^of$")
;; (erlang-push (list 'icr token (current-column)) stack)
;;(erlang-push (list '-> token (current-column)) stack))
)
(forward-sexp 1))
;; String: Try to skip over it. (Catch error if not complete.)
((= cs ?\")
(condition-case nil
(progn
(forward-sexp 1)
(if (> (point) to)
(progn
(setq in-what 'string)
(goto-char to))))
(error
(setq in-what 'string)
(goto-char to))))
;; Expression prefix e.i. $ or ^ (Note ^ can be in the character
;; literal $^ or part of string and $ outside of a string denotes
;; a character literal)
((= cs ?')
(cond
((= (following-char) ?\") ;; $ or ^ was the last char in a string
(forward-char 1))
(t
;; Maybe a character literal, quote the next char to avoid
;; situations as $" being seen as the begining of a string.
;; Note the quoting something in the middle of a string is harmless.
(quote (following-char))
(forward-char 1))))
;; Symbol constituent or punctuation
((memq cs '(?. ?_))
(cond
;; Clause end
((= (following-char) ?\;)
(if (and stack (eq (car (car stack)) '->))
(erlang-pop stack))
(forward-char 1))
;; Function end
((looking-at "\\.\\(\\s \\|\n\\|\\s<\\)")
(setq stack nil)
(forward-char 1))
;; Function head
((looking-at "->\\|:-")
(save-excursion
(back-to-indentation)
(cond ((looking-at "after[^_a-zA-Z0-9]")
(erlang-pop stack))))
(if (and stack (eq (car (car stack)) 'when))
(erlang-pop stack))
(erlang-push (list '-> token (current-column)) stack)
(forward-char 2))
;; List-comprehension divider
((looking-at "||")
(erlang-push (list '|| token (current-column)) stack)
(forward-char 2))
;;((looking-at ",$")
;; Normal catch not try-catch have caused icr
;; and then incr and faked "->" should be removed
;; (save-excursion
;; (back-to-indentation)
;; (cond ((looking-at "catch[^_a-zA-Z0-9]")
;; (erlang-pop stack)
;; (erlang-pop stack))))
;;(forward-char 1))
;; Parameter separator
((looking-at ",")
(forward-char 1))
;; Bit-syntax open paren
((looking-at "<<")
(erlang-push (list '\( token (current-column)) stack)
(forward-char 2))
;; Bbit-syntax close paren
((looking-at ">>")
(while (memq (car (car stack)) '(|| ->))
(erlang-pop stack))
(cond ((eq (car (car stack)) '\()
(erlang-pop stack))
((memq (car (car stack)) '(icr begin))
(error "Missing `end'"))
(t
(error "Unbalanced parentheses")))
(forward-char 2))
;; Macro
((= (following-char) ??)
;; Skip over the ?
(forward-char 1)
)
;; Other punctuation: Skip over it and any following punctuation
((= cs ?.)
;; Skip over all characters in the operand.
(skip-syntax-forward "."))
;; Other char: Skip over it.
(t
(forward-char 1))))
;; Open parenthesis
((= cs ?\()
(erlang-push (list '\( token (current-column)) stack)
(forward-char 1))
;; Close parenthesis
((= cs ?\))
(while (memq (car (car stack)) '(|| ->))
(erlang-pop stack))
(cond ((eq (car (car stack)) '\()
(erlang-pop stack))
((eq (car (car stack)) 'icr)
(erlang-pop stack)
;; Normal catch not try-catch might have caused icr
;; and then incr should be removed and is not an error.
(if (eq (car (car stack)) '\()
(erlang-pop stack)
(else
(error "Missing `end'"))
))
((eq (car (car stack)) 'begin)
(error "Missing `end'")
(t
(error "Unbalanced parenthesis"))
))
(forward-char 1))
;; Character quote: Skip it and the quoted char.
((= cs ?/)
(forward-char 2))
;; Character escape: Skip it and the escape sequence.
((= cs ?\\)
(forward-char 1)
(skip-syntax-forward "w"))
;; Everything else
(t
(forward-char 1)))
(list stack token cs in-what)))
(defun erlang-calculate-stack-indent (indent-point state)
"From the given last position and state (stack) calculate indentation.
Return nil if inside string, t if in a comment."
(let* ((stack (and state (car state)))
(token (nth 1 state))
(stack-top (and stack (car stack))))
(cond ((null state) ;No state
0)
((nth 3 state)
;; Return nil or t.
(eq (nth 3 state) 'comment))
((null stack)
(if (looking-at "when[^_a-zA-Z0-9]")
erlang-indent-guard
0))
((eq (car stack-top) '\()
;; Element of list, tuple or part of an expression,
(if (null erlang-argument-indent)
;; indent to next column.
(1+ (nth 2 stack-top))
(goto-char (nth 1 stack-top))
(cond ((looking-at "[({]\\s *\\($\\|%\\)")
;; Line ends with parenthesis.
(+ (erlang-indent-find-preceding-expr)
erlang-argument-indent))
(t
;; Indent to the same column as the first
;; argument.
(goto-char (1+ (nth 1 stack-top)))
(skip-chars-forward " \t")
(current-column)))))
((eq (car stack-top) 'icr)
;; The default indentation is the column of the option
;; directly following the keyword. (This does not apply to
;; `case'.) Should no option be on the same line, the
;; indentation is the indentation of the keyword +
;; `erlang-indent-level'.
;;
;; `after' should be indented to the save level as the
;; corresponding receive.
(if (looking-at "after[^_a-zA-Z0-9]")
(nth 2 stack-top)
(save-excursion
(goto-char (nth 1 stack-top))
(if (looking-at "case[^_a-zA-Z0-9]")
(+ (nth 2 stack-top) erlang-indent-level)
(skip-chars-forward "a-z")
(skip-chars-forward " \t")
(if (memq (following-char) '(?% ?\n))
(+ (nth 2 stack-top) erlang-indent-level)
(current-column)))))
(if (looking-at "catch[^_a-zA-Z0-9]")
(nth 2 stack-top)
(save-excursion
(goto-char (nth 1 stack-top))
(if (looking-at "case[^_a-zA-Z0-9]")
(+ (nth 2 stack-top) erlang-indent-level)
(skip-chars-forward "a-z")
(skip-chars-forward " \t")
(if (memq (following-char) '(?% ?\n))
(+ (nth 2 stack-top) erlang-indent-level)
(current-column)))))
)
;; Real indentation, where operators create extra indentation etc.
((memq (car stack-top) '(-> || begin))
(goto-char (nth 1 stack-top))
;; Check if there is more code after the '->' on the
;; same line. If so use this indentation as base, else
;; use parent indentation + 2 * level as base.
(let ((off erlang-indent-level)
(skip 2))
(cond ((null (cdr stack))) ; Top level in function.
((eq (car stack-top) 'begin)
(setq skip 5))
((eq (car stack-top) '->)
(setq off (* 2 erlang-indent-level))))
(let ((base (erlang-indent-find-base stack indent-point off skip)))
;; Look at last thing to see how we are to move relative
;; to the base.
(goto-char token)
(cond ((looking-at "||\\|,\\|->\\|:-")
base)
((erlang-at-keyword)
(+ (current-column) erlang-indent-level))
((or (= (char-syntax (following-char)) ?.)
(erlang-at-operator))
(+ base erlang-indent-level))
(t
(goto-char indent-point)
(cond ((memq (following-char) '(?\( ?{))
;; Function application or record.
(+ (erlang-indent-find-preceding-expr)
erlang-argument-indent))
;; Empty line, or end; treat it as the end of
;; the block. (Here we have a choice: should
;; the user be forced to reindent continued
;; lines, or should the "end" be reindented?)
((looking-at "\\(end\\|after\\|catch\\)[^_a-zA-Z0-9]\\|$")
(if (eq (car (car stack)) '->)
(erlang-pop stack))
(if stack
(erlang-caddr (car stack))
0))
;; Avoid treating comments a continued line.
((= (following-char) ?%)
base)
;; Continued line (e.g. line beginning
;; with an operator.)
(t (+ base erlang-indent-level)))))))
)
((eq (car stack-top) 'when)
(goto-char (nth 1 stack-top))
(if (looking-at "when\\s *\\($\\|%\\)")
(progn
(erlang-pop stack)
(if (and stack (eq (nth 0 (car stack)) 'icr))
(progn
(goto-char (nth 1 (car stack)))
(+ (nth 2 (car stack)) erlang-indent-guard
;; receive XYZ or receive
;; XYZ
(if (looking-at "[a-z]+\\s *\\($\\|%\\)")
erlang-indent-level
(* 2 erlang-indent-level))))
erlang-indent-guard))
;; "when" is followed by code, let's indent to the same
;; column.
(forward-char 4) ; Skip "when"
(skip-chars-forward " \t")
(current-column))))))
(defun erlang-indent-find-base (stack indent-point &optional offset skip)
"Find the base column for current stack."
(or skip (setq skip 2))
(or offset (setq offset erlang-indent-level))
(save-excursion
(let* ((stack-top (car stack)))
(goto-char (nth 1 stack-top))
(forward-char skip)
(if (looking-at "\\s *\\($\\|%\\)")
(progn
(if (memq (car stack-top) '(-> ||))
(erlang-pop stack))
;; Take parent identation + offset,
;; else just erlang-indent-level if no parent
(if stack
(+ (erlang-caddr (car stack))
offset)
erlang-indent-level))
(erlang-skip-blank indent-point)
(current-column)))))
;; Does not handle `begin' .. `end'.
(defun erlang-indent-find-preceding-expr ()
"Return the first column of the preceding expression.
This assumes that the preceding expression is either simple
\(i.e. an atom) or parenthesized."
(save-excursion
(forward-sexp -1)
(let ((col (current-column)))
(skip-chars-backward " \t")
;; Needed to match the colon in "'foo':'bar'".
(if (not (memq (preceding-char) '(?# ?:)))
col
(backward-char 1)
(forward-sexp -1)
(current-column)))))
(defun erlang-skip-blank (&optional lim)
"Skip over whitespace and comments until limit reached."
(or lim (setq lim (point-max)))
(let (stop)
(while (and (not stop) (< (point) lim))
(cond ((= (following-char) ?%)
(skip-chars-forward "^\n" lim))
((= (following-char) ?\n)
(skip-chars-forward "\n" lim))
((looking-at "\\s ")
(if (re-search-forward "\\S " lim 'move)
(forward-char -1)))
(t
(setq stop t))))
stop))
(defun erlang-at-keyword ()
"Are we looking at an Erlang keyword which will increase indentation?"
(looking-at (concat "\\(when\\|if\\|fun\\|case\\|begin\\|query\\|"
"of\\|receive\\|after\\|catch\\)[^_a-zA-Z0-9]")))
(defun erlang-at-operator ()
"Are we looking at an Erlang operator?"
(looking-at
"\\(bnot\\|div\\|mod\\|band\\|bor\\|bxor\\|bsl\\|bsr\\)[^_a-zA-Z0-9]"))
(defun erlang-comment-indent ()
"Compute Erlang comment indentation.
Used both by `indent-for-comment' and the Erlang specific indentation
commands."
(cond ((looking-at "%%%") 0)
((looking-at "%%")
(or (erlang-calculate-indent)
(current-indentation)))
(t
(save-excursion
(skip-chars-backward " \t")
(max (if (bolp) 0 (1+ (current-column)))
comment-column)))))
;;; Erlang movement commands
;; All commands below work as movement commands. I.e. if the point is
;; at the end of the clause, and the command `erlang-end-of-clause' is
;; executed, the point is moved to the end of the NEXT clause. (This
;; mimics the behaviour of `end-of-defun'.)
;;
;; Personally I would like to rewrite them to be "pure", and add a set
;; of movement functions, like `erlang-next-clause',
;; `erlang-previous-clause', and the same for functions.
;;
;; The current implementation makes it hopeless to use the functions as
;; subroutines in more complex commands. /andersl
(defun erlang-beginning-of-clause (&optional arg)
"Move backward to previous start of clause.
With argument, do this that many times.
Return t unless search stops due to end of buffer."
(interactive "p")
(or arg (setq arg 1))
(if (< arg 0)
;; Step back to the end of the previous line, unless we are at
;; the beginning of the buffer. The reason for this move is
;; that the regexp below includes the last character of the
;; previous line.
(if (bobp)
(or (looking-at "\n")
(forward-char 1))
(forward-char -1)
(if (looking-at "\\`\n")
(forward-char 1))))
;; The regexp matches a function header that isn't
;; included in a string.
(and (re-search-forward "\\(\\`\\|\\`\n\\|[^\\]\n\\)\\([a-z]\\|'\\|-\\)"
nil 'move (- arg))
(let ((beg (match-beginning 2)))
(and beg (goto-char beg))
t)))
(defun erlang-end-of-clause (&optional arg)
"Move to the end of the current clause.
With argument, do this that many times."
(interactive "p")
(or arg (setq arg 1))
(while (and (looking-at "[ \t]*[%\n]")
(zerop (forward-line 1))))
;; Move to the next clause.
(erlang-beginning-of-clause (- arg))
(beginning-of-line);; Just to be sure...
(let ((continue t))
(while (and (not (bobp)) continue)
(forward-line -1)
(skip-chars-forward " \t")
(if (looking-at "[%\n]")
nil
(end-of-line)
(setq continue nil)))))
(defun erlang-mark-clause ()
"Put mark at end of clause, point at beginning."
(interactive)
(push-mark (point))
(erlang-end-of-clause 1)
;; Sets the region. In Emacs 19 and XEmacs, we want to activate
;; the region.
(condition-case nil
(push-mark (point) nil t)
(error (push-mark (point))))
(erlang-beginning-of-clause 1)
;; The above function deactivates the mark.
(if (boundp 'deactivate-mark)
(funcall (symbol-function 'set) 'deactivate-mark nil)))
(defun erlang-beginning-of-function (&optional arg)
"Move backward to previous start of function.
With positive argument, do this that many times.
With negative argument, search forward.
Return t unless search stops due to end of buffer."
(interactive "p")
(or arg (setq arg 1))
(cond
;; Search backward
((> arg 0)
(while (and (> arg 0)
(and (erlang-beginning-of-clause 1)
(let ((start (point))
(name (erlang-name-of-function))
(arity (erlang-get-function-arity)))
;; Note: "arity" is nil for e.g. "-import", hence
;; two "-import" clauses are not considered to
;; be part of the same function.
(while (and (erlang-beginning-of-clause 1)
(string-equal name
(erlang-name-of-function))
arity
(equal arity
(erlang-get-function-arity)))
(setq start (point)))
(goto-char start)
t)))
(setq arg (1- arg))))
;; Search forward
((< arg 0)
(end-of-line)
(erlang-beginning-of-clause 1)
;; Step -arg functions forward.
(while (and (< arg 0)
;; Step one function forward, or stop if the end of
;; the buffer was reached. Return t if we found the
;; function.
(let ((name (erlang-name-of-function))
(arity (erlang-get-function-arity))
(found (erlang-beginning-of-clause -1)))
(while (and found
(string-equal name (erlang-name-of-function))
arity
(equal arity
(erlang-get-function-arity)))
(setq found (erlang-beginning-of-clause -1)))
found))
(setq arg (1+ arg)))))
(zerop arg))
(defun erlang-end-of-function (&optional arg)
"Move forward to next end of function.
With argument, do this that many times.
With negative argument go towards the beginning of the buffer."
(interactive "p")
(or arg (setq arg 1))
(let ((first t))
;; Forward
(while (and (> arg 0) (< (point) (point-max)))
(let ((pos (point)))
(while (progn
(if (and first
(progn
(forward-char 1)
(erlang-beginning-of-clause 1)))
nil
(or (bobp) (forward-char -1))
(erlang-beginning-of-clause -1))
(setq first nil)
(erlang-pass-over-function)
(skip-chars-forward " \t")
(if (looking-at "[%\n]")
(forward-line 1))
(<= (point) pos))))
(setq arg (1- arg)))
;; Backward
(while (< arg 0)
(let ((pos (point)))
(erlang-beginning-of-clause 1)
(erlang-pass-over-function)
(forward-line 1)
(if (>= (point) pos)
(if (erlang-beginning-of-function 2)
(progn
(erlang-pass-over-function)
(skip-chars-forward " \t")
(if (looking-at "[%\n]")
(forward-line 1)))
(goto-char (point-min)))))
(setq arg (1+ arg)))))
(eval-and-compile
(if (default-boundp 'beginning-of-defun-function)
(defalias 'erlang-mark-function 'mark-defun)
(defun erlang-mark-function ()
"Put mark at end of function, point at beginning."
(interactive)
(push-mark (point))
(erlang-end-of-function 1)
;; Sets the region. In Emacs 19 and XEmacs, we want to activate
;; the region.
(condition-case nil
(push-mark (point) nil t)
(error (push-mark (point))))
(erlang-beginning-of-function 1)
;; The above function deactivates the mark.
(if (boundp 'deactivate-mark)
(funcall (symbol-function 'set) 'deactivate-mark nil)))))
(defun erlang-pass-over-function ()
(while (progn
(erlang-skip-blank)
(and (not (looking-at "\\.\\(\\s \\|\n\\|\\s<\\)"))
(not (eobp))))
(forward-sexp 1))
(if (not (eobp))
(forward-char 1)))
(defun erlang-name-of-function ()
(save-excursion
;; Skip over attribute leader.
(if (looking-at "-[ \t]*")
(re-search-forward "-[ \t]*" nil 'move))
(let ((start (point)))
(forward-sexp 1)
(buffer-substring start (point)))))
;;; Miscellaneous
(defun erlang-fill-paragraph (&optional justify)
"Like \\[fill-paragraph], but handle Erlang comments.
If any of the current line is a comment, fill the comment or the
paragraph of it that point is in, preserving the comment's indentation
and initial `%':s."
(interactive "P")
(let ((has-comment nil)
;; If has-comment, the appropriate fill-prefix for the comment.
comment-fill-prefix)
;; Figure out what kind of comment we are looking at.
(save-excursion
(beginning-of-line)
(cond
;; Find the command prefix.
((looking-at (concat "\\s *" comment-start-skip))