branch: externals/greader commit cf1db7405bfa694c837e1d3e4d759b47d5956524 Author: Michelangelo Rodriguez <michelangelo.rodrig...@gmail.com> Commit: Michelangelo Rodriguez <michelangelo.rodrig...@gmail.com>
dict filters fixed. 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. --- greader-dict.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/greader-dict.el b/greader-dict.el index 807e5fd741..ae00dcfcda 100644 --- a/greader-dict.el +++ b/greader-dict.el @@ -350,6 +350,8 @@ If you want to add a partial replacement, you should add `\*'to the end of the WORD string parameter." ;; We prevent an infinite loop if disallowing that key and values ;; are the same. + (unless replacement + (setq replacement "")) (when (string-equal-ignore-case word replacement) (user-error "key and value are the same, aborting")) (puthash word replacement greader-dictionary) @@ -926,6 +928,8 @@ in the current sentence." (gethash (concat key greader-dict-filter-indicator) greader-dictionary)))) (list key value))) + (while (string-match "\n" key) + (setq key (replace-match "[[:space:]]" nil nil key))) (greader-dict-add (concat key greader-dict-filter-indicator) value) (greader-dict--filter-init)) @@ -982,11 +986,11 @@ hash table." "Apply filters defined in sequence to the current buffer." (maphash (lambda (k v) + (setq k (string-remove-suffix greader-dict-filter-indicator k)) + (setq k (string-trim-right k)) (save-excursion (goto-char (point-min)) - (while (re-search-forward (string-remove-suffix - greader-dict-filter-indicator k) - nil t) + (while (re-search-forward k nil t) (replace-match v)))) greader-filters))