emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/objed 3096642 001/216: Initial commit


From: Stefan Monnier
Subject: [elpa] externals/objed 3096642 001/216: Initial commit
Date: Tue, 8 Jan 2019 12:28:55 -0500 (EST)

branch: externals/objed
commit 309664229223e2217feb7940021a6556c3a4f1ca
Author: Clemera <address@hidden>
Commit: Clemera <address@hidden>

    Initial commit
---
 .gitignore                          |    2 +
 LICENSE                             |  674 ++++++++++
 README.asc                          |  363 ++++++
 images/end_of_block.gif             |  Bin 0 -> 147026 bytes
 images/expand_context.gif           |  Bin 0 -> 132484 bytes
 images/object_nav.gif               |  Bin 0 -> 244175 bytes
 images/remove_comments_in_defun.gif |  Bin 0 -> 178575 bytes
 images/reorder_lines_by_marking.gif |  Bin 0 -> 421280 bytes
 images/senteces_avy.gif             |  Bin 0 -> 176546 bytes
 images/upto.gif                     |  Bin 0 -> 155197 bytes
 objed-objects.el                    | 1958 ++++++++++++++++++++++++++++
 objed.el                            | 2443 +++++++++++++++++++++++++++++++++++
 12 files changed, 5440 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1c17549
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+# Compiled
+*.elc
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f288702
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://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 <https://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
+<https://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
+<https://www.gnu.org/licenses/why-not-lgpl.html>.
diff --git a/README.asc b/README.asc
new file mode 100644
index 0000000..929e2b6
--- /dev/null
+++ b/README.asc
@@ -0,0 +1,363 @@
+:experimental:
+
+
+= Objed - The text object editor
+
+A global minor-mode to navigate and edit text objects. Objed enables
+modal editing and composition of commands, too. It combines ideas of
+other Editors like Vim or Kakoune and tries to align them with regular
+Emacs conventions.
+
+For more information also check my https://www.with-emacs.com[blog].
+
+== Introduction
+
+Text objects are textual patterns like a line, a top level definition,
+a word, a sentence or any other unit of text. When `objed-mode` is
+enabled, certain editing commands (configurable) will activate `objed`
+and enable its modal editing features. When active, keys which would
+usually insert a character are mapped to objed commands. Other keys
+and commands will continue to work as they normally would and exit
+this editing state again.
+
+By default important self inserting keys like kbd:[Space] or
+kbd:[Return] are not bound to modal commands and will exit `objed` on
+insertion. This makes it convenient to move around and continue adding
+new text.
+
+With activation `objed` shows the current object type in the
+`mode-line`. The textual content of the object is highlighted visually
+in the buffer and the cursor color is changed, too. The user can now
+navigate by units of this object, change the object state or switch to
+other object types.
+
+The object state is either `inner` or `whole` and is indicated in the
+modeline by `(i)` or `(w)` after the object type. With inner state,
+anything that would be considered delimiters or padding around an
+object is excluded.
+
+The user can apply operations to objects. By marking objects before
+applying an operation, s?he can even operate on multiple objects at
+once. This works similar to the way you interact with files in
+`dired`. When marking an object the point moves on to the next object
+of this type.
+
+The object type used for initialization is determined by the mapping
+of the entry command (see `objed-cmd-alist`). For example using
+`beginning-of-defun` will activate `objed` using the `defun` object as
+initial object type. With command `next-line`, `objed` would
+initialize with the `line` object.
+
+Objeds modal state provides basic movement commands which move by
+line, word or character. Those switch automatically to the
+corresponding object type, otherwise they work the same as the regular
+Emacs movement commands. Other commands only activate the part between
+the initial position and the new position moved to. By repeating
+commands you can often expand/proceed to other objects. This way you
+can compose movement and editing operations very efficiently.
+
+The expansion commands distinguish between block objects (objects
+built out of lines of text) and context objects (programming
+constructs like strings, brackets or textual components like
+sentences). This way you can quickly expand to the desired objects.
+
+For example to move to the end of the paragraph, the user would first
+move to the end of the line with kbd:[Ctrl - e]. This would activate
+`objed` using the line object with the text moved over. The user can
+now continue to the end of the paragraph by by pressing kbd:[e]
+again. Now s?he is able to proceed even further by pressing kbd:[e]
+again OR to continue by adding new text to the end of the paragraph OR
+to continue by acting on the text moved over, for example killing it
+by pressing kbd:[k].
+
+As often with text editing, the explanation sounds more complicated
+than using it. To get a better impression of the editing workflow with
+`objed` I will try to add some animated demos soon.
+
+To learn more about available features and commands have a look at the
+descriptions below, the commentary section or the docstrings and
+bindings defined in `objed-map`. To define your own operations and
+text objects see `objed-define-op` and `objed-define-object`.
+
+
+## Examples of usage
+
+.Object navigation
+image::./images/object_nav.gif[Object navigation]
+
+++++
+<br>
+++++
+
+.Object expansion
+image::./images/expand_context.gif[Object expansion]
+
+++++
+<br>
+++++
+
+.End of block expansion
+image::./images/end_of_block.gif[End of block expansion]
+
+++++
+<br>
+++++
+
+.Upto context
+image::./images/upto.gif[Upto context]
+
+++++
+<br>
+++++
+
+.Marking objects and act on them
+image::./images/reorder_lines_by_marking.gif[Marking objects and act on them]
+
+++++
+<br>
+++++
+
+.Mark objects inside another one
+image::./images/remove_comments_in_defun.gif[Mark objects inside another one]
+
+++++
+<br>
+++++
+
+.Select current object type with avy
+image::./images/senteces_avy.gif[Select current object type with avy]
+
+++++
+<br>
+++++
+
+## Keys
+
+Although some features are still experimental the basic user interface
+will stay the same. The following gives an overview of available keys
+and commands.
+
+Basic movement commands (switch the object type on movement):
+
+[`objed-map`]
+|===
+|Shortcut |Purpose
+
+|kbd:[f/b]
+|Move forward/backward one character and activate the char object.
+
+|kbd:[s/r]
+|Move forward/backward one word and activate the word object (***).
+
+|kbd:[S/R]
+|Move forward/backward one symbol and activate the symbol object. Skips 
strings and comments.
+
+|kbd:[n/p]
+|Move to the next/previous line and activate the line object.
+|===
+
+
+(***): Emacs uses the kbd:[f/b] keys for word AND character movement
+       (depending on the used modifier). I made the decision to remap
+       kbd:[M-f], kbd:[M-b] to kbd:[M-s], kbd:[M-r] in my personal
+       configuration (using `key-translation-map`). This is by no
+       means necessary but might be something to think
+       about. Afterwards you are able to start word movement with
+       kbd:[M-s/r] and continue moving by words with kbd:[s/r] which
+       is more convenient than switching between kbd:[M-b/f] and
+       kbd:[s/r].  You can still access kbd:[M-s/r] regular bindings
+       by using Meta-shift (kbd:[M-S/R]).
+
+Commands for block objects (objects built out of lines of text):
+
+[`objed-map`]
+|===
+|Shortcut |Purpose
+
+|kbd:[l]
+|Activate (line based) object at point and move to its start. On repeat 
proceed to beginning of the indentation block, comment block, paragraph or 
other block objects.
+
+|kbd:[a]
+|Move to beginning of line and activate the text moved over. On repeat proceed 
to beginning of blocks like explained above.
+
+|kbd:[e]
+|Move to end of line and activate the text moved over. On repeat proceed to 
end of blocks like explained above.
+|===
+
+Commands for context objects. Those objects are common programming
+constructs like defuns, strings, parentheses but also sentences inside
+comments for example. Any whitespace after point is skipped before
+determining the context:
+
+[`objed-map`]
+|===
+|Shortcut |Purpose
+
+|kbd:[t/h]
+|If coming from basic movement the object at point is guessed based on 
context. Point is moved  to the beginning/end of object. This is useful to 
"jump out" of the current context. On repeat move to the previous/next instance 
of current object type
+
+|kbd:[o]
+|Activate the inner part of the object at point and move to the start. This is 
useful to act on the content of the string, brackets and so on. On repeat 
expand to other objects around current position.
+
+|kbd:[u]
+|Move to end of the inner object at point and activate the text moved over. On 
repeat toggle between beginning/end inside the object.
+
+|kbd:[q]
+|Move point to the other side of the current object.
+
+|kbd:[i]
+|Toggle the state of the current object (inner/whole).
+|===
+
+Commands to switch to other objects (and move point to its start):
+
+[`objed-map`]
+|===
+|Shortcut |Purpose
+
+|kbd:[.]
+|Switch To identifier object.
+
+|kbd:[_]
+|Switch to symbol object.
+
+|kbd:[%]
+|Switch to content object (defined by textual content of current object).
+
+|kbd:[c]
+|Prefix to switch to other objects, see `objed-object-map` for available 
objects and `objed-define-object` to add your own.
+|===
+
+Commands to edit objects (applying operations to them). When the
+region is active the operation acts on the current region. To act on
+multiple objects at once you can mark them first (see the "Misc
+commands" below):
+
+[`objed-map`]
+|===
+|Shortcut |Purpose
+
+
+|kbd:[k]
+|Kill current object(s).
+
+|kbd:[d]
+|Delete current object(s).
+
+|kbd:[w]
+|Copy current object(s).
+
+|kbd:[y]
+|Yank last killed text at point.
+
+|kbd:[w]
+|Copy current object(s).
+
+|kbd:[Tab]
+|Indent object(s).
+
+|kbd:[;]
+|Un/comment object(s).
+
+|kbd:[:]
+|Comment and duplicate object.
+
+|kbd:[$]
+|Flyspell region.
+
+|kbd:[`]
+|Prefix to surround object(s) with any pair using `electric` (built-in).
+
+
+|kbd:["/[/(/[/{]
+|Surround object with corresponding chars using `electric`,
+
+|kbd:[x]
+|Prefix to access other operations, see `objed-op-map` for available 
operations and `objed-define-op` to add your own.
+
+|===
+
+Misc commands:
+
+[`objed-map`]
+|===
+|Shortcut |Purpose
+
+|kbd:[,]
+|Pop to last state, which restores the last position and any object data.
+
+|kbd:[j]
+|Choose an instance of current object type with completion, using the contents 
of the first line for completion.
+
+|kbd:[z]
+|Choose an instance of current object type on the screen with `avy`.
+
+|kbd:[m]
+|Add/Remove current object to marked objects and move to next.
+
+|kbd:[M]
+|Add/Remove current object to marked objects and move to previous.
+
+|kbd:[v]
+|Scroll up.
+
+|kbd:[M - v]
+|Scroll down.
+
+|kbd:[/]
+|Undo last edit command.
+
+|kbd:[Ctrl - Space]
+|Set mark.
+
+|kbd:[Ctrl - h]
+|Get key binding help (uses `which-key` if available).
+
+|kbd:[g/Ctrl - g]
+|Exit and deactivate `objed`.
+|===
+
+
+Dispatch keys (dispatch to any object defined in `objed-object-map`).
+You can add your own prefix bindings using `objed-define-dispatch`.
+
+[`objed-map`]
+|===
+|Shortcut |Purpose
+
+|kbd:[*]
+|Mark all instances of current object inside another object type.
+
+|kbd:[<]
+|Activate part from point backward until boundary of some object.
+
+|kbd:[>]
+|Activate part from point forward until boundary of some object.
+|===
+
+
+== Installation
+
+For now you need to manually install `objed`. If you use `package.el`
+you should be able to `package-install-file` pointing at the folder to
+which you downloaded the code. Otherwise manually add it to your
+`load-path` and load it like this:
+
+```elisp
+(require 'objed)
+(objed-mode)
+```
+
+
+== Contribute
+
+I'm happy to receive pull requests or ideas to improve this
+package. Some parts suffer from the bottom up approach of developing
+it, but this also allowed me to experiment a lot and try ideas while
+working on them, something that Emacs is especially good at. Most of
+the features are tested using `emacs-lisp-mode` but hopefully there
+aren't to many problems using modes for other languages, I tried my
+best to write text objects in a language agnostic way by using Emacs
+syntax information. Testing this and writing tests in general would be
+an important next step.
+
diff --git a/images/end_of_block.gif b/images/end_of_block.gif
new file mode 100644
index 0000000..d24b27e
Binary files /dev/null and b/images/end_of_block.gif differ
diff --git a/images/expand_context.gif b/images/expand_context.gif
new file mode 100644
index 0000000..737e9be
Binary files /dev/null and b/images/expand_context.gif differ
diff --git a/images/object_nav.gif b/images/object_nav.gif
new file mode 100644
index 0000000..0853549
Binary files /dev/null and b/images/object_nav.gif differ
diff --git a/images/remove_comments_in_defun.gif 
b/images/remove_comments_in_defun.gif
new file mode 100644
index 0000000..7517375
Binary files /dev/null and b/images/remove_comments_in_defun.gif differ
diff --git a/images/reorder_lines_by_marking.gif 
b/images/reorder_lines_by_marking.gif
new file mode 100644
index 0000000..9d29211
Binary files /dev/null and b/images/reorder_lines_by_marking.gif differ
diff --git a/images/senteces_avy.gif b/images/senteces_avy.gif
new file mode 100644
index 0000000..c3187e0
Binary files /dev/null and b/images/senteces_avy.gif differ
diff --git a/images/upto.gif b/images/upto.gif
new file mode 100644
index 0000000..1906b2f
Binary files /dev/null and b/images/upto.gif differ
diff --git a/objed-objects.el b/objed-objects.el
new file mode 100644
index 0000000..466c213
--- /dev/null
+++ b/objed-objects.el
@@ -0,0 +1,1958 @@
+;;; objed-objects.el --- Part of the objed package -*- lexical-binding: t; -*-
+;; Copyright (C) 2018  Clemens Radermacher
+
+;; Author: Clemens Radermacher <address@hidden>
+;; Maintainer: Clemens Radermacher <address@hidden>
+
+;; 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:
+;;
+;; Code for text objects used by `objed'.
+;;; Code:
+
+;; * Bytecomp
+
+;; info for byte-comp
+(declare-function avy--process "ext:avy")
+(declare-function avy--style-fn "ext:avy")
+
+(declare-function sgml-skip-tag-backward "ext:sgml-mode")
+(declare-function sgml-skip-tag-forward "ext:sgml-mode")
+
+(declare-function org-at-heading-p "ext:org")
+(declare-function org-back-to-heading "ext:org")
+
+(declare-function outline-back-to-heading "ext:outline")
+(declare-function outline-next-heading "ext:outline")
+(declare-function outline-previous-heading "ext:outline")
+(declare-function outline-next-visible-heading "ext:outline")
+(declare-function outline-previous-visible-heading "ext:outline")
+
+;; dyn bindings
+(defvar avy-action nil)
+(defvar avy-all-windows nil)
+
+;; * Macros
+
+(defmacro objed-define-object (key name &rest args)
+  "Declare a text object for `objed'.
+
+Usage:
+
+  (objed-define-object key name
+     [:keyword [code]]...)
+
+KEY is a string to be interpreted as spelled-out keystrokes,
+using same format as for `kbd'. See documentation of
+‘edmacro-mode’ for details.
+
+NAME is a symbol which defines the name which will be used to
+refer to this object. ARGS is a list of keyword arguments and
+corresponding values according to the following descriptions:
+
+:atp
+
+Code to run which returns non-nil if point is right before the
+object.
+
+:ref
+
+Code to run which returns an object symbol which can be used to
+navigate references of an object. This defaults to the textual
+content of an object.
+
+:get-obj
+
+Code to run which returns object positions as a list of the form:
+
+    ((object-start object-end)
+     (inner-start inner-end))
+
+The function `objed-make-object' should be used to create such a
+list. If there is on object at point the code should return nil.
+
+
+:get-inner (optional)
+
+Code to run to return the inner positions for the object as a
+list of the form:
+
+    (inner-start inner-end)
+
+The function `objed-make-inner' should be used to create such a
+list. When this code runs the buffer is narrowed to the object.
+Using this keyword makes it possible to determine the inner part
+of an object seperately. One use case of this is to provide mode
+specific versions for the inner part of some object type.
+
+
+:try-next (optional)
+
+Code to run which moves point to the next available object. The
+code can assume it runs after point is moved out to the end of
+the current one if any. This will called until :get-obj returns
+non-nil. To indicate that search needs to be stopped, throw an
+error.
+
+
+:try-prev (optional)
+
+Code to run which moves point to the previous available object.
+The code can assume it runs after point is moved out to the
+beginning of the current one if any. This will called
+until :get-obj returns non-nil. To indicate that search needs to
+be stopped, throw an error.
+
+:mode (optional)
+
+Object defintions which don't use this keyword apply to all
+modes. If given it should be a symbol of a `major-mode'. Any
+keyword definitions used for this object will then override the
+default ones when in this mode."
+  (declare (indent 2))
+  (let* ((mode (plist-get args :mode))
+         (fname (if mode
+                    (intern (format "objed-%s-%s-object" name mode))
+                  (intern (format "objed-%s-object" name))))
+         (args (objed--get-arg-plist
+                args
+                '(:mode :atp :ref :get-obj :get-inner :try-next :try-prev)))
+         (arg (make-symbol "arg"))
+         (cbody nil)
+         (doc (format "%s object." (capitalize (symbol-name name))))
+         (atp (plist-get args :atp))
+         (obj (plist-get args :get-obj))
+         (inner (plist-get args :get-inner))
+         (next (plist-get args :try-next))
+         (prev (plist-get args :try-prev))
+         (ref  (plist-get args :ref)))
+
+    (unless mode
+      (push `((and (eq real-this-command ',fname)
+                   (not ,arg))
+              (objed--object-dispatch ',name))
+            cbody))
+    (when atp
+      (push `((eq ,arg :atp)
+              ,atp)
+            cbody))
+    (when ref
+      (push `((eq ,arg :ref)
+              ,ref)
+            cbody))
+    (when obj
+      (push `((eq ,arg :get-obj)
+              ,obj)
+            cbody))
+    (when inner
+      (push `((eq ,arg :get-inner)
+              ,inner)
+            cbody))
+    (when next
+      (push `((eq ,arg :try-next)
+              ,next)
+            cbody))
+    (when prev
+      (push `((eq ,arg :try-prev)
+              ,prev)
+            cbody))
+
+    (cond (mode
+           (push `(t ,arg) cbody)
+           `(defun ,fname (,arg)
+              ,doc
+              (cond ,@(nreverse cbody))))
+          (t
+           (let ((res (list 'progn)))
+             (when key
+               (push `(define-key  objed-object-map
+                        (kbd ,key) ',fname)
+                     res))
+             (push `(defun ,fname (,arg)
+                      ,doc
+                      (interactive "i")
+                      (cond ,@(nreverse cbody)))
+                   res)
+             (nreverse res))))))
+
+
+(defmacro objed--with-narrow-for-text (&rest body)
+  "Execute BODY narrowed to string or comment."
+  `(save-restriction
+    ;; stay inside
+     (unless (derived-mode-p 'text-mode)
+       (objed--narrow-if-string-or-comment))
+     ,@body))
+
+
+(defun objed--object-dispatch (name)
+  "Dispatch according to object NAME.
+
+Uses `objed--dispatch-alist' and defaults to
+update to given object."
+  (let* ((cmd (key-binding
+              (vector (aref (this-command-keys-vector) 0))))
+        (binding (assq cmd objed--dispatch-alist)))
+    (cond (binding
+          (funcall (cdr binding) name))
+         (t
+          ;; object called as command via M-x
+          (when (not objed--buffer)
+             (objed--init name))
+          ;; TODO: do something useful if called twice?
+          ;; (eq name objed--object)
+          (when (objed--switch-to name)
+            (goto-char (objed--beg)))))))
+
+(defun objed--inside-object-p (obj)
+  "Return non-nil if point point inside object OBJ."
+  (let*  ((objed--object obj)
+         (objed--obj-state 'whole)
+         (obj (if (symbolp obj)
+                  (objed--get)
+                obj)))
+    (when (and obj (not (objed--distant-p obj)))
+      obj)))
+
+
+;; * Global vars saving object information
+;; TODO: use defstruct object instead
+
+(defvar objed--object nil
+  "The symbol of the current object.")
+
+(defvar objed--current-obj nil
+  "The current object position data.
+
+Positions are stored in a list of the form:
+
+    ((object-start object-end)
+     (inner-start inner-end))")
+
+(defvar objed--obj-state nil
+  "The state used to get object positions.
+
+Either the symbol `whole' or `inner'.")
+
+
+(defvar objed--marked-ovs nil
+  "List of overlays of marked objects.")
+
+(defun objed--copy-object (&optional obj)
+  "Make a deep copy of object OBJ.
+
+OBJ defaults to `objed--current-obj'."
+  (let ((obj (or obj objed--current-obj)))
+    (list (copy-sequence (car obj))
+         (copy-sequence (cadr obj)))))
+
+
+;; * Get object positions
+
+(defun objed--beg (&optional obj)
+  "Get beginning position of object.
+
+OBJ is the object to use and defaults to `objed--current-obj'."
+  (let ((obj (or obj objed--current-obj)))
+    (caar obj)))
+
+
+(defun objed--end (&optional obj)
+  "Get end position of object.
+
+OBJ is the object to use and defaults to `objed--current-obj'."
+  (let ((obj (or obj objed--current-obj)))
+    (cadr (car obj))))
+
+(defun objed--other (&optional obj)
+  "Return object position opposite to point.
+
+OBJ is the object to use and defaults to `objed--current-obj'."
+  (let ((obj (or obj objed--current-obj)))
+    (if (/= (point) (objed--end))
+        (objed--end obj)
+      (objed--beg obj))))
+
+(defun objed--min (&optional obj)
+  "Get minimal position of current object.
+
+OBJ is the object to use and defaults to `objed--current-obj'."
+  (let ((obj (or obj objed--current-obj)))
+    (objed--apply #'min obj)))
+
+
+(defun objed--max (&optional obj)
+  "Get maximal position of current object.
+
+OBJ is the object to use and defaults to `objed--current-obj'."
+  (let ((obj (or obj objed--current-obj)))
+    (objed--apply #'max obj)))
+
+
+(defun objed--current (&optional obj)
+  "Get the current range of interest.
+
+If the region is active the range is defined by the region bounds
+otherwise the its the head of object OBJ which defaults to
+`objed--current-obj'."
+  (let ((obj (or obj objed--current-obj)))
+    (if (region-active-p)
+        (list (region-beginning) (region-end))
+      (car obj))))
+
+(defun objed--bounds (&optional obj)
+  "Get the current object bounds.
+
+If the region is active bounds are the region bounds otherwise
+the head of object OBJ which defaults to `objed--current-obj'."
+  (let ((obj (or obj objed--current-obj)))
+    (if (region-active-p)
+        (cons (region-beginning) (region-end))
+      (cons (objed--beg obj)
+           (objed--end obj)))))
+
+(defun objed--alt (&optional obj)
+  "Get the current tail of `objed--current-obj'.
+
+OBJ is the object to use and defaults to `objed--current-obj'."
+    (let ((obj (or obj objed--current-obj)))
+      (cadr obj)))
+
+(defun objed--alt-beg (&optional obj)
+  "Get beginning position of tail of object.
+
+OBJ is the object to use and defaults to `objed--current-obj'."
+  (let* ((obj (or obj objed--current-obj))
+         (posn (objed--alt obj)))
+    (car posn)))
+
+(defun objed--alt-end (&optional obj)
+  "Get end position of tail of object.
+
+OBJ is the object to use and defaults to `objed--current-obj'."
+  (let* ((obj (or obj objed--current-obj))
+         (posn (objed--alt obj)))
+    (cadr posn)))
+
+(defun objed--collect-backward (pos min &optional ends)
+  "Collect object positions in backward direction.
+
+Start from position POS and stop at MIN position. The resulting
+list contains cons cells of the start positions of the objects
+and the current window. If ENDS is non-nil collect end positions
+instead."
+  (let ((cw (get-buffer-window))
+        (sobj nil)
+        (posns nil)
+        (objed--obj-state 'whole)
+        (obj nil))
+    (save-excursion
+      (goto-char pos)
+      (while (and (> pos min)
+                  (setq obj (objed--get-prev (point)))
+                  (not (equal obj sobj)))
+        (setq sobj obj)
+        (goto-char (setq pos (objed--beg obj)))
+        (push (cons (if ends
+                        (objed--skip-backward
+                         (objed--max obj) 'ws)
+                      (objed--skip-forward pos 'ws))
+                    cw)
+              posns))
+      posns)))
+
+(defun objed--collect-forward (pos max)
+  "Collect object positions in forward direction.
+
+Start from position POS and stop at MAX position. The resulting
+list contains cons cells of the start positions of the objects
+and the current window."
+  (let ((cw (get-buffer-window))
+        (sobj nil)
+        (posns nil)
+        (objed--obj-state 'whole)
+        (obj nil))
+    (save-excursion
+      (goto-char pos)
+      (while (and (< pos max)
+                  (setq obj (objed--get-next (point)))
+                  (not (equal obj sobj)))
+        (setq sobj obj)
+        (goto-char (setq pos (objed--end obj)))
+        (push (cons (objed--skip-forward (objed--beg obj) 'ws)
+                    cw)
+              posns)))
+    (setq posns (nreverse posns))))
+
+(defun objed--collect-object-positions (beg end &optional fromp)
+  "Collect object positions.
+
+Returns object positions between BEG and END.
+
+If FROMP is non-nil collect from that position otherwise collect before
+and after current object.
+
+The resulting list contains cons cells of the start positions of
+the objects and the current window."
+  (append (objed--collect-backward
+           (or fromp (objed--min))
+           beg)
+          (objed--collect-forward
+           (or fromp (objed--max))
+           end)))
+
+
+(defun objed--collect-object-lines ()
+  "Collect first lines of objects before and after current object.
+
+Each string has its position as property pos on the first
+character of the string."
+  (let (lines llb lle lb le)
+    (dolist (pos2win (objed--collect-object-positions
+                      (point-min)
+                      (point-max))
+                     (nreverse lines))
+      (save-excursion
+        (setq lle le)
+        (setq llb lb)
+        (goto-char (car pos2win))
+        (let ((str (buffer-substring
+                    (setq lb (objed--skip-forward
+                              (line-beginning-position) 'ws))
+                    (setq le (line-end-position)))))
+          ;; one object per line
+          (when (and (or (not llb)
+                        (< lle lb)
+                        (not lle)
+                        (> llb le))
+                    (not (string= "" str)))
+            (push (cons str (point)) lines)))))))
+
+
+
+(defun objed--ace-until (&optional start back)
+  "Get position of object using `avy'.
+
+Start at pos START. Default to forward unless BACK is non-nil."
+  (let* ((avy-action #'identity)
+         (avy-style 'at-full)
+         (avy-all-windows t)
+         (posns (if back
+                    (objed--collect-backward
+                     (or start (point))
+                     (window-start) t)
+                  (objed--collect-forward
+                   (or start (point))
+                   (window-end)))))
+    (save-excursion
+      (cond (posns
+             (let ((pos (if (> (length posns) 1)
+                            (avy--process posns (avy--style-fn avy-style))
+                          (caar posns))))
+               (when (integer-or-marker-p pos)
+                 (objed--get back pos))))
+             (t
+              (prog1 nil
+                (message "No objects found.")))))))
+
+
+(defun objed--get (&optional dir pos)
+  "Get object at current position.
+
+Direction defaults to forward unless DIR is non-nil which means
+to search backwards.
+
+POS defaults to point. When no object is found at current
+position returns the next accessible one in DIR. Object position
+order depends on `objed--obj-state'."
+  (save-excursion
+    (let ((darg (if dir :try-prev :try-next))
+          (stop (if dir #'bobp #'eobp)))
+      (when pos
+         (goto-char pos))
+      (let (invisible break nobj obj)
+        ;; while there is no new object found which is visible
+        ;; and the buffer boundary is not reached
+        (while (and (not break)
+                    (or (not (and (setq nobj (objed--object :get-obj))
+                                  (and nobj (not (equal obj nobj)))))
+                        (and nobj
+                             ;; update the last seen one
+                             (setq obj nobj)
+                             (setq invisible
+                                   (objed--invisible-p (objed--beg nobj)))))
+                    (not (funcall stop)))
+          (cond (invisible
+                 (setq invisible nil)
+                 (goto-char (if dir
+                                (objed--prev-visible-point)
+                              (objed--next-visible-point))))
+                (t
+                 (let ((f (if dir  '> '<))
+                       (step (if dir -1 1)))
+                   (unless (funcall stop)
+                     (forward-char step)
+                     (let ((pos (point)))
+                       (objed--object darg)
+                       ;; check for valid move direction to avoid inf. loop if
+                       ;; the code of object misbehaves
+                       (when (funcall f (point) pos)
+                         (setq break t))))))))
+        (if (objed--inner-p)
+            (nreverse nobj)
+          nobj)))))
+
+
+(defun objed--get-object (o &optional s)
+  "Get object O with state S."
+  (let ((objed--object o)
+       (objed--obj-state (or s 'whole)))
+    (objed--get)))
+
+(defun objed--name2func (name &optional no-mode)
+  "Return function name for object with NAME.
+
+If NO-MODE is non-nil, ignore mode specific versions."
+  (let ((name (or (and (symbolp name) (symbol-name name))
+                  name)))
+    (or (and (not no-mode)
+             (intern-soft (format "objed-%s-%s-object" name major-mode)))
+        (intern-soft (format "objed-%s-object" name))
+        (error "Object unknown: %s" name))))
+
+(defun objed--object (query &optional obj no-mode)
+  "Call current object function with QUERY.
+
+OBJ defaults to variable `objed--object'. If NO-MODE is non-nil ignore mode
+specific versions of object."
+  (let* ((obj (or obj objed--object))
+         (objf (objed--name2func obj no-mode))
+         ;; for calling the object func
+         (inhibit-message t)
+         (overriding-terminal-local-map nil)
+         (res (objed--handle-query query objf)))
+    (if (keywordp res)
+        (objed--object res obj t)
+      res)))
+
+(defun objed--handle-query (query objf)
+  "Hand query QUERY for object function OBJF."
+  (cond ((memq query '(:try-next :try-prev))
+        (condition-case nil
+            (funcall objf query)
+          ((end-of-buffer beginning-of-buffer search-failed scan-error)
+           (ignore))))
+       (t
+        (funcall objf query))))
+
+(defun objed--next-visible-point (&optional pos)
+  "Get next visible position.
+
+Should start from an invisible position POS. POS defaults to
+point."
+  (next-single-char-property-change
+   (or pos (point)) 'invisible))
+
+(defun objed--prev-visible-point (&optional pos)
+  "Get previous visible position.
+
+Should start from an invisible position POS. POS defaults to
+point."
+  (previous-single-char-property-change
+   (or pos (point)) 'invisible))
+
+(defun objed--invisible-p (&optional pos)
+  "Check if point is at an invisible position.
+
+Position POS defaults to point."
+  (cl-dolist (ol (overlays-at (or pos (point))))
+    ;; see, reveal.el
+    ;; overlay alive
+    (when (overlay-start ol)
+      (let ((inv (overlay-get ol 'invisible)))
+        (when (and inv
+                   ;; make sure it's actually invisible
+                   (consp buffer-invisibility-spec)
+                   (cdr (assq inv buffer-invisibility-spec)))
+          (cl-return t))))))
+
+(defun objed--get-next (&optional from)
+  "Get next object from position or object.
+
+If FROM is a position search from there otherwise search starts
+from end of object FROM."
+  (let ((obj (or from objed--current-obj)))
+    (save-excursion
+      (when obj
+        (if (integer-or-marker-p obj)
+            (goto-char obj)
+         (goto-char (objed--max obj))))
+      (objed--object :try-next)
+      (objed--get))))
+
+(defun objed--get-prev (&optional from)
+  "Get previous object from position or object.
+
+If FROM is a position search from there otherwise search starts
+from beginning of object FROM."
+  (let ((obj (or from objed--current-obj)))
+    (save-excursion
+      (when obj
+        (if (integer-or-marker-p obj)
+            (goto-char obj)
+         (goto-char (objed--min obj))))
+      (objed--object :try-prev)
+      (objed--get t))))
+
+;; * Helpers to work with object format
+
+
+(defun objed--update-current-object (&optional range)
+  "Update positions of current object.
+
+Update `objed--current-obj' to RANGE which defaults to object at
+point. If RANGE is a single item list only update the head of
+current object position data."
+  (cond ((null range)
+         ;; get current object at point
+         (setq objed--current-obj (objed--get)))
+        ((and (consp range)
+              (not (consp (cdr range))))
+        (error "Wrong format for object data"))
+        (t
+         (setq objed--current-obj range))))
+
+
+(defun objed--switch-to (o &optional state odata)
+  "Switch to object O.
+
+STATE is the state for the object and defaults to whole. If ODATA
+is non-nil it is used as object position data, otherwise
+calculate the data of the object at current position using
+`objed--get'."
+  (setq objed--object o)
+  (setq objed--obj-state (or state 'whole))
+  (setq objed--current-obj (or odata (objed--get))))
+
+
+(cl-defun objed--change-to (&key beg end ibeg iend)
+  "Change position data of current object.
+
+BEG: the beginning position
+END: the end position
+IBEG: the beginning position of the inner part
+IEND: the end position of the inner part"
+  (cond ((eq objed--obj-state 'whole)
+        (when beg
+          (setf (car (car objed--current-obj)) beg))
+        (when end
+          (setf (car (cdar objed--current-obj)) end))
+        (when ibeg
+          (setf (car (cadr objed--current-obj)) ibeg))
+        (when iend
+          (setf (cadr (cadr objed--current-obj)) iend)))
+       ((eq objed--obj-state 'inner)
+        (when ibeg
+          (setf (car (car objed--current-obj)) ibeg))
+        (when iend
+          (setf (car (cdar objed--current-obj)) iend))
+        (when beg
+          (setf (car (cadr objed--current-obj)) beg))
+        (when end
+          (setf (cadr (cadr objed--current-obj)) end)))
+       (t
+        (error "No valid `objed--obj-state'"))))
+  
+
+(defun objed--distant-p (o)
+  "Determine if point is outside object O."
+  (and o
+       (not (<= (objed--min o)
+               (point) (objed--max o)))))
+
+(defun objed--do-all (f)
+  "Apply function F to all accessible objects.
+
+F recieves object range as its argument which is determined
+according to `objed--obj-state'."
+  (let ((obj nil)
+        (sobj nil)
+        (inhibit-message t)
+        (n 1))
+    ;; current one
+    (funcall f objed--current-obj)
+    ;; backward
+    (goto-char (objed--min))
+    (setq sobj objed--current-obj)
+    (while (and (> (point) (point-min))
+                (setq obj (objed--get-prev (point)))
+                (not (equal obj sobj)))
+      (goto-char (objed--min obj))
+      (funcall f obj)
+      (cl-incf n)
+      (setq sobj obj)
+      (goto-char (objed--min obj)))
+    ;; FIXME
+    (when objed--marked-ovs
+      (setq objed--marked-ovs
+           (nreverse objed--marked-ovs)))
+    ;; forward
+    (goto-char (objed--max))
+    (setq sobj objed--current-obj)
+    (while (and (< (point) (point-max))
+                (setq obj (objed--get-next (point)))
+                (not (equal obj sobj)))
+      (funcall f obj)
+      (cl-incf n)
+      (setq sobj obj)
+      (goto-char (objed--max obj)))
+    n))
+
+
+(defun objed--get-object-for-cmd (cmd)
+  "Guess which object to use.
+
+CMD is the command for which object should be guessed. Returns
+the guessed object."
+  (let ((c (cdr (assq cmd objed-cmd-alist))))
+    (if (consp c) (objed--at-p c) c)))
+
+
+(defun objed--in-p (c &optional inner)
+  "Return object name point is in.
+
+C is a list of object names to test for. If INNER is given check
+object data for inner state."
+  (let ((o nil))
+    (cl-dolist (cand c)
+      (when (and (setq o (objed--object :get-obj cand))
+                (if inner (setq o (nreverse o)) o)
+                (<= (objed--beg o)
+                    (point)
+                    (objed--end o)))
+       (cl-return cand)))))
+
+(defun objed--at-p (c)
+  "Return object name at point.
+
+C is a list of object names to test for."
+  (cl-dolist (cand c)
+    (when (objed--object :atp cand)
+      (cl-return cand))))
+
+(defun objed--at-beg-p (c)
+  "Return object name at point.
+
+C is a list of object names to test for."
+  (let ((o (objed--at-p c)))
+    (when o
+      (objed--save-state
+       (objed--switch-to o)
+       (= (objed--beg) (point))))))
+
+
+(defun objed--apply (func &optional obj)
+  "Apply function FUNC on postions of object.
+
+OBJ defaults to `objed--current-obj'."
+  (let ((obj (or obj objed--current-obj)))
+    (when obj
+      (apply func
+             (append (car obj)
+                     (cadr obj))))))
+
+
+(defun objed--merge (obj1 obj2)
+  "Merge objects OBJ1 and OBJ2 to build a new object."
+  (objed-make-object :beg (objed--min obj1)
+                     :end (objed--max obj2)))
+
+
+(defun objed--reverse ()
+  "Exchange current objects head and tail."
+  (if (objed--inner-p)
+      (setq objed--obj-state 'whole)
+    (setq objed--obj-state 'inner))
+  (objed--update-current-object
+   (nreverse objed--current-obj)))
+
+
+(defun objed--inner-p ()
+  "Return non-nil if current objects state is inner."
+  (eq objed--obj-state 'inner))
+
+(defun objed--goto-next (&optional arg)
+  "Move to the next object.
+
+With postitive prefix argument ARG move to the nth next object."
+  (let ((arg (or arg 1)))
+    (dotimes (_ arg)
+      (let ((obj (objed--get-next)))
+        (when obj
+          (objed--update-current-object obj)
+          (objed--goto-char (objed--beg obj)))))))
+
+
+(defun objed--goto-previous (&optional arg)
+  "Move to the previous object.
+
+With postitive prefix argument ARG move to the nth previous
+object."
+  (let ((arg (or arg 1)))
+    (dotimes (_ arg)
+      (let ((obj (objed--get-prev)))
+        (when obj
+          (objed--update-current-object obj)
+          (objed--goto-char (objed--beg obj)))))))
+
+
+
+(defun objed--make-object-overlay (&optional obj)
+  "Create an overlay to mark current object.
+
+OBJ is the object to use and defaults to `objed--current-obj'."
+  (let ((obj (or obj objed--current-obj)))
+    (objed--make-mark-overlay (objed--beg obj)
+                             (objed--end obj))))
+
+
+(defun objed--make-mark-overlay (beg end)
+  "Make an objed overaly over region between BEG, END."
+  (let ((ov (make-overlay beg end)))
+    (overlay-put ov 'objed t)
+    (overlay-put ov 'face 'objed-mark)
+    (overlay-put ov 'evaporate t)
+    (overlay-put ov 'rear-nonsticky t)
+    ov))
+
+(defun objed--mark (beg end)
+  "Mark region between BEG and END."
+  (push (objed--make-mark-overlay beg end)
+       objed--marked-ovs))
+
+(defun objed--mark-object (&optional obj append)
+  "Mark current object.
+
+If OBJ is given use it instead `objed--current-obj' If APPEND is
+non-nil append to the list of marked objects."
+  (let ((obj (or obj objed--current-obj)))
+    (if append
+       (setq objed--marked-ovs
+             (append objed--marked-ovs
+                     (list (objed--make-object-overlay obj))))
+      (push (objed--make-object-overlay obj)
+           objed--marked-ovs))))
+
+(defun objed--unmark-all ()
+  "Remove all marked objects."
+  (while objed--marked-ovs
+    (delete-overlay (pop objed--marked-ovs))))
+
+(defun objed--mark-ovps (ovsps)
+  "Mark objects using position data OVSPS."
+  (dolist (el ovsps)
+    (objed--mark (car el) (cdr el))))
+
+(defun objed--toggle-mark (&optional obj append)
+  "Unmark/Mark object.
+
+If OBJ is given use it instead `objed--current-obj' If APPEND is
+non-nil append to list of marked objects when marking."
+  (let ((obj (or obj objed--current-obj)))
+    (unless (objed--unmark-object obj)
+      (objed--mark-object obj append))))
+
+(defun objed--unmark-object (&optional obj)
+  "Unmark objects within current object.
+
+If OBJ is given use it instead `objed--current-obj'."
+  (let ((obj (or obj objed--current-obj))
+        (unmarked nil))
+    (cl-dolist (ov (overlays-in (objed--beg obj)
+                                (objed--end obj))
+                   unmarked)
+      (when (overlay-get ov 'objed)
+        (setq unmarked t)
+        (setq objed--marked-ovs
+              (delq ov objed--marked-ovs))
+        (delete-overlay ov)))
+    unmarked))
+
+
+;; * Creating objects
+
+(defun objed-bounds-from-region-cmd (cmd)
+  "Return buffer positions of region created by command CMD.
+
+Like for `bounds-of-thing-at-point' the positions are returned as
+a cons cell."
+  (let ((mark-active nil)
+        (last-command nil)
+        (inhibit-message t)
+       (objed--block-p t)
+        (message-log-max nil)
+        (current-prefix-arg nil))
+    (save-mark-and-excursion
+     (funcall-interactively cmd)
+     (cons (region-beginning) (region-end)))))
+
+(defun objed--inner-default (beg end)
+  "Return positions for inner range at runtime.
+
+BEG and END are the positions of the whole object.
+
+Tries to get inner positions by query current object
+for :get-inner. If that fails leading and trailing whitespace is
+skipped to determine the inner positions."
+  (let ((inner (or (save-excursion
+                    (save-restriction
+                      (narrow-to-region
+                       (objed--skip-forward beg 'ws)
+                       (objed--skip-backward end 'ws))
+                      (goto-char (point-min))
+                      (objed--object :get-inner)))
+                  (list (objed--skip-forward beg 'ws)
+                        (objed--skip-backward end 'ws)))))
+    (if (<= beg (car inner) (cadr inner) end)
+       inner
+      ;; fallback
+      (list (point) (1+ (point))))))
+
+(cl-defun objed-make-inner (&key ibeg iend ibounds)
+  "Helper to create internal used format of inner object part from positions.
+
+Positions of the inner part of the object can be provided as
+positions IBEG, IEND or as a cons cell of positions IBOUNDS."
+  (cond ((and (integer-or-marker-p ibeg)
+              (integer-or-marker-p iend))
+         (list ibeg iend))
+        ((and (consp ibounds)
+              (not (consp (cdr ibounds))))
+         (list (car ibounds)
+               (cdr ibounds)))))
+
+
+(cl-defun objed-make-object (&key obounds beg end ibounds ibeg iend)
+  "Helper to create internal used object format from positions.
+
+Positions of the whole object can be provided by BEG, END or a
+cons cell OBOUNDS.
+
+The positions of the inner part can be provided by IBEG, IEND or
+a cons cell IBOUNDS. If inner positions are omitted
+`objed--inner-default' is used to determine them."
+  (cl-assert (and (not (and obounds beg end))
+                  (not (and ibounds ibeg iend))))
+  (cond ((and (integer-or-marker-p beg)
+              (integer-or-marker-p end)
+              (integer-or-marker-p ibeg)
+              (integer-or-marker-p iend))
+         (list (list beg end)
+               (list ibeg iend)))
+        ((and (integer-or-marker-p beg)
+              (integer-or-marker-p end))
+         (cond ((consp ibounds)
+                (objed-make-object :beg beg
+                                  :end end
+                                  :ibeg (car ibounds)
+                                  :iend (cdr ibounds)))
+               ((or (functionp ibeg)
+                    (functionp iend))
+                (objed-make-object :beg beg
+                                   :end end
+                                   :ibeg (or (and (functionp ibeg)
+                                                  (funcall ibeg beg))
+                                             ibeg)
+                                   :iend (or (and (functionp iend)
+                                                  (funcall iend end))
+                                             iend)))
+
+               (t
+                (list (list beg end)
+                      (objed--inner-default beg end)))))
+        ((consp obounds)
+         (cond ((consp ibounds)
+                (objed-make-object :beg (car obounds)
+                                   :end (cdr obounds)
+                                   :ibeg (car ibounds)
+                                   :iend (cdr ibounds)))
+               ((and (integer-or-marker-p ibeg)
+                     (integer-or-marker-p iend))
+                (objed-make-object :beg (car obounds)
+                                   :end (cdr obounds)
+                                   :ibeg ibeg
+                                   :iend iend))
+               ((or (functionp ibeg)
+                    (functionp iend))
+                (objed-make-object :beg (car obounds)
+                                   :end (cdr obounds)
+                                   :ibeg (or (and (functionp ibeg)
+                                                  (funcall ibeg beg))
+                                             ibeg)
+                                   :iend (or (and (functionp iend)
+                                                  (funcall iend end))
+                                             iend)))
+
+               (t
+                (list (list (car obounds)
+                            (cdr obounds))
+                      (objed--inner-default (car obounds)
+                                            (cdr obounds))))))))
+
+
+
+;; * Object definition helpers
+
+(defun objed--in-string-p (&optional syn)
+  "Return non-nil if point is inside or at string.
+
+If SYN is given use it instead of syntax at point."
+  (let ((syn (or syn (syntax-ppss))))
+    (or (and (nth 3 syn)
+             (nth 8 syn))
+        (objed--at-string-p))))
+
+(defun objed--at-string-p ()
+  "Return non-nil if point is at string."
+  (let ((syn nil))
+    (and (not (nth 4 (syntax-ppss)))
+         (or (and (not (eobp))
+                  (eq ?\" (char-syntax (char-after)))
+                  (save-excursion
+                    (nth 3 (setq syn (syntax-ppss (1+ (point))))))
+                  (nth 8 syn))
+             (and (not (bobp))
+                  (eq ?\" (char-syntax (char-before)))
+                  (save-excursion
+                    (nth 3 (setq syn (syntax-ppss (1- (point))))))
+                  (nth 8 syn))))))
+
+(defun objed--inner-string (&optional bounds)
+  "Return inners bounds of string at point.
+
+If BOUNDS is given use it instead of string at point."
+  (let ((bounds (or bounds (objed--bounds-of-string-at-point))))
+    (when bounds
+      (let ((beg (save-excursion (goto-char (car bounds))
+                                 (while (eq ?\" (char-syntax (char-after)))
+                                   (forward-char 1))
+                                 (when (< (point) (cdr bounds))
+                                   (point))))
+            (end (save-excursion (goto-char (cdr bounds))
+                                 (while (eq ?\" (char-syntax (char-before)))
+                                   (forward-char -1))
+                                 (when (> (point) (car bounds))
+                                   (point)))))
+        (when (and beg end)
+          (cons beg end))))))
+
+(defun objed--in-comment-p (&optional syn)
+  "Return non-nil when in point is in or at comment.
+
+If SYN is given use it instead of syntax at point."
+  (let ((syn (or syn (syntax-ppss))))
+    (or (and (nth 4 syn)
+             (nth 8 syn))
+        (objed--at-comment-p))))
+
+(defun objed--at-comment-p ()
+  "Return non-nil if point is at comment."
+  (let ((syn nil))
+    (or (save-excursion
+          (and (not (eobp))
+              (char-after)
+               (eq ?\< (char-syntax (char-after)))
+               (skip-syntax-forward "<")
+               (nth 4 (setq syn (syntax-ppss)))
+               (nth 8 syn)))
+        (save-excursion
+          (and (not (bobp))
+              (char-after)
+               (eq ?\> (char-syntax (char-after)))
+               (prog1 t (unless (bolp) (skip-syntax-backward ">")))
+               (nth 4 (setq syn (syntax-ppss)))
+               (nth 8 syn))))))
+
+(defun objed--bounds-of-comment-at-point ()
+  "Return bounds of comment at point."
+  (let ((beg (objed--in-comment-p)))
+    (when beg
+      (cons beg
+            (save-excursion (goto-char beg)
+                            (forward-comment 1)
+                            (objed--skip-ws t)
+                            (point))))))
+
+(defun objed--bounds-of-string-at-point ()
+  "Return bounds of string at point."
+  (let ((beg (objed--in-string-p)))
+    (when beg
+      (cons beg
+            (save-excursion (goto-char beg)
+                            (forward-sexp 1)
+                            (point))))))
+
+(defun objed--comment-block ()
+  "Return bounds of comment block at point if point in comment."
+  (let ((start (objed--in-comment-p)))
+    (when start
+      (save-excursion
+        (goto-char start)
+        (let ((beg (objed--skip-backward (point) nil 'comment))
+              (end (objed--skip-forward (point) nil 'comment)))
+         (goto-char end)
+         (skip-chars-forward " \t\r\n" (line-beginning-position 2))
+          (cons beg (point)))))))
+
+(defun objed--inner-comment-block ()
+  "Get range of inner comment."
+  (let ((bounds (objed--comment-block)))
+    (cons (objed--skip-forward (car bounds)'ws)
+         (objed--skip-backward (cdr bounds)'ws))))
+
+(defun objed--skip-ws (&optional back)
+  "Skip whitspace.
+
+Defaults to forward, if BACK is non-nil skip backwards."
+  (if back
+      (skip-chars-backward " \r\n\t")
+    (skip-chars-forward " \r\n\t")))
+
+
+(defun objed--skip-forward (from &optional ws comment)
+ "Skip whitespace or comment forward from position FROM.
+
+If WS is given skip whitespace. COMMENT non-nil to skip
+comments."
+  (save-excursion
+    (goto-char from)
+    (cond (ws
+           (objed--skip-ws)
+           (if comment
+               (objed--skip-forward (point) nil 'comment)
+             (point)))
+          (comment
+           (let ((s (objed--in-comment-p)))
+             (when s
+               (goto-char s))
+             (while (and (not (eobp))
+                         (forward-comment 1)))
+             (objed--skip-ws t)
+             (point))))))
+
+(defun objed--skip-backward (from &optional ws comment)
+  "Skip whitespace or comment backward from position FROM.
+
+If WS is given skip whitespace. COMMENT non-nil to skip
+comments."
+  (save-excursion
+    (goto-char from)
+    (cond (ws
+           (objed--skip-ws t)
+           (if comment
+               (objed--skip-backward (point) nil 'comment)
+             (point)))
+          (comment
+           (let ((s (objed--in-comment-p)))
+             (when s
+               (goto-char s))
+             (while (and (not (bobp))
+                         (forward-comment -1)))
+             (objed--skip-ws)
+             (point))))))
+
+(defun objed--narrow-if-string-or-comment ()
+  "In comment or string narrow to them."
+  (let* ((bounds nil)
+        (ibounds (cond ((setq bounds (objed--bounds-of-string-at-point))
+                        (objed--inner-string bounds))
+                       ((setq bounds (objed--bounds-of-comment-at-point))
+                        (objed--inner-comment-block)))))
+    (when ibounds
+      (narrow-to-region (car ibounds) (cdr ibounds)))))
+
+
+(defun objed--in-string-or-comment-p ()
+  "Test if point is inside a string or a comment."
+  (let* ((sp (syntax-ppss))
+         (begin (nth 8 sp)))
+    (when (or (eq (char-after begin) ?\")
+              (nth 4 sp))
+      begin)))
+
+
+;; * Creation of objects
+
+(eval-and-compile
+  (defun objed--get-arg-plist (keylst valid &optional wrapped)
+    "Wraps any forms of keys in keylst in `progn' and returns property list.
+KEYLST is the list of keys and forms for object creation. VALID
+is a list of valid keyword for the returned list whic is a
+property list where each key has an associated progn."
+    (let* ((keyw (pop keylst))
+           (vkeyw (and keyw (keywordp keyw) (memq keyw valid) keyw))
+           forms)
+      (cond ((eq vkeyw :mode)
+             ;; skip
+             (objed--get-arg-plist (cdr keylst) valid wrapped))
+            (vkeyw
+             (while (and (not (keywordp (car keylst)))
+                         keylst)
+               (push (pop keylst) forms))
+             (push keyw wrapped)
+             ;; allowed to move point
+             (if (memq vkeyw '(:try-next :try-prev :ref))
+                 (push `(progn ,@(nreverse forms))
+                       wrapped)
+               (push `(save-mark-and-excursion
+                       ,@(nreverse forms))
+                     wrapped))
+             (objed--get-arg-plist keylst valid wrapped))
+            (keylst
+             (error "Malformed Object. Keyword %s not recognized" keyw))
+            (t
+             (nreverse wrapped))))))
+
+
+;; * Object definitions
+
+
+(objed-define-object nil char
+  :atp
+  (looking-at ".")
+  :get-obj
+  (objed-make-object
+   :beg (point)
+   :ibeg (point)
+   :end (1+ (point))
+   :iend (1+ (point)))
+  :try-next
+  ;; current one is skipped, for chars this means we are already at
+  ;; the next..
+  (forward-char 0)
+  :try-prev
+  (forward-char -1))
+
+
+(objed-define-object nil word
+  :atp
+  (looking-at "\\<")
+  :ref
+  (when (equal (bounds-of-thing-at-point 'word)
+               (bounds-of-thing-at-point 'symbol))
+    'identifier)
+  :get-obj
+  (objed-make-object
+   :obounds (bounds-of-thing-at-point 'word))
+  :try-next
+  (re-search-forward  "\\<." nil t)
+  :try-prev
+  (re-search-backward  ".\\>" nil t))
+
+ 
+(defun objed--next-symbol ()
+  "Move to next symbol."
+  (re-search-forward  "\\_<" nil t)
+  (let (syn start)
+    (while (setq start (nth 8 (setq syn (syntax-ppss))))
+      (goto-char start)
+      (when (cond ((nth 3 syn)
+                   (forward-sexp 1) t)
+                  ((nth 4 syn)
+                   (forward-comment 1) t))
+        (re-search-forward  "\\_<." nil t)))))
+
+
+(defun objed--prev-symbol ()
+  "Move to previous symbol."
+  (re-search-backward  "\\_>" nil t)
+  (let (start)
+    (while (setq start (nth 8 (syntax-ppss)))
+      (goto-char start)
+      (re-search-backward  "\\_>" nil t))))
+
+
+(objed-define-object nil symbol
+  :atp
+  (and (not (objed--in-string-or-comment-p))
+       (or (looking-at "\\_<")
+           (looking-back "\\_>" 1)))
+  :ref 'identifier
+  :get-obj
+  (objed-make-object
+   :obounds (when (not (objed--in-string-or-comment-p))
+             (bounds-of-thing-at-point 'symbol)))
+  :try-next
+  (objed--next-symbol)
+  :try-prev
+  (objed--prev-symbol))
+
+
+
+(defun objed--at-sexp-p ()
+  "Return non-nil if point at strutured expression.
+
+Ignores simple structured expressions like words or symbols."
+  (let ((opos (point))
+       (real-this-command 'forward-sexp))
+    (cl-flet ((zigzag
+              (arg)
+              (ignore-errors
+                (forward-sexp arg)
+                (unless (eq opos (point))
+                  (prog1 (point)
+                    (forward-sexp (- arg)))))))
+      (let ((zigp nil)
+           (wb (bounds-of-thing-at-point 'word))
+           (sb (bounds-of-thing-at-point 'symbol)))
+       (when (or (and (not (eobp))
+                      (save-excursion
+                        (eq (point) (progn (setq zigp (zigzag 1)) (point))))
+                      (not (member (cons (point) zigp) (list wb sb))))
+                 (and (not (bobp))
+                      (save-excursion
+                        (eq (point) (progn (setq zigp (zigzag -1)) (point))))
+                      (not (member (cons (point) zigp)
+                                   (list wb sb)))))
+         (and zigp
+              (cons (point) zigp)))))))
+
+(objed-define-object nil sexp
+  :atp
+  (objed--at-sexp-p)
+  :ref
+  (let ((s (save-excursion
+             (goto-char (objed--beg))
+             (skip-syntax-forward ".'")
+             (bounds-of-thing-at-point 'symbol))))
+    (when (and s
+               (or (equal s (cons (objed--beg)
+                                  (objed--end)))
+                   (equal s (cons (objed--alt-beg)
+                                  (objed--alt-end)))))
+      (goto-char (car s))
+      'identifier))
+  :get-obj
+  (let* ((sexpb nil)
+        (bounds (or (objed--at-sexp-p)
+                    (and (setq sexpb (save-excursion (forward-sexp -1)
+                                                     (objed--at-sexp-p)))
+                         (progn (forward-sexp -1)
+                                sexpb))
+                   (bounds-of-thing-at-point 'symbol)
+                   (bounds-of-thing-at-point 'word))))
+    (when bounds
+      (objed-make-object
+     :obounds bounds
+     :ibounds (when bounds
+               (goto-char (car bounds))
+               ;; include leading punctuation
+               (skip-syntax-forward ".'")
+               (let ((beg (point)))
+                 (goto-char (cdr bounds))
+                 (with-syntax-table text-mode-syntax-table
+                   (skip-syntax-backward "."))
+                 (skip-syntax-backward " .'")
+                 (cons beg (point)))))))
+  :try-next
+  (objed--with-narrow-for-text
+   (forward-sexp 1)
+   (unless (objed--at-sexp-p)
+     (forward-sexp -1)))
+  :try-prev
+  (objed--with-narrow-for-text
+    (forward-sexp -1)))
+
+
+(objed-define-object nil file
+  :atp
+  (looking-at "\\<")
+  :get-obj
+  ;; TODO: inner bounds without extension
+  (objed-make-object :obounds (bounds-of-thing-at-point 'filename))
+  :try-next
+  (re-search-forward  "\\<." nil t)
+  :try-prev
+  (re-search-backward  ".\\>" nil t))
+
+(objed-define-object nil defun
+  :get-obj
+  (objed-make-object
+   :obounds (objed-bounds-from-region-cmd #'mark-defun))
+  :try-next
+  ;; does not work for adjacent toplevel parens in lisp becaus try
+  ;; next is called after moving beyond the current one
+  ;; (beginning-of-defun -1)
+  (end-of-defun 1)
+  (beginning-of-defun 1)
+  :try-prev
+  (beginning-of-defun 1))
+
+(objed-define-object nil line
+  :atp
+  (or (looking-at "^")
+      (looking-back "^ *" (line-beginning-position)))
+  :get-obj
+  (objed-make-object :beg (line-beginning-position)
+                     :end (save-excursion
+                            ;; include hidden parts...
+                            (end-of-visible-line)
+                            (if (eobp)
+                                (point)
+                              (1+ (point)))))
+  :try-next
+  (skip-chars-forward " \t\r\n")
+  :try-prev
+  (skip-chars-backward " \t\r\n"))
+
+
+
+(objed-define-object nil textblock
+  :get-obj
+  (when (or (not (derived-mode-p 'prog-mode))
+           (derived-mode-p 'text-mode)
+           (objed--in-comment-p)
+           (objed--in-string-p))
+    (objed--with-narrow-for-text
+     (let ((bounds (objed--get-textblock-bounds)))
+       (when (and bounds
+                 (or (not (eq (car bounds) (point-min)))
+                     (not (eq (cdr bounds) (point-max)))))
+        (objed-make-object :obounds bounds)))))
+  
+  :try-next
+  (forward-word 1)
+  ;; TODO: remove error
+  (unless (or (objed--in-string-or-comment-p)
+             (derived-mode-p 'text-mode)
+             (not (derived-mode-p 'prog-mode)))
+    (error "No textblock found"))
+  :try-prev
+  (forward-word -1)
+  (unless (or (objed--in-string-or-comment-p)
+             (derived-mode-p 'text-mode)
+             (not (derived-mode-p 'prog-mode)))
+    (error "No textblock found")))
+
+
+(defun objed--column (pos)
+  "Get column at position POS."
+  (save-excursion
+    (goto-char pos)
+    (current-column)))
+
+(defun objed--get-indent-bounds (&optional inner block)
+  "Get range of indentation block.
+
+If INNER is non-nil get the range for inner state. If BLOCK is
+non-nil the indentation block can contain empty lines."
+  (let* ((oi (objed--indentation-position))
+        (ic (objed--column oi))
+        (pos nil)
+        (opos nil)
+        (beg (save-excursion
+              (while (and (not (bobp))
+                          (progn
+                            (forward-line -1)
+                            (or  (and block (looking-at  "^ *$"))
+                                 (and (= (objed--column (setq pos 
(objed--indentation-position)))
+                                         ic)
+                                      (or (not inner) (not (looking-at " *$")))
+                                      ;; dont accept empty
+                                      (or (not (eolp)) (not (bolp)))
+                                      (setq opos pos))))))
+              (prog1 (or opos oi)
+                (setq opos nil))))
+       (end (save-excursion
+              (save-excursion
+                (while (and (not (eobp))
+                            (progn
+                              (forward-line 1)
+                              (or (and block (looking-at  "^ *$"))
+                                  (and (= (objed--column (setq pos 
(objed--indentation-position)))
+                                          ic)
+                                       (or (not inner) (not (looking-at " 
*$")))
+                                       (or (not (eolp)) (not (bolp)))
+                                       (setq opos pos)))))))
+              (when opos
+                (goto-char opos))
+              (line-end-position))))
+    (when (and beg end)
+      (cons beg end))))
+
+
+(objed-define-object nil indent
+  :get-obj
+  (let ((bounds (objed--get-indent-bounds 'inner)))
+    (when bounds
+      (objed-make-object :obounds (cons (car bounds)
+                                       (1+ (cdr bounds))))))
+  :try-next
+  ;;(error "No next indent")
+  (objed--skip-ws)
+  :try-prev
+  (objed--skip-ws t))
+
+
+
+(objed-define-object nil iblock
+  :get-obj
+  (let ((bounds (objed--get-indent-bounds nil t)))
+    (when bounds
+      (objed-make-object :obounds (cons (car bounds)
+                                       (1+ (cdr bounds))))))
+  :try-next
+  (objed--skip-ws)
+  :try-prev
+  (objed--skip-ws t))
+
+
+(objed-define-object nil sentence
+  :atp
+  (when (or (derived-mode-p 'text-mode)
+           (objed--at-comment-p)
+           (objed--in-string-or-comment-p))
+    (let ((ip (ignore-errors
+               (save-excursion
+                 (forward-sentence)
+                 (backward-sentence)
+                 (point)))))
+      (and ip (= (point) ip))))
+  :get-obj
+  (when (or (derived-mode-p 'text-mode)
+           (objed--at-comment-p)
+           (objed--in-string-or-comment-p))
+    (objed--with-narrow-for-text
+     (let ((s (bounds-of-thing-at-point 'sentence)))
+       (when s
+        (goto-char (car s))
+        (objed-make-object
+         :beg (if (derived-mode-p 'text-mode)
+                  (car s)
+                (while (or (< 0 (skip-syntax-forward "<"))
+                           (< 0 (skip-chars-forward "[:space:]\n"))))
+                (point))
+         :ibeg (point)
+         :end (progn
+                (goto-char (cdr s))
+                ;; include trailing space
+                (skip-chars-forward
+                 "\s-"
+                 (+ (point)
+                    (if sentence-end-double-space
+                        2
+                      1)))
+                (point))
+         :iend (with-syntax-table text-mode-syntax-table
+                 (skip-syntax-backward ".-" (car s))
+                 (point)))))))
+  :try-next
+  (objed--with-narrow-for-text
+   ;; call twice if at start of sentence.
+    (unless (>= (point)
+                (save-excursion (backward-sentence)
+                                (forward-sentence)
+                                (point)))
+      (forward-sentence 1))
+    ;; move to start
+    (forward-sentence 1))
+  :try-prev
+  (objed--with-narrow-for-text
+   ;; call twice at end of sentence
+    (unless (<= (point)
+                (save-excursion (forward-sentence)
+                                (backward-sentence)
+                                (point)))
+      (backward-sentence 1))
+    (backward-sentence 1)))
+
+
+(objed-define-object nil paragraph
+  :atp
+  (and (or (bobp)
+           (save-excursion (forward-line -1)
+                           (looking-at "^ *$")))
+       (looking-back "^ *" (line-beginning-position)))
+  :get-obj
+  (let ((bounds (objed-bounds-from-region-cmd #'mark-paragraph)))
+    (objed-make-object :obounds bounds))
+  :try-next
+  (skip-chars-forward " \t\r\n")
+  :try-prev
+  (skip-chars-backward " \t\r\n"))
+
+
+
+(defun objed--bounds-within-comment-or-string-p (bounds)
+  "Return non-nil if BOUNDS are inside comment or string."
+  (let ((cbounds (cond ((objed--in-string-p)
+                       (objed--bounds-of-string-at-point))
+                      ((objed--in-comment-p)
+                       (objed--comment-block)))))
+    (when cbounds
+      (objed--bounds-within-bounds-p bounds cbounds))))
+
+(defun objed--bounds-within-bounds-p (b c)
+  "Return non-nil if bounds B are inside C."
+  (and (>= (car b) (car c))
+       (<= (cdr b) (cdr c))))
+                  
+
+(defun objed--get-textblock-bounds ()
+  "Get cons cell of beginnine and end position of textblock."
+  (save-excursion
+    (let ((po nil)
+        (opos (point)))
+    (cl-letf (((symbol-function 'fill-region-as-paragraph)
+               (lambda (beg end &rest _)
+                 (setq po (cons beg end)))))
+      ;; let inner not move point in general?
+      (fill-paragraph)
+      (when (consp po)
+       (goto-char (car po))
+       (objed--skip-ws)
+       (when (or (<= (point) opos (cdr po))
+                 (<= (cdr po) opos (point)))
+         (cons (point) (cdr po))))))))
+
+
+(objed-define-object nil buffer
+  :atp
+  (bobp)
+  :get-obj
+  (objed-make-object
+   :obounds (objed-bounds-from-region-cmd #'mark-whole-buffer)))
+
+
+(objed-define-object nil region
+  :get-obj
+  (objed-make-object
+   :beg (mark)
+   :end (point)))
+
+
+(objed-define-object nil bracket
+  :atp
+  (unless (objed--in-string-or-comment-p)
+    (or (looking-at "(\\|\\[\\|{")
+       (looking-back ")\\|\\]\\|}" 1)))
+  :get-obj
+  (unless (objed--in-string-or-comment-p)
+    (cond ((and (not (bobp))
+                (eq (char-syntax (char-before)) ?\)))
+           (let ((end (point))
+                 (beg (scan-sexps (point) -1)))
+             (objed-make-object :beg beg
+                               :end end
+                               :ibeg #'1+
+                               :iend #'1-)))
+         ((and (not (eobp))
+               (eq (char-syntax (char-after)) ?\())
+           (let ((beg (point))
+                 (end (scan-sexps (point) 1)))
+             (objed-make-object :beg beg
+                               :end end
+                               :ibeg #'1+
+                               :iend #'1-)))
+         (t
+          ;; get bracket expression point is in
+          (let* ((beg (cadr (syntax-ppss)))
+                 (end (when beg (scan-sexps beg 1))))
+            (objed-make-object :beg beg
+                               :end end
+                               :ibeg #'1+
+                               :iend #'1-)))))
+
+  :try-next
+  (when (re-search-forward "(\\|\\[\\|{" nil t)
+    (forward-char -1))
+  :try-prev
+  (when (re-search-backward ")\\|\\]\\|}" nil t)
+    (forward-char 1)))
+
+(objed-define-object nil string
+  :atp
+  (objed--at-string-p)
+  :get-obj
+  (let ((bounds (objed--bounds-of-string-at-point)))
+    (objed-make-object
+     :obounds bounds
+     :ibounds (and bounds (objed--inner-string bounds))))
+  :try-next
+  (let ((cont t)
+        (syn nil))
+    (while cont
+      (while (and (not (eobp))
+                  (not (eq ?\" (char-syntax (char-after)))))
+        (forward-char 1))
+      (if (not (nth 4 (setq syn (syntax-ppss))))
+          (setq cont nil)
+        (goto-char (nth 8 syn))
+        (forward-comment 1))))
+  :try-prev
+   (let ((cont t)
+         (syn nil))
+     (while cont
+       (while (and (not (bobp))
+                   (not (eq ?\" (char-syntax (char-before)))))
+         (forward-char -1))
+       (if (not (nth 4 (setq syn (syntax-ppss))))
+           (setq cont nil)
+         (goto-char (nth 8 syn))))))
+
+(objed-define-object nil comment
+  :atp
+  (objed--at-comment-p)
+  :get-obj
+  (let ((bounds (objed--comment-block)))
+    (objed-make-object :obounds bounds
+                      ;; TODO: support multi char/multi line comments
+                      ;; act different for them?
+                      :ibounds (when bounds
+                                 (goto-char (car bounds))
+                                 (skip-chars-forward
+                                  (format "%s \t" (or comment-start "")))
+                                 (cons (point)
+                                       (objed--skip-backward (cdr bounds) 
'ws)))))
+  :try-next
+  (comment-search-forward (point-max) t)
+  :try-prev
+  (comment-search-backward (point-min) t))
+
+
+
+;; TODO: get rid of this
+(defvar objed--content-bounds nil
+  "Holding bounds of current object for `objed-reference'.")
+
+(defun objed--next-content ()
+  "Search and set for next content object."
+  (let ((curr (apply 'buffer-substring (objed--current))))
+    (when objed--content-bounds
+      (goto-char (cdr objed--content-bounds)))
+    (if (search-forward curr nil t)
+       (setq objed--content-bounds
+             (cons (match-beginning 0) (match-end 0)))
+      (setq objed--content-bounds nil))))
+
+
+(defun objed--prev-content ()
+  "Search and set for prev content object."
+  (let ((curr (apply 'buffer-substring (objed--current))))
+    (when objed--content-bounds
+      (goto-char (car objed--content-bounds)))
+    (if (search-backward curr nil t)
+        (setq objed--content-bounds
+              (cons (match-beginning 0) (match-end 0)))
+      (setq objed--content-bounds nil))))
+
+
+;; special objects, for fallback of objed-reference
+(objed-define-object nil content
+  :get-obj
+  ;; has to be set by commands using this
+  (objed-make-object
+   :obounds
+   (or objed--content-bounds
+       (error "Last in current direction")))
+    :try-next
+  (objed--next-content)
+  :try-prev
+  (objed--prev-content))
+
+(objed-define-object nil identifier
+  :get-obj
+  (objed-make-object
+   :obounds (bounds-of-thing-at-point 'symbol))
+  :try-next
+  (objed-next-identifier)
+  :try-prev
+  (objed-prev-identifier))
+
+(defun objed-next-identifier ()
+  "Move to next identifier."
+  (interactive)
+   (let ((bds nil))
+    (if (not (setq bds (bounds-of-thing-at-point 'symbol)))
+        (re-search-forward  "\\_<" nil t)
+      (let ((sym (and (or bds (setq bds (bounds-of-thing-at-point 'symbol)))
+                      (buffer-substring (car bds) (cdr bds)))))
+       (unless (looking-at "\\_<")
+         (goto-char (cdr bds)))
+        (if (re-search-forward (format "\\_<%s\\_>" sym) nil t)
+            (goto-char (match-beginning 0))
+          (goto-char (car bds))
+          (when (eq real-this-command #'objed-current-or-next-context)
+            (run-at-time 0 nil (apply-partially #'message "Last one!"))))))))
+
+(defun objed-prev-identifier ()
+  "Move to previous identifier."
+  (interactive)
+  (let ((bds nil))
+    (if (not (setq bds (bounds-of-thing-at-point 'symbol)))
+        (re-search-backward  "\\_<" nil t)
+      (let ((sym (and (or bds (setq bds (bounds-of-thing-at-point 'symbol)))
+                      (buffer-substring (car bds) (cdr bds)))))
+        (when bds
+         (unless (looking-back "\\_>" 1)
+           (goto-char (car bds)))
+          (if (re-search-backward (format "\\_<%s\\_>" sym) nil t)
+              (goto-char (match-beginning 0))
+            (goto-char (car bds))
+            (when (eq real-this-command #'objed-current-or-previous-context)
+              (run-at-time 0 nil
+                           (apply-partially #'message "First one!")))))))))
+
+
+(objed-define-object nil section
+  :atp
+  (and (bound-and-true-p outline-minor-mode)
+       (bolp) (not (string= "" outline-regexp))
+       (eq (aref comment-start 0) (char-after))
+       (looking-at (format "^%s" outline-regexp)))
+  :get-obj
+  (when (and (bound-and-true-p outline-minor-mode)
+            (ignore-errors (outline-back-to-heading) t))
+    (objed-make-object :beg (point)
+                       :ibeg (line-end-position)
+                       :end (progn
+                              (outline-next-heading)
+                             (or (eobp)
+                                 (move-end-of-line 0))
+                              (point))
+                       :iend (progn (skip-chars-backward " \t\r\n")
+                                    (point))))
+  :try-next
+  (when (bound-and-true-p outline-minor-mode)
+    (outline-next-heading))
+  :try-prev
+  (when (bound-and-true-p outline-minor-mode)
+    (outline-previous-heading)))
+
+
+;; * Mode specific objects
+
+(objed-define-object nil defun
+  :mode emacs-lisp-mode
+  :atp
+  (looking-at "^(")
+  :ref
+  (down-list 1)
+  (forward-symbol 2)
+  (forward-symbol -1)
+  'identifier
+  :get-inner
+  ;; TODO: improve this
+  (cond ((looking-at "(defun")
+         (down-list 2)
+         (up-list 1)
+         (list (point)
+               (progn (goto-char (point-max))
+                      (down-list -1)
+                      (point))))
+        (t
+         (list (progn (down-list 1)
+                      (point))
+               (progn (goto-char (point-max))
+                      (down-list -1)
+                      (point))))))
+
+(objed-define-object nil tag
+  :atp
+  (and (derived-mode-p 'sgml-mode)
+       (or (looking-at "<")
+          (looking-back ">" 1)))
+  :get-obj
+  ;; TODO: fix detection if point inside <..|..>
+  (when (derived-mode-p 'sgml-mode)
+    ;; like with bracket detect at boundary
+    (objed-make-object
+     :beg (progn (unless (looking-at "<")
+                  (sgml-skip-tag-backward 1))
+                (point))
+     :ibeg (save-excursion (search-forward ">" nil t)
+                          (point))
+     :end (progn
+           (unless (looking-back ">" 1)
+             (sgml-skip-tag-forward 1))
+           (point))
+     :iend (progn (search-backward "<" nil t)
+                 (point))))
+  :try-next
+  (search-forward "<" nil t)
+  :try-prev
+  (search-backward ">" nil t))
+
+(declare-function org-mark-element "ext:org")
+(with-eval-after-load 'org
+  (objed-define-object nil section
+    :mode org-mode
+    :atp
+    (org-at-heading-p)
+    :get-obj
+    (objed-make-object
+     :obounds (when (ignore-errors (org-back-to-heading) t)
+                (cons (point)
+                      (progn (outline-next-visible-heading 1)
+                             (or (eobp) (move-end-of-line 0))
+                             (point)))))
+    :try-next
+    (outline-next-visible-heading 1)
+    :try-prev
+    (outline-previous-visible-heading 1))
+  (objed-define-object nil paragraph
+    :mode org-mode
+    :get-obj
+    (objed-make-object
+     :obounds (objed-bounds-from-region-cmd #'org-mark-element))))
+
+
+(objed-define-object nil output
+  :atp
+  (and (derived-mode-p 'comint-mode)
+       (looking-back comint-prompt-regexp
+                     (save-excursion
+                       (forward-line 0)
+                       (point))))
+  :get-obj
+  (when  (derived-mode-p 'comint-mode)
+    (objed-make-object
+     :obounds (let ((pos (point)))
+                (comint-next-prompt 1)
+                (move-end-of-line 0)
+                (if (> (point) pos)
+                    (cons pos (point))
+                  (move-end-of-line 2)
+                  (cons
+                   (line-beginning-position)
+                   (point))))))
+  :get-inner
+  (forward-line 1)
+  (list (point) (point-max))
+  :try-next
+  (comint-next-prompt 1)
+  :try-prev
+  (comint-previous-prompt 1))
+
+(with-eval-after-load 'python
+  (objed-define-object nil defun
+    :mode python-mode
+    :get-obj
+    (end-of-line 1)
+    (objed-make-object
+     :obounds (objed-bounds-from-region-cmd #'mark-defun))))
+
+(provide 'objed-objects)
+;;; objed-objects.el ends here
diff --git a/objed.el b/objed.el
new file mode 100644
index 0000000..0ba1c17
--- /dev/null
+++ b/objed.el
@@ -0,0 +1,2443 @@
+;;; objed.el --- Navigate and edit text objects. -*- lexical-binding: t -*-
+;; Copyright (C) 2018  Clemens Radermacher
+
+;; Author: Clemens Radermacher <address@hidden>
+;; Package-Requires: ((emacs "24.5") (cl-lib "0.5"))
+;; Version: 0.1
+;; Keywords: convenience
+;; URL: https://github.com/clemera/objed
+
+;; 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:
+;;
+;; A global minor-mode to navigate and edit text objects. Objed enables modal
+;; editing and composition of commands, too. It combines ideas of other Editors
+;; like Vim or Kakoune and tries to align them with regular Emacs conventions.
+;;
+;; Text objects are textual patterns like a line, a top level definition, a
+;; word, a sentence or any other unit of text. When `objed-mode' is enabled,
+;; certain editing commands (configurable) will activate `objed' and enable its
+;; modal editing features. When active, keys which would usually insert a
+;; character are mapped to objed commands. Other keys and commands will 
continue
+;; to work as they normally would and exit this editing state again.
+;;
+;; By default important self inserting keys like Space or Return are not bound
+;; to modal commands and will exit `objed' on insertion. This makes it
+;; convenient to move around and continue adding new text.
+;;
+;; With activation `objed' shows the current object type in the mode-line. The
+;; textual content of the object is highlighted visually in the buffer and the
+;; cursor color is changed, too. The user can now navigate by units of this
+;; object, change the object state or switch to other object types.
+;;
+;; The object state is either "inner" or "whole" and is indicated in the
+;; modeline by (i) or (w) after the object type. With inner state, anything 
that
+;; would be considered delimiters or padding around an object is excluded.
+;;
+;; The user can apply operations to objects. By marking objects before applying
+;; an operation, s?he can even operate on multiple objects at once. This works
+;; similar to the way you interact with files in `dired'. When marking an 
object
+;; the point moves on to the next object of this type.
+;;
+;; The object type used for initialization is determined by the mapping of the
+;; entry command (see `objed-cmd-alist'). For example using 
`beginning-of-defun'
+;; will activate `objed' using the `defun' object as initial object type. With
+;; command `next-line', `objed' would initialize with the `line' object.
+;;
+;; Objeds modal state provides basic movement commands which move by line, word
+;; or character. Those switch automatically to the corresponding object type,
+;; otherwise they work the same as the regular Emacs movement commands. Other
+;; commands only activate the part between the initial position and the new
+;; position moved to. By repeating commands you can often expand/proceed to
+;; other objects. This way you can compose movement and editing operations very
+;; efficiently.
+;;
+;; The expansion commands distinguish between block objects (objects built out
+;; of lines of text) and context objects (programming constructs like strings,
+;; brackets or textual components like sentences). This way you can quickly
+;; expand to the desired objects.
+;;
+;; For example to move to the end of the paragraph, the user would first move 
to
+;; the end of the line with "e". This would activate the text between the
+;; starting position and the end of the line. The user can now continue to the
+;; end of the paragraph by by pressing "e" again. Now s?he is able to proceed
+;; even further by pressing "e" again OR to continue by adding new text to the
+;; end of the paragraph OR to continue by acting on the text moved over, for
+;; example killing it by pressing "k".
+;;
+;; As often with text editing, the explanation sounds more complicated than
+;; using it. To get a better impression of the editing workflow with `objed'
+;; have look at https://github.com/clemera/objed where you can find some
+;; animated demos.
+;;
+;; To learn more about available features and commands have a look at the
+;; descriptions below or the Docstrings and bindings defined in `objed-map'. To
+;; define your own operations and text objects see `objed-define-op' and
+;; `objed-define-object'.
+;;
+;; Although some features are still experimental the basic user interface will
+;; stay the same. The following gives an overview of available keys and
+;; commands:
+;;
+;; Basic movement commands (switch the object type on movement):
+;; 
+;; [`objed-map']
+;; f/b: Move forward/backward one character and activate the char object.
+;; s/r: Move forward/backward one word and activate the word object (*).
+;; S/R: Move forward/backward one symbol and activate the symbol object.
+;;      Skips strings and comments.
+;; n/p: Move to the next/previous line and activate the line object.
+
+;; (*): Emacs uses the f/b keys for word AND character movement (depending on
+;;      the used modifier). I made the decision to remap M-f, M-b to M-s, M-r 
in
+;;      my personal configuration (using `key-translation-map'). This is by no
+;;      means necessary but might be something to think about. Afterwards you
+;;      are able to start word movement with M-s/r and continue moving by words
+;;      with s/r which is more convenient than switching between M-b/f and s/r.
+;;      You can still access M-s/r regular bindings by using Meta-shift 
(M-S/R).
+;;
+;; Commands for block objects (objects built out of lines of text):
+;;
+;; [`objed-map']
+;; l  : Activate (line based) object at point and move to its start.
+;;      On repeat proceed to beginning of the indentation block, comment block,
+;;      paragraph or other block objects.
+;; a  : Move to beginning of line and activate the text moved over.
+;;      On repeat proceed to beginning of blocks like explained above.
+;; e  : Move to end of line and activate the text moved over.
+;;      On repeat proceed to end of blocks like explained above.
+;;
+;; Commands for context objects. Those objects are common programming 
constructs
+;; like defuns, strings, parentheses but also sentences inside comments for
+;; example. Any whitespace after point is skipped before determine the context:
+;; 
+;; [`objed-map']
+;; t/h: If coming from basic movement the object at point is guessed
+;;      based on context. Point is moved  to the beginning/end of object.
+;;      This is useful to "jump out" of the current context.
+;;      On repeat move to the previous/next instance of current object type
+;; o  : Activate the inner part of the object at point and move to the start.
+;;      This is useful to act on the content of the string, brackets and so on.
+;;      On repeat expand to other objects around current position.
+;; u  : Move to end of the inner object at point and activate the text moved 
over.
+;;      On repeat toggle between beginning/end inside the object.
+;; q  : Move point to the other side of the current object.
+;; i  : Toggle the state of the current object (inner/whole).
+;; 
+;; Commands to switch to other objects (and move point to its start):
+;;
+;; [`objed-map']
+;; c  : Prefix to switch to other objects,
+;;      see `objed-object-map' for available objects
+;;      and `objed-define-object' to add your own.
+;;
+;; Some objects are directly accessible without a prefix:
+;;
+;; .  : Switch To identifier object.
+;; _  : Switch to symbol object.
+;; %  : Switch to content object (defined by textual content of current 
object).
+;;
+;; Commands to edit objects (applying operations to them). When the region is
+;; active the operation acts on the current region. To act on multiple objects
+;; at once you can mark them first (see the "Misc commands" below):
+;; 
+;; [`objed-map']
+;; x  : Prefix to access other operations,
+;;      see `objed-op-map' for available operations
+;;      and `objed-define-op' to add your own.
+;;
+;; Some operations are accessible without a prefix:
+;;
+;; k  : Kill current object(s).
+;;      Merges marked objects if they are only separated by whitespace.
+;; d  : Delete current object(s).
+;;      Merges marked objects if they are only separated by whitespace.
+;; w  : Copy current object(s).
+;; y  : Yank last killed text at point.
+;; TAB: Indent object(s).
+;; ;  : Un/comment object(s).
+;; :  : Comment and duplicate object.
+;; $  : Flyspell region.
+;;
+;; `      : Prefix to surround object(s) with any pair using `electric' 
(built-in).
+;; "([{   : Surround object with corresponding chars using `electric',
+;;
+;; Misc commands:
+;; 
+;; [`objed-map']
+;; ,    : Pop to last state, which restores the last position and any object 
data.
+;; j    : Choose an instance of current object type with completion,
+;;        using the contents of the first line for completion.
+;; z    : Choose an instance of current object type on the screen with `avy'.
+;; m    : Add/Remove current object to marked objects and move to next.
+;; M    : Add/Remove current object to marked objects and move to previous.
+;; v    : Scroll up.
+;; V/M-v: Scroll down.
+;; /    : Undo last edit command.
+;; C-SPC: Set mark.
+;; C-h  : Get key binding help (uses `which-key' if available).
+;; g/C-g: Exit and deactivate `objed'.
+;;
+;; Dispatch keys (dispatch to any object defined in `objed-object-map'):
+;; 
+;; [You can add your own prefix bindings using `objed-define-dispatch']
+;;  *  : Mark all instances of current object inside another object type.
+;;  <  : Activate part from point backward until boundary of some object.
+;;  >  : Activate part from point forward until boundary of some object.
+;;
+;;
+;; CONTRIBUTE:
+;;
+;; I'm happy to receive pull requests or ideas to improve this package. Some
+;; parts suffer from the bottom up approach of developing it, but this also
+;; allowed me to experiment a lot and try ideas while working on them, 
something
+;; that Emacs is especially good at. Most of the features are tested using
+;; `emacs-lisp-mode' but hopefully there aren't to many problems using modes 
for
+;; other languages, I tried my best to write text objects in a language 
agnostic
+;; way by using Emacs syntax information. Testing this and writing tests in
+;; general would be an important next step.
+;;
+;; This package would never been possible without the helpful community around
+;; Emacs. Thank you all and see you in parendise...Share the software!
+;;
+
+;;
+;;; Code:
+
+
+;; * Deps
+
+(require 'cl-lib)
+(require 'nadvice)
+(require 'face-remap)
+
+(require 'objed-objects)
+
+;; * Objed Mode
+
+(defvar objed-mode-map
+  (let ((map (make-sparse-keymap)))
+    ;; command can be used without using `objed-mode', too
+    (define-key map (kbd "M-SPC") 'objed-activate)
+    ;; (define-key map (kbd "C-.") 'objed-activate)
+    map)
+  "Keymap for /function`objed-mode'.")
+
+;;;###autoload
+(define-minor-mode objed-mode
+  "Enable objeds modal editing features after certain commands.
+
+With a prefix argument ARG, enable Objed mode if ARG is positive,
+and disable it otherwise. If called from Lisp, enable the mode if
+ARG is omitted or nil.
+
+Objed mode is a global minor mode. When enabled, any command
+configured in `objed-cmd-alist' will activate modal navigation
+and editing features on text objects. Available commands,
+operations and objects can be found in `objed-map',
+`objed-op-map' and `objed-object-map'.
+
+To define your own text objects and editing operations see
+`objed-define-object' and `objed-define-op'.
+
+Activating this mode loads the optional dependencies `which-key'
+and `avy' if they are available. This can be deactivated by
+setting the user options `objed-use-which-key-if-available-p' and
+`objed-use-avy-if-available-p' before loading."
+  :global t
+  (if objed-mode
+      (progn
+        (setq objed--which-key-avail-p (when objed-use-which-key-if-available-p
+                                        (require 'which-key nil t))
+             objed--avy-avail-p (when objed-use-avy-if-available-p
+                                  (require 'avy nil t)))
+        (dolist (cmd2obj objed-cmd-alist)
+          (advice-add (car cmd2obj) :after
+                      (apply-partially #'objed--activate (car cmd2obj)))
+         (advice-add (car cmd2obj) :before 'objed--save-start-position)))
+    (dolist (cmd2obj objed-cmd-alist)
+      (advice-remove (car cmd2obj)
+                     (apply-partially #'objed--activate (car cmd2obj)))
+      (advice-remove (car cmd2obj) 'objed--save-start-position))))
+
+;; * Customization
+
+(defgroup objed nil
+  "Navigate and edit text objects."
+  :group 'convenience
+  :prefix "objed-")
+
+(defgroup objed-faces nil
+  "Faces for `objed'"
+  :group 'objed
+  :group 'faces
+  :prefix "objed-")
+
+;; * Faces
+
+
+(defface objed-mark
+  '((t (:inherit region)))
+  "Face used for marked objects."
+  :group 'objed-faces)
+
+(defface objed-hl
+  '((t (:inherit highlight)))
+  "Face used for highlighting textual content of current object."
+  :group 'objed-faces)
+
+(defface objed-mode-line
+  '((t (:inherit objed-hl)))
+  "Face used for the mode line hint."
+  :group 'objed-faces)
+
+;; * User Settings and Variables
+
+(defcustom objed-disabled-modes
+  '(special-mode dired-mode Info-mode)
+  "List of modes for which objed should stay disabled.
+
+If the current `major-mode' is in the list or derives from a
+member of it `objed' will not activate.
+
+See also `objed-disabled-p'"
+  :group 'objed
+  :type '(repeat symbol))
+
+
+(defcustom objed-cmd-alist
+  '(
+    (left-char . char)
+    (right-char . char)
+    (backward-char . char)
+    (forward-char . char)
+    (forward-word . word)
+    (capitalize-word . word)
+    (backward-word . word)
+    (move-beginning-of-line . line)
+    (move-end-of-line . line)
+    (previous-line . line)
+    (next-line . line)
+    (beginning-of-buffer . line)
+    (end-of-buffer . char)
+    (scroll-up-command . line)
+    (scroll-down-command . line)
+    (xref-find-definitions . line)
+    (xref-pop-marker-stack . line)
+    (imenu . line)
+    (backward-paragraph . paragraph)
+    (forward-paragraph . paragraph)
+    (fill-paragraph . textblock)
+    (down-list string symbol word)
+    (forward-sexp sexp defun bracket string symbol word)
+    (backward-sexp sexp defun bracket string symbol word)
+    (indent-pp-sexp bracket sexp)
+    ;; just use inner line?
+    (back-to-indentation section defun bracket string line)
+    (org-beginning-of-line . line)
+    (org-end-of-line . line)
+    (backward-sentence . sentence)
+    (org-backward-sentence . sentence)
+    (org-backward-element . paragraph)
+    (backward-up-list bracket string)
+    (up-list bracket string)
+    (beginning-of-defun . defun)
+    (end-of-defun . defun)
+    (outline-previous-visible-heading . section)
+    (outline-next-visible-heading . section)
+    (org-previous-visible-heading . section)
+    (comint-previous-prompt . output)
+    (comint-next-prompt . output)
+    ;; editing entry commands
+    (delete-char . char)
+    (kill-line . char)
+    )
+  "Entry commands and associated objects.
+
+If the `cdr' of an entry is a list, each of the objects in this
+list is tried and the first that matches will be used for
+initialization."
+  :group 'objed
+  :type '(alist :key-type sexp
+                :value-type (choice sexp
+                                    (repeat sexp))))
+
+
+(defcustom objed-states-max 20
+  "Maximal number of states to remember.
+
+This option holds the number of times `objed-last' can
+be used to restore previous states."
+  :group 'objed
+  :type 'integer)
+
+  
+(defcustom objed-keeper-commands '(save-buffer read-only-mode undo)
+  "Regular Emacs commands which should not exit modal edit state.
+
+When regular commands are executed `objed' will exit its editing
+state. Commands added to this list wont do that."
+  :group 'objed
+  :type '(repeat function))
+
+(defcustom objed-cursor-color "#e52b50"
+  "Cursor color to use when `objed' is active."
+  :group 'objed
+  :type 'color)
+
+(defcustom objed-which-key-order #'which-key-description-order
+  "Key sort order to use for which key help popups."
+  :group 'objed
+  :type 'function)
+
+(defcustom objed-modeline-hint-p t
+  "Whether to show hint for current object in mode line."
+  :group 'objed)
+
+(defcustom objed-mode-line-format
+  '(:eval (propertize
+          (format " %s(%s) "
+                  (symbol-name objed--object)
+                  (char-to-string (aref (symbol-name objed--obj-state) 0)))
+          'face 'objed-mode-line))
+  "Format used to display hint in mode-line.
+
+Only relevant when `objed-modeline-hint-p' is non-nil."
+  :group 'objed
+  :type 'sexp)
+
+(defcustom objed-modeline-setup-func #'objed--setup-mode-line
+  "Function to setup the mode line.
+
+This function recieves `objed-mode-line-format' as an argument to
+add/remove the mode line hint.
+
+It also recieves a second optional argument which indicates if
+the hint should be remove or added. If non-nil the hint should be
+removed."
+  :group 'objed
+  :type 'symbol)
+
+(defcustom objed-initial-object 'region
+  "Object to use for inititalization with `objed-activate'."
+  :group 'objed
+  :type 'symbol)
+
+
+
+;; optional dep options
+
+(defcustom objed-use-which-key-if-available-p t
+  "Whether to allow loading and use of `which-key'.
+
+To avoid loading `which-key' set this var before activating `objed-mode.'"
+  :group 'objed
+  :type 'boolean)
+
+(defcustom objed-auto-wk-top-level-p nil
+  "Whether to show top level help automatically when activating.
+
+Respects `which-key-idle-delay'.
+The top level help is also available via `objed-show-top-level'."
+  :group 'objed
+  :type 'boolean)
+
+(defcustom objed-use-avy-if-available-p t
+  "Whether to allow loading and use of `avy'.
+
+To avoid loading `avy' set this var before activating `objed-mode.'"
+  :group 'objed
+  :type 'boolean)
+
+(defcustom objed-use-hl-p t
+  "Whether allow loading and use of `hl-line' to highlight the current object."
+  :group 'objed
+  :type 'boolean)
+
+
+;; info for byte-comp
+(defvar ivy-sort-function-alist nil)
+(defvar which-key-replacement-alist nil)
+(defvar which-key-mode nil)
+(defvar which-key-idle-delay nil)
+(defvar which-key--using-top-level nil)
+(defvar avy-all-windows nil)
+(defvar avy-action nil)
+
+(declare-function objed--exit-objed "objed" nil t)
+(declare-function electric-pair-post-self-insert-function "ext:electric")
+(declare-function which-key-description-order "ext:which-key")
+(declare-function which-key--create-buffer-and-show "ext:which-key")
+(declare-function avy--process "ext:avy")
+(declare-function avy--style-fn "ext:avy")
+(declare-function edit-indirect-region "ext:edit-indirect")
+
+;; * Helper Macros
+
+(defvar objed--exit-alist nil
+  "Maps operations to exit functions.
+
+If this list contains an entry for an operation, the
+exit function is called after execution of the operation.")
+
+(defvar objed--after-init-alist
+  '((move-end-of-line . objed--object-trailing-line)
+    (org-end-of-line . objed--object-trailing-line)
+    (backward-sentence . objed--goto-start))
+  "Maps commands which need special initialization to init functions.
+
+The init functions are called with the position point was before
+the command was executed.")
+
+(defvar objed--opoint nil
+  "Position before movement command activated `objed'.")
+
+
+(defmacro objed-define-op (key cmd &optional exit)
+  "Macro to create operations for `objed'.
+
+KEY is a string to be interpreted as spelled-out keystrokes,
+using same format as for `kbd'. If KEY is non-nil it is bound to
+and operation that will use CMD in `objed-map'.
+
+CMD should be a region command or a non-interactive function.
+
+In the latter case the function recieves two buffer positions as
+arguments. If the function is able to recieve three arguments the
+third argument will be the prefix argument passed to the
+operation.
+
+If EXIT is given it should be a function which is called after
+executing the operation. The function recieves one argument which
+is the string of the textual content the operation acted on.
+
+This macro returns a command that can be used as an `objed'
+operation."
+  (let ((name (intern (format "objed-%s" (symbol-name cmd))))
+        (res (list 'progn)))
+    (when key
+      (push `(define-key objed-map (kbd ,key) ',name) res))
+    (when exit
+      (push `(setq objed--exit-alist
+                  (cons (cons ',name #',exit) objed--exit-alist))
+           res))
+    (push `(defun ,name (arg)
+             "Objed operation."
+             (interactive "P")
+             (let ((cmd (objed--create-op ',cmd arg)))
+               (if objed--marked-ovs
+                   (objed--ov-apply ',name cmd objed--marked-ovs)
+                 (objed--ob-apply ',name cmd (objed--current)))))
+          res)
+    (nreverse res)))
+
+
+(defmacro objed--with-allow-input (&rest body)
+  "Allow input in minibuffer while `objed' is active.
+
+The code executed in BODY allows minibuffer input without
+interferring with `objed'."
+  `(let ((overriding-terminal-local-map nil))
+     (set-cursor-color objed--saved-cursor)
+     (unwind-protect (progn ,@body)
+       ;; body might exit objed...
+       (when objed--buffer
+         (set-cursor-color objed-cursor-color)))))
+
+
+(defvar objed--dispatch-alist nil
+  "Maps prefix commands to functions.
+
+Don't modify this list manually, use `objed-define-dispatch'.")
+
+(defvar objed--dispatch-key-alist nil
+  "Store keys for dispatch commands.")
+
+(defmacro objed-define-dispatch (key def)
+  "Define a dispatch binding.
+
+Defines a prefix key KEY. After pressing this prefix key the user
+is expected to invoke an object command bound in
+variable/`objed-object-map' to choose an object.
+
+KEY is a string to be interpreted as spelled-out keystrokes,
+using same format as for `kbd'.
+
+DEF is the symbol for the function to be called with the choosen
+object as an argument."
+  (declare (indent 2))
+  (let ((dp (intern (format "objed-%s-dispatch" (symbol-name def)))))
+    `(prog1 ',def
+       (push (cons ',dp ',def) objed--dispatch-alist)
+       (setf (symbol-function (define-prefix-command ',dp))
+            objed-dispatch-map)
+       (define-key objed-map (kbd ,key) ',dp)
+       ;; save for possible reinit of objed-map
+       (push (cons ,key ',dp) objed--dispatch-key-alist))))
+
+(defmacro objed--save-state (&rest body)
+  "Preserve state during execution of BODY."
+  `(let ((state (objed--get-current-state)))
+     (unwind-protect (progn ,@body )
+       (prog1 nil (objed--restore-state state)))))
+
+
+;; * Keymaps
+
+(defmacro objed--call-and-switch (cmd obj)
+  "Create objed command which will invoke CMD and switch to OBJ."
+  `(defun ,(intern (format "objed-%s" (symbol-name cmd))) ()
+     ,(format "Call `%s' and switch to object %s"
+             (symbol-name cmd) (symbol-name obj))
+     (interactive)
+     (call-interactively ',cmd)
+     (objed--switch-to ',obj)))
+
+
+(defvar objed-map
+  (let ((map (make-sparse-keymap)))
+    ;; block unused chars by default
+    (dolist (seq (list (number-sequence ?a ?z)
+                       (number-sequence ?A ?Z)))
+      (dolist (char seq)
+        (define-key map (format "%c" char) 'objed-undefined)))
+    ;; keep map active for numeric args
+    (dolist (n (number-sequence ?0 ?9))
+      (define-key map (format "%c" n) 'digit-argument)
+      (define-key map (kbd (format "M-%c" n)) 'digit-argument)
+      (define-key map (kbd (format "C-%c" n)) 'digit-argument))
+    ;; common emacs keys
+    (define-key map (kbd "C-g") 'objed-quit)
+    (define-key map "g" 'objed-quit)
+    (define-key map (kbd "C-h") 'objed-show-top-level)
+    ;; TODO: support repeated invokation
+    (define-key map (kbd "C-u") 'universal-argument)
+    (define-key map (kbd "C-SPC") 'set-mark-command)
+    ;; todo: restore object state, too?
+    (define-key map (kbd "/") (objed--call-and-switch undo char))
+    ;; usual emacs keys which should not trigger reset should be added to
+    ;; objed-keeper-commands...
+    
+    
+    ;; general movement
+    (define-key map "b" (objed--call-and-switch backward-char char))
+    (define-key map "f" (objed--call-and-switch forward-char char))
+
+    (define-key map "s" (objed--call-and-switch forward-word word))
+    (define-key map "r" (objed--call-and-switch backward-word word))
+
+    (define-key map "S" 'objed-forward-symbol)
+    (define-key map "R" 'objed-backward-symbol)
+   
+
+    (define-key map "p" (objed--call-and-switch previous-line line))
+    (define-key map "n" (objed--call-and-switch next-line line))
+
+
+    ;; block expansions
+    (define-key map "l" 'objed-expand-block)
+    (define-key map "a" 'objed-beg-of-block)
+    (define-key map "e" 'objed-end-of-block)
+
+    ;; context expansions
+    (define-key map "t" 'objed-current-or-previous-context)
+    (define-key map "h" 'objed-current-or-next-context)
+    (define-key map "o" 'objed-expand-context)
+    (define-key map "u" 'objed-upto-context)
+    
+    (define-key map "i" 'objed-toggle-state)
+    (define-key map "q" 'objed-toggle-side)
+    
+    ;; TODO: birdview mode/scroll mode
+    (define-key map "v" 'scroll-up-command)
+    (define-key map "\ev" 'scroll-down-command)
+    (define-key map "V" 'scroll-down-command)
+    
+    ;; marking/unmarking
+    (define-key map "m" 'objed-mark)
+    ;; jump back and  mark, unmark if necessary
+    (define-key map "M" 'objed-toggle-mark-backward)
+
+
+    ;; basic edit ops
+    (define-key map "k" 'objed-kill)
+    (define-key map "w" 'objed-copy)
+    (define-key map "d" 'objed-delete)
+    (define-key map "y" 'objed-yank)
+    (define-key map (kbd "TAB")
+      (objed-define-op nil objed-indent))
+
+      
+    (define-key map ";"
+      (objed-define-op nil objed-comment-or-uncomment-region))
+    (define-key map ":"
+      (objed-define-op nil objed-comment-duplicate))
+
+    (define-key map "$"
+      (objed-define-op nil flyspell-region))
+
+    (dolist (str (split-string  "'\"([{" "" t))
+      (define-key map (kbd str)
+       (objed-define-op nil objed-electric)))
+    
+    ;; quote op
+    (define-key map "`"
+      (objed-define-op nil objed-electric-pair))
+    ;; all the usual quoting signs
+
+    
+    ;; special commands
+    (define-key map "," 'objed-last)
+    ;; jump to objects with avy
+    (define-key map "z" 'objed-ace)
+    ;; swiper like object search
+    (define-key map "j" 'objed-occur)
+
+    ;; prefix keys
+    (define-key map "x" 'objed-op-map)
+    (define-key map "c" 'objed-object-map)
+
+    (dolist (k2d objed--dispatch-key-alist)
+      (define-key map (kbd (car k2d)) (cdr k2d)))
+
+    ;; direct acc objs
+    ;; moved to S/R
+    ;; (define-key map "_" 'objed-symbol-object)
+    ;; direct object switches
+    (define-key map "." 'objed-identifier-object)
+    (define-key map "%" 'objed-contents-object)
+     ;; not regular objects, selection
+    ;; (define-key map (kbd "M-SPC") 'objed-select-object)
+    ;; used for direct quoting now...
+    ;; (define-key map "{" 'objed-paragraph-object)
+    ;; (define-key map "[" 'objed-section-object)
+    ;; (define-key map "(" 'objed-textblock-object)
+    
+    map)
+  "Keymap for commands when `objed' is active.")
+
+
+(defun objed--define-prefix (key cmd)
+  "Create a prefix keymap for `objed-map'.
+
+The keymap will be accessible with KEY and bound to prefix command
+CMD.
+
+The keymap is initilized with basic bindings for numeric
+arguments and help.
+
+Other single character keys are bound to `objed-undefined'."
+  (let ((map (define-prefix-command cmd)))
+    ;; init as prefix
+    (define-key objed-map (kbd key) map)
+    ;; basic bindings
+    (dolist (seq (list (number-sequence ?a ?z)
+                       (number-sequence ?A ?Z)))
+      (dolist (char seq)
+        (define-key map (kbd (format "%c" char)) 'objed-undefined)))
+    (let (loop)
+      (define-key map "-" 'negative-argument)
+      ;; Make plain numbers do numeric args.
+      (setq loop ?0)
+      (while (<= loop ?9)
+        (define-key map (char-to-string loop) 'digit-argument)
+        (setq loop (1+ loop))))
+
+    (define-key map (kbd "C-h") 'objed-describe-prefix-bindings)
+    map))
+
+
+(defvar objed-op-map
+  (let ((map (objed--define-prefix "x" 'objed-op-map)))
+    (define-key map "x" 'objed-op-x)
+    
+    (define-key map "c"
+       ;; upcase, downcase, capitalize, reformat
+      (objed-define-op nil objed-case-op))
+    (define-key map "u"
+      (objed-define-op nil objed-undo-op))
+    (define-key map "r"
+      (objed-define-op nil objed-replace-op))
+    (define-key map "p"
+      (objed-define-op nil objed-pipe-region))
+    
+    ;; experimental
+    (define-key map "e" 'objed-eval)
+    ;; uses edit-indirect if av., via prefix
+    (define-key map "n" 'objed-narrow)
+    map)
+  "Map for additional operations called via a prefix from `objed-map'.
+
+To define new operations see `objed-define-op'.")
+
+
+(defvar objed-object-map
+  (let ((map (objed--define-prefix "c" 'objed-object-map)))
+    ;; choose via completion
+    (define-key map "x" 'objed-object-x)
+    (define-key map (kbd "SPC") 'objed-region-object)
+    ;; default objects
+    (define-key map "c" 'objed-char-object)
+    ;; sexp at point
+    (define-key map "o" 'objed-sexp-object)
+    
+    (define-key map "a" 'objed-sentence-object)
+    (define-key map "k" 'objed-textblock-object)
+    (define-key map "q" 'objed-paragraph-object)
+    (define-key map "i" 'objed-indent-object)
+    ;; meg
+    (define-key map "m" 'objed-iblock-object)
+    
+    (define-key map "b" 'objed-bracket-object)
+    (define-key map "d" 'objed-defun-object)
+    (define-key map "s" 'objed-string-object)
+    (define-key map ";" 'objed-comment-object)
+    
+    (define-key map "t" 'objed-tag-object)
+    (define-key map "f" 'objed-file-object)
+
+    (define-key map "p" 'objed-section-object)
+    (define-key map "l" 'objed-output-object)
+    (define-key map "h" 'objed-buffer-object)
+
+    ;;  handled by basic movement..
+    ;; (define-key map "w" 'objed-word-object)
+    ;; (define-key map "l" 'objed-line-object)
+    ;; (define-key map "s" 'objed-symbol-object)
+
+    map)
+  "Keymap used for additional text-objects by `objed'.
+
+To define new objects see `objed-define-object'.")
+
+;; * Dispatch definitions
+
+(defvar objed-dispatch-map
+  (let ((map (make-composed-keymap nil objed-object-map)))
+    (define-key map (kbd "C-h") 'objed-describe-dispatch-bindings)
+    map)
+  "Keymap for dispatching commands to objects.
+
+Use `objed-define-dispatch' to define a dispatch command.")
+
+(objed-define-dispatch "<" objed--backward-until)
+(objed-define-dispatch ">" objed--forward-until)
+(objed-define-dispatch "*" objed--mark-all-inside)
+
+
+(defun objed--backward-until (name)
+  "Activate part from point backward until object NAME."
+  (let* ((start (point))
+        (o (objed--until name t)))
+    (objed--switch-to
+     name nil
+     (objed-make-object
+      :beg  (point)
+      :end start
+      :ibeg (objed--min o)
+      :iend start))))
+
+(defun objed--forward-until (name)
+  "Activate part from point forward until object NAME."
+  (let* ((start (point))
+        (o (objed--until name)))
+    (objed--switch-to
+     name nil
+     (nreverse
+      (objed-make-object
+       :ibeg start
+       :iend (point)
+       :beg start
+       :end (objed--max o))))))
+
+(defun objed--mark-all-inside (name)
+  "Mark all objects of current type inside object NAME."
+  (save-excursion
+    (save-restriction
+      ;; narrow to object we search for objects in
+      (when (objed--save-state
+            (when (objed--switch-to name)
+              (narrow-to-region (objed--min) (objed--max))
+              (goto-char (point-min))))
+       ;; objed-mark-object
+       (let ((n (objed--do-all 'objed--mark-object)))
+         (message "Marked %s %ss in %s." n objed--object name))))))
+
+
+(defun objed--until (n &optional back)
+  "Get object N and move point accordingly.
+
+By default search object in forward direction. If BACK is non-nil
+search backwards."
+  (let* ((objed--object n)
+        (objed--obj-state 'whole)
+        (o (objed--get back)))
+    (prog1 o
+      (if (objed--distant-p o)
+         (if back
+             (goto-char (objed--end o))
+           (goto-char (objed--min o)))
+       (if back
+           (goto-char (objed--alt-beg o))
+         (goto-char (objed--alt-end o)))))))
+
+
+(defun objed-undefined ()
+  "Provide feedback if an undefined key is pressed."
+  (interactive)
+  (let ((msg (format "%s is undefined"
+                     (key-description (this-single-command-keys)))))
+    ;;(if (not objed--which-key-avail-p)
+    ;; (objed--maybe-which-key objed-map msg t))))
+    (message msg)))
+
+(defvar objed--look-around nil
+  "Object data used by toggle ends commands.")
+
+(defun objed--toggle-ends (init)
+  "Toggle point between ends of an object.
+
+INIT should be a function which initializes the object. Its start
+and end postion will be used for toggle."
+  (cond ((eq last-command 'ignore)
+        (let ((pos (objed--other)))
+          (objed--update-current-object
+           (objed--copy-object objed--look-around))
+          (objed--change-to :iend pos :end pos)
+          (goto-char (objed--beg)))
+        ;; set it to same name(ignore by push-state)
+        (setq this-command 'objed-look-around))
+       ((eq last-command 'objed-look-around)
+        (let ((pos (objed--other)))
+          (objed--update-current-object
+           (objed--copy-object objed--look-around))
+          (objed--change-to :ibeg pos :beg pos)
+          (goto-char (objed--end))
+          (setq this-command 'ignore)))
+       (t
+        (when (save-excursion (funcall init))
+          (setq objed--look-around (objed--copy-object))
+          (objed--change-to :ibeg (point) :beg (point))
+          (goto-char (objed--end))
+          ;; dont save state of modified object
+          (setq this-command 'ignore)))))
+
+
+
+;; * Init active state
+
+(defvar objed--which-key-avail-p nil
+  "Whether `which-key' package is available.")
+
+(defvar objed--avy-avail-p nil
+  "Whether `avy' package is available.")
+
+(defvar objed--saved-vars nil
+  "Variables to save and restore.")
+
+(defvar objed--hl-line-keep-p nil
+  "Whether to keep command `hl-line-mode' active on reset.")
+
+(defvar objed--saved-cursor nil
+  "Cursor color before objed got initialized.")
+
+(defvar objed--buffer nil
+  "Buffer where objed got initialized.")
+
+(defvar objed--block-p nil
+  "Block advices installed by `objed'.")
+
+(defvar objed--hl-cookie nil
+  "The remapping cookie for `hl-line' face.")
+
+(defvar objed--wk-replacement-alist
+  (list
+   ;; commands to ignore
+   `((nil . ,(regexp-opt
+              (list "objed-describe-prefix-bindings"
+                    "objed-describe-dispatch-bindings"
+                    "objed-show-top-level"
+                   "digit-argument"
+                    "universal-argument"
+                    "undefined"
+                    "negative-argument")))
+     . t)
+   ;; show only object name for objects
+   '((nil . "\\`objed-\\(.*?\\)-.*?object\\'")
+     . (nil . "\\1"))
+   ;; remove package prefix all others
+   '((nil . "\\`\\(objed-\\)+\\(.*\\)")
+     . (nil . "\\2")))
+  "Rules to add to `which-key-replacement-alist'.
+
+Only relevant when `which-key' is used.")
+
+(defvar objed--ignored-keys nil
+  "Keys recently ignored by `which-key' popup.
+
+Useful for keeping the same popup when pressing undefined keys.")
+
+(defvar-local objed-disabled-p nil
+  "If non-nil objed will not activate.")
+
+(defun objed--activate (cmd &rest _)
+  "Activate `objed' with command CMD.
+
+See `objed-cmd-alist'."
+  (when (and objed-mode
+            (not (minibufferp))
+            (not objed--block-p)
+            (eq real-this-command cmd)
+            (not objed-disabled-p)
+            ;; (memq (key-binding "q")
+            ;;            '(self-insert-command
+            ;;              outshine-self-insert-command
+            ;;              org-self-insert-command))
+            (or (memq major-mode '(messages-buffer-mode help-mode))
+                (not (apply 'derived-mode-p objed-disabled-modes))))
+      (objed--init cmd)))
+
+(defun objed--save-start-position (&rest _)
+  "Save position of point via `objed--opoint'."
+  (setq objed--opoint (point)))
+
+(defun objed--goto-start (&optional _)
+  "Goto start of current object."
+  (goto-char (objed--beg)))
+
+(defun objed--object-trailing-line (pos)
+  "Activate trailing part from POS."
+  (unless (eq objed--obj-state 'inner)
+    (objed--reverse))
+  (objed--change-to :beg pos :ibeg pos))
+
+(defun objed--init (&optional sym)
+  "Initialize `objed'.
+
+SYM is a symbol (command or object symbol) used to initialize."
+  ;; if anything went wrong make sure to start with clean state
+  (when objed--buffer
+    (objed--reset))
+  ;; (unless objed--buffer
+  (setq objed--current-obj nil)
+  (setq objed--obj-state 'whole)
+
+  (setq objed--buffer (current-buffer))
+  (add-hook 'pre-command-hook 'objed--push-state nil t)
+
+  (pcase-dolist
+      (`(,var . ,val)
+       `((hl-line-range-function . objed-hl-function)
+        (suggest-key-bindings . nil)
+        (which-key-sort-order . ,objed-which-key-order)
+        (which-key-replacement-alist
+         . ,(append objed--wk-replacement-alist
+                    which-key-replacement-alist))))
+    (push
+     (if (local-variable-p var)
+        (cons var (symbol-value var))
+       var)
+     objed--saved-vars)
+    (set (make-local-variable var) val))
+
+  (unless (or (setq objed--hl-line-keep-p
+                   (bound-and-true-p hl-line-mode))
+             (not sym)
+             (not objed-use-hl-p))
+    (unless (boundp 'hl-line-mode)
+      (require 'hl-line))
+    (setq objed--hl-cookie
+         (face-remap-add-relative 'hl-line 'objed-hl))
+    (hl-line-mode 1))
+
+  ;; init cursor
+  (setq objed--saved-cursor
+        (face-attribute 'cursor :background))
+  (set-cursor-color objed-cursor-color)
+
+  ;; init object
+  (if (commandp sym)
+      (let* ((objed--block-p t)
+            (initf (cdr (assq sym objed--after-init-alist)))
+            (o (objed--get-object-for-cmd sym)))
+       (when o
+         (objed--switch-to o))
+       (when initf (funcall initf objed--opoint)))
+    (objed--switch-to sym))
+
+  ;; transient map
+  (fset #'objed--exit-objed
+        (set-transient-map objed-map
+                          #'objed--keep-transient-p
+                          #'objed--reset))
+  
+  (when objed-modeline-hint-p
+    (funcall objed-modeline-setup-func objed-mode-line-format))
+  ;; show which key after redisplay if active
+  (when objed-auto-wk-top-level-p
+    (run-at-time 0 nil #'objed-show-top-level)))
+
+
+(defun objed--setup-mode-line (format &optional reset)
+  "Default function to setup the mode line hint.
+FORMAT is used for `mode-line-format'.
+
+Adds `objed-mode-line-format' at front. If RESET is non-nil the
+mode line hint is removed again."
+  (cond (reset
+        (setq mode-line-format
+              (delete format mode-line-format)))
+       (t
+        (push format mode-line-format))))
+
+
+(defun objed--keep-transient-p ()
+  "Return non-nil if `objed-map' should stay active.
+
+Reinitializes the current object in case the current command is
+one of `objed-keeper-commands'."
+  (or (commandp (lookup-key objed-map (this-command-keys-vector)))
+       (and (memq (key-binding (this-command-keys-vector))
+                 objed-keeper-commands)
+           (prog1 #'ignore
+             (add-hook 'post-command-hook 'objed--reinit-object-one-time nil 
t)))))
+  
+
+(defun objed--reinit-object-one-time ()
+  "To be used with `post-command-hook'.
+
+Reinitializes current object and removes itself from the hook."
+  (when objed--buffer
+    (with-current-buffer objed--buffer
+      (remove-hook 'post-command-hook 'objed--reinit-object-one-time t)
+      (objed--update-current-object))))
+
+
+(defun objed-hl-function ()
+  "Function used as default for `hl-line-range-function'."
+  (when (and objed--buffer objed--current-obj
+            ;; the region is the current text object now
+            (not (region-active-p)))
+    (cons (objed--beg) (objed--end))))
+
+
+;; * Help commands
+
+(defun objed-show-top-level (&optional interactive)
+  "Show bindings of `objed-map'.
+
+When `which-key' isn't use only show bindings if INTERACTIVE is
+non-nil which is the case when called interactively."
+  (interactive "p")
+  (unless (objed--maybe-which-key
+           objed-map "Op keys"
+           interactive)
+    (when interactive
+      (objed--describe-bindings objed-map))))
+
+(defun objed-describe-dispatch-bindings ()
+  "Describe `objed-dispatch-map' bindings."
+  (interactive)
+  (unless (objed--maybe-which-key
+           objed-dispatch-map "Select" t)
+    (setq mark-active nil)
+    (objed--describe-bindings
+     objed-dispatch-map (vector (aref (this-command-keys-vector) 0)))))
+
+(defun objed--describe-bindings (map &optional key)
+  "Decsribe bindings of keymap MAP which was activated with KEY."
+  (with-temp-buffer
+    (let ((key (or key
+                  ;; for top level make one up
+                  [modal]))
+          (imap (make-sparse-keymap)))
+      (define-key imap key map)
+      (set-transient-map imap)
+      (describe-bindings key (current-buffer))))
+  (objed--exit-objed))
+
+
+(defun objed-describe-prefix-bindings ()
+  "Show current prefix bindings and exit."
+  (interactive)
+  (call-interactively 'describe-prefix-bindings)
+  (objed--exit-objed))
+
+
+(defvar objed--avy-err-msg
+  "Package `avy' is not available.
+Add `avy' to your load path and restart `objed-mode' with a
+non-nil value of `objed-use-avy-if-available-p'."
+  "Error message to use if avy commands are not ready to run.")
+
+
+(defun objed--maybe-which-key (map desc &optional nowait iregex)
+  "Show which key popup if user configured to use it.
+
+MAP is the keymap which bindings should be displayed and DESC is
+a string to show as the description of the popup.
+
+Waits `which-key-idle-delay' before displaying the popup unless
+NOWAIT is non-nil. IREGEX is a regular expressions of bindings to
+ignore in `which-key' popup. Any binding whose description
+matches IREGEX is not displayed."
+  (when (and objed--which-key-avail-p
+             ;; let the user deactivate later as well...
+             objed-use-which-key-if-available-p
+             which-key-mode
+             (or nowait (sit-for which-key-idle-delay)))
+    (prog1 t
+      (setq which-key--using-top-level desc)
+      (let ((which-key-replacement-alist
+             (if iregex
+                 (append `(((nil . ,iregex) . t))
+                         which-key-replacement-alist)
+               which-key-replacement-alist)))
+        (which-key--create-buffer-and-show nil map)))))
+
+;; * Basic Movement, Block Objects (textblocks)
+
+(defvar objed--block-objects '(line iblock indent textblock paragraph section)
+  "List of objects which are 'line based'.
+
+Objects which are built by lines of text.")
+
+(defun objed--get-block-objects-for-context (&optional ignore)
+  "Get list of objects for current context.
+
+If IGNORE is non-nil it should be an object of
+`objed--block-objects' which should be ignored."
+  (let ((os (cond ((bound-and-true-p outline-minor-mode)
+                  objed--block-objects)
+                 ((eq major-mode 'org-mode)
+                  (let ((os nil))
+                    ;; TODO: sort by object size?
+                    (dolist (o objed--block-objects (nreverse os))
+                      (unless (memq o '(indent textblock iblock))
+                        (push o os)))))
+                 (t
+                  ;; performance is poor on slow
+                  ;; machines when searching after
+                  ;; every char with objed--get in case
+                  ;; there are no outlines/mode not active
+                  (remq 'section objed--block-objects)))))
+    (remq ignore
+         (if (save-excursion
+               (and (or (not (derived-mode-p 'text-mode))
+                        (derived-mode-p 'sgml-mode))
+                    (progn (unless (eolp) (objed--skip-ws))
+                           ;; if line is a comment line search
+                           ;; for textblocks (parag. inside comments)
+                           (objed--in-comment-p))))
+             (progn (unless (eolp) (objed--skip-ws))
+                    (append  os (list 'comment)))
+           os))))
+
+(defun objed--get-blocks (ignore collf &optional istate)
+  "Get line based object states.
+
+If IGNORE is non-nil it should be a symbol for a block object
+which should be ignored. COLLF is a function which should be used
+to collect positions used for sorting the results in ascending
+order. ISTATE is the object state to use and defaults to whole."
+  (objed--save-state
+     (let ((os (objed--get-block-objects-for-context ignore))
+          (states nil)
+          (oos nil)
+          (nos nil))
+     (while os
+       (when (and (ignore-errors
+                     (objed--switch-to (car os) istate))
+                 (not (member (objed--current) oos)))
+        (push (objed--current) oos)
+        (push (cons (funcall collf)
+                    (objed--get-current-state))
+              states))
+       (pop os))
+    ;; TODO: use size of object for sorting
+    (dolist (ps (sort states (lambda (a b)
+                              ;; ensure line comes first
+                              (and (not (eq (cadr (cddr a)) 'line))
+                                   ;; TODO: fix state format
+                                   (<= (car a) (car b)))))
+               nos)
+      (push (cdr ps) nos)))))
+
+
+(let ((blocks nil))
+  (defun objed-expand-block ()
+  "Jump to beginning of line based objects.
+
+Activates (line based) object at point (and move to its start).
+On repeat proceed to beginning of the indentation block,
+paragraph and other 'line based' objects.
+
+See also `objed--block-objects'."
+  (interactive)
+  (let ((init (not (memq last-command
+                        (list this-command
+                              'objed-toggle-side)))))
+    (when init
+      (setq blocks (cl-remove
+                   nil
+                   (objed--get-blocks
+                    ;; ignore current or allow toggle between
+                    ;; inner/whole here as well?
+                    objed--object
+                    #'objed--beg)
+                   :test (lambda (_ a)
+                           (let ((as (objed--beg (car (nthcdr 3 a)))))
+                             ;; make sure position is not below start
+                             (> as (objed--skip-forward (point) 'ws)))))))
+  (when blocks
+     (let ((sdiff (abs (- (point) (objed--beg))))
+          (ediff (abs (- (point) (objed--end)))))
+       (objed--restore-state (pop blocks))
+       (goto-char (cond ((or (> ediff sdiff)
+                            init)
+                        (objed--beg))
+                       (t
+                        (objed--end)))))))))
+
+
+
+
+(let ((blocks nil))
+  (defun objed-beg-of-block ()
+  "Jump to beginning of line based objects.
+
+Moves to beginning of line/indentation and activates the text
+moved over. On repeat proceed to beginning of the indentation
+block, paragraph and other 'line based' objects.
+
+See also `objed--block-objects'."
+  (interactive)
+  (cond ((eq last-command this-command)
+        (when blocks
+          (let ((end (objed--end)))
+            (objed--restore-state (pop blocks))
+            (objed--change-to :end end :iend end)
+            (goto-char (objed--beg)))))
+       (t
+        (objed--switch-to 'line
+                          (unless (<= (point)
+                                      (objed--indentation-position))
+                            'inner))
+        (objed--change-to :end (point) :iend (point))
+        (goto-char (objed--beg))
+        ;; get all which make sense from starting point
+        (setq blocks
+              (cl-remove-duplicates
+               (objed--get-blocks
+                nil ;;'line after inner...
+                #'objed--beg)
+               :test (lambda (a b)
+                       (let ((as (objed--beg (car (nthcdr 3 a))))
+                             (bs (objed--beg (car (nthcdr 3 b)))))
+                         (or (eq  as bs)
+                             (>= as (point)))))))))))
+
+
+(let ((blocks nil))
+  ;; line end of block
+  (defun objed-end-of-block ()
+    "Jump to end of line based objects.
+
+Moves to end of line and activates the text moved over. On repeat
+proceed to end of the indentation block, paragraph and other
+'line based' objects.
+
+See also `objed--block-objects'."
+    (interactive)
+    (cond ((eq last-command this-command)
+          (when blocks
+            (let ((beg (objed--beg)))
+              (objed--restore-state (pop blocks))
+              (objed--change-to :beg beg :ibeg beg)
+              (goto-char (objed--end)))))
+         (t
+          (objed--switch-to 'line 'inner)
+          (objed--change-to :beg (point) :ibeg (point))
+          (goto-char (objed--end))
+          ;; get all which make sense from starting point
+          (setq blocks
+                (cl-remove-duplicates
+                 (nreverse
+                  (objed--get-blocks
+                   'line
+                   #'objed--end
+                   ;; better for most cases
+                   'inner))
+                 :test (lambda (a b)
+                         (let ((as (objed--end (car (nthcdr 3 a))))
+                               (bs (objed--end (car (nthcdr 3 b)))))
+                           (or (eq  as bs)
+                               (<= as (point)))))))))))
+
+
+(defun objed-forward-symbol ()
+  "Move point forward one symbol.
+
+Skips strings and comments."
+  (interactive)
+  (let ((pos (point)))
+    (if (not (eq objed--object 'symbol))
+       (progn
+         (objed--switch-to 'symbol)
+         (goto-char (objed--end))
+         ;; at end of word...
+         (unless (or (> (point) pos)
+                     (eobp))
+           (objed--next-symbol)
+           (objed--switch-to 'symbol)
+           (goto-char (objed--end))))
+    (objed--next-symbol)
+    (objed--switch-to 'symbol)
+    (goto-char (objed--end)))))
+
+
+(defun objed-backward-symbol ()
+  "Move point backward one symbol.
+
+Skips strings and comments."
+  (interactive)
+  (let ((pos (point)))
+    (if (not (eq objed--object 'symbol))
+       (progn
+         (objed--switch-to 'symbol)
+         (goto-char (objed--beg))
+         (unless (< (point) pos)
+           ;; in case we got the fallback
+           (objed--prev-symbol)
+           (objed--prev-symbol)
+           (objed--switch-to 'symbol)
+           (goto-char (objed--beg))))
+      (objed--prev-symbol)
+      (objed--switch-to 'symbol)
+      (goto-char (objed--beg)))))
+
+
+;; * Context Objects (programming constructs)
+
+(defvar objed--context-objects '(string bracket tag textblock comment)
+  "List of objects to be choosen by context.")
+
+(defun objed--basic-p ()
+  "Return non-nil if current object is a basic object.
+
+From basic objects `objed' starts expanding to context objects."
+  (memq objed--object '(line word char symbol region buffer)))
+
+(defun objed--get-context-state (from)
+  "Get state to be used by expand commands.
+
+FROM is a list of objects to use for guessing the object at point."
+  (let (o)
+    (objed--save-state
+     (save-excursion
+       (cond ((setq o (objed--at-p
+                      (remq objed--object
+                            ;; maybe at other at line beginning as well
+                            ;; add section back here as well?
+                            '(defun))))
+             (objed--switch-to o))
+            ((setq o (objed--at-p (remq objed--object from)))
+             (objed--switch-to o))
+            ((setq o (save-excursion
+                       (when (<= (point) (objed--indentation-position))
+                         (objed--skip-ws))
+                       (or (objed--at-p (remq objed--object from))
+                           ;; never test for struct inside, its to broad
+                           (objed--in-p (remq objed--object from)))))
+             (when (<= (point) (objed--indentation-position))
+               (objed--skip-ws))
+             (objed--switch-to o))
+            (t
+             (goto-char (objed--beg))
+             (skip-chars-backward " \t")
+             (when (setq o (or (objed--at-p objed--context-objects)
+                               (objed--in-p objed--context-objects)))
+               (let ((c (objed--current)))
+                 (objed--switch-to o)
+                 (when (equal (objed--current) c)
+                   ;; FIX: more general
+                   (forward-char -1)
+                   (when (setq o (or (objed--at-p objed--context-objects)
+                                     (objed--in-p objed--context-objects)))
+                     (objed--switch-to o)))))))
+       (when o (objed--get-current-state))))))
+
+
+(defun objed-context-object ()
+  "Guess and activate object at point.
+
+Tries to guess the object at point and moves to start of it.
+
+Repeated calls will continue guessing objects and try to expand
+to an object containing the current one."
+  ;; stop with defun for now
+  (unless (eq objed--object 'defun)
+    (let ((objed--context-objects
+          ;; TODO: docstrings as well
+          (if (or (and (objed--in-comment-p)
+                       (not (objed--at-comment-p)))
+                  (and (derived-mode-p 'text-mode)
+                       ;; sentences in p tags?
+                       (not (derived-mode-p 'sgml-mode))))
+              (append (list 'sentence) objed--context-objects)
+            objed--context-objects))
+         (s nil))
+      ;; TODO: make direction, position dependend and stay at beg/end?
+      (if (setq s (objed--get-context-state objed--context-objects))
+       (progn (objed--restore-state s)
+              (force-mode-line-update)
+              (goto-char (objed--beg)))
+       ;; fallback if nothing else found
+        (or (objed--switch-to 'defun 'inner)
+            (objed--switch-to 'line 'inner))))))
+
+
+(defun objed-current-or-previous-context (&optional arg)
+  "Move to end of object at point and activate it.
+
+On repeat move to the previous instance of this object type. With
+postitive prefix argument ARG move to the nth previous object."
+  (interactive "p")
+  (if (objed--basic-p)
+      (objed-context-object)
+    ;; toggle side if coming from next?
+    (objed--goto-previous (or arg 1))))
+
+(defun objed-current-or-next-context (&optional arg)
+  "Move to beginning of object at point and activate it.
+
+On repeat move to the next instance of this object type. With
+postitive prefix argument ARG move to the nth next object."
+  (interactive "p")
+  (if (objed--basic-p)
+      (progn (objed-context-object)
+            (goto-char (objed--end)))
+  (objed--goto-next (or arg 1))))
+
+(defun objed-expand-context ()
+  "Expand to objects based on context.
+
+Starts at the inner part of the object point is in or at. Any
+whitespace following point is skipped. Point moves to the start."
+  (interactive)
+  (if (objed--basic-p)
+      (progn (objed-context-object)
+            (objed-toggle-state))
+    (if (objed--inner-p)
+       (let ((curr (objed--current)))
+         (objed-toggle-state)
+         (when (equal curr (objed--current))
+           (objed-context-object)
+           (goto-char (objed--beg))))
+    (objed-context-object)
+    (goto-char (objed--beg)))))
+
+(defun objed-upto-context ()
+  "Toggle between inner sides of object at point.
+
+Moves to end of (inner) object at point and activates the text
+moved over. On repeat toggle between beginning/end inside the
+object.
+
+Object is choosen based on context."
+  (interactive)
+  (objed--toggle-ends
+   (lambda ()
+     (objed-context-object)
+     (objed-toggle-state))))
+
+
+;; * General object commands
+
+(defun objed-object-x ()
+  "Choose and switch to object with completion."
+  (interactive)
+  (let (objects obj)
+     (map-keymap (lambda (_ev cmd)
+                  (let ((name (symbol-name cmd)))
+                    (when (string-match
+                           "\\`objed-\\(.*?\\)-object\\'"
+                           name)
+                      (push (match-string 1 name)
+                            objects))))
+                objed-object-map)
+     (when (setq obj (objed--with-allow-input
+                      (completing-read "Objects: " objects)))
+       (when (objed--switch-to obj)
+        (goto-char (objed--beg))))))
+
+
+(defun objed-activate ()
+  "Activate objed.
+
+Uses `objed-initial-object' for initialization."
+  (interactive)
+  (objed--init objed-initial-object))
+
+
+(defun objed--goto-char (pos)
+  "Move to position POS possibly skipping leading whitespace."
+  (goto-char
+   (if (eq objed--object 'char)
+       pos
+     (objed--skip-forward pos 'ws))))
+ 
+
+(defun objed-toggle-side ()
+  "Move to other side of object.
+
+Default to sexp at point."
+  (interactive)
+  (let ((sdiff (abs (- (point) (objed--beg))))
+       (ediff (abs (- (point) (objed--end)))))
+    (cond ((> ediff sdiff)
+          (goto-char (objed--end))
+          (objed--skip-ws t))
+         (t
+          (goto-char (objed--beg))
+          (objed--skip-ws)))))
+
+(defun objed-toggle-state ()
+  "Toggle state of object."
+  (interactive)
+  (let ((sdiff (abs (- (point) (objed--beg))))
+       (ediff (abs (- (point) (objed--end)))))
+    (objed--reverse)
+    (goto-char (cond ((> ediff sdiff)
+                     (objed--beg))
+                    (t
+                     (objed--end))))))
+
+
+(defun objed--indentation-position ()
+  "Get buffer position of indentation on current line."
+  (save-excursion
+    (back-to-indentation)
+    (point)))
+
+
+(defun objed-select-object ()
+  "Select current object with active region."
+  (interactive)
+  (push-mark (objed--end) t t)
+  (goto-char (objed--beg)))
+
+(defun objed-contents-object ()
+  "Switch to reference of an object.
+
+Reference is how you would refer to an object. As an example for
+a defun it would be the function name. This defaults to the
+textual content of an object via the content object."
+  (interactive)
+  (let ((ref (objed--object :ref)))
+    (if ref (objed--switch-to ref)
+      (setq objed--content-bounds
+           (objed--bounds))
+      (objed--switch-to 'content))
+    (goto-char (objed--beg))
+    (force-mode-line-update)))
+  
+
+(defun objed-ace ()
+  "Jump to an object with `avy'."
+  (interactive)
+  (unless (and objed--avy-avail-p
+               objed-use-avy-if-available-p)
+    (user-error objed--avy-err-msg))
+  (let* ((avy-action #'goto-char)
+         (avy-style 'at-full)
+         (avy-all-windows t)
+         (posns (objed--collect-object-positions
+                 (window-start) (window-end))))
+    (cond (posns
+           (if (> (length posns) 1)
+               (avy--process
+                posns (avy--style-fn avy-style))
+             (goto-char (caar posns)))
+           (objed--update-current-object))
+          (t
+           (message "No objects found.")))))
+
+(defun objed-occur ()
+  "Complete initial lines and jump to object."
+  (interactive)
+  (let* ((lines (objed--collect-object-lines))
+        (ivy-sort-function-alist nil)
+        (completion-table
+         ;; avoid auto sorting of completing read
+         (lambda (string pred action)
+           ;; FIX: its upside down for sections
+           (if (eq action 'metadata)
+               '(metadata (display-sort-function . identity)
+                          (cycle-sort-function . identity))
+             (complete-with-action action lines string pred))))
+        (res (objed--with-allow-input
+              (cdr (assoc (completing-read "Objects: " completion-table)
+                          lines)))))
+    (when res
+      (goto-char res)
+      (objed--update-current-object)
+      (goto-char (objed--beg)))))
+
+
+(defun objed-mark (&optional arg)
+  "Mark/unmark objects.
+
+Marks the object at point or unmarks it if it is marked already.
+If the object contains marked objects those are unmarked.
+
+Afterwards move to the next object. With positive numeric prefix
+argument ARG mark that many objects."
+  (interactive "p")
+  (let ((arg (or arg 1)))
+    (dotimes (_ arg)
+      (objed--toggle-mark)
+      (objed--goto-next))))
+
+
+(defun objed--merge-marked ()
+  "Merge marked objects.
+
+Unmarks all and marks the text between the first and last marked
+object instead and moves to its start."
+  (interactive)
+  (if (cdr objed--marked-ovs)
+      (let (first last)
+       (setq last (pop objed--marked-ovs))
+       (setq objed--marked-ovs (nreverse objed--marked-ovs))
+       (setq first (pop objed--marked-ovs))
+       (let ((beg (overlay-start first))
+             (end (overlay-end last)))
+         ;; reset marked
+         (delete-overlay first)
+         (delete-overlay last)
+         (dolist (ov objed--marked-ovs)
+           (delete-overlay ov))
+         (setq objed--marked-ovs nil)
+         (objed--change-to :beg beg :end end)
+         (goto-char beg))
+       (message "Merged marked objects before execution."))
+    (message "At least two marked objects needed.")))
+
+
+(defun objed-unmark (&optional arg)
+  "Unmark objects.
+
+Like `objed-mark' but unmarks. With positive numeric prefix
+argument ARG unmark that many objects."
+  (interactive "p")
+  (let ((arg (or arg 1)))
+    (dotimes (_ arg)
+      (objed--unmark-object)
+      (objed--goto-next))))
+
+(defun objed-toggle-mark ()
+  "Like `objed-mark', but don't move on to next object."
+  (interactive)
+  (objed--toggle-mark))
+
+
+(defun objed-toggle-mark-backward (&optional arg)
+  "Move to previous object and toggle mark it.
+
+With positive numeric prefix argument ARG unmark that many
+previous objects."
+  (interactive "p")
+  (let ((arg (or arg 1)))
+    (dotimes (_ arg)
+      ;; enf. top down order
+      (objed--toggle-mark nil 'append)
+      (objed--goto-previous))))
+
+(defun objed-last ()
+  "Resume to last state.
+
+This is for quickly resuming to states on navigation. Note that
+the state is only restored correctly if the buffer was not
+modified."
+  (interactive)
+  (objed--restore-state))
+
+
+;; * Region Commands as Operations
+
+(defvar objed--cmd-cache nil
+  "Caching results for `objed--read-cmd'.")
+
+(defun objed--init-cmd-cache (sym)
+  "Add SYM to `objed--cmd-cache' if it is a region command."
+  (require 'help)
+  ;; don't trigger autoloads
+  (let ((spec (when (not (and (symbolp sym)
+                              (autoloadp (indirect-function sym))))
+                (cadr (interactive-form sym)))))
+    (when (or (and spec (stringp spec)
+                   (string-match "\\`\\*?r" spec))
+              (and (commandp sym)
+                   (string-match "\\`(\\(start\\|begi?n?\\) end"
+                                 (format "%s" (help-function-arglist sym t)))))
+      (push sym objed--cmd-cache))))
+
+(defun objed--read-cmd (&optional force)
+  "Completing read an operation from available region commands.
+
+Uses `objed--cmd-cache' to save previous results. If FORCE is
+non-nil, invalidate the cache.
+
+Returns symbol of choosen region command."
+  (objed--with-allow-input
+   (when (or force (not objed--cmd-cache))
+     (setq objed--cmd-cache nil)
+     (mapatoms #'objed--init-cmd-cache))
+   (intern (completing-read "Operation: " objed--cmd-cache))))
+
+
+(defun objed--create-op (f arg)
+  "Create an operation.
+
+An operation is a function which acts on an object. It recieves
+two arguments beeing the buffer positions of an object. Provided
+function F is a command or a function from which to create the
+operation function. ARG is the prefix argument to be used by the
+operation."
+  (if (commandp f)
+      (objed--create-op-from-rcmd f arg)
+    ;; try to pass arg
+    (lambda (beg end)
+      (condition-case nil
+          (funcall f beg end arg)
+        ((wrong-number-of-arguments)
+         (when arg (message "Prefix arg ignored, not supported by operation."))
+         (funcall f beg end))))))
+
+
+(defun objed--create-op-from-rcmd (rcmd &optional prefix)
+  "Create an operation from a region command.
+
+The returned function (operation) recieves two positions as
+arguments and should have the same effect on the text between
+those positions as the region command would have had on selected
+text between those positions.
+
+Any arguments of region command RCMD will be determined the same
+way as if RCMD would be called interactively and thus might query
+the user for input at first use.
+
+Because any interactive input is captured before the operation is
+used this might not work correctly when interactive input depends on
+the positional arguments of the region command.
+
+When PREFIX is given it will be used by RCMD as
+`current-prefix-arg'."
+  (let ((current-prefix-arg prefix)
+        (handler (if (fboundp #'funcall-interactively)
+                     #'funcall-interactively #'funcall))
+        (oargs (objed--eval-rspec rcmd)))
+    (lambda (beg end)
+      (save-mark-and-excursion
+       ;; in case the region commands expects an active region...
+       (goto-char beg)
+       (push-mark end t t)
+       (objed--with-allow-input
+        (apply handler rcmd beg end oargs))))))
+
+
+(defun objed--eval-rspec (rcmd)
+  "Eval the interactive spec of region command RCMD.
+
+Returns the result (skipping the positional arguments)."
+  (save-mark-and-excursion
+   ;; some commands error when evaling the interactive spec if
+   ;; there is no mark
+   (unless (marker-position (mark-marker))
+     (set-marker (mark-marker) (point)))
+   (objed--with-allow-input
+    (cddr
+     (advice-eval-interactive-spec
+      (cadr (interactive-form rcmd)))))))
+
+;; * State Info
+
+(defvar objed--last-states nil
+  "Stack of last states.
+
+See `objed--get-current-state' for details.
+
+Each state is a list of the form:
+
+    (`current-buffer', `point', variable/`objed--object',
+      `objed--current-obj', position data of the marked objects
+      if any")
+
+(defun objed--get-current-state ()
+  "Return current state data."
+  (list (current-buffer)
+       (point) objed--object
+       (objed--copy-object) objed--obj-state
+       (and objed--marked-ovs
+            (let ((os nil))
+              (dolist (ov objed--marked-ovs (nreverse os))
+                (push (cons (overlay-start ov)
+                            (overlay-end ov))
+                      os))))))
+
+(defun objed--push-state ()
+  "When using objed commands, push state to `objed--last-states'.
+
+To be used in `pre-command-hook'."
+  (unless (eq real-this-command 'objed-last)
+    (let ((curr (objed--get-current-state)))
+      (unless (equal curr (car objed--last-states))
+       (push (objed--get-current-state)
+             objed--last-states)))))
+
+
+
+(defun objed--restore-state (&optional state)
+  "Restore state STATE.
+
+STATE defaults to first of `objed--last-states'. Note that the
+state is only restored correctly if the buffer was not modified."
+  (if (and (or state (setq state (pop objed--last-states)))
+          (eq (current-buffer) (pop state)))
+      (let* ((pos (pop state))
+            (obj (pop state))
+            (range (pop state))
+            (os (pop state))
+            (ovps (pop state)))
+        (prog1 (objed--switch-to obj os range)
+         (goto-char pos)
+         ;; FIXME
+         (objed--unmark-all)
+         (when ovps
+           (objed--mark-ovps ovps))))
+    (prog1 nil
+      (message "No previous state to restore."))))
+
+
+;; * Operation definitions
+
+(defun objed-op-x (&optional arg)
+  "Choose and apply an operation from region commands with completion.
+
+With numeric prerfix ARG of 0 invalidate the used cache. Any
+other value of ARG gets passed as prefix argument to the choosen
+region command."
+  (interactive "P")
+  (let* ((rcmd (objed--read-cmd (= 0 (prefix-numeric-value arg))))
+         (cmd (objed--create-op
+               rcmd
+               (and (not (= 0 (prefix-numeric-value arg)))
+                    arg))))
+    (if objed--marked-ovs
+        (objed--ov-apply this-command cmd objed--marked-ovs)
+      (objed--ob-apply this-command  cmd (objed--current)))))
+
+(defun objed-kill ()
+  "Kill objects."
+  (interactive)
+  (objed--kill-op this-command #'kill-region t))
+
+(defun objed-delete ()
+  "Delete objects."
+  (interactive)
+  (objed--kill-op this-command #'delete-region))
+
+(defun objed-copy ()
+  "Copy objects."
+  (interactive)
+  (objed--kill-op 'ignore #'copy-region-as-kill t)
+  (message "Copied to `kill-ring.'"))
+
+
+(defvar objed--electric-event nil
+  "Saves the event used for `objed-electric'.")
+
+(defun objed-electric-pair (beg end)
+  "Wrap region between BEG, END like `electric'."
+  (let ((event (or objed--electric-event
+                  (setq objed--electric-event (read-event)))))
+    (objed-electric beg end event)))
+
+
+(defun objed-electric (beg end &optional event)
+  "Wrap region between BEG and END like `electric'.
+
+EVENT is used for wrapping according to
+`electric-pair-post-self-insert-function' and defaults to
+`last-command-event'."
+  (interactive "r")
+  (require 'elec-pair)
+  (let ((electric-pair-mode t)
+       (last-command-event (or event last-command-event))
+        (epos nil)
+       ;; make sure to go to beginning
+       (rbeg (if (> beg end) end beg))
+       (rend (if (> beg end) beg end)))
+    (save-mark-and-excursion
+     ;; skip ws optionally?
+     (push-mark (objed--skip-backward rend 'ws) t t)
+     (goto-char rbeg)
+     (objed--skip-ws)
+     (insert last-command-event)
+     (setq epos (point))
+     (electric-pair-post-self-insert-function))
+    ;; leave point like electric would for region
+    (goto-char epos)))
+
+
+(defun objed-yank (arg)
+  "Yank and indent.
+
+ARG is passed to `yank'."
+  (interactive "*P")
+  (let ((start (point)))
+    (yank arg)
+    (indent-region start (point))
+    (indent-according-to-mode)
+    (objed--update-current-object)))
+
+(defun objed-indent (beg end)
+  "Indent region between BEG and END.
+
+Moves point over any whitespace afterwards."
+  (indent-region beg end)
+  (indent-according-to-mode))
+
+(defun objed-narrow (&optional arg)
+  "Narrow to object.
+
+With prefix argument ARG call `edit-indirect-region' if
+`edit-indirect' is available."
+  (interactive "P")
+  (if objed--marked-ovs
+      (message "Narrowing not possible with multiple objects.")
+    (if (and (require 'edit-indirect nil t)
+             arg)
+        (switch-to-buffer
+         (apply #'edit-indirect-region (objed--current)))
+      (apply 'narrow-to-region (objed--current))))
+  (objed--exit-objed))
+
+
+(defvar eval-sexp-fu-flash-mode nil)
+;; adapted from lispy
+(defun objed--eval-func (beg end &optional replace)
+  "Evaluate code between BEG and END.
+
+If REPLACE is non-nil replace the region with the result."
+  (if (and (= beg (point-min))
+           (= end (point-max)))
+      (ignore-errors
+        (eval-region beg end) t)
+    (let ((p (point))
+          (eval-sexp-fu-flash-mode nil))
+      (goto-char beg)
+      (let ((e-sexp (read (current-buffer)))
+            (regionp (/= (point) end))
+            (str nil))
+        (goto-char p)
+        (when (and (consp e-sexp)
+                   (not regionp))
+          ;; treat variable and face definitions special so they can be
+          ;; redefined; ignore reader macro if included in region
+          (cond ((and (memq (car e-sexp) (list 'defvar 'defcustom 
'defvar-local))
+                      (consp (cdr e-sexp))
+                      (boundp (cadr e-sexp)))
+                 (set (cadr e-sexp) (eval (car (cddr e-sexp)))))
+                ((eq (car e-sexp) 'defface)
+                 (elisp--eval-defun-1 (macroexpand e-sexp)))
+                ((memq (car e-sexp) '(\, \,@))
+                 (setq e-sexp (cadr e-sexp)))))
+        (when (setq str (condition-case e
+                            (if regionp
+                                (progn (eval-region beg end t)
+                                       t)
+                              (prin1-to-string (eval e-sexp lexical-binding)))
+                          (error (prog1 nil
+                                   (message (error-message-string e))))))
+          (if (not (stringp str))
+              t
+            (let ((message-log-max nil))
+              (message str))
+            (if (not replace)
+                str
+              (when str
+                (delete-region beg end)
+                (insert str)))))))))
+
+
+(defun objed-eval (&optional replace)
+  "Eval objects.
+
+If REPLACE is non-nil replace evaluated code with result."
+  (interactive "P")
+  (if objed--marked-ovs
+      (save-excursion
+        (dolist (ov (nreverse (copy-sequence objed--marked-ovs)))
+          (let ((beg (overlay-start ov))
+                (end (overlay-end ov)))
+            (delete-overlay ov)
+            (when (and beg end)
+              (goto-char beg)
+              (funcall 'objed--eval-func beg end replace)))))
+    (apply 'objed--eval-func
+           (append (objed--current) (list replace))))
+  (objed--exit-objed))
+
+(defun objed-pipe-region (beg end cmd &optional variant)
+  "Pipe region text between BEG and END through a shell CMD.
+
+VARIANT is either the char r or e to either replace the text with
+the result or to echo it."
+  (interactive (let ((variant (read-char-choice "Replace [r] Echo [e] "
+                                                (list ?r ?e)))
+                     (cmd (read-shell-command "Shell command: ")))
+
+                 (list (region-beginning) (region-end)
+                       cmd
+                       variant)))
+  (let* ((cbuf (current-buffer))
+         (obuf (generate-new-buffer " *objed-pipe-out*"))
+         (args (split-string cmd " "))
+         (cmd-name (pop args))
+         (skip-nline nil)
+         (ecode (with-temp-buffer
+                  (insert-buffer-substring cbuf beg end)
+                  ;; make sure text ends with newline so
+                  ;; it get processed by command
+                  (unless (memq (char-before)
+                                (list 10 13))
+                    (setq skip-nline t)
+                    (insert "\n"))
+                  (apply 'call-process-region (point-min) (point) cmd-name
+                         nil (list obuf) nil args)))
+         (output (with-current-buffer obuf
+                   ;; dont include newline if manually added
+                   (when skip-nline
+                     (skip-chars-backward "\n"))
+                   (buffer-substring (point-min) (point)))))
+    (cond ((string= "" output)
+           (kill-buffer obuf)
+           (message
+            "Command had empty ouput. Exit code %s." ecode))
+          ((string= output
+                    (buffer-substring-no-properties
+                     (region-beginning) (region-end)))
+           (kill-buffer obuf)
+           (message
+            "Command did not change text. Exit code %s" ecode))
+          ((not (zerop ecode))
+           (pop-to-buffer obuf)
+           (message
+            "Command exited with exit code %s." ecode))
+          (t
+           (cl-case variant
+             (?r
+              (kill-buffer obuf)
+              (delete-region beg end)
+              (insert output)
+              (message "Replaced region with output."))
+             (?e
+              (pop-to-buffer obuf)))))
+    (objed--exit-objed)))
+
+(defun objed--duplicate-1 (f beg end &optional arg)
+  "Duplicate and apply F an region between BEG and END.
+
+Apply function F on region before duplicating it. ARG is passed
+to F as third argument."
+  (let* ((end (set-marker (make-marker) end))
+         (reg (buffer-substring beg end)))
+    (apply f (list beg end arg))
+    (goto-char end)
+    (if (or (eobp)
+            (= (line-number-at-pos beg)
+               (line-number-at-pos end)))
+        (newline)
+      (skip-chars-forward "\r\n" (1+ (point))))
+    (skip-chars-forward " \t")
+    (let ((pos (point)))
+      (save-excursion
+        (insert reg)
+        (indent-according-to-mode)
+        (save-excursion
+          (goto-char (objed--skip-forward pos 'ws))
+          (indent-according-to-mode))
+        (indent-region pos (point)))
+      (goto-char (objed--skip-forward pos 'ws)))))
+
+(defun objed-duplicate-down (beg end &optional arg)
+  "Duplicate region between BEG and END below.
+
+If numeric ARG is given duplicate ARG times."
+  (objed--duplicate-1 'ignore beg end arg))
+
+(defun objed-comment-duplicate (beg end &optional arg)
+  "Comment and duplicate region between BEG and END.
+
+ARG has the same meaning as for `comment-region.'"
+  (objed--duplicate-1 #'comment-region beg end arg))
+
+(defun objed-comment-or-uncomment-region (beg end &optional arg)
+  "Similar to `comment-or-uncomment-region'.
+
+Comments empty line, too. BEG, END and ARG are passed to
+`comment-or-uncomment-region'."
+  (interactive "*r\nP")
+  (if (and (eq (save-excursion (goto-char beg)
+                              (beginning-of-line))
+              (save-excursion (goto-char end)
+                              (beginning-of-line)))
+          (save-excursion
+            (beginning-of-line)
+            (looking-at "^ *$")))
+      (progn (goto-char (save-excursion (beginning-of-line)
+                                       ;; dummy so comment region does its
+                                       ;; thing
+                                       (insert "a")
+                                       (prog1 (point-marker)
+                                         (comment-or-uncomment-region beg end 
arg))))
+            (delete-char -1))
+    (comment-or-uncomment-region beg end arg)))
+
+(defun objed-replace-op (beg end str)
+  "Replace region with string read from minibuffer.
+
+Use the region between BEG and END. STR is the string to use for
+replacement."
+  (interactive
+   (let ((beg (region-beginning))
+         (end (region-end)))
+     (list beg end (read-string "Replace with: "))))
+  (delete-region beg end)
+  (insert str))
+
+
+(defun objed-case-op (beg end case)
+  "Change case of region.
+
+Use region between BEG and END. CASE is a character which
+determines the case operation:
+
+u: upcase
+d: downcase
+c: capitalize."
+  (interactive
+   (list (region-beginning)
+         (region-end)
+         (read-char-choice "Upcase [u], Downcase [d], Capitalize [c]: "
+                           (list ?u ?d ?c))))
+  (cl-case case
+    (?u
+     (upcase-region beg end))
+    (?d
+     (downcase-region beg end))
+    (?c
+     (capitalize-region beg end))))
+
+
+(defun objed-undo-op (_beg _end)
+  "Undo in current object range."
+  (interactive "r")
+  ;; region is created by `objed--create-op-from-rcmd'
+  (if (fboundp 'undo-tree-undo)
+      (undo-tree-undo '(4))
+    (undo '(4))))
+
+
+;; * OP execution
+
+
+(defun objed--ob-apply (name action range)
+  "Apply an operation on a text object.
+
+NAME is the symbol of the operation.
+
+ACTION is a function which recieves the the two buffer
+positions of the text object range.
+
+RANGE is a list of the beginning and and position of
+the text object to act on."
+  (let ((text (apply #'buffer-substring range)))
+    (apply action range)
+    (objed-exit-op name text)))
+
+(defun objed--ov-apply (name action ovs)
+  "Apply and operation to marked objects.
+
+NAME is the symbol of the operation.
+
+ACTION is a function which recieves the two buffer
+positions of a marked object range.
+
+OVS is the list of marked objects."
+  (save-excursion
+    (dolist (ov (nreverse (copy-sequence ovs)))
+      (let ((beg (overlay-start ov))
+           (end (overlay-end ov)))
+       (when (and beg end)
+         (goto-char beg)
+         (funcall action beg end))
+       (delete-overlay ov))))
+    (objed-exit-op name))
+
+
+(defun objed--kill-op (op cmd &optional append)
+  "Op execution for `kill', `copy' and `delete' operations.
+
+OP is the internally used name for the operation and CMD the function used
+for execution. If APPEND is non-nil append to ‘kill-ring’ when
+killing marked objects.
+
+Marked object sequences are merged to built a single text object."
+  (cond ((and (cdr objed--marked-ovs)
+             (objed--ov-sequence-p
+              (nreverse (copy-sequence objed--marked-ovs))))
+        ;; seqences are auto merged for convenience
+        ;; this is usually what you want
+        (objed--merge-marked)
+        (objed--ob-apply op cmd (objed--current)))
+       (objed--marked-ovs
+        (dolist (ov (nreverse (copy-sequence objed--marked-ovs)))
+          (let ((beg (overlay-start ov))
+                (end (overlay-end ov)))
+            (delete-overlay ov)
+            (when (and beg end)
+              (goto-char beg)
+              (apply cmd (list beg end)))
+            ;; append subsequent kills
+            (when append
+              (setq last-command 'kill-region))))
+          (setq objed--marked-ovs nil)
+          (objed-exit-op op))
+       (t
+        
+        ;; no marked objects
+        (objed--ob-apply op cmd (objed--current))
+        ;; for possible repeats like default conf. (kill line...)
+        (unless (eq op 'ignore)
+          (objed--change-to :beg (point)
+                            :ibeg (point)))
+        )))
+
+(defun objed--ov-sequence-p (ovs)
+  "Return non-nil if OVS build a sequence.
+
+OVS are overlays. If the overlays are only sepearated by
+whitespace they build a sequence."
+  (let ((posns nil))
+    (dolist (ov ovs)
+      (goto-char (overlay-end ov))
+      (skip-chars-forward " \t\r\n")
+      (push (point) posns))
+    ;; skip last
+    (pop posns)
+    ;; get same order
+    (setq posns (nreverse posns))
+    ;; skip first
+    (pop ovs)
+    (not
+     ;; empty if sequence...
+     (cl-remove-if
+      (lambda (ov)
+       (= (overlay-start ov)
+          (pop posns)))
+      ovs))))
+
+
+;; * Exit active state
+
+(defun objed--line-p (text)
+  "Determine how TEXT spans over lines.
+
+Return non-nil if text spans over an entire single line or
+multiple ones."
+  (with-temp-buffer
+    (insert text)
+    (not (= -1  (forward-line -1)))))
+
+(defun objed-exit-op (op &optional text)
+  "Handle exit of an operation.
+
+OP is the operation (ignored for now). If TEXT is given it
+carries the textual content of the object the operation acted
+on."
+  ;; TODO: improve exit behaviour for default operations
+  (let ((exitf (assq op objed--exit-alist)))
+    ;; (objed--update-current-object)
+    (cond (exitf
+          (funcall (cdr exitf) text))
+         ((eq op 'ignore))
+         (t
+          (if (and text (objed--line-p text))
+              (objed--switch-to 'line)
+            (objed--switch-to 'char)
+            (goto-char (objed--beg)))))))
+
+(defun objed-quit ()
+  "Quit and deactivate `objed-map'."
+  (interactive)
+  (setq mark-active nil)
+  (objed--exit-objed))
+
+(defun objed--reset ()
+  "Reset variables and state information."
+  (when objed--buffer
+    (with-current-buffer objed--buffer
+
+      (setq objed--opoint nil)
+      (setq objed--electric-event nil)
+      
+      (when objed--marked-ovs
+        (dolist (ov objed--marked-ovs)
+          (delete-overlay ov))
+        (setq objed--marked-ovs nil))
+
+      (while objed--saved-vars
+        (let ((setting (pop objed--saved-vars)))
+          (if (consp setting)
+              (set (car setting) (cdr setting))
+            (kill-local-variable setting))))
+
+      (when objed--saved-cursor
+       (set-cursor-color objed--saved-cursor))
+      
+      (when objed--hl-cookie
+       (face-remap-remove-relative objed--hl-cookie))
+
+      (when objed-modeline-hint-p
+        (funcall objed-modeline-setup-func objed-mode-line-format 'reset))
+
+      (unless objed--hl-line-keep-p
+        (hl-line-mode -1))
+
+      (when (> (length objed--last-states) objed-states-max)
+        (setq objed--last-states
+             (cl-subseq objed--last-states 0 objed-states-max)))
+
+      (setq objed--block-p nil)
+      (remove-hook 'pre-command-hook 'objed--push-state t)
+      (setq objed--buffer nil))))
+
+
+
+(provide 'objed)
+;;; objed.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]