├── .elpaignore ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── config.yml ├── .gitignore ├── CHANGELOG.org ├── LICENSE ├── README.org ├── emacs-module.h ├── jinx-mod.c └── jinx.el /.elpaignore: -------------------------------------------------------------------------------- 1 | LICENSE 2 | .elpaignore 3 | .github -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 3 | name: 🐞 Bug report 4 | about: Report a bug. Do not use this for questions, support or feature requests. 5 | --- 6 | Thank you for reporting a bug. 7 | 8 | Please use the latest stable release of Emacs 30.1 and start with `emacs -Q` or 9 | `package-isolate` in order to only load a minimal set of packages. This way your 10 | Emacs configuration is not loaded. 11 | 12 | Please provide precise information and the exact steps to reproduce the issue. 13 | This is important to ensure that your problem can be reproduced on a different 14 | machine. 15 | 16 | If you are not really sure if your issue is a bug, please open a discussion 17 | instead. 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: "🙏 Please support my work on Jinx and my other Emacs packages" 4 | url: https://github.com/sponsors/minad 5 | about: Thanks! Your support helps dedicating time to project maintenance and development. 6 | - name: "💡 Suggest a feature ➞ Please create a discussion" 7 | url: https://github.com/minad/jinx/discussions/categories/ideas 8 | about: Start a new discussion suggesting an improvement or a feature. 9 | - name: "🧑‍🤝‍🧑 Ask the community for support" 10 | url: https://www.reddit.com/r/emacs 11 | about: Please be kind and support others. 12 | - name: "🤓 Ask the maintainer for support ➞ Please create a discussion" 13 | url: https://github.com/minad/jinx/discussions/categories/q-a 14 | about: Please keep in mind that my bandwidth is limited. 15 | - name: "🔍 Search through old issues or discussions" 16 | url: https://github.com/search?q=repo%3Aminad%2Fjinx&type=issues 17 | about: The same question may have been asked before. 18 | - name: "📝 Jinx wiki" 19 | url: https://github.com/minad/jinx/wiki 20 | about: Additional configuration tips are covered there. Feel free to edit! 21 | - name: "📖 Jinx manual" 22 | url: https://github.com/minad/jinx/blob/main/README.org 23 | about: The manual covers the basic setup and workflow. 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *-autoloads.el 2 | *-pkg.el 3 | *.elc 4 | *.info 5 | *.so 6 | *.texi 7 | *~ 8 | \#*\# 9 | /README-elpa 10 | -------------------------------------------------------------------------------- /CHANGELOG.org: -------------------------------------------------------------------------------- 1 | #+title: jinx.el - Changelog 2 | #+author: Daniel Mendler 3 | #+language: en 4 | 5 | * Version 2.2 (2025-05-26) 6 | 7 | - Stop using =enchant_dict_get_extra_word_characters=. Instead rely on the 8 | =jinx--syntax-table= for tokenization. 9 | 10 | * Version 2.1 (2025-04-04) 11 | 12 | - ~jinx-correct~: For capitalized words, offer lower case variants to save in 13 | personal dictionary and file local variables. 14 | - Add ~help-echo~ to the Jinx overlays. 15 | 16 | * Version 2.0 (2025-03-11) 17 | 18 | - Add ~jinx-dir-local-words~ saved in ~.dir-locals.el~. Words can be added to the 19 | ~.dir-locals.el~ with the ~/~ key in the ~jinx-correct~ dialog. The ~.dir-locals.el~ 20 | file of the current or a parent directory is used. If it does not exist it is 21 | created in the project root or the current directory. 22 | 23 | * Version 1.12 (2025-01-28) 24 | 25 | - Improve performance in large folded Org buffers. 26 | - Support ~lisp-data-mode~. 27 | - Retain dictionaries in weak hash table for sharing. 28 | 29 | * Version 1.11 (2024-12-22) 30 | 31 | - Require Emacs 28.1. 32 | - Remove special ~org-fold~ code. Set ~org-fold-core-style~ to ~overlays~ if unfolding 33 | in Org files does not work for you. 34 | - ~jinx-languages~: Group dictionaries by dictionary provider. 35 | 36 | * Version 1.10 (2024-07-23) 37 | 38 | - Bump Compat dependency to Compat 30. 39 | - Add include and linkpaths from FreeBSD for compilation. 40 | - Add ~jinx--syntax-overrides~ to override syntax table. 41 | 42 | * Version 1.9 (2024-06-29) 43 | 44 | - Bugfix: In some rare scenarios, Jinx could hang when checking pending regions. 45 | - ~jinx-correct-all~: Add ~ONLY-CHECK~ prefix argument. 46 | 47 | * Version 1.8 (2024-06-19) 48 | 49 | - Bugfix in ~jinx-correct~: Fix ~wrong-type-argument~ error if no Enchant 50 | dictionaries are found. 51 | 52 | * Version 1.7 (2024-05-15) 53 | 54 | - ~jinx--word-valid-p~: Do not error on invalid characters. 55 | - ~jinx-save-languages~: New custom variable. 56 | 57 | * Version 1.6 (2024-04-12) 58 | 59 | - Bugfix (again): Ensure that directory local variables work correctly with 60 | Jinx. It is possible to turn Jinx on or off via dir-locals, and also configure 61 | the language and local words. 62 | 63 | * Version 1.5 (2024-04-04) 64 | 65 | - Bugfix: Ensure that ~jinx-next~ unfolds hidden misspellings. 66 | - Bugfix: Ensure that directory local variable enabling ~jinx-mode~ works. 67 | 68 | * Version 1.4 (2024-03-10) 69 | 70 | - Bugfix: Ensure that ~jinx-correct~ saves words without text properties in the 71 | file-local variable ~jinx-local-words~. 72 | - Bugfix: Ensure that ~eval~ local variable enabling ~jinx-mode~ works. 73 | - ~jinx-correct~: If a region is marked, call ~jinx-correct-all~ and restrict 74 | corrections to the marked region. 75 | - ~jinx-exclude-faces~, ~jinx-include-faces~, ~jinx-exclude-regexps~: Support mode 76 | aliases. 77 | 78 | * Version 1.3 (2024-02-23) 79 | 80 | - Fix interaction bug with the newest version of AUCTeX, where the major mode 81 | got changed unexpectedly. 82 | 83 | * Version 1.2 (2024-01-22) 84 | 85 | - Fix deadlock on MacOS during Jinx startup. 86 | - Timer optimizations. 87 | 88 | * Version 1.1 (2023-12-27) 89 | 90 | - Add mouse context menu to correct misspellings. The menu is triggered by a 91 | right click on a misspelling. 92 | 93 | * Version 1.0 (2023-12-01) 94 | 95 | - Allow capitalized form of a word if non-capitalized word is stored in the 96 | session word list. 97 | - Replace =jinx-excluded-modes= with =global-jinx-modes=, the Emacs 28 convention 98 | for globalized minor modes. 99 | - =jinx-correct=: Offer session words as suggestions. 100 | - Add =jinx-correct-nearest=, =jinx-correct-all= and =jinx-correct-word= commands. The 101 | command =jinx-correct= dispatches to one of those commands depending on the 102 | prefix argument. 103 | - Recommend libenchant 2.3.1 or newer. Print a message if Enchant is outdated. 104 | - Support $LANG=C and $LANG=POSIX environment variable settings. 105 | 106 | * Version 0.9 (2023-07-02) 107 | 108 | - 🪄 Make sure that Emojis are not marked as misspelled 🧙🏼‍♀️. 109 | - Rename =jinx-correct-next/previous= to =jinx-next/previous=. The commands can be 110 | used outside the minibuffer. 111 | - Bind =M-n= and =M-p= to =jinx-next/previous= in =jinx-overlay-map=. 112 | - Bind =M-$= to =jinx-correct= in the =jinx-overlay-map=. 113 | - Add =jinx-repeat-map=. 114 | - Rename category of Jinx overlays to =jinx-overlay=. 115 | - Rename =jinx-misspelled-map= to =jinx-overlay-map=. 116 | - Add many more language modes to =jinx-camel-modes=. 117 | 118 | * Version 0.8 (2023-04-28) 119 | 120 | - =jinx-correct=: Consistently move backward to the previous misspelling. In order 121 | to move backward further, press =M-$= again (or =M-p=). Move forward with =M-n=. 122 | - =jinx-correct-select=: Support more than 10 quick keys. 123 | - =jinx-languages=: New argument =LANGS=. 124 | - Add =jinx-faces= customization group. 125 | - Add configurable save actions via =jinx--save-keys=. 126 | - Detect C compiler via $CC or =executable-find=. 127 | 128 | * Version 0.7 (2023-04-21) 129 | 130 | - Bugfixes 131 | - =jinx-languages=: Only ask in file-backed buffers if file-local variable should 132 | be saved. 133 | - Push =undo-boundary= before correcting a word, such that corrections are not 134 | undone in a single step. 135 | - =jinx-correct=: Use =+= as prefix to add word to the current session. 136 | - Add =jinx-correct-map= bound in the =jinx-correct= minibuffer. 137 | - Add navigation keys to correction UI. The commands =jinx-correct-next= and 138 | =jinx-correct-previous= are bound to the keys =M-n= and =M-p= in the 139 | =jinx-correct-map= respectively. The commands accept prefix arguments to skip 140 | over a number of misspellings. 141 | - Add quick selection keys to correction UI. The command =jinx-correct-select= is 142 | bound to the keys =1= to =9= in the =jinx-correct-map=. 143 | - Try to locate the native module =jinx-mod.so= first on the =load-path= before 144 | attempting to compile it. This is useful if the module is packed and installed 145 | separately. 146 | 147 | * Version 0.6 (2023-04-17) 148 | 149 | - Fix the type of a few characters: =.= punctuation character, ='= word character, =%= 150 | and =$= identifier characters. 151 | - Abandon =flyspell-mode-predicate= completely. Rely on faces only. 152 | - =jinx-languages=: The value must be a string now. Multiple language codes can be 153 | separated by space. 154 | - =jinx-languages=: Ask if the file-local variable should be saved when changing 155 | the language. 156 | - Add =jinx-local-words= to save file-local words. =jinx-correct= supports saving to 157 | =jinx-local-words= by pressing =*=. 158 | - Add a lighter and a minor mode menu. 159 | - Avoid scheduling the idle timer while typing a word. 160 | 161 | * Version 0.5 (2023-04-05) 162 | 163 | - Add =jinx-languages= command to switch languages locally or globally. 164 | - =jinx-correct=: When checking the whole buffer via =C-u M-$=, don't restore 165 | original point position upon =C-g= to ease cursory edits. Instead push a mark 166 | which can be used to go back to the original position. 167 | - Add =jinx-mode-map= to make it easy to bind keys if =jinx-mode= is enabled. The 168 | map is empty by default. 169 | - Ignore single quotes and apostrophes at the beginning and end of words. Please 170 | provide feedback if this is a reasonable approach. 171 | - Support spell checking of camelCased words via the =jinx-camel-modes= variable. 172 | 173 | * Version 0.4 (2023-03-27) 174 | 175 | - =jinx-languages=: Fall back to =$LANG= environment variable, since 176 | =current-locale-environment= is an Emacs 29 addition. 177 | - =jinx--mod-wordchars=: Handle non-UTF8 return values gracefully. 178 | - =jinx-correct=: Always start from nearest overlay. 179 | - =jinx-misspelled=: Use less obtrusive color for the underlining. 180 | 181 | * Version 0.3 (2023-03-27) 182 | 183 | - Add =jinx-misspelled-map=. 184 | - =jinx-correct=: Unfold invisible line when correcting misspellings. 185 | - =jinx-correct=: Show number of misspellings. 186 | - Add =emacs-module.h= to avoid compilation problems. 187 | - =jinx-languages=: Use =current-locale-environment= by default. 188 | 189 | * Version 0.2 (2023-03-26) 190 | 191 | - Start of changelog. 192 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | #+title: jinx.el - Enchanted Spell Checker 2 | #+author: Daniel Mendler 3 | #+language: en 4 | #+export_file_name: jinx.texi 5 | #+texinfo_dir_category: Emacs misc features 6 | #+texinfo_dir_title: Jinx: (jinx). 7 | #+texinfo_dir_desc: Enchanted Spell Checker 8 | 9 | #+html: GNU Emacs 10 | #+html: GNU ELPA 11 | #+html: GNU-devel ELPA 12 | #+html: MELPA 13 | #+html: MELPA Stable 14 | 15 | Jinx is a fast just-in-time spell-checker for Emacs. Jinx highlights misspelled 16 | words in the text of the visible portion of the buffer. For efficiency, Jinx 17 | highlights misspellings lazily, recognizes window boundaries and text folding, 18 | if any. For example, when unfolding or scrolling, only the newly visible part of 19 | the text is checked if it has not been checked before. Each misspelling can be 20 | corrected from a list of dictionary words presented as a completion menu. 21 | 22 | Installing Jinx is straight-forward and configuring should not need much 23 | intervention. Jinx can be used completely on its own, but can also safely 24 | co-exist with Emacs's built-in spell-checker Ispell. 25 | 26 | Jinx's high performance and low resource usage comes from directly calling the 27 | API of the [[https://rrthomas.github.io/enchant/][Enchant library]]. Jinx automatically compiles =jinx-mod.c= and loads the 28 | dynamic module at startup. By binding directly to the native Enchant API, Jinx 29 | avoids slower inter-process communication. Enchant is used by other text editors 30 | and supports multiple backends like [[https://nuspell.github.io/][Nuspell]], [[http://hunspell.github.io/][Hunspell]] and [[http://aspell.net/][Aspell]]. 31 | 32 | Jinx supports spell-checking multiple languages in the same buffer. See the 33 | =jinx-languages= variable to customize for multiple languages. Jinx can flexibly 34 | ignore misspellings via faces (=jinx-exclude-faces= and =jinx-include-faces=), 35 | regular expressions (=jinx-exclude-regexps=), and programmable predicates. Jinx 36 | comes preconfigured for the most important Emacs major modes. Modes like 37 | JavaScript, TypeScript, Java, Ruby or Rust are listed in =jinx-camel-modes=. For 38 | these modes composite words in =camelCase= and =PascalCase= are accepted. 39 | 40 | #+html: 41 | 42 | * Installation 43 | 44 | Jinx can be installed from GNU ELPA or MELPA directly with =package-install=. 45 | 46 | Most importantly your Emacs must be compiled with dynamic module support. Jinx 47 | requires =libenchant=, which is needed to compile the native module at install 48 | time. If =pkgconf= or =pkg-config= is available, Jinx will use it to locate 49 | =libenchant= during installation. Depending on your BSD or Linux distribution you 50 | have to install different packages: 51 | 52 | - Debian, Ubuntu: =libenchant-2-dev=, =pkgconf= 53 | - Arch, Gentoo: =enchant=, =pkgconf= 54 | - Guix: =emacs-jinx= defined in =emacs-xyz.scm= 55 | - Nix: =jinx= defined in =elpa-packages.nix= 56 | - Void, Fedora: =enchant2-devel=, =pkgconf= 57 | - OpenSUSE: =emacs-jinx= or =enchant=, =pkgconf= 58 | - FreeBSD, OpenBSD, Mac: =enchant2=, =pkgconf= 59 | 60 | On Windows the installation of the native module may require manual 61 | intervention. 62 | 63 | * Configuration 64 | 65 | Jinx has two modes: the command, =global-jinx-mode= activates globally; and the 66 | command, =jinx-mode=, for activating for specific modes. 67 | 68 | #+begin_src emacs-lisp 69 | ;; Alternative 1: Enable Jinx globally 70 | (add-hook 'emacs-startup-hook #'global-jinx-mode) 71 | 72 | ;; Alternative 2: Enable Jinx per mode 73 | (dolist (hook '(text-mode-hook prog-mode-hook conf-mode-hook)) 74 | (add-hook hook #'jinx-mode)) 75 | #+end_src 76 | 77 | The commands =jinx-correct= and =jinx-languages= are marked as autoloads. Invoking 78 | =jinx-correct= corrects the misspellings. Binding =jinx-correct= to =M-$= takes over 79 | that key from the default assignment to =ispell-word=. Since Jinx is independent 80 | of the Ispell package, =M-$= can be re-used. 81 | 82 | #+begin_src emacs-lisp 83 | (keymap-global-set "M-$" #'jinx-correct) 84 | (keymap-global-set "C-M-$" #'jinx-languages) 85 | #+end_src 86 | 87 | - =M-$= triggers correction for the misspelled word before point. 88 | - =C-u M-$= triggers correction for the entire buffer. 89 | - =C-u C-u M-$= forces correction of the word at point, even if it is not 90 | misspelled. 91 | 92 | A sample configuration with the popular =use-package= macro is shown here: 93 | 94 | #+begin_src emacs-lisp 95 | (use-package jinx 96 | :hook (emacs-startup . global-jinx-mode) 97 | :bind (("M-$" . jinx-correct) 98 | ("C-M-$" . jinx-languages))) 99 | #+end_src 100 | 101 | See also the [[https://github.com/minad/jinx/wiki][Jinx Wiki]] for additional configuration tips. The wiki documents 102 | configurations to save misspellings as global abbreviations and support for 103 | Ispell =LocalWords=. 104 | 105 | * Correcting misspellings 106 | 107 | The easiest way to correct a misspelling is to right click on the word, 108 | underlined with a wavy line. Then a context menu will open where you can select 109 | from suggestions. 110 | 111 | If you prefer to use the keyboard, invoke the command =jinx-correct=. The 112 | recommended binding is =M-$=, see the configuration section. Suggested corrections 113 | will be displayed as a completion menu. You can press the displayed digit keys 114 | to quickly select a suggestion. Furthermore the menu offers options to save the 115 | word temporarily for the current session, in the personal dictionary or in the 116 | file-local or directory-local variables. 117 | 118 | You can enter arbitrary input at the correction prompt in order to make the 119 | correction or to store a modified word in the personal dictionary. For example 120 | if you typed =alotriomorpc=, the prompt offers you the option =@alotriomorpc= which 121 | would add this word to your personal dictionary upon selection. You can then 122 | correct the option to =@allotriomorphic= and add it to the dictionary. 123 | 124 | While inside the =jinx-correct= prompt, the keys =M-n= and =M-p= are bound to 125 | =jinx-next= and =jinx-previous= respectively and allow you to move the next and 126 | previous misspelled word. 127 | 128 | The completion menu is compatible with all popular completion UIs: Vertico, Mct, 129 | Icomplete, Ivy, Helm and the default completions buffer. In case you use Vertico 130 | I suggest that you tweak the completion display via =vertico-multiform-mode= for 131 | the completion category =jinx=. You can for example use the grid display such that 132 | more suggestions fit on the screen and enable annotations. 133 | 134 | #+begin_src emacs-lisp 135 | (add-to-list 'vertico-multiform-categories 136 | '(jinx grid (vertico-grid-annotate . 20) (vertico-count . 4))) 137 | (vertico-multiform-mode) 138 | #+end_src 139 | 140 | * Navigating between misspellings 141 | 142 | When correcting a word with =jinx-correct=, the movement commands =jinx-next= and 143 | =jinx-previous= are available on the keys =M-n= and =M-p= to navigate to the next and 144 | previous misspelling respectively. The movement commands work from within the 145 | minibuffer during =jinx-correct= and also globally outside the minibuffer context. 146 | 147 | While the commands are not bound globally by default, they are available as =M-n= 148 | and =M-p= if point is placed on top of a misspelled word overlay. If you want you 149 | can add them and other commands to the =jinx-mode-map=, such that they are always 150 | available independent of point placement. If =repeat-mode= from Emacs 28 is 151 | enabled, the movement can be repeated with the keys =n= and =p=. 152 | 153 | * Enchant backends and personal dictionaries 154 | 155 | Enchant uses different backends for different languages. The backends are 156 | ordered as specified in the personal configuration file 157 | =~/.config/enchant/enchant.ordering= and the system-wide configuration file 158 | =/usr/share/enchant-2/enchant.ordering=. Enchant uses Hunspell as default backend 159 | for most languages. For English Enchant prefers Aspell and for Finnish and 160 | Turkish special backends called Voikko and Zemberek are used. 161 | 162 | Depending on the backend the personal dictionary will be taken from different 163 | locations, e.g., =~/.aspell.LANG.pws= or =~/.config/enchant/LANG.dic=. It is 164 | possible to symlink different personal dictionaries such that they are shared by 165 | different spell checkers. See the [[https://rrthomas.github.io/enchant/lib/enchant.html][Enchant manual]] for details. 166 | 167 | * Alternatives 168 | 169 | There exist multiple alternative spell-checking packages for Emacs, most 170 | famously the builtin ispell.el and flyspell.el packages. The main advantages of 171 | Jinx are its automatic checking of the visible text, its sharp focus on 172 | performance and the ability to easily use multiple dictionaries at once. The 173 | following three alternative packages come closest to the behavior of Jinx. 174 | 175 | - [[https://github.com/astoff/jit-spell][jit-spell]]: Jinx borrows ideas from Augusto Stoffel's Jit-spell. Jit-spell uses 176 | the less efficient Ispell process communication instead of Jinx's calling a 177 | native API. Since Jit-spell does not restrict spell checking to the visible 178 | text only, it may enqueue the entire buffer too eagerly for checking. This 179 | happens when scrolling around or when stealth font locking is enabled. For 180 | this reason, Jit-spell affected load and latency in my tests ([[https://github.com/astoff/jit-spell/issues/9][issue on Github]]). 181 | 182 | - [[https://codeberg.org/ideasman42/emacs-spell-fu][spell-fu]]: The idea to check words just in the visible text came from Campbell 183 | Barton's spell-fu package. Spell-fu is fast but incurs high memory overhead on 184 | account of its dictionary in a hash table. For languages with compound words 185 | and inflected word forms, this overhead magnifies ([[https://codeberg.org/ideasman42/emacs-spell-fu/issues/40][issue on Codeberg]]). By 186 | accessing the Enchant API directly, Jinx avoids any overhead. Jinx also 187 | benefits from the advanced spell-checker algorithms of Enchant (affixation, 188 | compound words, etc.). 189 | 190 | - flyspell: Flyspell is a built-in package. Flyspell highlights misspellings 191 | while typing. Only the word under the cursor is spell-checked. Jinx, on the 192 | other hand, is more effective because it automatically checks for misspellings 193 | in the entire visible text of the buffer at once. Flyspell can check the 194 | entire buffer but must be instructed to do so via the command =flyspell-buffer=. 195 | 196 | * Contributions 197 | 198 | Since this package is part of [[https://elpa.gnu.org/packages/jinx.html][GNU ELPA]] contributions require a copyright 199 | assignment to the FSF. 200 | -------------------------------------------------------------------------------- /emacs-module.h: -------------------------------------------------------------------------------- 1 | /* emacs-module.h - GNU Emacs module API. 2 | 3 | Copyright (C) 2015-2021 Free Software Foundation, Inc. 4 | 5 | This file is part of GNU Emacs. 6 | 7 | GNU Emacs is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or (at 10 | your option) any later version. 11 | 12 | GNU Emacs is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with GNU Emacs. If not, see . */ 19 | 20 | /* 21 | This file defines the Emacs module API. Please see the chapter 22 | `Dynamic Modules' in the GNU Emacs Lisp Reference Manual for 23 | information how to write modules and use this header file. 24 | */ 25 | 26 | #ifndef EMACS_MODULE_H 27 | #define EMACS_MODULE_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #ifndef __cplusplus 34 | #include 35 | #endif 36 | 37 | #define EMACS_MAJOR_VERSION 28 38 | 39 | #if defined __cplusplus && __cplusplus >= 201103L 40 | # define EMACS_NOEXCEPT noexcept 41 | #else 42 | # define EMACS_NOEXCEPT 43 | #endif 44 | 45 | #if defined __cplusplus && __cplusplus >= 201703L 46 | # define EMACS_NOEXCEPT_TYPEDEF noexcept 47 | #else 48 | # define EMACS_NOEXCEPT_TYPEDEF 49 | #endif 50 | 51 | #if 3 < __GNUC__ + (3 <= __GNUC_MINOR__) 52 | # define EMACS_ATTRIBUTE_NONNULL(...) \ 53 | __attribute__ ((__nonnull__ (__VA_ARGS__))) 54 | #elif (defined __has_attribute \ 55 | && (!defined __clang_minor__ \ 56 | || 3 < __clang_major__ + (5 <= __clang_minor__))) 57 | # if __has_attribute (__nonnull__) 58 | # define EMACS_ATTRIBUTE_NONNULL(...) \ 59 | __attribute__ ((__nonnull__ (__VA_ARGS__))) 60 | # endif 61 | #endif 62 | #ifndef EMACS_ATTRIBUTE_NONNULL 63 | # define EMACS_ATTRIBUTE_NONNULL(...) 64 | #endif 65 | 66 | #ifdef __cplusplus 67 | extern "C" { 68 | #endif 69 | 70 | /* Current environment. */ 71 | typedef struct emacs_env_28 emacs_env; 72 | 73 | /* Opaque pointer representing an Emacs Lisp value. 74 | BEWARE: Do not assume NULL is a valid value! */ 75 | typedef struct emacs_value_tag *emacs_value; 76 | 77 | enum { emacs_variadic_function = -2 }; 78 | 79 | /* Struct passed to a module init function (emacs_module_init). */ 80 | struct emacs_runtime 81 | { 82 | /* Structure size (for version checking). */ 83 | ptrdiff_t size; 84 | 85 | /* Private data; users should not touch this. */ 86 | struct emacs_runtime_private *private_members; 87 | 88 | /* Return an environment pointer. */ 89 | emacs_env *(*get_environment) (struct emacs_runtime *runtime) 90 | EMACS_ATTRIBUTE_NONNULL (1); 91 | }; 92 | 93 | /* Type aliases for function pointer types used in the module API. 94 | Note that we don't use these aliases directly in the API to be able 95 | to mark the function arguments as 'noexcept' before C++20. 96 | However, users can use them if they want. */ 97 | 98 | /* Function prototype for the module Lisp functions. These must not 99 | throw C++ exceptions. */ 100 | typedef emacs_value (*emacs_function) (emacs_env *env, ptrdiff_t nargs, 101 | emacs_value *args, 102 | void *data) 103 | EMACS_NOEXCEPT_TYPEDEF EMACS_ATTRIBUTE_NONNULL (1); 104 | 105 | /* Function prototype for module user-pointer and function finalizers. 106 | These must not throw C++ exceptions. */ 107 | typedef void (*emacs_finalizer) (void *data) EMACS_NOEXCEPT_TYPEDEF; 108 | 109 | /* Possible Emacs function call outcomes. */ 110 | enum emacs_funcall_exit 111 | { 112 | /* Function has returned normally. */ 113 | emacs_funcall_exit_return = 0, 114 | 115 | /* Function has signaled an error using `signal'. */ 116 | emacs_funcall_exit_signal = 1, 117 | 118 | /* Function has exit using `throw'. */ 119 | emacs_funcall_exit_throw = 2 120 | }; 121 | 122 | /* Possible return values for emacs_env.process_input. */ 123 | enum emacs_process_input_result 124 | { 125 | /* Module code may continue */ 126 | emacs_process_input_continue = 0, 127 | 128 | /* Module code should return control to Emacs as soon as possible. */ 129 | emacs_process_input_quit = 1 130 | }; 131 | 132 | /* Define emacs_limb_t so that it is likely to match GMP's mp_limb_t. 133 | This micro-optimization can help modules that use mpz_export and 134 | mpz_import, which operate more efficiently on mp_limb_t. It's OK 135 | (if perhaps a bit slower) if the two types do not match, and 136 | modules shouldn't rely on the two types matching. */ 137 | typedef size_t emacs_limb_t; 138 | #define EMACS_LIMB_MAX SIZE_MAX 139 | 140 | struct emacs_env_25 141 | { 142 | /* Structure size (for version checking). */ 143 | ptrdiff_t size; 144 | 145 | /* Private data; users should not touch this. */ 146 | struct emacs_env_private *private_members; 147 | 148 | /* Memory management. */ 149 | 150 | emacs_value (*make_global_ref) (emacs_env *env, emacs_value value) 151 | EMACS_ATTRIBUTE_NONNULL(1); 152 | 153 | void (*free_global_ref) (emacs_env *env, emacs_value global_value) 154 | EMACS_ATTRIBUTE_NONNULL(1); 155 | 156 | /* Non-local exit handling. */ 157 | 158 | enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env) 159 | EMACS_ATTRIBUTE_NONNULL(1); 160 | 161 | void (*non_local_exit_clear) (emacs_env *env) 162 | EMACS_ATTRIBUTE_NONNULL(1); 163 | 164 | enum emacs_funcall_exit (*non_local_exit_get) 165 | (emacs_env *env, emacs_value *symbol, emacs_value *data) 166 | EMACS_ATTRIBUTE_NONNULL(1, 2, 3); 167 | 168 | void (*non_local_exit_signal) (emacs_env *env, 169 | emacs_value symbol, emacs_value data) 170 | EMACS_ATTRIBUTE_NONNULL(1); 171 | 172 | void (*non_local_exit_throw) (emacs_env *env, 173 | emacs_value tag, emacs_value value) 174 | EMACS_ATTRIBUTE_NONNULL(1); 175 | 176 | /* Function registration. */ 177 | 178 | emacs_value (*make_function) (emacs_env *env, 179 | ptrdiff_t min_arity, 180 | ptrdiff_t max_arity, 181 | emacs_value (*func) (emacs_env *env, 182 | ptrdiff_t nargs, 183 | emacs_value* args, 184 | void *data) 185 | EMACS_NOEXCEPT 186 | EMACS_ATTRIBUTE_NONNULL(1), 187 | const char *docstring, 188 | void *data) 189 | EMACS_ATTRIBUTE_NONNULL(1, 4); 190 | 191 | emacs_value (*funcall) (emacs_env *env, 192 | emacs_value func, 193 | ptrdiff_t nargs, 194 | emacs_value* args) 195 | EMACS_ATTRIBUTE_NONNULL(1); 196 | 197 | emacs_value (*intern) (emacs_env *env, const char *name) 198 | EMACS_ATTRIBUTE_NONNULL(1, 2); 199 | 200 | /* Type conversion. */ 201 | 202 | emacs_value (*type_of) (emacs_env *env, emacs_value arg) 203 | EMACS_ATTRIBUTE_NONNULL(1); 204 | 205 | bool (*is_not_nil) (emacs_env *env, emacs_value arg) 206 | EMACS_ATTRIBUTE_NONNULL(1); 207 | 208 | bool (*eq) (emacs_env *env, emacs_value a, emacs_value b) 209 | EMACS_ATTRIBUTE_NONNULL(1); 210 | 211 | intmax_t (*extract_integer) (emacs_env *env, emacs_value arg) 212 | EMACS_ATTRIBUTE_NONNULL(1); 213 | 214 | emacs_value (*make_integer) (emacs_env *env, intmax_t n) 215 | EMACS_ATTRIBUTE_NONNULL(1); 216 | 217 | double (*extract_float) (emacs_env *env, emacs_value arg) 218 | EMACS_ATTRIBUTE_NONNULL(1); 219 | 220 | emacs_value (*make_float) (emacs_env *env, double d) 221 | EMACS_ATTRIBUTE_NONNULL(1); 222 | 223 | /* Copy the content of the Lisp string VALUE to BUFFER as an utf8 224 | null-terminated string. 225 | 226 | SIZE must point to the total size of the buffer. If BUFFER is 227 | NULL or if SIZE is not big enough, write the required buffer size 228 | to SIZE and return true. 229 | 230 | Note that SIZE must include the last null byte (e.g. "abc" needs 231 | a buffer of size 4). 232 | 233 | Return true if the string was successfully copied. */ 234 | 235 | bool (*copy_string_contents) (emacs_env *env, 236 | emacs_value value, 237 | char *buf, 238 | ptrdiff_t *len) 239 | EMACS_ATTRIBUTE_NONNULL(1, 4); 240 | 241 | /* Create a Lisp string from a utf8 encoded string. */ 242 | emacs_value (*make_string) (emacs_env *env, 243 | const char *str, ptrdiff_t len) 244 | EMACS_ATTRIBUTE_NONNULL(1, 2); 245 | 246 | /* Embedded pointer type. */ 247 | emacs_value (*make_user_ptr) (emacs_env *env, 248 | void (*fin) (void *) EMACS_NOEXCEPT, 249 | void *ptr) 250 | EMACS_ATTRIBUTE_NONNULL(1); 251 | 252 | void *(*get_user_ptr) (emacs_env *env, emacs_value arg) 253 | EMACS_ATTRIBUTE_NONNULL(1); 254 | void (*set_user_ptr) (emacs_env *env, emacs_value arg, void *ptr) 255 | EMACS_ATTRIBUTE_NONNULL(1); 256 | 257 | void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr)) 258 | (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1); 259 | void (*set_user_finalizer) (emacs_env *env, emacs_value arg, 260 | void (*fin) (void *) EMACS_NOEXCEPT) 261 | EMACS_ATTRIBUTE_NONNULL(1); 262 | 263 | /* Vector functions. */ 264 | emacs_value (*vec_get) (emacs_env *env, emacs_value vector, ptrdiff_t index) 265 | EMACS_ATTRIBUTE_NONNULL(1); 266 | 267 | void (*vec_set) (emacs_env *env, emacs_value vector, ptrdiff_t index, 268 | emacs_value value) 269 | EMACS_ATTRIBUTE_NONNULL(1); 270 | 271 | ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vector) 272 | EMACS_ATTRIBUTE_NONNULL(1); 273 | }; 274 | 275 | struct emacs_env_26 276 | { 277 | /* Structure size (for version checking). */ 278 | ptrdiff_t size; 279 | 280 | /* Private data; users should not touch this. */ 281 | struct emacs_env_private *private_members; 282 | 283 | /* Memory management. */ 284 | 285 | emacs_value (*make_global_ref) (emacs_env *env, emacs_value value) 286 | EMACS_ATTRIBUTE_NONNULL(1); 287 | 288 | void (*free_global_ref) (emacs_env *env, emacs_value global_value) 289 | EMACS_ATTRIBUTE_NONNULL(1); 290 | 291 | /* Non-local exit handling. */ 292 | 293 | enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env) 294 | EMACS_ATTRIBUTE_NONNULL(1); 295 | 296 | void (*non_local_exit_clear) (emacs_env *env) 297 | EMACS_ATTRIBUTE_NONNULL(1); 298 | 299 | enum emacs_funcall_exit (*non_local_exit_get) 300 | (emacs_env *env, emacs_value *symbol, emacs_value *data) 301 | EMACS_ATTRIBUTE_NONNULL(1, 2, 3); 302 | 303 | void (*non_local_exit_signal) (emacs_env *env, 304 | emacs_value symbol, emacs_value data) 305 | EMACS_ATTRIBUTE_NONNULL(1); 306 | 307 | void (*non_local_exit_throw) (emacs_env *env, 308 | emacs_value tag, emacs_value value) 309 | EMACS_ATTRIBUTE_NONNULL(1); 310 | 311 | /* Function registration. */ 312 | 313 | emacs_value (*make_function) (emacs_env *env, 314 | ptrdiff_t min_arity, 315 | ptrdiff_t max_arity, 316 | emacs_value (*func) (emacs_env *env, 317 | ptrdiff_t nargs, 318 | emacs_value* args, 319 | void *data) 320 | EMACS_NOEXCEPT 321 | EMACS_ATTRIBUTE_NONNULL(1), 322 | const char *docstring, 323 | void *data) 324 | EMACS_ATTRIBUTE_NONNULL(1, 4); 325 | 326 | emacs_value (*funcall) (emacs_env *env, 327 | emacs_value func, 328 | ptrdiff_t nargs, 329 | emacs_value* args) 330 | EMACS_ATTRIBUTE_NONNULL(1); 331 | 332 | emacs_value (*intern) (emacs_env *env, const char *name) 333 | EMACS_ATTRIBUTE_NONNULL(1, 2); 334 | 335 | /* Type conversion. */ 336 | 337 | emacs_value (*type_of) (emacs_env *env, emacs_value arg) 338 | EMACS_ATTRIBUTE_NONNULL(1); 339 | 340 | bool (*is_not_nil) (emacs_env *env, emacs_value arg) 341 | EMACS_ATTRIBUTE_NONNULL(1); 342 | 343 | bool (*eq) (emacs_env *env, emacs_value a, emacs_value b) 344 | EMACS_ATTRIBUTE_NONNULL(1); 345 | 346 | intmax_t (*extract_integer) (emacs_env *env, emacs_value arg) 347 | EMACS_ATTRIBUTE_NONNULL(1); 348 | 349 | emacs_value (*make_integer) (emacs_env *env, intmax_t n) 350 | EMACS_ATTRIBUTE_NONNULL(1); 351 | 352 | double (*extract_float) (emacs_env *env, emacs_value arg) 353 | EMACS_ATTRIBUTE_NONNULL(1); 354 | 355 | emacs_value (*make_float) (emacs_env *env, double d) 356 | EMACS_ATTRIBUTE_NONNULL(1); 357 | 358 | /* Copy the content of the Lisp string VALUE to BUFFER as an utf8 359 | null-terminated string. 360 | 361 | SIZE must point to the total size of the buffer. If BUFFER is 362 | NULL or if SIZE is not big enough, write the required buffer size 363 | to SIZE and return true. 364 | 365 | Note that SIZE must include the last null byte (e.g. "abc" needs 366 | a buffer of size 4). 367 | 368 | Return true if the string was successfully copied. */ 369 | 370 | bool (*copy_string_contents) (emacs_env *env, 371 | emacs_value value, 372 | char *buf, 373 | ptrdiff_t *len) 374 | EMACS_ATTRIBUTE_NONNULL(1, 4); 375 | 376 | /* Create a Lisp string from a utf8 encoded string. */ 377 | emacs_value (*make_string) (emacs_env *env, 378 | const char *str, ptrdiff_t len) 379 | EMACS_ATTRIBUTE_NONNULL(1, 2); 380 | 381 | /* Embedded pointer type. */ 382 | emacs_value (*make_user_ptr) (emacs_env *env, 383 | void (*fin) (void *) EMACS_NOEXCEPT, 384 | void *ptr) 385 | EMACS_ATTRIBUTE_NONNULL(1); 386 | 387 | void *(*get_user_ptr) (emacs_env *env, emacs_value arg) 388 | EMACS_ATTRIBUTE_NONNULL(1); 389 | void (*set_user_ptr) (emacs_env *env, emacs_value arg, void *ptr) 390 | EMACS_ATTRIBUTE_NONNULL(1); 391 | 392 | void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr)) 393 | (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1); 394 | void (*set_user_finalizer) (emacs_env *env, emacs_value arg, 395 | void (*fin) (void *) EMACS_NOEXCEPT) 396 | EMACS_ATTRIBUTE_NONNULL(1); 397 | 398 | /* Vector functions. */ 399 | emacs_value (*vec_get) (emacs_env *env, emacs_value vector, ptrdiff_t index) 400 | EMACS_ATTRIBUTE_NONNULL(1); 401 | 402 | void (*vec_set) (emacs_env *env, emacs_value vector, ptrdiff_t index, 403 | emacs_value value) 404 | EMACS_ATTRIBUTE_NONNULL(1); 405 | 406 | ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vector) 407 | EMACS_ATTRIBUTE_NONNULL(1); 408 | 409 | /* Returns whether a quit is pending. */ 410 | bool (*should_quit) (emacs_env *env) 411 | EMACS_ATTRIBUTE_NONNULL(1); 412 | }; 413 | 414 | struct emacs_env_27 415 | { 416 | /* Structure size (for version checking). */ 417 | ptrdiff_t size; 418 | 419 | /* Private data; users should not touch this. */ 420 | struct emacs_env_private *private_members; 421 | 422 | /* Memory management. */ 423 | 424 | emacs_value (*make_global_ref) (emacs_env *env, emacs_value value) 425 | EMACS_ATTRIBUTE_NONNULL(1); 426 | 427 | void (*free_global_ref) (emacs_env *env, emacs_value global_value) 428 | EMACS_ATTRIBUTE_NONNULL(1); 429 | 430 | /* Non-local exit handling. */ 431 | 432 | enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env) 433 | EMACS_ATTRIBUTE_NONNULL(1); 434 | 435 | void (*non_local_exit_clear) (emacs_env *env) 436 | EMACS_ATTRIBUTE_NONNULL(1); 437 | 438 | enum emacs_funcall_exit (*non_local_exit_get) 439 | (emacs_env *env, emacs_value *symbol, emacs_value *data) 440 | EMACS_ATTRIBUTE_NONNULL(1, 2, 3); 441 | 442 | void (*non_local_exit_signal) (emacs_env *env, 443 | emacs_value symbol, emacs_value data) 444 | EMACS_ATTRIBUTE_NONNULL(1); 445 | 446 | void (*non_local_exit_throw) (emacs_env *env, 447 | emacs_value tag, emacs_value value) 448 | EMACS_ATTRIBUTE_NONNULL(1); 449 | 450 | /* Function registration. */ 451 | 452 | emacs_value (*make_function) (emacs_env *env, 453 | ptrdiff_t min_arity, 454 | ptrdiff_t max_arity, 455 | emacs_value (*func) (emacs_env *env, 456 | ptrdiff_t nargs, 457 | emacs_value* args, 458 | void *data) 459 | EMACS_NOEXCEPT 460 | EMACS_ATTRIBUTE_NONNULL(1), 461 | const char *docstring, 462 | void *data) 463 | EMACS_ATTRIBUTE_NONNULL(1, 4); 464 | 465 | emacs_value (*funcall) (emacs_env *env, 466 | emacs_value func, 467 | ptrdiff_t nargs, 468 | emacs_value* args) 469 | EMACS_ATTRIBUTE_NONNULL(1); 470 | 471 | emacs_value (*intern) (emacs_env *env, const char *name) 472 | EMACS_ATTRIBUTE_NONNULL(1, 2); 473 | 474 | /* Type conversion. */ 475 | 476 | emacs_value (*type_of) (emacs_env *env, emacs_value arg) 477 | EMACS_ATTRIBUTE_NONNULL(1); 478 | 479 | bool (*is_not_nil) (emacs_env *env, emacs_value arg) 480 | EMACS_ATTRIBUTE_NONNULL(1); 481 | 482 | bool (*eq) (emacs_env *env, emacs_value a, emacs_value b) 483 | EMACS_ATTRIBUTE_NONNULL(1); 484 | 485 | intmax_t (*extract_integer) (emacs_env *env, emacs_value arg) 486 | EMACS_ATTRIBUTE_NONNULL(1); 487 | 488 | emacs_value (*make_integer) (emacs_env *env, intmax_t n) 489 | EMACS_ATTRIBUTE_NONNULL(1); 490 | 491 | double (*extract_float) (emacs_env *env, emacs_value arg) 492 | EMACS_ATTRIBUTE_NONNULL(1); 493 | 494 | emacs_value (*make_float) (emacs_env *env, double d) 495 | EMACS_ATTRIBUTE_NONNULL(1); 496 | 497 | /* Copy the content of the Lisp string VALUE to BUFFER as an utf8 498 | null-terminated string. 499 | 500 | SIZE must point to the total size of the buffer. If BUFFER is 501 | NULL or if SIZE is not big enough, write the required buffer size 502 | to SIZE and return true. 503 | 504 | Note that SIZE must include the last null byte (e.g. "abc" needs 505 | a buffer of size 4). 506 | 507 | Return true if the string was successfully copied. */ 508 | 509 | bool (*copy_string_contents) (emacs_env *env, 510 | emacs_value value, 511 | char *buf, 512 | ptrdiff_t *len) 513 | EMACS_ATTRIBUTE_NONNULL(1, 4); 514 | 515 | /* Create a Lisp string from a utf8 encoded string. */ 516 | emacs_value (*make_string) (emacs_env *env, 517 | const char *str, ptrdiff_t len) 518 | EMACS_ATTRIBUTE_NONNULL(1, 2); 519 | 520 | /* Embedded pointer type. */ 521 | emacs_value (*make_user_ptr) (emacs_env *env, 522 | void (*fin) (void *) EMACS_NOEXCEPT, 523 | void *ptr) 524 | EMACS_ATTRIBUTE_NONNULL(1); 525 | 526 | void *(*get_user_ptr) (emacs_env *env, emacs_value arg) 527 | EMACS_ATTRIBUTE_NONNULL(1); 528 | void (*set_user_ptr) (emacs_env *env, emacs_value arg, void *ptr) 529 | EMACS_ATTRIBUTE_NONNULL(1); 530 | 531 | void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr)) 532 | (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1); 533 | void (*set_user_finalizer) (emacs_env *env, emacs_value arg, 534 | void (*fin) (void *) EMACS_NOEXCEPT) 535 | EMACS_ATTRIBUTE_NONNULL(1); 536 | 537 | /* Vector functions. */ 538 | emacs_value (*vec_get) (emacs_env *env, emacs_value vector, ptrdiff_t index) 539 | EMACS_ATTRIBUTE_NONNULL(1); 540 | 541 | void (*vec_set) (emacs_env *env, emacs_value vector, ptrdiff_t index, 542 | emacs_value value) 543 | EMACS_ATTRIBUTE_NONNULL(1); 544 | 545 | ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vector) 546 | EMACS_ATTRIBUTE_NONNULL(1); 547 | 548 | /* Returns whether a quit is pending. */ 549 | bool (*should_quit) (emacs_env *env) 550 | EMACS_ATTRIBUTE_NONNULL(1); 551 | 552 | /* Processes pending input events and returns whether the module 553 | function should quit. */ 554 | enum emacs_process_input_result (*process_input) (emacs_env *env) 555 | EMACS_ATTRIBUTE_NONNULL (1); 556 | 557 | struct timespec (*extract_time) (emacs_env *env, emacs_value arg) 558 | EMACS_ATTRIBUTE_NONNULL (1); 559 | 560 | emacs_value (*make_time) (emacs_env *env, struct timespec time) 561 | EMACS_ATTRIBUTE_NONNULL (1); 562 | 563 | bool (*extract_big_integer) (emacs_env *env, emacs_value arg, int *sign, 564 | ptrdiff_t *count, emacs_limb_t *magnitude) 565 | EMACS_ATTRIBUTE_NONNULL (1); 566 | 567 | emacs_value (*make_big_integer) (emacs_env *env, int sign, ptrdiff_t count, 568 | const emacs_limb_t *magnitude) 569 | EMACS_ATTRIBUTE_NONNULL (1); 570 | }; 571 | 572 | struct emacs_env_28 573 | { 574 | /* Structure size (for version checking). */ 575 | ptrdiff_t size; 576 | 577 | /* Private data; users should not touch this. */ 578 | struct emacs_env_private *private_members; 579 | 580 | /* Memory management. */ 581 | 582 | emacs_value (*make_global_ref) (emacs_env *env, emacs_value value) 583 | EMACS_ATTRIBUTE_NONNULL(1); 584 | 585 | void (*free_global_ref) (emacs_env *env, emacs_value global_value) 586 | EMACS_ATTRIBUTE_NONNULL(1); 587 | 588 | /* Non-local exit handling. */ 589 | 590 | enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env) 591 | EMACS_ATTRIBUTE_NONNULL(1); 592 | 593 | void (*non_local_exit_clear) (emacs_env *env) 594 | EMACS_ATTRIBUTE_NONNULL(1); 595 | 596 | enum emacs_funcall_exit (*non_local_exit_get) 597 | (emacs_env *env, emacs_value *symbol, emacs_value *data) 598 | EMACS_ATTRIBUTE_NONNULL(1, 2, 3); 599 | 600 | void (*non_local_exit_signal) (emacs_env *env, 601 | emacs_value symbol, emacs_value data) 602 | EMACS_ATTRIBUTE_NONNULL(1); 603 | 604 | void (*non_local_exit_throw) (emacs_env *env, 605 | emacs_value tag, emacs_value value) 606 | EMACS_ATTRIBUTE_NONNULL(1); 607 | 608 | /* Function registration. */ 609 | 610 | emacs_value (*make_function) (emacs_env *env, 611 | ptrdiff_t min_arity, 612 | ptrdiff_t max_arity, 613 | emacs_value (*func) (emacs_env *env, 614 | ptrdiff_t nargs, 615 | emacs_value* args, 616 | void *data) 617 | EMACS_NOEXCEPT 618 | EMACS_ATTRIBUTE_NONNULL(1), 619 | const char *docstring, 620 | void *data) 621 | EMACS_ATTRIBUTE_NONNULL(1, 4); 622 | 623 | emacs_value (*funcall) (emacs_env *env, 624 | emacs_value func, 625 | ptrdiff_t nargs, 626 | emacs_value* args) 627 | EMACS_ATTRIBUTE_NONNULL(1); 628 | 629 | emacs_value (*intern) (emacs_env *env, const char *name) 630 | EMACS_ATTRIBUTE_NONNULL(1, 2); 631 | 632 | /* Type conversion. */ 633 | 634 | emacs_value (*type_of) (emacs_env *env, emacs_value arg) 635 | EMACS_ATTRIBUTE_NONNULL(1); 636 | 637 | bool (*is_not_nil) (emacs_env *env, emacs_value arg) 638 | EMACS_ATTRIBUTE_NONNULL(1); 639 | 640 | bool (*eq) (emacs_env *env, emacs_value a, emacs_value b) 641 | EMACS_ATTRIBUTE_NONNULL(1); 642 | 643 | intmax_t (*extract_integer) (emacs_env *env, emacs_value arg) 644 | EMACS_ATTRIBUTE_NONNULL(1); 645 | 646 | emacs_value (*make_integer) (emacs_env *env, intmax_t n) 647 | EMACS_ATTRIBUTE_NONNULL(1); 648 | 649 | double (*extract_float) (emacs_env *env, emacs_value arg) 650 | EMACS_ATTRIBUTE_NONNULL(1); 651 | 652 | emacs_value (*make_float) (emacs_env *env, double d) 653 | EMACS_ATTRIBUTE_NONNULL(1); 654 | 655 | /* Copy the content of the Lisp string VALUE to BUFFER as an utf8 656 | null-terminated string. 657 | 658 | SIZE must point to the total size of the buffer. If BUFFER is 659 | NULL or if SIZE is not big enough, write the required buffer size 660 | to SIZE and return true. 661 | 662 | Note that SIZE must include the last null byte (e.g. "abc" needs 663 | a buffer of size 4). 664 | 665 | Return true if the string was successfully copied. */ 666 | 667 | bool (*copy_string_contents) (emacs_env *env, 668 | emacs_value value, 669 | char *buf, 670 | ptrdiff_t *len) 671 | EMACS_ATTRIBUTE_NONNULL(1, 4); 672 | 673 | /* Create a Lisp string from a utf8 encoded string. */ 674 | emacs_value (*make_string) (emacs_env *env, 675 | const char *str, ptrdiff_t len) 676 | EMACS_ATTRIBUTE_NONNULL(1, 2); 677 | 678 | /* Embedded pointer type. */ 679 | emacs_value (*make_user_ptr) (emacs_env *env, 680 | void (*fin) (void *) EMACS_NOEXCEPT, 681 | void *ptr) 682 | EMACS_ATTRIBUTE_NONNULL(1); 683 | 684 | void *(*get_user_ptr) (emacs_env *env, emacs_value arg) 685 | EMACS_ATTRIBUTE_NONNULL(1); 686 | void (*set_user_ptr) (emacs_env *env, emacs_value arg, void *ptr) 687 | EMACS_ATTRIBUTE_NONNULL(1); 688 | 689 | void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr)) 690 | (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1); 691 | void (*set_user_finalizer) (emacs_env *env, emacs_value arg, 692 | void (*fin) (void *) EMACS_NOEXCEPT) 693 | EMACS_ATTRIBUTE_NONNULL(1); 694 | 695 | /* Vector functions. */ 696 | emacs_value (*vec_get) (emacs_env *env, emacs_value vector, ptrdiff_t index) 697 | EMACS_ATTRIBUTE_NONNULL(1); 698 | 699 | void (*vec_set) (emacs_env *env, emacs_value vector, ptrdiff_t index, 700 | emacs_value value) 701 | EMACS_ATTRIBUTE_NONNULL(1); 702 | 703 | ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vector) 704 | EMACS_ATTRIBUTE_NONNULL(1); 705 | 706 | /* Returns whether a quit is pending. */ 707 | bool (*should_quit) (emacs_env *env) 708 | EMACS_ATTRIBUTE_NONNULL(1); 709 | 710 | /* Processes pending input events and returns whether the module 711 | function should quit. */ 712 | enum emacs_process_input_result (*process_input) (emacs_env *env) 713 | EMACS_ATTRIBUTE_NONNULL (1); 714 | 715 | struct timespec (*extract_time) (emacs_env *env, emacs_value arg) 716 | EMACS_ATTRIBUTE_NONNULL (1); 717 | 718 | emacs_value (*make_time) (emacs_env *env, struct timespec time) 719 | EMACS_ATTRIBUTE_NONNULL (1); 720 | 721 | bool (*extract_big_integer) (emacs_env *env, emacs_value arg, int *sign, 722 | ptrdiff_t *count, emacs_limb_t *magnitude) 723 | EMACS_ATTRIBUTE_NONNULL (1); 724 | 725 | emacs_value (*make_big_integer) (emacs_env *env, int sign, ptrdiff_t count, 726 | const emacs_limb_t *magnitude) 727 | EMACS_ATTRIBUTE_NONNULL (1); 728 | 729 | /* Add module environment functions newly added in Emacs 28 here. 730 | Before Emacs 28 is released, remove this comment and start 731 | module-env-29.h on the master branch. */ 732 | 733 | void (*(*EMACS_ATTRIBUTE_NONNULL (1) 734 | get_function_finalizer) (emacs_env *env, 735 | emacs_value arg)) (void *) EMACS_NOEXCEPT; 736 | 737 | void (*set_function_finalizer) (emacs_env *env, emacs_value arg, 738 | void (*fin) (void *) EMACS_NOEXCEPT) 739 | EMACS_ATTRIBUTE_NONNULL (1); 740 | 741 | int (*open_channel) (emacs_env *env, emacs_value pipe_process) 742 | EMACS_ATTRIBUTE_NONNULL (1); 743 | 744 | void (*make_interactive) (emacs_env *env, emacs_value function, 745 | emacs_value spec) 746 | EMACS_ATTRIBUTE_NONNULL (1); 747 | 748 | /* Create a unibyte Lisp string from a string. */ 749 | emacs_value (*make_unibyte_string) (emacs_env *env, 750 | const char *str, ptrdiff_t len) 751 | EMACS_ATTRIBUTE_NONNULL(1, 2); 752 | }; 753 | 754 | /* Every module should define a function as follows. */ 755 | extern int emacs_module_init (struct emacs_runtime *runtime) 756 | EMACS_NOEXCEPT 757 | EMACS_ATTRIBUTE_NONNULL (1); 758 | 759 | #ifdef __cplusplus 760 | } 761 | #endif 762 | 763 | #endif /* EMACS_MODULE_H */ 764 | -------------------------------------------------------------------------------- /jinx-mod.c: -------------------------------------------------------------------------------- 1 | /* Jinx bindings to libenchant 2 | 3 | Copyright (C) 2023-2025 Free Software Foundation, Inc. 4 | 5 | GNU Emacs is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or (at 8 | your option) any later version. 9 | 10 | GNU Emacs is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with GNU Emacs. If not, see . */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #define jinx_unused(var) _##var __attribute__((unused)) 24 | #define jinx_autofree __attribute__((cleanup(jinx_autofree_cleanup))) 25 | 26 | int plugin_is_GPL_compatible; 27 | 28 | static EnchantBroker* broker = 0; 29 | static emacs_value Qt, Qnil, Qcons; 30 | 31 | static EnchantBroker* jinx_broker(void) { 32 | return broker ? broker : (broker = enchant_broker_init()); 33 | } 34 | 35 | static void jinx_autofree_cleanup(char **p) { 36 | free(*(void**)p); 37 | } 38 | 39 | static emacs_value jinx_str(emacs_env* env, const char* str) { 40 | return env->make_string(env, str, strlen(str)); 41 | } 42 | 43 | static emacs_value jinx_cons(emacs_env* env, emacs_value a, emacs_value b) { 44 | return env->funcall(env, Qcons, 2, (emacs_value[]){a, b}); 45 | } 46 | 47 | static char* jinx_cstr(emacs_env* env, emacs_value val) { 48 | ptrdiff_t size = 0; 49 | if (!env->copy_string_contents(env, val, 0, &size)) 50 | return 0; 51 | char* str = malloc(size); 52 | if (!str) { 53 | env->non_local_exit_signal(env, 54 | env->intern(env, "memory-full"), 55 | Qnil); 56 | return 0; 57 | } 58 | if (!env->copy_string_contents(env, val, str, &size)) { 59 | free(str); 60 | return 0; 61 | } 62 | return str; 63 | } 64 | 65 | static void jinx_defun(emacs_env* env, const char* name, 66 | ptrdiff_t min, ptrdiff_t max, void* fun) { 67 | env->funcall(env, env->intern(env, "defalias"), 2, 68 | (emacs_value[]){ 69 | env->intern(env, name), 70 | env->make_function(env, min, max, fun, 0, 0) 71 | }); 72 | } 73 | 74 | static void jinx_free_dict(void* dict) { 75 | enchant_broker_free_dict(broker, dict); 76 | } 77 | 78 | static emacs_value jinx_dict(emacs_env* env, ptrdiff_t jinx_unused(nargs), 79 | emacs_value args[], void* jinx_unused(data)) { 80 | jinx_autofree char* str = jinx_cstr(env, args[0]); 81 | EnchantDict* dict = 82 | str ? enchant_broker_request_dict(jinx_broker(), str) : 0; 83 | return dict 84 | ? env->make_user_ptr(env, jinx_free_dict, dict) 85 | : Qnil; 86 | } 87 | 88 | static void jinx_describe_cb(const char* const lang_tag, 89 | const char* const provider_name, 90 | const char* const jinx_unused(provider_desc), 91 | const char* const jinx_unused(provider_file), 92 | void* data) { 93 | emacs_env* env = ((emacs_env**)data)[0]; 94 | ((emacs_value*)data)[1] = jinx_cons(env, 95 | jinx_str(env, lang_tag), 96 | jinx_str(env, provider_name)); 97 | } 98 | 99 | static emacs_value jinx_describe(emacs_env* env, ptrdiff_t jinx_unused(nargs), 100 | emacs_value args[], void* jinx_unused(data)) { 101 | EnchantDict* dict = env->get_user_ptr(env, args[0]); 102 | if (!dict) 103 | return Qnil; 104 | void* data[] = { env, 0 }; 105 | enchant_dict_describe(dict, jinx_describe_cb, data); 106 | return data[1]; 107 | } 108 | 109 | static void jinx_langs_cb(const char* const lang_tag, 110 | const char* const provider_name, 111 | const char* const jinx_unused(provider_desc), 112 | const char* const jinx_unused(provider_file), 113 | void* data) { 114 | emacs_env* env = ((emacs_env**)data)[0]; 115 | ((emacs_value*)data)[1] = jinx_cons(env, 116 | jinx_cons(env, 117 | jinx_str(env, lang_tag), 118 | jinx_str(env, provider_name)), 119 | ((emacs_value*)data)[1]); 120 | } 121 | 122 | static emacs_value jinx_langs(emacs_env* env, ptrdiff_t jinx_unused(nargs), 123 | emacs_value jinx_unused(args[]), 124 | void* jinx_unused(data)) { 125 | void* data[] = { env, Qnil }; 126 | enchant_broker_list_dicts(jinx_broker(), jinx_langs_cb, data); 127 | return data[1]; 128 | } 129 | 130 | static emacs_value jinx_check(emacs_env* env, ptrdiff_t jinx_unused(nargs), 131 | emacs_value args[], void* jinx_unused(data)) { 132 | EnchantDict* dict = env->get_user_ptr(env, args[0]); 133 | jinx_autofree char* str = jinx_cstr(env, args[1]); 134 | // Do not error in the checking function (Non-Unicode strings) 135 | env->non_local_exit_clear(env); 136 | return !dict || !str || enchant_dict_check(dict, str, -1) ? Qnil : Qt; 137 | } 138 | 139 | static emacs_value jinx_add(emacs_env* env, ptrdiff_t jinx_unused(nargs), 140 | emacs_value args[], void* jinx_unused(data)) { 141 | EnchantDict* dict = env->get_user_ptr(env, args[0]); 142 | jinx_autofree char* str = jinx_cstr(env, args[1]); 143 | if (dict && str) 144 | enchant_dict_add(dict, str, -1); 145 | return Qnil; 146 | } 147 | 148 | static emacs_value jinx_suggest(emacs_env* env, ptrdiff_t jinx_unused(nargs), 149 | emacs_value args[], void* jinx_unused(data)) { 150 | EnchantDict* dict = env->get_user_ptr(env, args[0]); 151 | jinx_autofree char* str = jinx_cstr(env, args[1]); 152 | emacs_value list = Qnil; 153 | size_t count = 0; 154 | char** suggs = str && dict ? enchant_dict_suggest(dict, str, -1, &count) : 0; 155 | if (suggs) { 156 | while (count > 0) 157 | list = jinx_cons(env, jinx_str(env, suggs[--count]), list); 158 | enchant_dict_free_string_list(dict, suggs); 159 | } 160 | return list; 161 | } 162 | 163 | int emacs_module_init(struct emacs_runtime *runtime) { 164 | // Require Emacs binary compatibility 165 | if ((size_t)runtime->size < sizeof (*runtime)) 166 | return 1; 167 | emacs_env* env = runtime->get_environment(runtime); 168 | if ((size_t)env->size < sizeof (*env)) 169 | return 2; 170 | Qt = env->make_global_ref(env, env->intern(env, "t")); 171 | Qnil = env->make_global_ref(env, env->intern(env, "nil")); 172 | Qcons = env->make_global_ref(env, env->intern(env, "cons")); 173 | jinx_defun(env, "jinx--mod-suggest", 2, 2, jinx_suggest); 174 | jinx_defun(env, "jinx--mod-check", 2, 2, jinx_check); 175 | jinx_defun(env, "jinx--mod-add", 2, 2, jinx_add); 176 | jinx_defun(env, "jinx--mod-dict", 1, 1, jinx_dict); 177 | jinx_defun(env, "jinx--mod-langs", 0, 0, jinx_langs); 178 | jinx_defun(env, "jinx--mod-describe", 1, 1, jinx_describe); 179 | return 0; 180 | } 181 | -------------------------------------------------------------------------------- /jinx.el: -------------------------------------------------------------------------------- 1 | ;;; jinx.el --- Enchanted Spell Checker -*- lexical-binding: t -*- 2 | 3 | ;; Copyright (C) 2023-2025 Free Software Foundation, Inc. 4 | 5 | ;; Author: Daniel Mendler 6 | ;; Maintainer: Daniel Mendler 7 | ;; Created: 2023 8 | ;; Version: 2.2 9 | ;; Package-Requires: ((emacs "28.1") (compat "30")) 10 | ;; URL: https://github.com/minad/jinx 11 | ;; Keywords: convenience, text 12 | 13 | ;; This file is part of GNU Emacs. 14 | 15 | ;; This program is free software: you can redistribute it and/or modify 16 | ;; it under the terms of the GNU General Public License as published by 17 | ;; the Free Software Foundation, either version 3 of the License, or 18 | ;; (at your option) any later version. 19 | 20 | ;; This program is distributed in the hope that it will be useful, 21 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | ;; GNU General Public License for more details. 24 | 25 | ;; You should have received a copy of the GNU General Public License 26 | ;; along with this program. If not, see . 27 | 28 | ;;; Commentary: 29 | 30 | ;; Jinx is a fast just-in-time spell-checker for Emacs. Jinx 31 | ;; highlights misspelled words in the text of the visible portion of 32 | ;; the buffer. For efficiency, Jinx highlights misspellings lazily, 33 | ;; recognizes window boundaries and text folding, if any. For 34 | ;; example, when unfolding or scrolling, only the newly visible part 35 | ;; of the text is checked if it has not been checked before. Each 36 | ;; misspelling can be corrected from a list of dictionary words 37 | ;; presented as a completion menu. 38 | 39 | ;; Installing Jinx is straight-forward and configuring should not need 40 | ;; much intervention. Jinx can be used completely on its own, but can 41 | ;; also safely co-exist with Emacs's built-in spell-checker Ispell. 42 | 43 | ;; Jinx's high performance and low resource usage comes from directly 44 | ;; calling the API of the Enchant library, see 45 | ;; https://rrthomas.github.io/enchant/. Jinx automatically compiles 46 | ;; jinx-mod.c and loads the dynamic module at startup. By binding 47 | ;; directly to the native Enchant API, Jinx avoids slower 48 | ;; inter-process communication. 49 | 50 | ;; See the manual for further information. 51 | 52 | ;;; Code: 53 | 54 | (require 'compat) 55 | (eval-when-compile 56 | (require 'cl-lib) 57 | (require 'subr-x)) 58 | 59 | ;;;; Customization 60 | 61 | (defgroup jinx nil 62 | "Enchanted Spell Checker." 63 | :link '(info-link :tag "Info Manual" "(jinx)") 64 | :link '(url-link :tag "Website" "https://github.com/minad/jinx") 65 | :link '(url-link :tag "Wiki" "https://github.com/minad/jinx/wiki") 66 | :link '(emacs-library-link :tag "Library Source" "jinx.el") 67 | :group 'text 68 | :prefix "jinx-") 69 | 70 | (defcustom jinx-delay 0.2 71 | "Idle timer delay." 72 | :type 'float) 73 | 74 | (defcustom jinx-languages 75 | (replace-regexp-in-string 76 | "\\..*\\'" "" 77 | (or (bound-and-true-p current-locale-environment) 78 | (pcase (getenv "LANG") 79 | ((or "C" "POSIX") nil) 80 | (lang lang)) 81 | "en_US")) 82 | "Dictionary language codes, as a string separated by whitespace." 83 | :type 'string) 84 | 85 | (defcustom jinx-save-languages 'ask 86 | "Save the variable `jinx-languages' as file-local variable?" 87 | :type '(choice (const :tag "Never" nil) 88 | (const :tag "Always" t) 89 | (const :tag "Ask" ask))) 90 | 91 | ;;;###autoload 92 | (put 'jinx-languages 'safe-local-variable #'stringp) 93 | 94 | (defcustom jinx-include-faces 95 | '((prog-mode font-lock-comment-face 96 | font-lock-doc-face 97 | font-lock-string-face) 98 | (conf-mode font-lock-comment-face 99 | font-lock-string-face) 100 | ;; `yaml-mode' and `yaml-ts-mode' are text-modes, 101 | ;; while they should better be conf- or prog-modes. 102 | (yaml-mode . conf-mode) 103 | (yaml-ts-mode . conf-mode)) 104 | "Alist of faces per major mode. 105 | These faces mark regions which should be included in spell 106 | checking." 107 | :type '(alist :key-type symbol :value-type (choice symbol (repeat face)))) 108 | 109 | (defcustom jinx-camel-modes 110 | '(java-mode java-ts-mode js-mode js-ts-mode ruby-mode ruby-ts-mode rust-mode 111 | rust-ts-mode haskell-mode kotlin-mode swift-mode csharp-mode csharp-ts-mode 112 | objc-mode typescript-ts-mode typescript-mode tsx-ts-mode python-mode 113 | python-ts-mode dart-mode go-mode go-ts-mode scala-mode groovy-mode) 114 | "Modes where camelCase or PascalCase words should be accepted. 115 | Set to t to enable camelCase everywhere." 116 | :type '(choice (const t) (repeat symbol))) 117 | 118 | (defcustom jinx-exclude-faces 119 | '((markdown-mode 120 | markdown-code-face markdown-html-attr-name-face 121 | markdown-html-attr-value-face markdown-html-tag-name-face 122 | markdown-inline-code-face markdown-link-face markdown-markup-face 123 | markdown-plain-url-face markdown-reference-face markdown-url-face) 124 | (org-mode 125 | org-block org-block-begin-line org-block-end-line org-code org-cite 126 | org-cite-key org-date org-document-info-keyword org-done org-drawer 127 | org-footnote org-formula org-latex-and-related org-link org-macro 128 | org-meta-line org-property-value org-special-keyword org-tag org-todo 129 | org-verbatim org-warning 130 | ;; org-modern 131 | org-modern-tag org-modern-date-active org-modern-date-inactive) 132 | (tex-mode 133 | tex-math font-latex-math-face font-latex-sedate-face 134 | font-latex-verbatim-face font-lock-function-name-face 135 | font-lock-keyword-face font-lock-variable-name-face) 136 | (texinfo-mode 137 | font-lock-function-name-face font-lock-keyword-face 138 | font-lock-variable-name-face) 139 | (rst-mode 140 | rst-literal rst-external rst-directive rst-definition rst-reference) 141 | (sgml-mode 142 | font-lock-function-name-face font-lock-variable-name-face) 143 | (lisp-data-mode 144 | font-lock-constant-face font-lock-warning-face) 145 | (message-mode 146 | message-separator message-header-cc message-header-name 147 | message-header-newsgroups message-header-other message-header-to 148 | message-header-xheader message-cited-text-1 message-cited-text-2 149 | message-cited-text-3 message-cited-text-4 gnus-cite-1 gnus-cite-2 150 | gnus-cite-3 gnus-cite-4 gnus-cite-5 gnus-cite-6 gnus-cite-7 gnus-cite-8 151 | gnus-cite-9 gnus-cite-10 gnus-cite-11)) 152 | "Alist of faces per major mode. 153 | These faces mark regions which should be excluded in spell 154 | checking." 155 | :type '(alist :key-type symbol :value-type (choice symbol (repeat face)))) 156 | 157 | (defcustom jinx-exclude-regexps 158 | '((emacs-lisp-mode "Package-Requires:.*$") 159 | (t "[A-Z]+\\>" ;; Uppercase words 160 | "-+\\>" ;; Hyphens used as lines or bullet points 161 | "\\w*?[0-9]\\w*\\>" ;; Words with numbers, hex codes 162 | "[a-z]+://\\S-+" ;; URI 163 | "?" ;; Email 164 | "\\(?:Local Variables\\|End\\):\\s-*$" ;; Local variable indicator 165 | "jinx-\\(?:languages\\|local-words\\):\\s-+.*$")) ;; Local variables 166 | "List of excluded regexps per major mode." 167 | :type '(alist :key-type symbol :value-type (choice symbol (repeat regexp)))) 168 | 169 | (defcustom jinx-suggestion-distance 3 170 | "Maximal edit distance for session words to be included in suggestions." 171 | :type 'natnum) 172 | 173 | (defcustom jinx-menu-suggestions 10 174 | "Maximal number of suggestions shown in the context menu." 175 | :type 'natnum) 176 | 177 | (defvar-local jinx-local-words "" 178 | "File-local words, as a string separated by whitespace.") 179 | 180 | (defvar-local jinx-dir-local-words "" 181 | "Directory-local words, as a string separated by whitespace.") 182 | 183 | ;;;###autoload 184 | (progn 185 | (put 'jinx-local-words 'safe-local-variable #'stringp) 186 | (put 'jinx-dir-local-words 'safe-local-variable #'stringp) 187 | (put 'jinx-mode 'safe-local-variable #'not)) 188 | 189 | ;;;; Faces 190 | 191 | (defgroup jinx-faces nil 192 | "Faces used by Jinx." 193 | :group 'jinx 194 | :group 'faces) 195 | 196 | (defface jinx-misspelled 197 | '((((class color) (min-colors 88) (background dark) 198 | (supports :underline (:style wave))) 199 | :underline (:style wave :color "#d2b580")) 200 | (((class color) (min-colors 88) (background light) 201 | (supports :underline (:style wave))) 202 | :underline (:style wave :color "#5f4400")) 203 | (t :underline t :inherit error)) 204 | "Face used for misspelled words.") 205 | 206 | (defface jinx-highlight 207 | '((t :inherit isearch)) 208 | "Face used to highlight current misspelled word during correction.") 209 | 210 | (defface jinx-save 211 | '((t :inherit warning)) 212 | "Face used for the save actions during correction.") 213 | 214 | (defface jinx-key 215 | '((t :inherit completions-annotations)) 216 | "Face used for the select key during correction.") 217 | 218 | (defface jinx-annotation 219 | '((t :inherit completions-annotations)) 220 | "Face used for the annotation during correction.") 221 | 222 | ;;;; Keymaps 223 | 224 | (defvar-keymap jinx-overlay-map 225 | :doc "Keymap attached to misspelled words." 226 | "" `(menu-item "" (keymap) :filter ,#'jinx--correct-menu) 227 | "M-n" #'jinx-next 228 | "M-p" #'jinx-previous 229 | "M-$" #'jinx-correct) 230 | 231 | (fset 'jinx-overlay-map jinx-overlay-map) 232 | 233 | (defvar-keymap jinx-repeat-map 234 | :doc "Repeat keymap for navigation commands." 235 | :repeat (:exit (jinx-correct)) 236 | "M-n" #'jinx-next 237 | "M-p" #'jinx-previous 238 | "n" #'jinx-next 239 | "p" #'jinx-previous 240 | "$" #'jinx-correct) 241 | 242 | (defvar-keymap jinx-correct-map 243 | :doc "Keymap active in the correction minibuffer." 244 | "SPC" #'self-insert-command 245 | "M-n" #'jinx-next 246 | "M-p" #'jinx-previous 247 | "M-$" #'jinx-previous 248 | "0 " #'jinx-correct-select) 249 | (dotimes (i 9) 250 | (define-key jinx-correct-map (vector (+ ?1 i)) #'jinx-correct-select)) 251 | 252 | (defvar-keymap jinx-mode-map 253 | :doc "Keymap used when Jinx is active.") 254 | 255 | (easy-menu-define jinx-mode-menu jinx-mode-map 256 | "Menu used when Jinx is active." 257 | '("Jinx" 258 | ["Correct nearest" jinx-correct] 259 | ["Correct all" jinx-correct-all 260 | :keys "\\[universal-argument] \\[jinx-correct]"] 261 | ["Correct word" jinx-correct-word 262 | :keys "\\[universal-argument] \\[universal-argument] \\[jinx-correct]"] 263 | ["Change languages" jinx-languages] 264 | "----" 265 | ["Manual" (info "(jinx)")] 266 | ["Customize" (customize-group 'jinx)] 267 | ["Turn off" (jinx-mode -1)])) 268 | 269 | ;;;; Internal variables 270 | 271 | (defvar jinx--compile-flags 272 | '("-I." "-O2" "-Wall" "-Wextra" "-fPIC" "-shared") 273 | "List of compile flags passed to the C compiler.") 274 | 275 | (defvar jinx--reschedule-hooks 276 | '(window-selection-change-functions window-scroll-functions 277 | window-state-change-hook post-command-hook) 278 | "Hooks which reschedule the spell checking timer, see `jinx--reschedule'.") 279 | 280 | (defvar jinx--predicates 281 | (list #'jinx--face-ignored-p 282 | #'jinx--regexp-ignored-p 283 | #'jinx--word-valid-p) 284 | "Predicate functions called at point with argument START. 285 | Predicate should return t if the word before point is valid. 286 | Predicate may return a position to skip forward.") 287 | 288 | (defvar jinx--timer (timer-create) 289 | "Global timer to check pending regions.") 290 | 291 | (defvar jinx--syntax-table 292 | (let ((st (make-syntax-table))) 293 | (modify-syntax-entry ?' "w" st) 294 | (modify-syntax-entry ?’ "w" st) 295 | (modify-syntax-entry ?$ "_" st) 296 | (modify-syntax-entry ?% "_" st) 297 | (modify-syntax-entry '(#xe000 . #xf8ff) "_" st) ;; Priv. use area 298 | (modify-syntax-entry '(#xf0000 . #xffffd) "_" st) ;; Supp. priv. use area A 299 | (modify-syntax-entry '(#x100000 . #x10fffd) "_" st);; Supp. priv. use area B 300 | (modify-syntax-entry '(#x80 . #x9f) "_" st) ;; Control characters 301 | (modify-syntax-entry '(#x2150 . #x2bff) "_" st) ;; Number Forms - Misc. Arrows 302 | (modify-syntax-entry '(#xfe00 . #xfe0f) "_" st) ;; Variation Selectors 303 | (modify-syntax-entry '(#x1cf00 . #x1d7ff) "_" st) ;; Znamenny Musical - Math. Alpha. 304 | (modify-syntax-entry '(#x1ee00 . #x1fbff) "_" st) ;; Arabic Math. - Legacy Computing 305 | st) 306 | "Syntax table used during checking.") 307 | 308 | (defvar jinx--select-keys 309 | "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 310 | "Quick select keys used by `jinx-correct'.") 311 | 312 | (defvar jinx--save-keys 313 | `((?@ . ,#'jinx--save-personal) 314 | (?* . ,#'jinx--save-file) 315 | (?/ . ,#'jinx--save-dir) 316 | (?+ . ,#'jinx--save-session)) 317 | "Keys for save actions used by `jinx-correct'.") 318 | 319 | (defvar-local jinx--exclude-faces nil 320 | "List of excluded faces.") 321 | 322 | (defvar-local jinx--include-faces nil 323 | "List of included faces.") 324 | 325 | (defvar-local jinx--exclude-regexp nil 326 | "Ignore regexp.") 327 | 328 | (defvar-local jinx--camel nil 329 | "Accept camel case.") 330 | 331 | (defvar-local jinx--dicts nil 332 | "List of dictionaries.") 333 | 334 | (defvar jinx--dicts-hash (make-hash-table :test #'equal :weakness 'value) 335 | "Weak hash table of all loaded dictionaries.") 336 | 337 | (defvar-local jinx--session-words nil 338 | "List of words accepted in this session.") 339 | 340 | ;;;; Declarations for the bytecode compiler 341 | 342 | (defvar repeat-mode) 343 | (defvar jinx-mode) 344 | (declare-function jinx--mod-check "ext:jinx-mod.c") 345 | (declare-function jinx--mod-add "ext:jinx-mod.c") 346 | (declare-function jinx--mod-suggest "ext:jinx-mod.c") 347 | (declare-function jinx--mod-dict "ext:jinx-mod.c") 348 | (declare-function jinx--mod-describe "ext:jinx-mod.c") 349 | (declare-function jinx--mod-langs "ext:jinx-mod.c") 350 | 351 | ;;;; Overlay properties 352 | 353 | (put 'jinx-overlay 'evaporate t) 354 | (put 'jinx-overlay 'face 'jinx-misspelled) 355 | (put 'jinx-overlay 'mouse-face '(jinx-misspelled jinx-highlight)) 356 | (put 'jinx-overlay 'modification-hooks (list #'jinx--overlay-modified)) 357 | (put 'jinx-overlay 'insert-in-front-hooks (list #'jinx--overlay-modified)) 358 | (put 'jinx-overlay 'insert-behind-hooks (list #'jinx--overlay-modified)) 359 | (put 'jinx-overlay 'keymap 'jinx-overlay-map) 360 | (put 'jinx-overlay 'help-echo "Jinx: \\`mouse-3' menu, \\[jinx-correct] correct, \\`M-p' previous, \\`M-n' next") 361 | 362 | ;;;; Predicates 363 | 364 | (defun jinx--regexp-ignored-p (start) 365 | "Return non-nil if word at START matches ignore regexps." 366 | (save-excursion 367 | (goto-char start) 368 | (when (and jinx--exclude-regexp (looking-at-p jinx--exclude-regexp)) 369 | (save-match-data 370 | (looking-at jinx--exclude-regexp) 371 | (match-end 0))))) 372 | 373 | (defun jinx--face-ignored-p (start) 374 | "Return non-nil if face at START of word is ignored." 375 | (let ((face (get-text-property start 'face))) 376 | (or 377 | (and jinx--include-faces 378 | (if (listp face) 379 | (cl-loop for f in face never (memq f jinx--include-faces)) 380 | (not (memq face jinx--include-faces)))) 381 | (and jinx--exclude-faces 382 | (if (listp face) 383 | (cl-loop for f in face thereis (memq f jinx--exclude-faces)) 384 | (memq face jinx--exclude-faces)))))) 385 | 386 | (defun jinx--word-valid-p (word) 387 | "Return non-nil if WORD is valid. 388 | WORD can also be a start position." 389 | (unless (stringp word) 390 | (setq word (buffer-substring-no-properties word (point)))) 391 | (or (member word jinx--session-words) 392 | ;; Allow capitalized words 393 | (let (case-fold-search) 394 | (and (string-match-p "\\`[[:upper:]][[:lower:]]+\\'" word) 395 | (cl-loop 396 | for w in jinx--session-words 397 | thereis (and (string-equal-ignore-case word w) 398 | (string-match-p "\\`[[:lower:]]+\\'" w))))) 399 | (cl-loop for dict in jinx--dicts 400 | thereis (jinx--mod-check dict word)))) 401 | 402 | ;;;; Internal functions 403 | 404 | (defun jinx--in-base-buffer (&rest app) 405 | "Apply APP in `buffer-base-buffer', as required by `jit-lock' functions." 406 | (with-current-buffer (or (buffer-base-buffer) (current-buffer)) 407 | (apply app))) 408 | 409 | (defun jinx--overlay-modified (overlay &rest _) 410 | "Delete modified OVERLAY. 411 | This function is a modification hook for the overlay." 412 | (delete-overlay overlay)) 413 | 414 | (defun jinx--find-visible (start end visible) 415 | "Find (in)visible region between START and END. 416 | VISIBLE must be nil or t." 417 | (while (and (< start end) (eq (not visible) (not (invisible-p start)))) 418 | (let ((next (next-single-char-property-change start 'invisible nil end))) 419 | ;; END can be outside the buffer if the buffer size has changed in 420 | ;; between. Then `next-single-property-change' will return (point-max) 421 | ;; instead of END. See gh:minad/jinx#156. 422 | (setq start (if (> next start) next end)))) 423 | start) 424 | 425 | (defun jinx--check-pending (start end) 426 | "Check pending visible region between START and END." 427 | (let ((retry (and (eq (window-buffer) (current-buffer)) 428 | (symbolp real-last-command) 429 | (string-match-p "self-insert-command\\'" 430 | (symbol-name real-last-command)) 431 | (window-point)))) 432 | (while (< start end) 433 | (let* ((vfrom (jinx--find-visible start end t)) 434 | (vto (jinx--find-visible vfrom end nil))) 435 | (while (< vfrom vto) 436 | (let* ((pfrom (or (text-property-any vfrom vto 'jinx--pending t) vto)) 437 | (pto (or (text-property-not-all pfrom vto 'jinx--pending t) vto))) 438 | (when (< pfrom pto) 439 | (jinx--check-region pfrom pto retry)) 440 | (setq vfrom pto))) 441 | (setq start vto))))) 442 | 443 | (defun jinx--check-region (start end &optional retry) 444 | "Check region between START and END. 445 | Optionally RETRY word at given position. Return updated END 446 | position." 447 | (let ((st (syntax-table)) case-fold-search 448 | retry-start retry-end) 449 | (unwind-protect 450 | (with-silent-modifications 451 | (save-excursion 452 | (save-match-data 453 | ;; Use dictionary-dependent syntax table 454 | (set-syntax-table jinx--syntax-table) 455 | ;; Ensure that region starts and ends at word boundaries 456 | (goto-char start) 457 | (unless (looking-at-p "\\<") 458 | (re-search-backward "\\<\\|^") 459 | (setq start (match-beginning 0))) 460 | (goto-char end) 461 | (unless (looking-at-p "\\>") 462 | (re-search-forward "\\>\\|$") 463 | (setq end (match-beginning 0))) 464 | (jinx--delete-overlays start end) 465 | (goto-char start) 466 | (while (re-search-forward "\\<\\w+\\>" end t) 467 | (let ((word-start (match-beginning 0)) 468 | (word-end (match-end 0))) 469 | ;; No quote or apostrophe at start or end 470 | (while (and (< word-start word-end) 471 | (let ((c (char-after word-start))) 472 | (or (= c ?') (= c ?’)))) 473 | (cl-incf word-start)) 474 | (while (and (< word-start word-end) 475 | (let ((c (char-before word-end))) 476 | (or (= c ?') (= c ?’)))) 477 | (cl-decf word-end)) 478 | (while (< word-start word-end) 479 | (let ((subword-end word-end)) 480 | (when jinx--camel 481 | (goto-char word-start) 482 | (when (looking-at "\\([[:upper:]]?[[:lower:]]+\\)\\(?:[[:upper:]][[:lower:]]+\\)+\\>") 483 | (setq subword-end (match-end 1)))) 484 | (goto-char subword-end) 485 | (pcase (run-hook-with-args-until-success 'jinx--predicates word-start) 486 | ((and (pred integerp) skip) 487 | (goto-char (max subword-end (min end skip)))) 488 | ('nil 489 | (if (and retry (<= word-start retry subword-end)) 490 | (setq retry-start word-start retry-end subword-end retry nil) 491 | (overlay-put (make-overlay word-start subword-end) 'category 'jinx-overlay)))) 492 | (setq word-start subword-end))))) 493 | (remove-list-of-text-properties start end '(jinx--pending)) 494 | (when retry-start 495 | (put-text-property retry-start retry-end 'jinx--pending t))))) 496 | (set-syntax-table st)))) 497 | 498 | (defun jinx--get-overlays (start end &optional visible) 499 | "Return misspelled word overlays between START and END. 500 | If VISIBLE is non-nil, only include visible overlays." 501 | (let ((pt (point)) before overlays) 502 | (dolist (ov (overlays-in start end)) 503 | (when (and (eq (overlay-get ov 'category) 'jinx-overlay) 504 | (not (and visible (invisible-p (overlay-start ov))))) 505 | (push ov overlays))) 506 | (setq overlays 507 | (sort overlays 508 | (lambda (a b) (< (overlay-start a) (overlay-start b))))) 509 | (while (and (cdr overlays) (<= (overlay-start (cadr overlays)) pt)) 510 | (push (pop overlays) before)) 511 | (nconc overlays (nreverse before)))) 512 | 513 | (cl-defun jinx--force-overlays (start end &key visible check) 514 | "Return misspelled word overlays between START and END, enforce checking. 515 | If VISIBLE is non-nil, only include visible overlays. 516 | If CHECK is non-nil, always check first." 517 | (or (and (not check) (jinx--get-overlays start end visible)) 518 | (progn 519 | (with-delayed-message (1 "Fontifying...") 520 | (jinx--in-base-buffer #'jit-lock-fontify-now start end)) 521 | (with-delayed-message (1 "Checking...") 522 | (jinx--check-region start end)) 523 | (jinx--get-overlays start end visible)) 524 | (user-error (if visible "No misspelled word in visible text" 525 | "No misspelled word in whole buffer")))) 526 | 527 | (defun jinx--delete-overlays (start end) 528 | "Delete overlays between START and END." 529 | (dolist (ov (overlays-in start end)) 530 | (when (eq (overlay-get ov 'category) 'jinx-overlay) 531 | (delete-overlay ov)))) 532 | 533 | (defun jinx--cleanup () 534 | "Cleanup all overlays and trigger fontification." 535 | (with-silent-modifications 536 | (without-restriction 537 | (jinx--delete-overlays (point-min) (point-max)) 538 | (remove-list-of-text-properties (point-min) (point-max) '(jinx--pending)) 539 | (jinx--in-base-buffer #'jit-lock-refontify)))) 540 | 541 | (defun jinx--mark-pending (start end) 542 | "Mark region between START and END as pending." 543 | (put-text-property start end 'jinx--pending t) 544 | (unless inhibit-quit ;; non-nil for stealth locking 545 | (jinx--schedule)) 546 | nil) 547 | 548 | (defun jinx--mode-list (list) 549 | "Lookup by major mode in LIST." 550 | (cl-loop for (mode . vals) in list 551 | if (or (eq mode t) (derived-mode-p mode)) 552 | append (if (symbolp vals) (alist-get vals list) vals))) 553 | 554 | (defun jinx--get-org-language () 555 | "Get language from Org #+language keyword." 556 | (when (and (not (local-variable-p 'jinx-languages)) 557 | (derived-mode-p 'org-mode)) 558 | (save-excursion 559 | (save-match-data 560 | (goto-char (point-min)) 561 | (when (re-search-forward "^ *#\\+language: +\\([a-z_]+\\) *$" nil t) 562 | (setq-local jinx-languages (match-string-no-properties 1))))))) 563 | 564 | (defun jinx--timer-handler () 565 | "Global timer handler, checking the pending regions in all windows." 566 | (timer-set-function jinx--timer nil) 567 | (dolist (frame (frame-list)) 568 | (dolist (win (window-list frame 'no-miniwindow)) 569 | (when-let ((buffer (window-buffer win)) 570 | ((buffer-local-value 'jinx-mode buffer))) 571 | (with-current-buffer buffer 572 | (jinx--check-pending (window-start win) (window-end win))))))) 573 | 574 | (defun jinx--reschedule (&rest _) 575 | "Restart the global idle timer." 576 | (when (timer--function jinx--timer) 577 | (cancel-timer jinx--timer) 578 | (timer-set-function jinx--timer nil)) 579 | (jinx--schedule)) 580 | 581 | (defun jinx--schedule () 582 | "Start the global idle timer." 583 | (when (and (not (timer--function jinx--timer)) 584 | (not completion-in-region-mode) ;; Corfu completion 585 | (get-buffer-window)) ;; Buffer visible 586 | (timer-set-function jinx--timer #'jinx--timer-handler) 587 | (timer-set-idle-time jinx--timer jinx-delay) 588 | (timer-activate-when-idle jinx--timer t))) 589 | 590 | (defun jinx--load-module () 591 | "Compile and load dynamic module." 592 | (unless (fboundp #'jinx--mod-dict) 593 | (unless module-file-suffix 594 | (error "Jinx: Dynamic modules are not supported")) 595 | (let* ((mod-name (file-name-with-extension "jinx-mod" module-file-suffix)) 596 | (mod-file (locate-library mod-name t))) 597 | (unless mod-file 598 | (let* ((cc (or (getenv "CC") 599 | (seq-find #'executable-find '("gcc" "clang" "cc")) 600 | (error "Jinx: No C compiler found"))) 601 | (c-name (file-name-with-extension mod-name ".c")) 602 | (default-directory (file-name-directory 603 | (or (locate-library c-name t) 604 | (error "Jinx: %s not found" c-name)))) 605 | (command 606 | `(,cc ,@jinx--compile-flags "-o" ,mod-name ,c-name 607 | ,@(split-string-and-unquote 608 | (condition-case nil 609 | (car (process-lines "pkg-config" "--cflags" "--libs" "enchant-2")) 610 | (error "-I/usr/include/enchant-2 -I/usr/local/include/enchant-2 -L/usr/local/lib -lenchant-2")))))) 611 | (with-current-buffer (get-buffer-create "*jinx module compilation*") 612 | (let ((inhibit-read-only t)) 613 | (erase-buffer) 614 | (compilation-mode) 615 | (insert (string-join command " ") "\n") 616 | (if (equal 0 (apply #'call-process (car command) nil (current-buffer) t (cdr command))) 617 | (insert (message "Jinx: %s compiled successfully" mod-name)) 618 | (let ((msg (format "Jinx: Compilation of %s failed" mod-name))) 619 | (insert msg) 620 | (pop-to-buffer (current-buffer)) 621 | (error msg))))) 622 | (setq mod-file (expand-file-name mod-name)))) 623 | ;; Initialize Mac spell checker to avoid dead lock (gh:minad/jinx#91). 624 | (when (and (eq window-system 'mac) (fboundp 'mac-do-applescript)) 625 | (mac-do-applescript 626 | "use framework \"AppKit\" 627 | set spellChecker to current application's NSSpellChecker's sharedSpellChecker()")) 628 | (module-load mod-file)))) 629 | 630 | (defmacro jinx--correct-guard (&rest body) 631 | "Guard BODY during correction loop." 632 | `(cl-letf (((symbol-function #'jinx--timer-handler) #'ignore) ;; Inhibit 633 | (repeat-mode nil)) ;; No repeating of jinx-next and jinx-previous 634 | (unless jinx-mode (jinx-mode)) 635 | ,@body)) 636 | 637 | (defun jinx--invisible-open-temporarily () 638 | "Temporarily open overlays which hide the current line. 639 | See `isearch-open-necessary-overlays' and `isearch-open-overlay-temporary'." 640 | (let (restore) 641 | (dolist (ov (overlays-in (pos-bol) (pos-eol)) restore) 642 | (let ((inv (overlay-get ov 'invisible))) 643 | (when (and (invisible-p inv) (overlay-get ov 'isearch-open-invisible)) 644 | (push (if-let ((fun (overlay-get ov 'isearch-open-invisible-temporary))) 645 | (progn 646 | (funcall fun ov nil) 647 | (lambda () (funcall fun ov t))) 648 | (overlay-put ov 'invisible nil) 649 | (lambda () (overlay-put ov 'invisible inv))) 650 | restore)))))) 651 | 652 | (defun jinx--invisible-open-permanently () 653 | "Open overlays which hide the current line. 654 | See `isearch-open-necessary-overlays' and `isearch-open-overlay-temporary'." 655 | (dolist (ov (overlays-in (pos-bol) (pos-eol))) 656 | (when-let (fun (overlay-get ov 'isearch-open-invisible)) 657 | (when (invisible-p (overlay-get ov 'invisible)) 658 | (funcall fun ov))))) 659 | 660 | (defun jinx--correct-highlight (overlay fun) 661 | "Highlight and show OVERLAY during FUN." 662 | (declare (indent 1)) 663 | (let (restore) 664 | (goto-char (overlay-end overlay)) 665 | (unwind-protect 666 | (let ((hl (make-overlay (overlay-start overlay) (overlay-end overlay)))) 667 | (overlay-put hl 'face 'jinx-highlight) 668 | (overlay-put hl 'window (selected-window)) 669 | (setq restore (cons (lambda () (delete-overlay hl)) 670 | (jinx--invisible-open-temporarily))) 671 | (funcall fun)) 672 | (mapc #'funcall restore)))) 673 | 674 | (defun jinx--recheck-overlays () 675 | "Recheck all overlays in buffer after a dictionary update." 676 | (save-excursion 677 | (without-restriction 678 | (dolist (ov (overlays-in (point-min) (point-max))) 679 | (when (eq (overlay-get ov 'category) 'jinx-overlay) 680 | (goto-char (overlay-end ov)) 681 | (when (jinx--word-valid-p (overlay-start ov)) 682 | (delete-overlay ov))))))) 683 | 684 | (defun jinx--correct-setup () 685 | "Setup minibuffer for correction." 686 | (use-local-map (make-composed-keymap (list jinx-correct-map) (current-local-map))) 687 | ;; TODO Use `eager-display' on Emacs 31 688 | (when (and (eq completing-read-function #'completing-read-default) 689 | (not (bound-and-true-p vertico-mode)) 690 | (not (bound-and-true-p icomplete-mode))) 691 | (let ((message-log-max nil) 692 | (inhibit-message t)) 693 | (minibuffer-completion-help)))) 694 | 695 | (defun jinx--add-suggestion (list ht word group) 696 | "Add suggestion WORD to LIST and HT. 697 | The word will be associated with GROUP and get a prefix key." 698 | (unless (gethash word ht) 699 | (add-text-properties 700 | 0 (length word) 701 | (list 'jinx--group group 702 | 'jinx--prefix 703 | (let ((idx (1+ (hash-table-count ht)))) 704 | (cond 705 | ((< idx 10) 706 | (format #("%d " 0 3 (face jinx-key)) 707 | idx)) 708 | ((< (- idx 10) (length jinx--select-keys)) 709 | (format #("0%c " 0 4 (face jinx-key)) 710 | (aref jinx--select-keys (- idx 10))))))) 711 | word) 712 | (push word list) 713 | (puthash word t ht)) 714 | list) 715 | 716 | (defun jinx--session-suggestions (word) 717 | "Retrieve suggestions for WORD from session." 718 | (mapcar #'cdr 719 | (sort (cl-loop for w in jinx--session-words 720 | for d = (string-distance word w) 721 | if (<= d jinx-suggestion-distance) 722 | collect (cons d w)) 723 | #'car-less-than-car))) 724 | 725 | (defun jinx--correct-suggestions (word) 726 | "Retrieve suggestions for WORD from all dictionaries." 727 | (let ((ht (make-hash-table :test #'equal)) 728 | (list nil)) 729 | (dolist (dict jinx--dicts) 730 | (let* ((desc (jinx--mod-describe dict)) 731 | (group (format "Suggestions from dictionary ‘%s’ - %s" 732 | (car desc) (cdr desc)))) 733 | (dolist (w (jinx--mod-suggest dict word)) 734 | (setq list (jinx--add-suggestion list ht w group))))) 735 | (dolist (w (jinx--session-suggestions word)) 736 | (setq list (jinx--add-suggestion list ht w "Suggestions from session"))) 737 | (cl-loop 738 | for (key . fun) in jinx--save-keys 739 | for actions = (funcall fun nil key word) do 740 | (when (and actions (not (consp (car actions)))) 741 | (setq actions (list actions))) 742 | (cl-loop 743 | for (k w a) in actions 744 | for k2 = (propertize (if (stringp k) k (char-to-string k)) 745 | 'face 'jinx-save 'rear-nonsticky t) 746 | for a2 = (format #(" [%s]" 0 5 (face jinx-annotation)) a) 747 | do (cl-loop 748 | for w2 in (delete-consecutive-dups (list w (downcase w))) do 749 | (push (propertize (concat k2 w2) 750 | 'jinx--group "Accept and save" 751 | 'jinx--suffix a2) 752 | list)))) 753 | (nreverse list))) 754 | 755 | (defun jinx--correct-affixation (cands) 756 | "Affixate CANDS during completion." 757 | (cl-loop for cand in cands collect 758 | (list cand 759 | (or (get-text-property 0 'jinx--prefix cand) "") 760 | (or (get-text-property 0 'jinx--suffix cand) "")))) 761 | 762 | (defun jinx--correct-annotation (cand) 763 | "Annotate CAND during completion." 764 | (if-let ((prefix (get-text-property 0 'jinx--prefix cand))) 765 | (format #(" (%s)" 0 5 (face jinx-key)) (string-trim prefix)) 766 | (get-text-property 0 'jinx--suffix cand))) 767 | 768 | (defun jinx--group (word transform) 769 | "Group WORD during completion, TRANSFORM candidate if non-nil." 770 | (if transform 771 | word 772 | (get-text-property 0 'jinx--group word))) 773 | 774 | ;; TODO: Use `completion-table-with-metadata' 775 | (defun jinx--table-with-metadata (table metadata) 776 | "Return new completion TABLE with METADATA." 777 | (lambda (string pred action) 778 | (if (eq action 'metadata) 779 | `(metadata . ,metadata) 780 | (complete-with-action action table string pred)))) 781 | 782 | (cl-defun jinx--correct-overlay (overlay &key info initial) 783 | "Correct word at OVERLAY. 784 | Optionally show prompt INFO and insert INITIAL input." 785 | (catch 'jinx--goto 786 | (let* ((word (buffer-substring-no-properties 787 | (overlay-start overlay) (overlay-end overlay))) 788 | (choice 789 | (jinx--correct-highlight overlay 790 | (lambda () 791 | (when (or (< (point) (window-start)) (> (point) (window-end nil t))) 792 | (recenter)) 793 | (minibuffer-with-setup-hook 794 | #'jinx--correct-setup 795 | (or (completing-read 796 | (format "Correct ‘%s’%s: " word (or info "")) 797 | (jinx--table-with-metadata 798 | (jinx--correct-suggestions word) 799 | `((category . jinx) 800 | (display-sort-function . ,#'identity) 801 | (cycle-sort-function . ,#'identity) 802 | (group-function . ,#'jinx--group) 803 | (affixation-function . ,#'jinx--correct-affixation) 804 | (annotation-function . ,#'jinx--correct-annotation))) 805 | nil nil initial t word) 806 | word))))) 807 | (len (length choice))) 808 | (pcase (and (> len 0) (assq (aref choice 0) jinx--save-keys)) 809 | (`(,key . ,fun) 810 | (funcall fun 'save key 811 | (if (> len 1) (substring-no-properties choice 1) word)) 812 | (jinx--recheck-overlays)) 813 | ((guard (not (equal choice word))) 814 | (jinx--correct-replace overlay choice))) 815 | nil))) 816 | 817 | (defun jinx--correct-replace (overlay word) 818 | "Replace OVERLAY with WORD." 819 | (when-let ((start (overlay-start overlay)) 820 | (end (overlay-end overlay))) 821 | (undo-boundary) 822 | (delete-overlay overlay) 823 | (goto-char end) 824 | (insert-before-markers word) 825 | (delete-region start end))) 826 | 827 | (defun jinx--correct-menu (&rest _) 828 | "Return popup mouse menu to correct misspelling." 829 | (when-let ((posn (event-start last-input-event)) 830 | (pt (posn-point posn)) 831 | (ov (car (jinx--get-overlays pt pt t)))) 832 | (let ((menu nil) 833 | (word (buffer-substring-no-properties 834 | (overlay-start ov) (overlay-end ov)))) 835 | (dolist (dict jinx--dicts) 836 | (when-let ((desc (jinx--mod-describe dict)) 837 | (suggestions (jinx--mod-suggest dict word))) 838 | (push `[,(concat "── " (car desc) " ─ " (cdr desc) " ──") :active nil] menu) 839 | (cl-loop for w in suggestions repeat jinx-menu-suggestions do 840 | (push `[,w (jinx--correct-replace ,ov ,w)] menu)))) 841 | (when-let ((suggestions (jinx--session-suggestions word))) 842 | (push ["── Session ──" :active nil] menu) 843 | (cl-loop for w in suggestions repeat jinx-menu-suggestions do 844 | (push `[,w (jinx--correct-replace ,ov ,w)] menu))) 845 | (push ["── Accept and save ──" :active nil] menu) 846 | (cl-loop for (key . fun) in jinx--save-keys 847 | for actions = (funcall fun nil key word) do 848 | (unless (consp (car actions)) (setq actions (list actions))) 849 | (cl-loop for (k w a) in actions do 850 | (push `[,a (jinx-correct-word 851 | ,(overlay-start ov) ,(overlay-end ov) 852 | ,(concat (if (stringp k) k (char-to-string k)) w))] 853 | menu))) 854 | (easy-menu-create-menu (format "Correct \"%s\"" word) 855 | (delete-dups (nreverse menu)))))) 856 | 857 | (defun jinx--load-dicts () 858 | "Load dictionaries and setup syntax table." 859 | (unless (setq jinx--dicts 860 | (cl-loop for lang in (split-string jinx-languages) 861 | ;; Keep a weak reference to loaded dictionaries. 862 | ;; See . 863 | for dict = (with-memoization (gethash lang jinx--dicts-hash) 864 | (jinx--mod-dict lang)) 865 | if dict collect dict)) 866 | (message "Jinx: No dictionaries available for %S" jinx-languages))) 867 | 868 | (defun jinx--bounds-of-word () 869 | "Return bounds of word at point using `jinx--syntax-table'." 870 | (save-excursion 871 | (save-match-data 872 | (with-syntax-table jinx--syntax-table 873 | (unless (looking-at-p "\\<") 874 | (re-search-backward "\\<")) 875 | (when (re-search-forward "\\<\\w+\\>" nil t) 876 | (cons (match-beginning 0) (match-end 0))))))) 877 | 878 | (defun jinx--read-languages () 879 | "Read languages via `completing-read-multiple'." 880 | (jinx--load-module) 881 | (let ((langs (delete-dups 882 | (cl-loop for (l . p) in (jinx--mod-langs) collect 883 | (propertize l 'jinx--group (format "Provider %s" p)))))) 884 | (string-join 885 | (or (completing-read-multiple 886 | (format "Change languages (%s): " 887 | (string-join (split-string jinx-languages) ", ")) 888 | (jinx--table-with-metadata langs `((group-function . ,#'jinx--group))) 889 | nil t) 890 | (user-error "No languages selected")) 891 | " "))) 892 | 893 | (defun jinx--add-local-word (var word) 894 | "Add WORD to local word list VAR." 895 | (add-to-list 'jinx--session-words word) 896 | (set var 897 | (string-join 898 | (sort (delete-dups (cons word (split-string (symbol-value var)))) 899 | #'string<) 900 | " "))) 901 | 902 | ;;;; Save functions 903 | 904 | (defun jinx--save-personal (save key word) 905 | "Save WORD in personal dictionary. 906 | If SAVE is non-nil save, otherwise format candidate given action KEY." 907 | (if save 908 | (let ((idx (seq-position word key (lambda (x y) (not (equal x y)))))) 909 | (jinx--mod-add (or (nth idx jinx--dicts) 910 | (user-error "Invalid dictionary")) 911 | (substring word idx))) 912 | (cl-loop 913 | for dict in jinx--dicts for idx from 1 914 | for at = (make-string idx key) 915 | for ann = (format "Personal:%s" (car (jinx--mod-describe dict))) collect 916 | (list at word ann)))) 917 | 918 | (defun jinx--save-file (save key word) 919 | "Save WORD in file-local variable. 920 | If SAVE is non-nil save, otherwise format candidate given action KEY." 921 | (if save 922 | (progn 923 | (jinx--add-local-word 'jinx-local-words word) 924 | (add-file-local-variable 'jinx-local-words jinx-local-words)) 925 | (list key word "File"))) 926 | 927 | (defun jinx--save-dir (save key word) 928 | "Save WORD in directory-local variable. 929 | Uses a .dir-locals.el file in the current directory or any parent 930 | directory. If no .dir-locals.el file is found, it is created in the 931 | project root. If no project root is found, it is created in the current 932 | directory. If SAVE is non-nil save, otherwise format candidate given 933 | action KEY." 934 | (if save 935 | (progn 936 | (jinx--add-local-word 'jinx-dir-local-words word) 937 | (let ((default-directory 938 | (or (locate-dominating-file default-directory ".dir-locals.el") 939 | (when-let (proj (project-current)) 940 | (declare-function project-root "project") 941 | (project-root proj)) 942 | default-directory))) 943 | (save-window-excursion 944 | (add-dir-local-variable nil 'jinx-dir-local-words jinx-dir-local-words)))) 945 | (list key word "Directory"))) 946 | 947 | (defun jinx--save-session (save key word) 948 | "Save WORD for the current session. 949 | If SAVE is non-nil save, otherwise format candidate given action KEY." 950 | (if save 951 | (add-to-list 'jinx--session-words word) 952 | (list key word "Session"))) 953 | 954 | ;;;; Public commands 955 | 956 | ;;;###autoload 957 | (defun jinx-languages (langs &optional global) 958 | "Set languages locally or globally to LANGS. 959 | LANGS should be one or more language codes as a string, separated 960 | by whitespace. When called interactively, the language codes are 961 | read via `completing-read-multiple'. If the prefix argument 962 | GLOBAL is non-nil, the languages are changed globally for all 963 | buffers. See also the variable `jinx-languages'." 964 | (interactive (list (jinx--read-languages) current-prefix-arg)) 965 | (unless jinx-mode (jinx-mode)) 966 | (cond 967 | (global 968 | (kill-local-variable 'jinx-languages) 969 | (setq-default jinx-languages langs)) 970 | (t 971 | (setq-local jinx-languages langs) 972 | (when (or (assq 'jinx-languages file-local-variables-alist) 973 | (if (eq jinx-save-languages 'ask) 974 | (and buffer-file-name 975 | (y-or-n-p "Save `jinx-languages' as file-local variable? ")) 976 | jinx-save-languages)) 977 | (add-file-local-variable 'jinx-languages jinx-languages) 978 | (setf (alist-get 'jinx-languages file-local-variables-alist) jinx-languages)))) 979 | (jinx--load-dicts) 980 | (jinx--cleanup)) 981 | 982 | ;;;###autoload 983 | (defun jinx-correct-all (&optional only-check) 984 | "Correct all misspelled words in the buffer. 985 | With prefix argument ONLY-CHECK, only check the buffer and highlight all 986 | misspellings, but do not open the correction UI." 987 | (interactive "*P") 988 | (jinx--correct-guard 989 | (let* ((overlays (jinx--force-overlays (or (use-region-beginning) (point-min)) 990 | (or (use-region-end) (point-max)) 991 | :check t)) 992 | (count (length overlays)) 993 | (idx 0)) 994 | (unless only-check 995 | (deactivate-mark) 996 | (push-mark) 997 | (while-let ((ov (nth idx overlays))) 998 | (if-let (((overlay-buffer ov)) 999 | (skip (jinx--correct-overlay ov :info (format " (%d of %d)" (1+ idx) count)))) 1000 | (setq idx (mod (+ idx skip) count)) 1001 | (cl-incf idx))))))) 1002 | 1003 | ;;;###autoload 1004 | (defun jinx-correct-nearest () 1005 | "Correct nearest misspelled word." 1006 | (interactive "*") 1007 | (save-excursion 1008 | (jinx--correct-guard 1009 | (let* ((overlays (jinx--force-overlays (window-start) (window-end) :visible t)) 1010 | (count (length overlays)) 1011 | (idx 0)) 1012 | ;; Not using `while-let' is intentional here. 1013 | (while (when-let ((ov (nth idx overlays))) 1014 | (if (overlay-buffer ov) 1015 | (when-let ((skip (jinx--correct-overlay ov))) 1016 | (setq idx (mod (+ idx skip) count))) 1017 | (cl-incf idx)))))))) ;; Skip deleted overlay 1018 | 1019 | ;;;###autoload 1020 | (defun jinx-correct-word (&optional start end initial) 1021 | "Correct word between START and END, by default the word before point. 1022 | Suggest corrections even if the word is not misspelled. 1023 | Optionally insert INITIAL input in the minibuffer." 1024 | (interactive) 1025 | (unless (and start end) 1026 | (setf (cons start end) (or (jinx--bounds-of-word) 1027 | (user-error "No word at point")))) 1028 | (save-excursion 1029 | (jinx--correct-guard 1030 | (while-let ((skip (let ((ov (make-overlay start end))) 1031 | (unwind-protect 1032 | (jinx--correct-overlay ov :initial initial) 1033 | (delete-overlay ov))))) 1034 | (forward-to-word skip) 1035 | (when-let ((bounds (jinx--bounds-of-word))) 1036 | (setf (cons start end) bounds 1037 | initial nil)))))) 1038 | 1039 | ;;;###autoload 1040 | (defun jinx-correct (&optional arg) 1041 | "Correct word depending on prefix ARG. 1042 | This command dispatches to the following commands: 1043 | - `jinx-correct-nearest': If prefix ARG is nil, correct nearest 1044 | misspelled word. 1045 | - `jinx-correct-all': If a region is marked, or if prefix ARG 1046 | is 4, corresponding to \\[universal-argument] pressed once, 1047 | correct all misspelled words. 1048 | - `jinx-correct-word': If prefix ARG is 16, corresponding to 1049 | \\[universal-argument] pressed twice, correct word before point. 1050 | - If prefix ARG is 64, corresponding to \\[universal-argument] pressed 1051 | three times, check the whole buffer, but do not open the correction 1052 | UI." 1053 | (interactive "*P") 1054 | (pcase arg 1055 | ('nil (if (use-region-p) (jinx-correct-all) (jinx-correct-nearest))) 1056 | ('(16) (jinx-correct-word)) 1057 | ('(64) (jinx-correct-all t)) 1058 | (_ (jinx-correct-all)))) 1059 | 1060 | (defun jinx-correct-select () 1061 | "Quick selection key for corrections." 1062 | (declare (completion ignore)) 1063 | (interactive) 1064 | (let* ((keys (this-command-keys-vector)) 1065 | (word (nth (if (eq (aref keys 0) ?0) 1066 | (+ 9 (or (seq-position jinx--select-keys (aref keys 1)) 999)) 1067 | (- (aref keys 0) ?1)) 1068 | (all-completions "" minibuffer-completion-table)))) 1069 | (unless (and word (get-text-property 0 'jinx--prefix word)) 1070 | (user-error "Invalid select key `%s'" (key-description keys))) 1071 | (delete-minibuffer-contents) 1072 | (insert word) 1073 | (exit-minibuffer))) 1074 | 1075 | (defun jinx-next (n) 1076 | "Go to to Nth next misspelled word." 1077 | (interactive "p" jinx-mode) 1078 | (unless (= n 0) 1079 | (if (minibufferp) 1080 | (throw 'jinx--goto n) 1081 | (let ((ov (jinx--force-overlays (point-min) (point-max)))) 1082 | (unless (or (> n 0) (<= (overlay-start (car ov)) (point) (overlay-end (car ov)))) 1083 | (cl-incf n)) 1084 | (goto-char (overlay-end (nth (mod n (length ov)) ov))) 1085 | (jinx--invisible-open-permanently))))) 1086 | 1087 | (defun jinx-previous (n) 1088 | "Go to to Nth previous misspelled word." 1089 | (interactive "p" jinx-mode) 1090 | (jinx-next (- n))) 1091 | 1092 | ;;;###autoload 1093 | (define-minor-mode jinx-mode 1094 | "Enchanted Spell Checker." 1095 | :lighter (" " (:eval (concat "Jinx[" jinx-languages "]"))) 1096 | :group 'jinx 1097 | :keymap jinx-mode-map 1098 | (cond 1099 | ((buffer-base-buffer) ;; Do not enable in indirect buffers 1100 | (when jinx-mode 1101 | (jinx-mode -1))) 1102 | (jinx-mode 1103 | (jinx--load-module) 1104 | (cl-letf* ((enable-local-variables :safe) 1105 | (enable-local-eval nil) 1106 | ;; Fix reentrancy problem (gh:minad/jinx#158) 1107 | ((symbol-function #'jinx-mode) #'ignore)) 1108 | (hack-local-variables 'ignore-mode)) 1109 | (jinx--get-org-language) 1110 | (setq jinx--exclude-regexp 1111 | (when-let ((regexps (jinx--mode-list jinx-exclude-regexps))) 1112 | (mapconcat (lambda (r) (format "\\(?:%s\\)" r)) 1113 | regexps "\\|")) 1114 | jinx--include-faces (jinx--mode-list jinx-include-faces) 1115 | jinx--exclude-faces (jinx--mode-list jinx-exclude-faces) 1116 | jinx--camel (or (eq jinx-camel-modes t) 1117 | (seq-some #'derived-mode-p jinx-camel-modes)) 1118 | jinx--session-words (nconc (split-string jinx-dir-local-words) 1119 | (split-string jinx-local-words))) 1120 | (jinx--load-dicts) 1121 | (dolist (hook jinx--reschedule-hooks) 1122 | (add-hook hook #'jinx--reschedule nil t)) 1123 | (jit-lock-register #'jinx--mark-pending)) 1124 | (t 1125 | (mapc #'kill-local-variable '(jinx--exclude-regexp jinx--include-faces 1126 | jinx--exclude-faces jinx--camel 1127 | jinx--dicts jinx--syntax-table 1128 | jinx--session-words)) 1129 | (dolist (hook jinx--reschedule-hooks) 1130 | (remove-hook hook #'jinx--reschedule t)) 1131 | (jit-lock-unregister #'jinx--mark-pending) 1132 | (jinx--cleanup)))) 1133 | 1134 | ;; TODO use `:predicate' on Emacs 29 1135 | (defcustom global-jinx-modes '(text-mode prog-mode conf-mode) 1136 | "List of modes where Jinx should be enabled. 1137 | The variable can either be t, nil or a list of t, nil, mode 1138 | symbols or elements of the form (not modes)." 1139 | :type '(repeat sexp)) 1140 | 1141 | ;;;###autoload 1142 | (define-globalized-minor-mode global-jinx-mode 1143 | jinx-mode jinx--on 1144 | :group 'jinx) 1145 | 1146 | (defun jinx--on () 1147 | "Turn `jinx-mode' on." 1148 | (when (and (not (or noninteractive 1149 | buffer-read-only 1150 | (buffer-base-buffer) ;; Do not enable in indirect buffers 1151 | (eq (aref (buffer-name) 0) ?\s))) 1152 | ;; TODO use `:predicate' on Emacs 29 1153 | (or (eq t global-jinx-modes) 1154 | (eq t (cl-loop for p in global-jinx-modes thereis 1155 | (pcase-exhaustive p 1156 | ('t t) 1157 | ('nil 0) 1158 | ((pred symbolp) (and (derived-mode-p p) t)) 1159 | (`(not . ,m) (and (seq-some #'derived-mode-p m) 0))))))) 1160 | (jinx-mode))) 1161 | 1162 | (provide 'jinx) 1163 | ;;; jinx.el ends here 1164 | --------------------------------------------------------------------------------