I am a Software Engineer. Like Writting and Coding.
ginqi7 / dictionary-overlay Goto Github PK
View Code? Open in Web Editor NEWEmacs 插件-辅助英文阅读
Home Page: https://qiqijin.com/cn/dictionary-overlay.html
Emacs 插件-辅助英文阅读
Home Page: https://qiqijin.com/cn/dictionary-overlay.html
I am a Software Engineer. Like Writting and Coding.
cd ~/.config/emacs
emacs -Q -l test.el
M-x dictionary-overlay-start
(setq package-enable-at-startup nil)
(package-initialize)
(setq debug-on-error t)
(add-to-list 'load-path "~/.config/emacs/extensions/websocket-bridge/")
(require 'websocket-bridge)
(add-to-list 'load-path "~/.config/emacs/extensions/dictionary-overlay/")
(require 'dictionary-overlay)
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
make-process(:name "dictionary-overlay" :buffer " *websocket-bridge-app-dictionary-overlay*" :command ("python3" "/Users/suliveevil/.config/emacs/extensions/diction..." "dictionary-overlay" nil))
apply(make-process (:name "dictionary-overlay" :buffer " *websocket-bridge-app-dictionary-overlay*" :command ("python3" "/Users/suliveevil/.config/emacs/extensions/diction..." "dictionary-overlay" nil)))
start-process("dictionary-overlay" " *websocket-bridge-app-dictionary-overlay*" "python3" "/Users/suliveevil/.config/emacs/extensions/diction..." "dictionary-overlay" nil)
(setq process (start-process app-name process-buffer command extension-path app-name websocket-bridge-server-port))
(progn (setq process (start-process app-name process-buffer command extension-path app-name websocket-bridge-server-port)) (set-process-sentinel process #'(lambda (p _m) (if (eq 0 (process-exit-status p)) (progn (save-current-buffer (set-buffer ...) (ansi-color-apply-on-region ... ...)))))) (add-to-list 'websocket-bridge-app-list app-name t))
(let* ((process (intern (format "websocket-bridge-process-%s" app-name))) (process-buffer (format " *websocket-bridge-app-%s*" app-name))) (progn (setq process (start-process app-name process-buffer command extension-path app-name websocket-bridge-server-port)) (set-process-sentinel process #'(lambda (p _m) (if (eq 0 (process-exit-status p)) (progn (save-current-buffer ... ...))))) (add-to-list 'websocket-bridge-app-list app-name t)))
(if (member app-name websocket-bridge-app-list) (message "[WebsocketBridge] Application %s has start." app-name) (let* ((process (intern (format "websocket-bridge-process-%s" app-name))) (process-buffer (format " *websocket-bridge-app-%s*" app-name))) (progn (setq process (start-process app-name process-buffer command extension-path app-name websocket-bridge-server-port)) (set-process-sentinel process #'(lambda (p _m) (if (eq 0 ...) (progn ...)))) (add-to-list 'websocket-bridge-app-list app-name t))))
websocket-bridge-app-start("dictionary-overlay" "python3" "/Users/suliveevil/.config/emacs/extensions/diction...")
dictionary-overlay-start()
funcall-interactively(dictionary-overlay-start)
call-interactively(dictionary-overlay-start record nil)
command-execute(dictionary-overlay-start record)
execute-extended-command(nil "dictionary-overlay-start" nil)
funcall-interactively(execute-extended-command nil "dictionary-overlay-start" nil)
call-interactively(execute-extended-command nil nil)
command-execute(execute-extended-command)
Not sure how you usually use this package.
I usually go to the target buffer, and "M-x dictionary-overlay-render-buffer RET", and wait for magic to happen.
There's a hiccup for this method, when dictionary-overlay has not started, and dictionary-overlay-refresh-buffer
is chasing after, this happens:
dictionary-overlay/dictionary-overlay.el
Lines 249 to 255 in 47edbeb
As a workaround, I add (sit-for 1)
to make it wait for .py to finish loading, but quite ugly.
Wondering if there's an elegant way to address it.
(defun dictionary-overlay-render-buffer ()
"Render current buffer."
(interactive)
(when (not (member "dictionary-overlay" websocket-bridge-app-list))
(dictionary-overlay-start)
;; wait 1 sec for "dictionary-overlay.py" to finish loading
(sit-for 1))
(setq-local dictionary-overlay-active-p t)
(dictionary-overlay-refresh-buffer))
Though dictionary-overlay does a not-bad job in offering quick glance of word meanings, it is still too simple and sometimes provides wrong/off-topic meanings.
So I think we could allow third dictionaries to chime in, put it in fingertip, especially when you are inside overlay, one tap, and voila, a world of explanations.
A PR is ready #51 , not perfect, and caveat is, third party dictionary package gets word under cursor in their own way, and doesn't necessarily return the same word as dictionary-overlay gets. Good news is, I haven't met anything deviated too much.
dictionary-overlay/dictionary-overlay.el
Line 81 in 72835e7
请问这个要怎么配置啊?
orjson 3.8.2
(websocket-bridge-app-open-buffer 'dictionary-overlay)
`
WebSocket Client [dictionary-overlay] connected, the server port is 36479
Traceback (most recent call last):
File "/home/donald/.emacs.d/site-lisp/dictionary-overlay/dictionary-overlay.py", line 341, in
asyncio.run(main())
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
return future.result()
File "/home/donald/.emacs.d/site-lisp/dictionary-overlay/dictionary-overlay.py", line 299, in main
await asyncio.gather(init(), bridge.start())
File "/home/donald/.emacs.d/site-lisp/dictionary-overlay/dictionary-overlay.py", line 314, in init
with open(dictionary_file_path, "r", encoding="utf-8") as f: dictionary = json_parser.load(f)
AttributeError: module 'orjson' has no attribute 'load'. Did you mean: 'loads'?
`
Current version, when render buffer, it will remove all overlays on current buffer.
This will make some issues like :
it will remove org-mode's overlay
emacs -Q -l test.el
test.el
(setq package-enable-at-startup nil)
(package-initialize)
(setq debug-on-error t)
;; {{{ websocket-bridge
(add-to-list 'load-path "~/.config/emacs/extensions/websocket-bridge/")
(require 'websocket-bridge)
;; }}}
;; {{{ dictionary-overlay
(add-to-list 'load-path "~/.config/emacs/extensions/dictionary-overlay/")
(require 'dictionary-overlay)
;; dictionary-overlay-install ;; 安装依赖的 python 包
;; dictionary-overlay-install-google-translate ;; 安装 google-translate
;; variable
(setq dictionary-overlay-user-data-directory "~/.config/emacs/my-words")
(setq dictionary-overlay-just-unknown-words nil)
;; commands
;; dictionary-overlay-start ;; 启动 dictionary-overlay 应用
;; dictionary-overlay-restart ;; 重启 dictionary-overlay 应用
(global-set-key (kbd "s-R") 'dictionary-overlay-render-buffer) ;;使用翻译渲染当前 buffer
(global-set-key (kbd "C-c C-n") 'dictionary-overlay-jump-next-unkown-word) ;; 跳转到下一个生词
(global-set-key (kbd "C-c C-p") 'dictionary-overlay-jump-prev-unkown-word) ;; 跳转到上一个生词
(global-set-key (kbd "C-c C-f") 'dictionary-overlay-mark-word-known) ;; 标记当前单词为“已知”
(global-set-key (kbd "C-c C-s") 'dictionary-overlay-mark-word-unknown) ;; 标记当前单词为“生词”
;; 当前 buffer 中所有未标记为“生词”的单词全部标记为“已知”
(global-set-key (kbd "C-c C-a") 'dictionary-overlay-mark-buffer)
;; }}}
When I run the command "dictionary-overlay-lookup", display the follow messages:
Failed to open server localhost, continue with dict.org?(y or n)
dictionary-check-connection: Failed automatic server selection, please customize dictionary-server
Debugger entered--Lisp error: (void-function string-split)
string-split("288:300:conceptually:概念上" ":")
dictionary-overlay-last-unknown-word-pos()
dictionary-overlay-cursor-after-last-unknown-word-p()
dictionary-overlay-jump-next-unknown-word()
#(dictionary-overlay-jump-next-unknown-word)
apply(# dictionary-overlay-jump-next-unknown-word)
funcall-interactively(dictionary-overlay-jump-next-unknown-word)
#(dictionary-overlay-jump-next-unknown-word nil nil)
apply(# (dictionary-overlay-jump-next-unknown-word nil nil))
explain-pause--wrap-call-interactively(# dictionary-overlay-jump-next-unknown-word nil nil)
apply(explain-pause--wrap-call-interactively # (dictionary-overlay-jump-next-unknown-word nil nil))
call-interactively(dictionary-overlay-jump-next-unknown-word nil nil)
command-execute(dictionary-overlay-jump-next-unknown-word)
我用的skywind3000的edict词典,这个比较全比较大。我实在没想到哈利·波特1也有这么多自带词库找不到的单词。。。。
假设/home/jack/a这个目录下包含startdict词典的三个文件。我应该把dictionary-overlay-sdcv-dictionary-path设置为“/home/jack/a”吗,如此设置的话查询单词会报错。难道这是词库的问题?
After installing the package and dependencies, I ran dictionary-overlay-start
, I can see this in message buffer:
[WebsocketBridge] Server start websocket server on port 62124
When I invokedictionary-overlay-mark-buffer-unknown
, it raised the error:
websocket-send-text: Cannot send message to a closed websocket
When there's rendering process ongoing for an extremely long buffer, switching to another buffer would direct the rendering process to the new buffer where the cursor is at.
e.g., I'm rendering buffer on the right side, while waiting for it to finish, i click mouse at the left side, then the rendering focus switches to the left side, thus the messy, blotchy buffer on the left.
My point is:
Edited:
3. How do I know the rendering process is done, so I can add some hooks to it.
Per title:
Jump to first unknown word and last unknown word.
I hope I can do it, unfortunately I know nothing about python. /shrug
文档包涵了三个地方:
第2个是不是可以考虑去掉,写三个地方有点儿累手,修改的时候也容易遗漏。
当前版本,运行'dictionary-overlay-mark-word-unknown' or 'dictionary-overlay-mark-word-known' 会自动渲染当前buffer 给出翻译。但有时候,在书写场景,而非阅读场景。dictionary-overlay 会产生干扰。
因此需要增加一个local var, 只有主动调用dictionary-overlay-render-buffer 时,才把当前buffer 标记会可被渲染。
When meet an exception like network erro, the dictionary-overly will shutdown. A exception handle is required
安装后启动失败。以下是debug-init打开后的输出。系统:ubuntu22.04@wsl2
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
encode-coding-string(nil utf-8)
dictionary-encode-charset(nil "")
dictionary-do-search(nil "" dictionary-display-search-result)
dictionary-new-search-internal(nil "" dictionary-display-search-result)
dictionary-new-search((nil . ""))
dictionary-lookup-definition()
eval((dictionary-lookup-definition))
custom-initialize-reset(dictionary-overlay-lookup-with (funcall #'(closure (t) nil "" 'dictionary-lookup-definition)))
custom-declare-variable(dictionary-overlay-lookup-with (funcall #'(closure (t) nil "" 'dictionary-lookup-definition)) "Look up word with fn." :group dictionary-overlay :type (function))
eval-buffer(#<buffer load-735152> nil "/home/zwf/.emacs.d/site-lisp/dictionary-overlay/di..." nil t) ; Reading at buffer position 7416
load-with-code-conversion("/home/zwf/.emacs.d/site-lisp/dictionary-overlay/di..." "/home/zwf/.emacs.d/site-lisp/dictionary-overlay/di..." nil t)
#(dictionary-overlay)
apply(# dictionary-overlay nil)
(prog1 (apply orig feature args) (if (and (not already-loaded) (memq feature features)) (progn (let ((time (sanityinc/time-subtract-millis (current-time) require-start-time))) (add-to-list 'sanityinc/require-times (list feature require-start-time time) t)))))
(let* ((already-loaded (memq feature features)) (require-start-time (and (not already-loaded) (current-time)))) (prog1 (apply orig feature args) (if (and (not already-loaded) (memq feature features)) (progn (let ((time (sanityinc/time-subtract-millis ... require-start-time))) (add-to-list 'sanityinc/require-times (list feature require-start-time time) t))))))
sanityinc/require-times-wrapper(# dictionary-overlay)
apply(sanityinc/require-times-wrapper # dictionary-overlay)
require(dictionary-overlay)
eval-buffer(#<buffer load-351775> nil "/home/zwf/.emacs.d/lisp/init-local.el" nil t) ; Reading at buffer position 3586
load-with-code-conversion("/home/zwf/.emacs.d/lisp/init-local.el" "/home/zwf/.emacs.d/lisp/init-local.el" t t)
#(init-local nil t)
apply(# init-local (nil t))
(prog1 (apply orig feature args) (if (and (not already-loaded) (memq feature features)) (progn (let ((time (sanityinc/time-subtract-millis (current-time) require-start-time))) (add-to-list 'sanityinc/require-times (list feature require-start-time time) t)))))
(let* ((already-loaded (memq feature features)) (require-start-time (and (not already-loaded) (current-time)))) (prog1 (apply orig feature args) (if (and (not already-loaded) (memq feature features)) (progn (let ((time (sanityinc/time-subtract-millis ... require-start-time))) (add-to-list 'sanityinc/require-times (list feature require-start-time time) t))))))
sanityinc/require-times-wrapper(# init-local nil t)
apply(sanityinc/require-times-wrapper # (init-local nil t))
require(init-local nil t)
eval-buffer(#<buffer load> nil "/home/zwf/.emacs.d/init.el" nil t) ; Reading at buffer position 4495
load-with-code-conversion("/home/zwf/.emacs.d/init.el" "/home/zwf/.emacs.d/init.el" t t)
load("/home/zwf/.emacs.d/init" noerror nomessage)
startup--load-user-init-file(#f(compiled-function () #<bytecode -0x80fd433f0380fec>) #f(compiled-function () #<bytecode -0x1f3c686ddc0ca9b5>) t)
command-line()
normal-top-level()
另外,之前曾经成功使用过。但是dictionary-lookup-definition一直不能用,说没有definition.不知如何解决?
我现在用的词典和猫大的不一样,如果能允许自定义词典位置和字段查询就好了。
sdcv_dictionary_path = os.path.join(
os.path.dirname(__file__), "resources", "kdic-ec-11w"
)
sdcv_dictionary = Dictionary(sdcv_dictionary_path, in_memory=True)
sdcv_words = {}
candidates = []
for word in sdcv_dictionary.keys():
first_line_translation = sdcv_dictionary.dict[word].split()[0]
candidate_word = word.lower().replace('"', " ")
candidate_translation = first_line_translation.split(".")[-1].split(";")[0]
sdcv_words[candidate_word] = candidate_translation
I put it here as a reminder. 😄
The command is for undoing the most recent (word/buffer) mark.
It seems that it does not work for markdown buffer, and the elfeed test passes
通过连词符号“-”拼接的词,会被认为是两个词,举例: shake-up, 只会识别出 shake 或者 up,即使手动mark 选择 shake-up也不能添加到生词
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.