nice! 我之前试过用正则表达式替换\n 为"",但是没法达到删除单行不删除多行的效果。
(defun my-translate-command-1 ()
(interactive)
(do-translate (gts-translator
:picker (gts-noprompt-picker)
:engines (gts-google-rpc-engine)
:render (gts-buffer-render))))
@lorniu 想定义一个命令,但是提示 user-error: No definitions found for: do-translate
,这个命令改成什么了?
啊,笔误。文档中写错了,do-translate
应该是 gts-translate
。
刚才试出来了,多谢。现在可以正常工作了
@lorniu 大佬,请教一下怎么能够实现像老版本那样,翻译完成后自动复制到 kill-ring 时,只复制翻译后的中文。目前我下面这个设置的行为是连着前面的英文也一起复制了。
(defun go-translate-save-kill-ring ()
(interactive)
(gts-translate (gts-translator
:picker (gts-noprompt-picker)
:engines (gts-google-rpc-engine)
:render (gts-kill-ring-render))))
多谢,搞定了。新版本确实很灵活
我用的最多的是这个:
;; Pick directly and add the results into kill-ring
(defun go-translate-save-kill-ring ()
(interactive)
(gts-translate (gts-translator
:picker (gts-noprompt-picker)
:engines (gts-google-engine :parser (gts-google-summary-parser))
:render (gts-kill-ring-render))))
M-x customize-face
- go-translate-faces
,这里可以看到相关配色的配置。
其中跟弹出 frame 相关的,是 gts-pop-posframe-xxx 的几条。
用最新的emacs29时,gts-do-translate-popup 会报错
(setq gts-popup-translator
(gts-translator
:picker (gts-noprompt-picker)
:engines (list (gts-google-engine :parser (gts-google-summary-parser)))
:render (gts-posframe-pop-render)
))
(defun gts-do-translate-popup ()
(interactive)
(gts-translate gts-popup-translator))
下面使用emacs -Q 测试的
apply: Wrong number of arguments: ((t) (size-info) "Set POSFRAME's size based on SIZE-INFO." (let ((posframe (plist-get size-info :posframe)) (width (plist-get size-info :width)) (height (plist-get size-info :height)) (max-width (plist-get size-info :max-width)) (max-height (plist-get size-info :max-height)) (min-width (plist-get size-info :min-width)) (min-height (plist-get size-info :min-height))) (if height (progn (set-frame-height posframe height))) (if width (progn (set-frame-width posframe width))) (if (and height width) nil (posframe--fit-frame-to-buffer posframe max-height min-height max-width min-width (cond (width 'vertically) (height 'horizontally)))) (set (make-local-variable 'posframe--last-posframe-size) size-info)))
@lorniu 大佬,请教一下问题:
我想在执行 go-translate-at-point
后,在显示翻译内容的 buffer 中执行 variable-pitch-mode
来显示变宽字体,需要怎么设置?
我目前的配置如下:
(use-package go-translate
:bind (("C-c t g" . gts-do-translate)
("C-c t p" . go-translate-at-point)
("C-c t s" . go-translate-save-kill-ring))
:config
(setq gts-translate-list '(("en" "zh")))
(setq gts-default-translator
(gts-translator
:picker (gts-prompt-picker)
:engines (list (gts-bing-engine) (gts-google-engine))
:render (gts-buffer-render)))
;; Pick directly and use Google RPC API to translate
(defun go-translate-at-point ()
(interactive)
(gts-translate (gts-translator
:picker (gts-noprompt-picker)
:engines (gts-google-rpc-engine)
:render (gts-buffer-render))))
;; Pick directly and add the results into kill-ring
(defun go-translate-save-kill-ring ()
(interactive)
(gts-translate (gts-translator
:picker (gts-noprompt-picker)
:engines (gts-google-engine
:parser (gts-google-summary-parser))
:render (gts-kill-ring-render)))))
感谢 @lorniu 大佬的指点,显示变宽字体的问题也解决了:
(cl-defmethod gts-out :after ((_ gts-buffer-render) _)
(with-current-buffer gts-buffer-name
(read-only-mode 1)
(variable-pitch-mode 1)))
参考: 如何将显示翻译的*Go-Translate* buffer设置为只读? · Issue #31 · lorniu/go-translate · GitHub
google 后端有一段时间不能用了。
最近才发现,需要在 Emacs 中设置下 Proxy 就可以了。
(customize-set-variable 'url-proxy-services
'(("http" . "127.0.0.1:8079")
("https" . "127.0.0.1:8079")))
端口号改成自己的就好了。
另外注意到,同样的英文语句在不同的 Google 后端中,结果都不一样。
比如:
Org Export runs inside Emacs and is capable of converting Org files to a variety of other formats.
太好用了!十分感谢