Update packages

This commit is contained in:
Marcus Kammer 2020-02-14 23:09:34 +01:00
parent f3dcdf835e
commit 0ef9cab7b7
457 changed files with 3334 additions and 711 deletions

2
.gitignore vendored
View file

@ -13,3 +13,5 @@ elpy/rpc-venv/
.emacs.desktop
.emacs.desktop.lock
**/elpy/
/network-security.data
session.*

View file

@ -83,7 +83,7 @@
'(package-enable-at-startup t)
'(package-selected-packages
(quote
(org-pomodoro olivetti elm-mode dashboard pickle poet-theme flymake-eslint json-mode elpy darkroom dockerfile-mode ein spacemacs-theme flucui-themes leuven-theme htmlize scss-mode berrys-theme web-mode python-docstring sphinx-doc sphinx-frontend sphinx-mode ox-nikola racket-mode slime gherkin-mode powershell typescript-mode ob-http ob-ipython ob-restclient nord-theme restclient request restclient-test yaml-mode magit)))
(flymake-racket google-translate org-pomodoro olivetti elm-mode dashboard pickle poet-theme flymake-eslint json-mode elpy darkroom dockerfile-mode ein spacemacs-theme flucui-themes leuven-theme htmlize scss-mode berrys-theme web-mode python-docstring sphinx-doc sphinx-frontend sphinx-mode ox-nikola racket-mode slime gherkin-mode powershell typescript-mode ob-http ob-ipython ob-restclient nord-theme restclient request restclient-test yaml-mode magit)))
'(python-shell-interpreter "python3")
'(register-preview-delay 2)
'(register-separator 43)

View file

@ -1411,7 +1411,7 @@
(:maintainer "Michael Heerdegen" . "michael_heerdegen@web.de")
(:url . "https://github.com/michael-heerdegen/on-screen.el"))])
(org .
[(9 3 3)
[(9 3 6)
nil "Outline-based notes management and organizer" tar
((:url . "https://orgmode.org")
(:maintainer "Bastien Guerry" . "bzg@gnu.org")
@ -2271,7 +2271,7 @@
("Ivan Kanis" . "ivan@kanis.fr"))
(:maintainer "Ivan Kanis" . "ivan@kanis.fr"))])
(xclip .
[(1 9)
[(1 10)
nil "Copy&paste GUI clipboard from text terminal" single
((:url . "http://elpa.gnu.org/packages/xclip.html")
(:keywords "convenience" "tools")

View file

@ -1 +1 @@
Good signature from 066DAFCB81E42C40 GNU ELPA Signing Agent (2019) <elpasign@elpa.gnu.org> (trust undefined) created at 2020-02-08T11:05:02+0100 using RSA
Good signature from 066DAFCB81E42C40 GNU ELPA Signing Agent (2019) <elpasign@elpa.gnu.org> (trust undefined) created at 2020-02-14T11:05:02+0100 using RSA

View file

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 43 KiB

View file

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View file

@ -1,4 +1,4 @@
(define-package "dashboard" "20200121.1429" "A startup screen extracted from Spacemacs"
(define-package "dashboard" "20200214.525" "A startup screen extracted from Spacemacs"
'((emacs "25.3")
(page-break-lines "0.11"))
:keywords

View file

@ -91,6 +91,21 @@ to the specified width, with aspect ratio preserved."
:type 'boolean
:group 'dashboard)
(defcustom dashboard-footer-messages
'("The one true editor, Emacs!"
"Who the hell uses VIM anyway? Go Evil!"
"Free as free speech, free as free Beer"
"Richard Stallman is proud of you"
"Happy coding!"
"Vi Vi Vi, the editor of the beast"
"Welcome to the church of Emacs"
"While any text editor can save your files,\
only Emacs can save your soul"
"I showed you my source code,pls respond")
"A list of messages, one of which dashboard chooses to display."
:type 'list
:group 'dashboard)
(defcustom dashboard-show-shortcuts t
"Whether to show shortcut keys for each section."
:type 'boolean
@ -532,7 +547,7 @@ WIDGET-PARAMS are passed to the \"widget-create\" function."
((string-equal ,section-name "Agenda for today:")
(all-the-icons-octicon "primitive-dot" :height 1.0 :v-adjust 0.01))
((file-remote-p path)
(all-the-icons-octicon "radio-tower" :height 1.1 :v-adjust 0.01))
(all-the-icons-octicon "radio-tower" :height 1.0 :v-adjust 0.01))
(t (all-the-icons-icon-for-file (file-name-nondirectory path)))))))
(setq tag (concat icon " " ,@rest))))
@ -547,15 +562,20 @@ WIDGET-PARAMS are passed to the \"widget-create\" function."
,list)))
;; Footer
(defun dashboard-random-footer ()
"Return a random footer from `dashboard-footer-messages'."
(nth (random (length dashboard-footer-messages)) dashboard-footer-messages))
(defun dashboard-insert-footer ()
"Insert footer of dashboard."
(when dashboard-set-footer
(let ((footer (and dashboard-set-footer (dashboard-random-footer))))
(when footer
(insert "\n")
(dashboard-center-line dashboard-footer)
(dashboard-center-line footer)
(insert dashboard-footer-icon)
(insert " ")
(insert (propertize dashboard-footer 'face 'dashboard-footer))
(insert "\n")))
(insert (propertize footer 'face 'dashboard-footer))
(insert "\n"))))
;;
;; Recentf

View file

