Copy existing pronunciation of selected region or current word to `kill-ring'.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Fri, 17 Mar 2017 21:07:20 +0200
changeset 802 a812ec996022
parent 801 04397698b6be
child 803 13f5485d81c6
Copy existing pronunciation of selected region or current word to `kill-ring'.
contrib/gadict.el
--- a/contrib/gadict.el	Fri Mar 17 18:54:55 2017 +0200
+++ b/contrib/gadict.el	Fri Mar 17 21:07:20 2017 +0200
@@ -353,11 +353,23 @@
       (match-string 1)
       )))
 
+(defun gadict-copy-pronunciation (&optional headword)
+  "Copy existing pronunciation of selected region or current word to `kill-ring'."
+  (interactive
+   (list (if (use-region-p)
+             (buffer-substring region-beginning region-end)
+           (thing-at-point 'word))))
+  (save-excursion
+    (gadict-search-floor headword)
+    (when (search-forward-regexp "\\[\\([^]]+\\)]")
+      (kill-new (match-string 1)))))
+
 (defun gadict-setup-keymap ()
   "Setup gadict keymap."
-  (define-key (current-local-map) [M-return] 'gadict-search)
   (define-key (current-local-map) [S-return] 'gadict-insert-translation)
-  (define-key (current-local-map) [C-return] 'gadict-insert-template-in-order))
+  (define-key (current-local-map) [C-return] 'gadict-insert-template-in-order)
+  (define-key (current-local-map) [C-S-return] 'gadict-search)
+  (define-key (current-local-map) [M-return] 'gadict-copy-pronunciation))
 
 ;;;###autoload
 (define-derived-mode gadict-mode fundamental-mode "gadict"