Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议增加一个本地词典查询 #29

Open
heisaari opened this issue Jun 23, 2022 · 2 comments
Open

建议增加一个本地词典查询 #29

heisaari opened this issue Jun 23, 2022 · 2 comments

Comments

@heisaari
Copy link

为了加快查询速度(在线查结果总是要等一下才能出来)
建议结合https://github.com/skywind3000/ECDICT
增加一个本地简明英汉的查询结果,这样不仅速度快,断网的时候也能用

@kimim
Copy link

kimim commented Jun 17, 2023

Hello, I combined the power of sdcv with fanyi.el:

  (require 'sdcv)
  (defun kimim/sdcv-translate-result-advice (word dictionary-list)
    (let* ((arguments
            (cons word
                  (mapcan
                   (lambda (d) (list "-u" d)) dictionary-list)))
         (result (mapconcat
                  (lambda (result)
                    (let-alist result
                      (format
                       "## %s\n%s\n\n" .dict .definition)))
                  (apply #'sdcv-call-process arguments)
                  "")))
    (if (string-empty-p result)
        sdcv-fail-notify-string
      result)))

  (advice-add 'sdcv-translate-result
              :override
              #'kimim/sdcv-translate-result-advice)

  (defun kimim/fanyi-dwim-add-sdcv (word)
    (let ((buf (get-buffer fanyi-buffer-name)))
    (with-current-buffer buf
      (let ((inhibit-read-only t)
            (inhibit-point-motion-hooks t))
        ;; Clear the previous search result.
        (point-max)
        (insert "# SDCV\n\n")
        (insert
         (sdcv-search-with-dictionary
          word sdcv-dictionary-complete-list))
        (insert "\n\n")
        (beginning-of-buffer)))))

  (advice-add 'fanyi-dwim :after
              #'kimim/fanyi-dwim-add-sdcv)

@condy0919
Copy link
Owner

我在 emacs-china 上看到你发的帖子了!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants