summaryrefslogtreecommitdiff
path: root/greader-dict.el
AgeCommit message (Collapse)Author
2026-04-10Apply patches from Stefan Monnierexternals/greaderMichelangelo Rodriguez
* greader-dict.el: Require 'greader instead of forward-declaring greader--current-buffer, fixing byte-compilation of greader-dict-tests.el. (greader-dict-filters-prefix-map, greader-dict-prefix-map): Initialize keymaps inline in defvar declarations instead of mutating them with top-level define-key calls. Bind "d" in greader-prefix-keymap directly. * greader.el: Remove forward declaration of greader-dict-prefix-map and the eval-after-load form that bound it, since greader-dict.el now handles this itself. Co-Authored-By: Stefan Monnier <monnier@iro.umontreal.ca>
2026-03-25fix(dict): Fix and complete dictionary merging implementationMichelangelo Rodriguez
* greader-dict.el (greader-dict--merge): Return KEY unchanged when already merged, instead of nil; fixes nil key being inserted into the hash table on duplicate merge attempts. (greader-dict-merge--check-candidate): Fix inverted predicate logic and broken path comparison (full path vs. nondirectory); use expand-file-name for correct equality check. (greader-dict-merge--dictionaries): Iterate over (cdr dictionaries) to skip the main dictionary itself; call greader-dict-read-from-dict-file directly to avoid circular dispatch through greader-dict-merge-dictionary. (greader-dict-merge-dictionary): When called with FILENAME, update greader-dict-merge-dictionaries-alist, pass merge=t to greader-dict-read-from-dict-file, and respect greader-dict-merge-save. (greader-dict-merge-save): Rename to greader-dict-merge-save-to-file to avoid defcustom/defun namespace collision. (greader-dict-mode): Call greader-dict-load-merges and greader-dict-merge--dictionaries on startup to auto-reload saved merges. (greader-dict-prefix-map): Bind "M" to greader-dict-merge-dictionary. (greader-dict-filters-mode): Add forward declaration before with-greader-dict-temp-buffer to suppress byte-compiler warning. * greader-dict-tests.el: New file; 7 ERT tests covering greader-dict--merged-p, greader-dict--merge, greader-dict-add with merge flag, greader-dict-write-file skipping merged entries, and greader-dict-merge-dictionary loading and updating the alist. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25feat(dict): Implement non-destructive dictionary mergingMichelangelo Rodriguez
This commit introduces a feature to merge multiple dictionary files. This allows users to combine a primary dictionary with one or more auxiliary dictionaries (e.g., a personal word list) temporarily for a session or persistently across sessions, without modifying the main dictionary file. Key changes: - A new interactive command `greader-dict-merge-dictionary` allows merging another dictionary into the current one. - Merged entries are marked with a `greader-dict-merged` text property and are not saved to the main dictionary file, ensuring the merge is non-destructive. - Merge configurations are stored in `greader-dict-merge-dictionaries-alist` and can be saved persistently to a separate `.merges` file, controlled by the `greader-dict-merge-save` custom variable. - `greader-dict-read-from-dict-file` and `greader-dict-add` were updated to handle the merging logic.
2026-03-21greader-dict: avoid rebuilding match list on every word lookupMichelangelo Rodriguez
* greader-dict.el (greader-dict--get-key-from-word): Add optional MATCHES argument. When provided, use it directly instead of building a fresh temporary hash table of match-type entries on every invocation. The new implementation iterates over the list with `dolist', which avoids the O(m) allocation and copy that the previous code performed for each word that had no direct entry in `greader-dictionary'. (greader-dict-check-and-replace): Pre-compute the list of match-type keys once with `greader-dict--get-matches' and pass it to `greader-dict--get-key-from-word' on every iteration of the main word loop. This eliminates the repeated allocation that occurred for each unmatched word in the sentence.
2026-03-21greader-dict: avoid reloading dictionary during readingMichelangelo Rodriguez
In "greader-dict--update", wrap the code that reads the dictionary file from disk within an "unless greader-reading-mode" block. This prevents the dictionary from being reloaded while the reader is active, which could lead to inconsistent state or performance issues during playback.
2026-03-21greader-dict: add autoload cookie to obsolete aliasMichelangelo Rodriguez
* greader-dict.el (greader-dict-toggle-filters): Add ;;;###autoload cookie so that calling the obsolete alias before the library is loaded triggers autoloading correctly.
2026-03-21Merge branch 'master' into personalMichelangelo Rodriguez
2026-03-21greader-dict: remove redundant obsolete variable aliasMichelangelo Rodriguez
Remove the "greader-dict-toggle-filters" variable alias, as it is redundant with the function alias for "greader-dict-filters-mode".
2026-03-21greader-dict: rename greader-dict-toggle-filters to greader-dict-filters-modeMichelangelo Rodriguez
Rename the "greader-dict-toggle-filters" minor mode to "greader-dict-filters-mode" to align with Emacs naming conventions. Obsolete aliases for the function and the variable are provided to ensure backward compatibility. Internal references across the project have been updated accordingly.
2026-03-06greader-dict: ignore errors when adding a newline to temp bufferMichelangelo Rodriguez
When processing a single word, greader-dict appends a newline to the temporary buffer. This commit wraps the "newline" call in "ignore-errors" to prevent potential failures from interrupting the execution, especially if the buffer state is restricted.
2025-12-13Fix(greader-dict): Correctly reference the reading bufferMichelangelo Rodriguez
When dictionary functions are executed from a temporary buffer, they need to know the original buffer from which the lookup was initiated. Previously, the variable "greader-dict--current-reading-buffer" was not always correctly set, leading to issues where buffer-local values (like the dictionary language) could not be found. This change ensures that "greader--current-buffer" is prioritized when available, and correctly propagates the reading buffer context into the sandbox environment.
2025-12-13Fix: Remove unnecessary escape character from filter indicatorMichelangelo Rodriguez
2025-12-12Fix regexp escaping in greader-dict.elMichelangelo Rodriguez
Adjust regexp escaping for "greader-dict-match-indicator" and "greader-dict--item-type-alist" definitions. This change simplifies the string representation by removing unnecessary backslashes, as "%" is not a special character in Emacs Lisp strings unless used in a format string.
2025-11-25Refactor: Improve greader-dict and greader interactionMichelangelo Rodriguez
To prevent byte-compiler warnings, remove the "(require 'greader)" from "greader-dict.el" and introduce a "defvar" for "greader--current-buffer" instead. In "greader.el", add forward declarations for variables and functions used from "greader-dict.el". This ensures the byte-compiler is aware of them even if "greader-dict.el" is loaded later. Additionally, reorder the "greader-study-set-position" function for better code organization.
2025-11-23Fix: Ensure dictionary commands use the correct bufferMichelangelo Rodriguez
The greader-dict functions could fail when called from a buffer other than the one where "greader-reading-mode" was active. To solve this, "greader-dict.el" now uses the "greader--current-buffer" variable to find the correct buffer. This variable is now set more reliably via a new hook in "greader-reading-mode". This change centralizes the logic for tracking the active reading buffer, making dictionary operations more robust.
2025-11-22Fix(greader-dict): Correctly identify the reading bufferMichelangelo Rodriguez
The change in greader-dict--update ensures that the correct reading buffer is used when updating the dictionary. Previously, (current-buffer) was used, which could lead to errors if the update function was called from a different context than the buffer being read. The new implementation now prioritizes the value of greader--current-buffer, falling back to (current-buffer) only if it is not set. This improves the reliability of the dictionary update mechanism.
2025-11-06Refactor: Update dictionary on stop and simplify filter logicMichelangelo Rodriguez
The dictionary update process is now called from "greader-stop". This ensures that "greader-dict--update" is executed once when reading stops, making the update process more reliable. In "greader-dict.el", the logic for applying filters has been simplified. The function "greader-dict-check-and-replace" no longer fetches filter variables from the reading buffer. This reduces coupling between the dictionary and the reading buffer's local variables. The docstring for "greader-stop" has been updated to document the new behavior.
2025-10-28Merge branch ↵Michelangelo Rodriguez
'5-greader-dict-mode-with-a-linux-to-gnu-plus-linux-rule-makes-greader-hang' into 'master' Resolve "greader-dict-mode with a "Linux" to "GNU plus Linux" rule makes greader hang." Closes #5 See merge request michelangelo-rodriguez/greader!14
2025-10-27Refactor: Make keymap prefix customizableMichelangelo Rodriguez
This commit refactors the keybinding system to allow for greater user customization. The hardcoded "C-r" prefix has been replaced with a new customizable variable, `greader-keymap-prefix`. Users can now set their preferred keybinding prefix in their configuration. Key changes: - A new `greader-keymap-prefix` customizable variable is introduced. - Keymaps have been reorganized into a hierarchical structure using prefix maps (`greader-prefix-keymap`, `greader-dict-prefix-map`). - A new interactive function, `greader-set-map-prefix`, allows changing the prefix for the current session. - Dictionary keybindings are now loaded into the main prefix map via `eval-after-load`, improving modularity.
2025-10-22greader-dict.el (greader-dict-add-entry): Prohibit punctuation in replacementsMichelangelo Rodriguez
The validation for dictionary replacements was overly restrictive. It used the "\\W" regexp class, which disallows any character that is not a word constituent. This could prevent legitimate replacements. The check is now more specific, using the "[[:punct:]]" character class to only forbid punctuation marks. This aligns better with the intended behavior. The user error message has been updated accordingly.
2025-10-21Fix/Refactor: Improve dictionary functions' robustness and docsMichelangelo Rodriguez
- In `greader-dict.el`: - Remove a `goto-char` call in `greader-dict-substitute-words`, which was a leftover from a previous refactoring. - In `greader-dict-add-interactive`, prevent users from adding a replacement that contains non-word characters. This avoids unexpected behavior with text-to-speech engines. - Improve the docstrings for `greader-dict-add` and `greader-dict-filter-add` to better explain their behavior and limitations, especially regarding input validation and the use of special characters.
2025-10-17Remove a duplicate `(defvar-local greader-dictionary nil)` declaration.Yuval Langer
2025-07-22Fixed Docstring Warning.Michelangelo Rodriguez
2025-07-21Fix Guix build issue.Yuval Langer
Without this `(require 'greader)`, the Guix package manager cannot build the package, as noted here: <https://codeberg.org/guix/guix/pulls/1360#issuecomment-5901343>
2025-06-14Some checkdoc notes fixed.Michelangelo Rodriguez
2025-06-10Fixes and update.Michelangelo Rodriguez
Fixed changing language, the change now reflects immediately. Also the function `greader-dict-info' updated to count even defined filters.
2025-03-04Macro `with-greader-dict-temp-buffer' calls now behaves as expected, ↵Michelangelo Rodriguez
indenting the body as a function.
2025-01-06Macro `with-greader-dict-temp-buffer' added.Michelangelo Rodriguez
Now greader-dict.el uses this macro for operate with temp buffers.
2024-10-25greader-dict.el: now use if and when-let* to as if and when-let are obsolete.Michelangelo Rodriguez
2024-09-21greader-dict.el: `greader-dict--get-key-from-word' fixed.Michelangelo Rodriguez
Now it manages correctly an empty word.
2024-07-29greader-dict.el: Added user option `greader-dict-transform-match-to-word' to ↵Michelangelo Rodriguez
permit enabling or disabling the new feature.
2024-07-26greader-dict.el: now changing the dictionary works as expected.Michelangelo Rodriguez
2024-07-25greader-dict.el: Now the function greader-dict--add-match-as-word' works ↵Michelangelo Rodriguez
only when the replacement parameter contains a word.
2024-07-23greader-dict.el: more work for function `greader-dict--add-match-as-word.Michelangelo Rodriguez
Now this function handles the case in which there are two or more instances of the match. For example: If you want to substitute the word "einstein" defining a match "ein" there are two matches in the same word.
2024-07-23greader-dict.el: Now when a match is found, it will be converted in a word ↵Michelangelo Rodriguez
and added as word in the dictionary. In this way i hope that the performance of substitution will be slightly improved.
2024-07-23Fixed functions `greader-dict-add-entry' and `greader-dict--get-matches' to ↵Michelangelo Rodriguez
handle correctly things which have properties.
2024-07-20Function `greader-dict--word-alternatives fixed.Michelangelo Rodriguez
Documentation of command `greader-dict-add-entry' improved.
2024-07-20Function `greader-dict-substitute-word' fixed.Michelangelo Rodriguez
Now it works with "\" correctly.
2024-07-19dict filters fixed.Michelangelo Rodriguez
Now filters support multiple lines, them will be transformed in a regexp that don't conflict with the routine that reads the dictionary. More precisely, a "\n" will be replaced with "[[:space:]]" when it is saved in the database. furthermore, now filters can be replaced with an empty string.
2024-07-16greader-dict-add-entry: Modified the prompt to reflect last changes.Michelangelo Rodriguez
2024-07-16greader-dict.el: pp-buffer applied.Michelangelo Rodriguez
2024-07-16Function `greader-dict-modify-key' fixedMichelangelo Rodriguez
Now when this function is called without a prefix, it proposes only matches classified as words for completion.
2024-07-16Fixed docstring of `greader-dict-modify-key'Michelangelo Rodriguez
2024-07-16Added entry to `greader-dict-modify-key' in `greader-dict-mode-map'Michelangelo Rodriguez
2024-07-15greader-dict.el: modifiedMichelangelo Rodriguez
Function `greader-dict-add-entry fixed.
2024-07-15greader.el: modifiedMichelangelo Rodriguez
- Function `greader-dict--get-key-from-word simplified. - other minor fixes.
2024-07-15greader-dict-add-entry now deactivates the Mark after adding a match.Michelangelo Rodriguez
2024-07-01greader version 0.11.11Michelangelo Rodriguez
Minor fixes.
2024-06-24greader: "Package-lint" pacified.Michelangelo Rodriguez
2024-06-09greader-dict.el: rehorganized better in term of variables, grouped alltogeter.Michelangelo Rodriguez