branch: externals/greader
commit 152c4dfc80a933942c8d4c145bfac34540b734b2
Author: Michelangelo Rodriguez <[email protected]>
Commit: Michelangelo Rodriguez <[email protected]>

    greader-dict.el: more work for function `greader-dict--add-match-as-word.
    
    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.
---
 greader-dict.el | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/greader-dict.el b/greader-dict.el
index 5c88ea8f97..8a6f47250c 100644
--- a/greader-dict.el
+++ b/greader-dict.el
@@ -1000,7 +1000,8 @@ hash table."
         (replace-match v))))
    greader-filters))
 
-(defun greader-dict--add-match-as-word (key word replacement)
+(defun greader-dict--add-match-as-word (key word replacement &optional
+                                           original-word)
   "Add WORD and REPLACEMENT to the current dictionary.
 This function is used internally, please use the normal entry-points
 to add your own items to the dictionary."
@@ -1009,13 +1010,18 @@ to add your own items to the dictionary."
     (string-match key word)
     (setq start (match-beginning 0))
     (setq end (match-end 0))
-    (setq key word)
     (when (> start 0)
       (setq value (concat (substring word 0 start))))
     (setq value (concat value replacement))
     (when (> (length word) (length value))
       (setq value (concat value (substring word end))))
-    (greader-dict-add key value)))
+    (if (string-match key value)
+       (progn
+         (setq original-word word)
+         (greader-dict--add-match-as-word key value replacement
+                                          original-word))
+      (setq key (or original-word word))
+      (greader-dict-add key value))))
 
 (provide 'greader-dict)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Reply via email to