Ask for POS when adding a new article. Place point at the line for the first translation.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Mon, 14 Sep 2020 19:36:55 +0300
changeset 1241 57382ad6d332
parent 1240 39c9cb59cfea
child 1242 cceb112a1ca9
Ask for POS when adding a new article. Place point at the line for the first translation.
contrib/gadict.el
--- a/contrib/gadict.el	Mon Sep 14 19:21:52 2020 +0300
+++ b/contrib/gadict.el	Mon Sep 14 19:36:55 2020 +0300
@@ -254,12 +254,11 @@
   values in .dir-local.el or as -*- gadict-tr: \"...\" -*- file prelude")
 (put 'gadict-tr 'safe-local-variable 'string-or-null-p)
 
-(defun gadict-insert-article (headword)
+(defun gadict-insert-article (headword pos)
   "Insert new article after the current place.
 
 If `gadict-espeak-enabled' is `t' pronunciation will be filled
 with espeak `gadict-espeak-default-voice'."
-  (interactive)
   (if (re-search-forward "^__" nil t)
       (beginning-of-line)
     (goto-char (point-max)))
@@ -268,26 +267,15 @@
   (insert-char ?\n)
   (insert-char ?_ 2)
   (insert-char ?\n 3)
-  (when (stringp gadict-tr)
-    (mapc (lambda (tr)
-            (insert-char ?\n)
-            (insert tr)
-            (insert ": "))
-          (split-string gadict-tr ","))
-    (insert-char ?\n)
-    (backward-char)
-    (re-search-backward "^$"))
-  (backward-char)
+  (forward-char -1)
   (insert headword)
   (insert "\n  [")
-  (if gadict-espeak-enabled
-      (progn
-        (insert (gadict-espeak-ipa headword gadict-espeak-default-voice))
-        (insert "]")
-        (when gadict-tr
-          (search-forward ": ")))
-    (insert "]")
-    (backward-char)))
+  (when gadict-espeak-enabled
+    (insert (gadict-espeak-ipa headword gadict-espeak-default-voice)))
+  (insert "]")
+  (insert-char ?\n 2)
+  (insert pos)
+  (gadict--insert-tr))
 
 (defun gadict-search-floor (headword)
   "Move to HEADWORD definition or place on posiiton for new corresponding
@@ -329,13 +317,15 @@
   (gadict-search-floor headword)
   (recenter))
 
-(defun gadict-insert-article-in-order (headword)
+(defun gadict-insert-article-in-order ()
   "Insert new article template with respect of headword order."
-  (interactive (list (read-string "Headword: ")))
-  (unless (gadict-search-floor headword)
-    (gadict-insert-article headword))
-  (activate-input-method nil)
-  (recenter))
+  (interactive)
+  (let (headword pos)
+    (setq headword (read-string "Headword: "))
+    (unless (gadict-search-floor headword)
+      (setq pos (completing-read "POS: " gadict--pos nil t))
+      (gadict-insert-article headword pos)
+      (recenter))))
 
 (defun gadict--find-headword-end ()
   (save-excursion
@@ -354,19 +344,23 @@
         (goto-char headword-end)
       (re-search-forward "^\\(?:\\|__\\)$")
       (when (eq (char-before) ?_)
-        (beginning-of-line)
-        ;; (newline)
-        ;; (backward-char)
-        ))
-    (insert-char ?\n)
+        (beginning-of-line)))
+    (insert-char ?\n 2)
+    (forward-char -1)
     (insert pos)
-    (insert-char ?\n)
+    (gadict--insert-tr) ))
+
+(defun gadict--insert-tr ()
+  "Insert `gadict-tr' as multiline template on next line. Place point on the end of the first new line."
+  (when (stringp gadict-tr)
     (save-excursion
+      (end-of-line)
       (mapc (lambda (lang)
+              (insert-char ?\n)
               (insert lang)
-              (insert ": \n"))
+              (insert ": "))
             (split-string gadict-tr ",")))
-    (end-of-line) ))
+    (end-of-line 2)))
 
 (defun gadict-nearest-headword ()
   "Return nearest headword looking upward."