Giter Site home page Giter Site logo

dictionary-overlay's Introduction

Dictionary-overlay

目标

辅助英文较弱的 Emacser 进行英文阅读。提供了两种能力:

  1. 生词本提示:自定义“生词本”,阅读英文文章时,通过 overlay 给生词添加中文翻译。
  2. 透析阅读法:自定义“熟词本”,阅读英文文章时,通过 overlay 翻译当前文章所有未标记为“熟词”的单词

    images/2022-11-15_21-23-58_screenshot.png

安装

用于 Emacs 与外部应用进行 websocket 通信

Python 相关包

插件通过 python 编写,需要安装 python3

你可以使用 dictionary-overlay-install 来安装相关的 python 包(不包括 google-translate 和 pyobjc)。

网络翻译

默认会使用 sdcv 本地词典翻译。当单词在本地词典未找到时,会使用网络翻译,目前支持:

  1. crow-translate
  2. google-translate

你可以使用: dictionary-overlay-install-google-translate 来安装 google-translate

下载 dictionary-overlay

git clone --depth=1 -b main https://github.com/ginqi7/dictionary-overlay ~/.emacs.d/site-lisp/dictionary-overlay/

添加下面配置到 ~/.emacs

(add-to-list 'load-path "~/.emacs.d/site-lisp/dictionary-overlay/")
(require 'dictionary-overlay)

命令

命令说明
dictionary-overlay-start启动 dictionary-overlay 应用
dictionary-overlay-stop退出 dictionary-overlay 应用
dictionary-overlay-restart重启 dictionary-overlay 应用
dictionary-overlay-render-buffer使用翻译渲染当前 buffer
dictionary-overlay-toggle打开\关闭翻译渲染当前 buffer
dictionary-overlay-lookup查询当前词, 默认 Emacs 自带词典。自定义见选项
dictionary-overlay-jump-next-unknown-word跳转到下一个生词
dictionary-overlay-jump-prev-unknown-word跳转到上一个生词
dictionary-overlay-jump-first-unknown-word跳转到第一个生词
dictionary-overlay-jump-last-unknown-word跳转到最后一个生词
dictionary-overlay-jump-out-overlay光标跳到词末,离开overlay,恢复正常keymap
dictionary-overlay-mark-word-known标记当前单词为“已知”
dictionary-overlay-mark-word-unknown标记当前单词为“生词”
dictionary-overlay-mark-word-smart生词本模式时,默认标记当前单词为“未知”,透析模式时,标为“已知”
dictionary-overlay-mark-word-smart-reversely功能同上,但生词本模式时标记为“已知”,透析模式时,标为”未知“
dictionary-overlay-mark-buffer标签当前 buffer 中所有未标记为“生词”的单词全为“已知”
dictionary-overlay-mark-buffer-unknown标签当前 buffer 中所有未标记为“生词”的单词全为“未知”
dictionary-overlay-install安装 dictionary-overlay 所依赖的必选 python 包
dictionary-overlay-install-google-translate安装 google-translate
dictionary-overlay-modify-translation修改当前单词的“翻译”,可以选择词典中的翻译,也可以手动输入

选项

选项说明
dictionary-overlay-just-unknown-wordst 时使用“生词本”模式,nil 为“透析阅读”模式,默认为 t
dictionary-overlay-user-data-directory用户数据存放 目录,默认值为:“~/.emacs.d/dictionary-overlay-data”
dictionary-overlay-position显示翻译的位置:词后,help-echo, 默认在词后
dictionary-overlay-lookup-with查词词典设置:默认系统词典。可自定义第三方包,比如 youdao-dictionary, popweb
dictionary-overlay-inihibit-keymapt 时关闭 keymap, 默认为 nil
dictionary-overlay-auto-jump-after可选项:标为生词 mark-word-known, 标为熟词 mark-word-unknwon, 刷新 render-buffer
dictionary-overlay-translation-format翻译展示的形式,默认是:”(%s)”
dictionary-overlay-translators指定使用的翻译引擎以及使用顺序。默认包含’(“local” “sdcv” “darwin” “web”) 分别表示,本地dictionary.json 文件,内置的sdcv 词典, MacOs 系统词典,以及web 翻译,你可以选择使用的词典以及顺序。
dictionary-overlay-sdcv-dictionary-path默认值 nil, 此时会使用 dictionary-overlay 自带 的kdic-ec-11w 词典,如果你有自定义的 StarDict 词典,你可以设定自己的词典路径。

注意:手动修改dictionary-overlay-user-data-directory 目录下的文件时,请先关闭 dictionary-overlay 应用(运行dictionary-overlay-stop ),否则修改可能会被应用覆盖

face

选项说明
dictionary-overlay-unknownword生词的展示形态 face 默认为 nil, 用户可自行修改
dictionary-overlay-translation生词的翻译的展示形态 face 默认为 nil, 用户可自行修改

用于控制生词的展示, 为了不影响阅读默认为空,不对原始 face 做任何修改。如果希望能通过 face 对生词进行显示增加可以参考

(defface dictionary-overlay-translation
  '((((class color) (min-colors 88) (background light))
     :underline "#fb8c96" :background "#fbd8db")
    (((class color) (min-colors 88) (background dark))
     :underline "#C77577" :background "#7A696B")
    (t
     :inherit highlight))
  "Face for dictionary-overlay unknown words.")

