├── .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 | Make sure that you install the newest versions of the involved packages. Please
13 | also reinstall and recompile the involved packages, ideally remove all and
14 | reinstall all packages, to exclude compilation issues due to outdated
15 | dependencies.
16 |
17 | Please provide precise information, stack traces and the exact steps to
18 | reproduce the issue. This is important to ensure that your problem can be
19 | reproduced on a different machine.
20 |
21 | If you are not really sure if your issue is a bug, please open a discussion
22 | instead.
23 |
--------------------------------------------------------------------------------
/.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.4 (2025-10-13)
6 |
7 | - =jinx-exclude-properties=: New variable to exclude propertized text from
8 | checking. Exclude =read-only= text by default.
9 | - Use =eager-display= for the default completion UI.
10 | - Require Emacs 29.
11 |
12 | * Version 2.3 (2025-07-28)
13 |
14 | - ~jinx-correct-all~: Show message if ~ONLY-CHECK~ is non-nil.
15 |
16 | * Version 2.2 (2025-05-26)
17 |
18 | - Stop using =enchant_dict_get_extra_word_characters=. Instead rely on the
19 | =jinx--syntax-table= for tokenization.
20 |
21 | * Version 2.1 (2025-04-04)
22 |
23 | - ~jinx-correct~: For capitalized words, offer lower case variants to save in
24 | personal dictionary and file local variables.
25 | - Add ~help-echo~ to the Jinx overlays.
26 |
27 | * Version 2.0 (2025-03-11)
28 |
29 | - Add ~jinx-dir-local-words~ saved in ~.dir-locals.el~. Words can be added to the
30 | ~.dir-locals.el~ with the ~/~ key in the ~jinx-correct~ dialog. The ~.dir-locals.el~
31 | file of the current or a parent directory is used. If it does not exist it is
32 | created in the project root or the current directory.
33 |
34 | * Version 1.12 (2025-01-28)
35 |
36 | - Improve performance in large folded Org buffers.
37 | - Support ~lisp-data-mode~.
38 | - Retain dictionaries in weak hash table for sharing.
39 |
40 | * Version 1.11 (2024-12-22)
41 |
42 | - Require Emacs 28.1.
43 | - Remove special ~org-fold~ code. Set ~org-fold-core-style~ to ~overlays~ if unfolding
44 | in Org files does not work for you.
45 | - ~jinx-languages~: Group dictionaries by dictionary provider.
46 |
47 | * Version 1.10 (2024-07-23)
48 |
49 | - Bump Compat dependency to Compat 30.
50 | - Add include and linkpaths from FreeBSD for compilation.
51 | - Add ~jinx--syntax-overrides~ to override syntax table.
52 |
53 | * Version 1.9 (2024-06-29)
54 |
55 | - Bugfix: In some rare scenarios, Jinx could hang when checking pending regions.
56 | - ~jinx-correct-all~: Add ~ONLY-CHECK~ prefix argument.
57 |
58 | * Version 1.8 (2024-06-19)
59 |
60 | - Bugfix in ~jinx-correct~: Fix ~wrong-type-argument~ error if no Enchant
61 | dictionaries are found.
62 |
63 | * Version 1.7 (2024-05-15)
64 |
65 | - ~jinx--word-valid-p~: Do not error on invalid characters.
66 | - ~jinx-save-languages~: New custom variable.
67 |
68 | * Version 1.6 (2024-04-12)
69 |
70 | - Bugfix (again): Ensure that directory local variables work correctly with
71 | Jinx. It is possible to turn Jinx on or off via dir-locals, and also configure
72 | the language and local words.
73 |
74 | * Version 1.5 (2024-04-04)
75 |
76 | - Bugfix: Ensure that ~jinx-next~ unfolds hidden misspellings.
77 | - Bugfix: Ensure that directory local variable enabling ~jinx-mode~ works.
78 |
79 | * Version 1.4 (2024-03-10)
80 |
81 | - Bugfix: Ensure that ~jinx-correct~ saves words without text properties in the
82 | file-local variable ~jinx-local-words~.
83 | - Bugfix: Ensure that ~eval~ local variable enabling ~jinx-mode~ works.
84 | - ~jinx-correct~: If a region is marked, call ~jinx-correct-all~ and restrict
85 | corrections to the marked region.
86 | - ~jinx-exclude-faces~, ~jinx-include-faces~, ~jinx-exclude-regexps~: Support mode
87 | aliases.
88 |
89 | * Version 1.3 (2024-02-23)
90 |
91 | - Fix interaction bug with the newest version of AUCTeX, where the major mode
92 | got changed unexpectedly.
93 |
94 | * Version 1.2 (2024-01-22)
95 |
96 | - Fix deadlock on MacOS during Jinx startup.
97 | - Timer optimizations.
98 |
99 | * Version 1.1 (2023-12-27)
100 |
101 | - Add mouse context menu to correct misspellings. The menu is triggered by a
102 | right click on a misspelling.
103 |
104 | * Version 1.0 (2023-12-01)
105 |
106 | - Allow capitalized form of a word if non-capitalized word is stored in the
107 | session word list.
108 | - Replace =jinx-excluded-modes= with =global-jinx-modes=, the Emacs 28 convention
109 | for globalized minor modes.
110 | - =jinx-correct=: Offer session words as suggestions.
111 | - Add =jinx-correct-nearest=, =jinx-correct-all= and =jinx-correct-word= commands. The
112 | command =jinx-correct= dispatches to one of those commands depending on the
113 | prefix argument.
114 | - Recommend libenchant 2.3.1 or newer. Print a message if Enchant is outdated.
115 | - Support $LANG=C and $LANG=POSIX environment variable settings.
116 |
117 | * Version 0.9 (2023-07-02)
118 |
119 | - 🪄 Make sure that Emojis are not marked as misspelled 🧙🏼♀️.
120 | - Rename =jinx-correct-next/previous= to =jinx-next/previous=. The commands can be
121 | used outside the minibuffer.
122 | - Bind =M-n= and =M-p= to =jinx-next/previous= in =jinx-overlay-map=.
123 | - Bind =M-$= to =jinx-correct= in the =jinx-overlay-map=.
124 | - Add =jinx-repeat-map=.
125 | - Rename category of Jinx overlays to =jinx-overlay=.
126 | - Rename =jinx-misspelled-map= to =jinx-overlay-map=.
127 | - Add many more language modes to =jinx-camel-modes=.
128 |
129 | * Version 0.8 (2023-04-28)
130 |
131 | - =jinx-correct=: Consistently move backward to the previous misspelling. In order
132 | to move backward further, press =M-$= again (or =M-p=). Move forward with =M-n=.
133 | - =jinx-correct-select=: Support more than 10 quick keys.
134 | - =jinx-languages=: New argument =LANGS=.
135 | - Add =jinx-faces= customization group.
136 | - Add configurable save actions via =jinx--save-keys=.
137 | - Detect C compiler via $CC or =executable-find=.
138 |
139 | * Version 0.7 (2023-04-21)
140 |
141 | - Bugfixes
142 | - =jinx-languages=: Only ask in file-backed buffers if file-local variable should
143 | be saved.
144 | - Push =undo-boundary= before correcting a word, such that corrections are not
145 | undone in a single step.
146 | - =jinx-correct=: Use =+= as prefix to add word to the current session.
147 | - Add =jinx-correct-map= bound in the =jinx-correct= minibuffer.
148 | - Add navigation keys to correction UI. The commands =jinx-correct-next= and
149 | =jinx-correct-previous= are bound to the keys =M-n= and =M-p= in the
150 | =jinx-correct-map= respectively. The commands accept prefix arguments to skip
151 | over a number of misspellings.
152 | - Add quick selection keys to correction UI. The command =jinx-correct-select= is
153 | bound to the keys =1= to =9= in the =jinx-correct-map=.
154 | - Try to locate the native module =jinx-mod.so= first on the =load-path= before
155 | attempting to compile it. This is useful if the module is packed and installed
156 | separately.
157 |
158 | * Version 0.6 (2023-04-17)
159 |
160 | - Fix the type of a few characters: =.= punctuation character, ='= word character, =%=
161 | and =$= identifier characters.
162 | - Abandon =flyspell-mode-predicate= completely. Rely on faces only.
163 | - =jinx-languages=: The value must be a string now. Multiple language codes can be
164 | separated by space.
165 | - =jinx-languages=: Ask if the file-local variable should be saved when changing
166 | the language.
167 | - Add =jinx-local-words= to save file-local words. =jinx-correct= supports saving to
168 | =jinx-local-words= by pressing =*=.
169 | - Add a lighter and a minor mode menu.
170 | - Avoid scheduling the idle timer while typing a word.
171 |
172 | * Version 0.5 (2023-04-05)
173 |
174 | - Add =jinx-languages= command to switch languages locally or globally.
175 | - =jinx-correct=: When checking the whole buffer via =C-u M-$=, don't restore
176 | original point position upon =C-g= to ease cursory edits. Instead push a mark
177 | which can be used to go back to the original position.
178 | - Add =jinx-mode-map= to make it easy to bind keys if =jinx-mode= is enabled. The
179 | map is empty by default.
180 | - Ignore single quotes and apostrophes at the beginning and end of words. Please
181 | provide feedback if this is a reasonable approach.
182 | - Support spell checking of camelCased words via the =jinx-camel-modes= variable.
183 |
184 | * Version 0.4 (2023-03-27)
185 |
186 | - =jinx-languages=: Fall back to =$LANG= environment variable, since
187 | =current-locale-environment= is an Emacs 29 addition.
188 | - =jinx--mod-wordchars=: Handle non-UTF8 return values gracefully.
189 | - =jinx-correct=: Always start from nearest overlay.
190 | - =jinx-misspelled=: Use less obtrusive color for the underlining.
191 |
192 | * Version 0.3 (2023-03-27)
193 |
194 | - Add =jinx-misspelled-map=.
195 | - =jinx-correct=: Unfold invisible line when correcting misspellings.
196 | - =jinx-correct=: Show number of misspellings.
197 | - Add =emacs-module.h= to avoid compilation problems.
198 | - =jinx-languages=: Use =current-locale-environment= by default.
199 |
200 | * Version 0.2 (2023-03-26)
201 |
202 | - Start of changelog.
203 |
--------------------------------------------------------------------------------
/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:
10 | #+html:
11 | #+html:
12 | #+html:
13 | #+html:
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]], [[https://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-2023 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 | #if ((defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 202311 \
34 | && !defined __bool_true_false_are_defined && !defined __cplusplus)
35 | #include
36 | #endif
37 |
38 | #define EMACS_MAJOR_VERSION 29
39 |
40 | #if defined __cplusplus && __cplusplus >= 201103L
41 | # define EMACS_NOEXCEPT noexcept
42 | #else
43 | # define EMACS_NOEXCEPT
44 | #endif
45 |
46 | #if defined __cplusplus && __cplusplus >= 201703L
47 | # define EMACS_NOEXCEPT_TYPEDEF noexcept
48 | #else
49 | # define EMACS_NOEXCEPT_TYPEDEF
50 | #endif
51 |
52 | #if 3 < __GNUC__ + (3 <= __GNUC_MINOR__)
53 | # define EMACS_ATTRIBUTE_NONNULL(...) \
54 | __attribute__ ((__nonnull__ (__VA_ARGS__)))
55 | #elif (defined __has_attribute \
56 | && (!defined __clang_minor__ \
57 | || 3 < __clang_major__ + (5 <= __clang_minor__)))
58 | # if __has_attribute (__nonnull__)
59 | # define EMACS_ATTRIBUTE_NONNULL(...) \
60 | __attribute__ ((__nonnull__ (__VA_ARGS__)))
61 | # endif
62 | #endif
63 | #ifndef EMACS_ATTRIBUTE_NONNULL
64 | # define EMACS_ATTRIBUTE_NONNULL(...)
65 | #endif
66 |
67 | #ifdef __cplusplus
68 | extern "C" {
69 | #endif
70 |
71 | /* Current environment. */
72 | typedef struct emacs_env_29 emacs_env;
73 |
74 | /* Opaque pointer representing an Emacs Lisp value.
75 | BEWARE: Do not assume NULL is a valid value! */
76 | typedef struct emacs_value_tag *emacs_value;
77 |
78 | enum { emacs_variadic_function = -2 };
79 |
80 | /* Struct passed to a module init function (emacs_module_init). */
81 | struct emacs_runtime
82 | {
83 | /* Structure size (for version checking). */
84 | ptrdiff_t size;
85 |
86 | /* Private data; users should not touch this. */
87 | struct emacs_runtime_private *private_members;
88 |
89 | /* Return an environment pointer. */
90 | emacs_env *(*get_environment) (struct emacs_runtime *runtime)
91 | EMACS_ATTRIBUTE_NONNULL (1);
92 | };
93 |
94 | /* Type aliases for function pointer types used in the module API.
95 | Note that we don't use these aliases directly in the API to be able
96 | to mark the function arguments as 'noexcept' before C++20.
97 | However, users can use them if they want. */
98 |
99 | /* Function prototype for the module Lisp functions. These must not
100 | throw C++ exceptions. */
101 | typedef emacs_value (*emacs_function) (emacs_env *env, ptrdiff_t nargs,
102 | emacs_value *args,
103 | void *data)
104 | EMACS_NOEXCEPT_TYPEDEF EMACS_ATTRIBUTE_NONNULL (1);
105 |
106 | /* Function prototype for module user-pointer and function finalizers.
107 | These must not throw C++ exceptions. */
108 | typedef void (*emacs_finalizer) (void *data) EMACS_NOEXCEPT_TYPEDEF;
109 |
110 | /* Possible Emacs function call outcomes. */
111 | enum emacs_funcall_exit
112 | {
113 | /* Function has returned normally. */
114 | emacs_funcall_exit_return = 0,
115 |
116 | /* Function has signaled an error using `signal'. */
117 | emacs_funcall_exit_signal = 1,
118 |
119 | /* Function has exited using `throw'. */
120 | emacs_funcall_exit_throw = 2
121 | };
122 |
123 | /* Possible return values for emacs_env.process_input. */
124 | enum emacs_process_input_result
125 | {
126 | /* Module code may continue */
127 | emacs_process_input_continue = 0,
128 |
129 | /* Module code should return control to Emacs as soon as possible. */
130 | emacs_process_input_quit = 1
131 | };
132 |
133 | /* Define emacs_limb_t so that it is likely to match GMP's mp_limb_t.
134 | This micro-optimization can help modules that use mpz_export and
135 | mpz_import, which operate more efficiently on mp_limb_t. It's OK
136 | (if perhaps a bit slower) if the two types do not match, and
137 | modules shouldn't rely on the two types matching. */
138 | typedef size_t emacs_limb_t;
139 | #define EMACS_LIMB_MAX SIZE_MAX
140 |
141 | struct emacs_env_25
142 | {
143 | /* Structure size (for version checking). */
144 | ptrdiff_t size;
145 |
146 | /* Private data; users should not touch this. */
147 | struct emacs_env_private *private_members;
148 |
149 | /* Memory management. */
150 |
151 | emacs_value (*make_global_ref) (emacs_env *env, emacs_value value)
152 | EMACS_ATTRIBUTE_NONNULL(1);
153 |
154 | void (*free_global_ref) (emacs_env *env, emacs_value global_value)
155 | EMACS_ATTRIBUTE_NONNULL(1);
156 |
157 | /* Non-local exit handling. */
158 |
159 | enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env)
160 | EMACS_ATTRIBUTE_NONNULL(1);
161 |
162 | void (*non_local_exit_clear) (emacs_env *env)
163 | EMACS_ATTRIBUTE_NONNULL(1);
164 |
165 | enum emacs_funcall_exit (*non_local_exit_get)
166 | (emacs_env *env, emacs_value *symbol, emacs_value *data)
167 | EMACS_ATTRIBUTE_NONNULL(1, 2, 3);
168 |
169 | void (*non_local_exit_signal) (emacs_env *env,
170 | emacs_value symbol, emacs_value data)
171 | EMACS_ATTRIBUTE_NONNULL(1);
172 |
173 | void (*non_local_exit_throw) (emacs_env *env,
174 | emacs_value tag, emacs_value value)
175 | EMACS_ATTRIBUTE_NONNULL(1);
176 |
177 | /* Function registration. */
178 |
179 | emacs_value (*make_function) (emacs_env *env,
180 | ptrdiff_t min_arity,
181 | ptrdiff_t max_arity,
182 | emacs_value (*func) (emacs_env *env,
183 | ptrdiff_t nargs,
184 | emacs_value* args,
185 | void *data)
186 | EMACS_NOEXCEPT
187 | EMACS_ATTRIBUTE_NONNULL(1),
188 | const char *docstring,
189 | void *data)
190 | EMACS_ATTRIBUTE_NONNULL(1, 4);
191 |
192 | emacs_value (*funcall) (emacs_env *env,
193 | emacs_value func,
194 | ptrdiff_t nargs,
195 | emacs_value* args)
196 | EMACS_ATTRIBUTE_NONNULL(1);
197 |
198 | emacs_value (*intern) (emacs_env *env, const char *name)
199 | EMACS_ATTRIBUTE_NONNULL(1, 2);
200 |
201 | /* Type conversion. */
202 |
203 | emacs_value (*type_of) (emacs_env *env, emacs_value arg)
204 | EMACS_ATTRIBUTE_NONNULL(1);
205 |
206 | bool (*is_not_nil) (emacs_env *env, emacs_value arg)
207 | EMACS_ATTRIBUTE_NONNULL(1);
208 |
209 | bool (*eq) (emacs_env *env, emacs_value a, emacs_value b)
210 | EMACS_ATTRIBUTE_NONNULL(1);
211 |
212 | intmax_t (*extract_integer) (emacs_env *env, emacs_value arg)
213 | EMACS_ATTRIBUTE_NONNULL(1);
214 |
215 | emacs_value (*make_integer) (emacs_env *env, intmax_t n)
216 | EMACS_ATTRIBUTE_NONNULL(1);
217 |
218 | double (*extract_float) (emacs_env *env, emacs_value arg)
219 | EMACS_ATTRIBUTE_NONNULL(1);
220 |
221 | emacs_value (*make_float) (emacs_env *env, double d)
222 | EMACS_ATTRIBUTE_NONNULL(1);
223 |
224 | /* Copy the content of the Lisp string VALUE to BUFFER as an utf8
225 | null-terminated string.
226 |
227 | SIZE must point to the total size of the buffer. If BUFFER is
228 | NULL or if SIZE is not big enough, write the required buffer size
229 | to SIZE and return true.
230 |
231 | Note that SIZE must include the last null byte (e.g. "abc" needs
232 | a buffer of size 4).
233 |
234 | Return true if the string was successfully copied. */
235 |
236 | bool (*copy_string_contents) (emacs_env *env,
237 | emacs_value value,
238 | char *buf,
239 | ptrdiff_t *len)
240 | EMACS_ATTRIBUTE_NONNULL(1, 4);
241 |
242 | /* Create a Lisp string from a utf8 encoded string. */
243 | emacs_value (*make_string) (emacs_env *env,
244 | const char *str, ptrdiff_t len)
245 | EMACS_ATTRIBUTE_NONNULL(1, 2);
246 |
247 | /* Embedded pointer type. */
248 | emacs_value (*make_user_ptr) (emacs_env *env,
249 | void (*fin) (void *) EMACS_NOEXCEPT,
250 | void *ptr)
251 | EMACS_ATTRIBUTE_NONNULL(1);
252 |
253 | void *(*get_user_ptr) (emacs_env *env, emacs_value arg)
254 | EMACS_ATTRIBUTE_NONNULL(1);
255 | void (*set_user_ptr) (emacs_env *env, emacs_value arg, void *ptr)
256 | EMACS_ATTRIBUTE_NONNULL(1);
257 |
258 | void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr))
259 | (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1);
260 | void (*set_user_finalizer) (emacs_env *env, emacs_value arg,
261 | void (*fin) (void *) EMACS_NOEXCEPT)
262 | EMACS_ATTRIBUTE_NONNULL(1);
263 |
264 | /* Vector functions. */
265 | emacs_value (*vec_get) (emacs_env *env, emacs_value vector, ptrdiff_t index)
266 | EMACS_ATTRIBUTE_NONNULL(1);
267 |
268 | void (*vec_set) (emacs_env *env, emacs_value vector, ptrdiff_t index,
269 | emacs_value value)
270 | EMACS_ATTRIBUTE_NONNULL(1);
271 |
272 | ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vector)
273 | EMACS_ATTRIBUTE_NONNULL(1);
274 | };
275 |
276 | struct emacs_env_26
277 | {
278 | /* Structure size (for version checking). */
279 | ptrdiff_t size;
280 |
281 | /* Private data; users should not touch this. */
282 | struct emacs_env_private *private_members;
283 |
284 | /* Memory management. */
285 |
286 | emacs_value (*make_global_ref) (emacs_env *env, emacs_value value)
287 | EMACS_ATTRIBUTE_NONNULL(1);
288 |
289 | void (*free_global_ref) (emacs_env *env, emacs_value global_value)
290 | EMACS_ATTRIBUTE_NONNULL(1);
291 |
292 | /* Non-local exit handling. */
293 |
294 | enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env)
295 | EMACS_ATTRIBUTE_NONNULL(1);
296 |
297 | void (*non_local_exit_clear) (emacs_env *env)
298 | EMACS_ATTRIBUTE_NONNULL(1);
299 |
300 | enum emacs_funcall_exit (*non_local_exit_get)
301 | (emacs_env *env, emacs_value *symbol, emacs_value *data)
302 | EMACS_ATTRIBUTE_NONNULL(1, 2, 3);
303 |
304 | void (*non_local_exit_signal) (emacs_env *env,
305 | emacs_value symbol, emacs_value data)
306 | EMACS_ATTRIBUTE_NONNULL(1);
307 |
308 | void (*non_local_exit_throw) (emacs_env *env,
309 | emacs_value tag, emacs_value value)
310 | EMACS_ATTRIBUTE_NONNULL(1);
311 |
312 | /* Function registration. */
313 |
314 | emacs_value (*make_function) (emacs_env *env,
315 | ptrdiff_t min_arity,
316 | ptrdiff_t max_arity,
317 | emacs_value (*func) (emacs_env *env,
318 | ptrdiff_t nargs,
319 | emacs_value* args,
320 | void *data)
321 | EMACS_NOEXCEPT
322 | EMACS_ATTRIBUTE_NONNULL(1),
323 | const char *docstring,
324 | void *data)
325 | EMACS_ATTRIBUTE_NONNULL(1, 4);
326 |
327 | emacs_value (*funcall) (emacs_env *env,
328 | emacs_value func,
329 | ptrdiff_t nargs,
330 | emacs_value* args)
331 | EMACS_ATTRIBUTE_NONNULL(1);
332 |
333 | emacs_value (*intern) (emacs_env *env, const char *name)
334 | EMACS_ATTRIBUTE_NONNULL(1, 2);
335 |
336 | /* Type conversion. */
337 |
338 | emacs_value (*type_of) (emacs_env *env, emacs_value arg)
339 | EMACS_ATTRIBUTE_NONNULL(1);
340 |
341 | bool (*is_not_nil) (emacs_env *env, emacs_value arg)
342 | EMACS_ATTRIBUTE_NONNULL(1);
343 |
344 | bool (*eq) (emacs_env *env, emacs_value a, emacs_value b)
345 | EMACS_ATTRIBUTE_NONNULL(1);
346 |
347 | intmax_t (*extract_integer) (emacs_env *env, emacs_value arg)
348 | EMACS_ATTRIBUTE_NONNULL(1);
349 |
350 | emacs_value (*make_integer) (emacs_env *env, intmax_t n)
351 | EMACS_ATTRIBUTE_NONNULL(1);
352 |
353 | double (*extract_float) (emacs_env *env, emacs_value arg)
354 | EMACS_ATTRIBUTE_NONNULL(1);
355 |
356 | emacs_value (*make_float) (emacs_env *env, double d)
357 | EMACS_ATTRIBUTE_NONNULL(1);
358 |
359 | /* Copy the content of the Lisp string VALUE to BUFFER as an utf8
360 | null-terminated string.
361 |
362 | SIZE must point to the total size of the buffer. If BUFFER is
363 | NULL or if SIZE is not big enough, write the required buffer size
364 | to SIZE and return true.
365 |
366 | Note that SIZE must include the last null byte (e.g. "abc" needs
367 | a buffer of size 4).
368 |
369 | Return true if the string was successfully copied. */
370 |
371 | bool (*copy_string_contents) (emacs_env *env,
372 | emacs_value value,
373 | char *buf,
374 | ptrdiff_t *len)
375 | EMACS_ATTRIBUTE_NONNULL(1, 4);
376 |
377 | /* Create a Lisp string from a utf8 encoded string. */
378 | emacs_value (*make_string) (emacs_env *env,
379 | const char *str, ptrdiff_t len)
380 | EMACS_ATTRIBUTE_NONNULL(1, 2);
381 |
382 | /* Embedded pointer type. */
383 | emacs_value (*make_user_ptr) (emacs_env *env,
384 | void (*fin) (void *) EMACS_NOEXCEPT,
385 | void *ptr)
386 | EMACS_ATTRIBUTE_NONNULL(1);
387 |
388 | void *(*get_user_ptr) (emacs_env *env, emacs_value arg)
389 | EMACS_ATTRIBUTE_NONNULL(1);
390 | void (*set_user_ptr) (emacs_env *env, emacs_value arg, void *ptr)
391 | EMACS_ATTRIBUTE_NONNULL(1);
392 |
393 | void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr))
394 | (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1);
395 | void (*set_user_finalizer) (emacs_env *env, emacs_value arg,
396 | void (*fin) (void *) EMACS_NOEXCEPT)
397 | EMACS_ATTRIBUTE_NONNULL(1);
398 |
399 | /* Vector functions. */
400 | emacs_value (*vec_get) (emacs_env *env, emacs_value vector, ptrdiff_t index)
401 | EMACS_ATTRIBUTE_NONNULL(1);
402 |
403 | void (*vec_set) (emacs_env *env, emacs_value vector, ptrdiff_t index,
404 | emacs_value value)
405 | EMACS_ATTRIBUTE_NONNULL(1);
406 |
407 | ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vector)
408 | EMACS_ATTRIBUTE_NONNULL(1);
409 |
410 | /* Returns whether a quit is pending. */
411 | bool (*should_quit) (emacs_env *env)
412 | EMACS_ATTRIBUTE_NONNULL(1);
413 | };
414 |
415 | struct emacs_env_27
416 | {
417 | /* Structure size (for version checking). */
418 | ptrdiff_t size;
419 |
420 | /* Private data; users should not touch this. */
421 | struct emacs_env_private *private_members;
422 |
423 | /* Memory management. */
424 |
425 | emacs_value (*make_global_ref) (emacs_env *env, emacs_value value)
426 | EMACS_ATTRIBUTE_NONNULL(1);
427 |
428 | void (*free_global_ref) (emacs_env *env, emacs_value global_value)
429 | EMACS_ATTRIBUTE_NONNULL(1);
430 |
431 | /* Non-local exit handling. */
432 |
433 | enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env)
434 | EMACS_ATTRIBUTE_NONNULL(1);
435 |
436 | void (*non_local_exit_clear) (emacs_env *env)
437 | EMACS_ATTRIBUTE_NONNULL(1);
438 |
439 | enum emacs_funcall_exit (*non_local_exit_get)
440 | (emacs_env *env, emacs_value *symbol, emacs_value *data)
441 | EMACS_ATTRIBUTE_NONNULL(1, 2, 3);
442 |
443 | void (*non_local_exit_signal) (emacs_env *env,
444 | emacs_value symbol, emacs_value data)
445 | EMACS_ATTRIBUTE_NONNULL(1);
446 |
447 | void (*non_local_exit_throw) (emacs_env *env,
448 | emacs_value tag, emacs_value value)
449 | EMACS_ATTRIBUTE_NONNULL(1);
450 |
451 | /* Function registration. */
452 |
453 | emacs_value (*make_function) (emacs_env *env,
454 | ptrdiff_t min_arity,
455 | ptrdiff_t max_arity,
456 | emacs_value (*func) (emacs_env *env,
457 | ptrdiff_t nargs,
458 | emacs_value* args,
459 | void *data)
460 | EMACS_NOEXCEPT
461 | EMACS_ATTRIBUTE_NONNULL(1),
462 | const char *docstring,
463 | void *data)
464 | EMACS_ATTRIBUTE_NONNULL(1, 4);
465 |
466 | emacs_value (*funcall) (emacs_env *env,
467 | emacs_value func,
468 | ptrdiff_t nargs,
469 | emacs_value* args)
470 | EMACS_ATTRIBUTE_NONNULL(1);
471 |
472 | emacs_value (*intern) (emacs_env *env, const char *name)
473 | EMACS_ATTRIBUTE_NONNULL(1, 2);
474 |
475 | /* Type conversion. */
476 |
477 | emacs_value (*type_of) (emacs_env *env, emacs_value arg)
478 | EMACS_ATTRIBUTE_NONNULL(1);
479 |
480 | bool (*is_not_nil) (emacs_env *env, emacs_value arg)
481 | EMACS_ATTRIBUTE_NONNULL(1);
482 |
483 | bool (*eq) (emacs_env *env, emacs_value a, emacs_value b)
484 | EMACS_ATTRIBUTE_NONNULL(1);
485 |
486 | intmax_t (*extract_integer) (emacs_env *env, emacs_value arg)
487 | EMACS_ATTRIBUTE_NONNULL(1);
488 |
489 | emacs_value (*make_integer) (emacs_env *env, intmax_t n)
490 | EMACS_ATTRIBUTE_NONNULL(1);
491 |
492 | double (*extract_float) (emacs_env *env, emacs_value arg)
493 | EMACS_ATTRIBUTE_NONNULL(1);
494 |
495 | emacs_value (*make_float) (emacs_env *env, double d)
496 | EMACS_ATTRIBUTE_NONNULL(1);
497 |
498 | /* Copy the content of the Lisp string VALUE to BUFFER as an utf8
499 | null-terminated string.
500 |
501 | SIZE must point to the total size of the buffer. If BUFFER is
502 | NULL or if SIZE is not big enough, write the required buffer size
503 | to SIZE and return true.
504 |
505 | Note that SIZE must include the last null byte (e.g. "abc" needs
506 | a buffer of size 4).
507 |
508 | Return true if the string was successfully copied. */
509 |
510 | bool (*copy_string_contents) (emacs_env *env,
511 | emacs_value value,
512 | char *buf,
513 | ptrdiff_t *len)
514 | EMACS_ATTRIBUTE_NONNULL(1, 4);
515 |
516 | /* Create a Lisp string from a utf8 encoded string. */
517 | emacs_value (*make_string) (emacs_env *env,
518 | const char *str, ptrdiff_t len)
519 | EMACS_ATTRIBUTE_NONNULL(1, 2);
520 |
521 | /* Embedded pointer type. */
522 | emacs_value (*make_user_ptr) (emacs_env *env,
523 | void (*fin) (void *) EMACS_NOEXCEPT,
524 | void *ptr)
525 | EMACS_ATTRIBUTE_NONNULL(1);
526 |
527 | void *(*get_user_ptr) (emacs_env *env, emacs_value arg)
528 | EMACS_ATTRIBUTE_NONNULL(1);
529 | void (*set_user_ptr) (emacs_env *env, emacs_value arg, void *ptr)
530 | EMACS_ATTRIBUTE_NONNULL(1);
531 |
532 | void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr))
533 | (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1);
534 | void (*set_user_finalizer) (emacs_env *env, emacs_value arg,
535 | void (*fin) (void *) EMACS_NOEXCEPT)
536 | EMACS_ATTRIBUTE_NONNULL(1);
537 |
538 | /* Vector functions. */
539 | emacs_value (*vec_get) (emacs_env *env, emacs_value vector, ptrdiff_t index)
540 | EMACS_ATTRIBUTE_NONNULL(1);
541 |
542 | void (*vec_set) (emacs_env *env, emacs_value vector, ptrdiff_t index,
543 | emacs_value value)
544 | EMACS_ATTRIBUTE_NONNULL(1);
545 |
546 | ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vector)
547 | EMACS_ATTRIBUTE_NONNULL(1);
548 |
549 | /* Returns whether a quit is pending. */
550 | bool (*should_quit) (emacs_env *env)
551 | EMACS_ATTRIBUTE_NONNULL(1);
552 |
553 | /* Processes pending input events and returns whether the module
554 | function should quit. */
555 | enum emacs_process_input_result (*process_input) (emacs_env *env)
556 | EMACS_ATTRIBUTE_NONNULL (1);
557 |
558 | struct timespec (*extract_time) (emacs_env *env, emacs_value arg)
559 | EMACS_ATTRIBUTE_NONNULL (1);
560 |
561 | emacs_value (*make_time) (emacs_env *env, struct timespec time)
562 | EMACS_ATTRIBUTE_NONNULL (1);
563 |
564 | bool (*extract_big_integer) (emacs_env *env, emacs_value arg, int *sign,
565 | ptrdiff_t *count, emacs_limb_t *magnitude)
566 | EMACS_ATTRIBUTE_NONNULL (1);
567 |
568 | emacs_value (*make_big_integer) (emacs_env *env, int sign, ptrdiff_t count,
569 | const emacs_limb_t *magnitude)
570 | EMACS_ATTRIBUTE_NONNULL (1);
571 | };
572 |
573 | struct emacs_env_28
574 | {
575 | /* Structure size (for version checking). */
576 | ptrdiff_t size;
577 |
578 | /* Private data; users should not touch this. */
579 | struct emacs_env_private *private_members;
580 |
581 | /* Memory management. */
582 |
583 | emacs_value (*make_global_ref) (emacs_env *env, emacs_value value)
584 | EMACS_ATTRIBUTE_NONNULL(1);
585 |
586 | void (*free_global_ref) (emacs_env *env, emacs_value global_value)
587 | EMACS_ATTRIBUTE_NONNULL(1);
588 |
589 | /* Non-local exit handling. */
590 |
591 | enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env)
592 | EMACS_ATTRIBUTE_NONNULL(1);
593 |
594 | void (*non_local_exit_clear) (emacs_env *env)
595 | EMACS_ATTRIBUTE_NONNULL(1);
596 |
597 | enum emacs_funcall_exit (*non_local_exit_get)
598 | (emacs_env *env, emacs_value *symbol, emacs_value *data)
599 | EMACS_ATTRIBUTE_NONNULL(1, 2, 3);
600 |
601 | void (*non_local_exit_signal) (emacs_env *env,
602 | emacs_value symbol, emacs_value data)
603 | EMACS_ATTRIBUTE_NONNULL(1);
604 |
605 | void (*non_local_exit_throw) (emacs_env *env,
606 | emacs_value tag, emacs_value value)
607 | EMACS_ATTRIBUTE_NONNULL(1);
608 |
609 | /* Function registration. */
610 |
611 | emacs_value (*make_function) (emacs_env *env,
612 | ptrdiff_t min_arity,
613 | ptrdiff_t max_arity,
614 | emacs_value (*func) (emacs_env *env,
615 | ptrdiff_t nargs,
616 | emacs_value* args,
617 | void *data)
618 | EMACS_NOEXCEPT
619 | EMACS_ATTRIBUTE_NONNULL(1),
620 | const char *docstring,
621 | void *data)
622 | EMACS_ATTRIBUTE_NONNULL(1, 4);
623 |
624 | emacs_value (*funcall) (emacs_env *env,
625 | emacs_value func,
626 | ptrdiff_t nargs,
627 | emacs_value* args)
628 | EMACS_ATTRIBUTE_NONNULL(1);
629 |
630 | emacs_value (*intern) (emacs_env *env, const char *name)
631 | EMACS_ATTRIBUTE_NONNULL(1, 2);
632 |
633 | /* Type conversion. */
634 |
635 | emacs_value (*type_of) (emacs_env *env, emacs_value arg)
636 | EMACS_ATTRIBUTE_NONNULL(1);
637 |
638 | bool (*is_not_nil) (emacs_env *env, emacs_value arg)
639 | EMACS_ATTRIBUTE_NONNULL(1);
640 |
641 | bool (*eq) (emacs_env *env, emacs_value a, emacs_value b)
642 | EMACS_ATTRIBUTE_NONNULL(1);
643 |
644 | intmax_t (*extract_integer) (emacs_env *env, emacs_value arg)
645 | EMACS_ATTRIBUTE_NONNULL(1);
646 |
647 | emacs_value (*make_integer) (emacs_env *env, intmax_t n)
648 | EMACS_ATTRIBUTE_NONNULL(1);
649 |
650 | double (*extract_float) (emacs_env *env, emacs_value arg)
651 | EMACS_ATTRIBUTE_NONNULL(1);
652 |
653 | emacs_value (*make_float) (emacs_env *env, double d)
654 | EMACS_ATTRIBUTE_NONNULL(1);
655 |
656 | /* Copy the content of the Lisp string VALUE to BUFFER as an utf8
657 | null-terminated string.
658 |
659 | SIZE must point to the total size of the buffer. If BUFFER is
660 | NULL or if SIZE is not big enough, write the required buffer size
661 | to SIZE and return true.
662 |
663 | Note that SIZE must include the last null byte (e.g. "abc" needs
664 | a buffer of size 4).
665 |
666 | Return true if the string was successfully copied. */
667 |
668 | bool (*copy_string_contents) (emacs_env *env,
669 | emacs_value value,
670 | char *buf,
671 | ptrdiff_t *len)
672 | EMACS_ATTRIBUTE_NONNULL(1, 4);
673 |
674 | /* Create a Lisp string from a utf8 encoded string. */
675 | emacs_value (*make_string) (emacs_env *env,
676 | const char *str, ptrdiff_t len)
677 | EMACS_ATTRIBUTE_NONNULL(1, 2);
678 |
679 | /* Embedded pointer type. */
680 | emacs_value (*make_user_ptr) (emacs_env *env,
681 | void (*fin) (void *) EMACS_NOEXCEPT,
682 | void *ptr)
683 | EMACS_ATTRIBUTE_NONNULL(1);
684 |
685 | void *(*get_user_ptr) (emacs_env *env, emacs_value arg)
686 | EMACS_ATTRIBUTE_NONNULL(1);
687 | void (*set_user_ptr) (emacs_env *env, emacs_value arg, void *ptr)
688 | EMACS_ATTRIBUTE_NONNULL(1);
689 |
690 | void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr))
691 | (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1);
692 | void (*set_user_finalizer) (emacs_env *env, emacs_value arg,
693 | void (*fin) (void *) EMACS_NOEXCEPT)
694 | EMACS_ATTRIBUTE_NONNULL(1);
695 |
696 | /* Vector functions. */
697 | emacs_value (*vec_get) (emacs_env *env, emacs_value vector, ptrdiff_t index)
698 | EMACS_ATTRIBUTE_NONNULL(1);
699 |
700 | void (*vec_set) (emacs_env *env, emacs_value vector, ptrdiff_t index,
701 | emacs_value value)
702 | EMACS_ATTRIBUTE_NONNULL(1);
703 |
704 | ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vector)
705 | EMACS_ATTRIBUTE_NONNULL(1);
706 |
707 | /* Returns whether a quit is pending. */
708 | bool (*should_quit) (emacs_env *env)
709 | EMACS_ATTRIBUTE_NONNULL(1);
710 |
711 | /* Processes pending input events and returns whether the module
712 | function should quit. */
713 | enum emacs_process_input_result (*process_input) (emacs_env *env)
714 | EMACS_ATTRIBUTE_NONNULL (1);
715 |
716 | struct timespec (*extract_time) (emacs_env *env, emacs_value arg)
717 | EMACS_ATTRIBUTE_NONNULL (1);
718 |
719 | emacs_value (*make_time) (emacs_env *env, struct timespec time)
720 | EMACS_ATTRIBUTE_NONNULL (1);
721 |
722 | bool (*extract_big_integer) (emacs_env *env, emacs_value arg, int *sign,
723 | ptrdiff_t *count, emacs_limb_t *magnitude)
724 | EMACS_ATTRIBUTE_NONNULL (1);
725 |
726 | emacs_value (*make_big_integer) (emacs_env *env, int sign, ptrdiff_t count,
727 | const emacs_limb_t *magnitude)
728 | EMACS_ATTRIBUTE_NONNULL (1);
729 |
730 | void (*(*EMACS_ATTRIBUTE_NONNULL (1)
731 | get_function_finalizer) (emacs_env *env,
732 | emacs_value arg)) (void *) EMACS_NOEXCEPT;
733 |
734 | void (*set_function_finalizer) (emacs_env *env, emacs_value arg,
735 | void (*fin) (void *) EMACS_NOEXCEPT)
736 | EMACS_ATTRIBUTE_NONNULL (1);
737 |
738 | int (*open_channel) (emacs_env *env, emacs_value pipe_process)
739 | EMACS_ATTRIBUTE_NONNULL (1);
740 |
741 | void (*make_interactive) (emacs_env *env, emacs_value function,
742 | emacs_value spec)
743 | EMACS_ATTRIBUTE_NONNULL (1);
744 |
745 | /* Create a unibyte Lisp string from a string. */
746 | emacs_value (*make_unibyte_string) (emacs_env *env,
747 | const char *str, ptrdiff_t len)
748 | EMACS_ATTRIBUTE_NONNULL(1, 2);
749 | };
750 |
751 | struct emacs_env_29
752 | {
753 | /* Structure size (for version checking). */
754 | ptrdiff_t size;
755 |
756 | /* Private data; users should not touch this. */
757 | struct emacs_env_private *private_members;
758 |
759 | /* Memory management. */
760 |
761 | emacs_value (*make_global_ref) (emacs_env *env, emacs_value value)
762 | EMACS_ATTRIBUTE_NONNULL(1);
763 |
764 | void (*free_global_ref) (emacs_env *env, emacs_value global_value)
765 | EMACS_ATTRIBUTE_NONNULL(1);
766 |
767 | /* Non-local exit handling. */
768 |
769 | enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env)
770 | EMACS_ATTRIBUTE_NONNULL(1);
771 |
772 | void (*non_local_exit_clear) (emacs_env *env)
773 | EMACS_ATTRIBUTE_NONNULL(1);
774 |
775 | enum emacs_funcall_exit (*non_local_exit_get)
776 | (emacs_env *env, emacs_value *symbol, emacs_value *data)
777 | EMACS_ATTRIBUTE_NONNULL(1, 2, 3);
778 |
779 | void (*non_local_exit_signal) (emacs_env *env,
780 | emacs_value symbol, emacs_value data)
781 | EMACS_ATTRIBUTE_NONNULL(1);
782 |
783 | void (*non_local_exit_throw) (emacs_env *env,
784 | emacs_value tag, emacs_value value)
785 | EMACS_ATTRIBUTE_NONNULL(1);
786 |
787 | /* Function registration. */
788 |
789 | emacs_value (*make_function) (emacs_env *env,
790 | ptrdiff_t min_arity,
791 | ptrdiff_t max_arity,
792 | emacs_value (*func) (emacs_env *env,
793 | ptrdiff_t nargs,
794 | emacs_value* args,
795 | void *data)
796 | EMACS_NOEXCEPT
797 | EMACS_ATTRIBUTE_NONNULL(1),
798 | const char *docstring,
799 | void *data)
800 | EMACS_ATTRIBUTE_NONNULL(1, 4);
801 |
802 | emacs_value (*funcall) (emacs_env *env,
803 | emacs_value func,
804 | ptrdiff_t nargs,
805 | emacs_value* args)
806 | EMACS_ATTRIBUTE_NONNULL(1);
807 |
808 | emacs_value (*intern) (emacs_env *env, const char *name)
809 | EMACS_ATTRIBUTE_NONNULL(1, 2);
810 |
811 | /* Type conversion. */
812 |
813 | emacs_value (*type_of) (emacs_env *env, emacs_value arg)
814 | EMACS_ATTRIBUTE_NONNULL(1);
815 |
816 | bool (*is_not_nil) (emacs_env *env, emacs_value arg)
817 | EMACS_ATTRIBUTE_NONNULL(1);
818 |
819 | bool (*eq) (emacs_env *env, emacs_value a, emacs_value b)
820 | EMACS_ATTRIBUTE_NONNULL(1);
821 |
822 | intmax_t (*extract_integer) (emacs_env *env, emacs_value arg)
823 | EMACS_ATTRIBUTE_NONNULL(1);
824 |
825 | emacs_value (*make_integer) (emacs_env *env, intmax_t n)
826 | EMACS_ATTRIBUTE_NONNULL(1);
827 |
828 | double (*extract_float) (emacs_env *env, emacs_value arg)
829 | EMACS_ATTRIBUTE_NONNULL(1);
830 |
831 | emacs_value (*make_float) (emacs_env *env, double d)
832 | EMACS_ATTRIBUTE_NONNULL(1);
833 |
834 | /* Copy the content of the Lisp string VALUE to BUFFER as an utf8
835 | null-terminated string.
836 |
837 | SIZE must point to the total size of the buffer. If BUFFER is
838 | NULL or if SIZE is not big enough, write the required buffer size
839 | to SIZE and return true.
840 |
841 | Note that SIZE must include the last null byte (e.g. "abc" needs
842 | a buffer of size 4).
843 |
844 | Return true if the string was successfully copied. */
845 |
846 | bool (*copy_string_contents) (emacs_env *env,
847 | emacs_value value,
848 | char *buf,
849 | ptrdiff_t *len)
850 | EMACS_ATTRIBUTE_NONNULL(1, 4);
851 |
852 | /* Create a Lisp string from a utf8 encoded string. */
853 | emacs_value (*make_string) (emacs_env *env,
854 | const char *str, ptrdiff_t len)
855 | EMACS_ATTRIBUTE_NONNULL(1, 2);
856 |
857 | /* Embedded pointer type. */
858 | emacs_value (*make_user_ptr) (emacs_env *env,
859 | void (*fin) (void *) EMACS_NOEXCEPT,
860 | void *ptr)
861 | EMACS_ATTRIBUTE_NONNULL(1);
862 |
863 | void *(*get_user_ptr) (emacs_env *env, emacs_value arg)
864 | EMACS_ATTRIBUTE_NONNULL(1);
865 | void (*set_user_ptr) (emacs_env *env, emacs_value arg, void *ptr)
866 | EMACS_ATTRIBUTE_NONNULL(1);
867 |
868 | void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr))
869 | (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1);
870 | void (*set_user_finalizer) (emacs_env *env, emacs_value arg,
871 | void (*fin) (void *) EMACS_NOEXCEPT)
872 | EMACS_ATTRIBUTE_NONNULL(1);
873 |
874 | /* Vector functions. */
875 | emacs_value (*vec_get) (emacs_env *env, emacs_value vector, ptrdiff_t index)
876 | EMACS_ATTRIBUTE_NONNULL(1);
877 |
878 | void (*vec_set) (emacs_env *env, emacs_value vector, ptrdiff_t index,
879 | emacs_value value)
880 | EMACS_ATTRIBUTE_NONNULL(1);
881 |
882 | ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vector)
883 | EMACS_ATTRIBUTE_NONNULL(1);
884 |
885 | /* Returns whether a quit is pending. */
886 | bool (*should_quit) (emacs_env *env)
887 | EMACS_ATTRIBUTE_NONNULL(1);
888 |
889 | /* Processes pending input events and returns whether the module
890 | function should quit. */
891 | enum emacs_process_input_result (*process_input) (emacs_env *env)
892 | EMACS_ATTRIBUTE_NONNULL (1);
893 |
894 | struct timespec (*extract_time) (emacs_env *env, emacs_value arg)
895 | EMACS_ATTRIBUTE_NONNULL (1);
896 |
897 | emacs_value (*make_time) (emacs_env *env, struct timespec time)
898 | EMACS_ATTRIBUTE_NONNULL (1);
899 |
900 | bool (*extract_big_integer) (emacs_env *env, emacs_value arg, int *sign,
901 | ptrdiff_t *count, emacs_limb_t *magnitude)
902 | EMACS_ATTRIBUTE_NONNULL (1);
903 |
904 | emacs_value (*make_big_integer) (emacs_env *env, int sign, ptrdiff_t count,
905 | const emacs_limb_t *magnitude)
906 | EMACS_ATTRIBUTE_NONNULL (1);
907 |
908 | void (*(*EMACS_ATTRIBUTE_NONNULL (1)
909 | get_function_finalizer) (emacs_env *env,
910 | emacs_value arg)) (void *) EMACS_NOEXCEPT;
911 |
912 | void (*set_function_finalizer) (emacs_env *env, emacs_value arg,
913 | void (*fin) (void *) EMACS_NOEXCEPT)
914 | EMACS_ATTRIBUTE_NONNULL (1);
915 |
916 | int (*open_channel) (emacs_env *env, emacs_value pipe_process)
917 | EMACS_ATTRIBUTE_NONNULL (1);
918 |
919 | void (*make_interactive) (emacs_env *env, emacs_value function,
920 | emacs_value spec)
921 | EMACS_ATTRIBUTE_NONNULL (1);
922 |
923 | /* Create a unibyte Lisp string from a string. */
924 | emacs_value (*make_unibyte_string) (emacs_env *env,
925 | const char *str, ptrdiff_t len)
926 | EMACS_ATTRIBUTE_NONNULL(1, 2);
927 |
928 | /* Add module environment functions newly added in Emacs 29 here.
929 | Before Emacs 29 is released, remove this comment and start
930 | module-env-30.h on the master branch. */
931 | };
932 |
933 | /* Every module should define a function as follows. */
934 | extern int emacs_module_init (struct emacs_runtime *runtime)
935 | EMACS_NOEXCEPT
936 | EMACS_ATTRIBUTE_NONNULL (1);
937 |
938 | #ifdef __cplusplus
939 | }
940 | #endif
941 |
942 | #endif /* EMACS_MODULE_H */
943 |
--------------------------------------------------------------------------------
/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.4
9 | ;; Package-Requires: ((emacs "29.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-properties
158 | '((t read-only))
159 | "Alist of properties per major mode.
160 | These properties mark regions which should be excluded in spell
161 | checking."
162 | :type '(alist :key-type symbol :value-type (choice symbol (repeat symbol))))
163 |
164 | (defcustom jinx-exclude-regexps
165 | '((emacs-lisp-mode "Package-Requires:.*$")
166 | (t "[A-Z]+\\>" ;; Uppercase words
167 | "-+\\>" ;; Hyphens used as lines or bullet points
168 | "\\w*?[0-9]\\w*\\>" ;; Words with numbers, hex codes
169 | "[a-z]+://\\S-+" ;; URI
170 | "[-+_.~a-zA-Z][-+_.~:a-zA-Z0-9]*@[-.a-zA-Z0-9]+>?" ;; Email
171 | "\\(?:Local Variables\\|End\\):\\s-*$" ;; Local variable indicator
172 | "jinx-\\(?:languages\\|local-words\\):\\s-+.*$")) ;; Local variables
173 | "List of excluded regexps per major mode.
174 | The regexp must match at the beginning of the spell-checked word.
175 | Therefore `jinx-exclude-regexps' cannot be used to exclude larger parts
176 | of a buffer. Write a custom predicate instead, see `jinx--predicates'."
177 | :type '(alist :key-type symbol :value-type (choice symbol (repeat regexp))))
178 |
179 | (defcustom jinx-suggestion-distance 3
180 | "Maximal edit distance for session words to be included in suggestions."
181 | :type 'natnum)
182 |
183 | (defcustom jinx-menu-suggestions 10
184 | "Maximal number of suggestions shown in the context menu."
185 | :type 'natnum)
186 |
187 | (defvar-local jinx-local-words ""
188 | "File-local words, as a string separated by whitespace.")
189 |
190 | (defvar-local jinx-dir-local-words ""
191 | "Directory-local words, as a string separated by whitespace.")
192 |
193 | ;;;###autoload
194 | (progn
195 | (put 'jinx-local-words 'safe-local-variable #'stringp)
196 | (put 'jinx-dir-local-words 'safe-local-variable #'stringp)
197 | (put 'jinx-mode 'safe-local-variable #'not))
198 |
199 | ;;;; Faces
200 |
201 | (defgroup jinx-faces nil
202 | "Faces used by Jinx."
203 | :group 'jinx
204 | :group 'faces)
205 |
206 | (defface jinx-misspelled
207 | '((((class color) (min-colors 88) (background dark)
208 | (supports :underline (:style wave)))
209 | :underline (:style wave :color "#d2b580"))
210 | (((class color) (min-colors 88) (background light)
211 | (supports :underline (:style wave)))
212 | :underline (:style wave :color "#5f4400"))
213 | (t :underline t :inherit error))
214 | "Face used for misspelled words.")
215 |
216 | (defface jinx-highlight
217 | '((t :inherit isearch))
218 | "Face used to highlight current misspelled word during correction.")
219 |
220 | (defface jinx-save
221 | '((t :inherit warning))
222 | "Face used for the save actions during correction.")
223 |
224 | (defface jinx-key
225 | '((t :inherit completions-annotations))
226 | "Face used for the select key during correction.")
227 |
228 | (defface jinx-annotation
229 | '((t :inherit completions-annotations))
230 | "Face used for the annotation during correction.")
231 |
232 | ;;;; Keymaps
233 |
234 | (defvar-keymap jinx-overlay-map
235 | :doc "Keymap attached to misspelled words."
236 | "" `(menu-item "" (keymap) :filter ,#'jinx--correct-menu)
237 | "M-n" #'jinx-next
238 | "M-p" #'jinx-previous
239 | "M-$" #'jinx-correct)
240 |
241 | (fset 'jinx-overlay-map jinx-overlay-map)
242 |
243 | (defvar-keymap jinx-repeat-map
244 | :doc "Repeat keymap for navigation commands."
245 | :repeat (:exit (jinx-correct))
246 | "M-n" #'jinx-next
247 | "M-p" #'jinx-previous
248 | "n" #'jinx-next
249 | "p" #'jinx-previous
250 | "$" #'jinx-correct)
251 |
252 | (defvar-keymap jinx-correct-map
253 | :doc "Keymap active in the correction minibuffer."
254 | "SPC" #'self-insert-command
255 | "M-n" #'jinx-next
256 | "M-p" #'jinx-previous
257 | "M-$" #'jinx-previous
258 | "0 " #'jinx-correct-select)
259 | (dotimes (i 9)
260 | (define-key jinx-correct-map (vector (+ ?1 i)) #'jinx-correct-select))
261 |
262 | (defvar-keymap jinx-mode-map
263 | :doc "Keymap used when Jinx is active.")
264 |
265 | (easy-menu-define jinx-mode-menu jinx-mode-map
266 | "Menu used when Jinx is active."
267 | '("Jinx"
268 | ["Correct nearest" jinx-correct]
269 | ["Correct all" jinx-correct-all
270 | :keys "\\[universal-argument] \\[jinx-correct]"]
271 | ["Correct word" jinx-correct-word
272 | :keys "\\[universal-argument] \\[universal-argument] \\[jinx-correct]"]
273 | ["Change languages" jinx-languages]
274 | "----"
275 | ["Manual" (info "(jinx)")]
276 | ["Customize" (customize-group 'jinx)]
277 | ["Turn off" (jinx-mode -1)]))
278 |
279 | ;;;; Internal variables
280 |
281 | (defvar jinx--compile-flags
282 | '("-I." "-O2" "-Wall" "-Wextra" "-fPIC" "-shared")
283 | "List of compile flags passed to the C compiler.")
284 |
285 | (defvar jinx--reschedule-hooks
286 | '(window-selection-change-functions window-scroll-functions
287 | window-state-change-hook post-command-hook)
288 | "Hooks which reschedule the spell checking timer, see `jinx--reschedule'.")
289 |
290 | (defvar jinx--predicates
291 | (list #'jinx--face-excluded-p
292 | #'jinx--regexp-excluded-p
293 | #'jinx--property-excluded-p
294 | #'jinx--word-valid-p)
295 | "Predicate functions called at point with argument START.
296 | Predicate should return t if the word before point is valid.
297 | Predicate may return a position to skip forward.")
298 |
299 | (defvar jinx--timer (timer-create)
300 | "Global timer to check pending regions.")
301 |
302 | (defvar jinx--syntax-table
303 | (let ((st (make-syntax-table)))
304 | (modify-syntax-entry ?' "w" st)
305 | (modify-syntax-entry ?’ "w" st)
306 | (modify-syntax-entry ?$ "_" st)
307 | (modify-syntax-entry ?% "_" st)
308 | (modify-syntax-entry '(#xe000 . #xf8ff) "_" st) ;; Priv. use area
309 | (modify-syntax-entry '(#xf0000 . #xffffd) "_" st) ;; Supp. priv. use area A
310 | (modify-syntax-entry '(#x100000 . #x10fffd) "_" st);; Supp. priv. use area B
311 | (modify-syntax-entry '(#x80 . #x9f) "_" st) ;; Control characters
312 | (modify-syntax-entry '(#x2150 . #x2bff) "_" st) ;; Number Forms - Misc. Arrows
313 | (modify-syntax-entry '(#xfe00 . #xfe0f) "_" st) ;; Variation Selectors
314 | (modify-syntax-entry '(#x1cf00 . #x1d7ff) "_" st) ;; Znamenny Musical - Math. Alpha.
315 | (modify-syntax-entry '(#x1ee00 . #x1fbff) "_" st) ;; Arabic Math. - Legacy Computing
316 | st)
317 | "Syntax table used during checking.")
318 |
319 | (defvar jinx--select-keys
320 | "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
321 | "Quick select keys used by `jinx-correct'.")
322 |
323 | (defvar jinx--save-keys
324 | `((?@ . ,#'jinx--save-personal)
325 | (?* . ,#'jinx--save-file)
326 | (?/ . ,#'jinx--save-dir)
327 | (?+ . ,#'jinx--save-session))
328 | "Keys for save actions used by `jinx-correct'.")
329 |
330 | (defvar-local jinx--exclude-faces nil
331 | "List of excluded faces.")
332 |
333 | (defvar-local jinx--exclude-properties nil
334 | "List of excluded properties.")
335 |
336 | (defvar-local jinx--include-faces nil
337 | "List of included faces.")
338 |
339 | (defvar-local jinx--exclude-regexp nil
340 | "Ignore regexp.")
341 |
342 | (defvar-local jinx--camel nil
343 | "Accept camel case.")
344 |
345 | (defvar-local jinx--dicts nil
346 | "List of dictionaries.")
347 |
348 | (defvar jinx--dicts-hash (make-hash-table :test #'equal :weakness 'value)
349 | "Weak hash table of all loaded dictionaries.")
350 |
351 | (defvar-local jinx--session-words nil
352 | "List of words accepted in this session.")
353 |
354 | ;;;; Declarations for the bytecode compiler
355 |
356 | (defvar repeat-mode)
357 | (defvar jinx-mode)
358 | (declare-function jinx--mod-check "ext:jinx-mod.c")
359 | (declare-function jinx--mod-add "ext:jinx-mod.c")
360 | (declare-function jinx--mod-suggest "ext:jinx-mod.c")
361 | (declare-function jinx--mod-dict "ext:jinx-mod.c")
362 | (declare-function jinx--mod-describe "ext:jinx-mod.c")
363 | (declare-function jinx--mod-langs "ext:jinx-mod.c")
364 |
365 | ;;;; Overlay properties
366 |
367 | (put 'jinx-overlay 'evaporate t)
368 | (put 'jinx-overlay 'face 'jinx-misspelled)
369 | (put 'jinx-overlay 'mouse-face '(jinx-misspelled jinx-highlight))
370 | (put 'jinx-overlay 'modification-hooks (list #'jinx--overlay-modified))
371 | (put 'jinx-overlay 'insert-in-front-hooks (list #'jinx--overlay-modified))
372 | (put 'jinx-overlay 'insert-behind-hooks (list #'jinx--overlay-modified))
373 | (put 'jinx-overlay 'keymap 'jinx-overlay-map)
374 | (put 'jinx-overlay 'help-echo "Jinx: \\`mouse-3' menu, \\[jinx-correct] correct, \\`M-p' previous, \\`M-n' next")
375 |
376 | ;;;; Predicates
377 |
378 | (defun jinx--regexp-excluded-p (pos)
379 | "Return non-nil if word at POS matches a regexp from `jinx-exclude-regexps'."
380 | (save-excursion
381 | (goto-char pos)
382 | (when (and jinx--exclude-regexp (looking-at-p jinx--exclude-regexp))
383 | (save-match-data
384 | (looking-at jinx--exclude-regexp)
385 | (match-end 0)))))
386 |
387 | (defun jinx--face-excluded-p (pos)
388 | "Return non-nil if face at POS is excluded via `jinx-exclude-faces'."
389 | (let ((face (get-text-property pos 'face)))
390 | (or
391 | (and jinx--include-faces
392 | (if (listp face)
393 | (cl-loop for f in face never (memq f jinx--include-faces))
394 | (not (memq face jinx--include-faces))))
395 | (and jinx--exclude-faces
396 | (if (listp face)
397 | (cl-loop for f in face thereis (memq f jinx--exclude-faces))
398 | (memq face jinx--exclude-faces))))))
399 |
400 | (defun jinx--property-excluded-p (pos)
401 | "Return non-nil if property at POS is excluded via `jinx-exclude-properties'."
402 | (cl-loop for prop in jinx--exclude-properties
403 | thereis (get-char-property pos prop)))
404 |
405 | (defun jinx--read-only-p (pos)
406 | "Return non-nil if POS is read-only."
407 | (get-text-property pos 'read-only))
408 |
409 | (defun jinx--word-valid-p (word)
410 | "Return non-nil if WORD is valid.
411 | WORD can also be a position."
412 | (unless (stringp word)
413 | (setq word (buffer-substring-no-properties word (point))))
414 | (or (member word jinx--session-words)
415 | ;; Allow capitalized words
416 | (let (case-fold-search)
417 | (and (string-match-p "\\`[[:upper:]][[:lower:]]+\\'" word)
418 | (cl-loop
419 | for w in jinx--session-words
420 | thereis (and (string-equal-ignore-case word w)
421 | (string-match-p "\\`[[:lower:]]+\\'" w)))))
422 | (cl-loop for dict in jinx--dicts
423 | thereis (jinx--mod-check dict word))))
424 |
425 | ;;;; Internal functions
426 |
427 | (defun jinx--in-base-buffer (&rest app)
428 | "Apply APP in `buffer-base-buffer', as required by `jit-lock' functions."
429 | (with-current-buffer (or (buffer-base-buffer) (current-buffer))
430 | (apply app)))
431 |
432 | (defun jinx--overlay-modified (overlay &rest _)
433 | "Delete modified OVERLAY.
434 | This function is a modification hook for the overlay."
435 | (delete-overlay overlay))
436 |
437 | (defun jinx--find-visible (start end visible)
438 | "Find (in)visible region between START and END.
439 | VISIBLE must be nil or t."
440 | (while (and (< start end) (eq (not visible) (not (invisible-p start))))
441 | (let ((next (next-single-char-property-change start 'invisible nil end)))
442 | ;; END can be outside the buffer if the buffer size has changed in
443 | ;; between. Then `next-single-property-change' will return (point-max)
444 | ;; instead of END. See gh:minad/jinx#156.
445 | (setq start (if (> next start) next end))))
446 | start)
447 |
448 | (defun jinx--check-pending (start end)
449 | "Check pending visible region between START and END."
450 | (let ((retry (and (eq (window-buffer) (current-buffer))
451 | (symbolp real-last-command)
452 | (string-match-p "self-insert-command\\'"
453 | (symbol-name real-last-command))
454 | (window-point))))
455 | (while (< start end)
456 | (let* ((vfrom (jinx--find-visible start end t))
457 | (vto (jinx--find-visible vfrom end nil)))
458 | (while (< vfrom vto)
459 | (let* ((pfrom (or (text-property-any vfrom vto 'jinx--pending t) vto))
460 | (pto (or (text-property-not-all pfrom vto 'jinx--pending t) vto)))
461 | (when (< pfrom pto)
462 | (jinx--check-region pfrom pto retry))
463 | (setq vfrom pto)))
464 | (setq start vto)))))
465 |
466 | (defun jinx--check-region (start end &optional retry)
467 | "Check region between START and END.
468 | Optionally RETRY word at given position. Return updated END
469 | position."
470 | (let ((st (syntax-table)) case-fold-search
471 | retry-start retry-end)
472 | (unwind-protect
473 | (with-silent-modifications
474 | (save-excursion
475 | (save-match-data
476 | ;; Use dictionary-dependent syntax table
477 | (set-syntax-table jinx--syntax-table)
478 | ;; Ensure that region starts and ends at word boundaries
479 | (goto-char start)
480 | (unless (looking-at-p "\\<")
481 | (re-search-backward "\\<\\|^")
482 | (setq start (match-beginning 0)))
483 | (goto-char end)
484 | (unless (looking-at-p "\\>")
485 | (re-search-forward "\\>\\|$")
486 | (setq end (match-beginning 0)))
487 | (jinx--delete-overlays start end)
488 | (goto-char start)
489 | (while (re-search-forward "\\<\\w+\\>" end t)
490 | (let ((word-start (match-beginning 0))
491 | (word-end (match-end 0)))
492 | ;; No quote or apostrophe at start or end
493 | (while (and (< word-start word-end)
494 | (let ((c (char-after word-start)))
495 | (or (= c ?') (= c ?’))))
496 | (cl-incf word-start))
497 | (while (and (< word-start word-end)
498 | (let ((c (char-before word-end)))
499 | (or (= c ?') (= c ?’))))
500 | (cl-decf word-end))
501 | (while (< word-start word-end)
502 | (let ((subword-end word-end))
503 | (when jinx--camel
504 | (goto-char word-start)
505 | (when (looking-at "\\([[:upper:]]?[[:lower:]]+\\)\\(?:[[:upper:]][[:lower:]]+\\)+\\>")
506 | (setq subword-end (match-end 1))))
507 | (goto-char subword-end)
508 | (pcase (run-hook-with-args-until-success 'jinx--predicates word-start)
509 | ((and (pred integerp) skip)
510 | (goto-char (max subword-end (min end skip))))
511 | ('nil
512 | (if (and retry (<= word-start retry subword-end))
513 | (setq retry-start word-start retry-end subword-end retry nil)
514 | (overlay-put (make-overlay word-start subword-end) 'category 'jinx-overlay))))
515 | (setq word-start subword-end)))))
516 | (remove-list-of-text-properties start end '(jinx--pending))
517 | (when retry-start
518 | (put-text-property retry-start retry-end 'jinx--pending t)))))
519 | (set-syntax-table st))))
520 |
521 | (defun jinx--get-overlays (start end &optional visible)
522 | "Return misspelled word overlays between START and END.
523 | If VISIBLE is non-nil, only include visible overlays."
524 | (let ((pt (point)) before overlays)
525 | (dolist (ov (overlays-in start end))
526 | (when (and (eq (overlay-get ov 'category) 'jinx-overlay)
527 | (not (and visible (invisible-p (overlay-start ov)))))
528 | (push ov overlays)))
529 | (setq overlays
530 | (sort overlays
531 | (lambda (a b) (< (overlay-start a) (overlay-start b)))))
532 | (while (and (cdr overlays) (<= (overlay-start (cadr overlays)) pt))
533 | (push (pop overlays) before))
534 | (nconc overlays (nreverse before))))
535 |
536 | (cl-defun jinx--force-overlays (start end &key visible check)
537 | "Return misspelled word overlays between START and END, enforce checking.
538 | If VISIBLE is non-nil, only include visible overlays.
539 | If CHECK is non-nil, always check first."
540 | (or (and (not check) (jinx--get-overlays start end visible))
541 | (progn
542 | (with-delayed-message (1 "Fontifying...")
543 | (jinx--in-base-buffer #'jit-lock-fontify-now start end))
544 | (with-delayed-message (1 "Checking...")
545 | (jinx--check-region start end))
546 | (jinx--get-overlays start end visible))
547 | (user-error "No misspelled word in %s"
548 | (if visible "visible text" (format "buffer `%s'" (buffer-name))))))
549 |
550 | (defun jinx--delete-overlays (start end)
551 | "Delete overlays between START and END."
552 | (dolist (ov (overlays-in start end))
553 | (when (eq (overlay-get ov 'category) 'jinx-overlay)
554 | (delete-overlay ov))))
555 |
556 | (defun jinx--cleanup ()
557 | "Cleanup all overlays and trigger fontification."
558 | (with-silent-modifications
559 | (without-restriction
560 | (jinx--delete-overlays (point-min) (point-max))
561 | (remove-list-of-text-properties (point-min) (point-max) '(jinx--pending))
562 | (jinx--in-base-buffer #'jit-lock-refontify))))
563 |
564 | (defun jinx--mark-pending (start end)
565 | "Mark region between START and END as pending."
566 | (put-text-property start end 'jinx--pending t)
567 | (unless inhibit-quit ;; non-nil for stealth locking
568 | (jinx--schedule))
569 | nil)
570 |
571 | (defun jinx--mode-list (list)
572 | "Lookup by major mode in LIST."
573 | (cl-loop for (mode . vals) in list
574 | if (or (eq mode t) (derived-mode-p mode))
575 | append (if (symbolp vals) (alist-get vals list) vals)))
576 |
577 | (defun jinx--get-org-language ()
578 | "Get language from Org #+language keyword."
579 | (when (and (not (local-variable-p 'jinx-languages))
580 | (derived-mode-p 'org-mode))
581 | (save-excursion
582 | (save-match-data
583 | (goto-char (point-min))
584 | (when (re-search-forward "^ *#\\+language: +\\([a-z_]+\\) *$" nil t)
585 | (setq-local jinx-languages (match-string-no-properties 1)))))))
586 |
587 | (defun jinx--timer-handler ()
588 | "Global timer handler, checking the pending regions in all windows."
589 | (timer-set-function jinx--timer nil)
590 | (dolist (frame (frame-list))
591 | (dolist (win (window-list frame 'no-miniwindow))
592 | (when-let ((buffer (window-buffer win))
593 | ((buffer-local-value 'jinx-mode buffer)))
594 | (with-current-buffer buffer
595 | (jinx--check-pending (window-start win) (window-end win)))))))
596 |
597 | (defun jinx--reschedule (&rest _)
598 | "Restart the global idle timer."
599 | (when (timer--function jinx--timer)
600 | (cancel-timer jinx--timer)
601 | (timer-set-function jinx--timer nil))
602 | (jinx--schedule))
603 |
604 | (defun jinx--schedule ()
605 | "Start the global idle timer."
606 | (when (and (not (timer--function jinx--timer))
607 | (not completion-in-region-mode) ;; Corfu completion
608 | (get-buffer-window)) ;; Buffer visible
609 | (timer-set-function jinx--timer #'jinx--timer-handler)
610 | (timer-set-idle-time jinx--timer jinx-delay)
611 | (timer-activate-when-idle jinx--timer t)))
612 |
613 | (defun jinx--load-module ()
614 | "Compile and load dynamic module."
615 | (unless (fboundp #'jinx--mod-dict)
616 | (unless module-file-suffix
617 | (error "Jinx: Dynamic modules are not supported"))
618 | (let* ((mod-name (file-name-with-extension "jinx-mod" module-file-suffix))
619 | (mod-file (locate-library mod-name t)))
620 | (unless mod-file
621 | (let* ((cc (or (getenv "CC")
622 | (seq-find #'executable-find '("gcc" "clang" "cc"))
623 | (error "Jinx: No C compiler found")))
624 | (c-name (file-name-with-extension mod-name ".c"))
625 | (default-directory (file-name-directory
626 | (or (locate-library c-name t)
627 | (error "Jinx: %s not found" c-name))))
628 | (command
629 | `(,cc ,@jinx--compile-flags "-o" ,mod-name ,c-name
630 | ,@(split-string-and-unquote
631 | (condition-case nil
632 | (car (process-lines "pkg-config" "--cflags" "--libs" "enchant-2"))
633 | (error "-I/usr/include/enchant-2 -I/usr/local/include/enchant-2 -L/usr/local/lib -lenchant-2"))))))
634 | (with-current-buffer (get-buffer-create "*jinx module compilation*")
635 | (let ((inhibit-read-only t))
636 | (erase-buffer)
637 | (compilation-mode)
638 | (insert (string-join command " ") "\n")
639 | (if (equal 0 (apply #'call-process (car command) nil (current-buffer) t (cdr command)))
640 | (insert (message "Jinx: %s compiled successfully" mod-name))
641 | (let ((msg (format "Jinx: Compilation of %s failed" mod-name)))
642 | (insert msg)
643 | (pop-to-buffer (current-buffer))
644 | (error msg)))))
645 | (setq mod-file (expand-file-name mod-name))))
646 | ;; Initialize Mac spell checker to avoid dead lock (gh:minad/jinx#91).
647 | (when (and (eq window-system 'mac) (fboundp 'mac-do-applescript))
648 | (mac-do-applescript
649 | "use framework \"AppKit\"
650 | set spellChecker to current application's NSSpellChecker's sharedSpellChecker()"))
651 | (module-load mod-file))))
652 |
653 | (defmacro jinx--correct-guard (&rest body)
654 | "Guard BODY during correction loop."
655 | `(cl-letf (((symbol-function #'jinx--timer-handler) #'ignore) ;; Inhibit
656 | (repeat-mode nil)) ;; No repeating of jinx-next and jinx-previous
657 | (unless jinx-mode (jinx-mode))
658 | ,@body))
659 |
660 | (defun jinx--invisible-open-temporarily ()
661 | "Temporarily open overlays which hide the current line.
662 | See `isearch-open-necessary-overlays' and `isearch-open-overlay-temporary'."
663 | (let (restore)
664 | (dolist (ov (overlays-in (pos-bol) (pos-eol)) restore)
665 | (let ((inv (overlay-get ov 'invisible)))
666 | (when (and (invisible-p inv) (overlay-get ov 'isearch-open-invisible))
667 | (push (if-let ((fun (overlay-get ov 'isearch-open-invisible-temporary)))
668 | (progn
669 | (funcall fun ov nil)
670 | (lambda () (funcall fun ov t)))
671 | (overlay-put ov 'invisible nil)
672 | (lambda () (overlay-put ov 'invisible inv)))
673 | restore))))))
674 |
675 | (defun jinx--invisible-open-permanently ()
676 | "Open overlays which hide the current line.
677 | See `isearch-open-necessary-overlays' and `isearch-open-overlay-temporary'."
678 | (dolist (ov (overlays-in (pos-bol) (pos-eol)))
679 | (when-let (fun (overlay-get ov 'isearch-open-invisible))
680 | (when (invisible-p (overlay-get ov 'invisible))
681 | (funcall fun ov)))))
682 |
683 | (defun jinx--correct-highlight (overlay fun)
684 | "Highlight and show OVERLAY during FUN."
685 | (declare (indent 1))
686 | (let (restore)
687 | (goto-char (overlay-end overlay))
688 | (unwind-protect
689 | (let ((hl (make-overlay (overlay-start overlay) (overlay-end overlay))))
690 | (overlay-put hl 'face 'jinx-highlight)
691 | (overlay-put hl 'window (selected-window))
692 | (setq restore (cons (lambda () (delete-overlay hl))
693 | (jinx--invisible-open-temporarily)))
694 | (funcall fun))
695 | (mapc #'funcall restore))))
696 |
697 | (defun jinx--recheck-overlays ()
698 | "Recheck all overlays in buffer after a dictionary update."
699 | (save-excursion
700 | (without-restriction
701 | (dolist (ov (overlays-in (point-min) (point-max)))
702 | (when (eq (overlay-get ov 'category) 'jinx-overlay)
703 | (goto-char (overlay-end ov))
704 | (when (jinx--word-valid-p (overlay-start ov))
705 | (delete-overlay ov)))))))
706 |
707 | (defun jinx--correct-setup ()
708 | "Setup minibuffer for correction."
709 | (use-local-map
710 | (make-composed-keymap (list jinx-correct-map) (current-local-map))))
711 |
712 | (defun jinx--add-suggestion (list ht word group)
713 | "Add suggestion WORD to LIST and HT.
714 | The word will be associated with GROUP and get a prefix key."
715 | (unless (gethash word ht)
716 | (add-text-properties
717 | 0 (length word)
718 | (list 'jinx--group group
719 | 'jinx--prefix
720 | (let ((idx (1+ (hash-table-count ht))))
721 | (cond
722 | ((< idx 10)
723 | (format #("%d " 0 3 (face jinx-key))
724 | idx))
725 | ((< (- idx 10) (length jinx--select-keys))
726 | (format #("0%c " 0 4 (face jinx-key))
727 | (aref jinx--select-keys (- idx 10)))))))
728 | word)
729 | (push word list)
730 | (puthash word t ht))
731 | list)
732 |
733 | (defun jinx--session-suggestions (word)
734 | "Retrieve suggestions for WORD from session."
735 | (mapcar #'cdr
736 | (sort (cl-loop for w in jinx--session-words
737 | for d = (string-distance word w)
738 | if (<= d jinx-suggestion-distance)
739 | collect (cons d w))
740 | #'car-less-than-car)))
741 |
742 | (defun jinx--correct-suggestions (word)
743 | "Retrieve suggestions for WORD from all dictionaries."
744 | (let ((ht (make-hash-table :test #'equal))
745 | (list nil))
746 | (dolist (dict jinx--dicts)
747 | (let* ((desc (jinx--mod-describe dict))
748 | (group (format "Suggestions from dictionary ‘%s’ - %s"
749 | (car desc) (cdr desc))))
750 | (dolist (w (jinx--mod-suggest dict word))
751 | (setq list (jinx--add-suggestion list ht w group)))))
752 | (dolist (w (jinx--session-suggestions word))
753 | (setq list (jinx--add-suggestion list ht w "Suggestions from session")))
754 | (cl-loop
755 | for (key . fun) in jinx--save-keys
756 | for actions = (funcall fun nil key word) do
757 | (when (and actions (not (consp (car actions))))
758 | (setq actions (list actions)))
759 | (cl-loop
760 | for (k w a) in actions
761 | for k2 = (propertize (if (stringp k) k (char-to-string k))
762 | 'face 'jinx-save 'rear-nonsticky t)
763 | for a2 = (format #(" [%s]" 0 5 (face jinx-annotation)) a)
764 | do (cl-loop
765 | for w2 in (delete-consecutive-dups (list w (downcase w))) do
766 | (push (propertize (concat k2 w2)
767 | 'jinx--group "Accept and save"
768 | 'jinx--suffix a2)
769 | list))))
770 | (nreverse list)))
771 |
772 | (defun jinx--correct-affixation (cands)
773 | "Affixate CANDS during completion."
774 | (cl-loop for cand in cands collect
775 | (list cand
776 | (or (get-text-property 0 'jinx--prefix cand) "")
777 | (or (get-text-property 0 'jinx--suffix cand) ""))))
778 |
779 | (defun jinx--correct-annotation (cand)
780 | "Annotate CAND during completion."
781 | (if-let ((prefix (get-text-property 0 'jinx--prefix cand)))
782 | (format #(" (%s)" 0 5 (face jinx-key)) (string-trim prefix))
783 | (get-text-property 0 'jinx--suffix cand)))
784 |
785 | (defun jinx--group (word transform)
786 | "Group WORD during completion, TRANSFORM candidate if non-nil."
787 | (if transform
788 | word
789 | (get-text-property 0 'jinx--group word)))
790 |
791 | ;; TODO: Use `completion-table-with-metadata'
792 | (defun jinx--table-with-metadata (table metadata)
793 | "Return new completion TABLE with METADATA."
794 | (lambda (string pred action)
795 | (if (eq action 'metadata)
796 | `(metadata . ,metadata)
797 | (complete-with-action action table string pred))))
798 |
799 | (cl-defun jinx--correct-overlay (overlay &key info initial)
800 | "Correct word at OVERLAY.
801 | Optionally show prompt INFO and insert INITIAL input."
802 | (catch 'jinx--goto
803 | (let* ((word (buffer-substring-no-properties
804 | (overlay-start overlay) (overlay-end overlay)))
805 | (choice
806 | (jinx--correct-highlight overlay
807 | (lambda ()
808 | (when (or (< (point) (window-start)) (> (point) (window-end nil t)))
809 | (recenter))
810 | (minibuffer-with-setup-hook
811 | #'jinx--correct-setup
812 | (or (completing-read
813 | (format "Correct ‘%s’%s: " word (or info ""))
814 | (jinx--table-with-metadata
815 | (jinx--correct-suggestions word)
816 | `((category . jinx)
817 | (eager-display . t)
818 | (display-sort-function . ,#'identity)
819 | (cycle-sort-function . ,#'identity)
820 | (group-function . ,#'jinx--group)
821 | (affixation-function . ,#'jinx--correct-affixation)
822 | (annotation-function . ,#'jinx--correct-annotation)))
823 | nil nil initial t word)
824 | word)))))
825 | (len (length choice)))
826 | (pcase (and (> len 0) (assq (aref choice 0) jinx--save-keys))
827 | (`(,key . ,fun)
828 | (funcall fun 'save key
829 | (if (> len 1) (substring-no-properties choice 1) word))
830 | (jinx--recheck-overlays))
831 | ((guard (not (equal choice word)))
832 | (jinx--correct-replace overlay choice)))
833 | nil)))
834 |
835 | (defun jinx--correct-replace (overlay word)
836 | "Replace OVERLAY with WORD."
837 | (when-let ((start (overlay-start overlay))
838 | (end (overlay-end overlay)))
839 | (undo-boundary)
840 | (delete-overlay overlay)
841 | (goto-char end)
842 | (insert-before-markers word)
843 | (delete-region start end)))
844 |
845 | (defun jinx--correct-menu (&rest _)
846 | "Return popup mouse menu to correct misspelling."
847 | (when-let ((posn (event-start last-input-event))
848 | (pt (posn-point posn))
849 | (ov (car (jinx--get-overlays pt pt t))))
850 | (let ((menu nil)
851 | (word (buffer-substring-no-properties
852 | (overlay-start ov) (overlay-end ov))))
853 | (dolist (dict jinx--dicts)
854 | (when-let ((desc (jinx--mod-describe dict))
855 | (suggestions (jinx--mod-suggest dict word)))
856 | (push `[,(concat "── " (car desc) " ─ " (cdr desc) " ──") :active nil] menu)
857 | (cl-loop for w in suggestions repeat jinx-menu-suggestions do
858 | (push `[,w (jinx--correct-replace ,ov ,w)] menu))))
859 | (when-let ((suggestions (jinx--session-suggestions word)))
860 | (push ["── Session ──" :active nil] menu)
861 | (cl-loop for w in suggestions repeat jinx-menu-suggestions do
862 | (push `[,w (jinx--correct-replace ,ov ,w)] menu)))
863 | (push ["── Accept and save ──" :active nil] menu)
864 | (cl-loop for (key . fun) in jinx--save-keys
865 | for actions = (funcall fun nil key word) do
866 | (unless (consp (car actions)) (setq actions (list actions)))
867 | (cl-loop for (k w a) in actions do
868 | (push `[,a (jinx-correct-word
869 | ,(overlay-start ov) ,(overlay-end ov)
870 | ,(concat (if (stringp k) k (char-to-string k)) w))]
871 | menu)))
872 | (easy-menu-create-menu (format "Correct \"%s\"" word)
873 | (delete-dups (nreverse menu))))))
874 |
875 | (defun jinx--load-dicts ()
876 | "Load dictionaries and setup syntax table."
877 | (unless (setq jinx--dicts
878 | (cl-loop for lang in (split-string jinx-languages)
879 | ;; Keep a weak reference to loaded dictionaries.
880 | ;; See .
881 | for dict = (with-memoization (gethash lang jinx--dicts-hash)
882 | (jinx--mod-dict lang))
883 | if dict collect dict))
884 | (message "Jinx: No dictionaries available for %S" jinx-languages)))
885 |
886 | (defun jinx--bounds-of-word ()
887 | "Return bounds of word at point using `jinx--syntax-table'."
888 | (save-excursion
889 | (save-match-data
890 | (with-syntax-table jinx--syntax-table
891 | (unless (looking-at-p "\\<")
892 | (re-search-backward "\\<"))
893 | (when (re-search-forward "\\<\\w+\\>" nil t)
894 | (cons (match-beginning 0) (match-end 0)))))))
895 |
896 | (defun jinx--read-languages ()
897 | "Read languages via `completing-read-multiple'."
898 | (jinx--load-module)
899 | (let ((langs (delete-dups
900 | (cl-loop for (l . p) in (jinx--mod-langs) collect
901 | (propertize l 'jinx--group (format "Provider %s" p))))))
902 | (string-join
903 | (or (completing-read-multiple
904 | (format "Change languages (%s): "
905 | (string-join (split-string jinx-languages) ", "))
906 | (jinx--table-with-metadata langs `((group-function . ,#'jinx--group)))
907 | nil t)
908 | (user-error "No languages selected"))
909 | " ")))
910 |
911 | (defun jinx--add-local-word (var word)
912 | "Add WORD to local word list VAR."
913 | (add-to-list 'jinx--session-words word)
914 | (set var
915 | (string-join
916 | (sort (delete-dups (cons word (split-string (symbol-value var))))
917 | #'string<)
918 | " ")))
919 |
920 | ;;;; Save functions
921 |
922 | (defun jinx--save-personal (save key word)
923 | "Save WORD in personal dictionary.
924 | If SAVE is non-nil save, otherwise format candidate given action KEY."
925 | (if save
926 | (let ((idx (seq-position word key (lambda (x y) (not (equal x y))))))
927 | (jinx--mod-add (or (nth idx jinx--dicts)
928 | (user-error "Invalid dictionary"))
929 | (substring word idx)))
930 | (cl-loop
931 | for dict in jinx--dicts for idx from 1
932 | for at = (make-string idx key)
933 | for ann = (format "Personal:%s" (car (jinx--mod-describe dict))) collect
934 | (list at word ann))))
935 |
936 | (defun jinx--save-file (save key word)
937 | "Save WORD in file-local variable.
938 | If SAVE is non-nil save, otherwise format candidate given action KEY."
939 | (if save
940 | (progn
941 | (jinx--add-local-word 'jinx-local-words word)
942 | (add-file-local-variable 'jinx-local-words jinx-local-words))
943 | (list key word "File")))
944 |
945 | (defun jinx--save-dir (save key word)
946 | "Save WORD in directory-local variable.
947 | Uses a .dir-locals.el file in the current directory or any parent
948 | directory. If no .dir-locals.el file is found, it is created in the
949 | project root. If no project root is found, it is created in the current
950 | directory. If SAVE is non-nil save, otherwise format candidate given
951 | action KEY."
952 | (if save
953 | (progn
954 | (jinx--add-local-word 'jinx-dir-local-words word)
955 | (let ((default-directory
956 | (or (locate-dominating-file default-directory ".dir-locals.el")
957 | (when-let (proj (project-current))
958 | (declare-function project-root "project")
959 | (project-root proj))
960 | default-directory)))
961 | (save-window-excursion
962 | (add-dir-local-variable nil 'jinx-dir-local-words jinx-dir-local-words))))
963 | (list key word "Directory")))
964 |
965 | (defun jinx--save-session (save key word)
966 | "Save WORD for the current session.
967 | If SAVE is non-nil save, otherwise format candidate given action KEY."
968 | (if save
969 | (add-to-list 'jinx--session-words word)
970 | (list key word "Session")))
971 |
972 | ;;;; Public commands
973 |
974 | ;;;###autoload
975 | (defun jinx-languages (langs &optional global)
976 | "Set languages locally or globally to LANGS.
977 | LANGS should be one or more language codes as a string, separated
978 | by whitespace. When called interactively, the language codes are
979 | read via `completing-read-multiple'. If the prefix argument
980 | GLOBAL is non-nil, the languages are changed globally for all
981 | buffers. See also the variable `jinx-languages'."
982 | (interactive (list (jinx--read-languages) current-prefix-arg))
983 | (unless jinx-mode (jinx-mode))
984 | (cond
985 | (global
986 | (kill-local-variable 'jinx-languages)
987 | (setq-default jinx-languages langs))
988 | (t
989 | (setq-local jinx-languages langs)
990 | (when (or (assq 'jinx-languages file-local-variables-alist)
991 | (if (eq jinx-save-languages 'ask)
992 | (and buffer-file-name
993 | (y-or-n-p "Save `jinx-languages' as file-local variable? "))
994 | jinx-save-languages))
995 | (add-file-local-variable 'jinx-languages jinx-languages)
996 | (setf (alist-get 'jinx-languages file-local-variables-alist) jinx-languages))))
997 | (jinx--load-dicts)
998 | (jinx--cleanup))
999 |
1000 | ;;;###autoload
1001 | (defun jinx-correct-all (&optional only-check)
1002 | "Correct all misspelled words in the buffer.
1003 | With prefix argument ONLY-CHECK, only check the buffer and highlight all
1004 | misspelled words, but do not open the correction UI."
1005 | (interactive "*P")
1006 | (jinx--correct-guard
1007 | (let* ((overlays (jinx--force-overlays (or (use-region-beginning) (point-min))
1008 | (or (use-region-end) (point-max))
1009 | :check t))
1010 | (count (length overlays))
1011 | (idx 0))
1012 | (if only-check
1013 | (message "%d misspelled word%s in buffer `%s'"
1014 | count (if (= count 1) "" "s") (buffer-name))
1015 | (deactivate-mark)
1016 | (push-mark)
1017 | (while-let ((ov (nth idx overlays)))
1018 | (if-let (((overlay-buffer ov))
1019 | (skip (jinx--correct-overlay ov :info (format " (%d of %d)" (1+ idx) count))))
1020 | (setq idx (mod (+ idx skip) count))
1021 | (cl-incf idx)))))))
1022 |
1023 | ;;;###autoload
1024 | (defun jinx-correct-nearest ()
1025 | "Correct nearest misspelled word."
1026 | (interactive "*")
1027 | (save-excursion
1028 | (jinx--correct-guard
1029 | (let* ((overlays (jinx--force-overlays (window-start) (window-end) :visible t))
1030 | (count (length overlays))
1031 | (idx 0))
1032 | ;; Not using `while-let' is intentional here.
1033 | (while (when-let ((ov (nth idx overlays)))
1034 | (if (overlay-buffer ov)
1035 | (when-let ((skip (jinx--correct-overlay ov)))
1036 | (setq idx (mod (+ idx skip) count)))
1037 | (cl-incf idx)))))))) ;; Skip deleted overlay
1038 |
1039 | ;;;###autoload
1040 | (defun jinx-correct-word (&optional start end initial)
1041 | "Correct word between START and END, by default the word before point.
1042 | Suggest corrections even if the word is not misspelled.
1043 | Optionally insert INITIAL input in the minibuffer."
1044 | (interactive)
1045 | (unless (and start end)
1046 | (setf (cons start end) (or (jinx--bounds-of-word)
1047 | (user-error "No word at point"))))
1048 | (save-excursion
1049 | (jinx--correct-guard
1050 | (while-let ((skip (let ((ov (make-overlay start end)))
1051 | (unwind-protect
1052 | (jinx--correct-overlay ov :initial initial)
1053 | (delete-overlay ov)))))
1054 | (forward-to-word skip)
1055 | (when-let ((bounds (jinx--bounds-of-word)))
1056 | (setf (cons start end) bounds
1057 | initial nil))))))
1058 |
1059 | ;;;###autoload
1060 | (defun jinx-correct (&optional arg)
1061 | "Correct word depending on prefix ARG.
1062 | This command dispatches to the following commands:
1063 | - `jinx-correct-nearest': If prefix ARG is nil, correct nearest
1064 | misspelled word.
1065 | - `jinx-correct-all': If a region is marked, or if prefix ARG
1066 | is 4, corresponding to \\[universal-argument] pressed once,
1067 | correct all misspelled words.
1068 | - `jinx-correct-word': If prefix ARG is 16, corresponding to
1069 | \\[universal-argument] pressed twice, correct word before point.
1070 | - If prefix ARG is 64, corresponding to \\[universal-argument] pressed
1071 | three times, check the whole buffer, but do not open the correction
1072 | UI."
1073 | (interactive "*P")
1074 | (pcase arg
1075 | ('nil (if (use-region-p) (jinx-correct-all) (jinx-correct-nearest)))
1076 | ('(16) (jinx-correct-word))
1077 | ('(64) (jinx-correct-all t))
1078 | (_ (jinx-correct-all))))
1079 |
1080 | (defun jinx-correct-select ()
1081 | "Quick selection key for corrections."
1082 | (declare (completion ignore))
1083 | (interactive)
1084 | (let* ((keys (this-command-keys-vector))
1085 | (word (nth (if (eq (aref keys 0) ?0)
1086 | (+ 9 (or (seq-position jinx--select-keys (aref keys 1)) 999))
1087 | (- (aref keys 0) ?1))
1088 | (all-completions "" minibuffer-completion-table))))
1089 | (unless (and word (get-text-property 0 'jinx--prefix word))
1090 | (user-error "Invalid select key `%s'" (key-description keys)))
1091 | (delete-minibuffer-contents)
1092 | (insert word)
1093 | (exit-minibuffer)))
1094 |
1095 | (defun jinx-next (n)
1096 | "Go to to Nth next misspelled word."
1097 | (interactive "p" jinx-mode)
1098 | (unless (= n 0)
1099 | (if (minibufferp)
1100 | (throw 'jinx--goto n)
1101 | (let ((ov (jinx--force-overlays (point-min) (point-max))))
1102 | (unless (or (> n 0) (<= (overlay-start (car ov)) (point) (overlay-end (car ov))))
1103 | (cl-incf n))
1104 | (goto-char (overlay-end (nth (mod n (length ov)) ov)))
1105 | (jinx--invisible-open-permanently)))))
1106 |
1107 | (defun jinx-previous (n)
1108 | "Go to to Nth previous misspelled word."
1109 | (interactive "p" jinx-mode)
1110 | (jinx-next (- n)))
1111 |
1112 | ;;;###autoload
1113 | (define-minor-mode jinx-mode
1114 | "Enchanted Spell Checker."
1115 | :lighter (" " (:eval (concat "Jinx[" jinx-languages "]")))
1116 | :group 'jinx
1117 | :keymap jinx-mode-map
1118 | (cond
1119 | ((buffer-base-buffer) ;; Do not enable in indirect buffers
1120 | (when jinx-mode
1121 | (jinx-mode -1)))
1122 | (jinx-mode
1123 | (jinx--load-module)
1124 | (cl-letf* ((enable-local-variables :safe)
1125 | (enable-local-eval nil)
1126 | ;; Fix reentrancy problem (gh:minad/jinx#158)
1127 | ((symbol-function #'jinx-mode) #'ignore))
1128 | (hack-local-variables 'ignore-mode))
1129 | (jinx--get-org-language)
1130 | (setq jinx--exclude-regexp
1131 | (when-let ((regexps (jinx--mode-list jinx-exclude-regexps)))
1132 | (mapconcat (lambda (r) (format "\\(?:%s\\)" r))
1133 | regexps "\\|"))
1134 | jinx--include-faces (jinx--mode-list jinx-include-faces)
1135 | jinx--exclude-faces (jinx--mode-list jinx-exclude-faces)
1136 | jinx--exclude-properties (jinx--mode-list jinx-exclude-properties)
1137 | jinx--camel (or (eq jinx-camel-modes t)
1138 | (seq-some #'derived-mode-p jinx-camel-modes))
1139 | jinx--session-words (nconc (split-string jinx-dir-local-words)
1140 | (split-string jinx-local-words)))
1141 | (jinx--load-dicts)
1142 | (dolist (hook jinx--reschedule-hooks)
1143 | (add-hook hook #'jinx--reschedule nil t))
1144 | (jit-lock-register #'jinx--mark-pending))
1145 | (t
1146 | (mapc #'kill-local-variable '(jinx--exclude-regexp jinx--include-faces
1147 | jinx--exclude-faces jinx--camel
1148 | jinx--dicts jinx--syntax-table
1149 | jinx--session-words))
1150 | (dolist (hook jinx--reschedule-hooks)
1151 | (remove-hook hook #'jinx--reschedule t))
1152 | (jit-lock-unregister #'jinx--mark-pending)
1153 | (jinx--cleanup))))
1154 |
1155 | ;;;###autoload
1156 | (define-globalized-minor-mode global-jinx-mode
1157 | jinx-mode jinx--on
1158 | :group 'jinx
1159 | :predicate '(text-mode prog-mode conf-mode))
1160 |
1161 | (defun jinx--on ()
1162 | "Turn `jinx-mode' on."
1163 | (unless (or noninteractive
1164 | buffer-read-only
1165 | (buffer-base-buffer) ;; Do not enable in indirect buffers
1166 | (eq (aref (buffer-name) 0) ?\s))
1167 | (jinx-mode)))
1168 |
1169 | (provide 'jinx)
1170 | ;;; jinx.el ends here
1171 |
--------------------------------------------------------------------------------