contrib/gadict.el
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 10 Jan 2018 19:49:33 +0200
changeset 1004 181301cc2c0c
parent 998 14804339afc1
child 1007 672f0b73889a
permissions -rw-r--r--
Removed useless statement.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
381
1729e4655e4d Fix (package-buffer-info) errors: "Package lacks a \"Version\" or \"Package-Version\" header"
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 380
diff changeset
     1
;;; gadict.el --- major mode for editing gadict dictionary source files -*- lexical-binding: t -*-
320
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
361
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
     3
;; Copyright (C) 2016 by Oleksandr Gavenko <gavenkoa@gmail.com>
320
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
;; You can do anything with this file without any warranty.
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     7
;; Author: Oleksandr Gavenko <gavenkoa@gmail.com>
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
;; Maintainer: Oleksandr Gavenko <gavenkoa@gmail.com>
361
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
     9
;; Created: 2016
381
1729e4655e4d Fix (package-buffer-info) errors: "Package lacks a \"Version\" or \"Package-Version\" header"
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 380
diff changeset
    10
;; Version: 0.1
320
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    11
;; Keywords: dict, dictionary
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    12
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
;;; Commentary:
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    14
;;
510
212d9ff8725c Mode can be installed by...
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 457
diff changeset
    15
;; Mode can be installed by:
212d9ff8725c Mode can be installed by...
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 457
diff changeset
    16
;;
212d9ff8725c Mode can be installed by...
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 457
diff changeset
    17
;;   (autoload 'gadict-mode "gadict")
212d9ff8725c Mode can be installed by...
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 457
diff changeset
    18
;;
361
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
    19
;; File association can be registered by:
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
    20
;;
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
    21
;;   (add-to-list 'auto-mode-alist (cons "\\.gadict$" 'gadict-mode))
320
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    22
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    23
;;; Code:
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    24
710
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    25
(defun gadict--trim-left (s)
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    26
  "Remove whitespace at the beginning of S."
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    27
  (if (string-match "\\`[ \t\n\r]+" s)
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    28
      (replace-match "" t t s)
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    29
    s))
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    30
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    31
(defun gadict--trim-right (s)
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    32
  "Remove whitespace at the end of S."
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    33
  (if (string-match "[ \t\n\r]+\\'" s)
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    34
      (replace-match "" t t s)
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    35
    s))
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    36
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    37
(defun gadict--trim (s)
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    38
  "Remove whitespace at the beginning and end of S."
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    39
  (gadict--trim-left (gadict--trim-right s)))
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
    40
745
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    41

