[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dape 96b1815ed3 001/123: Initial commit
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dape 96b1815ed3 001/123: Initial commit |
Date: |
Tue, 5 Dec 2023 03:57:54 -0500 (EST) |
branch: externals/dape
commit 96b1815ed3d13bcaba688736b62e724f6030c79d
Author: Daniel Pettersson <daniel@dpettersson.net>
Commit: Daniel Pettersson <daniel@dpettersson.net>
Initial commit
---
LICENSE | 674 +++++++++++++++++++
README.org | 158 +++++
dape.el | 2148 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 2980 insertions(+)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000..20d40b6bce
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ 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 <http://www.gnu.org/licenses/>.
+
+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:
+
+ <program> Copyright (C) <year> <name of author>
+ 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
+<http://www.gnu.org/licenses/>.
+
+ 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
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
\ No newline at end of file
diff --git a/README.org b/README.org
new file mode 100644
index 0000000000..1b1c9d1e76
--- /dev/null
+++ b/README.org
@@ -0,0 +1,158 @@
+#+title: Dape - Debug Adapter Protocol for Emacs
+#+author: Daniel Pettersson
+#+language: en
+
+=Dape= Debug Adapter Protocol for Emacs.
+
+Use ~dape-configs~ to set up your debug adapter configurations.
+
+* Features
++ Log breakpoints
++ Conditional breakpoints
++ Variable explorer
++ Variable watch
++ Variable hover with ~eldoc~
++ REPL
++ Memory viewer with ~hexl~
++ ~compile~ integration
++ Debug adapter configuration ergonomics
++ No dependencies
+
+* Configuration
+Currently =Dape= does not come with any debug adapter configuration.
+
+#+begin_src emacs-lisp
+ (use-package dape
+ :config
+ ;; Use n for next etc. in REPL
+ ;; (setq dape-repl-use-shorthand t)
+
+ ;; Kill compile buffer on build success
+ ;; (add-hook 'dape-compile-compile-hooks 'kill-buffer)
+ )
+#+end_src
+
+* Supported debug adapters
+In theory all debug adapters should be compatible with =Dape=.
+
+** Javascript - vscode-js-debug
+To install ~vscode-js-debug~ and pull down
[[https://github.com/microsoft/vscode-js-debug][repo]].
+#+begin_src sh
+ npm install
+ npx gulp dapDebugServer
+#+end_src
+
+Example launch configuration for ~node~.
+#+begin_src emacs-lisp
+ (add-to-list `(vscode-js-node
+ modes (js-mode js-ts-mode)
+ host "localhost"
+ port 8123
+ command "node"
+ command-cwd "vscode-js-debug/dist/"
+ command-args ("src/dapDebugServer.js" "8123")
+ :type "pwa-node"
+ :request "launch"
+ :cwd ,dape-cwd-fn
+ :program dape--find-file
+ :outputCapture "console"
+ :sourceMapRenames t
+ :pauseForSourceMap nil
+ :enableContentValidation t
+ :autoAttachChildProcesses t
+ :console "internalConsole"
+ :killBehavior "forceful")
+ dape-configs)
+#+end_src
+
+For more information see
[[https://github.com/microsoft/vscode-js-debug/blob/main/OPTIONS.md][OPTIONS.md]].
+
+** Go - delve
+See
[[https://github.com/go-delve/delve/tree/master/Documentation/installation][delve
installation]].
+
+#+begin_src emacs-lisp
+ (add-to-list `(delve
+ modes (go-mode go-ts-mode)
+ command "dlv"
+ command-args ("dap" "--listen" "127.0.0.1:55878")
+ command-cwd ,dape-cwd-fn
+ host "127.0.0.1"
+ port 55878
+ :type "debug"
+ :request "launch"
+ :cwd ,dape-cwd-fn
+ :program ,dape-cwd-fn)
+ dape-configs)
+#+end_src
+
+For more information see
[[https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_dap.md][documentation]].
+
+** C, C++ and Rust
+Download latest [[https://github.com/vadimcn/codelldb/releases][release]] and
unpack ~vsix~ file with your favorite unzipper.
+
+#+begin_src emacs-lisp
+ (add-to-list `(codelldb
+ modes (c-mode c-ts-mode
+ c++-mode c++-ts-mode
+ rust-ts-mode rust-mode)
+ ;; Replace vadimcn.vscode-lldb with the vsix directory you
just extracted
+ command ,"vadimcn.vscode-lldb/adapter/codelldb"
+ host "localhost"
+ port 5818
+ command-args ("--port" "5818")
+ :type "lldb"
+ :request "launch"
+ :cwd ,dape-cwd-fn
+ :program dape--find-file)
+ dape-configs)
+#+end_src
+
+See [[https://github.com/vadimcn/codelldb/blob/v1.10.0/MANUAL.md][manual]] for
more information.
+
+** C and C++ - cppdbg
+Download latest
[[https://github.com/microsoft/vscode-cpptools/releases][release]] and unpack
~vsix~ file with your favorite unzipper.
+Then ~chmod +x debugAdapters/bin/OpenDebugAD7~.
+
+#+begin_src emacs-lisp
+ ;; Replace ms-vscode.cpptools with the vsix directory you just extracted
+ (setq dape-cppdbg-command
"ms-vscode.cpptools/debugAdapters/bin/OpenDebugAD7")
+ (add-to-list `(cppdbg
+ modes (c-mode c-ts-mode c++-mode c++-ts-mode)
+ command-cwd ,(file-name-directory
+ dape--cppdbg-command)
+ command ,cppdbg-command
+ :type "cppdbg"
+ :request "launch"
+ :cwd ,dape-cwd-fn
+ :program dape--find-file
+ :MIMode ,(cond
+ ((executable-find "gdb") "gdb")
+ ((executable-find "lldb") "lldb")))
+ dape-configs)
+#+end_src
+
+See [[https://code.visualstudio.com/docs/cpp/launch-json-reference][options]].
+
+** Python - debugpy
+Install debugpy with pip ~pip install debugpy~
+
+#+begin_src emacs-lisp
+ (add-to-list `(debugpy
+ modes (python-ts-mode python-mode)
+ command "python3"
+ command-args ("-m" "debugpy.adapter")
+ :type "executable"
+ :request "launch"
+ :cwd ,dape-cwd-fn
+ :program dape--find-file)
+ dape-configs)
+#+end_src
+
+See
[[https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings][options]].
+
+** Other untested adapters
+If you find a working configuration for any other debug adapter please submit
a PR.
+See
[[https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/][microsofts
list]].
+
+* Differences with dap-mode
+~dap-mode~ is the most popular alternative for wo
diff --git a/dape.el b/dape.el
new file mode 100644
index 0000000000..748552fd10
--- /dev/null
+++ b/dape.el
@@ -0,0 +1,2148 @@
+;;; dape.el -- Debug Adapter Protocol for Emacs -*- lexical-binding: t -*-
+
+;; Author: Daniel Pettersson
+;; Created: 2023
+;; License: GPL-3.0-or-later
+;; Version: 0.1
+;; Homepage: https://github.com/svaante/dape
+
+;; This file is not part of GNU Emacs.
+
+;; 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 <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This package integrates debug adapters within Emacs.
+;; Use `dape-configs' to set up your debug adapter configurations.
+
+;; To initiate debugging sessions, use the command `dape'.
+
+;; Note:
+;; For complete functionality, it's essential to activate `eldoc-mode'
+;; in your source buffers and enable `repeat-mode' for ergomonics.
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'subr-x)
+(require 'seq)
+(require 'font-lock)
+(require 'pulse)
+(require 'comint)
+(require 'repeat)
+(require 'compile)
+(require 'tree-widget)
+(require 'project)
+
+
+;;; Custom
+(defgroup dape nil
+ "Debug Adapter Protocol for Emacs."
+ :prefix "dape-"
+ :group 'applications)
+
+(defcustom dape-configs nil
+ "This variable holds the Dape configurations as an alist.
+In this alist, the `car' element serves as a symbol identifying each
+configuration. Each configuration, in turn, is a property list (plist)
+where keys can be symbols or keywords.
+
+Symbol Keys (Used by Dape):
+- `command': Shell command to initiate the debug adapter.
+- `command-args': List of string arguments for the command.
+- `command-cwd': Working directory for the command.
+- `host': Host of the debug adapter.
+- `port': Port of the debug adapter.
+- `modes': List of modes where the configuration is active in `dape'
+ completions.
+- `compile': Executes a shell command with `dape-compile-fn'.
+
+Debug adapter connection in configuration:
+- If only `command' is specified (without `host' and `port'), Dape
+ will communicate with the debug adapter through stdin/stdout.
+- If both `host' and `port' are specified, Dape will connect to the
+ debug adapter. If `command' is specified, Dape will wait until the
+ command is initiated before it connects with `host' and `port'.
+
+Keywords in configuration:
+ Keywords are transmitted to the adapter during the initialize and
+ launch/attach requests. Refer to `json-serialize' for detailed
+ information on how Dape serializes these keyword elements. Dape
+ uses nil as false.
+
+Functions in configuration:
+ If a value in a key is a function, the function's return value will
+ replace the key's value before execution.
+
+Example:
+((adapter-example-launch
+ (modes (prog-mode)
+ command \"adapter-example\"
+ compile \"make\"
+ :type \"debug\"
+ :request \"launch\"
+ :cwd ,dape-cwd-fn
+ :program dape--find-file))
+(adapter-example-tcp-launch
+ (modes (prog-mode)
+ command \"adapter-example\"
+ command-arg '(\"--port\" \"55878\")
+ host \"localhost\"
+ port 55878
+ :type \"debug\"
+ :request \"launch\"
+ :cwd ,dape-cwd-fn
+ :program dape--find-file)))"
+ :type '(alist :key-type (symbol :tag "Name")
+ :value-type
+ (plist :options
+ (((const :tag "Shell command to start the debug
adapter" command) string)
+ ((const :tag "List of string arguments for command"
command-args) (list string))
+ ((const :tag "Working directory for command"
command-cwd) string)
+ ((const :tag "Host of debug adapter" host) string)
+ ((const :tag "Port of debug adapter" port) integer)
+ ((const :tag "List of modes where config is active in
`dape' completions" modes) function)
+ ((const :tag "Runs shell command with
`dape-compile-fn'" compile) function)
+ (keyword sexp)))))
+
+(defcustom dape-key-prefix "\C-x\C-a"
+ "Prefix of all dape commands."
+ :type 'key-sequence)
+
+(defcustom dape-buffers-on-start '(dape-info dape-repl)
+ "Dape buffers to open when debugging starts."
+ :type '(list (const dape-info) (const dape-repl)))
+
+
+(defcustom dape-main-functions '("main")
+ "Functions to set breakpoints at startup if no other breakpoints are set."
+ :type '(list string))
+
+(defcustom dape-info-buttons
+ '(("next" . dape-next)
+ ("step" . dape-step-in)
+ ("out" . dape-step-out)
+ ("cont" . dape-continue)
+ ("pause" . dape-pause)
+ ("restart" . dape-restart)
+ ("quit" . dape-quit))
+ "Which actions to be displayed in `dape-info' buffer."
+ :type '(alist :key-type string
+ :value-type function))
+
+(defcustom dape-read-memory-default-count 1024
+ "The default count for `dape-read-memory'."
+ :type '(integer))
+
+(defcustom dape-repl-commands
+ '(("debug" . dape)
+ ("next" . dape-next)
+ ("continue" . dape-continue)
+ ("pause" . dape-pause)
+ ("step" . dape-step-in)
+ ("out" . dape-step-out)
+ ("restart" . dape-restart)
+ ("kill" . dape-kill)
+ ("quit" . dape-quit))
+ "Dape commands available in REPL buffer."
+ :type '(alist :key-type string
+ :value-type function))
+
+(defcustom dape-compile-fn #'compile
+ "Function to run compile with."
+ :type 'function)
+
+(defcustom dape-cwd-fn 'dape--default-cwd
+ "Function to get current working directory."
+ :type 'function)
+
+(defcustom dape-compile-compile-hooks nil
+ "Hook run after dape compilation succeded.
+The hook is run with one argument, the compilation buffer."
+ :type 'hook)
+
+(defcustom dape-repl-use-shorthand nil
+ "Dape `dape-repl-commands' can be invokend with first char of command."
+ :type 'boolean)
+
+(defcustom dape--debug-on
+ '(io info error std-server)
+ "Which types of logs should be printed to *dape-debug*."
+ :type '(list (const io :tag "dap IO")
+ (const info :tag "info logging")
+ (const error :tag "error logging")
+ (const std-server :tag "dap tcp server stdout")))
+;;; Face
+
+(defface dape-log-face
+ '((t :inherit (font-lock-doc-face)
+ :height 0.85 :box (:line-width -1)))
+ nil)
+
+(defface dape-expression-face
+ '((t :inherit (font-lock-warning-face)
+ :height 0.85 :box (:line-width -1)))
+ nil)
+
+(defface dape-breakpoint-face
+ '((t :inherit (bold)))
+ nil)
+
+(defface dape-stack-trace
+ '((t :inherit highlight :extend t))
+ nil)
+
+
+;;; Vars
+
+(defvar dape--name nil)
+(defvar dape--config nil)
+(defvar dape--timers nil)
+(defvar dape--seq nil)
+(defvar dape--seq-event nil)
+(defvar dape--cb nil)
+(defvar dape--state nil)
+(defvar dape--thread-id nil)
+(defvar dape--stack-id nil)
+(defvar dape--capabilities nil)
+(defvar dape--threads nil)
+(defvar dape--stack-pointers nil)
+(defvar dape--breakpoints nil)
+(defvar dape--watched nil)
+(defvar dape--server-process nil)
+(defvar dape--process nil)
+(defvar dape--parent-process nil)
+
+(defvar dape--tree-widget-open-p (make-hash-table :test 'equal))
+
+(defvar dape--scopes-widget nil)
+(defvar dape--watched-widget nil)
+(defvar dape--stack-widget nil)
+(defvar dape--threads-widget nil)
+(defvar dape--breakpoints-widget nil)
+
+(defvar dape--widget-guard nil)
+(defvar dape--repl-insert-text-guard nil)
+
+(defvar dape--config-history nil)
+
+
+;;; Utils
+
+(defmacro dape--callback (&rest body)
+ `(lambda (&optional process body success msg)
+ (ignore process body success msg)
+ ,@body))
+
+(defun dape--next-like-command (command &optional arg)
+ (if (dape--stopped-threads)
+ (dotimes (_ (or arg 1))
+ (dape-request (dape--live-process)
+ command
+ (dape--thread-id-object)
+ (dape--callback
+ (when success
+ (dape--remove-stack-pointers)
+ (dolist (thread dape--threads)
+ (plist-put thread :status "running"))
+ (dape--info-update-threads-widget)
+ (dape--update-state "running")))))
+ (message "No stopped thread.")))
+
+(defun dape--thread-id-object ()
+ (when dape--thread-id
+ (list :threadId dape--thread-id)))
+
+(defun dape--stopped-threads ()
+ (mapcan (lambda (thread)
+ (when (equal (plist-get thread :status) "stopped")
+ (list thread)))
+ dape--threads))
+
+(defun dape--current-thread ()
+ (seq-find (lambda (thread)
+ (eq (plist-get thread :id) dape--thread-id))
+ dape--threads))
+
+(defun dape--current-stack-frame ()
+ (let* ((stack-frames (thread-first
+ (dape--current-thread)
+ (plist-get :stackFrames)))
+ (stack-frames-with-source
+ (seq-filter (lambda (stack-frame)
+ (thread-first stack-frame
+ (plist-get :source)
+ (plist-get :path)))
+ stack-frames)))
+ (or (seq-find (lambda (stack-frame)
+ (eq (plist-get stack-frame :id)
+ dape--stack-id))
+ stack-frames-with-source)
+ (car stack-frames-with-source)
+ (car stack-frames))))
+
+(defun dape--object-to-marker (object &optional buffer-open-fn)
+ (when-let* ((path (thread-first object
+ (plist-get :source)
+ (plist-get :path)))
+ (line (plist-get object :line))
+ (buffer-open-fn (or buffer-open-fn 'find-file-noselect ))
+ (buffer (funcall buffer-open-fn path)))
+ (with-current-buffer buffer
+ (save-excursion
+ (goto-char (point-min))
+ (forward-line (1- line))
+ (when-let ((column (plist-get object :column)))
+ (when (> column 0)
+ (forward-char (1- column))))
+ (point-marker)))))
+
+(defun dape--goto-source (object &optional no-select pulse)
+ (when-let ((marker (dape--object-to-marker object)))
+ (let ((window
+ (display-buffer (marker-buffer marker)
+ '(display-buffer-reuse-window
+ display-buffer-pop-up-window))))
+ (unless no-select
+ (select-window window))
+ (with-current-buffer (marker-buffer marker)
+ (with-selected-window window
+ (goto-char (marker-position marker))
+ (when pulse
+ (pulse-momentary-highlight-region (line-beginning-position)
+ (line-beginning-position 2)
+ 'next-error)))))))
+
+(defun dape--default-cwd ()
+ (expand-file-name
+ (or (when-let ((project (project-current)))
+ (project-root project))
+ default-directory)))
+
+(defun dape--find-file ()
+ (let* ((completion-ignored-extensions nil)
+ (default-directory (funcall dape-cwd-fn)))
+ (expand-file-name
+ (read-file-name "Program: " default-directory nil t))))
+
+(defun dape--overlay-region (&optional extended)
+ (list (line-beginning-position)
+ (if extended
+ (line-beginning-position 2)
+ (1- (line-beginning-position 2)))))
+
+(defun dape--variable-string (plist)
+ (let ((name (plist-get plist :name))
+ (value (or (plist-get plist :value)
+ (plist-get plist :result)))
+ (type (plist-get plist :type)))
+ (concat
+ (propertize name
+ 'face 'font-lock-variable-name-face)
+ (unless (or (null value)
+ (string-empty-p value))
+ (format " = %s"
+ (propertize value
+ 'face 'font-lock-number-face)))
+ (unless (or (null type)
+ (string-empty-p type))
+ (format ": %s"
+ (propertize type
+ 'face 'font-lock-type-face))))))
+
+
+
+
+;;; Process and parsing
+
+(defconst dape--content-length-re
+ "\\(?:.*: .*\r\n\\)*Content-Length: \
+*\\([[:digit:]]+\\)\r\n\\(?:.*: .*\r\n\\)*\r\n")
+
+(defun dape--debug (type string &rest objects)
+ (when (memq type dape--debug-on)
+ (with-current-buffer (get-buffer-create "*dape-debug*")
+ (setq buffer-read-only t)
+ (goto-char (point-max))
+ (let ((inhibit-read-only t))
+ (insert (concat (propertize (format "[%s]"
+ (symbol-name type))
+ 'face 'match)
+ " "
+ (apply 'format string objects)))
+ (newline)))))
+
+(defun dape--live-process (&optional nowarn)
+ (if (and dape--process
+ (processp dape--process)
+ (process-live-p dape--process))
+ dape--process
+ (unless nowarn
+ (user-error "No debug process live."))))
+
+(defun dape--process-sentinel (process _msg)
+ (unless (process-live-p process)
+ (dape--remove-stack-pointers)
+ (dape--debug 'info "\nProcess %S exited with %d"
+ (process-command process)
+ (process-exit-status process))))
+
+(defun dape--handle-object (process object)
+ (dape--debug 'io "Received:\n%s" (pp-to-string object))
+ (when-let* ((type-string (plist-get object :type))
+ (type (intern type-string)))
+ (cl-case type
+ (response
+ (let ((seq (plist-get object :request_seq)))
+ (when-let ((timer (gethash seq dape--timers)))
+ (cancel-timer timer)
+ (remhash seq dape--timers))
+ (when-let ((cb (gethash seq dape--cb)))
+ (funcall cb
+ process
+ (plist-get object :body)
+ (plist-get object :success)
+ (plist-get object :message))
+ (remhash seq dape--cb))))
+ (request
+ (run-with-timer 0 nil 'dape-handle-request
+ process
+ (intern (plist-get object :command))
+ (plist-get object :arguments)))
+ (event
+ (let ((seq (plist-get object :seq)))
+ (cond
+ ;; FIXME This is only here for `godot' which keeps sending duplicate.
+ ((or (> seq dape--seq-event)
+ (zerop seq))
+ (setq dape--seq-event seq)
+ (dape-handle-event process
+ (intern (plist-get object :event))
+ (plist-get object :body)))
+ (t (dape--debug 'error
+ "Event ignored due to seq %d convention not followed" seq)))))
+ (_ (dape--debug 'info "No handler for type %s" type)))))
+
+(defun dape--process-filter (process string)
+ (when (process-live-p process)
+ (when-let ((input-buffer (process-buffer process))
+ (buffer (current-buffer)))
+ (with-current-buffer input-buffer
+ (goto-char (point-max))
+ (insert string)
+ (goto-char (point-min))
+ (let (done)
+ (while (not done)
+ (if-let ((object
+ (condition-case nil
+ (when (search-forward-regexp dape--content-length-re
+ nil
+ t)
+ (json-parse-buffer :object-type 'plist
+ :null-object nil
+ :false-object nil))
+ (error (and (erase-buffer) nil)))))
+ (with-current-buffer buffer
+ (dape--handle-object process object))
+ (setq done t))))
+ (delete-region (point-min) (point))))))
+
+
+;;; Outgoing requests
+
+(defconst dape--timeout 5)
+
+(defun dape--create-timer (process seq)
+ (puthash seq
+ (run-with-timer dape--timeout
+ nil
+ (dape--callback
+ (dape--debug 'error
+ "Timeout for reached for seq %d"
+ seq)
+ (dape--update-state "timed out")
+ (remhash seq dape--timers)
+ (when-let ((cb (gethash seq dape--cb)))
+ (clrhash dape--tree-widget-open-p)
+ (remhash seq dape--cb)
+ (funcall cb process nil nil nil)))
+ process)
+ dape--timers))
+
+(defun dape-send-object (process seq object)
+ (let* ((object (plist-put object :seq seq))
+ (json (json-serialize object :false-object nil))
+ (string (format "Content-Length: %d\r\n\r\n%s" (length json) json)))
+ (dape--debug 'io "Sending:\n%s" (pp-to-string object))
+ (process-send-string process string)))
+
+(defun dape-request (process command arguments &optional cb)
+ (let ((seq (setq dape--seq (1+ dape--seq)))
+ (object (and arguments (list :arguments arguments))))
+ (dape--create-timer process seq)
+ (when cb
+ (puthash seq cb dape--cb))
+ (dape-send-object process
+ seq
+ (thread-first object
+ (plist-put :type "request")
+ (plist-put :command command)))))
+
+(defun dape--initialize (process)
+ (dape-request process
+ "initialize"
+ (list :clientID "dape"
+ :adapterID (plist-get dape--config
+ :type)
+ :pathFormat "path"
+ :linesStartAt1 t
+ :columnsStartAt1 t
+ ;;:locale "en-US"
+ ;;:supportsVariableType t
+ ;;:supportsVariablePaging t
+ :supportsRunInTerminalRequest t
+ ;;:supportsMemoryReferences t
+ ;;:supportsInvalidatedEvent t
+ ;;:supportsMemoryEvent t
+ ;;:supportsArgsCanBeInterpretedByShell t
+ :supportsProgressReporting t
+ :supportsStartDebuggingRequest t
+ ;;:supportsVariableType t
+ )
+ (dape--callback
+ (setq dape--capabilities body)
+ (dape--launch-or-attach process))))
+
+(defun dape--launch-or-attach (process)
+ (if-let ((request (plist-get dape--config :request)))
+ (dape-request process
+ request
+ (append
+ (cl-loop for (key value) on dape--config by 'cddr
+ when (keywordp key)
+ append (list key value))
+ (plist-get dape--config 'start-debugging))
+ (dape--callback
+ (when (plist-get dape--config 'start-debugging)
+ (plist-put dape--config 'start-debugging nil))))
+ (user-error "Need to specify request in config `%S'"
+ dape--config)
+ (dape-kill)))
+
+(defun dape--set-breakpoints (process buffer breakpoints cb)
+ (let ((lines (mapcar (lambda (breakpoint)
+ (with-current-buffer (overlay-buffer breakpoint)
+ (line-number-at-pos (overlay-start breakpoint))))
+ breakpoints)))
+ (dape-request process
+ "setBreakpoints"
+ (list
+ :source
+ (list
+ :name (file-name-nondirectory
+ (buffer-file-name buffer))
+ :path (buffer-file-name buffer))
+ :breakpoints
+ (cl-map
+ 'vector
+ (lambda (overlay line)
+ (let (plist it)
+ (setq plist (list :line line))
+ (cond
+ ((setq it (overlay-get overlay 'dape-log-message))
+ (setq plist (plist-put plist :logMessage it)))
+ ((setq it (overlay-get overlay 'dape-expr-message))
+ (setq plist (plist-put plist :condition it))))
+ plist))
+ breakpoints
+ lines)
+ :lines (apply 'vector lines))
+ cb)))
+
+(defun dape--set-main-breakpoints (process cb)
+ (if (plist-get dape--capabilities :supportsFunctionBreakpoints)
+ (dape-request process
+ "setFunctionBreakpoints"
+ (list
+ :breakpoints
+ (cl-map 'vector
+ (lambda (name)
+ (list :name name))
+ dape-main-functions))
+ cb)
+ (funcall cb process)))
+
+(defun dape--configure-breakpoints (process cb)
+ (dape--clean-breakpoints)
+ (if-let ((counter 0)
+ (buffers-breakpoints (seq-group-by 'overlay-buffer
+ dape--breakpoints)))
+ (dolist (buffer-breakpoints buffers-breakpoints)
+ (pcase-let ((`(,buffer . ,breakpoints) buffer-breakpoints))
+ (dape--set-breakpoints process
+ buffer
+ breakpoints
+ (dape--callback
+ (setf counter (1+ counter))
+ (when (eq counter (length
buffers-breakpoints))
+ (funcall cb process nil))))))
+ (dape--set-main-breakpoints process cb)))
+
+(defun dape--configuration-done (process)
+ (dape-request process
+ "configurationDone"
+ nil
+ (dape--callback nil)))
+
+(defun dape--get-threads (process stopped-id all-threads-stopped cb)
+ (dape-request process
+ "threads"
+ nil
+ (dape--callback
+ (setq dape--threads
+ (cl-map
+ 'list
+ (lambda (new-thread)
+ (let ((thread
+ (or (seq-find
+ (lambda (old-thread)
+ (eq (plist-get new-thread :id)
+ (plist-get old-thread :id)))
+ dape--threads)
+ new-thread)))
+ (plist-put thread :name
+ (plist-get new-thread :name))
+ (cond
+ (all-threads-stopped
+ (plist-put thread :status "stopped"))
+ ((eq (plist-get thread :id) stopped-id)
+ (plist-put thread :status "stopped"))
+ (t thread))))
+ (plist-get body :threads)))
+ (funcall cb process))))
+
+(defun dape--stack-trace (process thread cb)
+ (cond
+ ((or (plist-get (dape--current-thread) :stackFrames)
+ (not (numberp (plist-get thread :id))))
+ (funcall cb process))
+ (t
+ (dape-request process
+ "stackTrace"
+ (list :threadId (plist-get thread :id)
+ :levels 50)
+ (dape--callback
+ (plist-put thread :stackFrames
+ (cl-map 'list
+ 'identity
+ (plist-get body :stackFrames)))
+ (funcall cb process))))))
+
+(defun dape--variables (process object cb)
+ (let ((variables-reference (plist-get object :variablesReference)))
+ (if (or (zerop variables-reference)
+ (plist-get object :variables))
+ (funcall cb process)
+ (dape-request process
+ "variables"
+ (list :variablesReference variables-reference)
+ (dape--callback
+ (plist-put object
+ :variables
+ (thread-last (plist-get body :variables)
+ (cl-map 'list 'identity)
+ (seq-filter 'identity)))
+ (funcall cb process))))))
+
+(defun dape--evaluate-expression (process frame-id expression context cb)
+ (dape-request process
+ "evaluate"
+ (list :frameId frame-id
+ :expression expression
+ :context context)
+ cb))
+
+(defun dape--scopes (process stack-frame cb)
+ (if-let ((id (plist-get stack-frame :id)))
+ (dape-request process
+ "scopes"
+ (list :frameId id)
+ (dape--callback
+ (let ((scopes (cl-map 'list 'identity (plist-get body
:scopes))))
+ (plist-put stack-frame :scopes scopes)
+ (funcall cb process))))
+ (funcall cb process)))
+
+(defun dape--update (process)
+ (let ((current-thread (dape--current-thread)))
+ (dolist (thread dape--threads)
+ (plist-put thread :stackFrames nil))
+ (dape--stack-trace process
+ current-thread
+ (dape--callback
+ (dape--update-ui)))))
+
+
+;;; Incoming requests
+
+(cl-defgeneric dape-handle-request (process command arguments)
+ (ignore process)
+ (dape--debug 'info "Unhandled request '%S' with arguments %S"
+ command
+ arguments))
+
+(cl-defmethod dape-handle-request (process (_command (eql runInTerminal))
arguments)
+ (let* ((cwd (plist-get process :cwd))
+ (default-directory (or (and cwd
+ (not (string-blank-p cwd))
+ cwd)
+ default-directory))
+ (buffer (get-buffer-create "*dape-shell*"))
+ (display-buffer-alist
+ '(((major-mode . shell-mode) . (display-buffer-no-window)))))
+ (async-shell-command (string-join
+ (cl-map 'list
+ 'identity
+ (plist-get arguments :args))
+ " ")
+ buffer
+ buffer)
+ (display-buffer buffer '((display-buffer-in-side-window) .
+ '((side . bottom)
+ (slot . 1))))))
+
+(cl-defmethod dape-handle-request (_process (_command (eql startDebugging))
arguments)
+ (setq dape--parent-process dape--process)
+ (dape dape--name
+ (plist-put dape--config
+ 'start-debugging
+ (plist-get arguments :configuration))))
+
+
+;;; Events
+
+(cl-defgeneric dape-handle-event (_process event body)
+ (dape--debug 'info "Unhandled event '%S' with body %S" event body))
+
+(cl-defmethod dape-handle-event (process (_event (eql initialized)) _body)
+ (dape--update-state "initialized")
+ (dape--configure-breakpoints
+ process
+ (dape--callback
+ (dape--configuration-done process))))
+
+(cl-defmethod dape-handle-event (_process (_event (eql process)) body)
+ (let ((start-method (format "%sed"
+ (or (plist-get body :startMethod)
+ "start"))))
+ (dape--update-state start-method)
+ (dape--repl-insert-text (format "Process %s %s\n"
+ start-method
+ (plist-get body :name)))))
+
+(cl-defmethod dape-handle-event (_process (_event (eql thread)) body)
+ (if-let ((thread
+ (seq-find (lambda (thread)
+ (eq (plist-get thread :id)
+ (plist-get body :threadId)))
+ dape--threads)))
+ (progn
+ (dape--debug 'info "thread %S" body)
+ (plist-put thread :status (plist-get body :reason))
+ (plist-put thread :name (or (plist-get thread :name)
+ "unnamed")))
+ (push (list :status (plist-get body :reason)
+ :id (plist-get body :threadId)
+ :name "unnamed")
+ dape--threads))
+ (dape--info-update-threads-widget))
+
+(cl-defmethod dape-handle-event (process (_event (eql stopped)) body)
+ (dape--update-state "stopped")
+ (setq dape--thread-id (plist-get body :threadId))
+ (dape--get-threads process
+ (plist-get body :threadId)
+ (plist-get body :allThreadsStopped)
+ (dape--callback
+ (dape--update process))))
+
+(cl-defmethod dape-handle-event (_process (_event (eql continued)) body)
+ (dape--remove-stack-pointers)
+ (unless dape--thread-id
+ (setq dape--thread-id (plist-get body :threadId)))
+ (dape--update-state "running"))
+
+(cl-defmethod dape-handle-event (_process (_event (eql output)) body)
+ (let ((category (plist-get body :category)))
+ (cond
+ ((equal category "stdout")
+ (dape--repl-insert-text (plist-get body :output)))
+ ((equal category "stderr")
+ (dape--repl-insert-text (propertize
+ (plist-get body :output)
+ 'face 'error)))
+ ((or (equal category "console")
+ (equal category "output"))
+ (dape--repl-insert-text (propertize
+ (plist-get body :output)
+ 'face 'italic))))))
+
+(cl-defmethod dape-handle-event (_process (_event (eql exited)) body)
+ (dape--update-state "exited")
+ (dape--remove-stack-pointers)
+ (dape--repl-insert-text (propertize
+ (format "* Exit code: %d *\n"
+ (plist-get body :exitCode))
+ 'face
+ 'highlight)))
+
+(cl-defmethod dape-handle-event (_process (_event (eql terminated)) _body)
+ (dape--update-state "terminated")
+ (dape--repl-insert-text (propertize
+ "* Program terminated *\n"
+ 'face
+ 'highlight))
+ (dape--remove-stack-pointers))
+
+
+;;; Startup/Setup
+
+(defun dape--setup (process name config)
+ (setq dape--name name
+ dape--config config
+ dape--seq 0
+ dape--seq-event 0
+ dape--timers (make-hash-table)
+ dape--cb (make-hash-table)
+ dape--thread-id nil
+ dape--capabilities nil
+ dape--threads nil
+ dape--stack-pointers nil
+ dape--stack-id nil
+ dape--process process)
+ (setq dape--widget-guard nil
+ dape--repl-insert-text-guard nil)
+ (dape--update-state "starting")
+ (dolist (fn dape-buffers-on-start)
+ (funcall fn))
+ (dape--initialize process))
+
+(defun dape--get-buffer ()
+ (let ((buffer (get-buffer-create "*dape-processes*")))
+ (with-current-buffer buffer
+ (let ((inhibit-read-only t))
+ (erase-buffer)))
+ buffer))
+
+(defun dape--start-multi-session (name config)
+ (dape--debug 'info "Starting new multi session")
+ (let ((buffer (dape--get-buffer))
+ (default-directory (or (plist-get config 'command-cwd)
+ default-directory))
+ (retries 30)
+ process)
+ (when (and (plist-get config 'command)
+ (not (plist-get config 'start-debugging)))
+ (setq dape--server-process
+ (make-process :name "Dape server"
+ :command (cons (plist-get config 'command)
+ (plist-get config 'command-args))
+ :buffer buffer
+ :sentinel 'dape--process-sentinel
+ :filter (lambda (_process string)
+ (dape--debug 'server-stdout
+ "Server stdout:\n%s"
+ string))
+ :noquery t))
+ (dape--debug 'info "Server process started %S"
+ (process-command dape--server-process)))
+ (while (and (not process)
+ (> retries 0))
+ (ignore-errors
+ (setq process
+ (make-network-process :name (symbol-name name)
+ :buffer buffer
+ :host (plist-get config 'host)
+ :service (plist-get config 'port)
+ :sentinel 'dape--process-sentinel
+ :filter 'dape--process-filter
+ :noquery t)))
+ (sleep-for 0 100)
+ (setq retries (1- retries)))
+ (if (zerop retries)
+ (user-error "Unable to connect to server %s:%d"
+ (plist-get config 'host)
+ (plist-get config 'port))
+ (dape--debug 'info "Connection to server established %s:%s"
+ (plist-get config 'host) (plist-get config 'port)))
+ (dape--setup process name config)))
+
+(defun dape--start-single-session (name config)
+ (dape--debug 'info "Starting new single session")
+ (let ((buffer (dape--get-buffer))
+ (default-directory (or (plist-get config 'command-cwd)
+ default-directory))
+ process)
+ (setq process (make-process :name (symbol-name name)
+ :command (cons (plist-get config 'command)
+ (plist-get config
'command-args))
+ :connection-type 'pipe
+ :coding 'no-conversion
+ :sentinel 'dape--process-sentinel
+ :filter 'dape--process-filter
+ :buffer buffer
+ :noquery t))
+ (dape--debug 'info "Process started %S" (process-command process))
+ (dape--setup process name config)))
+
+
+;;; Commands
+
+(defun dape-next (&optional arg)
+ "Step one line (skip functions)."
+ (interactive (list current-prefix-arg))
+ (dape--next-like-command "next" arg))
+
+(defun dape-step-in (&optional arg)
+ "Steps into function/method. If not possible behaves like `dape-next'."
+ (interactive (list current-prefix-arg))
+ (dape--next-like-command "stepIn" arg))
+
+(defun dape-step-out (&optional arg)
+ "Steps out of function/method. If not possible behaves like `dape-next'."
+ (interactive (list current-prefix-arg))
+ (dape--next-like-command "stepOut" arg))
+
+(defun dape-continue (&optional arg)
+ "Resumes execution."
+ (interactive (list current-prefix-arg))
+ (dape--next-like-command "continue" arg))
+
+(defun dape-pause ()
+ "Pause execution."
+ (interactive)
+ (dape-request (dape--live-process)
+ "pause"
+ (dape--thread-id-object)
+ (dape--callback nil)))
+
+(defun dape-restart ()
+ "Restart last debug session started."
+ (interactive)
+ (cond
+ ((and (dape--live-process t)
+ (plist-get dape--capabilities :supportsRestartRequest))
+ (dape-request dape--process "restart" nil))
+ ((and dape--name dape--config)
+ (dape dape--name dape--config))
+ (t
+ (user-error "Unable to derive session to restart."))))
+
+(defun dape-kill ()
+ "Kill debug session."
+ (interactive)
+ (let* (done
+ (kill-processes
+ (lambda (&rest _)
+ (dape--remove-stack-pointers)
+ (ignore-errors
+ (and dape--process
+ (delete-process dape--process))
+ (and dape--server-process
+ (delete-process dape--server-process))
+ (and dape--parent-process
+ (delete-process dape--parent-process)))
+ ;; Clean mode-line after 2 seconds
+ (run-with-timer 2 nil (lambda ()
+ (unless (dape--live-process t)
+ (setq dape--process nil)
+ (force-mode-line-update t))))
+ (setq done t))))
+ (cond
+ ((and (dape--live-process t)
+ (plist-get dape--capabilities
+ :supportsTerminateRequest))
+ (dape-request dape--process
+ "terminate"
+ nil
+ kill-processes)
+ ;; Busy wait for response at least 2 seconds
+ (cl-loop with max-iterations = 20
+ for i from 1 to max-iterations
+ until done
+ do (accept-process-output nil 0.1)
+ finally (unless done
+ (dape--debug 'error
+ "Terminate request timed out"))))
+ ((and (dape--live-process t)
+ (plist-get dape--capabilities
+ :supportTerminateDebuggee))
+ (dape-request dape--process
+ "disconnect"
+ (list
+ :terminateDebuggee t)
+ kill-processes)
+ ;; Busy wait for response at least 2 seconds
+ (cl-loop with max-iterations = 20
+ for i from 1 to max-iterations
+ until done
+ do (accept-process-output nil 0.1)
+ finally (unless done
+ (dape--debug 'error
+ "Disconnect request timed out"))))
+ (t
+ (funcall kill-processes)))))
+
+(defun dape-quit ()
+ "Kill debug session and kill related dape buffers."
+ (interactive)
+ (dape-kill)
+ (thread-last (buffer-list)
+ (seq-filter (lambda (buffer)
+ (string-match-p "\\*dape-.+\\*" (buffer-name
buffer))))
+ (seq-do (lambda (buffer)
+ (when-let ((window (get-buffer-window buffer)))
+ (delete-window window))
+ (kill-buffer buffer)))))
+
+(defun dape-toggle-breakpoint ()
+ "Add or remove breakpoint at current line.
+Will remove log or expression breakpoint at line added with
+`dape-log-breakpoint' and/or `dape-expression-breakpoint'."
+ (interactive)
+ (if (dape--breakpoints-at-point)
+ (dape-remove-breakpoint-at-point)
+ (dape--place-breakpoint)))
+
+(defun dape-log-breakpoint (log-message)
+ "Add log breakpoint at line.
+Argument LOG-MESSAGE contains string to print to *dape-repl*.
+Expressions within `{}` are interpolated."
+ (interactive
+ (list
+ (read-string "Log (Expressions within `{}` are interpolated): "
+ (when-let ((prev-log-breakpoint
+ (seq-find (lambda (ov)
+ (overlay-get ov 'dape-log-message))
+ (dape--breakpoints-at-point))))
+ (overlay-get prev-log-breakpoint 'dape-log-message)))))
+ (when-let ((prev-log-breakpoint (seq-find (lambda (ov)
+ (overlay-get ov
'dape-log-message))
+ (dape--breakpoints-at-point))))
+ (delq prev-log-breakpoint dape--breakpoints)
+ (delete-overlay prev-log-breakpoint))
+ (unless (string-empty-p log-message)
+ (dape--place-breakpoint log-message)))
+
+(defun dape-expression-breakpoint (expr-message)
+ "Add expression breakpoint at current line.
+When EXPR-MESSAGE is evaluated as true threads will pause at current line."
+ (interactive
+ (list
+ (read-string "Condition: "
+ (when-let ((prev-expr-breakpoint
+ (seq-find (lambda (ov)
+ (overlay-get ov 'dape-expr-message))
+ (dape--breakpoints-at-point))))
+ (overlay-get prev-expr-breakpoint 'dape-expr-message)))))
+ (when-let ((prev-expr-breakpoint
+ (seq-find (lambda (ov)
+ (overlay-get ov 'dape-expr-message))
+ (dape--breakpoints-at-point))))
+ (delq prev-expr-breakpoint dape--breakpoints)
+ (delete-overlay prev-expr-breakpoint))
+ (unless (string-empty-p expr-message)
+ (dape--place-breakpoint nil expr-message)))
+
+(defun dape-remove-breakpoint-at-point ()
+ "Remove breakpoint, log breakpoint and expression at current line."
+ (interactive)
+ (dolist (breakpoint (dape--breakpoints-at-point))
+ (dape--remove-breakpoint breakpoint)))
+
+(defun dape-remove-all-breakpoints ()
+ "Remove all breakpoints."
+ (interactive)
+ (let ((buffers-breakpoints (seq-group-by 'overlay-buffer
+ dape--breakpoints)))
+ (dolist (buffer-breakpoints buffers-breakpoints)
+ (pcase-let ((`(,buffer . ,breakpoints) buffer-breakpoints))
+ (dolist (breakpoint breakpoints)
+ (delq breakpoint dape--breakpoints)
+ (delete-overlay breakpoint))
+ (dape--update-breakpoints-in-buffer buffer))))
+ (dape--info-update-breakpoints-widget))
+
+;;;###autoload
+(defun dape (name config &optional skip-compile)
+ "Start debugging session.
+
+Start a debugging session based on NAME in `dape-configs' alist.
+Entries in plist CONFIG override config specified by NAME.
+See `dape-configs' for more information on CONFIG.
+
+SKIP-COMPILE ignores compile flag in config.
+
+When called as an interactive command, the first symbol like
+string is read as NAME and rest as element in CONFIG.
+
+Interactive example:
+ launch :program \"bin\"
+executes launch `dape-config' with :program as \"bin\"."
+ (interactive (dape--read-config))
+ (unless (plist-get config 'start-debugging)
+ (dape-kill))
+ (let ((base-config (alist-get name dape-configs))
+ evaled-config)
+ (unless base-config
+ (user-error "Unable to find `%s' in `dape-configs'" name))
+ (setq evaled-config
+ (dape--config-eval
+ (seq-reduce (apply-partially 'apply 'plist-put)
+ (seq-partition config 2)
+ (copy-tree base-config))))
+ (when (called-interactively-p)
+ (push (dape--config-to-string name
+ base-config
+ evaled-config)
+ dape--config-history))
+ (unless (or (plist-get config 'start-debugging)
+ skip-compile)
+ (when-let ((buffer (get-buffer "*dape-debug*")))
+ (with-current-buffer buffer
+ (let ((inhibit-read-only t))
+ (erase-buffer)))))
+ (cond
+ ((and (plist-get config 'compile) (not skip-compile))
+ (dape--compile name evaled-config))
+ ((and (plist-get config 'host) (plist-get config 'port))
+ (dape--start-multi-session name evaled-config))
+ (t
+ (dape--start-single-session name evaled-config)))))
+
+(defun dape-watch-dwim (expression)
+ "Add or remove watch for EXPRESSION
+Watched symbols are displayed in *dape-info* buffer.
+*dape-info* buffer is displayed by executing the `dape-info' command."
+ (interactive
+ (list (string-trim
+ (completing-read "Watch or unwatch symbol: "
+ (mapcar (lambda (plist) (plist-get plist :name))
+ dape--watched)
+ nil
+ nil
+ (or (and (region-active-p)
+ (buffer-substring (region-beginning)
+ (region-end)))
+ (thing-at-point 'expression))))))
+ (if-let ((plist
+ (cl-find-if (lambda (plist)
+ (equal (plist-get plist :name)
+ expression))
+ dape--watched)))
+ (setq dape--watched
+ (cl-remove plist dape--watched))
+ (push (list :name expression)
+ dape--watched))
+ (dape--info-update-widget dape--watched-widget))
+
+
+;;; Compile
+
+(defun dape--compile-compilation-finish (buffer str)
+ (remove-hook 'compilation-finish-functions
#'dape--compile-compilation-finish)
+ (cond
+ ((equal "finished\n" str)
+ (run-hook-with-args 'dape-compile-compile-hooks buffer)
+ (dape dape--name dape--config 'skip-compile))
+ (t
+ (dape--repl-insert-text (format "* Compilation failed %s *" str)))))
+
+(defun dape--compile (name config)
+ (let ((default-directory (plist-get config :cwd))
+ (command (plist-get config 'compile)))
+ (setq dape--config config)
+ (setq dape--name name)
+ (add-hook 'compilation-finish-functions #'dape--compile-compilation-finish)
+ (funcall dape-compile-fn command)))
+
+
+;;; Memory viewer
+
+(defun dape--address-to-number (address)
+ (cond
+ ((and (> (length address) 2)
+ (equal "0x" (substring address 0 2)))
+ (string-to-number (string-trim-left address "0x0*")
+ 16))
+ (t
+ (string-to-number address))))
+
+(defun dape-read-memory (memory-reference count)
+ "Read COUNT bytes of memory at MEMORY-REFERENCE."
+ (interactive
+ (list (string-trim
+ (read-string "Read memory reference: "
+ (when-let ((number (thing-at-point 'number)))
+ (number-to-string number))))
+ (read-number "Count: " dape-read-memory-default-count)))
+ (dape-request (dape--live-process)
+ "readMemory"
+ (list
+ :memoryReference memory-reference
+ :count count)
+ (dape--callback
+ (when-let ((address (plist-get body :address))
+ (data (plist-get body :data)))
+ (setq address (dape--address-to-number address)
+ data (base64-decode-string data))
+ (let ((buffer (generate-new-buffer
+ (format "*dape-memory @%s*"
+ memory-reference))))
+ (with-current-buffer buffer
+ (insert data)
+ (let (buffer-undo-list)
+ (hexl-mode))
+ ;; TODO Add hook with a writeMemory request
+ )
+ (pop-to-buffer buffer))))))
+
+
+;;; Breakpoints
+
+(defun dape--breakpoint-freeze (overlay _after _begin _end &optional _len)
+ ;; FIXME Press evil "O" on a break point line this will mess things up
+ (apply 'move-overlay overlay
+ (dape--overlay-region (eq (overlay-get overlay 'category)
+ 'dape-stack-pointer))))
+
+(defun dape--breakpoints-at-point ()
+ (seq-filter (lambda (overlay)
+ (eq 'dape-breakpoint (overlay-get overlay 'category)))
+ (overlays-in (line-beginning-position) (line-end-position))))
+
+(defun dape--update-breakpoints-in-buffer (buffer)
+ (when (buffer-live-p buffer)
+ (when-let ((process (dape--live-process t))
+ (breakpoints (thread-last dape--breakpoints
+ (seq-group-by 'overlay-buffer)
+ (alist-get buffer))))
+ (dape--set-breakpoints process
+ buffer
+ breakpoints
+ (dape--callback nil)))))
+
+(defun dape--place-breakpoint (&optional log-message expression)
+ (unless (derived-mode-p 'prog-mode)
+ (user-error "Trying to set breakpoint in none `prog-mode' buffer"))
+ (let ((breakpoint (apply 'make-overlay (dape--overlay-region))))
+ (overlay-put breakpoint 'window t)
+ (overlay-put breakpoint 'category 'dape-breakpoint)
+ (cond
+ (log-message
+ (overlay-put breakpoint 'dape-log-message log-message)
+ (overlay-put breakpoint 'after-string (concat
+ " "
+ (propertize
+ (format "Log: %s" log-message)
+ 'face 'dape-log-face))))
+ (expression
+ (overlay-put breakpoint 'dape-expr-message expression)
+ (overlay-put breakpoint 'after-string (concat
+ " "
+ (propertize
+ (format "Break: %s" expression)
+ 'face 'dape-expression-face))))
+ (t
+ (overlay-put breakpoint 'before-string
+ (propertize "B"
+ 'face 'dape-breakpoint-face))))
+ (overlay-put breakpoint 'modification-hooks '(dape--breakpoint-freeze))
+ (push breakpoint dape--breakpoints))
+ (dape--info-update-breakpoints-widget)
+ (dape--update-breakpoints-in-buffer (current-buffer)))
+
+(defun dape--remove-breakpoint (overlay)
+ (delq overlay dape--breakpoints)
+ (dape--update-breakpoints-in-buffer (overlay-buffer overlay))
+ (delete-overlay overlay)
+ (dape--info-update-breakpoints-widget))
+
+(defun dape--clean-breakpoints ()
+ (setq dape--breakpoints (seq-filter
+ 'overlay-buffer
+ dape--breakpoints)))
+
+
+;;; Stack pointers
+
+(defun dape--place-stack-pointer (marker &optional face prefix)
+ (when marker
+ (with-current-buffer (marker-buffer marker)
+ (save-excursion
+ (goto-char (marker-position marker))
+ (let ((stack-pointer
+ (apply 'make-overlay (dape--overlay-region t))))
+ (overlay-put stack-pointer 'face face)
+ (overlay-put stack-pointer 'priority 1)
+ (overlay-put stack-pointer 'window t)
+ (overlay-put stack-pointer 'category 'dape-stack-pointer)
+ (overlay-put stack-pointer 'before-string (concat prefix "→"))
+ (overlay-put stack-pointer 'modification-hooks
+ '(dape--breakpoint-freeze))
+ stack-pointer)))))
+
+(defun dape--remove-stack-pointers ()
+ (dolist (overlay dape--stack-pointers)
+ (when-let ((buffer (overlay-buffer overlay)))
+ (with-current-buffer buffer
+ (dape--remove-eldoc-hook)))
+ (delete-overlay overlay))
+ (setq dape--stack-pointers nil))
+
+(defun dape--place-stack-pointers (_process thread)
+ (when-let ((stopped-event-thread-p (eq dape--thread-id
+ (plist-get thread :id)))
+ (current-stack-frame (dape--current-stack-frame))
+ (index 0))
+ (dolist (stack-frame (thread-first (dape--current-thread)
+ (plist-get :stackFrames)))
+ (let ((selected (eq current-stack-frame stack-frame)))
+ (when-let* ((marker (dape--object-to-marker stack-frame
+ (unless selected
+ 'get-file-buffer)))
+ (overlay (dape--place-stack-pointer marker
+ (when selected
+ 'dape-stack-trace)
+ (unless (zerop index)
+ (number-to-string
index)))))
+ (when-let ((buffer (overlay-buffer overlay)))
+ (with-current-buffer buffer
+ (dape--add-eldoc-hook)))
+ (when selected
+ (dape--goto-source stack-frame
+ (memq major-mode
+ '(dape-repl-mode dape-info-mode))))
+ (push overlay
+ dape--stack-pointers))
+ (setq index (1+ index))))))
+
+
+;;; Info buffer
+
+(define-widget 'dape--tree-widget-open 'tree-widget-open-icon
+ nil
+ :tag "-")
+
+(define-widget 'dape--tree-widget-close 'tree-widget-close-icon
+ nil
+ :tag "+")
+
+(define-widget 'dape--tree-widget-empty 'tree-widget-empty-icon
+ nil
+ :tag "X")
+
+(define-widget 'dape--tree-widget-leaf 'tree-widget-leaf-icon
+ nil
+ :tag "•")
+
+(define-widget 'dape--tree-widget-space 'item
+ nil
+ :format " ")
+
+(defun dape--tree-widget-action (tree &optional event)
+ (tree-widget-action tree event)
+ ;; Cache current keystate
+ (puthash (widget-get tree :path)
+ (widget-get tree :open)
+ dape--tree-widget-open-p)
+ ;; If expanded set all parent to be expanded as well
+ (when (widget-get tree :open)
+ (let ((parent (widget-get tree :parent)))
+ (while parent
+ (puthash (widget-get parent :path)
+ t
+ dape--tree-widget-open-p)
+ (setq parent (widget-get parent :parent))))))
+
+(defun dape--tree-widget-convert-widget (tree)
+ (widget-put tree
+ :path
+ (cons (widget-get tree :key)
+ (widget-get (widget-get tree :parent) :path)))
+ (widget-put tree
+ :open
+ (gethash (widget-get tree :path)
+ dape--tree-widget-open-p
+ (widget-get tree :default)))
+ (tree-widget-convert-widget tree))
+
+(define-widget 'dape--tree-widget 'tree-widget
+ nil
+ :convert-widget 'dape--tree-widget-convert-widget
+ :default nil
+ :key nil
+ :path nil
+ :action 'dape--tree-widget-action
+ :open-icon 'dape--tree-widget-open
+ :close-icon 'dape--tree-widget-close
+ :empty-icon 'dape--tree-widget-empty
+ :leaf-icon 'dape--tree-widget-leaf
+ :guide 'dape--tree-widget-space
+ :no-guide 'dape--tree-widget-space
+ :end-guide 'dape--tree-widget-space
+ :nohandle-guide 'dape--tree-widget-space
+ :handle 'dape--tree-widget-space
+ :no-handle 'dape--tree-widget-space)
+
+(defmacro dape--with-update-ui-guard (fn args &rest body)
+ (declare (indent 2))
+ `(cond
+ (dape--widget-guard
+ (run-with-timer 1 nil ,fn ,@args))
+ (t
+ (setq dape--widget-guard t)
+ (ignore-errors ,@body)
+ (setq dape--widget-guard nil))))
+
+(defun dape--info-update-threads-widget ()
+ (dape--info-update-widget dape--threads-widget))
+
+(defun dape--info-update-breakpoints-widget ()
+ (dape--info-update-widget dape--breakpoints-widget))
+
+(defun dape--info-update-widget (&rest widgets)
+ (dape--with-update-ui-guard 'dape--info-update-widget (widgets)
+ (when-let ((buffer (get-buffer "*dape-info*")))
+ ;; FIX this seams owerkill, should be a cleaner way
+ (with-current-buffer buffer
+ (with-selected-window (get-buffer-window)
+ (save-window-excursion
+ (dolist (widget widgets)
+ (widget-value-set widget
+ (widget-value-value-get widget)))))))))
+
+(defconst dape--info-variables-fetch-depth 4)
+
+(defun dape--info-fetch-variables-1 (process object path cb)
+ (let ((objects (seq-filter (lambda (object)
+ (and (length< path
dape--info-variables-fetch-depth)
+ (gethash (cons (plist-get object :name)
+ path)
+ dape--tree-widget-open-p)))
+ (or (plist-get object :scopes)
+ (plist-get object :variables))))
+ (requests 0))
+ (if objects
+ (dolist (object objects)
+ (dape--variables process
+ object
+ (dape--callback
+ (dape--info-fetch-variables-1
+ process
+ object
+ (cons (plist-get object :name)
+ path)
+ (dape--callback
+ (setq requests (1+ requests))
+ (when (length= objects requests)
+ (funcall cb process)))))))
+ (funcall cb process))))
+
+(defun dape--update-scope (process)
+ (dape--scopes process
+ (dape--current-stack-frame)
+ (dape--callback
+ (dape--info-fetch-variables-1 process
+ (dape--current-stack-frame)
+ '("Variables")
+ (dape--callback
+ (dape--info-update-widget
+ dape--scopes-widget))))))
+
+(defun dape--expand-threads (_)
+ (mapcar (lambda (thread)
+ (widget-convert 'file-link
+ :id (plist-get thread :id)
+ :format (concat
+ (if (eq (plist-get thread :id)
+ dape--thread-id)
+ "→ %t"
+ "%[%t%]")
+ (format " [%s]"
+ (propertize
+ (plist-get thread :status)
+ 'face 'bold))
+ "\n")
+ :action (lambda (widget &rest _)
+ (setq dape--thread-id
+ (widget-get widget :id))
+ (dape--update-ui))
+ :tag (plist-get thread :name)))
+ dape--threads))
+
+(defun dape--expand-stack-p (tree)
+ (cond
+ ((plist-get (dape--current-thread) :stackFrames)
+ t)
+ ((not (equal (plist-get (dape--current-thread) :status)
+ "stopped"))
+ nil)
+ (t
+ (dape--stack-trace (dape--live-process)
+ (dape--current-thread)
+ (dape--callback
+ (when (plist-get (dape--current-thread) :stackFrames)
+ (dape--info-update-widget tree))))
+ nil)))
+
+(defun dape--expand-stack (_tree)
+ (let ((current-thread (dape--current-thread))
+ (current-stack-frame (dape--current-stack-frame)))
+ (when (equal (plist-get current-thread :status) "stopped")
+ (mapcar (lambda (stack-frame)
+ (widget-convert
+ 'file-link
+ :id (plist-get stack-frame :id)
+ :format (concat
+ (when (eq (plist-get current-stack-frame :id)
+ (plist-get stack-frame :id))
+ "→ ")
+ (if (thread-first stack-frame
+ (plist-get :source)
+ (plist-get :path))
+ "%[%t%]\n"
+ "%t\n"))
+ :action (lambda (widget &rest _)
+ (setq dape--stack-id
+ (widget-get widget :id))
+ (dape--update-ui))
+ :tag (propertize (plist-get stack-frame :name)
+ 'face 'font-lock-function-name-face)))
+ (plist-get current-thread :stackFrames)))))
+
+(defun dape--variable-to-widget (tree variable)
+ (cond
+ ((zerop (plist-get variable :variablesReference))
+ (widget-convert
+ 'item
+ :tag (dape--variable-string variable)))
+ (t
+ (widget-convert
+ 'dape--tree-widget
+ :parent tree
+ :key (plist-get variable :name)
+ :tag (dape--variable-string variable)
+ :expander-p
+ (lambda (tree)
+ (if (plist-get variable :variables)
+ t
+ (dape--variables (dape--live-process)
+ variable
+ (dape--callback
+ (when (plist-get variable :variables)
+ (dape--info-update-widget tree))))
+ nil))
+ :expander
+ (lambda (tree)
+ (mapcar (apply-partially 'dape--variable-to-widget tree)
+ (plist-get variable :variables)))))))
+
+(defun dape--expand-scopes-p (tree)
+ (cond
+ ((not (equal (plist-get (dape--current-thread) :status) "stopped"))
+ nil)
+ ((plist-get (dape--current-stack-frame) :scopes)
+ t)
+ (t
+ (dape--scopes (dape--live-process)
+ (dape--current-stack-frame)
+ (dape--callback
+ (when (plist-get (dape--current-stack-frame) :scopes)
+ (dape--info-update-widget tree))))
+ nil)))
+
+(defun dape--expand-scopes (tree)
+ (mapcar (apply-partially 'dape--variable-to-widget tree)
+ (plist-get (dape--current-stack-frame) :scopes)))
+
+(defun dape--expand-watched-p (tree)
+ (cond
+ ((not (equal (plist-get (dape--current-thread) :status) "stopped"))
+ nil)
+ ((not (cl-every (lambda (plist)
+ (plist-get plist :fetched))
+ dape--watched))
+ (funcall
+ (cl-reduce (lambda (cb plist)
+ (dape--callback
+ (dape--evaluate-expression
+ (dape--live-process)
+ (plist-get (dape--current-stack-frame) :id)
+ (plist-get plist :name)
+ "watch"
+ (dape--callback
+ (when success
+ (cl-loop for (key value) on body by 'cddr
+ do (plist-put plist key value)))
+ (plist-put plist :fetched t)
+ (funcall cb process)))))
+ dape--watched
+ :initial-value
+ (dape--callback
+ (dape--info-update-widget tree)))
+ (dape--live-process))
+ t)
+ (t t)))
+
+(defun dape--expand-watched (tree)
+ (thread-last dape--watched
+ (mapcar (lambda (plist)
+ (if (plist-get plist :result)
+ (dape--variable-to-widget tree plist)
+ (widget-convert 'item
+ :value (dape--variable-string
plist)))))))
+
+(defun dape--expand-breakpoints-widget (_)
+ (let ((current-stopped-files-lines
+ (thread-last (dape--stopped-threads)
+ (mapcan
+ (lambda (thread)
+ (when-let* ((stack-frame
+ (car (plist-get thread
+ :stackFrames)))
+ (file
+ (thread-first stack-frame
+ (plist-get :source)
+ (plist-get :path)))
+ (line
+ (plist-get stack-frame :line)))
+ (list (cons file line))))))))
+ (mapcan (lambda (overlay)
+ (when-let* ((buffer (overlay-buffer overlay))
+ (file (buffer-file-name buffer))
+ (line
+ (with-current-buffer buffer
+ (line-number-at-pos (overlay-start overlay)))))
+ (list
+ (widget-convert
+ 'file-link
+ :format (concat "%t%[%v%]"
+ (overlay-get overlay 'after-string)
+ "\n")
+ :action (lambda (&rest _)
+ (dape--goto-source `(:source (:path ,file)
+ :line ,line)
+ nil
+ t))
+ :tag (if (member (cons file line)
+ current-stopped-files-lines)
+ (propertize "→ " 'face 'bold)
+ "")
+ :value (format "%s:%d"
+ (string-trim-left
+ file
+ (regexp-quote
+ (expand-file-name
+ (plist-get dape--config :cwd))))
+ line)))))
+ dape--breakpoints)))
+
+(defun dape--info-press-widget-at-line (predicate-p)
+ (save-excursion
+ (if (funcall predicate-p (widget-at))
+ (widget-button-press (point))
+ (pcase-let ((`(,start . ,end) (bounds-of-thing-at-point 'line))
+ (found))
+ (goto-char start)
+ (while (and (not found)
+ (< (point) end))
+ (cond
+ ((funcall predicate-p (widget-at))
+ (widget-button-press (point))
+ (setq found t))
+ ((eobp)
+ (setq found t))
+ (t
+ (goto-char (next-overlay-change (point))))))))))
+
+(defun dape-info-buton-press-dwim ()
+ "Press button, change stack, change thread or goto breakpoint.
+Depending on line in *dape-info* buffer."
+ (interactive)
+ (dape--info-press-widget-at-line
+ (lambda (widget)
+ (memq (widget-type widget)
+ '(file-link link)))))
+
+(defun dape-info-tree-dwim ()
+ "Toggle tree expansion in *dape-info* buffer."
+ (interactive)
+ (dape--info-press-widget-at-line
+ (lambda (widget)
+ (memq (widget-type widget)
+ '(dape--tree-widget-open dape--tree-widget-close)))))
+
+(defvar dape-info-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "<return>") 'dape-info-buton-press-dwim)
+ (define-key map (kbd "<tab>") 'dape-info-tree-dwim)
+ map))
+
+(define-derived-mode dape-info-mode special-mode "Dape info"
+ "Dape info mode is displays various dape related information.
+See `dape-info' for more information."
+ :interactive nil
+ (let ((inhibit-read-only t))
+ (erase-buffer))
+ (setq-local buffer-read-only t
+ truncate-lines t
+ indent-tabs-mode nil
+ desktop-save-buffer nil
+ tree-widget-image-enable nil))
+
+(defun dape-info ()
+ "Create or select *dape-info* buffer.
+Buffer contains debug session information."
+ (interactive)
+ (let ((buffer (get-buffer-create "*dape-info*"))
+ window)
+ (with-current-buffer buffer
+ (dape-info-mode)
+ (dolist (button dape-info-buttons)
+ (pcase-let ((`(,name . ,fn) button))
+ (widget-create 'link
+ :value name
+ :action
+ (lambda (&rest _)
+ (funcall fn)))
+ (widget-insert " ")))
+ (when dape-info-buttons
+ (widget-insert "\n")
+ (forward-line -1)
+ (let ((ov (make-overlay (line-beginning-position)
+ (line-beginning-position 2))))
+ (overlay-put ov 'face 'region)
+ (overlay-put ov 'priority 1))
+ (forward-line))
+ (setq dape--watched-widget
+ (widget-create 'dape--tree-widget
+ :tag (propertize "Watched" 'face 'bold)
+ :path '("Watched")
+ :open t
+ :expander-p 'dape--expand-watched-p
+ :expander 'dape--expand-watched)
+ dape--scopes-widget
+ (widget-create 'dape--tree-widget
+ :tag (propertize "Variables" 'face 'bold)
+ :path '("Variables")
+ :open t
+ :default t
+ :expander-p 'dape--expand-scopes-p
+ :expander 'dape--expand-scopes)
+ dape--stack-widget
+ (widget-create 'dape--tree-widget
+ :tag (propertize "Stack" 'face 'bold)
+ :path '("Stack")
+ :open t
+ :expander-p 'dape--expand-stack-p
+ :expander 'dape--expand-stack)
+ dape--threads-widget
+ (widget-create 'dape--tree-widget
+ :tag (propertize "Threads" 'face 'bold)
+ :path '("Threads")
+ :open t
+ :expander-p 'identity ;; Always expand
+ :expander 'dape--expand-threads)
+ dape--breakpoints-widget
+ (widget-create 'dape--tree-widget
+ :tag (propertize "Breakpoints" 'face 'bold)
+ :path '("Breakpoints")
+ :open t
+ :expander-p 'identity ;; Always expand
+ :expander 'dape--expand-breakpoints-widget))
+ (widget-setup))
+ (setq window (display-buffer buffer
+ '((display-buffer-in-side-window)
+ . ((side . left)))))
+ (when (called-interactively-p)
+ (select-window window)
+ (goto-char (point-min)))))
+
+
+;;; REPL buffer
+
+(defun dape--completion-frame-id ()
+ (plist-get (dape--current-stack-frame) :id))
+
+(defun dape--repl-insert-text (msg)
+ (cond
+ (dape--repl-insert-text-guard
+ (run-with-timer 0.1 nil 'dape--repl-insert-text msg))
+ (t
+ (progn
+ (setq dape--repl-insert-text-guard t)
+ (when-let ((buffer (get-buffer "*dape-repl*")))
+ (with-current-buffer buffer
+ (save-excursion
+ (condition-case err
+ (progn
+ (goto-char (point-max))
+ (comint-previous-prompt 0)
+ (forward-line -1)
+ (end-of-line)
+ (when-let (line (thing-at-point 'line))
+ (when (eq (aref line 0) ?>)
+ (let ((inhibit-read-only t))
+ (insert "\n"))))
+ (let ((inhibit-read-only t))
+ (insert msg)))
+ (error
+ (setq dape--repl-insert-text-guard nil)
+ (signal (car err) (cdr err))))
+ (setq dape--repl-insert-text-guard nil))))
+ (unless (get-buffer-window "*dape-repl*")
+ (when (stringp msg)
+ (message "%s" (string-trim msg "\\\n" "\\\n"))))))))
+
+(defun dape--repl-input-sender (dummy-process input)
+ (let (cmd)
+ (if (not (dape--live-process t))
+ (comint-output-filter dummy-process
+ "DAPE server not running\n")
+ (cond
+ ;; Run previous input
+ ((and (string-empty-p input)
+ (not (string-empty-p (car (ring-elements comint-input-ring)))))
+ (when-let ((last (car (ring-elements comint-input-ring))))
+ (dape--repl-input-sender dummy-process last)))
+ ;; Run command from `dape-named-commands'
+ ((setq cmd
+ (or (alist-get input dape-repl-commands nil nil 'equal)
+ (and dape-repl-use-shorthand
+ (cl-loop for (key . value) in dape-repl-commands
+ when (equal (substring key 0 1) input)
+ return value))))
+ (setq dape--repl-insert-text-guard t)
+ (comint-output-filter dummy-process "\n> ")
+ (funcall cmd)
+ (setq dape--repl-insert-text-guard nil))
+ ;; Evaluate expression
+ ((dape--stopped-threads)
+ ;; FIXME `dape--repl-insert-text-guard' is used here to not mess up
ordering
+ ;; when running commands that will itself trigger output request
+ (setq dape--repl-insert-text-guard t)
+ (dape--evaluate-expression
+ (dape--live-process)
+ (plist-get (dape--current-stack-frame) :id)
+ (substring-no-properties input)
+ "repl"
+ (dape--callback
+ (comint-output-filter dummy-process
+ (concat
+ (if success
+ (plist-get body :result)
+ msg)
+ "\n\n> "))
+ (setq dape--repl-insert-text-guard nil))))
+ (t
+ (comint-output-filter
+ dummy-process
+ (format "* Unable to send \"%s\", no stopped threads *\n> "
+ input)))))))
+
+(defun dape--repl-completion-at-point ()
+ ;; FIXME repl completion needs some work
+ (let* ((bounds (save-excursion
+ (cons (and (skip-chars-backward "^\s")
+ (point))
+ (and (skip-chars-forward "^\s")
+ (point)))))
+ (column (1+ (- (cdr bounds) (car bounds))))
+ (str (buffer-substring-no-properties
+ (car bounds)
+ (cdr bounds)))
+ (collection
+ (mapcar (lambda (cmd)
+ (cons (car cmd)
+ (format " %s"
+ (propertize (symbol-name (cdr cmd))
+ 'face 'font-lock-builtin-face))))
+ dape-repl-commands))
+ done)
+ (list
+ (car bounds)
+ (cdr bounds)
+ (completion-table-dynamic
+ (lambda (_str)
+ (when-let ((frame-id (plist-get (dape--current-stack-frame) :id)))
+ (dape-request
+ (dape--live-process)
+ "completions"
+ (list :frameId frame-id
+ :text str
+ :column column
+ :line 1)
+ (dape--callback
+ (setq collection
+ (append
+ collection
+ (mapcar
+ (lambda (target)
+ (cons
+ (cond
+ ((plist-get target :text)
+ (plist-get target :text))
+ ((and (plist-get target :label)
+ (plist-get target :start))
+ (let ((label (plist-get target :label))
+ (start (plist-get target :start)))
+ (concat (substring str 0 start)
+ label
+ (substring str
+ (thread-first
+ target
+ (plist-get :length)
+ (+ 1 start)
+ (min (length str)))))))
+ ((and (plist-get target :label)
+ (memq (aref str (1- (length str))) '(?. ?/ ?:)))
+ (concat str (plist-get target :label)))
+ ((and (plist-get target :label)
+ (length> (plist-get target :label)
+ (length str)))
+ (plist-get target :label))
+ ((and (plist-get target :label)
+ (length> (plist-get target :label)
+ (length str)))
+ (cl-loop with label = (plist-get target :label)
+ for i downfrom (1- (length label)) downto 1
+ when (equal (substring str (- (length str)
i))
+ (substring label 0 i))
+ return (concat str (substring label i))
+ finally return label)))
+ (when-let ((type (plist-get target :type)))
+ (format " %s"
+ (propertize type
+ 'face 'font-lock-type-face)))))
+ (plist-get body :targets))))
+ (setq done t)))
+ (while-no-input
+ (while (not done)
+ (accept-process-output nil 0 1)))
+ collection)))
+ :annotation-function
+ (lambda (str)
+ (when-let ((annotation
+ (alist-get (substring-no-properties str) collection
+ nil nil 'equal)))
+ annotation)))))
+
+(define-derived-mode dape-repl-mode comint-mode "Dape REPL"
+ (add-hook 'completion-at-point-functions
+ #'dape--repl-completion-at-point
+ nil
+ t)
+ (setq-local comint-prompt-read-only t
+ comint-input-sender 'dape--repl-input-sender
+ comint-use-prompt-regexp nil
+ comint-process-echoes nil)
+ ;; Stolen from ielm
+ ;; Start a dummy process just to please comint
+ (unless (comint-check-proc (current-buffer))
+ (start-process "dape-repl" (current-buffer) nil)
+ (set-process-query-on-exit-flag (get-buffer-process (current-buffer))
+ nil)
+ (set-process-filter (get-buffer-process (current-buffer))
+ 'comint-output-filter)
+ (comint-output-filter (get-buffer-process (current-buffer))
+ (format
+ "\nWelcome to Dape REPL\n%s\n> "
+ (pp-to-string dape--config)))))
+
+(defun dape-repl ()
+ "Create or select *dape-repl* buffer."
+ (interactive)
+ (let ((buffer-name "*dape-repl*")
+ window)
+ (with-current-buffer (get-buffer-create buffer-name)
+ (dape-repl-mode)
+ (setq window (display-buffer (current-buffer)
+ '((display-buffer-reuse-window
+ display-buffer-in-side-window)
+ . ((side . bottom)
+ (slot . -1)))))
+ (when (called-interactively-p)
+ (select-window window)))))
+
+
+;;; Config
+
+(defvar dape-history nil)
+
+(defun dape--config-eval (config)
+ (cl-labels ((eval-value (value)
+ (cond
+ ((functionp value) (funcall-interactively value))
+ ((plistp value) (dape--config-eval value))
+ ((vectorp value) (cl-map 'vector #'eval-value value))
+ (t value))))
+ (cl-loop for (key value) on config by 'cddr
+ append (cond
+ ((memq key '(modes)) (list key value))
+ (t (list key (funcall #'eval-value value)))))))
+
+(defun dape--config-from-string (str)
+ (let (name read-config base-config)
+ (when (string-empty-p str)
+ (user-error "Expected `dape-config' name."))
+ (setq name (read str)
+ base-config (copy-tree (alist-get name dape-configs))
+ str (substring str (length (symbol-name name))))
+ (unless (string-empty-p str)
+ (setq read-config (read (format "(%s)" str))))
+ (unless (plistp read-config)
+ (user-error "Unexpected `dape-config' format, see `dape'."))
+ (cl-loop for (key value) on read-config by 'cddr
+ do (setq base-config (plist-put base-config key value)))
+ (list name base-config)))
+
+(defun dape--config-diff (pre-eval post-eval)
+ (cl-loop for (key value) on post-eval by 'cddr
+ unless (equal (plist-get pre-eval key) value)
+ append (list key value)))
+
+(defun dape--config-to-string (name pre-eval-config post-eval-config)
+ (let ((config-diff (dape--config-diff pre-eval-config
+ post-eval-config)))
+ (concat (format "%s" name)
+ (when-let ((config-str (and config-diff
+ (prin1-to-string config-diff))))
+ (format " %s"
+ (substring config-str
+ 1
+ (1- (length config-str))))))))
+
+(defun dape--read-config ()
+ (let ((candidate
+ (completing-read
+ "Dape config: "
+ (append
+ (mapcan
+ (lambda (name-config)
+ (let* ((config (cdr name-config))
+ (modes (plist-get config 'modes)))
+ (when (apply 'provided-mode-derived-p major-mode modes)
+ (list (car name-config)))))
+ dape-configs)
+ dape--config-history)
+ nil nil nil 'dape-history)))
+ (if-let ((config
+ (alist-get (intern candidate) dape-configs)))
+ (list (intern candidate) config)
+ (dape--config-from-string candidate))))
+
+;;; Hover
+
+(defun dape-hover-function (cb)
+ (when-let ((symbol (thing-at-point 'symbol)))
+ (dape--evaluate-expression (dape--live-process)
+ (plist-get (dape--current-stack-frame) :id)
+ (substring-no-properties symbol)
+ "hover"
+ (dape--callback
+ (when success
+ (funcall cb
+ (dape--variable-string
+ (plist-put body :name symbol))))))
+ t))
+
+(defun dape--add-eldoc-hook ()
+ (add-hook 'eldoc-documentation-functions #'dape-hover-function nil t))
+
+(defun dape--remove-eldoc-hook ()
+ (remove-hook 'eldoc-documentation-functions #'dape-hover-function t))
+
+
+;;; UI
+
+(defun dape--update-ui ()
+ (dape--remove-stack-pointers)
+ (dolist (watched dape--watched)
+ (plist-put watched :fetched nil))
+ (when-let ((process (dape--live-process))
+ (current-thread (dape--current-thread)))
+ (dape--stack-trace process
+ current-thread
+ (dape--callback
+ (dape--place-stack-pointers process current-thread)
+ (dape--info-update-widget dape--threads-widget
+ dape--stack-widget
+ dape--watched-widget
+ dape--breakpoints-widget)
+ (dape--update-scope process)))))
+
+(defun dape--update-state (msg)
+ (setq dape--state msg)
+ (force-mode-line-update t))
+
+(defun dape--mode-line-format ()
+ (format "Dape:%s"
+ (propertize
+ (or (and (dape--live-process t)
+ (or dape--state
+ "unknown"))
+ "not running")
+ 'face 'mode-line-emphasis)))
+
+(add-to-list 'mode-line-misc-info
+ `(dape--process
+ (" [" (:eval (dape--mode-line-format)) "] ")))
+
+
+;;; Keymaps
+
+(defvar-keymap dape-global-map
+ :doc "Keymap to repeat dape commands. Used in `repeat-mode'."
+ "d" #'dape
+ "p" #'dape-pause
+ "c" #'dape-continue
+ "n" #'dape-next
+ "s" #'dape-step-in
+ "o" #'dape-step-out
+ "r" #'dape-restart
+ "i" #'dape-info
+ "R" #'dape-repl
+ "m" #'dape-read-memory
+ "l" #'dape-log-breakpoint
+ "e" #'dape-expression-breakpoint
+ "b" #'dape-toggle-breakpoint
+ "B" #'dape-remove-all-breakpoints
+ "w" #'dape-watch-dwim
+ "q" #'dape-quit)
+
+(map-keymap-internal (lambda (_ cmd)
+ (unless (memq cmd '(dape
+ dape-repl
+ dape-info
+ dape-read-memory
+ dape-quit))
+ (put cmd 'repeat-map 'dape-global-map)))
+ dape-global-map)
+
+(global-set-key dape-key-prefix dape-global-map)
+
+(provide 'dape)
+
+;;; dape.el ends here
- [elpa] externals/dape 4eb75e39b2 031/123: Small readme fixup, (continued)
- [elpa] externals/dape 4eb75e39b2 031/123: Small readme fixup, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 04aabf1862 041/123: Update screenshots, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 95d52ea585 044/123: Fix parsing of codelldb adapter output on windows #1, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 3d800b349e 045/123: Add godot example config, ELPA Syncer, 2023/12/05
- [elpa] externals/dape b42b7def86 046/123: Fix timers when repl buffer is not available, ELPA Syncer, 2023/12/05
- [elpa] externals/dape efcfc93003 047/123: Fix duplicate variable overlays, ELPA Syncer, 2023/12/05
- [elpa] externals/dape cacddbb8e7 057/123: Improve error printout and do a better job of validating config, ELPA Syncer, 2023/12/05
- [elpa] externals/dape ccb6060b55 067/123: Add disconnect functionality and PID helper for attach requests, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 6da668abc4 009/123: Fix themes link in readme, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 6c501bfbc9 004/123: Fix watch dwim use symbol at point, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 96b1815ed3 001/123: Initial commit,
ELPA Syncer <=
- [elpa] externals/dape a21992c208 002/123: Add screenshot, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 6907fade6a 003/123: Fixup readme, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 572f2b2976 005/123: Fix bugs section, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 32cbd92a76 007/123: Add straight installation to readme, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 1bd018e477 015/123: Update formatting in roadmap section, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 2d4c0e6748 022/123: Add file and line to stack in info buffer, ELPA Syncer, 2023/12/05
- [elpa] externals/dape d896720cc1 011/123: Add projectile configuration in readme, ELPA Syncer, 2023/12/05
- [elpa] externals/dape c780c6f1e2 013/123: Fix crash when % is present in log and expression breakpoints, ELPA Syncer, 2023/12/05
- [elpa] externals/dape e314b97bc1 016/123: Refactor update and update ui, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 480bcd14f8 017/123: Improve REPL welcome message, ELPA Syncer, 2023/12/05