contrib/gadict.el
changeset 743 03065194ef59
parent 742 5a5be84a113d
child 744 4d78dbc5a9b0
equal deleted inserted replaced
742:5a5be84a113d 743:03065194ef59
   308             gadict-espeak-program
   308             gadict-espeak-program
   309             gadict-espeak-program-ipa-args
   309             gadict-espeak-program-ipa-args
   310             (if (stringp voice) (concat "-v" (shell-quote-argument voice)) "")
   310             (if (stringp voice) (concat "-v" (shell-quote-argument voice)) "")
   311             (shell-quote-argument str)))))
   311             (shell-quote-argument str)))))
   312 
   312 
   313 (defun gadict-espeak-ipa-line (headword)
   313 (defun gadict-espeak-headline-line (headword)
   314   (mapconcat (lambda (voice) (format "%s: %s"
   314   (mapconcat (lambda (voice) (format "%s: %s"
   315                                 (propertize voice 'face '(:foreground "red"))
   315                                 (propertize voice 'face '(:foreground "red"))
   316                                 (gadict-espeak-ipa headword voice)))
   316                                 (gadict-espeak-ipa headword voice)))
   317              (if (listp gadict-espeak-voices-list) gadict-espeak-voices-list '(nil))
   317              (if (listp gadict-espeak-voices-list) gadict-espeak-voices-list '(nil))
   318              " | "))
   318              " | "))
   319 
   319 
   320 ;; (defun gadict-espeak-ipa-display ()
   320 ;; (defun gadict-espeak-headline-display ()
   321 ;;   (interactive)
   321 ;;   (interactive)
   322 ;;   (message (gadict-espeak-ipa-line)))
   322 ;;   (message (gadict-espeak-headline-line)))
   323 
   323 
   324 (defvar gadict-espeak-ipa-headword nil)
   324 (defvar gadict-espeak-headline-headword nil)
   325 
   325 
   326 (defun gadict-espeak-ipa-display ()
   326 (defun gadict-espeak-headline-display ()
   327   (when (eq major-mode 'gadict-mode)
   327   (when (eq major-mode 'gadict-mode)
   328     (let ( (headword (condition-case nil (gadict-nearest-headword) (error nil))) )
   328     (let ( (headword (condition-case nil (gadict-nearest-headword) (error nil))) )
   329       (unless (eq headword gadict-espeak-ipa-headword)
   329       (unless (eq headword gadict-espeak-headline-headword)
   330         (setq gadict-espeak-ipa-headword headword)
   330         (setq gadict-espeak-headline-headword headword)
   331         (setq header-line-format (if headword (gadict-espeak-ipa-line headword) nil))
   331         (setq header-line-format (if headword (gadict-espeak-headline-line headword) nil))
   332         (force-mode-line-update)))))
   332         (force-mode-line-update)))))
   333 
   333 
   334 (defvar gadict-espeak-ipa-timer nil)
   334 (defvar gadict-espeak-headline-timer nil)
   335 (defun gadict-espeak-ipa-enable ()
   335 (defun gadict-espeak-headline-enable ()
   336   (unless gadict-espeak-ipa-timer
   336   (unless gadict-espeak-headline-timer
   337     (setq gadict-espeak-ipa-timer (run-with-idle-timer 1 t #'gadict-espeak-ipa-display))))
   337     (setq gadict-espeak-headline-timer (run-with-idle-timer 1 t #'gadict-espeak-headline-display))))
   338 (defun gadict-espeak-ipa-disable ()
   338 (defun gadict-espeak-headline-disable ()
   339   (when gadict-espeak-ipa-timer
   339   (when gadict-espeak-headline-timer
   340     (cancel-timer gadict-espeak-ipa-timer))
   340     (cancel-timer gadict-espeak-headline-timer))
   341   (setq gadict-espeak-ipa-timer nil))
   341   (setq gadict-espeak-headline-timer nil))
   342 
   342 
   343 (defun gadict-setup-keymap ()
   343 (defun gadict-setup-keymap ()
   344   "Setup gadict keymap."
   344   "Setup gadict keymap."
   345   (define-key (current-local-map) [M-return] 'gadict-search)
   345   (define-key (current-local-map) [M-return] 'gadict-search)
   346   (define-key (current-local-map) [S-return] 'gadict-insert-translation)
   346   (define-key (current-local-map) [S-return] 'gadict-insert-translation)
   357   (gadict-setup-comment)
   357   (gadict-setup-comment)
   358   (gadict-setup-indent)
   358   (gadict-setup-indent)
   359   (gadict-setup-expansions)
   359   (gadict-setup-expansions)
   360   (when (executable-find gadict-espeak-program)
   360   (when (executable-find gadict-espeak-program)
   361     (setq gadict-espeak-enabled t)
   361     (setq gadict-espeak-enabled t)
   362     (gadict-espeak-ipa-enable)))
   362     (gadict-espeak-headline-enable)))
   363 
   363 
   364 (provide 'gadict)
   364 (provide 'gadict)
   365 
   365 
   366 ;;; dict-mode.el ends here
   366 ;;; dict-mode.el ends here
   367 
   367