pax_global_header 0000666 0000000 0000000 00000000064 13022740610 0014505 g ustar 00root root 0000000 0000000 52 comment=29f50a940113d793a21998f3bb414fdd9b0c5daa
elm-mode-0.20.3/ 0000775 0000000 0000000 00000000000 13022740610 0013266 5 ustar 00root root 0000000 0000000 elm-mode-0.20.3/.gitignore 0000664 0000000 0000000 00000000041 13022740610 0015251 0 ustar 00root root 0000000 0000000 build/
cache/
*.*~
[#]*
.*
*.elc
elm-mode-0.20.3/LICENSE 0000664 0000000 0000000 00000104506 13022740610 0014301 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
{project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
elm-mode-0.20.3/README.md 0000664 0000000 0000000 00000020041 13022740610 0014542 0 ustar 00root root 0000000 0000000 # elm-mode
Elm mode for Emacs.
## Features
1. Syntax highlighting.
1. Intelligent indentation.
1. Integration with [elm-make](https://github.com/elm-lang/elm-make).
1. Integration with [elm-repl](https://github.com/elm-lang/elm-repl).
1. Integration with [elm-reactor](https://github.com/elm-lang/elm-reactor).
1. Integration with [elm-package](https://github.com/elm-lang/elm-package).
1. Integration with [elm-oracle][elm-oracle]
1. Integration with [elm-format][elm-format]
1. Integration with [elm-test][elm-test]
## Indentation
`elm-mode` indentation is based on cycling: every time you insert a new
line there will be one or more indentation levels available for you to
choose from. The exact number is printed in the minibuffer either as
`Sole indentation` or `Indent cycle (n)...` where `n` is the number of
available indentations to choose from. If the automatic indentation
level was not the one you expected simply hit `TAB` to cycle through the
list (note that hitting any other key will cancel the cycle).
## Installation
### MELPA
If your Emacs has `package.el` (which is automatically the case
for Emacs >= 24), you can install `elm-mode` from the package in
[MELPA](http://melpa.milkbox.net/).
### From source
Add this repo to your load-path and `(require 'elm-mode)`. Ensure that
the following dependencies are available:
* [f](https://github.com/rejeep/f.el)
* [let-alist](https://elpa.gnu.org/packages/let-alist.html)
* [s](https://github.com/magnars/s.el)
This package assumes you are runing Emacs 24 or later.
## Bindings
The following bindings are available in `elm-mode`:
#### `TAGS`
| Keybinding | Description |
| ---------------------- | ------------------------------------------------------------------- |
| C-c M-t | Generate a TAGS file for the current project. |
| C-c . | Jump to tag at point. |
| C-c , | Jump to previous location after visiting a tag. |
TAGS file generation requires that the UNIX `find`, `egrep` commands
and the Emacs `etags` command be available in your path.
Set or customize `elm-tags-on-save` to `t` to generate a new TAGS file
for the current project on every save.
Set or customize `elm-tags-exclude-elm-stuff` to `nil` to include
source files inside `elm-stuff` directories when generating the TAGS
file.
#### `elm-make`
| Keybinding | Description |
| ---------------------- | --------------------------------------------------------------------------------- |
| C-c C-c | Compile the current buffer. |
| C-u C-c C-c | Compile the current buffer, specifying the output file. |
| C-c M-c | Compile the main elm file. |
| C-u C-c M-c | Compile the main elm file, specifying the output file. |
| C-c C-a | Add missing type annotations to the current buffer. |
| C-u C-c C-a | Add missing type annotations to the current buffer, prompting before each change. |
| C-c C-r | Clean up imports in the current buffer. |
| C-u C-c C-r | Clean up imports in the current buffer, prompting before each change. |
#### `elm-repl`
| Keybinding | Description |
| ------------------ | ---------------------------------------------------------------------- |
| C-c C-l | Load the current file in a REPL. |
| C-c C-p | Push the current region to a REPL. |
| C-c C-e | Push the current decl. to a REPL (requires haskell-mode
). |
#### `elm-reactor`
| Keybinding | Description |
| ---------------------- | ------------------------------------------------------------------ |
| C-c C-n | Preview the current buffer in a browser. |
| C-u C-c C-n | Preview the current buffer in a browser in debug mode. |
| C-c C-m | Preview the main elm file in a browser. |
| C-u C-c C-m | Preview the main elm file in a browser in debug mode. |
#### `elm-package`
| Keybinding | Description |
| ---------------------- | ------------------------------------------------------------ |
| C-c C-d | View a function's documentation in a browser. |
| C-c C-i | Import a module from one of the dependencies. |
| C-c C-s | Sort the imports in the current file. |
| C-c M-k | Open the package catalog. |
| C-u C-c M-k | Open the package catalog, refreshing the package list first. |
The following bindings are available in the package list buffer:
| Keybinding | Description |
| ------------ | ------------------------------ |
| g | Refresh package list. |
| n | Next package. |
| p | Previous package. |
| v | View package in browser. |
| m | Mark package for installation. |
| i | Mark package for installation. |
| u | Unmark package. |
| x | Install marked packages. |
Set or customize `elm-sort-imports-on-save` to `t` to apply
`elm-sort-imports` on the current buffer on every save.
#### `elm-oracle`
The following functionality requires [elm-oracle][elm-oracle] to be
installed. `elm-oracle` does not come with the Elm installer so you
will have to install it manually.
| Keybinding | Description |
| ------------------- | --------------------------------------------------------- |
| C-c C-t | Show the type of the function at point in the minibuffer. |
| C-c M-d | Show the documentation of the function at point. |
`elm-mode` supports auto-completion through `elm-oracle`. To
use [company-mode][company] for auto-completion, add the Elm backend
to the backend list:
```elisp
(add-to-list 'company-backends 'company-elm)
```
The Company backend supports `company-quickhelp` to display
documentation snippets for the autocompletion candidates.
Here's a screenshot of `company-mode` in action:

#### `elm-format`
The following functionality requires [elm-format][elm-format] to be
installed. `elm-format` does not come with the Elm installer so you
will have to install it manually.
| Keybinding | Description |
| ------------------ | ---------------------------------------- |
| C-c C-f | Automatically format the current buffer. |
Set or customize `elm-format-on-save` to `t` to apply `elm-format` on
the current buffer on every save.
Set or customize `elm-format-elm-version` to change which version of
Elm to format against. Valid options are `0.17` and `0.16`. The
default is `0.17`.
#### `elm-test`
The following functionality requires [elm-test][elm-test] to be
installed. `elm-test` does not come with the Elm installer so you
will have to install it manually.
| Keybinding | Description |
| ------------------ | ------------------------------------------- |
| C-c t | Run the test suite for the current project. |
[company-mode]: http://company-mode.github.io/
[elm-format]: https://github.com/avh4/elm-format#installation-
[elm-oracle]: https://github.com/ElmCast/elm-oracle#installation
[elm-test]: https://github.com/rtfeldman/node-test-runner
elm-mode-0.20.3/elm-font-lock.el 0000664 0000000 0000000 00000017027 13022740610 0016266 0 ustar 00root root 0000000 0000000 ;;; elm-font-lock.el --- Font locking module for Elm mode.
;; Copyright (C) 2013, 2014 Joseph Collard
;; Copyright (C) 2015 Bogdan Popa
;; Authors: Joseph Collard
;; URL: https://github.com/jcollard/elm-mode
;; This file is not part of GNU Emacs.
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see .
;;; Commentary:
;;; Code:
(require 'font-lock)
(require 'rx)
(defgroup elm-font-lock nil
"Font locking for Elm code."
:group 'faces)
(defface elm-font-lock-operators
'((t :inherit font-lock-builtin-face))
"The default face used to highlight operators inside expressions."
:group 'elm-font-lock)
(defcustom elm-font-lock-operators-face 'elm-font-lock-operators
"The face used to highlight operators inside expressions.
To disable this highlighting, set this to nil."
:type '(choice (const nil)
face)
:group 'elm-font-lock)
(defface elm-font-lock-multiline-list-delimiters
'((t :inherit font-lock-keyword-face))
"The default face used to highlight brackets and commas in multiline lists."
:group 'elm-font-lock)
(defcustom elm-font-lock-multiline-list-delimiters-face 'elm-font-lock-multiline-list-delimiters
"The face used to highlight brackets and commas in multilist lists.
To disable this highlighting, set this to nil."
:type '(choice (const nil)
face)
:group 'elm-font-lock)
(defconst elm--keywords
'("let" "case" "in" "if" "of" "then" "else" "effect"
"module" "import" "as" "exposing" "type" "where"
"alias" "port" "infix" "infixr" "infixl")
"Reserved keywords.")
(defconst elm--regexp-keywords
(concat (regexp-opt elm--keywords 'words) "[^']")
"A regular expression representing the reserved keywords.")
(defconst elm--font-lock-keywords
(cons elm--regexp-keywords font-lock-keyword-face)
"Highlighting for keywords.")
(defun elm--syntax-stringify ()
"Syntax propertize triple quoted strings."
(let* ((ppss (save-excursion
(backward-char 3)
(syntax-ppss)))
(string-started (and (not (nth 4 ppss)) (nth 8 ppss)))
(quote-starting-pos (- (point) 3))
(quote-ending-pos (point)))
(if (not string-started)
(put-text-property quote-starting-pos (1+ quote-starting-pos)
'syntax-table (string-to-syntax "|"))
(put-text-property (1- quote-ending-pos) quote-ending-pos
'syntax-table (string-to-syntax "|")))))
(defconst elm--syntax-propertize
(syntax-propertize-rules
;;; Syntax rule for -- comments
((rx (and (0+ " ") (group "--")
(0+ any) (group "\n")))
(1 "< b")
(2 "> b"))
;;; Syntax rule for char literals
((rx (and (1+ " ")
(group "'")
(optional "\\") any
(group "'")))
(1 "\"")
(2 "\""))
((rx (and (or point
(not (any ?\\ ?\"))
(and (or (not (any ?\\)) point) ?\\ (* ?\\ ?\\) (any ?\")))
(* ?\\ ?\\)
"\"\"\""))
(0 (ignore (elm--syntax-stringify))))))
(defun elm--syntax-propertize-function (begin end)
"Mark special lexemes between BEGIN and END."
(funcall elm--syntax-propertize begin end)
(save-excursion
(goto-char begin)
(while (re-search-forward "\\\\[({]" end t)
(let ((open (match-beginning 0)))
(add-text-properties open (1+ open) '(syntax-table (1 . nil)))))))
(defvar elm--syntax-table
(let ((st (make-syntax-table)))
;;; Syntax entry for {- -} type comments.
(modify-syntax-entry ?{ "(} 1n" st)
(modify-syntax-entry ?- ". 23n" st)
(modify-syntax-entry ?} "){ 4n" st)
(modify-syntax-entry ?\" "\"\"" st)
(modify-syntax-entry ?\\ "\\" st)
st))
;;; Name regexp is according to https://github.com/elm-lang/elm-compiler/blob/353930a474fee4d833f962100edde70417691bca/src/Parse/Helpers.hs#L65
(defconst elm--regexp-function
"^\\([a-z_][0-9A-Za-z_']*\\|([^)]+)\\)"
"A regular expression representing function names.")
(defconst elm--font-lock-functions
(cons elm--regexp-function font-lock-function-name-face)
"Highlighting for function names.")
(defconst elm--regexp-type
"\\<[A-Z][0-9A-Za-z_']*"
"A regular expression representing modules and types.")
(defconst elm--font-lock-types
(cons elm--regexp-type font-lock-type-face)
"Highlighting for module names and types.")
(defconst elm--regexp-operators
(concat "\\(" "`[^`]+`"
"\\|" "\\B\\\\"
"\\|" "[-+*/\\\\|<>=:!@#$%^&,.]+"
"\\)")
"A regular expression representing operators inside expressions.")
(defconst elm--font-lock-operators
(cons elm--regexp-operators '(1 elm-font-lock-operators-face))
"Highlighting for operators inside expressions.")
(defconst elm--regexp-multiline-list-comma-closing-brackets
(concat "^[[:space:]]*" (regexp-opt '("," "]" "}") t))
"A regular expression representing commas and closing brackets in multiline lists and records.")
(defconst elm--font-lock-multiline-list-comma-closing-brackets
(cons elm--regexp-multiline-list-comma-closing-brackets
'(1 elm-font-lock-multiline-list-delimiters-face))
"Highlighting for commas and closing brackets in multiline lists and records.")
(defun elm--match-multiline-list-opening-bracket (limit)
"Highlighting search function for opening brackets in multiline lists and records.
Also highlights opening brackets without a matching bracket."
(when (elm--search-forward-opening-bracket limit)
(let ((opening (point))
(eol (line-end-position))
(closing (elm--search-forward-closing-bracket)))
(if (or (= closing opening) (> closing eol))
(progn
(set-match-data (match-data))
(goto-char (+ 1 opening))
t)
(elm--match-multiline-list-opening-bracket limit)))))
(defun elm--search-forward-opening-bracket (limit)
"Go to the next opening bracket up to LIMIT."
(if (search-forward-regexp (regexp-opt '("[" "{")) limit t)
(progn
(backward-char)
t)))
(defun elm--search-forward-closing-bracket ()
"Go to the next matching bracket, assuming that the cursor is on an opening bracket."
(ignore-errors
(save-match-data
(forward-sexp)))
(point))
(defconst elm--font-lock-multiline-list-opening-brackets
'(elm--match-multiline-list-opening-bracket (0 elm-font-lock-multiline-list-delimiters-face))
"Highlighting for opening brackets in multiline lists and records.")
(defconst elm--font-lock-highlighting
(list (list elm--font-lock-keywords
elm--font-lock-functions
elm--font-lock-types
elm--font-lock-multiline-list-comma-closing-brackets
elm--font-lock-multiline-list-opening-brackets
elm--font-lock-operators)
nil nil))
(defun turn-on-elm-font-lock ()
"Turn on Elm font lock."
(setq font-lock-multiline t)
(set-syntax-table elm--syntax-table)
(set (make-local-variable 'syntax-propertize-function) #'elm--syntax-propertize-function)
(set (make-local-variable 'font-lock-defaults) elm--font-lock-highlighting))
(provide 'elm-font-lock)
;;; elm-font-lock.el ends here
elm-mode-0.20.3/elm-format.el 0000664 0000000 0000000 00000005200 13022740610 0015650 0 ustar 00root root 0000000 0000000 ;;; elm-format.el --- Automatically format an Elm buffer.
;; Copyright (C) 2015 Bogdan Popa
;; Author: Bogdan Popa
;; URL: https://github.com/jcollard/elm-mode
;; This file is not part of GNU Emacs.
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see .
;;; Commentary:
;;; Code:
(defcustom elm-format-on-save nil
"Controls whether or not `elm-format' should be run on the current buffer on save."
:group 'elm-format
:type 'boolean)
(defcustom elm-format-elm-version "0.17"
"The version of Elm against which code should be formatted."
:group 'elm-format
:type '(choice (const :tag "Default: 0.17" "0.17")
(const :tag "0.16" "0.16")))
(defvar elm-format-command "elm-format"
"The name of the `elm-format' command.")
;;;###autoload
(defun elm-mode-format-buffer ()
"Apply `elm-format' to the current buffer."
(interactive)
(let* ((column (current-column))
(line (line-number-at-pos))
;;; elm-format requires that the file have a .elm extension
(in-file (make-temp-file "elm-format" nil ".elm"))
(err-file (make-temp-file "elm-format"))
(out-file (make-temp-file "elm-format"))
(contents (buffer-substring-no-properties (point-min) (point-max)))
(_ (with-temp-file in-file (insert contents)))
(retcode
(with-temp-buffer
(call-process elm-format-command
nil (list (current-buffer) err-file)
nil
in-file
"--output" out-file
"--elm-version" elm-format-elm-version
"--yes"))))
(if (/= retcode 0)
(with-temp-buffer
(insert-file-contents err-file nil nil nil t)
(message "Error: elm-format failed on current buffer.\n\n%s" (buffer-string)))
(insert-file-contents out-file nil nil nil t)
(goto-char (point-min))
(forward-line (1- line))
(goto-char (+ column (point))))
(delete-file err-file)
(delete-file out-file)))
(provide 'elm-format)
;;; elm-format.el ends here
elm-mode-0.20.3/elm-imenu.el 0000664 0000000 0000000 00000000611 13022740610 0015476 0 ustar 00root root 0000000 0000000 ;;; elm-imenu.el --- imenu support for elm
;;; Commentary:
;;; Code:
(require 'imenu)
(defun elm-imenu-create-index ()
"Create an imenu index for the current buffer."
(save-excursion
(imenu--generic-function
'((nil "^type \\([A-Z][^ \n]+\\)" 1)
(nil "^type alias \\([A-Z][^ \n]+\\)" 1)
(nil "^\\([^ ]+\\) :" 1)))))
(provide 'elm-imenu)
;;; elm-imenu.el ends here
elm-mode-0.20.3/elm-indent.el 0000664 0000000 0000000 00000154075 13022740610 0015660 0 ustar 00root root 0000000 0000000 ;;; elm-indent.el --- "semi-intelligent" indentation module for Elm Mode
;; Copyright 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
;; Copyright 1997-1998 Guy Lapalme
;; Copyright 2015 Bogdan Popa
;; Author: 1997-1998 Guy Lapalme
;; Keywords: indentation Elm layout-rule
;; Version: 1.2
;; URL: http://www.iro.umontreal.ca/~lapalme/layout/index.html
;; This file is not part of GNU Emacs.
;; This file was adapted from `haskell-indent.el'.
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see .
;;; Commentary:
;;; Code:
(require 's)
(with-no-warnings
(require 'cl))
;;; Customizations
(defgroup elm-indent nil
"Elm indentation."
:group 'elm
:link '(custom-manual "(elm-mode)Indentation")
:prefix "elm-indent-")
(defcustom elm-indent-offset 4
"Indentation of Elm statements with respect to containing block."
:type 'integer
:group 'elm-indent)
(defcustom elm-indent-rhs-align-column 0
"Column on which to align right-hand sides (use 0 for ad-hoc alignment)."
:type 'integer
:group 'elm-indent)
(defcustom elm-indent-look-past-empty-line t
"If nil, indentation engine will not look past an empty line for layout points."
:group 'elm-indent
:type 'boolean)
(defcustom elm-indent-thenelse 0
"If non-zero, \"then\" and \"else\" are indented by that amount."
:group 'elm-indent
:type 'integer)
(defcustom elm-indent-after-keywords
`(("of" ,elm-indent-offset)
("in" ,elm-indent-offset 0)
("{" ,elm-indent-offset)
"if"
"then"
"else"
"let")
"Keywords after which indentation should be indented by some offset.
Each keyword info can have the following forms:
KEYWORD | (KEYWORD OFFSET [OFFSET-HANGING])
If absent OFFSET-HANGING defaults to OFFSET.
If absent OFFSET defaults to `elm-indent-offset'.
OFFSET-HANGING is the offset to use in the case where the keyword
is at the end of an otherwise-non-empty line."
:set-after '(elm-indent-offset)
:group 'elm-indent
:type '(repeat (choice string
(cons :tag "" (string :tag "keyword:")
(cons :tag "" (integer :tag "offset")
(choice (const nil)
(list :tag ""
(integer :tag "offset-pending"))))))))
(defcustom elm-indent-dont-hang '("(")
"Lexemes that should never be considered as hanging."
:group 'elm-indent
:type '(repeat string))
;;; Internals
(defconst elm-indent-start-keywords-re
(concat "\\<"
(regexp-opt '("module" "import" "type" "infix" "infixl" "infixr") t)
"\\>")
"Regexp for keywords to complete when standing at the first word of a line.")
(defvar elm-indent-off-side-keywords-re
(concat "\\<"
(regexp-opt '("let"))
"\\>[ \t]*"))
(defvar elm-indent-last-info nil)
(defvar elm-indent-info)
(defvar elm-indent-current-line-first-ident ""
"Global variable that keeps track of the first ident of the line to indent.")
(defvar elm-indent-inhibit-after-offset nil)
(defun elm-indent-point-to-col (apoint)
"Return the column number of APOINT."
(save-excursion
(goto-char apoint)
(current-column)))
(defun elm-indent-push-col (col &optional name)
"Push indentation information for the column COL.
The info is followed by NAME (if present).
Makes sure that the same indentation info is not pushed twice.
Uses free var `elm-indent-info'."
(let ((tmp (cons col name)))
(if (member tmp elm-indent-info)
elm-indent-info
(push tmp elm-indent-info))))
(defun elm-indent-push-pos (pos &optional name)
"Push indentation information for POS followed by NAME (if present)."
(elm-indent-push-col (elm-indent-point-to-col pos) name))
(defun elm-indent-column+offset (column offset)
(unless offset (setq offset elm-indent-offset))
(setq column (+ column offset)))
(defun elm-indent-push-pos-offset (pos &optional offset)
"Pushes indentation information for the column corresponding to POS
followed by an OFFSET (if present use its value otherwise use
`elm-indent-offset')."
(elm-indent-push-col (elm-indent-column+offset
(elm-indent-point-to-col pos)
offset)))
(defun elm-indent-empty-line-p ()
"Checks if the current line is empty; deals with Bird style scripts."
(save-excursion
(beginning-of-line)
(looking-at "[ \t]*$")))
(defun elm-indent-skip-blanks-and-newlines-forward (end)
"Skip forward blanks, tabs and newlines until END."
(skip-chars-forward " \t\n" end))
(defun elm-indent-skip-blanks-and-newlines-backward (start)
"Skip backward blanks, tabs and newlines up to START."
(skip-chars-backward " \t\n" start))
(defun elm-indent-start-of-def ()
"Return the position of the start of a definition.
The start of a def is expected to be recognizable by starting in column 0,
unless `elm-indent-look-past-empty-line' is nil, in which case we
take a coarser approximation and stop at the first empty line."
(save-excursion
(let ((start-code nil)
(top-col 0)
(save-point (point)))
;; determine the starting point of the current piece of code
(setq start-code (if start-code (1+ start-code) (point-min)))
;; go backward until the first preceding empty line
(forward-line -1)
(while (and (if elm-indent-look-past-empty-line
(or (> (current-indentation) top-col)
(elm-indent-empty-line-p))
(and (> (current-indentation) top-col)
(not (elm-indent-empty-line-p))))
(> (point) start-code)
(= 0 (forward-line -1))))
;; go forward after the empty line
(if (elm-indent-empty-line-p)
(forward-line 1))
(setq start-code (point))
;; find the first line of code which is not a comment
(forward-comment (point-max))
(if (> (point) save-point)
start-code
(point)))))
(defun elm-indent-open-structure (start end)
"If any structure (list or tuple) is not closed, between START and END,
returns the location of the opening symbol, nil otherwise."
(save-excursion
(nth 1 (parse-partial-sexp start end))))
(defun elm-indent-in-string (start end)
"If a string is not closed , between START and END, returns the
location of the opening symbol, nil otherwise."
(save-excursion
(let ((pps (parse-partial-sexp start end)))
(if (nth 3 pps) (nth 8 pps)))))
(defun elm-indent-in-comment (start end)
"Check, starting from START, if END is at or within a comment.
Returns the location of the start of the comment, nil otherwise."
(when (<= start end)
(let (pps)
(cond ((= start end) nil)
((nth 4 (save-excursion (setq pps (parse-partial-sexp start end))))
(nth 8 pps))
;; We also want to say that we are *at* the beginning of a comment.
((and (not (nth 8 pps))
(>= (point-max) (+ end 2))
(nth 4 (save-excursion
(setq pps (parse-partial-sexp end (+ end 2))))))
(nth 8 pps))))))
(defun elm-indent-type-at-point ()
"Return the type of the line (also puts information in `match-data')."
(cond
((elm-indent-empty-line-p) 'empty)
((elm-indent-in-comment (point-min) (point)) 'comment)
((looking-at "\\(\\([[:alpha:]]\\(\\sw\\|'\\)*\\)\\|_\\)[ \t\n]*") 'ident)
((looking-at "\\(|[^|]\\)[ \t\n]*") 'guard)
((looking-at "\\(=[^>=]\\|:[^:]\\|->\\|<-\\)[ \t\n]*") 'rhs)
(t 'other)))
(defun elm-indent-contour-line (start end)
"Generate contour information between START and END points."
(if (< start end)
(save-excursion
(goto-char end)
(elm-indent-skip-blanks-and-newlines-backward start)
(let ((cur-col (current-column)) ; maximum column number
(fl 0) ; number of lines that forward-line could not advance
contour)
(while (and (> cur-col 0) (= fl 0) (>= (point) start))
(back-to-indentation)
(if (< (point) start) (goto-char start))
(and (not (member (elm-indent-type-at-point)
'(empty comment))) ; skip empty and comment lines
(< (current-column) cur-col) ; less indented column found
(push (point) contour) ; new contour point found
(setq cur-col (current-column)))
(setq fl (forward-line -1)))
contour))))
(defun elm-indent-next-symbol (end)
"Move point to the next symbol."
(skip-syntax-forward ")" end)
(if (< (point) end)
(progn
(forward-sexp 1)
(elm-indent-skip-blanks-and-newlines-forward end))))
(defun elm-indent-next-symbol-safe (end)
"Puts point to the next following symbol, or to end if there are no more symbols in the sexp."
(condition-case errlist (elm-indent-next-symbol end)
(error (goto-char end))))
(defun elm-indent-separate-valdef (start end)
"Return a list of positions for important parts of a valdef."
(save-excursion
(let (valname valname-string aft-valname
guard aft-guard
rhs-sign aft-rhs-sign
type)
;; "parse" a valdef separating important parts
(goto-char start)
(setq type (elm-indent-type-at-point))
(if (or (memq type '(ident other))) ; possible start of a value def
(progn
(if (eq type 'ident)
(progn
(setq valname (match-beginning 0))
(setq valname-string (match-string 0))
(goto-char (match-end 0)))
(skip-chars-forward " \t" end)
(setq valname (point)) ; type = other
(elm-indent-next-symbol-safe end))
(while (and (< (point) end)
(setq type (elm-indent-type-at-point))
(or (memq type '(ident other))))
(if (null aft-valname)
(setq aft-valname (point)))
(elm-indent-next-symbol-safe end))))
(if (and (< (point) end) (eq type 'guard)) ; start of a guard
(progn
(setq guard (match-beginning 0))
(goto-char (match-end 0))
(while (and (< (point) end)
(setq type (elm-indent-type-at-point))
(not (eq type 'rhs)))
(if (null aft-guard)
(setq aft-guard (point)))
(elm-indent-next-symbol-safe end))))
(if (and (< (point) end) (eq type 'rhs)) ; start of a rhs
(progn
(setq rhs-sign (match-beginning 0))
(goto-char (match-end 0))
(if (< (point) end)
(setq aft-rhs-sign (point)))))
(list valname valname-string aft-valname
guard aft-guard rhs-sign aft-rhs-sign))))
(defsubst elm-indent-no-otherwise (guard)
"Check if there is no otherwise at GUARD."
(save-excursion
(goto-char guard)
(not (looking-at "|[ \t]*otherwise\\>"))))
(defun elm-indent-guard (start end end-visible indent-info)
"Find indentation information for a line starting with a guard."
(save-excursion
(let* ((elm-indent-info indent-info)
(sep (elm-indent-separate-valdef start end))
(valname (nth 0 sep))
(guard (nth 3 sep))
(rhs-sign (nth 5 sep)))
;; push information indentation for the visible part
(if (and guard (< guard end-visible) (elm-indent-no-otherwise guard))
(elm-indent-push-pos guard)
(if rhs-sign
(elm-indent-push-pos rhs-sign) ; probably within a data definition...
(if valname
(elm-indent-push-pos-offset valname))))
elm-indent-info)))
(defun elm-indent-rhs (start end end-visible indent-info)
"Find indentation information for a line starting with a rhs."
(save-excursion
(let* ((elm-indent-info indent-info)
(sep (elm-indent-separate-valdef start end))
(valname (nth 0 sep))
(guard (nth 3 sep))
(rhs-sign (nth 5 sep)))
;; push information indentation for the visible part
(if (and rhs-sign (< rhs-sign end-visible))
(elm-indent-push-pos rhs-sign)
(if (and guard (< guard end-visible))
(elm-indent-push-pos-offset guard)
(if valname ; always visible !!
(elm-indent-push-pos-offset valname))))
elm-indent-info)))
(defconst elm-indent-decision-table
(let ((or "\\)\\|\\("))
(concat "\\("
"1.1.11" or ; 1= vn gd rh arh
"1.1.10" or ; 2= vn gd rh
"1.1100" or ; 3= vn gd agd
"1.1000" or ; 4= vn gd
"1.0011" or ; 5= vn rh arh
"1.0010" or ; 6= vn rh
"110000" or ; 7= vn avn
"100000" or ; 8= vn
"001.11" or ; 9= gd rh arh
"001.10" or ;10= gd rh
"001100" or ;11= gd agd
"001000" or ;12= gd
"000011" or ;13= rh arh
"000010" or ;14= rh
"000000" ;15=
"\\)")))
(defun elm-indent-find-case (test)
"Find the index that matches TEST in the decision table."
(if (string-match elm-indent-decision-table test)
;; use the fact that the resulting match-data is a list of the form
;; (0 6 [2*(n-1) nil] 0 6) where n is the number of the matching regexp
;; so n= ((length match-data)/2)-1
(- (/ (length (match-data 'integers)) 2) 1)
(error "elm-indent-find-case: impossible case: %s" test)))
(defun elm-indent-after-list-item-p ()
(with-no-warnings
;; HACK: we depend on open being dynamically bound while handling
;; indentation inside of a parenthesized expression.
(when open
(or (eq (char-after open) ?\()
(eq (char-after open) ?\[)))))
(defun elm-indent-empty (start end end-visible indent-info)
"Find indentation points for an empty line."
(save-excursion
(let* ((elm-indent-info indent-info)
(sep (elm-indent-separate-valdef start end))
(valname (pop sep))
(valname-string (pop sep))
(aft-valname (pop sep))
(guard (pop sep))
(aft-guard (pop sep))
(rhs-sign (pop sep))
(aft-rhs-sign (pop sep))
(last-line (= end end-visible))
(test (string
(if valname ?1 ?0)
(if (and aft-valname (< aft-valname end-visible)) ?1 ?0)
(if (and guard (< guard end-visible)) ?1 ?0)
(if (and aft-guard (< aft-guard end-visible)) ?1 ?0)
(if (and rhs-sign (< rhs-sign end-visible)) ?1 ?0)
(if (and aft-rhs-sign (< aft-rhs-sign end-visible)) ?1 ?0))))
(if (and valname-string ; special case for start keywords
(string-match elm-indent-start-keywords-re valname-string))
(progn
(elm-indent-push-pos valname)
;; Special case for `type' declarations.
(if (string-match "\\" valname-string)
(elm-indent-push-pos-offset valname)
(elm-indent-push-pos-offset valname 0)))
(case ; general case
(elm-indent-find-case test)
;; "1.1.11" 1= vn gd rh arh
(1 (elm-indent-push-pos valname)
(elm-indent-push-pos valname valname-string)
(if (elm-indent-no-otherwise guard) (elm-indent-push-pos guard "| "))
(elm-indent-push-pos aft-rhs-sign))
;; "1.1.10" 2= vn gd rh
(2 (elm-indent-push-pos valname)
(elm-indent-push-pos valname valname-string)
(if last-line
(elm-indent-push-pos-offset guard)
(if (elm-indent-no-otherwise guard) (elm-indent-push-pos guard "| "))))
;; "1.1100" 3= vn gd agd
(3 (elm-indent-push-pos valname)
(elm-indent-push-pos aft-guard)
(if last-line (elm-indent-push-pos-offset valname)))
;; "1.1000" 4= vn gd
(4 (elm-indent-push-pos valname)
(if last-line (elm-indent-push-pos-offset guard 2)))
;; "1.0011" 5= vn rh arh
(5 (elm-indent-push-pos valname)
(if (or (and aft-valname (= (char-after rhs-sign) ?\=))
(= (char-after rhs-sign) ?\:))
(elm-indent-push-pos valname valname-string))
(elm-indent-push-pos aft-rhs-sign))
;; "1.0010" 6= vn rh
(6 (elm-indent-push-pos valname)
(elm-indent-push-pos valname valname-string)
(if last-line (elm-indent-push-pos-offset valname)))
;; "110000" 7= vn avn
(7 (elm-indent-push-pos valname)
(elm-indent-push-pos-offset valname))
;; "100000" 8= vn
(8 (if (elm-indent-after-list-item-p)
(progn
(elm-indent-push-pos valname)
(elm-indent-push-pos-offset valname))
(elm-indent-push-pos valname)
(elm-indent-push-pos-offset valname)))
;; "001.11" 9= gd rh arh
(9 (if (elm-indent-no-otherwise guard) (elm-indent-push-pos guard "| "))
(elm-indent-push-pos aft-rhs-sign))
;; "001.10" 10= gd rh
(10 (if (elm-indent-no-otherwise guard) (elm-indent-push-pos guard "| "))
(if last-line (elm-indent-push-pos-offset guard)))
;; "001100" 11= gd agd
(11 (if (elm-indent-no-otherwise guard) (elm-indent-push-pos guard "|> "))
(elm-indent-push-pos aft-guard))
;; "001000" 12= gd
(12 (if (elm-indent-no-otherwise guard) (elm-indent-push-pos guard "|> "))
(if last-line (elm-indent-push-pos-offset guard 2)))
;; "000011" 13= rh arh
(13 (elm-indent-push-pos aft-rhs-sign))
;; "000010" 14= rh
(14 (if last-line (elm-indent-push-pos-offset rhs-sign 2 )))
;; "000000" 15=
(t (error "elm-indent-empty: %s impossible case" test ))))
elm-indent-info)))
(defun elm-indent-ident (start end end-visible indent-info)
"Find indentation points for a line starting with an identifier."
(save-excursion
(let*
((elm-indent-info indent-info)
(sep (elm-indent-separate-valdef start end))
(valname (pop sep))
(valname-string (pop sep))
(aft-valname (pop sep))
(guard (pop sep))
(aft-guard (pop sep))
(rhs-sign (pop sep))
(aft-rhs-sign (pop sep))
(last-line (= end end-visible))
(is-where
(string-match "where[ \t]*" elm-indent-current-line-first-ident))
(diff-first ; not a function def with the same name
(or (null valname-string)
(not (string= (s-trim valname-string)
(s-trim elm-indent-current-line-first-ident)))))
;; (is-type-def
;; (and rhs-sign (eq (char-after rhs-sign) ?\:)))
(test (string
(if valname ?1 ?0)
(if (and aft-valname (< aft-valname end-visible)) ?1 ?0)
(if (and guard (< guard end-visible)) ?1 ?0)
(if (and aft-guard (< aft-guard end-visible)) ?1 ?0)
(if (and rhs-sign (< rhs-sign end-visible)) ?1 ?0)
(if (and aft-rhs-sign (< aft-rhs-sign end-visible)) ?1 ?0))))
(if (and valname-string ; special case for start keywords
(string-match elm-indent-start-keywords-re valname-string))
(progn
(elm-indent-push-pos valname)
(if (string-match "\\" valname-string)
;; Special case for `type' declarations.
(elm-indent-push-pos-offset valname)
(if (not (string-match
elm-indent-start-keywords-re
elm-indent-current-line-first-ident))
(elm-indent-push-pos-offset valname))))
(if (string= elm-indent-current-line-first-ident ":")
(if valname (elm-indent-push-pos valname))
(case ; general case
(elm-indent-find-case test)
;; "1.1.11" 1= vn gd rh arh
(1 (if is-where
(elm-indent-push-pos guard)
(elm-indent-push-pos valname)
(if diff-first (elm-indent-push-pos aft-rhs-sign))))
;; "1.1.10" 2= vn gd rh
(2 (if is-where
(elm-indent-push-pos guard)
(elm-indent-push-pos valname)
(if last-line
(elm-indent-push-pos-offset guard))))
;; "1.1100" 3= vn gd agd
(3 (if is-where
(elm-indent-push-pos-offset guard)
(elm-indent-push-pos valname)
(if diff-first
(elm-indent-push-pos aft-guard))))
;; "1.1000" 4= vn gd
(4 (if is-where
(elm-indent-push-pos guard)
(elm-indent-push-pos valname)
(if last-line
(elm-indent-push-pos-offset guard 2))))
;; "1.0011" 5= vn rh arh
(5 (if is-where
(elm-indent-push-pos-offset valname)
(elm-indent-push-pos valname)
(if diff-first
(elm-indent-push-pos aft-rhs-sign))))
;; "1.0010" 6= vn rh
(6 (elm-indent-push-pos valname)
(elm-indent-push-pos valname valname-string)
(if last-line (elm-indent-push-pos-offset valname)))
;; "110000" 7= vn avn
(7 (elm-indent-push-pos valname)
(elm-indent-push-pos-offset valname))
;; "100000" 8= vn
(8 (elm-indent-push-pos valname)
(elm-indent-push-pos-offset valname))
;; "001.11" 9= gd rh arh
(9 (if is-where
(elm-indent-push-pos guard)
(elm-indent-push-pos aft-rhs-sign)))
;; "001.10" 10= gd rh
(10 (if is-where
(elm-indent-push-pos guard)
(if last-line
(elm-indent-push-pos-offset guard))))
;; "001100" 11= gd agd
(11 (if is-where
(elm-indent-push-pos guard)
(if (elm-indent-no-otherwise guard)
(elm-indent-push-pos aft-guard))))
;; "001000" 12= gd
(12 (if last-line (elm-indent-push-pos-offset guard 2)))
;; "000011" 13= rh arh
(13 (elm-indent-push-pos aft-rhs-sign))
;; "000010" 14= rh
(14 (if last-line (elm-indent-push-pos-offset rhs-sign 2)))
;; "000000" 15=
(t (error "elm-indent-ident: %s impossible case" test )))))
elm-indent-info)))
(defun elm-indent-other (start end end-visible indent-info)
"Find indentation points for a non-empty line starting with something other
than an identifier, a guard or rhs."
(save-excursion
(let* ((elm-indent-info indent-info)
(sep (elm-indent-separate-valdef start end))
(valname (pop sep))
(valname-string (pop sep))
(aft-valname (pop sep))
(guard (pop sep))
(aft-guard (pop sep))
(rhs-sign (pop sep))
(aft-rhs-sign (pop sep))
(last-line (= end end-visible))
(test (string
(if valname ?1 ?0)
(if (and aft-valname (< aft-valname end-visible)) ?1 ?0)
(if (and guard (< guard end-visible)) ?1 ?0)
(if (and aft-guard (< aft-guard end-visible)) ?1 ?0)
(if (and rhs-sign (< rhs-sign end-visible)) ?1 ?0)
(if (and aft-rhs-sign (< aft-rhs-sign end-visible)) ?1 ?0))))
(if (and valname-string ; special case for start keywords
(string-match elm-indent-start-keywords-re valname-string))
(elm-indent-push-pos-offset valname)
(case ; general case
(elm-indent-find-case test)
;; "1.1.11" 1= vn gd rh arh
(1 (elm-indent-push-pos aft-rhs-sign))
;; "1.1.10" 2= vn gd rh
(2 (if last-line
(elm-indent-push-pos-offset guard)
(elm-indent-push-pos-offset rhs-sign 2)))
;; "1.1100" 3= vn gd agd
(3 (elm-indent-push-pos aft-guard))
;; "1.1000" 4= vn gd
(4 (elm-indent-push-pos-offset guard 2))
;; "1.0011" 5= vn rh arh
(5 (elm-indent-push-pos valname)
(elm-indent-push-pos aft-rhs-sign))
;; "1.0010" 6= vn rh
(6 (if last-line
(elm-indent-push-pos-offset valname)
(elm-indent-push-pos-offset rhs-sign 2)))
;; "110000" 7= vn avn
(7 (elm-indent-push-pos valname)
(elm-indent-push-pos-offset valname))
;; "100000" 8= vn
(8 (elm-indent-push-pos valname))
;; "001.11" 9= gd rh arh
(9 (elm-indent-push-pos aft-rhs-sign))
;; "001.10" 10= gd rh
(10 (if last-line
(elm-indent-push-pos-offset guard)
(elm-indent-push-pos-offset rhs-sign 2)))
;; "001100" 11= gd agd
(11 (if (elm-indent-no-otherwise guard)
(elm-indent-push-pos aft-guard)))
;; "001000" 12= gd
(12 (if last-line (elm-indent-push-pos-offset guard 2)))
;; "000011" 13= rh arh
(13 (elm-indent-push-pos aft-rhs-sign))
;; "000010" 14= rh
(14 (if last-line (elm-indent-push-pos-offset rhs-sign 2)))
;; "000000" 15=
(t (error "elm-indent-other: %s impossible case" test ))))
elm-indent-info)))
(defun elm-indent-valdef-indentation (start end end-visible curr-line-type
indent-info)
"Find indentation information for a value definition."
(let ((elm-indent-info indent-info))
(if (< start end-visible)
(case curr-line-type
(empty (elm-indent-empty start end end-visible indent-info))
(ident (elm-indent-ident start end end-visible indent-info))
(guard (elm-indent-guard start end end-visible indent-info))
(rhs (elm-indent-rhs start end end-visible indent-info))
(comment (error "Comment indent should never happen"))
(other (elm-indent-other start end end-visible indent-info)))
elm-indent-info)))
(defun elm-indent-line-indentation (line-start line-end end-visible
curr-line-type indent-info)
"Compute indentation info between LINE-START and END-VISIBLE.
Separate a line of program into valdefs between offside keywords
and find indentation info for each part."
(save-excursion
;; point is (already) at line-start
(assert (eq (point) line-start))
(let ((elm-indent-info indent-info)
(start (or (elm-indent-in-comment line-start line-end)
(elm-indent-in-string line-start line-end))))
(if start ; if comment at the end
(setq line-end start)) ; end line before it
;; loop on all parts separated by off-side-keywords
(while (and (re-search-forward elm-indent-off-side-keywords-re
line-end t)
(not (or (elm-indent-in-comment line-start (point))
(elm-indent-in-string line-start (point)))))
(let ((beg-match (match-beginning 0)) ; save beginning of match
(end-match (match-end 0))) ; save end of match
;; Do not try to find indentation points if off-side-keyword at
;; the start...
(if (or (< line-start beg-match)
;; Actually, if we're looking at a "let" inside a "do", we
;; should add the corresponding indentation point.
(eq (char-after beg-match) ?l))
(setq elm-indent-info
(elm-indent-valdef-indentation line-start beg-match
end-visible
curr-line-type
elm-indent-info)))
;; ...but keep the start of the line if keyword alone on the line
(if (= line-end end-match)
(elm-indent-push-pos beg-match))
(setq line-start end-match)
(goto-char line-start)))
(elm-indent-valdef-indentation line-start line-end end-visible
curr-line-type elm-indent-info))))
(defun elm-indent-layout-indent-info (start contour-line)
(let ((elm-indent-info nil)
(curr-line-type (elm-indent-type-at-point))
line-start line-end end-visible)
(save-excursion
(if (eq curr-line-type 'ident)
(let ; guess the type of line
((sep
(elm-indent-separate-valdef
(point) (line-end-position))))
;; if the first ident is where or the start of a def
;; keep it in a global variable
(setq elm-indent-current-line-first-ident
(if (string-match "where[ \t]*" (nth 1 sep))
(nth 1 sep)
(if (nth 5 sep) ; is there a rhs-sign
(if (= (char-after (nth 5 sep)) ?\:) ;is it a typdef
":" (nth 1 sep))
"")))))
(while contour-line ; explore the contour points
(setq line-start (pop contour-line))
(goto-char line-start)
(setq line-end (line-end-position))
(setq end-visible ; visible until the column of the
(if contour-line ; next contour point
(save-excursion
(move-to-column
(elm-indent-point-to-col (car contour-line)))
(point))
line-end))
(unless (or (elm-indent-open-structure start line-start)
(elm-indent-in-comment start line-start))
(setq elm-indent-info
(elm-indent-line-indentation line-start line-end
end-visible curr-line-type
elm-indent-info)))))
elm-indent-info))
(defun elm-indent-find-matching-start (regexp limit &optional pred start)
(let ((open (elm-indent-open-structure limit (point))))
(if open (setq limit (1+ open))))
(unless start (setq start (point)))
(when (re-search-backward regexp limit t)
(let ((nestedcase (match-end 1))
(outer (or (elm-indent-in-string limit (point))
(elm-indent-in-comment limit (point))
(elm-indent-open-structure limit (point))
(if (and pred (funcall pred start)) (point)))))
(cond
(outer
(goto-char outer)
(elm-indent-find-matching-start regexp limit pred start))
(nestedcase
;; Nested case.
(and (elm-indent-find-matching-start regexp limit pred)
(elm-indent-find-matching-start regexp limit pred start)))
(t (point))))))
(defun elm-indent-comment (open start)
"Compute indent info for comments and text inside comments.
OPEN is the start position of the comment in which point is."
;; Ideally we'd want to guess whether it's commented out code or
;; whether it's text. Instead, we'll assume it's text.
(save-excursion
(if (= open (point))
;; We're actually just in front of a comment: align with following
;; code or with comment on previous line.
(let ((prev-line-info
(cond
((eq (char-after) ?\{) nil) ;Align as if it were code.
((and (forward-comment -1)
(> (line-beginning-position 3) open))
;; We're after another comment and there's no empty line
;; between us.
(list (list (elm-indent-point-to-col (point)))))
(t nil)))) ;Else align as if it were code
;; Align with following code.
(forward-comment (point-max))
;; There are several possible indentation points for this code-line,
;; but the only valid indentation point for the comment is the one
;; that the user will select for the code-line. Obviously we can't
;; know that, so we just assume that the code-line is already at its
;; proper place.
;; Strictly speaking "assume it's at its proper place" would mean
;; we'd just use (current-column), but since this is using info from
;; lines further down and it's common to reindent line-by-line,
;; we'll align not with the current indentation, but with the
;; one that auto-indentation "will" select.
(append
prev-line-info
(let ((indent-info (save-excursion
(elm-indent-indentation-info start)))
(col (current-column)))
;; Sort the indent-info so that the current indentation comes
;; out first.
(setq indent-info
(sort indent-info
(lambda (x y)
(<= (abs (- col (car x))) (abs (- col (car y)))))))
indent-info)))
;; We really are inside a comment.
(if (looking-at "-}")
(progn
(forward-char 2)
(forward-comment -1)
(list (list (1+ (elm-indent-point-to-col (point))))))
(let ((offset (if (looking-at "--?")
(- (match-beginning 0) (match-end 0)))))
(forward-line -1) ;Go to previous line.
(back-to-indentation)
(if (< (point) start) (goto-char start))
(list (list (if (and comment-start-skip (looking-at comment-start-skip))
(if offset
(+ 2 offset (elm-indent-point-to-col (point)))
(elm-indent-point-to-col (match-end 0)))
(elm-indent-point-to-col (point))))))))))
(defun elm-indent-closing-keyword (start)
(let ((open (save-excursion
(elm-indent-find-matching-start
(case (char-after)
(?i "\\<\\(?:\\(in\\)\\|let\\)\\>")
(?o "\\<\\(?:\\(of\\)\\|case\\)\\>")
(?t "\\<\\(?:\\(then\\)\\|if\\)\\>")
(?e "\\<\\(?:\\(else\\)\\|if\\)\\>"))
start))))
;; For a "hanging let/case/if at EOL" we should use a different
;; indentation scheme.
(save-excursion
(goto-char open)
(if (elm-indent-hanging-p)
(setq open (elm-indent-virtual-indentation start))))
;; FIXME: we should try and figure out if the `if' is in a `do' layout
;; before using elm-indent-thenelse.
(list (list (+ (if (memq (char-after) '(?t ?e)) elm-indent-thenelse 0)
(elm-indent-point-to-col open))))))
(defun elm-indent-skip-lexeme-forward ()
(and (zerop (skip-syntax-forward "w"))
(skip-syntax-forward "_")
(skip-syntax-forward "(")
(skip-syntax-forward ")")))
(defun elm-indent-offset-after-info ()
"Return the info from `elm-indent-after-keywords' for keyword at point."
(let ((id (buffer-substring
(point)
(save-excursion
(elm-indent-skip-lexeme-forward)
(point)))))
(or (assoc id elm-indent-after-keywords)
(car (member id elm-indent-after-keywords)))))
(defun elm-indent-hanging-p ()
;; A Hanging keyword is one that's at the end of a line except it's not at
;; the beginning of a line.
(not (or (= (current-column) (current-indentation))
(save-excursion
(let ((lexeme
(buffer-substring
(point)
(progn (elm-indent-skip-lexeme-forward) (point)))))
(or (member lexeme elm-indent-dont-hang)
(> (line-end-position)
(progn (forward-comment (point-max)) (point)))))))))
(defun elm-indent-after-keyword-column (offset-info start &optional default)
(unless offset-info
(setq offset-info (elm-indent-offset-after-info)))
(unless default (setq default elm-indent-offset))
(setq offset-info
(if elm-indent-inhibit-after-offset '(0) (cdr-safe offset-info)))
(if (not (elm-indent-hanging-p))
(elm-indent-column+offset (current-column)
(or (car offset-info) default))
;; The keyword is hanging at the end of the line.
(elm-indent-column+offset
(elm-indent-virtual-indentation start)
(or (cadr offset-info) (car offset-info) default))))
(defun elm-indent-inside-paren-update-syntax-p (open)
(let ((end (point)))
(save-excursion
(goto-char open)
(and (not (looking-at ".*="))
(progn
(forward-line)
(elm-indent-skip-blanks-and-newlines-forward end)
(eq (char-after) ?\|))))))
(defun elm-indent-inside-paren (open)
;; there is an open structure to complete
(if (looking-at "\\s)\\|[|;,]")
;; A close-paren or a , or ; can only correspond syntactically to
;; the open-paren at `open'. So there is no ambiguity.
(let* ((is-close-brace (eq (char-after) ?\}))
(inside-update (elm-indent-inside-paren-update-syntax-p open)))
(if (and (eq (char-after) ?\;) (eq (char-after open) ?\())
(message "Mismatched punctuation: `%c' in %c...%c"
(char-after) (char-after open)
(if (eq (char-after open) ?\() ?\) ?\})))
(save-excursion
(goto-char open)
(list (list
(if (elm-indent-hanging-p)
(elm-indent-virtual-indentation nil)
(if (and inside-update
(not is-close-brace)
(eq (char-after open) ?\{))
(elm-indent-point-to-col (+ elm-indent-offset open))
(elm-indent-point-to-col open)))))))
;; There might still be layout within the open structure.
(let* ((end (point))
(basic-indent-info
;; Anything else than a ) is subject to layout.
(if (looking-at "\\s.\\|\\$ ")
(elm-indent-point-to-col open) ; align a punct with (
(let ((follow (save-excursion
(goto-char (1+ open))
(elm-indent-skip-blanks-and-newlines-forward end)
(point))))
(if (= follow end)
(save-excursion
(goto-char open)
(elm-indent-after-keyword-column nil nil 1))
(elm-indent-point-to-col (+ elm-indent-offset follow))))))
(open-column (elm-indent-point-to-col open))
(contour-line (elm-indent-contour-line (1+ open) end)))
(if (null contour-line)
(list (list basic-indent-info))
(let ((indent-info
(elm-indent-layout-indent-info
(1+ open) contour-line)))
;; Fix up indent info.
(let ((base-elem (assoc open-column indent-info)))
(if base-elem
(progn (setcar base-elem basic-indent-info)
(setcdr base-elem nil))
(if (not (eq basic-indent-info 0))
(setq indent-info (append (list (list basic-indent-info)) indent-info))
(setq indent-info (append indent-info (list (list basic-indent-info))))))
indent-info))))))
(defun elm-indent-virtual-indentation (start)
"Compute the \"virtual indentation\" of text at point.
The \"virtual indentation\" is the indentation that text at point would have
had, if it had been placed on its own line."
(let ((col (current-column))
(elm-indent-inhibit-after-offset (elm-indent-hanging-p)))
(if (save-excursion (skip-chars-backward " \t") (bolp))
;; If the text is indeed on its own line, than the virtual indent is
;; the current indentation.
col
;; Else, compute the indentation that it would have had.
(let ((info (elm-indent-indentation-info start))
(max -1))
;; `info' is a list of possible indent points. Each indent point is
;; assumed to correspond to a different parse. So we need to find
;; the parse that corresponds to the case at hand (where there's no
;; line break), which is assumed to always be the
;; deepest indentation.
(dolist (x info)
(setq x (car x))
;; Sometimes `info' includes the current indentation (or yet
;; deeper) by mistake, because elm-indent-indentation-info
;; wasn't designed to be called on a piece of text that is not at
;; BOL. So ignore points past `col'.
(if (and (> x max) (not (>= x col)))
(setq max x)))
;; In case all the indent points are past `col', just use `col'.
(if (>= max 0) max col)))))
(defun elm-indent-indentation-info (&optional start)
"Return a list of possible indentations for the current line.
These are then used by `elm-indent-cycle'.
START if non-nil is a presumed start pos of the current definition."
(unless start (setq start (elm-indent-start-of-def)))
(let (open contour-line)
(cond
;; in string?
((setq open (elm-indent-in-string start (point)))
(list (list (+ (elm-indent-point-to-col open)
(if (looking-at "\\\\") 0 1)))))
;; in comment ?
((setq open (elm-indent-in-comment start (point)))
(elm-indent-comment open start))
;; Closing the declaration part of a `let' or the test exp part of a case.
((looking-at "\\(?:in\\|of\\|then\\|else\\)\\>")
(elm-indent-closing-keyword start))
;; Right after a special keyword.
((save-excursion
(forward-comment (- (point-max)))
(when (and (not (zerop (skip-syntax-backward "w")))
(setq open (elm-indent-offset-after-info)))
(list (list (elm-indent-after-keyword-column open start))))))
;; open structure? ie ( { [
((setq open (elm-indent-open-structure start (point)))
(elm-indent-inside-paren open))
;; full indentation
((setq contour-line (elm-indent-contour-line start (point)))
(elm-indent-layout-indent-info start contour-line))
(t
;; simple contour just one indentation at start
(list (list (elm-indent-point-to-col start)))))))
(defun elm-indent-cycle ()
"Indentation cycle.
We stay in the cycle as long as the TAB key is pressed."
(interactive "*")
(let ((marker (if (> (current-column)
(current-indentation))
(point-marker)))
(bol (progn (beginning-of-line) (point))))
(back-to-indentation)
(unless (and (eq last-command this-command)
(eq bol (car elm-indent-last-info)))
(save-excursion
(setq elm-indent-last-info
(list bol (elm-indent-indentation-info) 0 0))))
(let* ((il (nth 1 elm-indent-last-info))
(index (nth 2 elm-indent-last-info))
(last-insert-length (nth 3 elm-indent-last-info))
(indent-info (nth index il)))
(indent-line-to (car indent-info)) ; insert indentation
(delete-char last-insert-length)
(setq last-insert-length 0)
(let ((text (cdr indent-info)))
(if text
(progn
(insert text)
(setq last-insert-length (length text)))))
(setq elm-indent-last-info
(list bol il (% (1+ index) (length il)) last-insert-length))
(if (= (length il) 1)
(message "Sole indentation")
(message "Indent cycle (%d)..." (length il)))
(if marker
(goto-char (marker-position marker))))))
(defun elm-indent-region (start end)
"Apply `elm-indent-cycle' to every line between START and END."
(save-excursion
(goto-char start)
(while (< (point) end)
(elm-indent-cycle)
(forward-line))))
;;; Alignment functions
(defun elm-indent-shift-columns (dest-column region-stack)
"Shift columns in REGION-STACK to go to DEST-COLUMN.
Elements of the stack are pairs of points giving the start and end
of the regions to move."
(let (reg col diffcol reg-end)
(while (setq reg (pop region-stack))
(setq reg-end (copy-marker (cdr reg)))
(goto-char (car reg))
(setq col (current-column))
(setq diffcol (- dest-column col))
(if (not (zerop diffcol))
(catch 'end-of-buffer
(while (<= (point) (marker-position reg-end))
(if (< diffcol 0)
(backward-delete-char-untabify (- diffcol) nil)
(insert-char ?\ diffcol))
(end-of-line 2) ; should be (forward-line 1)
(if (eobp) ; but it adds line at the end...
(throw 'end-of-buffer nil))
(move-to-column col)))))))
(defun elm-indent-align-def (p-arg type)
"Align guards or rhs within the current definition before point.
If P-ARG is t align all defs up to the mark.
TYPE is either 'guard or 'rhs."
(save-excursion
(let (start-block end-block
(maxcol (if (eq type 'rhs) elm-indent-rhs-align-column 0))
contour sep defname defnamepos
defcol pos lastpos
regstack eqns-start start-found)
;; find the starting and ending boundary points for alignment
(if p-arg
(if (mark) ; aligning everything in the region
(progn
(when (> (mark) (point)) (exchange-point-and-mark))
(setq start-block
(save-excursion
(goto-char (mark))
(line-beginning-position)))
(setq end-block
(progn (if (bolp)
(forward-line -1))
(line-end-position))))
(error "The mark is not set for aligning definitions"))
;; aligning the current definition
(setq start-block (elm-indent-start-of-def))
(setq end-block (line-end-position)))
;; find the start of the current valdef using the contour line
;; in reverse order because we need the nearest one from the end
(setq contour
(reverse (elm-indent-contour-line start-block end-block)))
(setq pos (car contour)) ; keep the start of the first contour
;; find the nearest start of a definition
(while (and (not defname) contour)
(goto-char (pop contour))
(if (elm-indent-open-structure start-block (point))
nil
(setq sep (elm-indent-separate-valdef (point) end-block))
(if (nth 5 sep) ; is there a rhs?
(progn (setq defnamepos (nth 0 sep))
(setq defname (nth 1 sep))))))
;; start building the region stack
(if defnamepos
(progn ; there is a valdef
;; find the start of each equation or guard
(if p-arg ; when indenting a region
;; accept any start of id or pattern as def name
(setq defname "\\<\\|("))
(setq defcol (elm-indent-point-to-col defnamepos))
(goto-char pos)
(setq end-block (line-end-position))
(catch 'top-of-buffer
(while (and (not start-found)
(>= (point) start-block))
(if (<= (current-indentation) defcol)
(progn
(move-to-column defcol)
(if (and (looking-at defname) ; start of equation
(not (elm-indent-open-structure start-block (point))))
(push (cons (point) 'eqn) eqns-start)
;; found a less indented point not starting an equation
(setq start-found t)))
;; more indented line
(back-to-indentation)
(if (and (eq (elm-indent-type-at-point) 'guard) ; start of a guard
(not (elm-indent-open-structure start-block (point))))
(push (cons (point) 'gd) eqns-start)))
(if (bobp)
(throw 'top-of-buffer nil)
(backward-to-indentation 1))))
;; remove the spurious guards before the first equation
(while (and eqns-start (eq (cdar eqns-start) 'gd))
(pop eqns-start))
;; go through each equation to find the region to indent
(while eqns-start
(let ((eqn (caar eqns-start)))
(setq lastpos (if (cdr eqns-start)
(save-excursion
(goto-char (caadr eqns-start))
(forward-line -1)
(line-end-position))
end-block))
(setq sep (elm-indent-separate-valdef eqn lastpos)))
(if (eq type 'guard)
(setq pos (nth 3 sep))
;; check if what follows a rhs sign is more indented or not
(let ((rhs (nth 5 sep))
(aft-rhs (nth 6 sep)))
(if (and rhs aft-rhs
(> (elm-indent-point-to-col rhs)
(elm-indent-point-to-col aft-rhs)))
(setq pos aft-rhs)
(setq pos rhs))))
(if pos
(progn ; update region stack
(push (cons pos (or lastpos pos)) regstack)
(setq maxcol ; find the highest column number
(max maxcol
(progn ;find the previous non-empty column
(goto-char pos)
(skip-chars-backward
" \t"
(line-beginning-position))
(if (bolp)
;;if on an empty prefix
(elm-indent-point-to-col pos) ;keep original indent
(1+ (elm-indent-point-to-col (point)))))))))
(pop eqns-start))
;; now shift according to the region stack
(if regstack
(elm-indent-shift-columns maxcol regstack)))))))
;;; Insertion functions
(defun elm-indent-insert-equal ()
"Insert an = sign and align the previous rhs of the current function."
(interactive "*")
(if (or (bolp)
(/= (preceding-char) ?\ ))
(insert ?\ ))
(insert "= ")
(elm-indent-align-def mark-active 'rhs))
;;; elm-indent-mode
(defvar elm-indent-mode nil
"Non-nil if the semi-intelligent Elm indentation mode is in effect.")
(make-variable-buffer-local 'elm-indent-mode)
(defvar elm-indent-map
(let ((map (make-sparse-keymap)))
(define-key map [?\C-c ?\C-=] 'elm-indent-insert-equal)
map))
;;;###autoload
(defun turn-on-elm-indent ()
"Turn on ``intelligent'' Elm indentation mode."
(set (make-local-variable 'indent-line-function) 'elm-indent-cycle)
(set (make-local-variable 'indent-region-function) 'elm-indent-region)
(setq elm-indent-mode t)
;; Activate our keymap.
(let ((map (current-local-map)))
(while (and map (not (eq map elm-indent-map)))
(setq map (keymap-parent map)))
(if map
;; elm-indent-map is already active: nothing to do.
nil
;; Put our keymap on top of the others. We could also put it in
;; second place, or in a minor-mode. The minor-mode approach would be
;; easier, but it's harder for the user to override it. This approach
;; is the closest in behavior compared to the previous code that just
;; used a bunch of local-set-key.
(set-keymap-parent elm-indent-map (current-local-map))
;; Protect our keymap.
(setq map (make-sparse-keymap))
(set-keymap-parent map elm-indent-map)
(use-local-map map)))
(run-hooks 'elm-indent-hook))
(defun turn-off-elm-indent ()
"Turn off ``intelligent'' Elm indentation mode."
(kill-local-variable 'indent-line-function)
;; Remove elm-indent-map from the local map.
(let ((map (current-local-map)))
(while map
(let ((parent (keymap-parent map)))
(if (eq elm-indent-map parent)
(set-keymap-parent map (keymap-parent parent))
(setq map parent)))))
(setq elm-indent-mode nil))
;; Put this minor mode on the global minor-mode-alist.
(or (assq 'elm-indent-mode (default-value 'minor-mode-alist))
(setq-default minor-mode-alist
(append (default-value 'minor-mode-alist)
'((elm-indent-mode " Elm Indent")))))
;;;###autoload
(defun elm-indent-mode (&optional arg)
"``Intelligent'' Elm indentation mode.
This deals with the layout rules of Elm.
\\[elm-indent-cycle] starts the cycle which proposes new
possibilities as long as the TAB key is pressed. Any other key
or mouse click terminates the cycle and is interpreted except for
RET which merely exits the cycle.
Other special keys are:
\\[elm-indent-insert-equal]
inserts an =
Invokes `elm-indent-hook' if not nil."
(interactive "P")
(setq elm-indent-mode
(if (null arg)
(not elm-indent-mode)
(> (prefix-numeric-value arg) 0)))
(if elm-indent-mode
(turn-on-elm-indent)
(turn-off-elm-indent)))
(provide 'elm-indent)
;;; elm-indent.el ends here
elm-mode-0.20.3/elm-interactive.el 0000664 0000000 0000000 00000116613 13022740610 0016710 0 ustar 00root root 0000000 0000000 ;;; elm-interactive.el --- Run an interactive Elm session. -*- lexical-binding: t -*-
;; Copyright (C) 2015, 2016 Bogdan Popa
;; Author: Bogdan Popa
;; URL: https://github.com/jcollard/elm-mode
;; This file is not part of GNU Emacs.
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see .
;;; Commentary:
;;; Code:
(require 'ansi-color)
(require 'comint)
(require 'compile)
(require 'cl-lib)
(require 'elm-font-lock)
(require 'elm-util)
(require 'f)
(require 'json)
(require 'let-alist)
(require 's)
(require 'subr-x)
(require 'tabulated-list)
(require 'url)
(defvar elm-interactive--seen-prompt nil
"Non-nil represents the fact that a prompt has been spotted.")
(make-variable-buffer-local 'elm-interactive--seen-prompt)
(defvar elm-interactive--current-project nil)
(defvar elm-interactive--process-name "elm")
(defvar elm-interactive--buffer-name "*elm*")
(defvar elm-reactor--process-name "elm-reactor")
(defvar elm-reactor--buffer-name "*elm-reactor*")
(defcustom elm-interactive-command "elm-repl"
"The Elm REPL command."
:type '(string)
:group 'elm)
(defcustom elm-interactive-arguments '()
"Command line arguments to pass to the Elm REPL command."
:type '(repeat string)
:group 'elm)
(defvar elm-interactive-prompt-regexp "^[>|] "
"Prompt for `run-elm-interactive'.")
(defcustom elm-reactor-command "elm-reactor"
"The Elm Reactor command."
:type '(string)
:group 'elm)
(defcustom elm-reactor-port "8000"
"The Elm Reactor port."
:type '(string)
:group 'elm)
(defcustom elm-reactor-address "127.0.0.1"
"The Elm Reactor address."
:type '(string)
:group 'elm)
(defcustom elm-reactor-arguments `("-p" ,elm-reactor-port "-a" ,elm-reactor-address)
"Command line arguments to pass to the Elm Reactor command."
:type '(repeat string)
:group 'elm)
(defvar elm-compile--buffer-name "*elm-make*")
(defcustom elm-compile-command "elm-make"
"The Elm compilation command."
:type '(string)
:group 'elm)
(defcustom elm-compile-arguments '("--yes" "--warn" "--output=elm.js")
"Command line arguments to pass to the Elm compilation command."
:type '(repeat string)
:group 'elm)
(defvar elm-compile-error-regexp-alist-alist
'((elm-file "-- [^-]+ -+ \\(.+\\)$" 1 nil)
(elm-line "^\\([0-9]+\\)|" nil 1))
"Regexps to match Elm compiler errors in compilation buffer.")
(defvar elm-compile-error-regexp-alist '(elm-line elm-file))
(dolist (alist elm-compile-error-regexp-alist-alist)
(add-to-list 'compilation-error-regexp-alist-alist alist))
(dolist (symbol elm-compile-error-regexp-alist)
(add-to-list 'compilation-error-regexp-alist symbol))
(defcustom elm-create-package-command "elm make --yes"
"The command that is used to initialize a new package definition."
:type '(string)
:group 'elm)
(defvar elm-package--contents nil
"The contents of the Elm package catalog.")
(defvar elm-package--dependencies nil
"The package dependencies for the current Elm package.")
(defvar elm-package--cache nil
"A cache for extended package information.")
(defvar elm-package--marked-contents nil)
(defvar elm-package--working-dir nil)
(defvar elm-package-compile-buffer-name "*elm-package-compile*")
(defvar elm-package-buffer-name "*elm-package*")
(defcustom elm-package-command "elm-package"
"The Elm package command."
:type '(string)
:group 'elm)
(defcustom elm-package-arguments '("install" "--yes")
"Command line arguments to pass to the Elm package command."
:type '(repeat string)
:group 'elm)
(defcustom elm-package-catalog-root
"http://package.elm-lang.org/"
"The root URI for the Elm package catalog."
:type '(string)
:group 'elm)
(defvar elm-package-catalog-format
[(" " 1 nil)
("Name" 30 t)
("Version" 7 nil)
("Status" 10 t)
("Summary" 80 nil)]
"The format of the package list header.")
(defvar elm-interactive-mode-map
(let ((map (make-keymap)))
(define-key map "\t" #'completion-at-point)
(define-key map (kbd "C-a") #'elm-interactive-mode-beginning)
map)
"Keymap for Elm interactive mode.")
(defcustom elm-oracle-command "elm-oracle"
"The Elm Oracle command."
:type '(string)
:group 'elm)
(defconst elm-oracle--pattern
"\\(?:[^A-Za-z0-9_.']\\)\\(\\(?:[A-Za-z_][A-Za-z0-9_']*[.]\\)?[A-Za-z0-9_']*\\)"
"The prefix pattern used for completion.")
(defvar elm-oracle--completion-cache (make-hash-table :test #'equal)
"A cache for Oracle-based completions by prefix.")
(defvar elm-oracle--eldoc-cache (make-hash-table :test #'equal)
"A cache for Eldoc completions.")
(defcustom elm-sort-imports-on-save nil
"Controls whether or not imports should be automaticaly reordered on save."
:type 'boolean
:group 'elm)
(defvar elm-package-mode-map
(let ((map (make-keymap)))
(define-key map "g" #'elm-package-refresh)
(define-key map "n" #'elm-package-next)
(define-key map "p" #'elm-package-prev)
(define-key map "v" #'elm-package-view)
(define-key map "m" #'elm-package-mark)
(define-key map "i" #'elm-package-mark)
(define-key map "u" #'elm-package-unmark)
(define-key map "x" #'elm-package-install)
map)
"Keymap for Elm package mode.")
(defun elm-interactive-mode-beginning ()
"Go to the start of the line."
(interactive)
(beginning-of-line)
(goto-char (+ 2 (point))))
(defun elm-interactive--get-process-buffer ()
"Get the REPL process buffer."
(get-buffer-process elm-interactive--buffer-name))
(defun elm-interactive--spot-prompt (_string)
"Spot the prompt, _STRING is ignored."
(let ((proc (elm-interactive--get-process-buffer)))
(when proc
(save-excursion
(goto-char (process-mark proc))
(if (re-search-backward comint-prompt-regexp
(line-beginning-position) t)
(setq elm-interactive--seen-prompt t))))))
(defun elm-interactive--wait-for-prompt (proc &optional timeout)
"Wait until PROC sends us a prompt or TIMEOUT.
The process PROC should be associated to a comint buffer.
Stolen from haskell-mode."
(with-current-buffer (process-buffer proc)
(while (progn
(goto-char comint-last-input-end)
(not (or elm-interactive--seen-prompt
(setq elm-interactive--seen-prompt
(re-search-forward comint-prompt-regexp nil t))
(not (accept-process-output proc timeout))))))
(unless elm-interactive--seen-prompt
(error "Can't find the prompt"))))
(defun elm-interactive--send-command (command)
"Send a COMMAND to the REPL."
(let ((proc (elm-interactive--get-process-buffer)))
(with-current-buffer (process-buffer proc)
(elm-interactive--wait-for-prompt proc 10)
(goto-char (process-mark proc))
(insert-before-markers command)
(move-marker comint-last-input-end (point))
(setq elm-interactive--seen-prompt nil)
(comint-send-string proc command))))
(defun elm-interactive-kill-current-session ()
"Stop the current REPL session and delete its buffer."
(interactive)
(when (and elm-interactive--current-project
(get-buffer-process elm-interactive--buffer-name)
(not (equal elm-interactive--current-project (elm--find-dependency-file-path)))
(y-or-n-p "This will kill your existing REPL session. Continue? "))
(delete-process elm-interactive--buffer-name)
(kill-buffer elm-interactive--buffer-name)))
;;;###autoload
(define-derived-mode elm-interactive-mode comint-mode "Elm Interactive"
"Major mode for `run-elm-interactive'.
\\{elm-interactive-mode-map}"
(setq-local comint-prompt-regexp elm-interactive-prompt-regexp)
(setq-local comint-prompt-read-only t)
(setq-local comint-use-prompt-regexp t)
(add-hook 'comint-output-filter-functions #'elm-interactive--spot-prompt nil t)
(turn-on-elm-font-lock))
;;;###autoload
(defun run-elm-interactive ()
"Run an inferior instance of `elm-repl' inside Emacs."
(interactive)
(elm-interactive-kill-current-session)
(let* ((default-directory (elm--find-dependency-file-path))
(buffer (comint-check-proc elm-interactive--process-name)))
(setq elm-interactive--current-project default-directory)
(pop-to-buffer
(if (or buffer (not (derived-mode-p 'elm-interactive-mode))
(comint-check-proc (current-buffer)))
(get-buffer-create (or buffer elm-interactive--buffer-name))
(current-buffer)))
(unless buffer
(apply #'make-comint-in-buffer elm-interactive--process-name buffer
elm-interactive-command nil elm-interactive-arguments)
(elm-interactive-mode))))
;;;###autoload
(defun elm-repl-load ()
"Load an interactive REPL if there isn't already one running.
Changes the current root directory to be the directory with the closest
package json if one exists otherwise sets it to be the working directory
of the file specified."
(interactive)
(save-buffer)
(let ((import-statement (elm--build-import-statement)))
(run-elm-interactive)
(elm-interactive--send-command ":reset\n")
(elm-interactive--send-command import-statement)))
;;;###autoload
(defun elm-repl-push (beg end)
"Push the region from BEG to END to an interactive REPL."
(interactive "r")
(let* ((to-push (buffer-substring-no-properties beg end))
(lines (split-string (s-trim-right to-push) "\n")))
(run-elm-interactive)
(dolist (line lines)
(elm-interactive--send-command (concat line " \\\n")))
(elm-interactive--send-command "\n")))
;;;###autoload
(defun elm-repl-push-decl ()
"Push the current top level declaration to the REPL."
(interactive)
(let ((lines (elm--get-decl)))
(run-elm-interactive)
(dolist (line lines)
(elm-interactive--send-command (concat line " \\\n")))
(elm-interactive--send-command "\n")))
;;; Reactor:
;;;###autoload
(defun run-elm-reactor ()
"Run the Elm reactor process."
(interactive)
(let ((default-directory (elm--find-dependency-file-path))
(process (get-process elm-reactor--process-name)))
(when process
(delete-process process))
(apply #'start-process elm-reactor--process-name elm-reactor--buffer-name
elm-reactor-command elm-reactor-arguments)))
(defun elm-reactor--browse (path &optional debug)
"Open (reactor-relative) PATH in browser with optional DEBUG.
Runs `elm-reactor' first."
(run-elm-reactor)
(let ((qs (if debug "?debug" "")))
(browse-url (concat "http://" elm-reactor-address ":" elm-reactor-port "/" path qs))))
;;;###autoload
(defun elm-preview-buffer (debug)
"Preview the current buffer using Elm reactor (in debug mode if DEBUG is truthy)."
(interactive "P")
(let* ((fname (buffer-file-name))
(deppath (elm--find-dependency-file-path))
(path (f-relative fname deppath)))
(elm-reactor--browse path debug)))
;;;###autoload
(defun elm-preview-main (debug)
"Preview the main elm file using Elm reactor (in debug mode if DEBUG is truthy)."
(interactive "P")
(elm-reactor--browse (elm--find-main-file) debug))
;;; Make:
(defun elm-compile--command (file &optional output json)
"Generate a command that will compile FILE into OUTPUT, with or without JSON reporting."
(let* ((elm-compile-arguments
(if output
(append (cl-remove-if (apply-partially #'string-prefix-p "--output=") elm-compile-arguments)
(list (concat "--output=" (expand-file-name output))))
elm-compile-arguments))
(elm-compile-arguments
(if json
(append elm-compile-arguments (list "--report=json"))
elm-compile-arguments)))
(s-join " " (cl-list* elm-compile-command file elm-compile-arguments))))
(defun elm-compile--colorize-compilation-buffer ()
"Handle ANSI escape sequences in compilation buffer."
(read-only-mode)
(ansi-color-apply-on-region compilation-filter-start (point))
(read-only-mode))
(add-hook 'compilation-filter-hook #'elm-compile--colorize-compilation-buffer)
(defun elm-compile--file (file &optional output)
"Compile FILE into OUTPUT."
(let ((default-directory (elm--find-dependency-file-path))
(compilation-buffer-name-function (lambda (_) elm-compile--buffer-name)))
(compile (elm-compile--command file output))))
(defun elm-compile--file-json (file &optional output)
"Compile FILE into OUTPUT and return the JSON report."
(let* ((default-directory (elm--find-dependency-file-path))
(report (shell-command-to-string
(elm-compile--command file output t))))
(if (string-prefix-p "[" report)
(json-read-from-string report)
(error "Nothing to do"))))
(defun elm-compile--temporary (file)
"Compile FILE to a temporary output file and return the compilation report."
(let* ((output (make-temp-file "" nil ".js"))
(report (elm-compile--file-json file output)))
(delete-file output)
report))
;;;###autoload
(defun elm-compile-buffer (&optional output)
"Compile the current buffer into OUTPUT."
(interactive
(when current-prefix-arg
(list (read-file-name "Output to: "))))
(elm-compile--file (elm--buffer-local-file-name) output))
;;;###autoload
(defun elm-compile-main (&optional output)
"Compile the main elm file into OUTPUT."
(interactive
(when current-prefix-arg
(list (read-file-name "Output to: "))))
(elm-compile--file (elm--find-main-file) output))
(defun elm-compile--ensure-saved ()
"Ensure the current buffer has been saved."
(when (buffer-modified-p)
(if (y-or-n-p "Save current buffer? ")
(save-buffer)
(error "You must save your changes first"))))
;;;###autoload
(defun elm-compile-clean-imports (&optional prompt)
"Remove unused imports from the current buffer, PROMPT optionally before deleting."
(interactive "P")
(elm-compile--ensure-saved)
(let* ((report (elm-compile--temporary (elm--buffer-local-file-name)))
(line-offset 0))
(dolist (ob (mapcar #'identity report))
(let-alist ob
(when (equal .tag "unused import")
(save-excursion
(goto-char 0)
(forward-line (- .region.start.line 1 line-offset))
(when (or (not prompt) (y-or-n-p "Delete this import? "))
(dotimes (_ (1+ (- .region.end.line
.region.start.line)))
(kill-whole-line)
(setq line-offset (1+ line-offset))))))))))
(defconst elm-import--pattern
(cl-labels ((re-or (&rest forms)
(concat "\\(?:" (s-join "\\|" forms) "\\)"))
(re-? (&rest forms)
(concat "\\(?:" (s-join "" forms) "\\)?"))
(re-* (&rest forms)
(concat "\\(?:" (s-join "" forms) "\\)*")))
(let* ((spaces "[[:space:]\n]")
(ws (concat spaces "*"))
(ws+ (concat spaces "+"))
(upcase "[A-Z][A-Za-z0-9_]*")
(lowcase "[a-z][A-Za-z0-9_]*")
(as-form (concat ws+ "as" ws+ upcase))
(exposing-union-type
(concat upcase
(re-? ws
"("
(re-or "\\.\\." ;; expose all
(concat upcase
(re-* ws "," ws upcase)))
ws
")")))
(exposing-operator
(re-? ws "([^)]+)"))
(exposing-subform
(re-or lowcase exposing-union-type exposing-operator))
(exposing-form
(concat ws+
"exposing"
ws
"("
ws
(re-or "\\.\\." ;; expose all
(concat exposing-subform
(re-* ws "," ws exposing-subform)))
ws
")")))
(concat "^import"
ws+
(concat upcase (re-* "\\." upcase))
(re-? (re-or (concat as-form (re-? exposing-form))
(concat exposing-form (re-? as-form)))))))
"Regex to match elm import (including multiline).
Import consists of the word \"import\", real package name, and optional
\"as\" part, and \"exposing\" part, which may be ordered in either way.")
;;;###autoload
(defun elm-sort-imports ()
"Sort the import list in the current buffer."
(interactive)
(save-excursion
(goto-char (point-min))
(re-search-forward elm-import--pattern nil t)
(re-search-backward elm-import--pattern nil t)
(let* ((beg (point))
(_ (while (re-search-forward elm-import--pattern nil t)))
(end (point))
(text (buffer-substring-no-properties beg end))
(imports (mapcar 'first
(s-match-strings-all elm-import--pattern text))))
(kill-region beg end)
(insert (s-join "\n" (sort imports 'string<))))))
;;;###autoload
(defun elm-compile-add-annotations (&optional prompt)
"Add missing type annotations to the current buffer, PROMPT optionally before inserting."
(interactive "P")
(elm-compile--ensure-saved)
(let* ((report (elm-compile--temporary (elm--buffer-local-file-name)))
(line-offset 0))
(dolist (ob (mapcar #'identity report))
(let-alist ob
(when (equal .tag "missing type annotation")
;; Drop the first 2 lines from .details since they contain the warning itself.
(let ((annotation (s-join "\n" (cdr (cdr (s-split "\n" .details))))))
(goto-char 0)
(forward-line (+ line-offset (1- .region.start.line)))
(setq line-offset (1+ line-offset))
(when (or (not prompt) (y-or-n-p (format "Add annotation '%s'? " annotation)))
(princ (format "%s\n" annotation) (current-buffer)))))))))
;;; Package:
;;;###autoload
(defun elm-create-package ()
"Generate a new package definition in the current directory."
(interactive)
(when (elm--has-dependency-file)
(error "Elm-package.json already exists"))
(let* ((default-directory (elm--find-dependency-file-path)))
(message "Creating elm package definition. This might take a minute...")
(shell-command elm-create-package-command)))
(defun elm-package--build-uri (&rest segments)
"Build a URI by combining the package catalog root and SEGMENTS."
(concat elm-package-catalog-root (s-join "/" segments)))
(defun elm-package--format-entry (index entry)
"Format a package '(INDEX ENTRY) for display in the package listing."
(let-alist entry
(let ((mark (if (-contains? elm-package--marked-contents index)
"*"
""))
(button (list .name . ()))
(status (if (-contains? elm-package--dependencies .name)
"dependency"
"available")))
(list index (vector mark button (elt .versions 0) status .summary)))))
(defun elm-package--entries ()
"Return the formatted package list."
(-map-indexed #'elm-package--format-entry elm-package--contents))
(defun elm-package--get-marked-packages ()
"Get packages that are marked for installation."
(-map (lambda (id)
(let-alist (nth id elm-package--contents)
(concat .name " " (elt .versions 0))))
elm-package--marked-contents))
(defun elm-package--get-marked-install-commands ()
"Get a list of the commands required to install the marked packages."
(-map (lambda (package)
(concat elm-package-command " " (s-join " " elm-package-arguments) " " package))
(elm-package--get-marked-packages)))
(defun elm-package--read-dependencies ()
"Read the current package's dependencies."
(setq elm-package--working-dir (elm--find-dependency-file-path))
(let-alist (elm--read-dependency-file)
(setq elm-package--dependencies (-map (lambda (dep) (symbol-name (car dep)))
.dependencies))))
(defun elm-package--read-json (uri)
"Read a JSON file from a URI."
(with-current-buffer (url-retrieve-synchronously uri)
(goto-char (point-min))
(re-search-forward "^ *$")
(json-read)))
(defun elm-package--read-package ()
"Read a package from the minibuffer."
(completing-read "Package: " elm-package--dependencies nil t))
(defun elm-package--read-module (package)
"Read a module from PACKAGE from the minibuffer."
(completing-read "Module: " (elm-package-modules package) nil t))
(defun elm-package--read-module-definition (package module)
"Read a definition from PACKAGE and MODULE from the minibuffer."
(completing-read "Definition: " (elm-package-definitions package module) nil t))
(defun elm-package-refresh-package (package version)
"Refresh the cache for PACKAGE with VERSION."
(let ((documentation-uri
(elm-package--build-uri "packages" package version "documentation.json")))
(setq elm-package--cache
(cons `(,package . ,(elm-package--read-json documentation-uri))
elm-package--cache))))
(defun elm-package-latest-version (package)
"Get the latest version of PACKAGE."
(let ((package (-find (lambda (p)
(let-alist p
(equal .name package)))
elm-package--contents)))
(if (not package)
(error "Package not found")
(let-alist package
(elt .versions 0)))))
(defun elm-package--ensure-cached (package)
"Ensure that PACKAGE has been cached."
(unless (assoc package elm-package--cache)
(elm-package-refresh-package package (elm-package-latest-version package))))
(defun elm-package-modules (package)
"Get PACKAGE's module list."
(elm-package--ensure-cached package)
(sort
(mapcar (lambda (module)
(let-alist module .name))
(cdr (assoc package elm-package--cache)))
#'string<))
(defun elm-package--select-module (package module-name)
"Select a PACKAGE's MODULE-NAME from the cache."
(elm-package--ensure-cached package)
(elt (cl-remove-if-not
(lambda (module)
(let-alist module (equal module-name .name)))
(cdr (assoc package elm-package--cache))) 0))
(defun elm-package-definitions (package module-name)
"Get all of PACKAGE's MODULE-NAME's definitions."
(let-alist (elm-package--select-module package module-name)
(let* ((extract (lambda (x)
(let ((name (cdr (assq 'name x))))
(cons name nil))))
(aliases (mapcar extract .aliases))
(types (mapcar extract .types))
(values (mapcar extract .values)))
(append aliases types values))))
(defun elm-package-definition (package module-name definition-name)
"Get documentation from PACKAGE's MODULE-NAME for DEFINITION-NAME."
(let-alist (elm-package--select-module package module-name)
(elt (cl-remove-if-not
(lambda (x)
(equal definition-name (cdr (assq 'name x))))
(vconcat .aliases .types .values))
0)))
(defun elm-package-refresh ()
"Refresh the package catalog's contents."
(interactive)
(with-current-buffer elm-package-buffer-name
(elm-package--read-dependencies)
(tabulated-list-print :remember-pos)))
(defun elm-package-prev (&optional n)
"Goto (Nth) previous package."
(interactive "p")
(elm-package-next (- n))
(forward-line 0)
(forward-button 1))
(defun elm-package-next (&optional n)
"Goto (Nth) next package."
(interactive "p")
(dotimes (_ (abs n))
(let ((d (cl-signum n)))
(forward-line (if (> n 0) 1 0))
(when (eobp)
(forward-line -1))
(forward-button d))))
(defun elm-package-mark ()
"Mark the package at point."
(interactive)
(let ((id (tabulated-list-get-id)))
(when id
(setq elm-package--marked-contents (cons id elm-package--marked-contents))
(elm-package-next 1)
(elm-package-refresh))))
(defun elm-package-unmark ()
"Unmark the package at point."
(interactive)
(let ((id (tabulated-list-get-id)))
(when id
(setq elm-package--marked-contents
(-reject (lambda (x) (= id x))
elm-package--marked-contents))
(elm-package-next 1)
(elm-package-refresh))))
(defun elm-package-view ()
"View the package at point in a browser."
(interactive)
(let ((id (tabulated-list-get-id)))
(when id
(let-alist (nth id elm-package--contents)
(browse-url (elm-package--build-uri "packages" .name (elt .versions 0)))))))
(defun elm-package--install-sentinel (_proc _msg)
"Refreshes the package buffer on _PROC exit, ignoring _MSG."
(elm-package-refresh))
(defun elm-package-install ()
"Install the marked packages."
(interactive)
(unless elm-package--marked-contents
(error "Nothing to install"))
(let* ((and (elm--shell-and-command))
(command-to-run (s-join and (elm-package--get-marked-install-commands))))
(when (yes-or-no-p (concat "Install " (s-join ", " (elm-package--get-marked-packages)) " ?"))
(let* ((default-directory elm-package--working-dir)
(compilation-buffer-name-function (lambda (_) elm-package-compile-buffer-name))
(compilation-buffer (compile command-to-run)))
(setq elm-package--marked-contents nil)
(set-process-sentinel (get-buffer-process compilation-buffer)
#'elm-package--install-sentinel)))))
;;;###autoload
(defun elm-package-catalog (refresh)
"Show the package catalog, refreshing the list if REFRESH is truthy."
(interactive "P")
(elm--assert-dependency-file)
(when (or refresh (not elm-package--contents))
(elm-package-refresh-contents))
(let ((buffer (get-buffer-create elm-package-buffer-name)))
(pop-to-buffer buffer)
(elm-package--read-dependencies)
(elm-package-mode)))
;;;###autoload
(defun elm-package-refresh-contents ()
"Refresh the package list."
(interactive)
(elm--assert-dependency-file)
(let* ((all-packages (elm-package--build-uri "all-packages")))
(with-current-buffer (url-retrieve-synchronously all-packages)
(goto-char (point-min))
(re-search-forward "^ *$")
(setq elm-package--marked-contents nil)
(setq elm-package--contents (append (json-read) nil)))))
;;;###autoload
(defun elm-import (refresh)
"Import a module, refreshing if REFRESH is truthy."
(interactive "P")
(elm--assert-dependency-file)
(when (or refresh (not elm-package--contents))
(elm-package-refresh-contents))
(elm-package--read-dependencies)
(let* ((package (elm-package--read-package))
(module (elm-package--read-module package))
(statement (concat "import " module))
(statement (read-string "Import statement: " statement)))
(save-excursion
(goto-char (point-min))
(if (re-search-forward "^import " nil t)
(beginning-of-line)
(forward-line 1)
(insert "\n"))
(insert (concat statement "\n"))))
(elm-sort-imports))
(defun elm-documentation--show (documentation)
"Show DOCUMENTATION in a help buffer."
(let-alist documentation
(help-setup-xref (list #'elm-documentation--show documentation) nil)
(save-excursion
(with-help-window (help-buffer)
(with-current-buffer (help-buffer)
(point-min)
(insert (propertize .name 'face 'font-lock-function-name-face))
(when .args
(insert (concat " " (s-join " " .args))))
(when .cases
(let ((first t))
(mapc
(lambda (case)
(if first
(insert "\n = ")
(insert "\n | "))
(insert (propertize (elt case 0) 'face 'font-lock-function-name-face))
(insert (concat " " (s-join " " (elt case 1))))
(setq first nil))
.cases)))
(when .type
(insert " : ")
(insert (propertize .type 'face 'font-lock-type-face)))
(insert (concat "\n\n" (s-trim-left .comment))))))) )
;;;###autoload
(defun elm-documentation-lookup (refresh)
"Lookup the documentation for a function, refreshing if REFRESH is truthy."
(interactive "P")
(elm--assert-dependency-file)
(when (or refresh (not elm-package--contents))
(elm-package-refresh-contents))
(elm-package--read-dependencies)
(let* ((package (elm-package--read-package))
(module (elm-package--read-module package))
(definition (elm-package--read-module-definition package module))
(documentation (elm-package-definition package module definition)))
(elm-documentation--show documentation)))
;;;###autoload
(define-derived-mode elm-package-mode tabulated-list-mode "Elm Package"
"Special mode for elm-package.
\\{elm-package-mode-map}"
(buffer-disable-undo)
(setq truncate-lines t
tabulated-list-format elm-package-catalog-format
tabulated-list-entries #'elm-package--entries)
(tabulated-list-init-header)
(tabulated-list-print))
(autoload 'popup-make-item "popup")
(defun elm-oracle--completion-prefix-at-point ()
"Return the completions prefix found at point."
(save-excursion
(let* ((_ (re-search-backward elm-oracle--pattern nil t))
(beg (1+ (match-beginning 0)))
(end (match-end 0)))
(s-trim (buffer-substring-no-properties beg end)))))
(defun elm-oracle--completion-namelist (prefix &optional callback)
"Extract a list of identifier names for PREFIX. Async if CALLBACK is provided."
(cl-flet* ((names (candidates)
(-map (lambda (candidate)
(let-alist candidate
.fullName))
candidates))
(names-async (candidates)
(funcall callback (names candidates))))
(if callback
(elm-oracle--get-completions-cached prefix #'names-async)
(names (elm-oracle--get-completions-cached prefix)))))
(defun elm-oracle--completions-select (candidate)
"Search completions for CANDIDATE."
(aref (elm-oracle--get-completions-cached candidate) 0))
(defun elm-oracle--completion-docbuffer (candidate)
"Return the documentation for CANDIDATE."
(company-doc-buffer
(let-alist (elm-oracle--completions-select candidate)
(format "%s\n\n%s" .signature .comment))))
(defun elm-oracle--completion-annotation (candidate)
"Return the annotation for CANDIDATE."
(let-alist (elm-oracle--completions-select candidate)
(format " %s" .signature)))
(defun elm-oracle--completion-signature (candidate)
"Return the signature for CANDIDATE."
(let-alist (elm-oracle--completions-select candidate)
(format "%s : %s" candidate .signature)))
(defun elm-oracle--get-completions-async (command callback)
"Get completions by running COMMAND asynchronously. CALLBACK called on success."
(let ((output nil))
(cl-flet ((output-filter (_proc string)
(add-to-list 'output string))
(process-sentinel (_proc event)
(if (equal event "finished\n")
(let ((data (json-read-from-string (s-join "" (reverse output)))))
(funcall callback data)))))
(make-process
:name "elm-oracle"
:buffer "elm-oracle"
:command command
:filter #'output-filter
:sentinel #'process-sentinel
:connection-type 'pipe))))
(defun elm-oracle--get-completions-sync (command)
"Get completions by running COMMAND synchronously."
(json-read-from-string (shell-command-to-string (s-join " " command))))
(defun elm-oracle--get-completions-cached-1 (prefix &optional callback)
"Get completions for PREFIX. Async if CALLBACK is provided."
(when (not (elm--has-dependency-file))
(error "Completion only works inside Elm projects. Create one with `M-x elm-create-package RET`"))
(let* ((default-directory (elm--find-dependency-file-path))
(current-file (or (buffer-file-name) (elm--find-main-file)))
(command (list elm-oracle-command
(shell-quote-argument current-file)
(shell-quote-argument prefix))))
(cl-flet* ((cache (candidates)
(when (> (length candidates) 0)
(puthash prefix candidates elm-oracle--completion-cache)))
(cache-async (candidates)
(cache candidates)
(funcall callback candidates)))
(if callback
(if (fboundp 'make-process)
(elm-oracle--get-completions-async command #'cache-async)
;; If make-process is not available (<25.1) then we downgrade to a sync call
(cache-async (elm-oracle--get-completions-sync command)))
(cache (elm-oracle--get-completions-sync command))))))
(defun elm-oracle--filter-completions (prefix candidates)
"Filter by PREFIX a list of CANDIDATES."
(cl-remove-if-not (lambda (candidate)
(let-alist candidate
(string-prefix-p prefix .fullName)))
candidates))
(defun elm-oracle--get-completions-cached (prefix &optional callback)
"Cache and return the cached elm-oracle completions for PREFIX. Async if CALLBACK is provided."
(when (and prefix (s-contains? "." prefix))
(or (gethash prefix elm-oracle--completion-cache)
(let* ((module (car (s-split-up-to "\\." prefix 1)))
(module-candidates (gethash module elm-oracle--completion-cache)))
(cl-flet ((handle-async (candidates)
(funcall callback
(elm-oracle--filter-completions prefix candidates))))
(if callback
(if module-candidates
(handle-async module-candidates)
(elm-oracle--get-completions-cached-1 module #'handle-async))
(elm-oracle--filter-completions prefix
(or module-candidates
(elm-oracle--get-completions-cached-1 module)))))))))
(defun elm-oracle--get-completions (prefix &optional popup)
"Get elm-oracle completions for PREFIX with optional POPUP formatting."
(let* ((candidates (elm-oracle--get-completions-cached prefix))
(candidates
(-map (lambda (candidate)
(let-alist candidate
(if popup
(popup-make-item .fullName
:document (concat .signature "\n\n" .comment)
:summary .signature)
.fullName)))
candidates)))
candidates))
(defun elm-oracle--get-first-completion (item &optional callback)
"Get the first completion for ITEM. Async if CALLBACK provided."
(let* ((default-directory (elm--find-dependency-file-path))
(current-file (buffer-file-name))
(command (list elm-oracle-command current-file item)))
(cl-flet* ((select-first (candidates)
(when (> (length candidates) 0)
(elt candidates 0)))
(select-first-async (candidates)
(funcall callback (select-first candidates))))
(if callback
(elm-oracle--get-completions-async command #'select-first-async)
(select-first (json-read-from-string (shell-command-to-string (s-join " " command))))))))
(defun elm-oracle--function-at-point ()
"Get the name of the function at point."
(save-excursion
(let ((symbol (symbol-name (symbol-at-point))))
(skip-chars-forward "[A-Za-z0-9_.']")
(let* ((_ (re-search-backward elm-oracle--pattern nil t))
(beg (1+ (match-beginning 0)))
(end (match-end 0))
(item (s-trim (buffer-substring-no-properties beg end))))
(if (string-empty-p item)
symbol
item)))))
(defun elm-oracle--completion-at-point ()
"Get the Oracle completion object at point."
(elm-oracle--get-first-completion (elm-oracle--function-at-point)))
(defun elm-oracle--propertize-completion-type (completion)
"Propertize COMPLETION so that it can be displayed in the minibuffer."
(when completion
(let-alist completion
(when (and (not .error) .name)
(concat
(propertize .fullName 'face 'font-lock-function-name-face)
": "
.signature)))))
(defun elm-oracle--type-at-point ()
"Get the type of the function at point."
(elm-oracle--propertize-completion-type (elm-oracle--completion-at-point)))
;;;###autoload
(defun elm-oracle-type-at-point ()
"Print the type of the function at point to the minibuffer."
(interactive)
(let ((type (elm-oracle--type-at-point)))
(if type
(message type)
(message "Unknown type"))))
;;;###autoload
(defun elm-eldoc ()
"Get the type of the function at point for eldoc."
(let* ((name (elm-oracle--function-at-point))
(type (gethash name elm-oracle--eldoc-cache)))
(cl-flet ((cache (completion)
(when completion
(puthash name (elm-oracle--propertize-completion-type completion) elm-oracle--eldoc-cache))))
(elm-oracle--get-first-completion name #'cache)
type)))
;;;###autoload
(defun elm-oracle-doc-at-point ()
"Show the documentation of the value at point."
(interactive)
(let ((completion (elm-oracle--completion-at-point)))
(if completion
(elm-documentation--show completion)
(message "Unknown symbol"))))
;;;###autoload
(defun elm-oracle-completion-at-point-function ()
"Completion at point function for elm-oracle."
(save-excursion
(let* ((_ (re-search-backward elm-oracle--pattern nil t))
(beg (1+ (match-beginning 0)))
(end (match-end 0))
(prefix (s-trim (buffer-substring-no-properties beg end)))
(completions (elm-oracle--get-completions prefix)))
(list beg end completions :exclusive 'no))))
;;;###autoload
(defun elm-oracle-setup-completion ()
"Set up standard completion.
Add this function to your `elm-mode-hook' to enable an
elm-specific `completion-at-point' function."
(add-hook 'completion-at-point-functions
#'elm-oracle-completion-at-point-function
nil t))
(defvar ac-sources)
(defvar ac-source-elm
`((candidates . (elm-oracle--get-completions ac-prefix t))
(prefix . ,elm-oracle--pattern)))
;;;###autoload
(defun elm-oracle-setup-ac ()
"Set up auto-complete support.
Add this function to your `elm-mode-hook'."
(add-to-list 'ac-sources 'ac-source-elm))
;;;###autoload
(defun company-elm (command &optional arg &rest ignored)
"Provide completion info according to COMMAND and ARG. IGNORED is not used."
(interactive (list 'interactive))
(when (derived-mode-p 'elm-mode)
(cl-case command
(interactive (company-begin-backend 'company-elm))
(prefix
(let ((prefix (elm-oracle--completion-prefix-at-point)))
(when (s-contains? "." prefix)
prefix)))
(doc-buffer (elm-oracle--completion-docbuffer arg))
(candidates (cons :async (apply-partially #'elm-oracle--completion-namelist arg)))
(annotation (elm-oracle--completion-annotation arg))
(meta (elm-oracle--completion-signature arg)))))
;;;###autoload
(defun elm-test-project ()
"Run the elm-test command on the current project."
(interactive)
(elm--assert-dependency-file)
(let ((default-directory (elm--find-dependency-file-path))
(compilation-buffer-name-function (lambda (_) "*elm-test*")))
(compile "elm-test")))
(provide 'elm-interactive)
;;; elm-interactive.el ends here
elm-mode-0.20.3/elm-mode.el 0000664 0000000 0000000 00000007300 13022740610 0015307 0 ustar 00root root 0000000 0000000 ;;; elm-mode.el --- Major mode for Elm
;; Copyright (C) 2013, 2014 Joseph Collard
;; Copyright (C) 2015, 2016 Bogdan Popa
;; Author: Joseph Collard
;; Package-Requires: ((f "0.17") (let-alist "1.0.4") (s "1.7.0") (emacs "24"))
;; URL: https://github.com/jcollard/elm-mode
;; This file is not part of GNU Emacs.
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see .
;;; Commentary:
;;; Code:
(require 'elm-tags)
(require 'elm-format)
(require 'elm-imenu)
(require 'elm-indent)
(require 'elm-interactive)
(require 'elm-font-lock)
(defgroup elm nil
"Support for the elm programming language."
:link '(url-link :tag "Github" "https://github.com/jcollard/elm-mode")
:group 'languages)
(defun elm-mode-after-save-handler ()
"Perform various operations upon saving a buffer."
(when elm-sort-imports-on-save
(elm-sort-imports))
(when elm-tags-on-save
(elm-mode-generate-tags))
(when elm-format-on-save
(elm-mode-format-buffer))
(when (or elm-sort-imports-on-save
elm-tags-on-save
elm-format-on-save)
(let ((before-save-hook '())
(after-save-hook '()))
(basic-save-buffer))))
(defvar elm-mode-map
(let ((map (make-keymap)))
(define-key map "\C-c\C-f" 'elm-mode-format-buffer)
(define-key map "\C-c\M-t" 'elm-mode-generate-tags)
(define-key map "\C-c." 'elm-mode-goto-tag-at-point)
(define-key map "\C-c," 'pop-tag-mark)
(define-key map "\C-c\C-l" 'elm-repl-load)
(define-key map "\C-c\C-p" 'elm-repl-push)
(define-key map "\C-c\C-e" 'elm-repl-push-decl)
(define-key map "\C-c\C-a" 'elm-compile-add-annotations)
(define-key map "\C-c\C-r" 'elm-compile-clean-imports)
(define-key map "\C-c\C-c" 'elm-compile-buffer)
(define-key map "\C-c\M-c" 'elm-compile-main)
(define-key map "\C-c\M-k" 'elm-package-catalog)
(define-key map "\C-c\C-n" 'elm-preview-buffer)
(define-key map "\C-c\C-m" 'elm-preview-main)
(define-key map "\C-c\C-d" 'elm-documentation-lookup)
(define-key map "\C-c\C-i" 'elm-import)
(define-key map "\C-c\C-s" 'elm-sort-imports)
(define-key map "\C-c\C-t" 'elm-oracle-type-at-point)
(define-key map "\C-c\M-d" 'elm-oracle-doc-at-point)
(define-key map "\C-ct" 'elm-test-project)
map)
"Keymap for Elm major mode.")
;;;###autoload
(define-derived-mode elm-mode prog-mode "Elm"
"Major mode for editing Elm source code."
(setq-default indent-tabs-mode nil)
;; Elm is not generally suitable for electric indentation, since
;; there is no unambiguously correct indent level for any given
;; line.
(when (boundp 'electric-indent-inhibit)
(setq-local electric-indent-inhibit t))
(setq-local comment-start "--")
(setq-local comment-end "")
(setq-local imenu-create-index-function #'elm-imenu-create-index)
(setq-local paragraph-separate "\\(\r\t\n\\|-}\\)$")
(add-function :before-until (local 'eldoc-documentation-function) #'elm-eldoc)
(setq-local eldoc-idle-delay 0.25)
(add-hook 'after-save-hook #'elm-mode-after-save-handler nil t)
(turn-on-elm-font-lock)
(turn-on-elm-indent))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.elm\\'" . elm-mode))
(provide 'elm-mode)
;;; elm-mode.el ends here
elm-mode-0.20.3/elm-tags.el 0000664 0000000 0000000 00000004303 13022740610 0015321 0 ustar 00root root 0000000 0000000 ;;; elm-tags.el --- etags support for Elm.
;; Copyright (C) 2016 Bogdan Popa
;; Author: Bogdan Popa
;; URL: https://github.com/jcollard/elm-mode
;; This file is not part of GNU Emacs.
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see .
;;; Commentary:
;;; Code:
(require 'elm-util)
(require 'f)
(defcustom elm-tags-on-save nil
"Controls whether or not TAGS files should be generated on save."
:group 'elm-tags
:type 'boolean)
(defcustom elm-tags-exclude-elm-stuff t
"Controls whether or not sources in the `elm-stuff' directory should be excluded from the TAGS file."
:group 'elm-tags
:type 'boolean)
(defconst elm-tags-regexps
(f-join
(f-dirname load-file-name)
"elm.tags"))
;;;###autoload
(defun elm-mode-goto-tag-at-point ()
"Go to tag at point."
(interactive)
(let ((tag (find-tag-default)))
(unless tag
(user-error "No tag candidate found around point"))
(find-tag tag)))
;;;###autoload
(defun elm-mode-generate-tags ()
"Generate a TAGS file for the current project."
(interactive)
(when (elm--has-dependency-file)
(let* ((default-directory (elm--find-dependency-file-path))
(find-command "find . -type f -name \"*.elm\" -print")
(exclude-command (if elm-tags-exclude-elm-stuff
(concat find-command " | egrep -v elm-stuff")
find-command))
(etags-command (concat
exclude-command
" | etags --language=none --regex=@" elm-tags-regexps " -")))
(call-process-shell-command (concat etags-command "&") nil 0))))
(provide 'elm-tags)
;;; elm-tags.el ends here
elm-mode-0.20.3/elm-util.el 0000664 0000000 0000000 00000010663 13022740610 0015346 0 ustar 00root root 0000000 0000000 ;;; elm-utils.el --- General utility functions used by Elm mode modules.
;; Copyright (C) 2013, 2014 Joseph Collard
;; Copyright (C) 2015 Bogdan Popa
;; Author: Joseph Collard
;; URL: https://github.com/jcollard/elm-mode
;; This file is not part of GNU Emacs.
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see .
;;; Commentary:
;;; Code:
(require 'f)
(require 'json)
(require 'let-alist)
(require 's)
(require 'haskell-decl-scan nil 'noerror)
(require 'inf-haskell nil 'noerror)
(defcustom elm-main-file "Main.elm"
"Allows for a custom main file to be specified."
:type 'string
:group 'elm-util)
(defconst elm-package-json
"elm-package.json"
"The name of the package JSON configuration file.")
(defun elm--get-module-name ()
"Return the qualified name of the module in the current buffer."
(save-excursion
(goto-char (point-min))
(unless (re-search-forward "module +\\([A-Z][A-Za-z0-9.]*\\)" nil t)
(error "Module declaration not found"))
(buffer-substring-no-properties (match-beginning 1) (match-end 1))))
(defun elm--get-decl ()
"Return the current declaration.
Relies on `haskell-mode' stuff."
(unless (fboundp #'haskell-ds-backward-decl)
(error "This functionality requires haskell-mode"))
(save-excursion
(goto-char (1+ (point)))
(let* ((start (or (haskell-ds-backward-decl) (point-min)))
(end (or (haskell-ds-forward-decl) (point-max)))
(raw-decl (s-trim-right (buffer-substring start end)))
(lines (split-string raw-decl "\n"))
(first-line (car lines)))
(inferior-haskell-flash-decl start end)
(if (string-match-p "^[a-z].*:" first-line)
(cdr lines)
lines))))
(defun elm--build-import-statement ()
"Generate a statement that will import the current module."
(concat "import " (elm--get-module-name) " exposing (..) \n"))
(defun elm--get-buffer-dirname ()
"Return the absolute dirname of the current buffer."
(concat (f-dirname (buffer-file-name)) "/"))
(defun elm--buffer-local-file-name ()
"Return the current file name relative to the dependency file."
(let ((dirname (buffer-file-name))
(deppath (elm--find-dependency-file-path)))
(f-relative dirname deppath)))
(defun elm--find-dependency-file-path ()
"Recursively search for a directory containing a package JSON file."
(or (locate-dominating-file default-directory elm-package-json)
(file-name-as-directory (f-dirname (buffer-file-name)))))
(defun elm--has-dependency-file ()
"Check if a dependency file exists."
(f-exists? (f-join (elm--find-dependency-file-path) elm-package-json)))
(declare-function elm-create-package "elm-interactive.el" nil)
(defun elm--assert-dependency-file ()
"Report an error unless there is a package file."
(unless (elm--has-dependency-file)
(if (yes-or-no-p "Elm package file not found. Create a new package?")
(call-interactively #'elm-create-package)
(error "Elm package file not found"))))
(defun elm--read-dependency-file ()
"Find and read the JSON dependency file into an object."
(elm--assert-dependency-file)
(let ((dep-file (f-join (elm--find-dependency-file-path) elm-package-json)))
(json-read-file dep-file)))
(defun elm--find-main-file ()
"Find the main elm file."
(let-alist (elm--read-dependency-file)
(let ((source-dir (aref .source-directories 0)))
(if (equal "." source-dir)
elm-main-file
(f-join source-dir elm-main-file)))))
(defun elm--shell-and-command ()
"Determine the appropriate 'and' command for the current shell.
Currently only special cases the Fish shell, returning '; and ' when
Fish is used as the default system shell. Returns ' && ' in all other
cases."
;; TODO: Windows?
(let* ((shell (getenv "SHELL"))
(executable (car (reverse (s-split "/" shell)))))
(pcase executable
("fish" "; and ")
(_ " && "))))
(provide 'elm-util)
;;; elm-util.el ends here
elm-mode-0.20.3/elm.tags 0000664 0000000 0000000 00000000173 13022740610 0014724 0 ustar 00root root 0000000 0000000 /^module +\([^ ]+\)/\1/
/^ +[=|] *\([A-Z][^ ]*\)/\1/
/^\(type +alias\|type\) +\([^ ]+\)/\2/
/^\((\([^)]+\))\|[^ ]+\).*=/\1/ elm-mode-0.20.3/screenshots/ 0000775 0000000 0000000 00000000000 13022740610 0015626 5 ustar 00root root 0000000 0000000 elm-mode-0.20.3/screenshots/auto-complete.png 0000664 0000000 0000000 00000411421 13022740610 0021115 0 ustar 00root root 0000000 0000000 PNG
IHDR ^ _ iCCPICC Profile HT+) Л J
Ut *ł" V"ʺXʛ{{ys|/wwf `p