@ -0,0 +1,33 @@
;;; flymake-racket-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (directory-file-name
(or (file-name-directory #$) (car load-path))))
;;;### (autoloads nil "flymake-racket" "flymake-racket.el" (0 0 0
;;;;;; 0))
;;; Generated autoloads from flymake-racket.el
(autoload 'flymake-racket-setup "flymake-racket" "\
Set up Flymake for Racket.
\(fn)" t nil)
(autoload 'flymake-racket-add-hook "flymake-racket" "\
Add `flymake-racket-lint' to `flymake-diagnostic-functions'.
\(fn)" nil nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "flymake-racket" '("flymake-racket-")))
;;;***
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; coding: utf-8
;; End:
;;; flymake-racket-autoloads.el ends here

View file

@ -0,0 +1,2 @@
;;; -*- no-byte-compile: t -*-
(define-package "flymake-racket" "20180912.109" "Flymake extension for Racket." '((emacs "26.1")) :commit "d20fa60d66db3f7c2df0133814564ee5b36d2aba" :keywords '("languages" "racket" "scheme") :maintainer '("James Nguyen" . "james@jojojames.com") :url "https://github.com/jojojames/flymake-racket")

View file

@ -0,0 +1,235 @@
;;; flymake-racket.el --- Flymake extension for Racket. -*- lexical-binding: t -*-
;; Copyright (C) 2018 James Nguyen
;; Authors: James Nguyen <james@jojojames.com>
;; Maintainer: James Nguyen <james@jojojames.com>
;; URL: https://github.com/jojojames/flymake-racket
;; Package-Version: 20180912.109
;; Version: 1.0
;; Package-Requires: ((emacs "26.1"))
;; Keywords: languages racket scheme
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Flymake extension for Racket.
;;
;; (with-eval-after-load 'flymake
;; (flymake-racket-setup))
;;; Code:
(require 'flymake)
(require 'cl-lib)
(eval-when-compile (require 'subr-x))
;;; Flymake
(defcustom flymake-racket-executable "raco"
"Executable for racket."
:type 'string
:group 'flymake-racket)
(defcustom flymake-racket-args '("expand")
"Args to pass to racket."
:type 'list
:group 'flymake-racket)
(defvar-local flymake-racket--lint-process nil
"Buffer-local process started for linting the buffer.")
(defvar flymake-racket-raco-has-expand-p nil
"Boolean to check if `flymake-racket-executable' contains expand.")
;;;###autoload
(defun flymake-racket-setup ()
"Set up Flymake for Racket."
(interactive)
(add-hook 'racket-mode-hook #'flymake-racket-add-hook)
(add-hook 'scheme-mode-hook #'flymake-racket-add-hook))
;;;###autoload
(defun flymake-racket-add-hook ()
"Add `flymake-racket-lint' to `flymake-diagnostic-functions'."
;; Checking if raco expand exists is really slow (200ms~), so
;; try to do it using the `async' library.
(if (and (fboundp 'async-start)
(eq flymake-racket-raco-has-expand-p nil))
(let ((buffer (current-buffer)))
(async-start
`(lambda ()
(load ,(locate-library "flymake-racket"))
(require 'flymake-racket)
(flymake-racket--check-shell-raco-expand))
`(lambda (result)
(setq flymake-racket-raco-has-expand-p (if result 'yes 'no))
(with-current-buffer ,buffer
(flymake-racket-add-hook)
;; Because we did this asynchronously, we should explicitly
;; start a syntax check.. but only if `flymake-start-on-flymake-mode'
;; is t.
(when flymake-start-on-flymake-mode
(flymake-start))))))
(when (flymake-racket--raco-has-expand)
(add-hook 'flymake-diagnostic-functions
'flymake-racket-lint-if-possible nil t))))
(defun flymake-racket-lint-if-possible (report-fn &rest args)
"Run `flymake-racket-lint' if possible.
REPORT-FN is called when `flymake-racket-lint' runs.
ARGS is passed straight through to `flymake-racket-lint'."
(when (or
(eq major-mode 'racket-mode)
(and (eq major-mode 'scheme-mode)
(boundp 'geiser-impl--implementation)
(eq geiser-impl--implementation 'racket)))
(apply #'flymake-racket-lint report-fn args)))
(defun flymake-racket-lint (report-fn &rest _args)
"A Flymake backend for racket check.
REPORT-FN will be called when racket process finishes."
(when (and flymake-racket--lint-process
(process-live-p flymake-racket--lint-process))
(kill-process flymake-racket--lint-process))
(let ((source-buffer (current-buffer))
(output-buffer (generate-new-buffer " *flymake-racket-lint*")))
(setq flymake-racket--lint-process
(make-process
:name "flymake-racket-lint"
:buffer output-buffer
:command `(,flymake-racket-executable
,@flymake-racket-args
,buffer-file-name)
:connection-type 'pipe
:sentinel
(lambda (proc _event)
(when (eq (process-status proc) 'exit)
(unwind-protect
(cond
((not (and (buffer-live-p source-buffer)
(eq proc (with-current-buffer source-buffer
flymake-racket--lint-process))))
(flymake-log :warning
"racket process %s obsolete" proc))
((zerop (process-exit-status proc))
;; No racket errors/warnings..
(funcall report-fn nil))
((= 1 (process-exit-status proc))
(flymake-racket--lint-done report-fn
source-buffer
output-buffer))
(:error
(funcall report-fn
:panic
:explanation
(format "racket process %s errored." proc))))
(kill-buffer output-buffer))))))))
;; Helpers
(defun flymake-racket--lint-done (report-fn
source-buffer
output-buffer)
"Process racket result and call REPORT-FN.
SOURCE-BUFFER is the buffer to apply flymake to.
OUTPUT-BUFFER is the result of running racket on SOURCE-BUFFER."
(with-current-buffer
source-buffer
(save-excursion
(save-restriction
(widen)
(funcall
report-fn
(with-current-buffer output-buffer
(let* ((result '()) ;; Accumulate results here.
(lines (split-string (buffer-string) "\n" t))
(numLines (length lines))
(i 0)
(source-buffer-name
(with-current-buffer source-buffer
(file-name-nondirectory buffer-file-name))))
;; Example error message:
;; racket_file.rkt:24:0: read-syntax: expected a `)` to close `(`
;; possible cause: indentation suggests a missing `)` before line 34
(while (< i numLines)
;; Filter out messages that don't match buffer name.
(when (string-prefix-p source-buffer-name (nth i lines))
(let* ((line (nth i lines))
(split (split-string line ":" t))
(_ (nth 0 split)) ; filename
(line (string-to-number (nth 1 split)))
(column (string-to-number (nth 2 split)))
(message (mapconcat (lambda (str) str)
(cdddr split)
""))
(point (flymake-racket--find-point
source-buffer
line
column)))
(when (and (< (1+ i) numLines)
(string-match-p "possible cause"
(nth (1+ i) lines)))
(setq message (concat message "\n" (nth (1+ i) lines)))
;; Skip next line when processing.
(setq i (1+ i)))
;; Accumulate the result.
(push (flymake-make-diagnostic source-buffer
point
(1+ point)
:warning
message)
result)))
(setq i (1+ i)))
result)))))))
(defun flymake-racket--find-point (source-buffer line column)
"Return point given LINE and COLUMN in SOURCE-BUFFER."
(with-current-buffer source-buffer
(save-excursion
(goto-char (point-min))
(forward-line (1- line))
(move-to-column column)
(point))))
(defun flymake-racket--raco-has-expand ()
"Check if raco has expand."
(cond
((eq flymake-racket-raco-has-expand-p 'yes) t)
((eq flymake-racket-raco-has-expand-p 'no) nil)
(:default
(setq flymake-racket-raco-has-expand-p
(flymake-racket--check-shell-raco-expand))
(if flymake-racket-raco-has-expand-p
(setq flymake-racket-raco-has-expand-p 'yes)
(setq flymake-racket-raco-has-expand-p 'no))
(flymake-racket--raco-has-expand))))
(defun flymake-racket--check-shell-raco-expand ()
"Check if raco has expand using `call-process'."
(with-temp-buffer
(call-process flymake-racket-executable nil t nil "expand")
(goto-char (point-min))
(not (looking-at-p
(rx bol (1+ not-newline)
"Unrecognized command: expand"
eol)))))
(provide 'flymake-racket)
;;; flymake-racket.el ends here

Binary file not shown.

View file

@ -0,0 +1,10 @@
((:files
("google-translate.el"
"google-translate-core.el"
"google-translate-tk.el"
"google-translate-core-ui.el"
"google-translate-default-ui.el"
"google-translate-pkg.el"
"google-translate-smooth-ui.el"
"Makefile"))
(:current-version "0.11.18"))

Binary file not shown.

View file

@ -0,0 +1,151 @@
;;; google-translate-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (directory-file-name
(or (file-name-directory #$) (car load-path))))
;;;### (autoloads nil "google-translate-backend" "google-translate-backend.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from google-translate-backend.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "google-translate-backend" '("google-translate-backend-")))
;;;***
;;;### (autoloads nil "google-translate-core" "google-translate-core.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from google-translate-core.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "google-translate-core" '("google-translate-")))
;;;***
;;;### (autoloads nil "google-translate-core-ui" "google-translate-core-ui.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from google-translate-core-ui.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "google-translate-core-ui" '("gtos" "google-translate-")))
;;;***
;;;### (autoloads nil "google-translate-default-ui" "google-translate-default-ui.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from google-translate-default-ui.el
(autoload 'google-translate-query-translate "google-translate-default-ui" "\
Interactively translate text with Google Translate.
Query a text (a word or a phrase), and pop up a buffer named *Google
Translate* displaying available translations of the text.
If no defaults for the source and target languages are specified (by
setting the variables `google-translate-default-source-language' and
`google-translate-default-target-language'), interactively query the
missing parts. For example, a reasonable option may be to specify a
default for the target language and always be queried for the source
language.
With a `C-u' prefix argument, query the source and target languages,
even if any defaults are specified. For example, you may frequently
need to translate from English to Russian, and you may choose to set
the default source and target languages to \"en\" and \"ru\", resp.
However, occasionally you may also need to translate from Russian to
English. With a `C-u' prefix argument you can override the defaults
and specify the source and target languages explicitly.
The languages are queried with completion, and the null input at the
source language prompt is considered as an instruction for Google
Translate to detect the source language.
\(fn &optional OVERRIDE-P)" t nil)
(autoload 'google-translate-query-translate-reverse "google-translate-default-ui" "\
Like `google-translate-query-translate', but performs translation
in the reverse direction.
The value of the variable `google-translate-default-source-language'
\(if set) becomes the target language, and the value of the variable
`google-translate-default-target-language' (if also set) becomes the
source language.
In particular, when both variables are set, translation is performed
in the reverse direction.
\(fn &optional OVERRIDE-P)" t nil)
(autoload 'google-translate-at-point "google-translate-default-ui" "\
Translate the word at point or the words in the active region.
For the meaning of OVERRIDE-P, see `google-translate-query-translate'.
\(fn &optional OVERRIDE-P)" t nil)
(autoload 'google-translate-at-point-reverse "google-translate-default-ui" "\
Like `google-translate-at-point', but performs translation in the
reverse direction.
\(fn &optional OVERRIDE-P)" t nil)
(autoload 'google-translate-buffer "google-translate-default-ui" "\
Translate current buffer.
For the meaning of OVERRIDE-P, see `google-translate-query-translate'.
\(fn &optional OVERRIDE-P REVERSE-P)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "google-translate-default-ui" '("%google-translate-" "google-translate-")))
;;;***
;;;### (autoloads nil "google-translate-smooth-ui" "google-translate-smooth-ui.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from google-translate-smooth-ui.el
(autoload 'google-translate-smooth-translate "google-translate-smooth-ui" "\
Translate a text using translation directions.
Make a prompt in minibuffer for a text to translate. Default text
is word at point.
In case of `google-translate-translation-directions-alist' is
empty list then after inputed translating text prompts for source
language and then for target languages.
In case of `google-translate-translation-directions-alist' is not
empty list takes current translation direction and makes
appropriate translation. Current translation direction indicates
in the minibuffers' prompt.
A current translation direction could be changed directly in the
minibuffer by means of key bindings such as C-n and C-p for
changing to the next translation direction and to the previous
one respectively.
\(fn)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "google-translate-smooth-ui" '("google-translate-")))
;;;***
;;;### (autoloads nil "google-translate-tk" "google-translate-tk.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from google-translate-tk.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "google-translate-tk" '("google-translate--")))
;;;***
;;;### (autoloads nil nil ("google-translate-pkg.el" "google-translate.el")
;;;;;; (0 0 0 0))
;;;***
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; coding: utf-8
;; End:
;;; google-translate-autoloads.el ends here

View file

@ -0,0 +1,142 @@
;;; google-translate-backend.el --- Backend methods for url retrieve.
;; Copyright (C) 2019 Tomotaka SUWA <tomotaka.suwa@gmail.com>
;; Author: Oleksandr Manzyuk <manzyuk@gmail.com>
;; Maintainer: Andrey Tykhonov <atykhonov@gmail.com>
;; URL: https://github.com/atykhonov/google-translate
;; Version: 0.11.17
;; Keywords: convenience
;; This file is NOT part of GNU Emacs.
;; This is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Provide backend facilities to cope with google translate.
;;; Code:
(defvar google-translate-backend-method 'emacs
"The backend method for URL retrieve.
Valid symbols are below:
- emacs: use built in `url-retrieve-synchronously'
- curl: invoke curl command
- wget: invoke wget command
and any other keys of `google-translate-backend-commands'.")
(defvar google-translate-backend-user-agent "Emacs"
"The user agent string for HTTP request header.")
(defvar google-translate-backend-commands
'((curl :args ("-s" "-L" "-A"))
(wget :args ("-q" "-O" "-" "-U")))
"An alist of external program specifications.
The form of each element is (KEY P-LIST). The variable
`google-translate-backend-method' may have one of KEYs and is
used for determine the command to execute. The P-LIST of each
element represents command specific information.
Available properties:
- Property `:name': the program name(optional)
- Property `:args': a list of arguments passed to the program
If you omit the `:name' property, (symbol-name KEY) will be used
as the program name. The `:args' property must be composed to
satisfy all the following conditions:
- Output content to standard output
- Suppress non-content(HTTP headers, progress messages, etc)
- Handle location response header
- Place User-Agent option at last
So if you would like to use another program \"foo\", for example:
\(push \\='(foo :name \"foo-x86\"
:args (\"-q\" \"--agent\"))
google-translate-backend-commands)
\(setq google-translate-backend-method \\='foo)
And the command line looks like:
foo-x86 -q --agent ['google-translate-backend-user-agent] [URL]")
(defvar google-translate-backend-debug nil
"Non-nil means log http activities to the *google-translate-debug* buffer.")
(defun google-translate-backend--log (&rest args)
"Log http activities to the *google-translate-debug* buffer along with ARGS.
Disabled if `google-translate-backend-debug' is nil."
(when google-translate-backend-debug
(let ((message (mapconcat 'identity
(list (current-time-string)
(prin1-to-string args)
"-- begin --"
(buffer-string)
"-- end --")
"\n")))
(with-current-buffer
(get-buffer-create "*google-translate-backend-debug*")
(goto-char (point-max))
(insert message)
(newline)))))
(defun google-translate-backend--emacs (url)
"Get URL contents by `url-retrieve-synchronously'."
(insert
(let ((url-user-agent google-translate-backend-user-agent))
(with-current-buffer (url-retrieve-synchronously url)
(set-buffer-multibyte t)
(google-translate-backend--log url 'emacs)
(goto-char (point-min))
(re-search-forward "\n\n")
(prog1 (buffer-substring (point)
(point-max))
(kill-buffer))))))
(defun google-translate-backend--process (url key spec)
"Get URL contents by `call-process'.
\(KEY SPEC) would be exist in `google-translate-backend-commands'."
(let ((name (or (plist-get spec :name)
(symbol-name key)))
(args (plist-get spec :args))
(agent google-translate-backend-user-agent))
(apply 'call-process
(append (list name nil t nil)
args
(list agent url)))
(google-translate-backend--log url key spec)))
(defun google-translate-backend-retrieve (url)
"Get URL contents via `google-translate-backend-method'."
(let ((method google-translate-backend-method))
(if (eq method 'emacs)
(google-translate-backend--emacs url)
(let ((spec (cdr (assq method
google-translate-backend-commands))))
(if (null spec)
(error "Unknown backend method: %s" method)
(google-translate-backend--process url method spec))))))
(provide 'google-translate-backend)
;;; google-translate-backend.el ends here

View file

@ -0,0 +1,848 @@
;;; google-translate-core-ui.el --- google translate core UI
;; Copyright (C) 2012 Oleksandr Manzyuk <manzyuk@gmail.com>
;; Author: Oleksandr Manzyuk <manzyuk@gmail.com>
;; Maintainer: Andrey Tykhonov <atykhonov@gmail.com>
;; URL: https://github.com/atykhonov/google-translate
;; Version: 0.11.18
;; Keywords: convenience
;; Contributors:
;; Tassilo Horn <tsdh@gnu.org>
;; Bernard Hurley <bernard@marcade.biz>
;; Chris Bilson <cbilson@pobox.com>
;; Takumi Kinjo <takumi.kinjo@gmail.com>
;; momomo5717 <momomo5717@gmail.com>
;; This file is NOT part of GNU Emacs.
;; This is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This script provides the most common functions and variables for
;; UI. It does not contain any interactive functions and overall is
;; not going to be used directly by means of
;; `execute-extended-command' (M-x). Its purpose to provide the most
;; valuable and useful functionality for packages and scripts which
;; provide UI.
;;
;; The most important functions are the following:
;;
;; - `google-translate-translate'
;;
;; - `google-translate-read-source-language'
;;
;; - `google-translate-read-target-language'
;;
;; `google-translate-translate' translates the given text from source
;; language to target language and shows a translation.
;;
;; `google-translate-read-source-language' reads source language from
;; minibuffer and returns language
;; abbreviation. `google-translate-read-target-language' reads target
;; language from minibuffer and returns language abbreviation.
;; Customization:
;; You can customize the following variables:
;;
;; - `google-translate-output-destination'
;;
;; - `google-translate-enable-ido-completion'
;;
;; - `google-translate-show-phonetic'
;;
;; - `google-translate-listen-program'
;;
;; - `google-translate-pop-up-buffer-set-focus'
;;
;; - `google-translate-preferable-input-methods-alist'
;;
;; `google-translate-output-destination' determines translation output
;; destination. If `nil' the translation output will be displayed in
;; the pop up buffer. If value equal to `echo-area' then translation
;; outputs in the Echo Area. In case of `popup' the translation
;; outputs to the popup tooltip using `popup' package. In case of
;; `kill-ring' the translation outputs to the kill ring. And in case
;; of `current-buffer' the translation outputs to the current
;; buffer. If you would like output translation to the Echo Area you
;; would probably like to increase it because only part of translation
;; could visible there with the default settings. To increase Echo
;; Area you could increase the value of `max-mini-window-height'
;; variable, for example: `(setq max-mini-window-height 0.5)'.
;;
;; If `google-translate-enable-ido-completion' is non-NIL, the input
;; will be read with ido-style completion.
;;
;; The variable `google-translate-show-phonetic' controls whether the
;; phonetic spelling of the original text and its translation is
;; displayed if available. If you want to see the phonetics, set this
;; variable to t.
;;
;; The variable `google-translate-listen-program' determines the
;; program to use to listen translations. By default the program looks
;; for `mplayer' in the PATH, if `mplayer' is found then listening
;; function will be available and you'll see `Listen' button in the
;; buffer with the translation. You can use any other suitable
;; program. If you use Windows please download and unpack `mplayer'
;; and add its path (directory) to the system PATH variable. Please
;; note that translation listening is not available if
;; `google-translate-output-destination' is set to `echo-area' or
;; `popup'.
;;
;; The variable `google-translate-pop-up-buffer-set-focus' determines
;; whether window (buffer) with translation gets focus when it pop
;; ups. If `nil', it doesn't get focus and focus remains in the same
;; window as was before translation. If `t', window (buffer with
;; translation) gets focus. Please note that that setting works only
;; for pop up buffer, i.e. when `google-translate-output-destination'
;; is `nil'.
;;
;; The `google-translate-input-method-auto-toggling' variable
;; determines whether input method auto toggling is enabled or not.
;;
;; While switching among languages I noticed that I change input
;; method quite often. Input method auto toggling allows switch on
;; appropriate input method while switching among languages. Auto
;; toggling will work in case of
;; `google-translate-input-method-auto-toggling' is set to `t' and
;; `google-translate-preferable-input-methods-alist' is defined
;; properly.
;;
;; This variable may be defined as follow (just for example):
;;
;; (setq google-translate-preferable-input-methods-alist '((nil . ("en"))
;; (ukrainian-programmer-dvorak . ("ru" "uk"))))
;;
;; In this way, input method is disabled (because of nil) for the
;; minibuffer when source language is English. And
;; "ukrainian-programmer-dvorak" input method is enabled when source
;; language is Russian or Ukrainian.
;; Customization of faces:
;; - `google-translate-text-face', used to display the original text
;; (defaults to `default')
;;
;; - `google-translate-phonetic-face', used to display the phonetics
;; (defaults to `shadow')
;;
;; - `google-translate-translation-face', used to display the highest
;; ranking translation (defaults to `default' with the `weight'
;; attribute set to `bold')
;;
;; - `google-translate-suggestion-label-face' used to display the
;; label for suggestion (defaults to `default' with the `foreground'
;; attribute set to `red')
;;
;; - `google-translate-suggestion-face' used to display the suggestion
;; in case of word is misspelled (defaults to `default' with the
;; `slant' attribute set to `italic' and `underline' attribute set
;; to `t')
;;
;; - `google-translate-listen-button-face' used to display the "Listen"
;; button (defaults to `height' 0.8).
;;
;; For example, to show the translation in a larger font change the
;; `height' attribute of the face `google-translate-translation-face'
;; like so:
;;
;; (set-face-attribute 'google-translate-translation-face nil :height 1.4)
;;
;;
;;; Code:
;;
(eval-when-compile (require 'cl))
(require 'google-translate-core)
(require 'ido)
(defvar google-translate-supported-languages-alist
'(("Afrikaans" . "af")
("Albanian" . "sq")
("Amharic" . "am")
("Arabic" . "ar")
("Armenian" . "hy")
("Azerbaijani" . "az")
("Basque" . "eu")
("Belarusian" . "be")
("Bengali" . "bn")
("Bosnian" . "bs")
("Bulgarian" . "bg")
("Catalan" . "ca")
("Cebuano" . "ceb")
("Chichewa" . "ny")
("Chinese Simplified" . "zh-CN")
("Chinese Traditional" . "zh-TW")
("Corsican" . "co")
("Croatian" . "hr")
("Czech" . "cs")
("Danish" . "da")
("Dutch" . "nl")
("English" . "en")
("Esperanto" . "eo")
("Estonian" . "et")
("Filipino" . "tl")
("Finnish" . "fi")
("French" . "fr")
("Frisian" . "fy")
("Galician" . "gl")
("Georgian" . "ka")
("German" . "de")
("Greek" . "el")
("Gujarati" . "gu")
("Haitian Creole" . "ht")
("Hausa" . "ha")
("Hawaiian" . "haw")
("Hebrew" . "iw")
("Hindi" . "hi")
("Hmong" . "hmn")
("Hungarian" . "hu")
("Icelandic" . "is")
("Igbo" . "ig")
("Indonesian" . "id")
("Irish" . "ga")
("Italian" . "it")
("Japanese" . "ja")
("Javanese" . "jw")
("Kannada" . "kn")
("Kazakh" . "kk")
("Khmer" . "km")
("Korean" . "ko")
("Kurdish (Kurmanji)" . "ku")
("Kyrgyz" . "ky")
("Lao" . "lo")
("Latin" . "la")
("Latvian" . "lv")
("Lithuanian" . "lt")
("Luxembourgish" . "lb")
("Macedonian" . "mk")
("Malagasy" . "mg")
("Malay" . "ms")
("Malayalam" . "ml")
("Maltese" . "mt")
("Maori" . "mi")
("Marathi" . "mr")
("Mongolian" . "mn")
("Myanmar (Burmese)" . "my")
("Nepali" . "ne")
("Norwegian" . "no")
("Pashto" . "ps")
("Persian" . "fa")
("Polish" . "pl")
("Portuguese" . "pt")
("Punjabi" . "pa")
("Romanian" . "ro")
("Russian" . "ru")
("Samoan" . "sm")
("Scots Gaelic" . "gd")
("Serbian" . "sr")
("Sesotho" . "st")
("Shona" . "sn")
("Sindhi" . "sd")
("Sinhala" . "si")
("Slovak" . "sk")
("Slovenian" . "sl")
("Somali" . "so")
("Spanish" . "es")
("Sundanese" . "su")
("Swahili" . "sw")
("Swedish" . "sv")
("Tajik" . "tg")
("Tamil" . "ta")
("Telugu" . "te")
("Thai" . "th")
("Turkish" . "tr")
("Ukrainian" . "uk")
("Urdu" . "ur")
("Uzbek" . "uz")
("Vietnamese" . "vi")
("Welsh" . "cy")
("Xhosa" . "xh")
("Yiddish" . "yi")
("Yoruba" . "yo")
("Zulu" . "zu"))
"Alist of the languages supported by Google Translate.
Each element is a cons-cell of the form (NAME . CODE), where NAME
is a human-readable language name and CODE is its code used as a
query parameter in HTTP requests.")
(defvar google-translate-translation-listening-debug nil
"For debug translation listening purposes.")
(defstruct gtos
"google translate output structure contains miscellaneous
information which intended to be outputed to the buffer, echo
area or popup tooltip."
source-language target-language text
auto-detected-language text-phonetic translation
translation-phonetic detailed-translation suggestion detailed-definition)
(defgroup google-translate-core-ui nil
"Emacs core UI script for the Google Translate package."
:group 'processes)
(defcustom google-translate-enable-ido-completion nil
"If non-NIL, use `ido-completing-read' rather than
`completing-read' for reading input."
:group 'google-translate-core-ui
:type '(choice (const :tag "No" nil)
(other :tag "Yes" t)))
(defcustom google-translate-show-phonetic nil
"If non-NIL, try to show the phonetic spelling."
:group 'google-translate-core-ui
:type '(choice (const :tag "No" nil)
(const :tag "Yes" t)))
(defcustom google-translate-listen-program
(executable-find "mplayer")
"The program to use to listen translations. By default the
program looks for `mplayer' in the PATH, if `mplayer' is found
then listening function will be available and you'll see `Listen'
button in the buffer with the translation. You can use any other
suitable program."
:group 'google-translate-core-ui
:type '(string))
(defcustom google-translate-output-destination
nil
"Determines where translation output will be displayed. If
`nil' the translation output will be displayed in the pop up
buffer (default). If value equals to `echo-area' then translation
outputs in the Echo Area. And in case of `popup' the translation
outputs to the popup tooltip using `popup' package."
:group 'google-translate-core-ui
:type '(symbol))
(defcustom google-translate-pop-up-buffer-set-focus
nil
"Determines whether window (buffer) with translation gets focus
when it pop ups. If `nil', it doesn't get focus and focus remains
in the same window as was before translation. If `t',
window (buffer with translation) gets focus.")
(defcustom google-translate-listen-button-label
"[Listen]"
"Label of the 'Listen' button."
:group 'google-translate-core-ui
:type 'string)
(defface google-translate-text-face
'((t (:inherit default)))
"Face used to display the original text."
:group 'google-translate-core-ui)
(defface google-translate-phonetic-face
'((t (:inherit shadow)))
"Face used to display the phonetic spelling."
:group 'google-translate-core-ui)
(defface google-translate-translation-face
'((t (:weight bold)))
"Face used to display the probable translation."
:group 'google-translate-core-ui)
(defface google-translate-suggestion-label-face
'((t (:foreground "red")))
"Face used to display the suggestion label."
:group 'google-translate-core-ui)
(defface google-translate-suggestion-face
'((t (:slant italic :underline t)))
"Face used to display the suggestion."
:group 'google-translate-core-ui)
(defface google-translate-listen-button-face
'((t (:inherit button :height 0.8)))
"Face used to display button \"Listen\"."
:group 'google-translate-core-ui)
(defvar google-translate-input-method-auto-toggling nil
"When `t' the current source language is compared with the
values from `google-translate-preferable-input-methods-alist' and
enables appropriate input method for the minibuffer. So this
feature may allow to avoid switching between input methods while
translating using different languages.")
(defvar google-translate-preferable-input-methods-alist
'((nil . nil))
"Alist of preferable input methods for certain languages.
Each element is a cons-cell of the form (INPUT-METHOD
. LANGUAGES-LIST), where INPUT-METHOD is the input method which
will be switched on, when translation source language equals to
one of the language from the LANGUAGE-LIST.
INPUT-METHOD could be specified as nil. In such case input method
disables.
As example, this alist could looks like the following:
'((nil . \"en\")
(ukrainian-programmer-dvorak . (\"ru\" \"uk\")))
In this way, `ukrainian-programmer-dvorak' will be auto enabled
for the minibuffer when Russian or Ukrainian (as source language)
is active.")
(defun google-translate-supported-languages ()
"Return a list of names of languages supported by Google Translate."
(mapcar #'car google-translate-supported-languages-alist))
(defun google-translate-language-abbreviation (language)
"Return the abbreviation of LANGUAGE."
(if (string-equal language "Detect language")
"auto"
(cdr (assoc language google-translate-supported-languages-alist))))
(defun google-translate-language-display-name (abbreviation)
"Return a name suitable for use in prompts of the language whose
abbreviation is ABBREVIATION."
(if (string-equal abbreviation "auto")
"unspecified language"
(car (rassoc abbreviation google-translate-supported-languages-alist))))
(defun google-translate-paragraph (text face &optional output-format)
"Return TEXT as a filled paragraph into the current buffer and
apply FACE to it. Optionally use OUTPUT-FORMAT."
(let ((beg (point))
(output-format
(if output-format output-format "\n%s\n")))
(with-temp-buffer
(insert (format output-format text))
(facemenu-set-face face beg (point))
(fill-region beg (point))
(buffer-substring (point-min) (point-max)))))
(defun google-translate-setup-preferable-input-method (source-language)
"Set input method which takes from the value of
`google-translate-preferable-input-methods-alist' variable."
(interactive)
(let* ((preferable-input-method
(google-translate-find-preferable-input-method source-language)))
(set-input-method preferable-input-method)))
(defun google-translate-find-preferable-input-method (source-language)
"Look for the SOURCE-LANGUAGE in the
`google-translate-preferable-input-methods-alist' and return
input method for it."
(let ((input-method nil))
(dolist (item google-translate-preferable-input-methods-alist)
(dolist (language (cdr item))
(when (string-equal source-language language)
(setq input-method (car item)))))
input-method))
(defun google-translate--translation-title (gtos format)
"Return translation title which contains information about used
source and target languages."
(let ((source-language (gtos-source-language gtos))
(target-language (gtos-target-language gtos))
(auto-detected-language (gtos-auto-detected-language gtos)))
(format format
(if (string-equal source-language "auto")
(format "%s (detected)"
(google-translate-language-display-name
auto-detected-language))
(google-translate-language-display-name
source-language))
(google-translate-language-display-name
target-language))))
(defun google-translate--translating-text (gtos format)
"Outputs in buffer translating text."
(let ((text (gtos-text gtos)))
(let ((output-format format))
(google-translate-paragraph
text
'google-translate-text-face
output-format))))
(defun google-translate--text-phonetic (gtos format)
"Outputs in buffer text phonetic in case of
`google-translate-show-phonetic' is set to t."
(let ((text-phonetic (gtos-text-phonetic gtos)))
(if (and google-translate-show-phonetic
(not (string-equal text-phonetic "")))
(google-translate-paragraph
text-phonetic
'google-translate-phonetic-face
format)
"")))
(defun google-translate--translated-text (gtos format)
"Output in buffer translation."
(let ((translation (gtos-translation gtos)))
(google-translate-paragraph
translation
'google-translate-translation-face
format)))
(defun google-translate--translation-phonetic (gtos format)
"Output in buffer translation phonetic in case of
`google-translate-show-phonetic' is set to t."
(let ((translation-phonetic (gtos-translation-phonetic gtos)))
(if (and google-translate-show-phonetic
(not (string-equal translation-phonetic "")))
(google-translate-paragraph
translation-phonetic
'google-translate-phonetic-face
format)
"")))
(defun google-translate--detailed-translation (detailed-translation translation
format1
format2)
"Return detailed translation."
(with-temp-buffer
(loop for item across detailed-translation do
(let ((index 0)
(label (aref item 0)))
(unless (string-equal label "")
(put-text-property 0 (length label)
'font-lock-face
'google-translate-translation-face
label)
(insert (format format1 label))
(loop for translation across (aref item 2) do
(let ((content
(format "%s (%s)"
(aref translation 0)
(mapconcat 'identity
(aref translation 1)
", "))))
(insert (format format2
(incf index)
content)))))))
(buffer-substring (point-min) (point-max))))
(defun google-translate--detailed-definition (detailed-definition definition
format1
format2)
"Return detailed definition."
(with-temp-buffer
(let ((section "DEFINITION"))
(put-text-property 0 (length section)
'font-lock-face
'google-translate-translation-face
section)
(insert (format "\n%s\n" section)))
(loop for item across detailed-definition do
(let ((index 0)
(label (aref item 0)))
(unless (string-equal label "")
(put-text-property 0 (length label)
'font-lock-face
'google-translate-translation-face
label)
(insert (format format1 label))
(loop for definition across (aref item 1) do
(insert (format format2
(incf index)
(if (> (length definition) 2)
(format "%s\n \"%s\""
(aref definition 0)
(aref definition 2))
(format "%s" (aref definition 0)))))))))
(buffer-substring (point-min) (point-max))))
(defun google-translate--suggestion (gtos)
"Return suggestion."
(let ((source-language (gtos-source-language gtos))
(target-language (gtos-target-language gtos))
(suggestion (gtos-suggestion gtos)))
(if suggestion
(with-temp-buffer
(insert "\n")
(let ((beg (point)))
(insert "Did you mean: ")
(facemenu-set-face 'google-translate-suggestion-label-face
beg (point)))
(goto-char (+ (point) 1))
(let ((beg (point)))
(insert-text-button suggestion
'action 'google-translate--suggestion-action
'follow-link t
'suggestion suggestion
'source-language source-language
'target-language target-language)
(facemenu-set-face 'google-translate-suggestion-face
beg (point))
(insert "\n"))
(buffer-substring (point-min) (point-max)))
"")))
(defun google-translate--suggestion-action (button)
"Suggestion action which occur when suggestion button is
clicked."
(interactive)
(let ((suggestion (button-get button 'suggestion))
(source-language (button-get button 'source-language))
(target-language (button-get button 'target-language)))
(google-translate-translate source-language
target-language
suggestion)))
(defun google-translate--listen-button (language text)
"Return listen button."
(with-temp-buffer
(insert " ")
(insert-text-button google-translate-listen-button-label
'action 'google-translate--listen-action
'face 'google-translate-listen-button-face
'follow-link t
'text text
'language language)
(insert "\n")
(buffer-substring (point-min) (point-max))))
(defun google-translate--listen-action (button)
"Do translation listening."
(interactive)
(let ((text (button-get button 'text))
(language (button-get button 'language)))
(google-translate-listen-translation language text)))
(defun google-translate-listen-translation (language text)
(let ((buf "*mplayer output*"))
(message "Retrieving audio message...")
(if google-translate-translation-listening-debug
(with-current-buffer (get-buffer-create buf)
(insert (format "Listen program: %s\r\n" google-translate-listen-program))
(insert (format "Listen URL: %s\r\n" (google-translate-format-listen-url text language)))
(call-process google-translate-listen-program nil t nil
(format "%s" (google-translate-format-listen-url text language)))
(switch-to-buffer buf))
(call-process google-translate-listen-program nil nil nil
(format "%s" (google-translate-format-listen-url text language))))))
(defun google-translate-translate (source-language target-language text &optional output-destination)
"Translate TEXT from SOURCE-LANGUAGE to TARGET-LANGUAGE.
In case of `google-translate-output-destination' is nil pops up a
buffer named *Google Translate* with available translations of
TEXT. In case of `google-translate-output-destination' is
`echo-area' outputs translation in the echo area. If
`google-translate-output-destination' is `popup' outputs
translation in the popup tooltip using `popup' package.
To deal with multi-line regions, sequences of white space
are replaced with a single space. If the region contains not text, a
message is printed."
(let* ((json (google-translate-request source-language
target-language
text)))
(if (null json)
(message "Nothing to translate.")
(let* ((detailed-translation
(google-translate-json-detailed-translation json))
(detailed-definition
(google-translate-json-detailed-definition json))
(gtos
(make-gtos
:source-language source-language
:target-language target-language
:auto-detected-language (aref json 2)
:text text
:text-phonetic (google-translate-json-text-phonetic json)
:translation (google-translate-json-translation json)
:translation-phonetic (google-translate-json-translation-phonetic json)
:detailed-translation detailed-translation
:detailed-definition detailed-definition
:suggestion (when (null detailed-translation)
(google-translate-json-suggestion json))))
(output-destination (if (null output-destination)
google-translate-output-destination
output-destination)))
(cond
((null output-destination)
(google-translate-buffer-output-translation gtos))
((equal output-destination 'echo-area)
(google-translate-echo-area-output-translation gtos))
((equal output-destination 'popup)
(google-translate-popup-output-translation gtos))
((equal output-destination 'kill-ring)
(google-translate-kill-ring-output-translation gtos))
((equal output-destination 'current-buffer)
(google-translate-current-buffer-output-translation gtos))
((equal output-destination 'help)
(let ((describe-func
(function
(lambda (gtos)
(google-translate-help-buffer-output-translation gtos)))))
(help-setup-xref (list 'google-translate-translate source-language target-language text) nil)
(with-help-window (help-buffer)
(funcall describe-func gtos)))))))))
(defun google-translate-popup-output-translation (gtos)
"Output translation to the popup tooltip using `popup'
package."
(require 'popup)
(popup-tip
(with-temp-buffer
(google-translate-insert-translation gtos)
(google-translate--trim-string
(buffer-substring (point-min) (point-max))))))
(defun google-translate-echo-area-output-translation (gtos)
"Output translation to the echo area (See
http://www.gnu.org/software/emacs/manual/html_node/elisp/The-Echo-Area.html)"
(message
(with-temp-buffer
(google-translate-insert-translation gtos)
(google-translate--trim-string
(buffer-substring (point-min) (point-max))))))
(defun google-translate-kill-ring-output-translation (gtos)
"Output translation to the kill ring."
(kill-new
(with-temp-buffer
(insert
(gtos-translation gtos))
(google-translate--trim-string
(buffer-substring (point-min) (point-max)))))
(message "Translated text was added to the kill ring."))
(defun google-translate-current-buffer-output-translation (gtos)
"Output translation to current buffer."
(insert
(gtos-translation gtos))
(message "Translated text was added to current buffer."))
(defun google-translate-insert-translation (gtos)
"Insert translation to the current buffer."
(let ((translation (gtos-translation gtos))
(detailed-translation (gtos-detailed-translation gtos)))
(insert
(google-translate--translation-title gtos "%s -> %s:")
(google-translate--translating-text gtos " %s")
(google-translate--text-phonetic gtos " [%s]")
" - "
(google-translate--translated-text gtos "%s")
(google-translate--translation-phonetic gtos " [%s]")
(if detailed-translation
(google-translate--detailed-translation
detailed-translation translation
"\n* %s " "%d. %s ")
(google-translate--suggestion gtos)))))
(defun google-translate-buffer-output-translation (gtos)
"Output translation to the temp buffer."
(let ((buffer-name "*Google Translate*"))
(with-output-to-temp-buffer buffer-name
(if google-translate-pop-up-buffer-set-focus
(select-window (display-buffer buffer-name))
(set-buffer buffer-name))
(google-translate-buffer-insert-translation gtos))))
(defun google-translate-help-buffer-output-translation (gtos)
"Output translation to the help buffer."
(and google-translate-pop-up-buffer-set-focus
(select-window (display-buffer "*Help*")))
(google-translate-buffer-insert-translation gtos))
(defun google-translate-buffer-insert-translation (gtos)
"Insert translation to the current temp buffer."
(let ((translation (gtos-translation gtos))
(detailed-translation (gtos-detailed-translation gtos))
(detailed-definition (gtos-detailed-definition gtos))
(source-language (gtos-source-language gtos))
(target-language (gtos-target-language gtos))
(auto-detected-language (gtos-auto-detected-language gtos))
(text (gtos-text gtos)))
(insert
(google-translate--translation-title gtos "Translate from %s to %s:\n")
"\n"
(google-translate--translating-text
gtos
(if (null google-translate-listen-program)
"%s\n"
"%s"))
(if google-translate-listen-program
(google-translate--listen-button
(if (string-equal source-language "auto")
auto-detected-language
source-language) text) "")
(google-translate--text-phonetic gtos "\n%s\n")
"\n"
(google-translate--translated-text
gtos
(if (null google-translate-listen-program)
"%s\n"
"%s"))
(if google-translate-listen-program
(google-translate--listen-button target-language translation) "")
(google-translate--translation-phonetic gtos "\n%s\n")
(if detailed-translation
(google-translate--detailed-translation
detailed-translation translation
"\n%s\n" "%2d. %s\n")
(google-translate--suggestion gtos))
(if detailed-definition
(google-translate--detailed-definition
detailed-definition translation
"\n%s\n" "%2d. %s\n")
""))))
(defun google-translate-read-source-language (&optional prompt)
"Read a source language, with completion, and return its abbreviation.
The null input is equivalent to \"Detect language\"."
(let ((completion-ignore-case t)
(prompt
(if (null prompt)
"Translate from: "
prompt)))
(google-translate-language-abbreviation
(google-translate-completing-read
prompt
(google-translate-supported-languages)
"Detect language"))))
(defun google-translate-read-target-language (&optional prompt)
"Read a target language, with completion, and return its abbreviation.
The input is guaranteed to be non-null."
(let ((completion-ignore-case t)
(prompt
(if (null prompt)
"Translate to: "
prompt)))
(cl-flet ((read-language ()
(google-translate-completing-read
prompt
(google-translate-supported-languages))))
(let ((target-language (read-language)))
(while (string-equal target-language "")
(setq target-language (read-language)))
(google-translate-language-abbreviation target-language)))))
(defun google-translate-completing-read (prompt choices &optional def)
"Read a string in the minibuffer with completion.
If `google-translate-enable-ido-completion' is non-NIL, use
ido-style completion."
(funcall (if google-translate-enable-ido-completion
#'ido-completing-read
#'completing-read)
prompt choices nil t nil nil def))
(provide 'google-translate-core-ui)
;;; google-translate-core-ui.el ends here

View file

@ -0,0 +1,265 @@
;;; google-translate-core.el --- google-translate core script.
;; Copyright (C) 2012 Oleksandr Manzyuk <manzyuk@gmail.com>
;; Author: Oleksandr Manzyuk <manzyuk@gmail.com>
;; Maintainer: Andrey Tykhonov <atykhonov@gmail.com>
;; URL: https://github.com/atykhonov/google-translate
;; Version: 0.11.18
;; Keywords: convenience
;; Contributors:
;; Tassilo Horn <tsdh@gnu.org>
;; Bernard Hurley <bernard@marcade.biz>
;; Chris Bilson <cbilson@pobox.com>
;; Takumi Kinjo <takumi.kinjo@gmail.com>
;; momomo5717 <momomo5717@gmail.com>
;; This file is NOT part of GNU Emacs.
;; This is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file is the core of `google-translate' package. It does contains
;; the most important and vital functions and variables for the
;; package functionality.
;;
;; The most important is the `google-translate-request' function which
;; is intended to be used by other scripts and packages, expecially by
;; the packages which provides UI.
;;
;; This, `google-translate-core', package doesn't provide any UI.
;;
;; `google-translate-request' function sends http request to the
;; google service and returns JSON response which contains translation
;; and other info.
;;
;; There are also a set of helper functions which are going to be
;; useful to retrieve data from the mentioned JSON response:
;;
;; `google-translate-json-text-phonetic' - retrieves text phonetic;
;;
;; `google-translate-json-translation' - retrieves translation;
;;
;; `google-translate-json-translation-phonetic' - retrieves
;; phonetic translation;
;;
;; `google-translate-json-detailed-translation' - retrieves
;; additional, detailed information which relates to the
;; translation.
;;
;;; Code:
(eval-when-compile (require 'cl))
(require 'json)
(require 'url)
(require 'google-translate-tk)
(defgroup google-translate-core nil
"Google Translate core script."
:group 'processes)
(defvar google-translate-base-url
"http://translate.google.com/translate_a/single")
(defvar google-translate-listen-url
"http://translate.google.com/translate_tts")
(defun google-translate--format-query-string (query-params)
"Format QUERY-PARAMS as a query string.
QUERY-PARAMS must be an alist of field-value pairs."
(mapconcat #'(lambda (p)
(format "%s=%s"
(url-hexify-string (car p))
(url-hexify-string (cdr p))))
query-params "&"))
(defun google-translate--format-request-url (query-params)
"Format QUERY-PARAMS as a Google Translate HTTP request URL.
QUERY-PARAMS must be an alist of field-value pairs."
(concat google-translate-base-url
"?"
(google-translate--format-query-string query-params)))
(defun google-translate--format-listen-url (query-params)
"Format QUERY-PARAMS as a Google Translate HTTP request URL for listen translation.
QUERY-PARAMS must be an alist of field-value pairs."
(concat google-translate-listen-url
"?"
(google-translate--format-query-string query-params)))
(defun google-translate-format-listen-url (text language)
"Format listen url for TEXT and TARGET-LANGUAGE."
(google-translate--format-listen-url `(("ie" . "UTF-8")
("q" . ,text)
("tl" . ,language)
("total" . "1")
("idx" . "0")
("textlen" . ,(number-to-string (length text)))
("client" . "t")
("prev" . "input")
("tk" . ,(google-translate--gen-tk text)))))
(defun google-translate--http-response-body (url &optional for-test-purposes)
"Retrieve URL and return the response body as a string."
(let ((google-translate-backend-debug (or for-test-purposes
google-translate-backend-debug)))
(with-temp-buffer
(save-excursion
(google-translate-backend-retrieve url))
(set-buffer-multibyte t)
(buffer-string))))
(defun google-translate--insert-nulls (string)
"Google Translate responses with an almost valid JSON string
respresentation except that the nulls appear to be dropped. In
particular the response may contain the substrings \"[,\",
\",,\", and \",]\". This function undoes that."
(with-temp-buffer
(set-buffer-multibyte t)
(insert string)
(goto-char (point-min))
(while (re-search-forward "\\(\\[,\\|,,\\|,\\]\\)" (point-max) t)
(backward-char)
(insert "null"))
(buffer-string)))
(defun google-translate--trim-string (string)
"Remove whitespaces in beginning and ending of STRING.
White space here is any of: space, tab, emacs newline (line feed, ASCII 10)."
(replace-regexp-in-string "\\`[ \t\n\r]*" ""
(replace-regexp-in-string "[ \t\n\r]*\\'" "" string)))
(defun google-translate--strip-string (string)
"Replace spaces, tabs, line feeds (ASCII 10) and carridge
returns (ASCII 13) by a single space symbol."
(replace-regexp-in-string "[[:space:]\n\r]+" " " string))
(defun google-translate-prepare-text-for-request (text)
"Make TEXT as clean as possible berofe sending it in the
request."
(google-translate--trim-string
(google-translate--strip-string text)))
(defun google-translate-request (source-language target-language text)
"Send to the Google Translate http request which consigned to
translate TEXT from SOURCE-LANGUAGE to TARGET-LANGUAGE. Returns
response in json format."
(let ((cleaned-text (google-translate-prepare-text-for-request text)))
(when (and
(stringp cleaned-text)
(> (length cleaned-text) 0))
(json-read-from-string
(google-translate--insert-nulls
(google-translate--request source-language target-language text))))))
(defun google-translate--request (source-language
target-language
text
&optional for-test-purposes)
"Send to the Google Translate http request which consigned to
translate TEXT from SOURCE-LANGUAGE to TARGET-LANGUAGE."
(google-translate--http-response-body
(google-translate--format-request-url
`(("client" . "t")
("ie" . "UTF-8")
("oe" . "UTF-8")
("sl" . ,source-language)
("tl" . ,target-language)
("q" . ,text)
("dt" . "bd")
("dt" . "ex")
("dt" . "ld")
("dt" . "md")
("dt" . "qc")
("dt" . "rw")
("dt" . "rm")
("dt" . "ss")
("dt" . "t")
("dt" . "at")
("pc" . "1")
("otf" . "1")
("srcrom" . "1")
("ssel" . "0")
("tsel" . "0")
("tk" . ,(google-translate--gen-tk text))))
for-test-purposes))
(defun google-translate-json-text-phonetic (json)
"Retrieve from the JSON (which returns by the
`google-translate-request' function) phonetic transcription of
the translating text."
(mapconcat (lambda (item) (if (> (length item) 3) (aref item 3) ""))
(aref json 0) ""))
(defun google-translate-json-translation (json)
"Retrieve from the JSON (which returns by the
`google-translate-request' function) translation of the
translating text."
(mapconcat #'(lambda (item) (aref item 0))
(aref json 0) ""))
(defun google-translate-json-translation-phonetic (json)
"Retrieve from the JSON (which returns by the
`google-translate-request' function) phonetic transcription of
the translating text."
(mapconcat #'(lambda (item) (if (> (length item) 2) (aref item 2) ""))
(aref json 0) ""))
(defun google-translate-json-detailed-translation (json)
"Retrieve from the JSON (which returns by the
`google-translate-request' function) a dictionary article
represented by a vector of items, where each item is a 2-element
vector whose zeroth element is the name of a part of speech and
whose first element is a vector of translations for that part of
speech."
(aref json 1))
(defun google-translate-json-detailed-definition (json)
"Retrieve the definition of translating text in source language from the JSON
which returned by the `google-translate-request' function.
This function returns the definition if it's included within the JSON as 12th
element, or returns nil if not included.
The definition is a dictionary article represented by a vector of items, where
each item is a 2-element vector whose zeroth element is the name of a part of
speech and whose first element is a vector of definitions for that part of
speech."
(if (> (length json) 12)
(aref json 12)))
(defun google-translate-json-suggestion (json)
"Retrieve from JSON (which returns by the
`google-translate-request' function) suggestion. This function
does matter when translating misspelled word. So instead of
translation it is possible to get suggestion."
(let ((info (aref json 7)))
(when info
(aref info 1))))
(defun google-translate-version ()
(interactive)
(message "Google Translate (version): %s" "0.11.18"))
(provide 'google-translate-core)
;;; google-translate-core.el ends here

View file

@ -0,0 +1,302 @@
;;; google-translate-default-ui.el --- default UI for Google Translate
;;; package
;; Copyright (C) 2012 Oleksandr Manzyuk <manzyuk@gmail.com>
;; Author: Oleksandr Manzyuk <manzyuk@gmail.com>
;; Maintainer: Andrey Tykhonov <atykhonov@gmail.com>
;; URL: https://github.com/atykhonov/google-translate
;; Version: 0.11.18
;; Keywords: convenience
;; Contributors:
;; Tassilo Horn <tsdh@gnu.org>
;; Bernard Hurley <bernard@marcade.biz>
;; Chris Bilson <cbilson@pobox.com>
;; Takumi Kinjo <takumi.kinjo@gmail.com>
;; momomo5717 <momomo5717@gmail.com>
;; This file is NOT part of GNU Emacs.
;; This is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides default UI for the Google Translate package. It
;; was originally written by Oleksandr Manzyuk and was part of
;; google-translate.el. It was extracted to this,
;; google-translate-default-ui.el file due to refactoring (the goal of
;; which is to separate backend from UI and provide better way for
;; having different UIs for Google Translate package).
;;
;; Invoking the function `google-translate-query-translate' queries the source
;; and target languages and text to translate, and shows a buffer with
;; available translations of the text. Invoking the function
;; `google-translate-at-point' translates the word at point or the active
;; region.
;; Customization:
;; You can customize the following variables:
;;;;
;; - `google-translate-default-source-language'
;;
;; - `google-translate-default-target-language'
;; If the variable `google-translate-default-source-language' is set
;; to a non-NIL value, the source language won't be queried and that
;; value will be used instead. Analogously, if you set the variable
;; `google-translate-default-target-language' to some non-NIL value,
;; that value will be used without querying.
;; You can always override this behavior by supplying a `C-u' prefix
;; argument to the function `google-translate-query-translate'.
;; Here is an example. Suppose that your native language is Russian
;; and you frequently need to translate from various languages to
;; Russian. Then it is reasonable
;;
;; - to set the variable `google-translate-default-target-language'
;; to "ru", and
;;
;; - to leave `google-translate-default-source-language' set to its
;; default value, NIL.
;;
;; In this case, the function `google-translate-query-translate' is
;; only going to query the source language and text to translate.
;; If you need to translate to some language other than Russian, you
;; can override the default for the target language by supplying a
;; `C-u' prefix argument, in which case you will be queried for both
;; the source and target languages, as well as text to translate.
;; If you frequently translate from some fixed language, it is also
;; reasonable to set `google-translate-default-source-language' to
;; an appropriate value.
;;
;; If you have both the default source and target languages specified,
;; you may like to bind functions `google-translate-at-point-reverse'
;; and `google-translate-query-translate-reverse' to some keys, e.g.:
;;
;; (global-set-key (kbd "C-c r") 'google-translate-at-point-reverse)
;; (global-set-key (kbd "C-c R") 'google-translate-query-translate-reverse)
;;
;; This will allow you to quickly translate in the reverse direction.
;; When the default source (resp. target) language is not set, the
;; target (resp. source) language of the reverse translation will be
;; queried interactively.
;; The admitted values of `google-translate-default-source-language'
;; and `google-translate-default-target-language' are the codes of the
;; languages supported by Google Translate (like "ru" for Russian
;; above). See `google-translate-supported-languages' for the list of
;; the supported languages, or customize the defaults using the
;; customization mechanism of Emacs. Setting a default language to
;; NIL means that language will always be queried. Moreover, the
;; variable `google-translate-default-source-language' can be set to a
;; special value "auto" that is interpreted as the instruction for
;; Google Translate to detect the source language. This option is
;; also available when you are queried for the source language: simply
;; leave this parameter blank by pressing RET. (If you have enabled
;; the ido-style completion, "Detect language" is going to be the
;; first option, which you can select simply by hitting RET.)
;;
;;; Code:
(require 'google-translate-core-ui)
(defgroup google-translate-default-ui nil
"Default UI interface to the Google Translate package."
:group 'processes)
(defcustom google-translate-default-source-language nil
"Default source language.
A string designating a language supported by Google Translate.
Set this variable to NIL (the default value) if you want to
always be queried for the source language, or to \"auto\" if you
want Google Translate to always detect the source language.
See the variable `google-translate-supported-languages-alist' for
the list of available languages."
:group 'google-translate-manzyuk-ui
:type `(radio ,@(mapcar #'(lambda (lang)
`(const :tag ,(car lang) ,(cdr lang)))
google-translate-supported-languages-alist)
(const :tag "Detect language" "auto")
(other :tag "Always ask" nil)))
(defcustom google-translate-default-target-language nil
"Default target language.
A string designating a language supported by Google Translate.
Set this variable to NIL (the default value) if you want to
always be queried for the target language.
See the variable `google-translate-supported-languages-alist' for
the list of available languages."
:group 'google-translate-manzyuk-ui
:type `(radio ,@(mapcar #'(lambda (lang)
`(const :tag ,(car lang) ,(cdr lang)))
google-translate-supported-languages-alist)
(other :tag "Always ask" nil)))
(defun google-translate-read-args (override-p reverse-p)
"Query and return the language arguments of `google-translate-translate'.
When OVERRIDE-P is NIL, the source (resp. target) language is queried
only if the variable `google-translate-default-source-language' (resp.
`google-translate-default-target-language') is NIL. If OVERRIDE-P is
non-NIL, both the source and target languages are queried, allowing
one to override the defaults if they are specified.
REVERSE-P is used to reverse the default direction of translation: if
it's non-NIL, the value of `google-translate-default-source-language'
becomes the default target language and vice versa."
(let* ((default-source-language
(if reverse-p
google-translate-default-target-language
google-translate-default-source-language))
(default-target-language
(if reverse-p
google-translate-default-source-language
google-translate-default-target-language))
(source-language
(if (and default-source-language
(not override-p))
default-source-language
(google-translate-read-source-language
"Translate from: ")))
(target-language
(if (and default-target-language
(not override-p))
default-target-language
(google-translate-read-target-language
(format "Translate from %s to: "
(google-translate-language-display-name
source-language))))))
(list source-language target-language)))
(defun %google-translate-query-translate (override-p reverse-p)
(let* ((langs (google-translate-read-args override-p reverse-p))
(source-language (car langs))
(target-language (cadr langs)))
(google-translate-translate
source-language target-language
(if google-translate-input-method-auto-toggling
(minibuffer-with-setup-hook
(lambda ()
(google-translate-setup-preferable-input-method source-language))
(%google-translate-default-ui-read-from-minibuffer source-language target-language))
(%google-translate-default-ui-read-from-minibuffer source-language target-language)))))
(defun %google-translate-default-ui-read-from-minibuffer (source-language target-language)
(read-from-minibuffer
(format "Translate from %s to %s: "
(google-translate-language-display-name source-language)
(google-translate-language-display-name target-language))))
;;;###autoload
(defun google-translate-query-translate (&optional override-p)
"Interactively translate text with Google Translate.
Query a text (a word or a phrase), and pop up a buffer named *Google
Translate* displaying available translations of the text.
If no defaults for the source and target languages are specified (by
setting the variables `google-translate-default-source-language' and
`google-translate-default-target-language'), interactively query the
missing parts. For example, a reasonable option may be to specify a
default for the target language and always be queried for the source
language.
With a `C-u' prefix argument, query the source and target languages,
even if any defaults are specified. For example, you may frequently
need to translate from English to Russian, and you may choose to set
the default source and target languages to \"en\" and \"ru\", resp.
However, occasionally you may also need to translate from Russian to
English. With a `C-u' prefix argument you can override the defaults
and specify the source and target languages explicitly.
The languages are queried with completion, and the null input at the
source language prompt is considered as an instruction for Google
Translate to detect the source language."
(interactive "P")
(%google-translate-query-translate override-p nil))
;;;###autoload
(defun google-translate-query-translate-reverse (&optional override-p)
"Like `google-translate-query-translate', but performs translation
in the reverse direction.
The value of the variable `google-translate-default-source-language'
\(if set) becomes the target language, and the value of the variable
`google-translate-default-target-language' (if also set) becomes the
source language.
In particular, when both variables are set, translation is performed
in the reverse direction."
(interactive "P")
(%google-translate-query-translate override-p t))
(defun %google-translate-at-point (override-p reverse-p)
(let* ((langs (google-translate-read-args override-p reverse-p))
(source-language (car langs))
(target-language (cadr langs))
(bounds nil))
(google-translate-translate
source-language target-language
(if (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(or (and (setq bounds (bounds-of-thing-at-point 'word))
(buffer-substring-no-properties (car bounds) (cdr bounds)))
(error "No word at point."))))))
;;;###autoload
(defun google-translate-at-point (&optional override-p)
"Translate the word at point or the words in the active region.
For the meaning of OVERRIDE-P, see `google-translate-query-translate'."
(interactive "P")
(%google-translate-at-point override-p nil))
;;;###autoload
(defun google-translate-at-point-reverse (&optional override-p)
"Like `google-translate-at-point', but performs translation in the
reverse direction."
(interactive "P")
(%google-translate-at-point override-p t))
;;;###autoload
(defun google-translate-buffer (&optional override-p reverse-p)
"Translate current buffer.
For the meaning of OVERRIDE-P, see `google-translate-query-translate'."
(interactive "P")
(let* ((langs (google-translate-read-args override-p reverse-p))
(source-language (car langs))
(target-language (cadr langs)))
(google-translate-translate
source-language target-language
(if (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(or (buffer-substring-no-properties (point-min) (point-max))
(error "Translate current buffer error."))))))
(provide 'google-translate-default-ui)
;;; google-translate-default-ui.el ends here

View file

@ -0,0 +1,4 @@
(define-package "google-translate" "20190620.1416" "Emacs interface to Google Translate." 'nil)
;; Local Variables:
;; no-byte-compile: t
;; End:

View file

@ -0,0 +1,323 @@
;;; google-translate-smooth-ui.el --- Just another UI to Google
;;; Translate package
;; Copyright (C) 2012 Oleksandr Manzyuk <manzyuk@gmail.com>
;; Author: Oleksandr Manzyuk <manzyuk@gmail.com>
;; Maintainer: Andrey Tykhonov <atykhonov@gmail.com>
;; URL: https://github.com/atykhonov/google-translate
;; Version: 0.11.18
;; Keywords: convenience
;; Contributors:
;; Tassilo Horn <tsdh@gnu.org>
;; Bernard Hurley <bernard@marcade.biz>
;; Chris Bilson <cbilson@pobox.com>
;; Takumi Kinjo <takumi.kinjo@gmail.com>
;; momomo5717 <momomo5717@gmail.com>
;; This file is NOT part of GNU Emacs.
;; This is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; `google-translate-smooth-ui' is a just alternative to the default
;; `google-translate-default-ui'. It was written with mind to provide
;; impoved user interface and, especially, to achieve better
;; supporting of many default languages. `google-translate-default-ui'
;; supports two default languages very well but there is no space for
;; the third one.
;;
;; Invoking the function `google-translate-smooth-translate' queries
;; text and (optionally) the source and target languages to translate,
;; and shows a buffer with available translations of the text.
;; Installation:
;; Assuming that the files `google-translate.el',
;; `google-translate-core.el', `google-translate-core-ui.el' and
;; `google-translate-smooth-ui.el' are somewhere on the load path, add
;; the following lines to your .emacs file:
;;
;; (require 'google-translate-smooth-ui)
;; (global-set-key "\C-ct" 'google-translate-smooth-translate)
;;
;; Change the key bindings to your liking.
;;
;; Configuration:
;;
;; `google-translate-translation-directions-alist' alist is intended
;; to contain translation directions.
;;
;; For example it could be defined (in your .emacs or init.el) as:
;;
;; (setq google-translate-translation-directions-alist '(("en" . "ru"))
;;
;; in this way one translation direction ("en" > "ru") is defined and
;; when `google-translate-smooth-translate' function executes it will
;; output the prompt (in minibuffer) which will looks like as the
;; following:
;;
;; [English > Russian] Translate:
;;
;; You may set as many translation directions as you would like
;; to. For example such piece of code will define four translation
;; directions:
;;
;; (setq google-translate-translation-directions-alist
;; '(("de" . "en") ("en" . "de") ("de" . "fr") ("fr" . "de")))
;;
;; in this way, when `google-translate-smooth-translate' function
;; executes you'll be queried by the prompt which will looks like the
;; following:
;;
;; [German > English] Translate:
;;
;; and, also in this way, you'll be able to switch between different
;; translation directions directly from minibuffer by using "C-n" and
;; "C-p" key bindings. "C-n" key binding changes current translation
;; direction to the next direction defined in the
;; `google-translate-translation-directions-alist' variable. And "C-p"
;; key binding changes current translation direction to the previous
;; one. Thus, while executing `google-translate-smooth-translate'
;; function and having in minibuffer such prompt:
;;
;; [German > English] Translate:
;;
;; then after pressing "C-n" you'll get the following prompt:
;;
;; [English > German] Translate:
;;
;; By default `google-translate-translation-directions-alist' is empty
;; and thus during execution of `google-translate-smooth-translate'
;; you'll be queried (to input a text) by the prompt:
;;
;; Translate:
;;
;; And after inputed text you'll be queried also for the source and
;; target languages. To let the package to be known which languages
;; you would like to always use and to avoid repetitive language
;; quering it is reasonable to define them in the mentioned
;; `google-translate-translation-directions-alist' variable.
;; Customization:
;; `google-translate-smooth-ui' doesn't contain any customizable
;; variables. But `google-translate-smooth-ui' extends
;; `google-translate-core-ui' and thus it could be customized via this
;; package's variables. Please read documentation for the
;; `google-translate-core-ui' package.
;;
;;; Code:
(require 'google-translate-core-ui)
(defgroup google-translate-smooth-ui nil
"Just Another UI for Google Translate package."
:group 'processes)
(defvar google-translate-translation-directions-alist
'()
"Alist of translation directions. Each of direction could be
selected directly in the minibuffer during translation.
Each element is a cons-cell of the form (SOURCE_CODE
. TARGET_CODE), where SOURCE_CODE is a source language code and
TARGET_CODE is a target language code.
Language codes are defined in
`google-translate-supported-languages-alist' variable.
As example, this alist could looks like the following:
'((\"en\" . \"ru\")
(\"ru\" . \"en\")
(\"uk\" . \"ru\")
(\"ru\" . \"uk\"))")
(defvar google-translate-current-translation-direction 0
"Points to nth element of
`google-translate-translation-directions-alist' variable and
keeps current translation direction while changing translation
directions.")
(defvar google-translate-translation-direction-query ""
"Temporal variable which keeps a minibuffer text while
switching translation directions.")
(defvar google-translate-try-other-direction nil
"Indicates that other translation direction is going to be
used.")
(defvar google-translate-minibuffer-keymap nil
"Keymap for minibuffer for changing translation directions.")
(defun google-translate-change-translation-direction (direction)
"Change translation direction. If DIRECTION is 'next then
change current direction by the next one. Otherwise change it to
the previous one."
(let ((current google-translate-current-translation-direction)
(length (length google-translate-translation-directions-alist)))
(setq current
(if (equal direction 'next)
(+ current 1)
(- current 1)))
(when (< current 0)
(setq current (- length 1)))
(when (> current (- length 1))
(setq current 0))
(setq google-translate-current-translation-direction current)
(setq google-translate-translation-direction-query
(minibuffer-contents))))
(defun google-translate-next-translation-direction ()
"Switch to the next translation direction. If current direction
is the last in the list of existing directions then switch to the
first one."
(interactive)
(google-translate-change-translation-direction 'next)
(setq google-translate-try-other-direction t)
(exit-minibuffer))
(defun google-translate-previous-translation-direction ()
"Switch to the previous translation direction. If current
direction is the first in the list of existing directions then
switch to the last one."
(interactive)
(google-translate-change-translation-direction 'previous)
(setq google-translate-try-other-direction t)
(exit-minibuffer))
(defun google-translate-query-translate-using-directions ()
"Tranlate query using translation directions described by
`google-translate-translation-directions-alist' variable.
This function allows to select desired translation direction
directly in the minibuffer while translating a word or a
sentence.
This function defines two key bindings for the minibuffer which
allow to select direction:
C-p - to select previous direction,
C-n - to select next direction."
(interactive)
(let ((text ""))
(setq google-translate-try-other-direction nil)
(setq text
(if google-translate-input-method-auto-toggling
(minibuffer-with-setup-hook
(lambda ()
(google-translate-setup-preferable-input-method
(google-translate--current-direction-source-language)))
'google-translate-setup-preferable-input-method
(google-translate--read-from-minibuffer))
(google-translate--read-from-minibuffer)))
(if google-translate-try-other-direction
(call-interactively 'google-translate-query-translate-using-directions)
text)))
(defun google-translate--setup-minibuffer-keymap ()
"Setup additional key bindings for minibuffer."
(unless google-translate-minibuffer-keymap
(setq google-translate-minibuffer-keymap
(let ((map (make-sparse-keymap)))
(define-key map "\C-p" 'google-translate-previous-translation-direction)
(define-key map "\C-n" 'google-translate-next-translation-direction)
(define-key map "\C-l" 'google-translate-clear-minibuffer)
(set-keymap-parent map minibuffer-local-map)
map))))
(defun google-translate-clear-minibuffer ()
"Delete minibuffer contents."
(interactive)
(delete-minibuffer-contents))
(defun google-translate--read-from-minibuffer ()
"Read string from minibuffer."
(let* ((source-language
(google-translate--current-direction-source-language))
(target-language
(google-translate--current-direction-target-language))
(prompt (if (or (null source-language)
(null target-language))
"Translate: "
(format "[%s > %s] Translate: "
(google-translate-language-display-name source-language)
(google-translate-language-display-name target-language)))))
(google-translate--setup-minibuffer-keymap)
(read-from-minibuffer
prompt
google-translate-translation-direction-query
google-translate-minibuffer-keymap nil nil
google-translate-translation-direction-query t)))
(defun google-translate--current-direction-source-language ()
"Retrieve source language from the current translation
direction."
(car (nth google-translate-current-translation-direction
google-translate-translation-directions-alist)))
(defun google-translate--current-direction-target-language ()
"Retrieve target language from the current translation
direction."
(cdr (nth google-translate-current-translation-direction
google-translate-translation-directions-alist)))
;;;###autoload
(defun google-translate-smooth-translate ()
"Translate a text using translation directions.
Make a prompt in minibuffer for a text to translate. Default text
is word at point.
In case of `google-translate-translation-directions-alist' is
empty list then after inputed translating text prompts for source
language and then for target languages.
In case of `google-translate-translation-directions-alist' is not
empty list takes current translation direction and makes
appropriate translation. Current translation direction indicates
in the minibuffers' prompt.
A current translation direction could be changed directly in the
minibuffer by means of key bindings such as C-n and C-p for
changing to the next translation direction and to the previous
one respectively."
(interactive)
(setq google-translate-translation-direction-query
(if (use-region-p)
(google-translate--strip-string
(buffer-substring-no-properties (region-beginning) (region-end)))
(current-word t t)))
(setq google-translate-current-translation-direction 0)
(let* ((text (google-translate-query-translate-using-directions))
(source-language (google-translate--current-direction-source-language))
(target-language (google-translate--current-direction-target-language)))
(when (null source-language)
(setq source-language (google-translate-read-source-language)))
(when (null target-language)
(setq target-language (google-translate-read-target-language)))
(google-translate-translate source-language target-language text)))
(provide 'google-translate-smooth-ui)
;;; google-translate-smooth-ui.el ends here

View file

@ -0,0 +1,176 @@
;;; google-translate-tk.el --- functions for generation `tk'
;;; parameter.
;; Copyright (C) 2012 Oleksandr Manzyuk <manzyuk@gmail.com>
;; Author: Oleksandr Manzyuk <manzyuk@gmail.com>
;; Maintainer: Andrey Tykhonov <atykhonov@gmail.com>
;; URL: https://github.com/atykhonov/google-translate
;; Version: 0.11.18
;; Keywords: convenience
;; Contributors:
;; Tassilo Horn <tsdh@gnu.org>
;; Bernard Hurley <bernard@marcade.biz>
;; Chris Bilson <cbilson@pobox.com>
;; Takumi Kinjo <takumi.kinjo@gmail.com>
;; momomo5717 <momomo5717@gmail.com>
;; This file is NOT part of GNU Emacs.
;; This is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file contains functions for generation `tk' parameter which is
;; required to make a valid request to the Google Translate.
;;; Code:
(require 'cl-lib)
(require 'google-translate-backend)
(defvar google-translate--bit-v-len 32)
(defvar google-translate--tkk-url
"http://translate.google.com/")
(defun google-translate--bit-v-2comp (v)
"Return the two's complement of V."
(let* ((vc (vconcat v))
(len (length vc)))
;; Complement of v
(cl-loop for i from 0 below len do
(aset vc i (logxor (aref vc i) 1)))
;; vc = complement of v + 1
(cl-loop for i downfrom (1- len) to 0
do (aset vc i (logxor (aref vc i) 1))
when (> (aref vc i) 0) return nil)
vc))
(defun google-translate--number-to-bit-v (n)
"Return a bit vector from N."
(if (< n 0) (google-translate--bit-v-2comp
(google-translate--number-to-bit-v (abs n)))
(let ((v (make-vector google-translate--bit-v-len 0)))
(cl-loop for i downfrom (1- google-translate--bit-v-len) to 0
with q
when (< n 1) return nil do
(setq q (ffloor (* n 0.5)))
(aset v i (floor (- n (* 2.0 q))))
(setq n q))
v)))
(defun google-translate--bit-v-to-number (v)
"Return a floating-point number from V."
(if (and (> (aref v 0) 0)
;; Exclude [1 0 ... 0]
(cl-loop for i from 1 below google-translate--bit-v-len
thereis (> (aref v i) 0)))
(- (google-translate--bit-v-to-number (google-translate--bit-v-2comp v)))
(funcall (if (> (aref v 0) 0) #'- #'+)
(cl-reduce (lambda (acc e) (+ (* acc 2.0) e))
v :initial-value 0.0))))
(defun google-translate--logfn (fn n1 n2)
"Helper function for logical FN."
(let ((v1 (google-translate--number-to-bit-v n1))
(v2 (google-translate--number-to-bit-v n2))
(v (make-vector google-translate--bit-v-len 0)))
(cl-loop for i from 0 below google-translate--bit-v-len do
(aset v i (funcall fn (aref v1 i) (aref v2 i))))
(google-translate--bit-v-to-number v)))
(defun google-translate--logand (n1 n2)
"Return a floating-point number from N1 and N2."
(google-translate--logfn #'logand n1 n2))
(defun google-translate--logxor (n1 n2)
"Return a floating-point number from N1 and N2."
(google-translate--logfn #'logxor n1 n2))
(defun google-translate--lsh (n d)
"Return a floating-point number.
Shift the bits in N to the left or rihgt D places.
D is an integer."
(let ((v (google-translate--number-to-bit-v n))
(v-result (make-vector google-translate--bit-v-len 0)))
(if (< d 0) ;; Shift Right Logical
;; [x0 x1 ... xn-d ... xn] => [0 ... 0 x0 x1 ... xn-d]
(cl-loop for i from (abs d) below google-translate--bit-v-len
for j from 0 do
(aset v-result i (aref v j)))
;; Shift Left Logical
;; [x0 x1 ... xd ... xn] => [xd ... xn 0 ... 0]
(cl-loop for i from d below google-translate--bit-v-len
for j from 0 do
(aset v-result j (aref v i))))
(google-translate--bit-v-to-number v-result)))
(defun google-translate--search-tkk ()
"Search TKK."
(let ((start nil)
(tkk nil)
(nums '()))
(setq start (search-forward ",tkk:'"))
(search-forward "',")
(backward-char 2)
(setq tkk (buffer-substring start (point)))
(setq nums (split-string tkk "\\."))
(list (string-to-number (car nums))
(string-to-number (car (cdr nums))))))
(defun google-translate--get-b-d1 ()
"Return a list of b and d1 for `google-translate--gen-tk'."
(let ((url-request-extra-headers '(("Connection" . "close"))))
(with-temp-buffer
(save-excursion (google-translate-backend-retrieve
google-translate--tkk-url))
(google-translate--search-tkk))))
(defun google-translate--gen-rl (a b)
(cl-loop for c from 0 below (- (length b) 2) by 3
for d = (aref b (+ c 2)) do
(setq d (if (>= d ?a) (- d 87) (- d ?0)))
(setq d (if (= (aref b (1+ c)) ?+)
(google-translate--lsh a (- d))
(google-translate--lsh a d)))
(setq a (if (= (aref b c) ?+)
(google-translate--logand (+ a d) 4294967295.0)
(google-translate--logxor a d))))
a)
(defun google-translate--gen-tk (text &optional b-d1)
(setq b-d1 (or b-d1 (google-translate--get-b-d1)))
(let* ((b (cl-first b-d1))
(d1 (cl-second b-d1))
(ub "+-3^+b+-f")
(vb "+-a^+6")
(a (cl-reduce (lambda (a e) (google-translate--gen-rl (+ a e) vb))
(encode-coding-string text 'utf-8) :initial-value b)))
(setq a (google-translate--gen-rl a ub))
(setq a (google-translate--logxor a d1))
(when (< a 0) ;; (abs a) + 2^31
(setq a (+ (google-translate--logand a 2147483647.0) 2147483648.0)))
(setq a (ffloor (mod a 1e6)))
(format "%s.%s"
(car (split-string (number-to-string a) "\\."))
(car (split-string (number-to-string
(google-translate--logxor a b)) "\\.")))))
(provide 'google-translate-tk)
;;; google-translate-tk.el ends here

View file

@ -0,0 +1,84 @@
;;; google-translate.el --- Emacs interface to Google Translate
;; Copyright (C) 2012 Oleksandr Manzyuk <manzyuk@gmail.com>
;; Author: Oleksandr Manzyuk <manzyuk@gmail.com>
;; Maintainer: Andrey Tykhonov <atykhonov@gmail.com>
;; URL: https://github.com/atykhonov/google-translate
;; Version: 0.11.18
;; Keywords: convenience
;; Contributors:
;; Tassilo Horn <tsdh@gnu.org>
;; Bernard Hurley <bernard@marcade.biz>
;; Chris Bilson <cbilson@pobox.com>
;; Takumi Kinjo <takumi.kinjo@gmail.com>
;; momomo5717 <momomo5717@gmail.com>
;; This file is NOT part of GNU Emacs.
;; This is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Installation:
;; From MELPA or Marmalade.
;; Just run `M-x package-install RET google-translate RET`
;; Manual installation.
;; Assuming that the file `google-translate.el' and other files which
;; relates to this package is somewhere on the load path, add the
;; following lines to your `.emacs' file:
;; (require 'google-translate)
;; (require 'google-translate-default-ui)
;; (global-set-key "\C-ct" 'google-translate-at-point)
;; (global-set-key "\C-cT" 'google-translate-query-translate)
;; or
;; (require 'google-translate)
;; (require 'google-translate-smooth-ui)
;; (global-set-key "\C-ct" 'google-translate-smooth-translate)
;;
;; Change the key bindings to your liking.
;; The difference between these configurations is in UI which will be
;; used: Default UI or Smooth UI.
;;
;; Please read the source of `google-translate-default-ui.el' and
;; `google-translate-smooth-ui.el' for more details.
;; Customization:
;; Variables which are available for customization are depends on UI
;; package which is selected for the google-translate
;; package. google-translate-default-ui - is UI which is selected by
;; default. It loads by default and is available right after
;; google-translate installation and its initialization. Please read
;; documentation for the `google-translate-core-ui.el' and
;; `google-translate-default-ui.el' packages for more info about
;; customization.
;;
;;; Code:
(require 'google-translate-default-ui)
(provide 'google-translate)
;;; google-translate.el ends here

View file

@ -1,2 +0,0 @@
;;; -*- no-byte-compile: t -*-
(define-package "olivetti" "20200207.749" "Minor mode for a nice writing environment" '((emacs "25.3")) :commit "37da7d49117ee2128a18e022d630e43f15660f4a" :keywords '("wp" "text") :authors '(("Paul W. Rankin" . "code@paulwrankin.com")) :maintainer '("Paul W. Rankin" . "code@paulwrankin.com") :url "https://gthub.com/rnkn/olivetti")

View file

@ -0,0 +1,2 @@
;;; -*- no-byte-compile: t -*-
(define-package "olivetti" "20200212.1439" "Minor mode for a nice writing environment" '((emacs "24.5")) :commit "4b113151308c1214e8e70a7846558dad9c918859" :keywords '("wp" "text") :authors '(("Paul W. Rankin" . "code@paulwrankin.com")) :maintainer '("Paul W. Rankin" . "code@paulwrankin.com") :url "https://gthub.com/rnkn/olivetti")

View file

@ -1,13 +1,14 @@
;;; olivetti.el --- Minor mode for a nice writing environment -*- lexical-binding: t; -*-
;; Copyright (c) 2014-2019 Free Software Foundation, Inc.
;; Copyright (c) 2019 Paul W. Rankin
;; Copyright (c) 2014-2019 Paul W. Rankin
;; Copyright (c) 2019 Free Software Foundation, Inc.
;; Copyright (c) 2019-2020 Paul W. Rankin
;; Author: Paul W. Rankin <code@paulwrankin.com>
;; Keywords: wp, text
;; Package-Version: 20200207.749
;; Version: 1.9.1
;; Package-Requires: ((emacs "25.3"))
;; Package-Version: 20200212.1439
;; Version: 1.9.2
;; Package-Requires: ((emacs "24.5"))
;; URL: https://gthub.com/rnkn/olivetti
;; This file is not part of GNU Emacs.
@ -295,8 +296,6 @@ fraction of the window width."
(olivetti-set-all-margins)
(message "Text body width set to %s" olivetti-body-width))
(require 'seq)
(defun olivetti-expand (&optional arg)
"Incrementally increase the value of `olivetti-body-width'.
@ -311,10 +310,10 @@ If prefixed with ARG, incrementally decrease."
(olivetti-set-all-margins)
(message "Text body width set to %s" olivetti-body-width)
(unless overriding-terminal-local-map
(let ((keys (seq-subseq (this-single-command-keys) 0 -1))
(let ((keys (substring (this-single-command-keys) 0 -1))
(map (cdr olivetti-mode-map)))
(seq-do (lambda (k) (setq map (assq k map))) keys)
(set-transient-map (cdr map) t))))
(mapc (lambda (k) (setq map (assq k map))) keys)
(when (consp map) (set-transient-map (cdr map) t)))))
(defun olivetti-shrink (&optional arg)
"Incrementally decrease the value of `olivetti-body-width'.

View file

@ -1 +1 @@
Good signature from 066DAFCB81E42C40 GNU ELPA Signing Agent (2019) <elpasign@elpa.gnu.org> (trust undefined) created at 2020-02-05T11:05:09+0100 using RSA
Good signature from 066DAFCB81E42C40 GNU ELPA Signing Agent (2019) <elpasign@elpa.gnu.org> (trust undefined) created at 2020-02-13T11:05:02+0100 using RSA

View file

@ -104,6 +104,8 @@ If the value is nil, timeout is disabled."
(result-params (cdr (assq :result-params params)))
(print-level nil)
(print-length nil)
;; Remove comments, they break (let [...] ...) bindings
(body (replace-regexp-in-string "^[ ]*;+.*$" "" body))
(body (org-trim
(concat
;; Source block specified namespace :ns.
@ -113,7 +115,7 @@ If the value is nil, timeout is disabled."
(format "(let [%s]\n%s)"
(mapconcat
(lambda (var)
(format "%S (quote %S)" (car var) (cdr var)))
(format "%S %S" (car var) (cdr var)))
vars
"\n ")
body))))))

View file

@ -2764,11 +2764,12 @@ block but are passed literally to the \"example-block\"."
(lambda (s)
;; Comment, according to LANG mode,
;; string S. Return new string.
(unless org-babel-tangle-uncomment-comments
(with-temp-buffer
(funcall (org-src-get-lang-mode lang))
(comment-region (point)
(progn (insert s) (point)))
(org-trim (buffer-string)))))
(org-trim (buffer-string))))))
(expand-body
(lambda (i)
;; Expand body of code blocked

View file

@ -35,7 +35,7 @@
;; - gnuplot :: http://www.gnuplot.info/
;;
;; - gnuplot-mode :: http://cars9.uchicago.edu/~ravel/software/gnuplot-mode.html
;; - gnuplot-mode :: you can search the web for the latest active one.
;;; Code:
(require 'ob)

Some files were not shown because too many files have changed in this diff Show more