Full Code of noctuid/link-hint.el for AI

master 8fda5dcb9caf cached
3 files
106.2 KB
26.1k tokens
1 requests
Download .txt
Repository: noctuid/link-hint.el
Branch: master
Commit: 8fda5dcb9caf
Files: 3
Total size: 106.2 KB

Directory structure:
gitextract_gbwr8qn6/

├── LICENSE
├── README.org
└── link-hint.el

================================================
FILE CONTENTS
================================================

================================================
FILE: LICENSE
================================================
                    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>.



================================================
FILE: README.org
================================================
[[http://melpa.org/#/link-hint][file:http://melpa.org/packages/link-hint-badge.svg]]

* Demonstration
Using this package to install this package:
[[http://noctuid.github.io/link-hint.el/assets/paradox_demonstration.gif][http://noctuid.github.io/link-hint.el/assets/paradox_demonstration.gif]]

* About
=link-hint.el= is inspired by the link hinting functionality in vim-like browsers and browser plugins such as pentadactyl. It provides commands for using avy to open, copy, or take a user-defined action on "links."

Currently the following types of links are supported:

- Plain text urls (e.g. =http://github.com=; includes irc urls and mailto)
- File paths
- Shr urls (e.g. elfeed links, links in html mu4e and gnus messages, eww urls, etc.)
- Org mode urls (includes =mailto:= links)
- Markdown links (including "wiki links"; see =markdown-enable-wiki-links=)
- Mu4e links (urls and mailto addresses)
- Mu4e attachments
- Gnus html mail rendered with gnus-w3m or emacs-w3m (instead of shr)
- Help mode links
- Info mode links
- Package menu links (describe package, install package, keyword buttons, etc.)
- Compilation mode links
- W3m links (urls, email addresses, etc.)
- Customize links
- Nov.el links
- notmuch-hello links
- Deadgrep matches
- Other button links (e.g. WoMan/Man/Dictionary links, ag mode, epa-key-list-mode, etc.)
- Completion List candidates (better put it before /link-hint-file-link/ for *project.el*)
- Dired filenames
- Org Agenda items
- Xref items
- Bug reference mode links

Feel free to request support for any useful link type I may have missed. Also, if you think it would be beneficial to have a more specific link type split from a more generic link type, feel free to make an issue. For example, there may be some specific type of button you want to ignore or use in a custom command without affecting other buttons.

** Similar
*** Ace-link
There is also [[https://github.com/abo-abo/ace-link][ace-link]] which I didn't know about when writing this package. The main functional differences at the time of writing are as follows:

- link-hint supports more link types
- link-hint supports operating on multiple different types of links with the same command in the same buffer; types are optionally tied to major modes, but generic link support is also provided (e.g. buttons and file paths)
- link-hint supports easily adding more link types and actions
- link-hint supports operating on multiple links at a time

*** Embark
There is some overlap with embark since both packages provide multiple actions for different types of things.  Here is a comparison:

- Link-hint is mainly focused on links/buttons rather than types of =completing-reading= candidates
- Link-hint is more focused on selecting links anywhere visible using avy
- Both embark and link-hint can take different actions on different types of things at the point in a buffer; link-hint can actually fall back to using =embark-dwim= (see [[#at-point-fallback-commands][At Point Fallback Commands]])
- If there is interest, link-hint can provide better integration with embark (provide feedback on issue #38 if interested)
  - Add completing-read support (with support for choosing an action with embark or running =embark-collect=)
  - Add a builtin link-hint action that just calls =embark-act= on the link position

** Basic Setup
Basic usage of this package only requires making key bindings for ~link-hint-open-link~ or other commands. Here is an example configuration using [[https://github.com/jwiegley/use-package][use-package]]:
#+begin_src emacs-lisp
(use-package link-hint
  :ensure t
  :bind
  ("C-c l o" . link-hint-open-link)
  ("C-c l c" . link-hint-copy-link))
#+end_src

Here is an example configuration for evil:
#+begin_src emacs-lisp
(use-package link-hint
  :ensure t
  :defer t)

(define-key evil-normal-state-map (kbd "SPC f") 'link-hint-open-link)
#+end_src

** Browser Choice
~browse-url~ is used for opening urls, so in the case that the desired browser is not being used by default, the user can set ~browse-url-browser-function~:

#+begin_src emacs-lisp
;; Use chromium to open urls
(setq browse-url-browser-function 'browse-url-chromium)

;; Use firefox to open urls
(setq browse-url-browser-function 'browse-url-firefox)

;; Use qutebrowser to open urls
(setq browse-url-browser-function 'browse-url-generic)
(setq browse-url-generic-program "qutebrowser")
;; Open urls in a new tab instead of window; can also be set in the config file
(setq browse-url-generic-args '("--target" "tab"))
#+end_src

** Provided Commands
This package provides the following commands for operating on links:
- ~link-hint-open-link-at-point~ - Open the link at point.
- ~link-hint-copy-link-at-point~ - Copy the link at point to the kill ring (and optionally to the clipboard/primary).
- ~link-hint-open-link~ - Use avy to select and open a single visible link. If only one link is currently visible, it will be automatically opened without the need for selection.
- ~link-hint-open-multiple-links~ - Use avy to select multiple visible links and open them as soon as a key that does not correspond to a link (a key not in the avy overlay) is pressed (like pentadactyl's =g;=).
- ~link-hint-open-all-links~ - Opens all links visible in the buffer.
- ~link-hint-copy-link~ - Use avy to select and copy a single visible link to the kill ring. ~select-enable-clipboard~ and ~select-enable-clipboard~ can each be set to a non-nil value to also use the clipboard and/or primary.

~link-hint-copy-multiple-links~ and ~link-hint-copy-all-links~ also exist, but they may not be useful very often.

This package does not bind any commands by default.

** At Point Fallback Commands
:PROPERTIES:
:CUSTOM_ID: at-point-fallback-commands
:END:

While the main purpose of link-hint is remote link selection with avy, it does provide commands to operate on a link at point (since it already has the necessary code to do so).  =link-hint-open-link-at-point=, for example, can be used as a sort of global "act on the point" command.  If there is not a link at the point, you can make it fall back to another command by setting =link-hint-action-fallback-commands=.  Some potentially useful fallback commands would be =embark-dwim= and =action-key= (hyperbole).

To still get the "no links found" error message when nothing happens, fallback command should return nil if it also fails to do anything.
#+begin_src emacs-lisp
(setq link-hint-action-fallback-commands
      (list :open (lambda ()
                    (condition-case _
                        (progn
                          (embark-dwim)
                          t)
                      (error
                       nil)))))
#+end_src

Here is a more complex example that will try to jump to the definition in programming modes where possible before falling back to hyperbole.  If you want something like this, you will probably need to tweak this rather than use it as-is.
#+begin_src emacs-lisp
(defun noct-open ()
  "Open the thing at point.
Try with lsp or smart jump (if in a prog-mode buffer) then with hyperbole."
  (interactive)
  (or (when (derived-mode-p 'prog-mode)
        (cond ((bound-and-true-p lsp-mode)
               (not (stringp (lsp-find-definition))))
              ((fboundp 'smart-jump-go)
               ;; return nil instead of prompting when there is no definition
               ;; at point
               (cl-letf (((symbol-function 'xref--prompt-p) #'ignore))
                 (smart-jump-go)))))
      (when (fboundp 'action-key)
        (action-key))))

(setq link-hint-action-fallback-commands (list :open #'noct-open))
#+end_src

** Overriding Avy Settings
=link-hint.el= supports overriding avy's settings. For example, if you want to use a different avy style just for link hinting, you can set ~link-hint-avy-style~:

#+begin_src emacs-lisp
(setq link-hint-avy-style 'pre)
#+end_src

This will cause the overlays to be displayed before the links (and not cover them). Note that using the =post= style will not put the overlay at the end of links. I don't think this style makes much sense for links, but feel free to open an issue if you would like this style to be supported.

Here is the full list of settings:
- =link-hint-avy-style=
- =link-hint-avy-keys=
- =link-hint-avy-all-windows=
- =link-hint-avy-all-windows-alt=
- =link-hint-avy-background=
- =link-hint-avy-ignored-modes=

By default, these variables are not bound, and avy's corresponding settings are used. =avy-styles-alist= and =avy-keys-alist= are also supported for the provided commands (as well as ~avy-resume~).

** Messaging
By default, link-hint will print a message in the echo area when an action is performed. =link-hint-message= can be set to =nil= to disable this behavior. It can also be set to a custom message function such as ~lv-message~.

=link-hint-action-messages= is a plist that is used for the default description of each action keyword (e.g. =:open "Opened"=).

** Point/Window Restoration
Link hint will move the point (and sometimes the window; see =avy-all-windows=) when acting on a link. When =link-hint-restore= is a non-nil value, link-hint will automatically restore the point and window when the link action does not intentionally change the point/window. For example, if =link-hint-avy-all-windows= is a non-nil value, and the user copies a link in a different window, the point will stay the same in the buffer containing the link, and the selected window will stay the same. On the other hand, if the user opens a url in ~eww~ in a new window, the ~eww~ window will be selected, but the point in the link buffer will be restored. Similarly, if the user opens an org link to a local (same buffer) heading, the point and window will not be restored.

** Defining New Link Types and Actions
~link-hint-define-type~ is the helper function used to define new link types. ~link-hint-define-type~ is just simple helper to alter the symbol plist of =link-hint-<type>= (though it is recommended to use it directly in case the implementation changes). For example, here is how =shr-url= could be defined if it did not already exist:
#+begin_src emacs-lisp
(link-hint-define-type 'shr-url
  :next #'link-hint--next-shr-url
  :at-point-p #'link-hint--shr-url-at-point-p
  :open #'browse-url
  :copy #'kill-new)

(push 'link-hint-shr-url link-hint-types)
#+end_src

All link hint types are defined in this way, so see the source code for more examples.

*** Mandatory Keywords
=:next=
- should be a function that returns the position of the next link /after/ the point (i.e. if there is a link at the point, it should not return the point)
- should not move the point (wrap your code in ~save-excursion~ if you move the point)
- arglist: =(bound)= - one argument for the end bound for searching

=:at-point-p=
- should be a function that returns a non-nil value if there is a link at the point
- its return value can be used in the action functions
- arglist: =()= - not passed any arguments

*** Predicate Keywords
These keywords are used to determine when a type is active. If these keywords are specified, link-hint will only check for the link type if the buffer meets the requirements. These are not strictly necessary but can be used, for example, to help performance (this is usually not an issue except for "overlay button" links currently - woman buttons, dictionary mode buttons, etc.).

=:predicates= should be a list of functions that should each return true if the link type passes/is valid in the current buffer.

=:vars= should be a list of variables and/or major modes. If at least one of them is bound and true or the current major mode, the link type passes.

=:not-vars= should be a list of variables and/or major modes. If any of them are bound and true or the current major mode, the link type does not pass.

All of these checks must pass for the link type to be considered active. It is also possible to create commands that only operate on specific link types by binding =link-hint-types= (e.g. ~(let ((link-hint-types ...)))~).

*** Action Keywords
The main actions supported by default are =:open= and =:copy=. Custom action keywords can have any name not already used by link-hint, but you may want to give your keywords some unique prefix to ensure they do not clash in case link-hint adds new action types (e.g. =:my-<action>=).

=:<action>= (e.g. =:open=)
- should be function that will perform an action on a link (e.g. open it in the case of =:open=)
- arglist: =(<at-point-p return list item 1> <at-point-p return list item 2> ...)= or =(<at-point-p return value as single argument>)= or =()=; the function is not required to take a specific number of arguments
  - if you want to use information obtained in the =:at-point-p= call, you can give the action implementation function a non-empty arglist
    - if the =:at-point-p= function returns a list, you can use multiple arguments (one for each item in the list)
    - if your =:at-point-p= function returns a single value, you should use a single argument, e.g. the text-url link type's =:at-point-p= function returns the url to open as a string, so the =:open= function can just be ~browse-url~ (which takes a url as an argument)
  - if you use an empty arglist, the function should operate at the link at point

Link types are not required to support all action keywords. If a link type does not support a particular action keyword, it will just be ignored for that action.

*** Action Modifier Keywords
=:parse= should be a function that takes two arguments: the return value of the link type's =:at-point-p= function and the action keyword. It should return a valid input for the action function. This can be useful, for example, if the =at-point-p= function returns a plist, struct, etc. and each action function only needs part of it (see the definition of =package-link= for a concrete example).

=:<action>-multiple= should be a boolean value corresponding to whether it makes sense to perform the action on multiple links in a row.

=:<action>-message= should be a string that will be used instead of the normal message string. For example, =:open-message "Installed"= is specified for the =package-install-link= type.

=:describe= should be a function that returns a string representation of the link to be used when messaging. If not set, the return value of the =:at-point-p= function is used directly.

** Creating New Commands
The user can create new commands to do something other than copy or open a link using the ~link-hint--one~, ~link-hint--multiple~, and ~link-hint--all~ helper functions. Each takes a single action keyword as an argument.

Here is an example of adding a command that downloads a url:
#+begin_src emacs-lisp
;; `link-hint-define-type' can be used to add new keywords
(link-hint-define-type 'text-url
  :download #'w3m-download)

(link-hint-define-type 'w3m-link
  :download #'w3m-download)

...

(defun link-hint-download-link ()
  "Use avy to select and download a text URL with download-region.el."
  (interactive)
  (avy-with link-hint-download-link
    (link-hint--one :download)))
#+end_src

** Using for Links in Terminal with Tmux
This may seem like a strange use for this package, but I've been doing this due to lack of a better alternative. Unfortunately, most of the methods for generically opening urls in a terminal running tmux (e.g. urlscan, urlview, w3m, terminal keybindings, tmux-urlview, and tmux-open) aren't very quick or customizable. [[https://github.com/tmux/tmux][tmux-fingers]] looks more promising but currently only supports copying, doesn't allow for customizable hint keys, and is slow for me.

I've started using this keybinding on the rare occasion that I need to open a url from somewhere other than emacs:
#+begin_src shell
bind-key f capture-pane \; save-buffer /tmp/tmux-buffer \; \
	new-window 'emacsclient -t -e "(find-file \"/tmp/tmux-buffer\")" -e "(goto-address-mode)" -e "(link-hint-open-link)" -e "(kill-this-buffer)" -e "(delete-frame)"'
#+end_src

I kill the buffer to ensure that emacs won't prompt to revert the file on later invocations in the case that auto-revert-mode is off.

One downside (shared by most other methods) is that it may be a bit disorienting to have the positions of links moved when opening a new tmux window. In this regard, having link-opening functionality directly in a terminal is nice.



================================================
FILE: link-hint.el
================================================
;;; link-hint.el --- Use avy to open, copy, etc. visible links -*- lexical-binding: t -*-

;; Author: Fox Kiester <noct@posteo.net>
;; URL: https://github.com/noctuid/link-hint.el
;; Keywords: convenience url avy link links hyperlink
;; Package-Requires: ((avy "0.4.0") (emacs "24.4"))
;; Version: 0.1

;; This file is not part of GNU Emacs.

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:
;; This packages provides commands for operating on visible links with avy. It
;; is inspired by link hinting from vim-like browsers and browser plugins such
;; as pentadactyl. For example, `link-hint-open-link' will use avy to select and
;; open a visible link. A link is not limited to a url but can also be a file
;; link, button, org link, info link, help link, mu4e attachment, mailto
;; address, etc. Commands are also provided for copying links to the kill ring
;; (and optionally the clipboard and/or primary) and for opening multiple links
;; at once like with pentadactyl's "g;" or qutebrowser's "--rapid" flag. It is
;; possible for the user to add both new link types and new link actions.

;; For more information, see the link-hint.el README/documentation.

;;; Code:
(require 'cl-lib)
(require 'avy)
(require 'thingatpt)
(require 'browse-url)
(require 'goto-addr)
(require 'ffap)
(require 'rx)

;; * Options
(defgroup link-hint nil
  "Provides commands for operating on visible links with avy."
  :group 'convenience
  :prefix "link-hint-")

(defcustom link-hint-types
  '(link-hint-shr-url
    ;; mode specific
    link-hint-org-link
    link-hint-markdown-link
    link-hint-mu4e-url
    link-hint-mu4e-attachment
    link-hint-gnus-w3m-url
    link-hint-gnus-w3m-image-url
    link-hint-deadgrep
    link-hint-help-link
    link-hint-info-link
    link-hint-overlay-button
    link-hint-package-link
    link-hint-package-keyword-link
    link-hint-package-install-link
    link-hint-epkg-button
    link-hint-compilation-link
    link-hint-w3m-link
    link-hint-w3m-message-link
    link-hint-treemacs
    link-hint-nov-link
    link-hint-customize-widget
    link-hint-notmuch-hello
    link-hint-completion-list-candidate
    link-hint-dired-filename
    link-hint-org-agenda-item
    link-hint-xref-item
    link-hint-bug-reference
    ;; generic
    link-hint-button
    link-hint-text-url
    link-hint-file-link)
  "Link types to check for."
  :type '(repeat :tag "Types"
                 (choice
                  (const :tag "Button" link-hint-button)
                  (const :tag "Completion List" link-hint-completion-list-candidate)
                  (const :tag "Compilation Link" link-hint-compilation-link)
                  (const :tag "Customize Widget" link-hint-customize-widget)
                  (const :tag "Deadgrep" link-hint-deadgrep)
                  (const :tag "Dired filename" link-hint-dired-filename)
                  (const :tag "Epkg Button" link-hint-epkg-button)
                  (const :tag "File Link" link-hint-file-link)
                  (const :tag "Gnus W3m Image Url" link-hint-gnus-w3m-image-url)
                  (const :tag "Gnus W3m Url" link-hint-gnus-w3m-url)
                  (const :tag "Help Link" link-hint-help-link)
                  (const :tag "Info Link" link-hint-info-link)
                  (const :tag "Markdown Link" link-hint-markdown-link)
                  (const :tag "Mu4e Attachment" link-hint-mu4e-attachment)
                  (const :tag "Mu4e Url" link-hint-mu4e-url)
                  (const :tag "Notmuch Hello" link-hint-notmuch-hello)
                  (const :tag "Nov Link" link-hint-nov-link)
                  (const :tag "Org Agenda" link-hint-org-agenda-item)
                  (const :tag "Org Link" link-hint-org-link)
                  (const :tag "Overlay Button" link-hint-overlay-button)
                  (const :tag "Package Install Link" link-hint-package-install-link)
                  (const :tag "Package Keyword Link" link-hint-package-keyword-link)
                  (const :tag "Package Link" link-hint-package-link)
                  (const :tag "Shr Url" link-hint-shr-url)
                  (const :tag "Text Url" link-hint-text-url)
                  (const :tag "Treemacs" link-hint-treemacs)
                  (const :tag "W3m Link" link-hint-w3m-link)
                  (const :tag "W3m Message Link" link-hint-w3m-message-link)
                  (const :tag "Xref Item" link-hint-xref-item)
                  (const :tag "Bug Reference" link-hint-bug-reference)
                  (symbol :tag "Custom Type"))))

(defcustom link-hint-action-fallback-commands nil
  "Plist of action to fallback command pairs.
If no link is detected at point when running an at-point command like
`link-hint-open-link-at-point', check this plist and run the fallback command
instead if any is matched.  For example, set this to (list :open #'<command>)
where <command> is something like `embark-dwim', `action-key' (hyperbole), or
`smart-jump-go' (e.g. conditionally in a `prog-mode' buffer).  See the
documentation for a more complex example.  To still get a message that there is
no supported link at point on failure, the fallback command should return nil if
they also don't find anything."
  :type '(plist
          :key-type (sexp :tag "Action")
          :value-type (function :tag "Fallback command")))

(defcustom link-hint-action-messages
  (list :copy "Copied"
        :open "Opened"
        :browse-url "Browsed")
  "Plist of action to description message pairs."
  :type '(plist :options ((:copy (string :tag "Copy" :value "Copied"))
                          (:open (string :tag "Open" :value "Opened"))
                          (:browse-url (string :tag "Browse Url" :value "Browsed")))
                :key-type (sexp :tag "Action")
                :value-type (string :tag "Description")))

(defcustom link-hint-message #'message
  "The function to use to message information or nil."
  :type '(choice
          (const :tag "Don't message" nil)
          (function-item :tag "Message" message)
          (function :tag "Custom function")))

(defcustom link-hint-url-regexp
  goto-address-url-regexp
  "Regexp used to determine what constitutes a text url.
Defaults to `goto-address-url-regxp'.

This is used for searching for urls and checking if there is a match at point,
but the regexp only needs to match the beginning of the url. `thingatpt' is used
to obtain the full url.

Note that this is used for text urls only in modes that don't have some
mechanism for supporting urls. This won't affect link-hint's behavior in
`org-mode' or modes that use shr.el for urls, for example."
  :type 'regexp)

(defcustom link-hint-maybe-file-regexp
  (rx (or bol blank) (zero-or-one (or "~" (seq (char alpha) ":"))) "/" (1+ not-newline))
  "Regexp used to determine what constitutes a potential file link."
  :type 'regexp)

(defcustom link-hint-delete-trailing-paren t
  "Whether to delete a ) at the end of a url.
This is a workaround for Emacs libraries including unwanted parens in urls.
See issue #15 for more information."
  :type 'boolean)

(defcustom link-hint-restore t
  "Whether to restore the point and window after opening a link.
Note that the point will never be restored if the action intentionally moves the
point within the link buffer (e.g. opening a local org heading link). Similarly,
the window will never be restored if the action intentionally opens/selects a
new window (e.g. opening a url in `eww')."
  :type 'boolean)

;; ** Avy Settings
;;  these only have an effect if bound by the user
(defvar link-hint-avy-style)

(defvar link-hint-avy-keys)

(defvar link-hint-avy-all-windows)

(defvar link-hint-avy-all-windows-alt)

(defvar link-hint-avy-background)

(defvar link-hint-avy-ignored-modes)

;; * Link Finding Helper Functions
(defun link-hint--find-regexp (search-regexp start-bound end-bound)
  "Find the first occurrence of SEARCH-REGEXP.
Only search the range between just after START-BOUND and END-BOUND."
  (save-excursion
    (let (case-fold-search)
      (goto-char start-bound)
      (ignore-errors (forward-char))
      (when (re-search-forward search-regexp end-bound t)
        (match-beginning 0)))))

(defun link-hint--next-regexp (search-regexp bound)
  "Find the next occurrence of SEARCH-REGEXP.
Only search the range between just after the point and BOUND."
  (link-hint--find-regexp search-regexp (point) bound))

(declare-function widget-forward "ext:wid-edit")
(defun link-hint--next-widget (bound)
  "Find the next widget location. Currently only used for custom mode.
Only search the range between just after the point and BOUND."
  (save-excursion
    (save-restriction
      (narrow-to-region (point) bound)
      ;; Emacs <30 will raise an error when there is no widget forward
      ;; of point.  Emacs 30 introduced code that no longer raises an
      ;; error in this case, and it doesn't move point either.
      ;; Therefore we return nil if an error is raised (Emacs <30),
      ;; but we also return nil if `widget-forward' doesn't move point
      ;; (Emacs 30).
      (ignore-errors
        (let ((start (point))
              (new-pos (progn
                         (widget-forward 1)
                         (point))))
          (when (> new-pos start)
            new-pos))))))

(defun link-hint--find-property-with-value
    (property value start-bound end-bound)
  "Find the first location where PROPERTY has VALUE.
If VALUE is nil, find the first location where PROPERTY exists. Only search the
range from between just after the START-BOUND and END-BOUND."
  (let (first-non-match-pos)
    (setq first-non-match-pos
          (funcall (if value
                       #'text-property-not-all
                     #'text-property-any)
                   start-bound end-bound property value))
    (when first-non-match-pos
      (funcall (if value
                   #'text-property-any
                 #'text-property-not-all)
               first-non-match-pos end-bound property value))))

(defun link-hint--property-text
    (property &optional before-bound after-bound)
  "Return all text around the point for which PROPERTY stays the same.
Search only before the point to BEFORE-BOUND and after the point to AFTER-BOUND.
If the property does not change in this range, return the text between
BEFORE-BOUND and AFTER-BOUND."
  ;; TODO are these default bounds reasonable?
  ;; links can be split with a newline (e.g. Info-mode)
  (let ((before-bound (or before-bound
                          (save-excursion
                            (goto-char (window-start))
                            (forward-line -5)
                            (point))))
        (after-bound (or after-bound
                         (save-excursion
                           (goto-char (window-end nil t))
                           (forward-line 5)
                           (point)))))
    (buffer-substring-no-properties
     (previous-single-property-change (1+ (point)) property nil before-bound)
     (next-single-property-change (point) property nil after-bound))))

(defun link-hint--next-property-with-value (property value end-bound)
  "Find the next location where PROPERTY has VALUE.
Only search the range from between just after the point and END-BOUND."
  (link-hint--find-property-with-value property value (point) end-bound))

(defun link-hint--find-property (property start-bound end-bound)
  "Find the first location where PROPERTY exists.
Only search the range from between just after the START-BOUND and the
END-BOUND."
  (link-hint--find-property-with-value property nil start-bound end-bound))

(defun link-hint--next-property (property bound)
  "Find the next location where PROPERTY exists.
Only search the range from between just after the point and BOUND."
  (link-hint--find-property property (point) bound))

;; * Link Type Definition
(defun link-hint- (symbol)
  "Preface SYMBOL with \"link-hint-\"."
  (intern (format "link-hint-%S" symbol)))

;;;###autoload
(defun link-hint-define-type (name &rest properties)
  "Add a new type of link called NAME to link-hint.el.
PROPERTIES should be property value pairs to add to the symbol plist of
link-hint-NAME."
  (declare (indent defun))
  (let ((type (link-hint- name)))
    (cl-loop for (prop value)
             on properties by 'cddr
             do (put type prop value))))

;; ** Helpers
(defun link-hint--min (&rest numbers)
  "Find the minimum from the list NUMBERS, ignoring nil values."
  (setq numbers (remq nil numbers))
  (when numbers
    (apply #'min numbers)))

(defun link-hint--var-valid-p (var)
  "Return t if VAR is bound and true or is the current major mode."
  (or (eq var major-mode)
      (and (boundp var)
           (symbol-value var))))

(defun link-hint--type-valid-p (type)
  "Return whether TYPE is a valid type for the current buffer.
This is done by checking that all its predicates hold, that at least one of its
variables is bound and true or the current `major-mode', and that none of its
\"not\" variables are true (if bound) or the current `major-mode'."
  (let ((predicates (get type :predicates))
        (vars (get type :vars))
        (not-vars (get type :not-vars)))
    ;; note: cl-every will always return t for a null seq but cl-some will not
    ;; however, this behavior is not documented (hence or)
    (and (or (null predicates)
             (cl-every (lambda (pred)
                         (funcall pred))
                       predicates))
         (or (null vars)
             (cl-some #'link-hint--var-valid-p vars))
         (or (null not-vars)
             (not (cl-some #'link-hint--var-valid-p not-vars))))))

;; ** Text Url
(defun link-hint--next-text-url (bound)
  "Find the next text url.
Only search the range between just after the point and BOUND."
  (link-hint--next-regexp link-hint-url-regexp bound))

(defun link-hint--text-url-at-point-p ()
  "Return the text url at the point or nil."
  (let ((url (thing-at-point-url-at-point t)))
    (and url
         ;; this should filter out any lax matches that aren't actually urls;
         ;; note that thingatpt will add missing schemes (www -> http://www)
         (string-match-p link-hint-url-regexp url)
         url)))

(defun link-hint--process-url (url _action)
  "Return URL without any trailing parentheses."
  (if link-hint-delete-trailing-paren
      (replace-regexp-in-string ")*$" "" url)
    url))

(link-hint-define-type 'text-url
  :next #'link-hint--next-text-url
  :at-point-p #'link-hint--text-url-at-point-p
  :not-vars '(org-mode
              ;; modes that use shr.el
              mu4e-view-mode
              elfeed-show-mode
              eww-mode)
  :parse #'link-hint--process-url
  :open #'browse-url
  :open-multiple t
  :copy #'kill-new)

;; ** File Link
(defun link-hint--find-file-link (start-bound end-bound)
  "Find the first file link.
Only search the range between just after START-BOUND and END-BOUND."
  (save-excursion
    (let (file-link-pos)
      (goto-char start-bound)
      (while (and
              (setq file-link-pos
                    (link-hint--find-regexp link-hint-maybe-file-regexp
                                            (point) end-bound))
              (progn
                (goto-char file-link-pos)
                (when (looking-at (rx blank))
                  (forward-char)
                  (setq file-link-pos (point)))
                t)
              (not (ffap-file-at-point))))
      (when (and file-link-pos
                 (ffap-file-at-point))
        file-link-pos))))

(defun link-hint--next-file-link (bound)
  "Find the next file link.
Only search the range between just after the point and BOUND."
  (link-hint--find-file-link (point) bound))

(link-hint-define-type 'file-link
  :next #'link-hint--next-file-link
  :at-point-p #'ffap-file-at-point
  ;; TODO consider making file links opt-in (use :vars)
  :not-vars '(org-mode Info-mode)
  :open #'find-file-at-point
  :copy #'kill-new)

;; ** Generic Button
(defun link-hint--next-button (bound)
  "Find the next button.
Only search the range between just after the point and BOUND."
  (link-hint--next-property 'button bound))

(defun link-hint--button-at-point-p ()
  "Return the button at the point or nil."
  (let ((button (button-at (point))))
    (when button
      (button-label button))))

(link-hint-define-type 'button
  :next #'link-hint--next-button
  :at-point-p #'link-hint--button-at-point-p
  ;; TODO add more
  :not-vars '(woman-mode treemacs-mode Man-mode dictionary-mode fanyi-mode)
  :open #'push-button
  :copy #'kill-new)

;; ** Shr Url
(defun link-hint--next-shr-url (bound)
  "Find the next shr url.
Only search the range between just after the point and BOUND."
  ;; `shr-next-link' just uses text properties as well
  (link-hint--next-property 'shr-url bound))

(defun link-hint--shr-url-at-point-p ()
  "Return the shr url at the point or nil."
  (get-text-property (point) 'shr-url))

(link-hint-define-type 'shr-url
  :next #'link-hint--next-shr-url
  :at-point-p #'link-hint--shr-url-at-point-p
  ;; would need a comprehensive list of all modes that use shr.el
  ;; :vars
  :not-vars '(mastodon-mode nov-mode)
  :open #'browse-url
  :open-multiple t
  :copy #'kill-new)

;; ** Org Link
(defun link-hint--next-org-link (bound)
  "Find the next org link.
Only search the range between just after the point and BOUND."
  (link-hint--next-property 'htmlize-link bound))

(defun link-hint--org-link-at-point-p ()
  "Return the org link at the point or nil."
  ;; note: org uses :uri even for elisp forms, shell commands, etc.
  ;; note: org doesn't provide a property for the text in [[url][text]]
  (plist-get (get-text-property (point) 'htmlize-link) :uri))

(declare-function org-open-at-point "org")
(declare-function org-open-link-from-string "org")
(defun link-hint--open-org-link (uri)
  "Open the org link URI."
  ;; org-open-at-point won't work e.g. for =http://address.com= even
  ;; though `org-next-link' will jump to it
  (condition-case nil
      (org-open-at-point-global)
    (error (if (fboundp 'org-link-open-from-string)
               (org-link-open-from-string uri)
             (org-open-link-from-string uri)))))

(link-hint-define-type 'org-link
  :next #'link-hint--next-org-link
  :at-point-p #'link-hint--org-link-at-point-p
  :vars '(org-mode org-journal-mode org-agenda-mode org-link-minor-mode orglink-mode org-roam-mode)
  :open #'link-hint--open-org-link
  :open-multiple t
  :copy #'kill-new)

;; ** Treemacs Link
(declare-function treemacs-visit-node-in-most-recently-used-window "ext:treemacs")
(declare-function treemacs-visit-node-default "ext:treemacs")
(declare-function treemacs-button-get "ext:treemacs")
(declare-function treemacs-node-at-point "ext:treemacs")
(defun link-hint--open-treemacs-button ()
  "Open an entry in a treemacs buffer."
  (if (string-prefix-p " *Treemacs-" (buffer-name))
      (treemacs-visit-node-in-most-recently-used-window)
    (treemacs-visit-node-default)))

(defun link-hint--copy-treemacs ()
  "Copy an entry in a treemacs buffer."
  (kill-new (format "%s"
                    (treemacs-button-get
                     (treemacs-node-at-point) :key))))

(defun link-hint--treemacs-at-point-p ()
  "`:at-point-p' for treemacs buffers."
  (let ((node (treemacs-node-at-point)))
    (when node
      (format "%s" (treemacs-button-get node :key)))))

(link-hint-define-type 'treemacs
  :next #'link-hint--next-button
  :at-point-p #'link-hint--treemacs-at-point-p
  :vars '(treemacs-mode)
  :open #'link-hint--open-treemacs-button
  :open-multiple t
  :copy #'link-hint--copy-treemacs)

;; ** Markdown Link
(declare-function markdown-next-link "ext:markdown-mode")
(defun link-hint--next-markdown-link (bound)
  "Find the next markdown link.
Only search the range between just after the point and BOUND."
  ;; `markdown-next-link' does not use text properties
  (let ((start (point)))
    (save-excursion
      (let ((match-pos (markdown-next-link)))
        (when (and match-pos
                   (< start match-pos bound))
          match-pos)))))

(declare-function markdown-link-at-pos "ext:markdown-mode")
(declare-function markdown-wiki-link-p "ext:markdown-mode")
(declare-function markdown-wiki-link-link "ext:markdown-mode")
(defun link-hint--markdown-link-at-point-p ()
  "Return the markdown link at the point or nil."
  (if (markdown-wiki-link-p)
      (markdown-wiki-link-link)
    (let ((link (markdown-link-at-pos (point))))
      (unless (cl-every #'null link)
        link))))

(defun link-hint--parse-markdown-link (link action)
  "Alter LINK so that it can be passed to the ACTION function."
  (cl-case action
    ((:describe :copy) (if (listp link)
                           (nth 3 link)
                         link))
    (t link)))

(declare-function markdown-follow-link-at-point "ext:markdown-mode")
(declare-function markdown-follow-wiki-link "ext:markdown-mode")
(defun link-hint--open-markdown-link (link)
  "Open the markdown link at the point or LINK."
  (if (listp link)
      (markdown-follow-link-at-point)
    (markdown-follow-wiki-link link)))

(link-hint-define-type 'markdown-link
  :next #'link-hint--next-markdown-link
  :at-point-p #'link-hint--markdown-link-at-point-p
  :vars '(markdown-mode gfm-mode markdown-view-mode)
  :parse #'link-hint--parse-markdown-link
  :open #'link-hint--open-markdown-link
  :open-multiple t
  :copy #'kill-new)

;; ** Mu4e Url
(defun link-hint--next-mu4e-url (bound)
  "Find the next mu4e url.
Only search the range between just after the point and BOUND."
  (link-hint--next-property 'mu4e-url bound))

(defun link-hint--mu4e-url-at-point-p ()
  "Return the mu4e url at the point or nil."
  (get-text-property (point) 'mu4e-url))

(declare-function mu4e~view-browse-url-from-binding "ext:mu4e-view")
(declare-function mu4e--view-browse-url-from-binding "ext:mu4e-view")
(defun link-hint--open-mu4e-url (url)
  "Open the mu4e URL."
  ;; note: browse-url also supports mailto
  (if (fboundp 'mu4e--view-browse-url-from-binding)
      (mu4e--view-browse-url-from-binding url)
    (mu4e~view-browse-url-from-binding url)))

(link-hint-define-type 'mu4e-url
  :next #'link-hint--next-mu4e-url
  :at-point-p #'link-hint--mu4e-url-at-point-p
  :vars '(mu4e-view-mode)
  :open #'link-hint--open-mu4e-url
  :open-multiple t
  :copy #'kill-new)

;; ** Mu4e Attachment
(defun link-hint--next-mu4e-attachment (bound)
  "Find the next mu4e attachment.
Only search the range between just after the point and BOUND."
  (link-hint--next-property 'mu4e-attnum bound))

(defun link-hint--mu4e-attachment-at-point-p ()
  "Return the mu4e attachment number at the point or nil."
  (get-text-property (point) 'mu4e-attnum))

(declare-function mu4e-view-open-attachment "ext:mu4e-view")
(defun link-hint--open-mu4e-attachment (attnum)
  "Open the mu4e attachment having number ATTNUM."
  (mu4e-view-open-attachment nil attnum))

(declare-function mu4e-view-save-attachment-single "ext:mu4e-view")
(defun link-hint--copy-mu4e-attachment (attnum)
  "Save the mu4e attachment having number ATTNUM."
  (mu4e-view-save-attachment-single nil attnum))

(link-hint-define-type 'mu4e-attachment
  :next #'link-hint--next-mu4e-attachment
  :at-point-p #'link-hint--mu4e-attachment-at-point-p
  :vars '(mu4e-view-mode)
  :open #'link-hint--open-mu4e-attachment
  :copy #'link-hint--copy-mu4e-attachment)

;; ** Gnus w3m Url
;; only applicable when `mm-text-html-renderer' is gnus-w3m; shr is the default
(defun link-hint--next-gnus-w3m-url (bound)
  "Find the next gnus-w3m url.
Only search the range between just after the point and BOUND."
  (link-hint--next-property 'gnus-string bound))

(defun link-hint--gnus-w3m-url-at-point-p ()
  "Return the gnus-w3m url at the point or nil."
  (get-text-property (point) 'gnus-string))

(link-hint-define-type 'gnus-w3m-url
  :next #'link-hint--next-gnus-w3m-url
  :at-point-p #'link-hint--gnus-w3m-url-at-point-p
  :vars '(gnus-article-mode)
  :open #'browse-url
  :open-multiple t
  :copy #'kill-new)

;; ** Gnus w3m Image Url
;; only applicable when `mm-text-html-renderer' is gnus-w3m; shr is the default
(defun link-hint--next-gnus-w3m-image-url (bound)
  "Find the next gnus-w3m image url.
Only search the range between just after the point and BOUND."
  (link-hint--next-property 'image-url bound))

(defun link-hint--gnus-w3m-image-url-at-point-p ()
  "Return the gnus-w3m image url at the point or nil."
  (get-text-property (point) 'image-url))

(link-hint-define-type 'gnus-w3m-image-url
  :next #'link-hint--next-gnus-w3m-image-url
  :at-point-p #'link-hint--gnus-w3m-image-url-at-point-p
  :vars '(gnus-article-mode)
  :open #'browse-url
  :open-multiple t
  :copy #'kill-new)

;; ** Help Link
(defun link-hint--next-help-link (bound)
  "Find the next help link.
Only search the range between just after the point and BOUND."
  (link-hint--next-property 'help-args bound))

(defun link-hint--help-link-at-point-p ()
  "Return the name of the help link at the point or nil."
  (let ((help-link (get-text-property (point) 'help-args)))
    (when help-link
      (format "%s" help-link))))

(link-hint-define-type 'help-link
  :next #'link-hint--next-help-link
  :at-point-p #'link-hint--help-link-at-point-p
  :vars '(help-mode)
  :open #'push-button
  :copy #'kill-new)

;; ** Info Link
(declare-function Info-follow-nearest-node "info")
(defun link-hint--next-info-link (bound)
  "Find the next info link.
Only search the range between just after the point and BOUND."
  ;; Info-next-reference doesn't work for all links and uses
  ;; `next-single-char-property-change'
  (link-hint--min (link-hint--next-property-with-value
                   'font-lock-face 'info-xref bound)
                  ;; visited links have a different face
                  (link-hint--next-property-with-value
                   'font-lock-face 'info-xref-visited bound)))

(defun link-hint--info-link-at-point-p ()
  "Return the name of the info link at the point or nil."
  ;; (Info-extract-pointer "next")
  (when (or (eq (get-text-property (point) 'font-lock-face)
                'info-xref)
            (eq (get-text-property (point) 'font-lock-face)
                'info-xref-visited))
    ;; note: Info-mode doesn't use buttons
    (link-hint--property-text 'font-lock-face)))

(defun link-hint--open-info-link (_)
  "Open the info link at the point."
  (Info-follow-nearest-node))

(link-hint-define-type 'info-link
  :next #'link-hint--next-info-link
  :at-point-p #'link-hint--info-link-at-point-p
  :vars '(Info-mode)
  :open #'link-hint--open-info-link
  :copy #'kill-new)

;; ** Package Link
(defun link-hint--next-package-link (bound)
  "Find the next package link.
Only search the range between just after the point and BOUND."
  ;; (link-hint--next-property-with-value
  ;;  'action 'package-menu-describe-package bound)
  (link-hint--next-property 'package-desc bound))

(defun link-hint--package-link-at-point-p ()
  "Return the name of the package at the point or nil."
  (get-text-property (point) 'package-desc))

(declare-function package-desc-name "ext:package")
(declare-function package-desc-extras "ext:package")
(defun link-hint--parse-package-link (package-desc action)
  "Alter PACKAGE-DESC so that it can be passed to the ACTION function."
  (cl-case action
    (:browse-url (cdr (assq :url (package-desc-extras package-desc))))
    ((:describe :copy) (symbol-name (package-desc-name package-desc)))
    (t package-desc)))

(link-hint-define-type 'package-link
  :next #'link-hint--next-package-link
  :at-point-p #'link-hint--package-link-at-point-p
  :vars '(package-menu-mode paradox-menu-mode)
  :parse #'link-hint--parse-package-link
  :open #'describe-package
  :browse-url #'browse-url
  :browse-multiple t
  :copy #'kill-new)

;; ** Package Home Page Link (paradox only)
;; TODO

;; ** Package Keyword Link
(defun link-hint--next-package-keyword-link (bound)
  "Find the next package keyword link.
Only search the range between just after the point and BOUND."
  ;; (link-hint--next-property-with-value
  ;;  'action 'package-keyword-button-action bound)
  (link-hint--next-property 'package-keyword bound))

(defun link-hint--package-keyword-link-at-point-p ()
  "Return the name of the package keywords at the point or nil."
  (get-text-property (point) 'package-keyword))

(link-hint-define-type 'package-keyword-link
  :next #'link-hint--next-package-keyword-link
  :at-point-p #'link-hint--package-keyword-link-at-point-p
  :vars '(help-mode)
  :open #'push-button
  :copy #'kill-new)

;; ** Package Install Link
(defun link-hint--next-package-install-link (bound)
  "Find the next package installation link.
Only search the range between just after the point and BOUND."
  (link-hint--next-property-with-value
   'action 'package-install-button-action bound))

(defun link-hint--package-install-link-at-point-p ()
  "If there is a package link at the point, return its name."
  (when (eq (get-text-property (point) 'action)
            'package-install-button-action)
    (package-desc-name (get-text-property (point) 'package-desc))))

(link-hint-define-type 'package-install-link
  :next #'link-hint--next-package-install-link
  :at-point-p #'link-hint--package-install-link-at-point-p
  :vars '(help-mode)
  :open #'push-button
  :open-message "Installed")

;; ** epkg Button
(declare-function epkg-list-keyworded-packages "ext:epkg")
(declare-function epkg-list-packages-by-author "ext:epkg")
(declare-function epkg-describe-package "ext:epkg")
(defun link-hint--overlay-epkg-category (overlay)
  "If OVERLAY contains a category of epkg, return it."
  (let ((category (overlay-get overlay 'category)))
    (when (and category (require 'epkg nil t))
      (catch 'category
        (dolist (type '(epkg-package
                        epkg-author
                        epkg-keyword
                        epkg-library))
          (when (eq category (button-category-symbol type))
            (throw 'category type)))))))

(defun link-hint--next-epkg-button (bound)
  "Find the next epkg button.
Only search the range between just after the point and BOUND."
  (catch 'found
    (save-restriction
      (let (pos)
        (narrow-to-region (point) (or bound (point-max)))
        (save-excursion
          (while (and (setq pos (next-overlay-change (point)))
                      (< pos (point-max)))
            (dolist (ol (overlays-at pos))
              (let ((category (link-hint--overlay-epkg-category ol)))
                (when category
                  (throw 'found pos))))
            (goto-char pos))
          nil)))))

(defun link-hint--at-epkg-button-p ()
  "If the point is at an epkg button, return its label."
  (catch 'text
    (dolist (ol (overlays-at (point)))
      (when (link-hint--overlay-epkg-category ol)
        (throw 'text (buffer-substring-no-properties
                      (overlay-start ol) (overlay-end ol)))))))

(defun link-hint--open-epkg-button ()
  "Open an epkg button at point."
  (let ((label (link-hint--at-epkg-button-p)))
    (cl-case (link-hint--overlay-epkg-category (car (overlays-at (point))))
      (epkg-package
       (epkg-describe-package label))
      (epkg-author
       (epkg-list-packages-by-author label))
      (epkg-keyword
       (epkg-list-keyworded-packages (intern label)))
      (epkg-library
       (find-library label)))))

(link-hint-define-type 'epkg-button
  :next #'link-hint--next-epkg-button
  :at-point-p #'link-hint--at-epkg-button-p
  :vars '(help-mode)
  :open #'link-hint--open-epkg-button
  :open-message "Following"
  :copy #'kill-new)

;; ** Compilation Link
(declare-function compile-goto-error "compile")
(defun link-hint--next-compilation-link (bound)
  "Find the next compilation link.
Only search the range between just after the point and BOUND."
  (link-hint--next-property 'compilation-message bound))

(defun link-hint--compilation-link-at-point-p ()
  "Return the compilation link message at the point or nil."
  (get-text-property (point) 'compilation-message))

(link-hint-define-type 'compilation-link
  :next #'link-hint--next-compilation-link
  :at-point-p #'link-hint--compilation-link-at-point-p
  :vars '(compilation-mode compilation-minor-mode compilation-shell-minor-mode)
  ;; no simple way to get message for copying
  :open #'compile-goto-error)

;; ** w3m Link
(defun link-hint--next-w3m-link (bound)
  "Find the next w3m link.
Only search the range between just after the point and BOUND."
  ;; `w3m-goto-next-link' also uses text properties
  (link-hint--next-property 'w3m-href-anchor bound))

(defun link-hint--w3m-link-at-point-p ()
  "Return the w3m link at the point or nil."
  (get-text-property (point) 'w3m-href-anchor))

(declare-function w3m-view-this-url "ext:w3m")
(link-hint-define-type 'w3m-link
  :next #'link-hint--next-w3m-link
  :at-point-p #'link-hint--w3m-link-at-point-p
  :vars '(w3m-mode)
  :open #'w3m-view-this-url
  :copy #'kill-new)

;; ** w3m Message Link
;; w3m can be used for rendering email (e.g. `mm-text-html-renderer' is w3m)
;; same as w3m link but with different open action
(link-hint-define-type 'w3m-message-link
  :next #'link-hint--next-w3m-link
  :at-point-p #'link-hint--w3m-link-at-point-p
  :vars '(gnus-article-mode notmuch-show-mode)
  :open #'browse-url
  :copy #'kill-new)

;; ** Overlay Button
;; Although potentially it might work in more modes, because this function
;; uses `next-single-char-property-change', which is slow, it’s only used for
;; woman, man, and dictionary modes.
(defun link-hint--find-overlay-button (start-bound end-bound)
  "Find the first button location returned from `next-button’.
Only search the range between just after START-BOUND and END-BOUND."
  (let (button)
    (save-restriction
      (narrow-to-region start-bound end-bound)
      (setq button (next-button (point)))
      (when button
        (button-start button)))))

(defun link-hint--next-overlay-button (bound)
  "Find the next overlay button location.
Only search the range between just after the point and BOUND."
  (link-hint--find-overlay-button (point) bound))

(link-hint-define-type 'overlay-button
  :next #'link-hint--next-overlay-button
  :at-point-p #'link-hint--button-at-point-p
  :vars '(dictionary-mode
          epa-key-list-mode
          fanyi-mode
          Man-mode
          notmuch-show-mode
          woman-mode)
  :open #'push-button
  :copy #'kill-new)

;; ** Nov.el Link
(declare-function nov-browse-url "ext:nov")
(defun link-hint--nov-browse ()
  "Call `nov-browse-url' with no args."
  (nov-browse-url))

(link-hint-define-type 'nov-link
  :next #'link-hint--next-shr-url
  :at-point-p #'link-hint--shr-url-at-point-p
  :vars '(nov-mode)
  :open #'link-hint--nov-browse
  :copy #'kill-new)

;; ** Deadgrep matches
(declare-function deadgrep-visit-result "ext:deadgrep")
(defun link-hint--next-deadgrep-link (bound)
  "Find the next deadgrep link.
Only search the range between just after the point and BOUND."
  (link-hint--next-property-with-value 'face 'deadgrep-meta-face bound))

(defun link-hint--deadgrep-link-at-point-p ()
  "Return the source location at the point."
  (let ((filename (get-text-property (point) 'deadgrep-filename))
        (line-number (get-text-property (point) 'deadgrep-line-number)))
    (when (and filename line-number)
      (format "%s:%s" filename line-number))))

(link-hint-define-type 'deadgrep
  :next #'link-hint--next-deadgrep-link
  :at-point-p #'link-hint--deadgrep-link-at-point-p
  :vars '(deadgrep-mode)
  :open #'deadgrep-visit-result)

;; ** Customize Widget
;; (customize-link (and (eq major-mode 'Custom-mode)
;;                      (button-at (point))))
;; (customize-field (and (eq major-mode 'Custom-mode)
;;                       (eq (car (widget-tabable-at))
;;                           'editable-field)))

(declare-function Custom-newline "cus-edit")
(defun link-hint--open-customize-widget ()
  "Open the customize widget at the point."
  (Custom-newline (point)))

(defun link-hint--customize-widget-at-point-p ()
  "Return button text of the customize widget at the point or nil."
  (let ((button (get-char-property (point) 'button)))
    (when button
      (plist-get (cdr button) :tag))))

(link-hint-define-type 'customize-widget
  :next #'link-hint--next-widget
  :at-point-p #'link-hint--customize-widget-at-point-p
  :vars '(Custom-mode)
  :open #'link-hint--open-customize-widget
  :copy #'kill-new)

;; ** notmuch-hello widgets
(defun link-hint--widget-button-at-point-p ()
  "Return point of the customize widget at the point or nil."
  (when (get-char-property (point) 'button) (point)))

(defun link-hint--next-widget-button (bound)
  "Return pos of the next widget up to BOUND."
  (let ((start (point)))
    (save-excursion
      (widget-forward 1)
      (while (not (link-hint--widget-button-at-point-p))
        (widget-forward 1))
      (when (and (link-hint--widget-button-at-point-p)
                 (> (point) start)
                 (< (point) bound))
        (point)))))

(defun link-hint--copy-widget (pos)
  "Copy the text of the button at POS."
  (kill-new (widget-get (widget-at pos) :value)))

(link-hint-define-type 'notmuch-hello
  :next #'link-hint--next-widget-button
  :at-point-p #'link-hint--widget-button-at-point-p
  :vars '(notmuch-hello-mode)
  :open #'widget-button-press
  :copy #'link-hint--copy-widget)

;; ** Completion List candidate
(defun link-hint--next-completion-list-candidate (bound)
  "Find the next completion list candidate location.
Only search the range between just after the point and BOUND."
  (save-excursion
    (let ((start (point)))
      (next-completion 1)
      (let ((pos (point)))
        (when (or (< start pos bound)
                  ;; edge case where `next-completion' will not move the point
                  ;; the first time it's called
                  (and (boundp 'completions-header-format)
                       (null completions-header-format)
		       (null completion-show-help)
                       (= start (point-min))))
          pos)))))

(defun link-hint--open-completion-list-candidate (&rest _ignore)
  "Select completion list candidate at point."
  (choose-completion))

(defun link-hint--completion-list-candidate-at-point-p ()
  "Return the completion list candidate at the point or nil."
  (get-text-property (point) 'completion--string))

(link-hint-define-type 'completion-list-candidate
  :next #'link-hint--next-completion-list-candidate
  :vars '(completion-list-mode)
  :open #'link-hint--open-completion-list-candidate
  :at-point-p #'link-hint--completion-list-candidate-at-point-p
  :copy #'kill-new)

;; ** Dired filename
(defun link-hint--next-dired-filename (bound)
  "Find the next dired filename location.
Only search the range between just after the point and BOUND."
  (link-hint--next-property 'dired-filename bound))

(defun link-hint--dired-filename-at-point-p ()
  "Return the dired filename at the point or nil."
  (when (get-text-property (point) 'dired-filename)
    (link-hint--property-text 'dired-filename)))

(declare-function dired-find-file "dired")

(link-hint-define-type 'dired-filename
  :next #'link-hint--next-dired-filename
  :at-point-p #'link-hint--dired-filename-at-point-p
  :vars '(dired-mode)
  :open #'dired-find-file
  :copy #'kill-new)

;; ** Org Agenda item
(defun link-hint--next-org-agenda-item (bound)
  "Find the next org agenda item.
Only search the range between just after the point and BOUND."
  (link-hint--next-property 'org-marker bound))

(declare-function org-agenda-switch-to "org-agenda")

(defun link-hint--open-org-agenda-item (&rest _ignore)
  "Open org agenda item at point."
  (org-agenda-switch-to))

(defun link-hint--org-agenda-item-at-point-p ()
  "Return the org agenda at the point or nil."
  (get-text-property (point) 'txt))

(link-hint-define-type 'org-agenda-item
  :next #'link-hint--next-org-agenda-item
  :vars '(org-agenda-mode)
  :open #'link-hint--open-org-agenda-item
  :at-point-p #'link-hint--org-agenda-item-at-point-p
  :copy #'kill-new)

;; ** Xref item
(defun link-hint--next-xref-item (bound)
  "Find the next xref item.
Only search the range between just after the point and BOUND."
  (link-hint--next-property 'xref-item bound))

(declare-function xref-goto-xref "xref")
(declare-function xref--item-at-point "xref")
(declare-function xref-item-summary "xref")

(defun link-hint--copy-xref-item ()
  "Copy a xref item in a xref buffer."
  (kill-new (xref-item-summary (xref--item-at-point))))

(link-hint-define-type 'xref-item
  :next #'link-hint--next-xref-item
  :vars '(xref--xref-buffer-mode)
  :open #'xref-goto-xref
  :at-point-p #'xref--item-at-point
  :copy #'link-hint--copy-xref-item)

;; ** bug-reference-mode item
(defun link-hint--next-bug-reference (bound)
  "Find the next bug-reference."
  (let ((next (next-single-char-property-change
               (point) 'bug-reference-url nil bound)))
    (unless (eq next bound)
      ;; check 'bug-reference-url is set at next - if it is then return
      ;; this
      (catch 'found
        (dolist (overlay (overlays-at next))
          (when (overlay-get overlay 'bug-reference-url)
            (throw 'found next)))
        ;; otherwise find the next one
        (setq next
              (next-single-char-property-change
               next 'bug-reference-url nil bound))
        (unless (eq next bound) next)))))

(defun link-hint--bug-reference-at-point-p ()
  "Return the bug-reference url at the point or nil."
  (car (get-char-property-and-overlay (point) 'bug-reference-url)))

(link-hint-define-type 'bug-reference
  :next #'link-hint--next-bug-reference
  :at-point-p #'link-hint--bug-reference-at-point-p
  :vars '(bug-reference-mode bug-reference-prog-mode)
  :open #'browse-url
  :copy #'kill-new)

;; * Avy/Action Helper Functions
(defun link-hint--collect (start end type)
  "Between START and END in the current buffer, collect all links of TYPE."
  (save-excursion
    (goto-char start)
    (let ((current-window (get-buffer-window))
          (next-func (get type :next))
          (at-point-p (get type :at-point-p))
          links
          link-pos)
      ;; as all "next-" functions are designed to look after the point,
      ;; check if there is a link at the point the first time, in order
      ;; to catch links that are at the start bound,
      ;; TODO explain this better and retest
      ;; as the eol of an invisible line can be visible in org buffers,
      ;; don't do this if the point is at the eol
      ;; TODO make this a do while instead if find a way around this
      (when (and (not (looking-at (rx eol)))
                 (funcall at-point-p))
        (push (list :pos (point)
                    :win current-window
                    :args (funcall at-point-p)
                    :type type)
              links))
      (while (setq link-pos (funcall next-func end))
        (goto-char link-pos)
        (push (list :pos link-pos
                    :win current-window
                    :args (funcall at-point-p)
                    :type type)
              links))
      links)))

;; WORKAROUND for avy--find-visible-regions sometimes excluding visible ranges
;; (which may be org's fault)
;; (defun avy--next-invisible-point ()
;;   "Return the next closest point with 'invisible property."
;;   (let ((s (point)))
;;     (while (and (not (= (point-max) (setq s (next-overlay-change s))))
;;                 (let ((invisible-property (get-char-property s 'invisible)))
;;                   (or (not invisible-property)
;;                       (equal invisible-property 'org-link)))))
;;     s))

;; other way
;; modified version of avy--find-visible-regions

;; TODO retest avy--find-visible-regions and make a bug report if necessary
;; TODO consistency (start end vs beg end)
(defun link-hint--find-visible-regions (rbeg rend)
  "Return a list of all visible regions between RBEG and REND."
  (setq rbeg (max rbeg (point-min)))
  (setq rend (min rend (point-max)))
  (when (< rbeg rend)
    (let (visibles beg)
      (save-excursion
        (save-restriction
          (narrow-to-region rbeg rend)
          (setq beg (goto-char (point-min)))
          (while (not (= (point) (point-max)))
            (goto-char (or (link-hint--next-property 'invisible (point-max))
                           (point-max)))
            (push (cons beg (point)) visibles)
            (setq beg (goto-char
                       (or (next-single-property-change
                            (point)
                            'invisible)
                           (point-max)))))
          (nreverse visibles))))))

(defun link-hint--equal (x y)
  "Return whether links X and Y are equal based on their window and position."
  (and (= (plist-get x :pos)
          (plist-get y :pos))
       (eq (plist-get x :win)
           (plist-get y :win))))

(defun link-hint--< (x y)
  "Return whether link X's position is before link Y's."
  (< (plist-get x :pos) (plist-get y :pos)))

(defun link-hint--collect-visible-links ()
  "Collect all visible links in the current buffer."
  (let (all-link-positions)
    (dolist (bounds (link-hint--find-visible-regions (window-start)
                                                     (window-end nil t)))
      (dolist (type link-hint-types)
        (when (link-hint--type-valid-p type)
          (setq all-link-positions
                (append all-link-positions
                        (link-hint--collect (car bounds) (cdr bounds) type))))))
    (sort (cl-delete-duplicates all-link-positions
                                :test #'link-hint--equal
                                ;; types earlier in `link-hint-types' have
                                ;; higher priority
                                :from-end t)
          #'link-hint--<)))

(cl-defun link-hint--get-links ()
  "Return a list of all visible links (potentially in multiple windows)."
  (let ((avy-all-windows (if (boundp 'link-hint-avy-all-windows)
                             link-hint-avy-all-windows
                           avy-all-windows))
        (avy-all-windows-alt (if (boundp 'link-hint-avy-all-windows-alt)
                                 link-hint-avy-all-windows-alt
                               avy-all-windows-alt))
        (avy-ignored-modes (if (boundp 'link-hint-avy-ignored-modes)
                               link-hint-avy-ignored-modes
                             avy-ignored-modes))
        links)
    (avy-dowindows current-prefix-arg
      (setq links (append links (link-hint--collect-visible-links))))
    (if links
        links
      (when link-hint-message
        (funcall link-hint-message "No links found."))
      nil)))

(defun link-hint--process (links)
  "Select a link from LINKS using avy.
If there is only one link in LINKS and `avy-single-candidate-jump' is non-nil,
return it."
  (let ((avy-background (if (boundp 'link-hint-avy-background)
                            link-hint-avy-background
                          avy-background))
        (avy-keys (if (boundp 'link-hint-avy-keys)
                      link-hint-avy-keys
                    avy-keys))
        ;; prevent window from shifting avy overlays out of view
        (scroll-margin 0))
    (if (or (cdr links)
            (not avy-single-candidate-jump))
        (save-selected-window
          (let* ((avy-action #'identity)
                 (pos (avy-process
                       (mapcar (lambda (x) (cons (plist-get x :pos)
                                                 (plist-get x :win)))
                               links)
                       (avy--style-fn (if (boundp 'link-hint-avy-style)
                                          link-hint-avy-style
                                        avy-style)))))
            (if (numberp pos)
                (cl-find (list :pos pos :win (get-buffer-window))
                         links
                         :test #'link-hint--equal)
              (when link-hint-message
                (funcall link-hint-message "Aborted link selection."))
              nil)))
      (car links))))

(defun link-hint--apply (func args &optional parser action)
  "Try to call FUNC with ARGS.
If PARSER is specified, first change ARGS by passing PARSER ARGS and ACTION.
First try `apply'. If there is an error (ARGS is the wrong number of arguments
for FUNC), `funcall' FUNC with ARGS. Finally, call FUNC alone."
  (when parser
    (setq args (funcall parser args action)))
  ;; TODO is there a way to know how many arguments a function takes?
  (condition-case nil
      (apply func args)
    (error (condition-case nil
               (funcall func args)
             (error (funcall func))))))

(defun link-hint--message (action &optional link-description type)
  "Display a message about an ACTION performed on a link.
`link-hint-message' holds the function to use to message (or is nil if there
should be no messaging). LINK-DESCRIPTION can either be a number corresponding
to the number of links acted upon or a description of a single link. Custom
messages for ACTION can be created by altering `link-hint-action-messages' or
adding an :<action>-message property to the link TYPE."
  (when link-hint-message
    (funcall link-hint-message "%s %s"
             (or (when type
                   (get type (intern (format "%s-message" action))))
                 (plist-get link-hint-action-messages action)
                 (format "Called %s on" action))
             (or (when (numberp link-description)
                   (format "%s links" link-description))
                 link-description
                 "a link"))))

(defun link-hint--action (action link)
  "Take ACTION on LINK.
If the point/window are not intentionally changed by the action, restore them."
  (let* ((original-win (get-buffer-window))
         link-buffer
         link-buffer-original-pos
         (link-pos (plist-get link :pos))
         (link-win (plist-get link :win))
         new-win-buffer
         (type (plist-get link :type))
         (parser (get type :parse))
         (args (plist-get link :args))
         (link-description (link-hint--apply
                            (or (get type :describe) #'identity)
                            args
                            parser
                            :describe))
         ret)
    (select-window link-win)
    (setq link-buffer (current-buffer)
          link-buffer-original-pos (point))
    (goto-char link-pos)
    (setq ret (link-hint--apply (get type action) args parser action))
    (when link-hint-restore
      ;; note: selected window can change without current buffer changing, so
      ;; check selected window
      (setq new-win-buffer (window-buffer (selected-window)))
      (cond ((and (eq new-win-buffer link-buffer)
                  (= (point) link-pos))
             ;; when the buffer doesn't change and the point is still at the
             ;; link, restore the position and window (no side effects have
             ;; occurred)
             (goto-char link-buffer-original-pos)
             (when (window-valid-p original-win)
               (select-window original-win)))
            ((and (buffer-live-p link-buffer)
                  (not (eq new-win-buffer link-buffer)))
             ;; when the buffer changes and the old buffer still exists, restore
             ;; the original position in the old buffer
             (if (and
                  ;; old window still exists
                  (window-valid-p link-win)
                  ;; old window still holds original buffer
                  (eq link-buffer (window-buffer link-win)))
                 ;; restore the point in that window
                 (set-window-point link-win link-buffer-original-pos)
               ;; `save-excursion' to prevent altering the current window's
               ;; point; only set the buffer's point since it is no longer
               ;; displayed in the old window
               ;; see https://www.gnu.org/software/emacs/manual/html_node/elisp/Point.html#Point
               (save-excursion
                 (with-current-buffer link-buffer
                   (goto-char link-buffer-original-pos)))))
            ;; when buffer doesn't change but position does (e.g. local org
            ;; link), do nothing
            ))
    (link-hint--message action link-description type)
    ret))

(defun link-hint--links-action (action links)
  "Take ACTION on every link in LINKS."
  (dolist (link links)
    (let (link-hint-message)
      (link-hint--action action link)))
  (link-hint--message action (length links)))

(defun link-hint--valid-types (&rest properties)
  "Return a list of valid link hint types based on PROPERTIES."
  (cl-loop for type in link-hint-types
           when (cl-every (lambda (prop) (get type prop))
                          properties)
           collect type))

(defun link-hint--one (action)
  "Take ACTION on one visible link selected with avy."
  (let* ((link-hint-types (link-hint--valid-types action))
         (links (link-hint--get-links))
         link)
    (when links
      (setq link (link-hint--process links))
      (when link
        (link-hint--action action link)))))

(defun link-hint--multiple (action)
  "Take ACTION on multiple visible links selected with avy."
  (let* ((multiple-action (intern (format "%s-multiple" action)))
         (link-hint-types (link-hint--valid-types action multiple-action))
         (links (link-hint--get-links))
         link
         chosen-links)
    (while (setq link (link-hint--process links))
      (push link chosen-links))
    (link-hint--links-action action (nreverse chosen-links))))

(defun link-hint--all (action)
  "Take ACTION on all visible links."
  (let* ((multiple-action (intern (format "%s-multiple" action)))
         (link-hint-types (link-hint--valid-types action multiple-action))
         (links (link-hint--get-links)))
    (link-hint--links-action action links)))

;; * User Commands
;; ** Avy Commands
;;;###autoload
(defun link-hint-open-link ()
  "Use avy to open a visible link."
  (interactive)
  (avy-with link-hint-open-link
    (link-hint--one :open)))

;;;###autoload
(defun link-hint-copy-link ()
  "Copy a visible link of a supported type to the kill ring with avy.
`select-enable-clipboard' and `select-enable-primary' can be set to non-nil
values to copy the link to the clipboard and/or primary as well."
  (interactive)
  (avy-with link-hint-copy-link
    (link-hint--one :copy)))

;;;###autoload
(defun link-hint-open-multiple-links ()
  "Use avy to open multiple visible links at once."
  (interactive)
  (avy-with link-hint-open-multiple-links
    (link-hint--multiple :open)))

;;;###autoload
(defun link-hint-copy-multiple-links ()
  "Use avy to copy multiple visible links at once to the kill ring."
  (interactive)
  (avy-with link-hint-copy-multiple-links
    (link-hint--multiple :copy)))

;;;###autoload
(defun link-hint-open-all-links ()
  "Open all visible links."
  (interactive)
  (avy-with link-hint-open-all-links
    (link-hint--all :open)))

;;;###autoload
(defun link-hint-copy-all-links ()
  "Copy all visible links."
  (interactive)
  (avy-with link-hint-copy-all-links
    (link-hint--all :copy)))

;; ** At Point Commands
(defun link-hint--get-link-at-point ()
  "Return the link with the highest priority at the point or nil."
  (let (args)
    (cl-dolist (type link-hint-types)
      (when (and (link-hint--type-valid-p type)
                 (setq args (funcall (get type :at-point-p))))
        (cl-return (list :pos (point)
                         :win (get-buffer-window)
                         :args args
                         :type type))))))

(defun link-hint--action-at-point (action)
  "Take ACTION on the highest priority link at the point."
  (let ((link-hint-types (link-hint--valid-types action))
        (link (link-hint--get-link-at-point)))
    (if link
        (link-hint--action action link)
      (let ((fallback (plist-get link-hint-action-fallback-commands action)))
        (unless (or (and fallback (funcall fallback))
                    (not link-hint-message))
          (funcall link-hint-message
                   "There is no link supporting the %s action at the point."
                   action))))))

;;;###autoload
(defun link-hint-open-link-at-point ()
  "Open the link with the highest priority at the point."
  (interactive)
  (link-hint--action-at-point :open))

;;;###autoload
(defun link-hint-copy-link-at-point ()
  "Copy the link with the highest priority at the point."
  (interactive)
  (link-hint--action-at-point :copy))

(provide 'link-hint)
;;; link-hint.el ends here
Download .txt
gitextract_gbwr8qn6/

├── LICENSE
├── README.org
└── link-hint.el
Condensed preview — 3 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (112K chars).
[
  {
    "path": "LICENSE",
    "chars": 35142,
    "preview": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
  },
  {
    "path": "README.org",
    "chars": 16380,
    "preview": "[[http://melpa.org/#/link-hint][file:http://melpa.org/packages/link-hint-badge.svg]]\n\n* Demonstration\nUsing this package"
  },
  {
    "path": "link-hint.el",
    "chars": 57210,
    "preview": ";;; link-hint.el --- Use avy to open, copy, etc. visible links -*- lexical-binding: t -*-\n\n;; Author: Fox Kiester <noct@"
  }
]

About this extraction

This page contains the full source code of the noctuid/link-hint.el GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 3 files (106.2 KB), approximately 26.1k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!