Added package definition. master
authorplugd <plugd@thelambdalab.xyz>
Sun, 26 May 2024 19:38:38 +0000 (21:38 +0200)
committerplugd <plugd@thelambdalab.xyz>
Sun, 26 May 2024 19:38:38 +0000 (21:38 +0200)
COPYING [new file with mode: 0644]
README
lurk-pkg.el [new file with mode: 0644]
lurk.el

diff --git a/COPYING b/COPYING
new file mode 100644 (file)
index 0000000..733c072
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,675 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    {one line to give the program's name and a brief idea of what it does.}
+    Copyright (C) {year}  {name of author}
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    {project}  Copyright (C) {year}  {fullname}
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+
diff --git a/README b/README
index d074583..17c34ef 100644 (file)
--- a/README
+++ b/README
@@ -7,4 +7,11 @@ buffer.  Of course, the difficult part is in trying to ensure that the
 result remains vaguely readable...
 
 This is extremely preliminary work, and is as yet more-or-less unusable
-by anyone besides the truly dedicated.
\ No newline at end of file
+by anyone besides the truly dedicated.
+
+License
+-------
+
+Lurk is free software and is distributed under the terms of the GNU
+General Public License version 3, which can be found in the file named
+COPYING.
\ No newline at end of file
diff --git a/lurk-pkg.el b/lurk-pkg.el
new file mode 100644 (file)
index 0000000..00e9096
--- /dev/null
@@ -0,0 +1,3 @@
+(define-package "lurk" "1.0.0"
+  "The Little Unibuffer IRC Klient"
+  ((emacs "26.1")))
diff --git a/lurk.el b/lurk.el
index 1e09ee1..8114597 100644 (file)
--- a/lurk.el
+++ b/lurk.el
@@ -1,13 +1,13 @@
 ;;; lurk.el --- Little Unibuffer iRc Klient -*- lexical-binding:t -*-
 
-;; Copyright (C) 2021 Tim Vaughan
+;; Copyright (C) 2021--2024 plugd
 
-;; Author: Tim Vaughan <timv@ughan.xyz>
+;; Author: plugd <plugd@thelambdalab.xyz>
 ;; Created: 14 June 2021
-;; Version: 1.0
-;; Keywords: network
+;; Version: 2.0
 ;; Homepage: http://thelambdalab.xyz/lurk
-;; Package-Requires: ((emacs "26"))
+;; Keywords: comm
+;; Package-Requires: ((emacs "26.1"))
 
 ;; This file is not part of GNU Emacs.
 
 
 ;;; Commentary:
 
+;; A very simple IRC client which uses only a single buffer.
+
 ;;; Code:
 
 (provide 'lurk)
 
+(require 'cl-lib)
+
 
 ;;; Customizations
-;;
 
 (defgroup lurk nil
-  "Little Unibuffer iRc Klient."
+  "Multinetwork Unibuffer iRc Klient"
   :group 'network)
 
-(defcustom lurk-nick "plugd"
-  "Default nick.")
+(defcustom lurk-default-nick "plugd"
+  "Default nick."
+  :type '(string))
 
 (defcustom lurk-default-quit-msg "Bye"
-  "Default quit message when none supplied.")
+  "Default quit message when none supplied."
+  :type '(string))
 
 (defcustom lurk-networks
-  '(("libera" "irc.libera.chat" 6697))
-  "IRC networks.")
-
-(defcustom lurk-allow-ipv6 nil
-  "Set to non-nil to allow use of IPv6.")
+  '(("libera" "irc.libera.chat" 6697)
+    ("tilde" "tilde.chat" 6697)
+    ("sdf" "irc.sdf.org" 6697))
+  "IRC networks."
+  :type '(alist :key-type string))
 
 (defcustom lurk-show-joins nil
   "Set to non-nil to be notified of joins, parts and quits.")
 
 (defcustom lurk-display-header t
-  "If non-nil, use buffer header to display information on current host and channel.")
+  "If non-nil, use buffer header to display current host and channel."
+  :type '(boolean))
+
+(defcustom lurk-autoreply-table nil
+  "Table of autoreply messages.
+
+Each autoreply is a list of two elements: (matcher reply)
+
+Here matcher is a list:
+
+(network src cmd params ...)
+
+and reply is another list:
+
+ (cmd params ...)
+
+Each entry in the matcher list is a regular expression tested against the
+corresponding values in the incomming message.  Entries can be nil,
+in which case they match anything."
+  :type '(list (list) (list)))
+
 
 ;;; Faces
 ;;
 
 (defface lurk-text
   '((t :inherit default))
-  "Face used for Lurk text.")
+  "Face used for lurk text.")
 
 (defface lurk-prompt
   '((t :inherit font-lock-keyword-face))
@@ -74,7 +99,7 @@
 
 (defface lurk-faded
   '((t :inherit shadow))
-  "Face used for faded Lurk text.")
+  "Face used for faded lurk text.")
 
 (defface lurk-timestamp
   '((t :inherit shadow))
 
 (defface lurk-error
   '((t :inherit error))
-  "Face used for Lurk error text.")
+  "Face used for lurk error text.")
 
 (defface lurk-notice
   '((t :inherit warning))
-  "Face used for Lurk notice text.")
+  "Face used for lurk notice text.")
+
 
 ;;; Global variables
 ;;
 
-(defvar lurk-version "Lurk v0.1"
+(defvar lurk-version "Lurk v0.0"
   "Value of this string is used in response to CTCP version queries.")
 
 (defvar lurk-notice-prefix "-!-")
-
 (defvar lurk-error-prefix "!!!")
-
 (defvar lurk-prompt-string ">")
 
 (defvar lurk-debug nil
     nil))
 
 
-;;; Network process
+;;; Network processes
 ;;
 
-(defvar lurk-response "")
+(defvar lurk-connection-table nil
+  "An alist associating networks to connection information.
+This includes the process and the response string.")
 
-(defun lurk-filter (proc string)
-  (dolist (line (split-string (concat lurk-response string) "\n"))
-    (if (string-suffix-p "\r" line)
-        (lurk-eval-msg-string (string-trim line))
-      (setq lurk-response line))))
+(defun lurk-connection-process (network)
+  (elt (assoc network lurk-connection-table) 1))
 
-(defun lurk-sentinel (proc string)
-  (unless (equal "open" (string-trim string))
-    (lurk-display-error "Disconnected from server.")
-    (clrhash lurk-contexts)
-    (lurk-set-current-context nil)
-    (lurk-render-prompt)
-    (cancel-timer lurk-ping-timer)))
+(defun lurk-connection-nick (network)
+  (elt (assoc network lurk-connection-table) 2))
+
+(defun lurk-set-connection-nick (network nick)
+  (setf (elt (assoc network lurk-connection-table) 2) nick))
+
+(defun lurk-connection-response (network)
+  (elt (assoc network lurk-connection-table) 3))
+
+(defun lurk-set-connection-response (network string)
+  (setf (elt (assoc network lurk-connection-table) 3) string))
+
+(defun lurk-connection-new (network process nick)
+  (add-to-list 'lurk-connection-table
+               (list network process nick "")))
+
+(defun lurk-connection-remove (network)
+  (setq lurk-connection-table
+        (seq-remove (lambda (row) (equal (car row) network))
+                    lurk-connection-table)))
+
+(defun lurk-make-network-filter (network)
+  (lambda (_proc string)
+    (dolist (line (split-string (concat (lurk-connection-response network) string)
+                                "\n"))
+      (if (string-suffix-p "\r" line)
+          (lurk-eval-msg-string network (string-trim line))
+        (lurk-set-connection-response network line)))))
+
+(defun lurk-make-network-sentinel (network)
+  (lambda (_proc string)
+    (unless (equal "open" (string-trim string))
+      (lurk-display-error "Disconnected from network.")
+      (lurk-connection-remove network)
+      (lurk-remove-network-contexts network)
+      (lurk-highlight-current-context)
+      (lurk-render-prompt))))
 
 (defun lurk-start-process (network)
   (let* ((row (assoc network lurk-networks))
          (host (elt row 1))
          (port (elt row 2))
          (flags (seq-drop row 3)))
-    (make-network-process :name "lurk"
+    (make-network-process :name (concat "lurk-" network)
                           :host host
                           :service port
-                          :family (if lurk-allow-ipv6 nil 'ipv4)
-                          :filter #'lurk-filter
-                          :sentinel #'lurk-sentinel
+                          :family nil
+                          :filter (lurk-make-network-filter network)
+                          :sentinel (lurk-make-network-sentinel network)
                           :nowait nil
                           :tls-parameters (if (memq :notls flags)
                                               nil
                                                    :hostname host)))
                           :buffer "*lurk*")))
 
-(defvar lurk-ping-timer nil)
 (defvar lurk-ping-period 60)
 
-(defun lurk-ping-function ()
-  (lurk-send-msg (lurk-msg nil nil "PING" (car (process-contact (get-process "lurk")))))
-  (setq lurk-ping-timer (run-with-timer lurk-ping-period nil #'lurk-ping-function)))
+;; IDEA: Have a single ping timer which pings all connected hosts
 
 (defun lurk-connect (network)
-  (if (get-process "lurk")
-      (lurk-display-error "Already connected.  Disconnect first.")
+  (if (assoc network lurk-connection-table)
+      (lurk-display-error "Already connected to this network")
     (if (not (assoc network lurk-networks))
         (lurk-display-error "Network '" network "' is unknown.")
-      (clrhash lurk-contexts)
-      (lurk-set-current-context nil)
-      (lurk-start-process network)
-      (lurk-send-msg (lurk-msg nil nil "USER" lurk-nick 0 "*" lurk-nick))
-      (lurk-send-msg (lurk-msg nil nil "NICK" lurk-nick))
-      (setq lurk-ping-timer (run-with-timer lurk-ping-period nil #'lurk-ping-function)))))
-
-(defun lurk-connected-p ()
-  (let ((proc (get-process "lurk")))
-    (and proc (eq (process-status proc) 'open))))
-
-(defun lurk-send-msg (msg)
+      (let ((proc (lurk-start-process network)))
+        (lurk-connection-new network proc lurk-default-nick))
+      (lurk-send-msg network (lurk-msg nil nil "USER" lurk-default-nick 0 "*" lurk-default-nick))
+      (lurk-send-msg network (lurk-msg nil nil "NICK" lurk-default-nick))
+      (lurk-add-context (list network))
+      (lurk-highlight-current-context)
+      (lurk-render-prompt))))
+
+(defun lurk-send-msg (network msg)
   (if lurk-debug
       (lurk-display-string nil nil (lurk-msg->string msg)))
-  (let ((proc (get-process "lurk")))
+  (let ((proc (lurk-connection-process network)))
     (if (and proc (eq (process-status proc) 'open))
         (process-send-string proc (concat (lurk-msg->string msg) "\r\n"))
-      (lurk-display-error "No server connection established.")
-      (error "No server connection established"))))
+      (lurk-display-error "No network connection established"))))
 
 
-;;; Server messages
+;;; network messages
 ;;
 
 (defun lurk-msg (tags src cmd &rest params)
    (opt (group (+ not-newline))))
   "Regex used to parse IRC messages.
 Note that this regex is incomplete.  Noteably, we discard the non-nick
-portion of the source component of the message, as LURK doesn't use this.")
+portion of the source component of the message, as lurk doesn't use this.")
 
 (defun lurk-string->msg (string)
   (if (string-match lurk-msg-regex string)
@@ -231,13 +277,13 @@ portion of the source component of the message, as LURK doesn't use this.")
              (params-str (match-string 4 string))
              (params
               (if params-str
-                  (let* ((idx (cl-search ":" params-str))
+                  (let* ((idx (seq-position params-str ?:))
                          (l (split-string (string-trim (substring params-str 0 idx))))
                          (r (if idx (list (substring params-str (+ 1 idx))) nil)))
                     (append l r))
                 nil)))
         (apply #'lurk-msg (append (list tags src cmd) params)))
-    (error "Failed to parse string " string)))
+    (error "Failed to parse string %s" string)))
 
 (defun lurk-msg->string (msg)
   (let ((tags (lurk-msg-tags msg))
@@ -259,81 +305,152 @@ portion of the source component of the message, as LURK doesn't use this.")
 ;;; Contexts
 ;;
 
-(defvar lurk-current-context nil)
-(defvar lurk-contexts (make-hash-table :test #'equal))
-
-(defun lurk-add-context (name)
-  (puthash name nil lurk-contexts))
-
-(defun lurk-del-context (name)
-  (remhash name lurk-contexts))
-
-(defun lurk-get-context-users (name)
-  (gethash name lurk-contexts))
-
-(defun lurk-context-known-p (name)
-  (not (eq (gethash name lurk-contexts 0) 0)))
-
-(defun lurk-add-context-users (context users)
-  (puthash context
-           (cl-union users
-                     (gethash context lurk-contexts))
-           lurk-contexts))
-
-(defun lurk-del-context-user (context user)
-  (puthash context
-           (remove user (gethash context lurk-contexts))
-           lurk-contexts))
-
-(defun lurk-del-user (user)
-  (dolist (context (lurk-get-context-list))
-    (lurk-del-context-user context user)))
-
-(defun lurk-rename-user (old-nick new-nick)
-  (dolist (context (lurk-get-context-list))
-    (lurk-del-context-user context old-nick)
-    (lurk-add-context-users context (list new-nick))))
-
-(defun lurk-get-context-type (name)
-  (cond
-   ((string-prefix-p "#" name) 'channel)
-   ((string-match-p (rx (or "." "localhost")) name) 'host)
-   (t 'nick)))
-
-(defun lurk-get-context-list ()
-  (let ((res nil))
-    (maphash (lambda (key val)
-               (cl-pushnew key res))
-             lurk-contexts)
-    res))
-
-(defun lurk-get-next-context (&optional prev)
-  (if lurk-current-context
-      (let* ((context-list (if prev
-                               (reverse (lurk-get-context-list))
-                             (lurk-get-context-list)))
-             (context-list* (member lurk-current-context context-list)))
-        (if (> (length context-list*) 1)
-            (cadr context-list*)
-          (car context-list)))
+;; A context is a list (network channel) identifying the network
+;; and channel.  The tail of the list contains the nicks of users
+;; present in the channel.
+;;
+;; Each network has a special context (network) used for messages
+;; to/from the network itself.
+
+(defvar lurk-contexts nil
+  "List of currently-available contexts.
+The head of this list is always the current context.")
+
+(defun lurk-current-context ()
+  "Return the current context."
+  (if lurk-contexts
+      (car lurk-contexts)
     nil))
 
-(defun lurk-set-current-context (context)
-  (setq lurk-current-context context)
-  (lurk-highlight-context context)
-  (lurk-render-prompt)
-  (if lurk-zoomed
-      (lurk-zoom-in lurk-current-context)))
+(defun lurk-contexts-equal (c1 c2)
+  (if (lurk-network-context-p c1)
+      (and (lurk-network-context-p c2)
+           (equal (lurk-context-network c1)
+                  (lurk-context-network c2)))
+    (and (not (lurk-network-context-p c2))
+         (equal (seq-take c1 2)
+                (seq-take c2 2)))))
+
+(defun lurk-context-network (ctx)
+  (elt ctx 0))
+
+(defun lurk-context-channel (ctx)
+  (elt ctx 1))
+
+(defun lurk-network-context-p (ctx)
+  (not (cdr ctx)))
+
+(defun lurk-add-context (ctx)
+  (add-to-list 'lurk-contexts ctx))
+
+(defun lurk-remove-context (ctx)
+  (setq lurk-contexts
+        (seq-remove
+         (lambda (this-ctx)
+           (lurk-contexts-equal this-ctx ctx))
+         lurk-contexts)))
+
+(defun lurk-remove-network-contexts (network)
+  (setq lurk-contexts
+        (seq-remove (lambda (row) (equal (car row) network))
+                    lurk-contexts)))
+
+(defun lurk-context->string (ctx)
+  (concat
+   (if (lurk-network-context-p ctx)
+       ""
+     (concat (lurk-context-channel ctx) "@"))
+   (lurk-context-network ctx)))
+
+(defun lurk-string->context (string)
+  (if (not (string-prefix-p "#" string))
+      (lurk-get-context string)
+    (let* ((parts (string-split string "@"))
+           (channel (elt parts 0))
+           (network (elt parts 1)))
+      (lurk-get-context network channel))))
+
+(defun lurk-get-context (network &optional channel)
+  (if (and channel (string-prefix-p "#" channel))
+      (let ((test-ctx (list network channel)))
+        (seq-find (lambda (ctx)
+                    (equal (seq-take ctx 2) test-ctx))
+                  lurk-contexts))
+    (car (member (list network) lurk-contexts))))
+
+(defun lurk-cycle-contexts (&optional reverse)
+  (setq lurk-contexts
+        (if reverse
+            (let ((nminus1 (- (length lurk-contexts) 1)))
+              (cons
+               (elt lurk-contexts nminus1)
+               (seq-take lurk-contexts nminus1)))
+          (append (cdr lurk-contexts) (list (car lurk-contexts))))))
+
+(defun lurk-switch-to-context (ctx)
+  (setq lurk-contexts
+        (let* ((new-head (memq ctx lurk-contexts))
+               (new-tail (take (- (length lurk-contexts)
+                                  (length new-head))
+                               lurk-contexts)))
+          (append new-head new-tail))))
+
+
+;;; Context users
+;;
+
+(defvar lurk-context-users nil
+  "Association list between channel contexts and users.")
+
+(defun lurk-get-context-users (ctx)
+  (cdr (assoc ctx lurk-context-users)))
+
+(defun lurk-set-context-users (ctx users)
+  (setq lurk-context-users
+        (cons (cons ctx users) (assoc-delete-all ctx lurk-context-users))))
+
+(defun lurk-add-context-users (ctx users)
+  (lurk-set-context-users
+   ctx
+   (cl-union users (lurk-get-context-users ctx))))
+
+(defun lurk-del-context-user (ctx user)
+  (lurk-set-context-users
+   ctx
+   (delete user (lurk-get-context-users ctx))))
 
-(defun lurk-cycle-contexts (&optional rev)
-  (if lurk-current-context
-      (lurk-set-current-context (lurk-get-next-context rev))
-    (lurk-display-error "No channels joined.")))
+(defun lurk-del-all-context-users (ctx)
+  (lurk-set-context-users ctx nil))
+
+(defun lurk-del-network-user (network user)
+  (dolist (ctx lurk-contexts)
+    (if (and (equal (lurk-context-network ctx) network)
+             (not (lurk-network-context-p ctx)))
+        (lurk-del-context-user ctx user))))
+
+(defun lurk-del-all-network-users (network)
+  (dolist (ctx lurk-contexts)
+    (if (and (equal (lurk-context-network ctx) network)
+             (not (lurk-network-context-p ctx)))
+        (lurk-del-all-context-users ctx))))
+
+(defun lurk-rename-network-user (network old-nick new-nick)
+  (dolist (ctx lurk-contexts)
+    (when (and (equal (lurk-context-network ctx) network)
+               (member old-nick (lurk-get-context-users ctx)))
+      (lurk-del-context-user ctx old-nick)
+      (lurk-add-context-users ctx (list new-nick)))))
 
 
 ;;; Buffer
 ;;
 
+(defvar lurk-prompt-marker nil
+  "Marker for prompt position in lurk buffer.")
+
+(defvar lurk-input-marker nil
+  "Marker for prompt position in lurk buffer.")
+
 (defun lurk-render-prompt ()
   (with-current-buffer "*lurk*"
     (let ((update-point (= lurk-input-marker (point)))
@@ -348,9 +465,10 @@ portion of the source component of the message, as LURK doesn't use this.")
           (delete-region lurk-prompt-marker lurk-input-marker)
           (goto-char lurk-prompt-marker)
           (insert
-           (propertize (if lurk-current-context
-                           lurk-current-context
-                         "")
+           (propertize (let ((ctx (lurk-current-context)))
+                         (if ctx
+                             (lurk-context->string ctx)
+                           ""))
                        'face 'lurk-context
                        'read-only t)
            (propertize lurk-prompt-string
@@ -366,32 +484,25 @@ portion of the source component of the message, as LURK doesn't use this.")
         (if (car v)
             (set-window-point (cadr v) lurk-input-marker))))))
   
-(defvar lurk-prompt-marker nil
-  "Marker for prompt position in LURK buffer.")
-
-(defvar lurk-input-marker nil
-  "Marker for prompt position in LURK buffer.")
-
 (defun lurk-setup-header ()
   (with-current-buffer "*lurk*"
     (setq-local header-line-format
                 '((:eval
-                   (let ((proc (get-process "lurk")))
-                     (if proc
-                         (concat
-                          "Host: " (car (process-contact proc))
-                          ", Context: "
-                          (if lurk-current-context
+                   (let* ((ctx (lurk-current-context)))
+                     (if ctx
+                         (let ((network (lurk-context-network ctx)))
+                           (concat
+                            "Network: " network ", "
+                            (if (lurk-network-context-p ctx)
+                                "network"
                               (concat
-                               lurk-current-context
+                               "Channel: "
+                               (lurk-context-channel ctx)
                                " ("
                                (number-to-string
-                                (length (lurk-get-context-users lurk-current-context)))
-                               " users)")
-                            "Server"))
-                       "No connection")))
-                  (:eval
-                   (if lurk-zoomed " [ZOOMED]" ""))))))
+                                (length (lurk-get-context-users ctx)))
+                               ")"))))
+                       "No connection")))))))
 
 (defun lurk-setup-buffer ()
   (with-current-buffer (get-buffer-create "*lurk*")
@@ -404,6 +515,7 @@ portion of the source component of the message, as LURK doesn't use this.")
         (set-marker lurk-input-marker (point-max))
       (setq lurk-input-marker (point-max-marker)))
     (goto-char (point-max))
+    (lurk-highlight-current-context)
     (lurk-render-prompt)
     (if lurk-display-header
         (lurk-setup-header))))
@@ -414,6 +526,7 @@ portion of the source component of the message, as LURK doesn't use this.")
     (let ((inhibit-read-only t))
       (delete-region (point-min) lurk-prompt-marker))))
 
+
 ;;; Output formatting and highlighting
 ;;
 
@@ -435,7 +548,7 @@ portion of the source component of the message, as LURK doesn't use this.")
   "List of seen contexts and associated face lists.")
 
 (defun lurk-get-context-facelist (context)
-  (let ((facelist (gethash context lurk-context-facelists)))
+  (let* ((facelist (gethash context lurk-context-facelists)))
     (unless facelist
       (setq facelist (list 'lurk-text))
       (puthash context facelist lurk-context-facelists))
@@ -450,33 +563,6 @@ portion of the source component of the message, as LURK doesn't use this.")
       (fill-region (point-min) (point-max) nil t)
       (buffer-string))))
 
-(defun lurk--start-of-final-line ()
-  (with-current-buffer "*lurk*"
-    (save-excursion
-      (goto-char (point-max))
-      (line-beginning-position))))
-
-(defun lurk-scroll-windows-to-last-line ()
-  (with-current-buffer "*lurk*"
-    (dolist (window (get-buffer-window-list))
-      (if (>= (window-point window) (lurk--start-of-final-line))
-          (with-selected-window window
-            (recenter -1))))))
-
-(defun lurk-make-context-button (context &optional label)
-  (with-temp-buffer
-    (insert-text-button (or label context)
-                        'action #'lurk--context-button-action
-                        'follow-link t
-                        'help-echo "Switch context.")
-    (buffer-string)))
-
-(defun lurk--context-button-action (button)
-  (let ((context (button-get button 'context)))
-    (if (eq lurk-current-context context)
-        (lurk-toggle-zoom)
-      (lurk-set-current-context context))))
-
 (defun lurk-display-string (context prefix &rest strings)
   (with-current-buffer "*lurk*"
     (save-excursion
@@ -485,7 +571,10 @@ portion of the source component of the message, as LURK doesn't use this.")
              (old-pos (marker-position lurk-prompt-marker))
              (padded-timestamp (concat (format-time-string "%H:%M ")))
              (padded-prefix (if prefix (concat prefix " ") ""))
-             (context-atom (if context (intern context) nil)))
+             (context-atom (if context
+                               (intern (lurk-context->string context))
+                             nil))
+             (context-face (lurk-get-context-facelist context)))
         (insert-before-markers
          (lurk--fill-strings
           80
@@ -502,39 +591,54 @@ portion of the source component of the message, as LURK doesn't use this.")
                       'invisible context-atom)
           (lurk-add-formatting
            (propertize (concat (apply #'lurk-buttonify-urls strings) "\n")
-                       'face (lurk-get-context-facelist context)
+                       'face context-face
                        'read-only t
                        'context context
                        'invisible context-atom)))))))
   (lurk-scroll-windows-to-last-line))
 
-(defun lurk-display-message (from to text)
-  (let ((context (if (eq 'channel (lurk-get-context-type to))
-                     to
-                   (if (equal to lurk-nick) from to))))
+(defun lurk-click-context (button)
+  (lurk-switch-to-context (button-get button 'context))
+  (lurk-highlight-current-context)
+  (lurk-render-prompt)
+  (if lurk-zoomed
+      (lurk-zoom-in (lurk-current-context))))
+
+(defun lurk-make-context-button (context &optional string)
+  (with-temp-buffer
+    (let ((label (or string (lurk-context->string context))))
+      (insert-text-button label
+                          'action #'lurk-click-context
+                          'context context
+                          'follow-link t
+                          'help-echo "Switch context"))
+    (buffer-string)))
+
+(defun lurk-display-message (network from to text)
+  (let ((context (if (string-prefix-p "#" to)
+                     (lurk-get-context network to)
+                   (lurk-get-context network))))
     (lurk-display-string
      context
      (propertize
-      (pcase (lurk-get-context-type to)
-        ('channel (concat
-                   (lurk-make-context-button to)
-                   " <" from ">"))
-        ('nick (lurk-make-context-button context (concat "[" from " -> " to "]")))
-        (_
-         (error "Unsupported context type")))
+      (if (lurk-network-context-p context)
+          (concat "[" from "->" to "]")
+        (concat
+         (lurk-make-context-button context)
+         " <" from ">"))
       'face (lurk-get-context-facelist context))
      text)))
 
-(defun lurk-display-action (from to action-text)
-  (let ((context (if (eq 'channel (lurk-get-context-type to))
-                     to
-                   (if (equal to lurk-nick) from to))))
+(defun lurk-display-action (network from to action-text)
+  (let ((context (if (string-prefix-p "#" to)
+                     (lurk-get-context network to)
+                   (lurk-get-context network))))
     (lurk-display-string
      context
      (propertize
-      (concat (lurk-make-context-button context) " * " from)
+      (concat (lurk-context->string context) " *")
       'face (lurk-get-context-facelist context))
-     action-text)))
+     from " " action-text)))
 
 (defun lurk-display-notice (context &rest notices)
   (lurk-display-string
@@ -548,13 +652,14 @@ portion of the source component of the message, as LURK doesn't use this.")
    (propertize lurk-error-prefix 'face 'lurk-error)
    (apply #'concat messages)))
 
-(defun lurk-highlight-context (context)
-  (maphash
-   (lambda (this-context facelist)
-     (if (equal this-context context)
-         (setcar facelist 'lurk-text)
-       (setcar facelist 'lurk-faded)))
-   lurk-context-facelists)
+(defun lurk-highlight-current-context ()
+  (with-current-buffer "*lurk*"
+    (maphash
+     (lambda (this-context facelist)
+       (if (equal this-context (lurk-current-context))
+           (setcar facelist 'lurk-text)
+         (setcar facelist 'lurk-faded)))
+     lurk-context-facelists))
   (force-window-update "*lurk*"))
 
 (defun lurk-zoom-in (context)
@@ -562,7 +667,8 @@ portion of the source component of the message, as LURK doesn't use this.")
     (maphash
      (lambda (this-context _)
        (when this-context
-         (let ((this-context-atom (intern this-context)))
+         (let ((this-context-atom
+                (intern (lurk-context->string this-context))))
            (if (equal this-context context)
                (remove-from-invisibility-spec this-context-atom)
              (add-to-invisibility-spec this-context-atom)))))
@@ -574,21 +680,27 @@ portion of the source component of the message, as LURK doesn't use this.")
   (with-current-buffer "*lurk*"
     (maphash
      (lambda (this-context _)
-       (let ((this-context-atom (if this-context (intern this-context) nil)))
+       (let ((this-context-atom
+              (if this-context
+                  (intern (lurk-context->string this-context))
+                nil)))
          (remove-from-invisibility-spec this-context-atom)))
      lurk-context-facelists)
     (force-window-update "*lurk*"))
   (lurk-scroll-windows-to-last-line))
 
-(defun lurk-clear-context (context)
+(defun lurk--start-of-final-line ()
   (with-current-buffer "*lurk*"
     (save-excursion
-      (goto-char (point-min))
-      (let ((inhibit-read-only t)
-            (match nil))
-        (while (setq match (text-property-search-forward 'context context t))
-          (delete-region (prop-match-beginning match)
-                         (prop-match-end match)))))))
+      (goto-char (point-max))
+      (line-beginning-position))))
+
+(defun lurk-scroll-windows-to-last-line ()
+  (with-current-buffer "*lurk*"
+    (dolist (window (get-buffer-window-list))
+      (if (>= (window-point window) (lurk--start-of-final-line))
+          (with-selected-window window
+            (recenter -1))))))
 
 (defconst lurk-url-regex
   (rx (:
@@ -632,7 +744,7 @@ portion of the source component of the message, as LURK doesn't use this.")
           (strikethrough nil)
           (prev-point (point)))
       (while (re-search-forward (rx (or (any "\x02\x1D\x1F\x1E\x0F")
-                                        (: "\x03" (+ digit) (opt "," (* digit)))))
+                                        (: "\x03" (* digit) (opt "," (* digit)))))
                                 nil t)
         (let ((beg (+ (match-beginning 0) 1)))
           (if bold
@@ -662,124 +774,143 @@ portion of the source component of the message, as LURK doesn't use this.")
 ;;; Message evaluation
 ;;
 
-(defun lurk-eval-msg-string (string)
+(defun lurk-eval-msg-string (network string)
   (if lurk-debug
       (lurk-display-string nil nil string))
   (let* ((msg (lurk-string->msg string)))
-    (lurk-process-autoreplies msg)
+    (lurk-process-autoreplies network msg)
     (pcase (lurk-msg-cmd msg)
       ("PING"
-       (lurk-send-msg
+       (lurk-send-msg network
         (lurk-msg nil nil "PONG" (lurk-msg-params msg))))
 
       ("PONG")
 
-      ("001"
+      ("001" ; RPL_WELCOME
        (let* ((params (lurk-msg-params msg))
               (nick (elt params 0))
               (text (string-join (seq-drop params 1) " ")))
-         (setq lurk-nick nick)
-         (lurk-display-notice nil text)))
+         (lurk-set-connection-nick network nick)
+         (lurk-display-notice (lurk-get-context network) text))
+       (let* ((row (assoc network lurk-networks))
+              (channels (if (memq :channels row)
+                            (cdr (memq :channels row))
+                          nil)))
+         (dolist (channel channels)
+           (lurk-command-join (list channel)))))
 
       ("353" ; NAMEREPLY
        (let* ((params (lurk-msg-params msg))
               (channel (elt params 2))
-              (names (split-string (elt params 3))))
-         (if (lurk-context-known-p channel)
-             (lurk-add-context-users channel names)
-           (lurk-display-notice nil "Users in " channel ": " (string-join names " ")))))
+              (names (split-string (elt params 3)))
+              (ctx (lurk-get-context network channel)))
+         (if ctx
+             (lurk-add-context-users ctx names)
+           (lurk-display-notice ctx "Users in " channel
+                                ": " (string-join names " ")))))
 
       ("366" ; ENDOFNAMES
        (let* ((params (lurk-msg-params msg))
-              (channel (elt params 1)))
-         (if (lurk-context-known-p channel)
+              (channel (elt params 1))
+              (ctx (lurk-get-context network channel)))
+         (if ctx
              (lurk-display-notice
-              channel
-              (lurk--as-string (length (lurk-get-context-users channel)))
+              ctx
+              (lurk--as-string (length (lurk-get-context-users ctx)))
               " users in " channel)
-           (lurk-display-notice nil "End of " channel " names list."))))
+           (lurk-display-notice (lurk-get-context network)
+                                "End of " channel " names list."))))
 
-      ("331"
+      ("331" ; RPL_NOTOPIC
        (let* ((params (lurk-msg-params msg))
-              (channel (elt params 1)))
-         (lurk-display-notice
-          channel
-          "No topic set.")))
+              (channel (elt params 1))
+              (ctx (lurk-get-context network channel)))
+         (lurk-display-notice ctx "No topic set.")))
 
-      ("332"
+      ("332" ; RPL_TOPIC
        (let* ((params (lurk-msg-params msg))
               (channel (elt params 1))
-              (topic (elt params 2)))
-         (lurk-display-notice channel "Topic: " topic)))
-
-      ("333") ; Avoid displaying these
+              (topic (elt params 2))
+              (ctx (lurk-get-context network channel)))
+         (lurk-display-notice ctx "Topic: " topic)))
 
       ((rx (= 3 (any digit)))
-       (lurk-display-notice nil (mapconcat 'identity (cdr (lurk-msg-params msg)) " ")))
+       (lurk-display-notice (lurk-get-context network)
+                            (mapconcat 'identity (cdr (lurk-msg-params msg)) " ")))
 
       ((and "JOIN"
-            (guard (equal lurk-nick (lurk-msg-src msg))))
-       (let ((channel (car (lurk-msg-params msg))))
-         (lurk-add-context channel)
-         (lurk-set-current-context channel)
-         (lurk-display-notice channel "Joining channel " channel)
+            (guard (equal (lurk-connection-nick network)
+                          (lurk-msg-src msg))))
+       (let* ((channel (car (lurk-msg-params msg)))
+              (context (list network channel)))
+         (lurk-add-context context)
+         (lurk-del-all-context-users context)
+         (lurk-display-notice (lurk-current-context)
+                              "Joining channel " channel " on " network)
+         (lurk-highlight-current-context)
          (lurk-render-prompt)))
 
       ("JOIN"
-       (let ((channel (car (lurk-msg-params msg)))
-             (nick (lurk-msg-src msg)))
-         (lurk-add-context-users channel (list nick))
+       (let* ((channel (car (lurk-msg-params msg)))
+              (nick (lurk-msg-src msg))
+              (ctx (lurk-get-context network channel)))
+         (lurk-add-context-users ctx (list nick))
          (if lurk-show-joins
-             (lurk-display-notice channel nick " joined channel " channel))))
+             (lurk-display-notice ctx nick " joined channel " channel
+                                  " on " network))))
 
       ((and "PART"
-            (guard (equal lurk-nick (lurk-msg-src msg))))
-       (let ((channel (car (lurk-msg-params msg))))
-         (lurk-display-notice channel "Left channel " channel)
-         (lurk-del-context channel)
-         (if (equal channel lurk-current-context)
-             (lurk-set-current-context (lurk-get-next-context)))
+            (guard (equal (lurk-connection-nick network)
+                          (lurk-msg-src msg))))
+       (let* ((channel (car (lurk-msg-params msg)))
+              (context (list network channel)))
+         (lurk-display-notice context "Left channel " channel)
+         (lurk-remove-context context)
+         (lurk-del-all-context-users context)
+         (lurk-highlight-current-context)
          (lurk-render-prompt)))
 
       ("PART"
-       (let ((channel (car (lurk-msg-params msg)))
-             (nick (lurk-msg-src msg)))
-         (lurk-del-context-user channel nick)
+       (let* ((channel (car (lurk-msg-params msg)))
+              (nick (lurk-msg-src msg))
+              (ctx (lurk-get-context network channel)))
+         (lurk-del-context-user ctx nick)
          (if lurk-show-joins
-             (lurk-display-notice channel nick " left channel " channel))))
-
-      ((and "KICK")
-       (let ((kicker-nick (lurk-msg-src msg))
-             (channel (car (lurk-msg-params msg)))
-             (nick (cadr (lurk-msg-params msg)))
-             (reason (caddr (lurk-msg-params msg))))
-         (if (equal nick lurk-nick)
-             (progn
-               (lurk-display-notice channel kicker-nick " kicked you from " channel ": " reason)
-               (lurk-del-context channel)
-               (if (equal channel lurk-current-context)
-                   (lurk-set-current-context (lurk-get-next-context)))
-               (lurk-render-prompt))
-           (lurk-del-context-user channel nick)
-           (lurk-display-notice channel kicker-nick " kicked " nick " from " channel ": " reason))))
-
-      ("QUIT"
-       (let ((nick (lurk-msg-src msg))
-             (reason (mapconcat 'identity (lurk-msg-params msg) " ")))
-         (lurk-del-user nick)
-         (if lurk-show-joins
-             (lurk-display-notice nil nick " quit: " reason))))
+             (lurk-display-notice ctx nick " left channel " channel
+                                  " on " network))))
 
       ((and "NICK"
-            (guard (equal lurk-nick (lurk-msg-src msg))))
-       (setq lurk-nick (car (lurk-msg-params msg)))
-       (lurk-display-notice nil "Set nick to " lurk-nick))
+            (guard (equal (lurk-connection-nick network)
+                          (lurk-msg-src msg))))
+       (let ((new-nick (car (lurk-msg-params msg)))
+             (old-nick (lurk-connection-nick network)))
+         (lurk-set-connection-nick network new-nick)
+         (lurk-rename-network-user network old-nick new-nick)
+         (lurk-display-notice (lurk-get-context network)
+                              "Nick set to " new-nick " on " network)))
 
       ("NICK"
        (let ((old-nick (lurk-msg-src msg))
              (new-nick (car (lurk-msg-params msg))))
-         (lurk-display-notice nil old-nick " is now known as " new-nick)
-         (lurk-rename-user old-nick new-nick)))
+         (lurk-display-notice (lurk-get-context network)
+                              old-nick " is now known as " new-nick
+                              " on " network)
+         (lurk-rename-network-user network old-nick new-nick)))
+
+      ("TOPIC"
+       (let ((channel (car (lurk-msg-params msg)))
+             (nick (lurk-msg-src msg))
+             (topic (cadr (lurk-msg-params msg))))
+         (lurk-display-notice (lurk-get-context network channel)
+                              nick " set the topic: " topic)))
+
+      ("QUIT"
+       (let ((nick (lurk-msg-src msg))
+             (reason (mapconcat 'identity (lurk-msg-params msg) " ")))
+         (lurk-del-network-user network nick)
+         (if lurk-show-joins
+             (lurk-display-notice (lurk-get-context network)
+                                  nick " on " network " has quit: " reason))))
 
       ("NOTICE"
        (let ((nick (lurk-msg-src msg))
@@ -789,9 +920,10 @@ portion of the source component of the message, as LURK doesn't use this.")
            ((rx (: "\01VERSION "
                    (let version (* (not "\01")))
                    "\01"))
-            (lurk-display-notice nil "CTCP version reply from " nick ": " version))
+            (lurk-display-notice (lurk-get-context network)
+                                 "CTCP version reply from " nick ": " version))
            (_
-            (lurk-display-notice nil text)))))
+            (lurk-display-notice (lurk-get-context network channel) text)))))
 
       ("PRIVMSG"
        (let* ((from (lurk-msg-src msg))
@@ -801,47 +933,43 @@ portion of the source component of the message, as LURK doesn't use this.")
          (pcase text
            ("\01VERSION\01"
             (let ((version-string (concat lurk-version " - running on GNU Emacs " emacs-version)))
-              (lurk-send-msg (lurk-msg nil nil "NOTICE"
+              (lurk-send-msg network
+                             (lurk-msg nil nil "NOTICE"
                                        (list from (concat "\01VERSION "
                                                           version-string
                                                           "\01")))))
-            (lurk-display-notice nil "CTCP version request received from " from))
+            (lurk-display-notice (lurk-get-context network)
+                                 "CTCP version request received from "
+                                 from " on " network))
 
            ((rx (let ping (: "\01PING " (* (not "\01")) "\01")))
-            (lurk-send-msg (lurk-msg nil nil "NOTICE" (list from ping)))
-            (lurk-display-notice from "CTCP ping received from " from))
+            (lurk-send-msg network (lurk-msg nil nil "NOTICE" (list from ping)))
+            (lurk-display-notice (lurk-get-context network)
+                                 "CTCP ping received from " from " on " network))
 
            ("\01USERINFO\01"
-            (lurk-display-notice from "CTCP userinfo request from " from " (no response sent)"))
+            (lurk-display-notice (lurk-get-context network)
+                                 "CTCP userinfo request from " from
+                                 " on " network " (no response sent)"))
+
+           ("\01CLIENTINFO\01"
+            (lurk-display-notice (lurk-get-context network)
+                                 "CTCP clientinfo request from " from
+                                 " on " network " (no response sent)"))
 
            ((rx (: "\01ACTION " (let action-text (* (not "\01"))) "\01"))
-            (lurk-display-action from to action-text))
+            (lurk-display-action network from to action-text))
 
            (_
-            (lurk-display-message from to text)))))
+            (lurk-display-message network from to text)))))
+
       (_
-       (lurk-display-notice nil (lurk-msg->string msg))))))
+       (lurk-display-notice (lurk-get-context network)
+                            (lurk-msg->string msg))))))
 
 
 ;;; User-defined responses
-
-
-(defvar lurk-autoreply-table nil
-  "Table of autoreply messages.
-
-Each autoreply is a list of two elements: (matcher reply)
-
-Here matcher is a list:
-
-(network src cmd params ...)
-
-and reply is another list:
-
- (cmd params ...)
-
-Each entry in the matcher list is a regular expression tested against the
-corresponding values in the incomming message.  Entries can be nil,
-in which case they match anything.")
+;;
 
 (defun lurk--lists-equal (l1 l2)
     (if (and l1 l2)
@@ -851,25 +979,23 @@ in which case they match anything.")
           nil)
       t))
 
-(defun lurk-process-autoreply (msg autoreply)
+(defun lurk-process-autoreply (network msg autoreply)
   (let ((matcher (car autoreply))
         (reply (cadr autoreply)))
-    (let ((network (car matcher)))
-      (when (and (or (not network)
-                     (and (get-process "lurk")
-                          (equal (car (process-contact (get-process "lurk")))
-                                 (cadr (assoc network lurk-networks)))))
+    (let ((target-network (car matcher)))
+      (when (and (or (not target-network)
+                     (and (equal network target-network)))
                  (lurk--lists-equal (cdr matcher)
                                     (append (list (lurk-msg-src msg)
                                                   (lurk-msg-cmd msg))
                                             (lurk-msg-params msg))))
-        (lurk-send-msg
+        (lurk-send-msg network
          (lurk-msg nil nil (car reply) (cdr reply)))))))
 
-(defun lurk-process-autoreplies (msg)
+(defun lurk-process-autoreplies (network msg)
   (mapc
    (lambda (autoreply)
-     (lurk-process-autoreply msg autoreply))
+     (lurk-process-autoreply network msg autoreply))
    lurk-autoreply-table))
 
 
@@ -879,22 +1005,23 @@ in which case they match anything.")
 (defvar lurk-command-table
   '(("DEBUG" "Toggle debug mode on/off." lurk-command-debug lurk-boolean-completions)
     ("HEADER" "Toggle display of header." lurk-command-header lurk-boolean-completions)
-    ("CONNECT" "Connect to an IRC network." lurk-command-connect lurk-network-completions)
+    ("SHOWJOINS" "Toggles display of joins/parts." lurk-command-showjoins lurk-boolean-completions)
     ("NETWORKS" "List known IRC networks." lurk-command-networks)
-    ("JOIN" "Join one or more channels." lurk-command-join)
-    ("TOPIC" "Set topic for current channel." lurk-command-topic)
-    ("ME" "Display action." lurk-command-me)
-    ("VERSION" "Request version of another user's client via CTCP." lurk-command-version lurk-nick-completions)
-    ("PART" "Leave channel." lurk-command-part lurk-context-completions)
+    ("CONNECT" "Connect to an IRC network." lurk-command-connect lurk-network-completions)
     ("QUIT" "Disconnect from current network." lurk-command-quit)
+    ("JOIN" "Join one or more channels." lurk-command-join)
+    ("PART" "Leave channel." lurk-command-part lurk-channel-completions)
+    ("SWITCHCONTEXT" "Switch current context" lurk-command-switch-context lurk-context-completions)
     ("NICK" "Change nick." lurk-command-nick)
     ("LIST" "Display details of one or more channels." lurk-command-list)
-    ("WHOIS" "Ask server for details of nick." nil lurk-nick-completions)
-    ("USERS" "List nicks of users in current context." lurk-command-users)
+    ("TOPIC" "Set/query topic for current channel." lurk-command-topic)
+    ("USERS" "List nicks of users in current channel." lurk-command-users)
     ("MSG" "Send private message to user." lurk-command-msg lurk-nick-completions)
+    ("ME" "Display action." lurk-command-me)
+    ("VERSION" "Request version of another user's client via CTCP." lurk-command-version lurk-nick-completions)
     ("CLEAR" "Clear buffer text." lurk-command-clear lurk-context-completions)
     ("HELP" "Display help on client commands." lurk-command-help lurk-help-completions))
-  "Table of commands explicitly supported by Lurk.")
+  "Table of commands explicitly supported by lurk.")
 
 (defun lurk-boolean-completions ()
   '("on" "off"))
@@ -902,15 +1029,19 @@ in which case they match anything.")
 (defun lurk-network-completions ()
   (mapcar (lambda (row) (car row)) lurk-networks))
 
-(defun lurk-nick-completions ()
-  (lurk-get-context-users lurk-current-context))
-
-(defun lurk-context-completions ()
-  (lurk-get-context-list))
-
 (defun lurk-help-completions ()
   (mapcar (lambda (row) (car row)) lurk-command-table))
 
+(defun lurk-channel-completions ()
+  (mapcar (lambda (ctx)
+            (lurk-context->string ctx))
+          (seq-filter (lambda (ctx)
+                        (not (lurk-network-context-p ctx)))
+                      lurk-contexts)))
+
+(defun lurk-context-completions ()
+  (mapcar (lambda (ctx) (lurk-context->string ctx)) lurk-contexts))
+
 (defun lurk-command-help (params)
   (if params
       (let* ((cmd-str (upcase (car params)))
@@ -945,6 +1076,16 @@ in which case they match anything.")
     (setq-local header-line-format nil)
     (lurk-display-notice nil "Header disabled.")))
 
+(defun lurk-command-showjoins (params)
+  (setq lurk-show-joins 
+        (if params
+            (if (equal (upcase (car params)) "ON")
+                t
+              nil)
+          (not lurk-show-joins)))
+  (lurk-display-notice nil "Joins/parts will now be "
+                       (if lurk-show-joins "shown" "hidden") "."))
+
 (defun lurk-command-connect (params)
   (if params
       (let ((network (car params)))
@@ -952,95 +1093,140 @@ in which case they match anything.")
         (lurk-connect network))
     (lurk-display-notice nil "Usage: /connect <network>")))
 
-(defun lurk-command-networks (params)
+(defun lurk-command-networks (_params)
   (lurk-display-notice nil "Currently-known networks:")
   (dolist (row lurk-networks)
-    (seq-let (network server port &rest others) row
+    (seq-let (network network port &rest _others) row
       (lurk-display-notice nil "\t" network
-                           " [" server
+                           " [" network
                            " " (number-to-string port) "]")))
   (lurk-display-notice nil "(Modify the `lurk-networks' variable to add more.)"))
 
+(defun lurk-command-quit (params)
+  (let ((ctx (lurk-current-context)))
+    (if (not ctx)
+        (lurk-display-error "No current network")
+      (let ((quit-msg (if params (string-join params " ") lurk-default-quit-msg)))
+        (lurk-send-msg
+         (lurk-context-network ctx)
+         (lurk-msg nil nil "QUIT" quit-msg))))))
+
 (defun lurk-command-join (params)
   (if params
-      (dolist (channel params)
-        (lurk-send-msg (lurk-msg nil nil "JOIN" channel)))
+      (let ((network (lurk-context-network (lurk-current-context))))
+        (dolist (channel params)
+          (lurk-send-msg network (lurk-msg nil nil "JOIN" channel))))
     (lurk-display-notice nil "Usage: /join channel [channel2 ...]")))
 
 (defun lurk-command-part (params)
-  (let ((channel (if params (car params) lurk-current-context)))
-    (if channel
-        (lurk-send-msg (lurk-msg nil nil "PART" channel))
-      (lurk-display-error "No current channel to leave."))))
-
-(defun lurk-command-version (params)
-  (if params
-      (let ((nick (car params)))
-        (lurk-send-msg (lurk-msg nil nil "PRIVMSG"
-                                 (list nick "\01VERSION\01")))
-        (lurk-display-notice nil "CTCP version request sent to " nick))
-    (lurk-display-notice nil "Usage: /version <nick>")))
-
-(defun lurk-command-quit (params)
-  (let ((quit-msg (if params (string-join params " ") lurk-default-quit-msg)))
-    (lurk-send-msg (lurk-msg nil nil "QUIT" quit-msg))))
+  (let ((ctx (cond
+              ((not params) (lurk-current-context))
+              ((seq-contains (car params) "@") (lurk-string->context (car params)))
+              (t (list (lurk-context-network (lurk-current-context))  (car params))))))
+    (let ((network (lurk-context-network ctx))
+          (channel (lurk-context-channel ctx)))
+      (if channel
+          (lurk-send-msg network (lurk-msg nil nil "PART" channel))
+        (lurk-display-error "Specify which channel to leave")))))
+
+(defun lurk-command-switch-context (params)
+  (if (not params)
+      (lurk-display-notice nil "Usage: /switchcontext #channel@network")
+    (let ((ctx (lurk-string->context (car params))))
+      (lurk-switch-to-context ctx)
+      (lurk-highlight-current-context)
+      (lurk-render-prompt)
+      (if lurk-zoomed
+          (lurk-zoom-in (lurk-current-context))))))
 
 (defun lurk-command-nick (params)
-  (let ((new-nick (if params (string-join params " ") nil)))
-    (if new-nick
-        (if (lurk-connected-p)
-            (lurk-send-msg (lurk-msg nil nil "NICK" new-nick))
-          (setq lurk-nick nick)
-          (lurk-display-notice nil "Set default nick to '" nick "'."))
-      (lurk-display-notice nil "Current nick: " lurk-nick))))
-
-(defun lurk-command-me (params)
-  (if lurk-current-context
-      (if params
-          (let* ((action (string-join params " "))
-                 (ctcp-text (concat "\01ACTION " action "\01")))
-            (lurk-send-msg (lurk-msg nil nil "PRIVMSG"
-                                     (list lurk-current-context ctcp-text)))
-            (lurk-display-action lurk-nick lurk-current-context action))
-        (lurk-display-notice nil "Usage: /me <action>"))
-    (lurk-display-notice nil "No current channel.")))
+  (if params
+      (let ((new-nick (string-join params " "))
+            (ctx (lurk-current-context)))
+        (if ctx
+            (lurk-send-msg (lurk-context-network ctx)
+                           (lurk-msg nil nil "NICK" new-nick))
+          (lurk-display-error "No current connection")))
+    (lurk-display-notice nil "Usage: /nick <new-nick>")))
 
 (defun lurk-command-list (params)
-  (if (not params)
-      (lurk-display-notice nil "This command can generate lots of output. Use `/LIST -yes' if you really want this, or `/LIST <channel_regexp>' to reduce the output.")
-    (if (equal (upcase (car params)) "-YES")
-        (lurk-send-msg (lurk-msg nil nil "LIST"))
-      (lurk-send-msg (lurk-msg nil nil "LIST" (car params))))))
+  (let ((ctx (lurk-current-context)))
+    (if ctx
+        (if (not params)
+            (lurk-display-notice nil "This command can generate lots of output."
+                                 " Use `/LIST -yes' if you really want this,"
+                                 " or `/LIST <channel_regexp>' to reduce the output.")
+          (let ((network (lurk-context-network ctx)))
+            (if (equal (upcase (car params)) "-YES")
+                (lurk-send-msg network (lurk-msg nil nil "LIST"))
+              (lurk-send-msg network (lurk-msg nil nil "LIST"
+                                              (car params))))))
+      (lurk-display-error "No current connection"))))
 
 (defun lurk-command-topic (params)
-  (if lurk-current-context
-      (if params
-          (lurk-send-msg (lurk-msg nil nil "TOPIC" lurk-current-context (string-join params " ")))
-        (lurk-display-notice nil "Usage: /topic <new topic>"))
-    (lurk-display-notice nil "No current channel.")))
+  (let ((ctx (lurk-current-context)))
+    (if (and ctx (not (lurk-network-context-p ctx)))
+        (let ((network (lurk-context-network ctx))
+              (channel (lurk-context-channel ctx)))
+          (if params
+              (lurk-send-msg network
+                             (lurk-msg nil nil "TOPIC" channel
+                                       (string-join params " ")))
+            (lurk-send-msg network
+                           (lurk-msg nil nil "TOPIC" channel))))
+      (lurk-display-notice nil "No current channel."))))
 
 (defun lurk-command-msg (params)
-  (if (and params (>= (length params) 2))
-      (let ((to (car params))
-            (text (string-join (cdr params) " ")))
-        (lurk-send-msg (lurk-msg nil nil "PRIVMSG" to text))
-        (lurk-display-message lurk-nick to text))
-    (lurk-display-notice nil "Usage: /msg <nick> <message>")))
-
-(defun lurk-command-clear (params)
-  (if (not params)
-      (lurk-clear-buffer)
-    (dolist (context params)
-      (lurk-clear-context context))))
+  (let ((network (lurk-context-network (lurk-current-context))))
+    (if (and params (>= (length params) 2))
+        (let ((to (car params))
+              (text (string-join (cdr params) " ")))
+          (lurk-send-msg network (lurk-msg nil nil "PRIVMSG" to text))
+          (lurk-display-message network
+                                (lurk-connection-nick network)
+                                to text))
+      (lurk-display-notice nil "Usage: /msg <nick> <message>"))))
+
+(defun lurk-command-me (params)
+  (let* ((ctx (lurk-current-context))
+         (network (lurk-context-network ctx)))
+    (if (and ctx (not (lurk-network-context-p ctx)))
+        (if params
+            (let* ((channel (lurk-context-channel ctx))
+                   (my-nick (lurk-connection-nick network))
+                   (action (string-join params " "))
+                   (ctcp-text (concat "\01ACTION " action "\01")))
+              (lurk-send-msg network
+                             (lurk-msg nil nil "PRIVMSG"
+                                       (list channel ctcp-text)))
+              (lurk-display-action network my-nick channel action))
+          (lurk-display-notice nil "Usage: /me <action>"))
+      (lurk-display-notice nil "No current channel."))))
+
+(defun lurk-command-version (params)
+  (let ((ctx (lurk-current-context)))
+    (if ctx
+        (if params
+            (let ((network (lurk-context-network ctx))
+                  (nick (car params)))
+              (lurk-send-msg network
+                             (lurk-msg nil nil "PRIVMSG"
+                                       (list nick "\01VERSION\01")))
+              (lurk-display-notice ctx "CTCP version request sent to "
+                                   nick " on " network))
+          (lurk-display-notice ctx "Usage: /version <nick>"))
+      (lurk-display-notice nil "No current channel."))))
+
+(defun lurk-command-users (_params)
+  (let ((ctx (lurk-current-context)))
+    (if (and ctx (not (lurk-network-context-p ctx)))
+        (let ((channel (lurk-context-channel ctx))
+              (network (lurk-context-network ctx))
+              (users (lurk-get-context-users ctx)))
+          (lurk-display-notice ctx "Users in " channel " on " network ":")
+          (lurk-display-notice ctx (string-join users " ")))
+      (lurk-display-notice nil "No current channel."))))
 
-(defun lurk-command-users (params)
-  (if lurk-current-context
-      (progn
-        (lurk-display-notice lurk-current-context "Users in " lurk-current-context ":")
-        (lurk-display-notice
-         lurk-current-context
-         (string-join (lurk-get-context-users lurk-current-context) " ")))
-    (lurk-display-notice nil "No current channel.")))
 
 ;;; Command entering
 ;;
@@ -1058,17 +1244,24 @@ in which case they match anything.")
                          nil)))
            (if (and command-row (elt command-row 2))
                (funcall (elt command-row 2) params)
-             (lurk-send-msg (lurk-msg nil nil (upcase cmd-str) params)))))
+             (lurk-send-msg
+              (lurk-context-network (lurk-current-context))
+              (lurk-msg nil nil (upcase cmd-str) params)))))
         (_
-         (lurk-display-error "Badly formed command.")))
+         (lurk-display-error "Badly formed command")))
     (unless (string-empty-p string)
-      (if lurk-current-context
-          (progn
-            (lurk-send-msg (lurk-msg nil nil "PRIVMSG"
-                                     lurk-current-context
-                                     string))
-            (lurk-display-message lurk-nick lurk-current-context string))
-        (lurk-display-error "No current context.")))))
+      (let ((ctx (lurk-current-context)))
+        (if ctx
+            (if (not (lurk-network-context-p ctx))
+                (let ((network (lurk-context-network ctx))
+                      (channel (lurk-context-channel ctx)))
+                  (lurk-send-msg network
+                                 (lurk-msg nil nil "PRIVMSG" channel string))
+                  (lurk-display-message network
+                                        (lurk-connection-nick network)
+                                        channel string))
+              (lurk-display-error "No current channel"))
+          (lurk-display-error "No current context"))))))
 
 
 ;;; Command history
@@ -1092,16 +1285,43 @@ in which case they match anything.")
       (insert (elt lurk-history lurk-history-index)))))
 
 
-;;; Interactive functions
+;;; Interactive commands
 ;;
 
+(defun lurk-enter ()
+  "Enter current contents of line after prompt."
+  (interactive)
+  (with-current-buffer "*lurk*"
+    (let ((line (buffer-substring lurk-input-marker (point-max))))
+      (push line lurk-history)
+      (setq lurk-history-index nil)
+      (let ((inhibit-read-only t))
+        (delete-region lurk-input-marker (point-max)))
+      (lurk-enter-string line))))
+
+(defun lurk-history-next ()
+  (interactive)
+  (lurk-history-cycle -1))
+
+(defun lurk-history-prev ()
+  (interactive)
+  (lurk-history-cycle +1))
+
 (defun lurk-cycle-contexts-forward ()
   (interactive)
-  (lurk-cycle-contexts))
+  (lurk-cycle-contexts)
+  (lurk-highlight-current-context)
+  (lurk-render-prompt)
+  (if lurk-zoomed
+      (lurk-zoom-in (lurk-current-context))))
 
 (defun lurk-cycle-contexts-reverse ()
   (interactive)
-  (lurk-cycle-contexts t))
+  (lurk-cycle-contexts t)
+  (lurk-highlight-current-context)
+  (lurk-render-prompt)
+  (if lurk-zoomed
+      (lurk-zoom-in (lurk-current-context))))
 
 (defvar lurk-zoomed nil
   "Keeps track of zoom status.")
@@ -1110,16 +1330,9 @@ in which case they match anything.")
   (interactive)
   (if lurk-zoomed
       (lurk-zoom-out)
-    (lurk-zoom-in lurk-current-context))
+    (lurk-zoom-in (lurk-current-context)))
   (setq lurk-zoomed (not lurk-zoomed)))
 
-(defun lurk-history-next ()
-  (interactive)
-  (lurk-history-cycle -1))
-
-(defun lurk-history-prev ()
-  (interactive)
-  (lurk-history-cycle +1))
 
 (defun lurk-complete-input ()
   (interactive)
@@ -1145,24 +1358,12 @@ in which case they match anything.")
                              (re-search-backward " " lurk-input-marker t)))
                 (start (if space-idx (+ 1 space-idx) lurk-input-marker)))
            (unless (string-prefix-p "/" (buffer-substring start end))
-             (let* ((users (lurk-get-context-users lurk-current-context))
+             (let* ((users (lurk-get-context-users (lurk-current-context)))
                     (users-no@ (mapcar
                                 (lambda (u) (car (split-string u "@" t)))
                                 users)))
                (completion-in-region start end users-no@)))))))))
 
-(defun lurk-enter ()
-  "Enter current contents of line after prompt."
-  (interactive)
-  (with-current-buffer "*lurk*"
-    (let ((line (buffer-substring lurk-input-marker (point-max))))
-      (push line lurk-history)
-      (setq lurk-history-index nil)
-      (let ((inhibit-read-only t))
-        (delete-region lurk-input-marker (point-max)))
-      (lurk-enter-string line))))
-
-
 ;;; Mode
 ;;
 
@@ -1171,37 +1372,34 @@ in which case they match anything.")
     (define-key map (kbd "RET") 'lurk-enter)
     (define-key map (kbd "TAB") 'lurk-complete-input)
     (define-key map (kbd "C-c C-z") 'lurk-toggle-zoom)
-    (define-key map (kbd "<C-tab>") 'lurk-cycle-contexts-forward)
-    (define-key map (kbd "<C-S-tab>") 'lurk-cycle-contexts-reverse)
     (define-key map (kbd "<C-up>") 'lurk-history-prev)
     (define-key map (kbd "<C-down>") 'lurk-history-next)
+    (define-key map (kbd "<C-tab>") 'lurk-cycle-contexts-forward)
+    (define-key map (kbd "<C-S-iso-lefttab>") 'lurk-cycle-contexts-reverse)
+    (define-key map (kbd "<C-S-tab>") 'lurk-cycle-contexts-reverse)
     (when (fboundp 'evil-define-key*)
       (evil-define-key* 'motion map
         (kbd "TAB") 'lurk-complete-input))
     map))
 
 (define-derived-mode lurk-mode text-mode "lurk"
-  "Major mode for LURK.")
+  "Major mode for lurk.")
 
 (when (fboundp 'evil-set-initial-state)
   (evil-set-initial-state 'lurk-mode 'insert))
 
-
 ;;; Main start procedure
 ;;
 
-(defun lurk (&optional network)
-  "Start lurk or just switch to the lurk buffer if one already exists.
-Also connect to NETWORK if non-nil."
+;;;###autoload
+(defun lurk ()
+  "Start lurk or just switch to the lurk buffer if one already exists."
   (interactive)
   (if (get-buffer "*lurk*")
       (switch-to-buffer "*lurk*")
     (switch-to-buffer "*lurk*")
     (lurk-mode)
-    (lurk-setup-buffer)
-    (if network
-        (lurk-command-connect (list network))))
-  "Started LURK.")
-
+    (lurk-setup-buffer))
+  "Started lurk.")
 
 ;;; lurk.el ends here