face `dictionary-overlay-unknownword` 如果用户不自行定义,那么不会给单词加上 overlay, 只会新增翻译的 overlay. 这样的好处是,当你在单词上移动时,仍旧按照字母移动,而不是按照 overlay 移动。

推荐使用的 face :

(copy-face 'font-lock-keyword-face 'dictionary-overlay-unknownword)
(copy-face 'font-lock-comment-face 'dictionary-overlay-translation)

images/dictionary-overlay-face.png

快捷键

(setq dictionary-overlay-inihibit-keymap nil) 可以使用若干自带的快捷键,当point 在一个生词的overlay 之上时,可以:

ddictionary-overlay-lookup查当前词
rdictionary-overlay-refresh-buffer刷新buffer
pdictionary-overlay-jump-prev-unknown-word跳转到上一个生词
ndictionary-overlay-jump-next-unknown-word跳转到下一个生词
<dictionary-overlay-jump-first-unknown-word跳转到第一个生词
>dictionary-overlay-jump-last-unknown-word跳转到最后一个生词
mdictionary-overlay-mark-word-smart透析模式,把单词标记为“熟词”
Mdictionary-overlay-mark-word-smart-reversely生词本模式,把单词标记为“熟词”
cdictionary-overlay-modify-translation修改翻译
<escape>dictionary-overlay-jump-out-of-overlay跳出overlay 让快捷键在非overlay 词语中失效。

快捷键只在标记为生词的overlay 上生效,因此 dictionary-overlay-mark-word-unknown 还需要自行绑定需要的快捷键

使用方法探讨

默认使用“生词本”模式,阅读英文文章时,需要手动添加生词( dictionary-overlay-mark-word-unknown )。可以和你的“查询单词”的快捷键保持在一起。那么你下次遇到生词时,会自动展示出生词。

当你开始阅读文章时,可以把当前 buffer 中所有未标记为 known 的单词标记为 unknown ( dictionary-overlay-mark-buffer-unknown )

当你阅读完一篇文章以后,可以把当前 buffer 中所有未标记为 unknown 的单词标记为 known ( dictionary-overlay-mark-buffer )

当一个生词反复出现,你觉得自己已经认识了它,可以标记为 known ( dictionary-overlay-mark-word-known ),下次不再展示翻译。

当你阅读了足够多的文章,你应该积累了一定量的 known-words ,此时,或许你可以尝试使用析阅读法”( (setq dictionary-overlay-just-unknown-words nil) )将自动展示,“或许”你不认识的单词。

如果喜欢最小的视觉干扰,可以通过 (setq dictionary-overlay-position ‘help-echo) 把翻译位置设置在 help-echo 里,只有鼠标通过时才显示释义。注意:目前支持的释义仍过于简单,并不推荐使用此法,同时由于默认无face,推荐设置前述 (copy-face ‘font-lock-keyword-face ‘dictionary-overlay-unknownword)。

功能特性

  • 使用 snowballstemmer 进行词干提取,能够用于标记词干相同,形态不一的单词
  • 增加翻译修改功能,允许用户选择合适的词意

dictionary-overlay's People

Contributors

ginqi7 avatar qingshuizheng avatar manateelazycat avatar suliveevil avatar jousimies avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.