branch: externals/greader
commit cdbdf246950bfb655fb36879318c053fef4ad577
Author: Michelangelo Rodriguez <michelangelo.rodrig...@gmail.com>
Commit: Michelangelo Rodriguez <michelangelo.rodrig...@gmail.com>

    greader-dict.el: Command `greader-dict-modify-key' added.
    
    This command modifies a key itself, that is, without modifying the
    associated value.
---
 greader-dict.el | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/greader-dict.el b/greader-dict.el
index 09e2be4277..d3c0d257fb 100644
--- a/greader-dict.el
+++ b/greader-dict.el
@@ -681,7 +681,31 @@ If TYPE is `all', all items in the current dictionary will 
be included."
      matches
      (lambda (s1 s2)
        (string-greaterp s2 s1)))))
-
+(defun greader-dict-modify-key (arg)
+  "Modify a key (_NOT_ a value associated with it!).
+While `greader-dict-add-entry can modify either keys or associated
+values, `greader-dict-modify-key' allows you to modify the key
+itself, without modifying the associated value.
+if prefix ARG is non-nil, then this command proposes only keys that
+are classified as matches."
+  (interactive "P")
+  (let ((key (read-string "key to modify: " nil nil (if arg
+                                                       
(greader-dict--get-matches
+                                                        'match)
+                                                     (greader-dict--get-matches
+                                                      'all))))
+       (new-key nil))
+    (unless key
+      (user-error "Key not valid"))
+    (if-let ((backup-value (gethash key)))
+       (progn
+         (setq new-key (read-string (concat "substitute key " key "
+  with:") nil nil key))
+         (unless new-key
+           (user-error "Invalid replacement"))
+         (greader-dict-remove key)
+         (greader-dict-add new-key backup-value))
+      (user-error "Key not found"))))
 
 (provide 'greader-dict)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Reply via email to