Coder Social home page Coder Social logo

dictionary-overlay's Introduction

Hi, I'm JinQiqi👋

I am a Software Engineer. Like Writting and Coding.

Buy me a cup of coffee

Github Stats

Most Used Languages

Recent Activity

activity graph

dictionary-overlay's People

Contributors

ginqi7 avatar jousimies avatar manateelazycat avatar qingshuizheng avatar suliveevil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dictionary-overlay's Issues

wrong-type-argument stringp nil

reproduce

cd ~/.config/emacs
emacs -Q -l test.el

M-x dictionary-overlay-start

test.el

(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)

debug

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)

(sit-for 1) needed for dictionary-overlay-start to finish loading?

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:

image

(defun dictionary-overlay-render-buffer ()
"Render current buffer."
(interactive)
(when (not (member "dictionary-overlay" websocket-bridge-app-list))
(dictionary-overlay-start))
(setq-local dictionary-overlay-active-p t)
(dictionary-overlay-refresh-buffer))

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))

[feature] add lookup support, allow 3rd dictionary to chime in

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.

websocket-send-text: Cannot send message to a closed websocket: #s(websocket-frame text

image

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'?

`

第二次执行 `dictionary-overlay-mark-word-unknown` 时渲染失败。

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)
;; }}}

Lisp error: (void-function string-split)

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)

dictionary-overlay-sdcv-dictionary-path路径设置问题

我用的skywind3000的edict词典,这个比较全比较大。我实在没想到哈利·波特1也有这么多自带词库找不到的单词。。。。

假设/home/jack/a这个目录下包含startdict词典的三个文件。我应该把dictionary-overlay-sdcv-dictionary-path设置为“/home/jack/a”吗,如此设置的话查询单词会报错。难道这是词库的问题?

Got error: Cannot send message to a closed websocket

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

Overlay rendering should stay in dedicated buffer

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.

image

My point is:

  1. Are we able to restrict the rendering process to the targeted buffer, without overflowing?
  2. When the targeted buffer is killed, the rendering process should stop, otherwise it would rendering everywhere.

Edited:
3. How do I know the rendering process is done, so I can add some hooks to it.

[提问] 关于文档部分,要写三次么?

文档包涵了三个地方:

  1. defcustom/defvar/defun 本身带doc;
  2. .el文件顶端又写了一部分
  3. readme.org

第2个是不是可以考虑去掉,写三个地方有点儿累手,修改的时候也容易遗漏。

[request] Add a local var, Detects whether the current buffer is actively rendering

当前版本,运行'dictionary-overlay-mark-word-unknown' or 'dictionary-overlay-mark-word-known' 会自动渲染当前buffer 给出翻译。但有时候,在书写场景,而非阅读场景。dictionary-overlay 会产生干扰。

因此需要增加一个local var, 只有主动调用dictionary-overlay-render-buffer 时,才把当前buffer 标记会可被渲染。

Debugger entered--Lisp error: (wrong-type-argument stringp nil)

安装后启动失败。以下是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

websocket parse json error

image

Sometimes there will be an error like that:

⛔ Error (websocket): in callback `on-message': could not parse JSON stream: "unable to decode byte 0xc3", "", 1, 0, 0

It won't affect this tool's usability, but it bothers me.

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.