4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    42
926
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    43
(defconst gadict--vowels-re "[o$(O+8+:+7+9(Ba$(O+3+0,Af(Be,0#$(O+1(Bi,0!(Bu$(O+5+C+U+S+T(B]+")
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    44
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    45
(defun gadict--vowel-group-count (s)
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    46
  (let ( (cnt 0) (start 0) )
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    47
    (while (string-match gadict--vowels-re s start)
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    48
      (setq cnt (1+ cnt))
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    49
      (setq start (match-end 0)))
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    50
    cnt))
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    51
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    52
(defun gadict--espeak-cleanup-accent (s)
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    53
  "Remove accent if only one syllable in word."
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    54
  (if (<= (gadict--vowel-group-count s) 1)
987
6880ca22ec67 Clean up lower IPA accent sign from one syllable word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 984
diff changeset
    55
      (replace-regexp-in-string "[$,1$h$l(B]" "" s)
926
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    56
    s))
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    57
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    58
(defun gadict--espeak-cleanup-accent-in-sentence (s)
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    59
  "Remove accent if only one syllable in word."
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    60
  (mapconcat #'gadict--espeak-cleanup-accent (split-string s " ") " "))
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    61
744
4d78dbc5a9b0 Cleanup espeak IPA output.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 743
diff changeset
    62
(defun gadict--espeak-cleanup (s)
4d78dbc5a9b0 Cleanup espeak IPA output.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 743
diff changeset
    63
  "Cleanup espeak IPA output."
925
79ac87d08976 Linearize function call chain.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 887
diff changeset
    64
  (mapc (lambda (fn) (setq s (funcall fn s)))
79ac87d08976 Linearize function call chain.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 887
diff changeset
    65
        (list
79ac87d08976 Linearize function call chain.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 887
diff changeset
    66
         ;; UTF symbol between t$(O*h(B to make ligature.
79ac87d08976 Linearize function call chain.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 887
diff changeset
    67
         (lambda (str) (replace-regexp-in-string "[\x200D]" "" str))
79ac87d08976 Linearize function call chain.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 887
diff changeset
    68
         (lambda (str) (replace-regexp-in-string "t$(O*h(B" "$,1$G(B" str))
998
14804339afc1 Avoid ᵻ symbol.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 987
diff changeset
    69
         (lambda (str) (replace-regexp-in-string "$,1k{(B" ",0!(B" str))
926
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    70
         #'gadict--trim
50969212d5d2 Remove accent if only one syllable in word.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 925
diff changeset
    71
         #'gadict--espeak-cleanup-accent-in-sentence))
925
79ac87d08976 Linearize function call chain.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 887
diff changeset
    72
  s)
744
4d78dbc5a9b0 Cleanup espeak IPA output.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 743
diff changeset
    73
745
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    74
(defvar gadict-espeak-enabled nil
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    75
  "Is espeak used.")
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    76
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    77
(defvar gadict-espeak-program "espeak")
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    78
(defvar gadict-espeak-program-ipa-args "-q --ipa=2")
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    79
;; "en" "en-gb" "en-us" "en-sc"
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    80
(defvar gadict-espeak-voices-list '("en-gb" "en-us")
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    81
  "What voices to show. Look to 'espeak --voices' for full list.")
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    82
(defvar gadict-espeak-default-voice "en-us"
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    83
  "Default voice for espeak. Used in article template.")
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    84
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    85
(defun gadict-espeak-ipa (str &optional voice)
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    86
  (gadict--espeak-cleanup
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    87
   (shell-command-to-string
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    88
    (format "%s %s %s %s"
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    89
            gadict-espeak-program
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    90
            gadict-espeak-program-ipa-args
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    91
            (if (stringp voice) (concat "-v" (shell-quote-argument voice)) "")
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    92
            (shell-quote-argument str)))))
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    93
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    94
(defun gadict-espeak-headline-line (headword)
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    95
  (mapconcat (lambda (voice) (format "%s: %s"
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    96
                                (propertize voice 'face '(:foreground "red"))
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    97
                                (gadict-espeak-ipa headword voice)))
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    98
             (if (listp gadict-espeak-voices-list) gadict-espeak-voices-list '(nil))
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
    99
             " | "))
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   100
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   101
;; (defun gadict-espeak-headline-display ()
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   102
;;   (interactive)
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   103
;;   (message (gadict-espeak-headline-line)))
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   104
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   105
(defvar gadict-espeak-headline-headword nil)
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   106
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   107
(defun gadict-espeak-headline-display ()
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   108
  (when (eq major-mode 'gadict-mode)
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   109
    (let ( (headword (condition-case nil (gadict-nearest-headword) (error nil))) )
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   110
      (unless (eq headword gadict-espeak-headline-headword)
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   111
        (setq gadict-espeak-headline-headword headword)
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   112
        (setq header-line-format (if headword (gadict-espeak-headline-line headword) nil))
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   113
        (force-mode-line-update)))))
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   114
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   115
(defvar gadict-espeak-headline-timer nil)
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   116
(defun gadict-espeak-headline-enable ()
746
73abbe6d4bd3 Hide headline on disable. Expose headline enable/disable function as interactive.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 745
diff changeset
   117
  "Enable headline with espeak IPA pronunciation."
73abbe6d4bd3 Hide headline on disable. Expose headline enable/disable function as interactive.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 745
diff changeset
   118
  (interactive)
745
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   119
  (unless gadict-espeak-headline-timer
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   120
    (setq gadict-espeak-headline-timer (run-with-idle-timer 1 t #'gadict-espeak-headline-display))))
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   121
(defun gadict-espeak-headline-disable ()
746
73abbe6d4bd3 Hide headline on disable. Expose headline enable/disable function as interactive.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 745
diff changeset
   122
  "Enable headline with espeak IPA pronunciation."
73abbe6d4bd3 Hide headline on disable. Expose headline enable/disable function as interactive.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 745
diff changeset
   123
  (interactive)
745
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   124
  (when gadict-espeak-headline-timer
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   125
    (cancel-timer gadict-espeak-headline-timer))
746
73abbe6d4bd3 Hide headline on disable. Expose headline enable/disable function as interactive.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 745
diff changeset
   126
  (setq gadict-espeak-headline-timer nil)
73abbe6d4bd3 Hide headline on disable. Expose headline enable/disable function as interactive.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 745
diff changeset
   127
  (setq header-line-format nil))
745
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   128
4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   129

4679b9e75798 Fix Warning: reference to free variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 744
diff changeset
   130
726
d41eddc3561f Add "det" keyword.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 719
diff changeset
   131
(defconst gadict--pos '("n" "v" "adj" "adv" "pron" "det" "prep" "num" "conj" "int" "phr" "phr.v" "contr" "abbr" "prefix")
652
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   132
  "Defined parts of speech.")
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   133
565
ac68f2680ea0 Add syntax to add related words. Add separators between ant/syn/rel in
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 563
diff changeset
   134
(defconst gadict--art-lang-regex (regexp-opt '("en" "ru" "uk" "la")))
984
73d6e2631338 Added support for collocations' reference.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
   135
(defconst gadict--art-rel-regex (regexp-opt '("ant" "syn" "rel" "topic" "hyper" "hypo" "col")))
647
6ae5399c8087 Add ``rare`` attribute to headword to filter low frequency headwords out from
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 618
diff changeset
   136
(defconst gadict--art-var-regex (regexp-opt '("rare" "v1" "v2" "v3" "s" "pl" "male" "female" "abbr" "comp" "super" "Am" "Br" "Au")))
652
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   137
(defconst gadict--art-pos-regex (regexp-opt gadict--pos))
565
ac68f2680ea0 Add syntax to add related words. Add separators between ant/syn/rel in
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 563
diff changeset
   138
580
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   139
(defgroup gadict nil
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   140
  "gadict-mode customization."
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   141
  :group 'wp)
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   142
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   143
(defface gadict-tr-face '((t :foreground "#40a040" :slant italic))
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   144
  "Face for marker of translation."
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   145
  :group 'gadict)
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   146
(defface gadict-ex-face '((t :foreground "#20a0c0" :slant italic))
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   147
  "Face for marker of example."
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   148
  :group 'gadict)
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   149
(defface gadict-glos-face '((t :foreground "#a04040" :slant italic))
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   150
  "Face for marker of explanation."
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   151
  :group 'gadict)
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   152
361
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
   153
(defvar gadict-font-lock-keywords
565
ac68f2680ea0 Add syntax to add related words. Add separators between ant/syn/rel in
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 563
diff changeset
   154
  `( ("^\\(__\\)\n\n\\(\\w.*\\)$" (1 font-lock-function-name-face) (2 font-lock-keyword-face))
378
8c629eb20c0b Highlight other article headers.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 375
diff changeset
   155
     ("^ .*\n\\(\\w.*\\)" (1 font-lock-keyword-face))
373
51565d9fe630 Highlight comment syntax. Fix uncommenting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 372
diff changeset
   156
     ("^#.*" . font-lock-comment-face)
581
8497d1849d57 Help to find places where COLON is used instead of MODIFIER LETTER TRIANGULAR COLON.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 580
diff changeset
   157
     ("^ +\\[[^]\n:]+]" . font-lock-type-face)
934
6eea1f63443f Added syntax highlighting for homophone's syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 926
diff changeset
   158
     ("^ +homo: " . 'gadict-tr-face)
580
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   159
     (,(format "^%s: " gadict--art-lang-regex) . 'gadict-tr-face)
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   160
     (,(format "^%s> " gadict--art-lang-regex) . 'gadict-ex-face)
f7c1fd21a5dd Add custom faces for translations, explanations and examples.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 579
diff changeset
   161
     (,(format "^%s= " gadict--art-lang-regex) . 'gadict-glos-face)
565
ac68f2680ea0 Add syntax to add related words. Add separators between ant/syn/rel in
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 563
diff changeset
   162
     (,(format "^%s: " gadict--art-rel-regex) . font-lock-doc-face)
ac68f2680ea0 Add syntax to add related words. Add separators between ant/syn/rel in
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 563
diff changeset
   163
     (,(format "^ +%s$" gadict--art-var-regex) . font-lock-doc-face)
ac68f2680ea0 Add syntax to add related words. Add separators between ant/syn/rel in
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 563
diff changeset
   164
     (,(format "^%s$" gadict--art-pos-regex) . font-lock-warning-face) ))
320
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   165
371
d5d1d3e6d11e gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 370
diff changeset
   166
(defun gadict-setup-fontlock ()
380
f0e2c538bf85 Add docs to functions to 100% satisfy checkdoc.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 379
diff changeset
   167
  "Setup gadict fontlock."
371
d5d1d3e6d11e gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 370
diff changeset
   168
  (setq font-lock-defaults
d5d1d3e6d11e gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 370
diff changeset
   169
        '(gadict-font-lock-keywords
d5d1d3e6d11e gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 370
diff changeset
   170
          t nil nil nil
d5d1d3e6d11e gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 370
diff changeset
   171
          (font-lock-multiline . t) ))
d5d1d3e6d11e gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 370
diff changeset
   172
  (add-hook 'font-lock-extend-region-functions 'gadict-font-lock-extend-region t) )
d5d1d3e6d11e gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 370
diff changeset
   173
382
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   174
(defun gadict-setup-syntax ()
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   175
  "Setup gadict characters syntax."
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   176
  (modify-syntax-entry ?' "w"))
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   177
367
ba263c893207 Rename to gadict-setup-comment
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 366
diff changeset
   178
(defun gadict-setup-comment ()
380
f0e2c538bf85 Add docs to functions to 100% satisfy checkdoc.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 379
diff changeset
   179
  "Setup gadict comment commands."
370
04caf7b9657c Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 369
diff changeset
   180
  (set (make-local-variable 'comment-start)  "#")
04caf7b9657c Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 369
diff changeset
   181
  (set (make-local-variable 'comment-continue)  nil)
04caf7b9657c Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 369
diff changeset
   182
  (set (make-local-variable 'comment-end)  "")
04caf7b9657c Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 369
diff changeset
   183
  (set (make-local-variable 'comment-end-skip)  nil)
04caf7b9657c Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 369
diff changeset
   184
  (set (make-local-variable 'comment-multi-line)  nil)
373
51565d9fe630 Highlight comment syntax. Fix uncommenting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 372
diff changeset
   185
  (set (make-local-variable 'comment-use-syntax)  nil) )
365
86acae5bd220 gadict-setup-comment-style
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 362
diff changeset
   186
368
9c6515663b38 Define paragraph/page break at "__" delimiter.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 367
diff changeset
   187
(defun gadict-setup-paragraph ()
965
741b3dc00a7c Make possible selection of whole line after word for expand-region.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 949
diff changeset
   188
  "Setup gadict sentence/paragraph definition."
370
04caf7b9657c Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 369
diff changeset
   189
  (set (make-local-variable 'paragraph-separate)  "__$")
965
741b3dc00a7c Make possible selection of whole line after word for expand-region.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 949
diff changeset
   190
  (set (make-local-variable 'paragraph-start)  "__$")
741b3dc00a7c Make possible selection of whole line after word for expand-region.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 949
diff changeset
   191
  (set (make-local-variable 'sentence-end) "\n"))
368
9c6515663b38 Define paragraph/page break at "__" delimiter.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 367
diff changeset
   192
9c6515663b38 Define paragraph/page break at "__" delimiter.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 367
diff changeset
   193
(defun gadict-setup-page ()
380
f0e2c538bf85 Add docs to functions to 100% satisfy checkdoc.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 379
diff changeset
   194
  "Setup gadict page definition."
370
04caf7b9657c Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 369
diff changeset
   195
  (set (make-local-variable 'page-delimiter)  "__$") )
368
9c6515663b38 Define paragraph/page break at "__" delimiter.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 367
diff changeset
   196
382
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   197
(defvar gadict-indent-offset 2
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   198
  "Indent level.")
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   199
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   200
(defun gadict-indent-line ()
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   201
  "Indent line in gdict mode."
390
7783ce39023d Fix: Warning: Unused lexical variable `indent'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 382
diff changeset
   202
  (if (eq (current-indentation) gadict-indent-offset)
382
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   203
      (indent-line-to 0)
390
7783ce39023d Fix: Warning: Unused lexical variable `indent'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 382
diff changeset
   204
    (indent-line-to gadict-indent-offset)))
382
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   205
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   206
(defun gadict-setup-indent ()
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   207
  "Setup indenting for gdict mode."
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   208
  (set (make-local-variable 'indent-line-function) 'gadict-indent-line))
369
0f500491f990 Setup syntax table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 368
diff changeset
   209
374
aeaa3f721014 Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 373
diff changeset
   210
(defun gadict-mark-article ()
380
f0e2c538bf85 Add docs to functions to 100% satisfy checkdoc.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 379
diff changeset
   211
  "Mark current article."
374
aeaa3f721014 Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 373
diff changeset
   212
  (end-of-line)
aeaa3f721014 Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 373
diff changeset
   213
  (re-search-backward "^__$")
aeaa3f721014 Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 373
diff changeset
   214
  (set-mark (point))
aeaa3f721014 Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 373
diff changeset
   215
  (forward-line)
aeaa3f721014 Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 373
diff changeset
   216
  (if (re-search-forward "^__$" nil t)
aeaa3f721014 Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 373
diff changeset
   217
      (forward-line 0)
aeaa3f721014 Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 373
diff changeset
   218
    (goto-char (point-max)))
aeaa3f721014 Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 373
diff changeset
   219
  (exchange-point-and-mark))
aeaa3f721014 Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 373
diff changeset
   220
972
2cb45551e1e0 For copy/paste it's better to select line with \n.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 965
diff changeset
   221
(defun gadict-mark-line ()
2cb45551e1e0 For copy/paste it's better to select line with \n.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 965
diff changeset
   222
  "Mark current line."
2cb45551e1e0 For copy/paste it's better to select line with \n.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 965
diff changeset
   223
  (forward-line 0)
2cb45551e1e0 For copy/paste it's better to select line with \n.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 965
diff changeset
   224
  (set-mark (point))
2cb45551e1e0 For copy/paste it's better to select line with \n.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 965
diff changeset
   225
  (forward-line 1)
2cb45551e1e0 For copy/paste it's better to select line with \n.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 965
diff changeset
   226
  (exchange-point-and-mark))
2cb45551e1e0 For copy/paste it's better to select line with \n.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 965
diff changeset
   227
391
68d510b25621 Fix: Warning: assignment to free variable `er/try-expand-list'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 390
diff changeset
   228
(defvar er/try-expand-list)
374
aeaa3f721014 Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 373
diff changeset
   229
(defun gadict-setup-expansions ()
375
a2ec98ead57a Fix warning from M-x checkdoc. Add lexical-binding: t.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 374
diff changeset
   230
  "Add `gadict-mode' specific expansions."
972
2cb45551e1e0 For copy/paste it's better to select line with \n.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 965
diff changeset
   231
  (set (make-local-variable 'er/try-expand-list) (list #'er/mark-word #'gadict-mark-line #'gadict-mark-article)))
374
aeaa3f721014 Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 373
diff changeset
   232
395
32309860fe92 Simplify code.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 392
diff changeset
   233
(defvar font-lock-beg)
32309860fe92 Simplify code.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 392
diff changeset
   234
(defvar font-lock-end)
361
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
   235
(defun gadict-font-lock-extend-region ()
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
   236
  "Look for '__' expression and extend `font-lock-beg' and `font-lock-end'."
329
410c26a389a6 Fix highlighting near beginning and end of buffer.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 328
diff changeset
   237
  ;; (message "%d:%d, %d lines" font-lock-beg font-lock-end (count-lines font-lock-beg font-lock-end))
328
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
   238
  (cond
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
   239
   ((and
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
   240
     (< (count-lines font-lock-beg font-lock-end) 5)
329
410c26a389a6 Fix highlighting near beginning and end of buffer.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 328
diff changeset
   241
     (not (and (<= (point-max) font-lock-end) (<= font-lock-beg (point-min)) )))
325
e64b740278c5 Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 324
diff changeset
   242
    (save-excursion
e64b740278c5 Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 324
diff changeset
   243
      (goto-char font-lock-beg)
e64b740278c5 Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 324
diff changeset
   244
      (forward-line -2)
328
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
   245
      (setq font-lock-beg (point))
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
   246
      (goto-char font-lock-end)
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
   247
      (forward-line 3)
965
741b3dc00a7c Make possible selection of whole line after word for expand-region.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 949
diff changeset
   248
      (setq font-lock-end (point)))
328
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
   249
    t)
361
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
   250
   (t nil) ))
325
e64b740278c5 Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 324
diff changeset
   251
372
e14e384267ee Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 371
diff changeset
   252
(defvar-local gadict-tr nil
e14e384267ee Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 371
diff changeset
   253
  "Translation markers as string separated by comma. Define own
e14e384267ee Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 371
diff changeset
   254
  values in .dir-local.el or as -*- gadict-tr: \"...\" -*- file prelude")
379
c336b3ebd9df Mark gadict-tr as safe variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 378
diff changeset
   255
(put 'gadict-tr 'safe-local-variable 'string-or-null-p)
372
e14e384267ee Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 371
diff changeset
   256
398
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   257
(defun gadict-insert-template (&optional headword)
742
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   258
  "Insert new article template after the current place.
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   259
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   260
If `gadict-espeak-enabled' is `t' pronunciation will be filled
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   261
with espeak `gadict-espeak-default-voice'."
335
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
   262
  (interactive)
361
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
   263
  (if (re-search-forward "^__" nil t)
335
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
   264
      (beginning-of-line)
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
   265
    (goto-char (point-max)))
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
   266
  (while (eq (char-before) ?\n)
375
a2ec98ead57a Fix warning from M-x checkdoc. Add lexical-binding: t.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 374
diff changeset
   267
    (delete-char -1))
335
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
   268
  (insert-char ?\n)
361
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
   269
  (insert-char ?_ 2)
335
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
   270
  (insert-char ?\n 3)
372
e14e384267ee Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 371
diff changeset
   271
  (when (stringp gadict-tr)
e14e384267ee Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 371
diff changeset
   272
    (mapc (lambda (tr)
e14e384267ee Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 371
diff changeset
   273
            (insert-char ?\n)
e14e384267ee Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 371
diff changeset
   274
            (insert tr)
e14e384267ee Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 371
diff changeset
   275
            (insert ": "))
e14e384267ee Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 371
diff changeset
   276
          (split-string gadict-tr ","))
e14e384267ee Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 371
diff changeset
   277
    (insert-char ?\n)
563
e003bfd46c29 Fix: proper back to headword position.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 542
diff changeset
   278
    (backward-char)
372
e14e384267ee Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 371
diff changeset
   279
    (re-search-backward "^$"))
398
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   280
  (backward-char)
423
6a772e1fc63d Add bracket for pronunciation if headword is provided. Recenter point for best view.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 420
diff changeset
   281
  (when headword
6a772e1fc63d Add bracket for pronunciation if headword is provided. Recenter point for best view.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 420
diff changeset
   282
    (insert headword)
742
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   283
    (insert "\n  [")
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   284
    (if gadict-espeak-enabled
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   285
        (progn
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   286
          (insert (gadict-espeak-ipa headword gadict-espeak-default-voice))
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   287
          (insert "]")
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   288
          (when gadict-tr
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   289
            (search-forward ": ")))
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   290
      (insert "]")
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   291
      (backward-char))))
398
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   292
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   293
(defun gadict-search-floor (headword)
440
fb584cf490db Fix: very first word inserted in second position, should at first.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 435
diff changeset
   294
  "Move to HEADWORD definition or place on posiiton for new corresponding
fb584cf490db Fix: very first word inserted in second position, should at first.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 435
diff changeset
   295
definition. Check for headwords ordering during search.
398
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   296
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   297
Return `t' if definition found, `nil' if no such headword."
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   298
  (let ( prev curr )
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   299
    (catch 'exit
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   300
      (goto-char (point-min))
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   301
      (unless (re-search-forward "^__$" nil t)
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   302
        (throw 'exit nil))
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   303
      (forward-line 2)
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   304
      (setq prev (buffer-substring-no-properties (point) (line-end-position)))
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   305
      (when (string= headword prev)
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   306
        (throw 'exit t))
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   307
      (when (string< headword prev)
440
fb584cf490db Fix: very first word inserted in second position, should at first.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 435
diff changeset
   308
        (goto-char (point-min))
398
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   309
        (throw 'exit nil))
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   310
      (while t
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   311
        (unless (re-search-forward "^__$" nil t)
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   312
          (throw 'exit nil))
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   313
        (forward-line 2)
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   314
        (setq curr (buffer-substring-no-properties (point) (line-end-position)))
730
0ea3bcaae957 Allow duplication of consequent headwords to word around different
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 726
diff changeset
   315
        (when (string> prev curr)
398
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   316
          (error (format "%s < %s" curr prev)))
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   317
        (when (string= headword curr)
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   318
          (throw 'exit t))
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   319
        (when (string< headword curr)
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   320
          (forward-line -2)
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   321
          (re-search-backward "^__$")
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   322
          (forward-line 2)
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   323
          (throw 'exit nil))
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   324
        (setq prev curr)) )))
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   325
448
a61c140a4b6f Recenter screen to article on search request.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 444
diff changeset
   326
(defun gadict-search (headword)
a61c140a4b6f Recenter screen to article on search request.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 444
diff changeset
   327
  "Move to HEADWORD definition or place on posiiton for new corresponding
a61c140a4b6f Recenter screen to article on search request.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 444
diff changeset
   328
definition. Check for headwords ordering during search."
a61c140a4b6f Recenter screen to article on search request.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 444
diff changeset
   329
  (interactive (list (read-string "Headword: ")))
a61c140a4b6f Recenter screen to article on search request.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 444
diff changeset
   330
  (gadict-search-floor headword)
453
ad2b19c9d05d Fix: "recenter-top-bottom" => "recenter" to place view point at center of
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 448
diff changeset
   331
  (recenter))
448
a61c140a4b6f Recenter screen to article on search request.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 444
diff changeset
   332
398
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   333
(defun gadict-insert-template-in-order (headword)
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   334
  "Insert new article template with respect of headword order."
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   335
  (interactive (list (read-string "Headword: ")))
54ef571cf72a Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 395
diff changeset
   336
  (unless (gadict-search-floor headword)
435
ca2c73d8698f Recenter also if article is found.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 423
diff changeset
   337
    (gadict-insert-template headword))
453
ad2b19c9d05d Fix: "recenter-top-bottom" => "recenter" to place view point at center of
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 448
diff changeset
   338
  (recenter))
335
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
   339
652
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   340
(defun gadict--find-headword-end ()
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   341
  (save-excursion
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   342
    (end-of-line)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   343
    (re-search-backward "^__$")
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   344
    (re-search-forward "^$")
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   345
    (forward-char)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   346
    (re-search-forward "^$")
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   347
    (point)))
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   348
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   349
(defun gadict-insert-translation (pos)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   350
  "Insert translation template with using value of `gadict-tr'."
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   351
  (interactive (list (completing-read "POS: " gadict--pos nil t)))
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   352
  (let ( (headword-end (gadict--find-headword-end)) )
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   353
    (if (< (point) headword-end)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   354
        (goto-char headword-end)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   355
      (re-search-forward "^\\(?:\\|__\\)$")
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   356
      (when (eq (char-before) ?_)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   357
        (beginning-of-line)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   358
        ;; (newline)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   359
        ;; (backward-char)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   360
        ))
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   361
    (insert-char ?\n)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   362
    (insert pos)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   363
    (insert-char ?\n)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   364
    (save-excursion
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   365
      (mapc (lambda (lang)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   366
              (insert lang)
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   367
              (insert ": \n"))
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   368
            (split-string gadict-tr ",")))
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   369
    (end-of-line) ))
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   370
710
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   371
(defun gadict-nearest-headword ()
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   372
  "Return nearest headword looking upward."
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   373
  (save-excursion
714
ac5c3669ce32 Fix Warning: Unused lexical variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 712
diff changeset
   374
    (let ( (orig (point)) limit )
710
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   375
      (re-search-backward "^__$")
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   376
      (forward-line 1)
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   377
      (unless (and (eq (char-before) ?\n) (eq (char-after) ?\n))
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   378
        (error "Syntax error: there is not empty line after '__'..."))
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   379
      (forward-line 1)
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   380
      (when (< orig (point))
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   381
        (setq orig (point)))
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   382
      (setq limit (point))
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   383
      (re-search-forward "^$")
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   384
      (when (< orig (point))
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   385
        (goto-char orig)
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   386
        (end-of-line))
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   387
      (re-search-backward "^\\([^ ].*\\)$" limit)
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   388
      (match-string 1)
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   389
      )))
59bfd8195afa Initial code for displaying IPA pronunciation from espeak.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 652
diff changeset
   390
802
a812ec996022 Copy existing pronunciation of selected region or current word to `kill-ring'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 746
diff changeset
   391
(defun gadict-copy-pronunciation (&optional headword)
a812ec996022 Copy existing pronunciation of selected region or current word to `kill-ring'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 746
diff changeset
   392
  "Copy existing pronunciation of selected region or current word to `kill-ring'."
a812ec996022 Copy existing pronunciation of selected region or current word to `kill-ring'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 746
diff changeset
   393
  (interactive
a812ec996022 Copy existing pronunciation of selected region or current word to `kill-ring'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 746
diff changeset
   394
   (list (if (use-region-p)
803
13f5485d81c6 Fix: region-beginning / region-end are functions, not variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 802
diff changeset
   395
             (buffer-substring (region-beginning) (region-end))
802
a812ec996022 Copy existing pronunciation of selected region or current word to `kill-ring'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 746
diff changeset
   396
           (thing-at-point 'word))))
a812ec996022 Copy existing pronunciation of selected region or current word to `kill-ring'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 746
diff changeset
   397
  (save-excursion
a812ec996022 Copy existing pronunciation of selected region or current word to `kill-ring'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 746
diff changeset
   398
    (gadict-search-floor headword)
a812ec996022 Copy existing pronunciation of selected region or current word to `kill-ring'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 746
diff changeset
   399
    (when (search-forward-regexp "\\[\\([^]]+\\)]")
a812ec996022 Copy existing pronunciation of selected region or current word to `kill-ring'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 746
diff changeset
   400
      (kill-new (match-string 1)))))
a812ec996022 Copy existing pronunciation of selected region or current word to `kill-ring'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 746
diff changeset
   401
862
8ce278ad45d8 Added key binding to copy espeak content to kill-ring.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 803
diff changeset
   402
(defun gadict-copy-espeak-pronunciation (&optional headword)
8ce278ad45d8 Added key binding to copy espeak content to kill-ring.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 803
diff changeset
   403
  "Copy espeak pronunciation of selected region or current word to `kill-ring'."
8ce278ad45d8 Added key binding to copy espeak content to kill-ring.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 803
diff changeset
   404
  (interactive
8ce278ad45d8 Added key binding to copy espeak content to kill-ring.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 803
diff changeset
   405
   (list (if (use-region-p)
8ce278ad45d8 Added key binding to copy espeak content to kill-ring.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 803
diff changeset
   406
             (buffer-substring (region-beginning) (region-end))
8ce278ad45d8 Added key binding to copy espeak content to kill-ring.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 803
diff changeset
   407
           (thing-at-point 'word))))
8ce278ad45d8 Added key binding to copy espeak content to kill-ring.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 803
diff changeset
   408
  (kill-new (gadict-espeak-headline-line headword)))
8ce278ad45d8 Added key binding to copy espeak content to kill-ring.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 803
diff changeset
   409
366
98ac19478839 gadict-setup-keymap
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 365
diff changeset
   410
(defun gadict-setup-keymap ()
380
f0e2c538bf85 Add docs to functions to 100% satisfy checkdoc.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 379
diff changeset
   411
  "Setup gadict keymap."
652
fa97354a56d3 Insert translation template with using value of `gadict-tr'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 647
diff changeset
   412
  (define-key (current-local-map) [S-return] 'gadict-insert-translation)
802
a812ec996022 Copy existing pronunciation of selected region or current word to `kill-ring'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 746
diff changeset
   413
  (define-key (current-local-map) [C-return] 'gadict-insert-template-in-order)
a812ec996022 Copy existing pronunciation of selected region or current word to `kill-ring'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 746
diff changeset
   414
  (define-key (current-local-map) [C-S-return] 'gadict-search)
862
8ce278ad45d8 Added key binding to copy espeak content to kill-ring.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 803
diff changeset
   415
  (define-key (current-local-map) [M-return] 'gadict-copy-pronunciation)
8ce278ad45d8 Added key binding to copy espeak content to kill-ring.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 803
diff changeset
   416
  (define-key (current-local-map) [M-S-return] 'gadict-copy-espeak-pronunciation))
335
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
   417
320
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   418
;;;###autoload
361
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
   419
(define-derived-mode gadict-mode fundamental-mode "gadict"
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
   420
  "Derived mode for editing gadict dictionary source files."
371
d5d1d3e6d11e gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 370
diff changeset
   421
  (gadict-setup-fontlock)
366
98ac19478839 gadict-setup-keymap
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 365
diff changeset
   422
  (gadict-setup-keymap)
369
0f500491f990 Setup syntax table.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 368
diff changeset
   423
  (gadict-setup-syntax)
368
9c6515663b38 Define paragraph/page break at "__" delimiter.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 367
diff changeset
   424
  (gadict-setup-paragraph)
9c6515663b38 Define paragraph/page break at "__" delimiter.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 367
diff changeset
   425
  (gadict-setup-page)
374
aeaa3f721014 Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 373
diff changeset
   426
  (gadict-setup-comment)
382
9a596f1366ac Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 381
diff changeset
   427
  (gadict-setup-indent)
719
ebc16c3a9129 Enable gadict-espeak-ipa if "espeak" available in PATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 714
diff changeset
   428
  (gadict-setup-expansions)
ebc16c3a9129 Enable gadict-espeak-ipa if "espeak" available in PATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 714
diff changeset
   429
  (when (executable-find gadict-espeak-program)
742
5a5be84a113d If `gadict-espeak-enabled' is `t' pronunciation will be filled with espeak
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 730
diff changeset
   430
    (setq gadict-espeak-enabled t)
743
03065194ef59 Rename gadict-espeak-ipa => gadict-espeak-headline.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 742
diff changeset
   431
    (gadict-espeak-headline-enable)))
361
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
   432
6dee73a3e3cb Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 335
diff changeset
   433
(provide 'gadict)
320
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   434
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   435
;;; dict-mode.el ends here
375
a2ec98ead57a Fix warning from M-x checkdoc. Add lexical-binding: t.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 374
diff changeset
   436
a2ec98ead57a Fix warning from M-x checkdoc. Add lexical-binding: t.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 374
diff changeset
   437
(provide 'gadict)
a2ec98ead57a Fix warning from M-x checkdoc. Add lexical-binding: t.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 374
diff changeset
   438
a2ec98ead57a Fix warning from M-x checkdoc. Add lexical-binding: t.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 374
diff changeset
   439
;;; gadict.el ends here