有道翻译提示框错位问题

在Emacs中配置了有道翻译,提示框会出现错位的现象。请问大家如何解决? 配置代码如下:

(use-package youdao-dictionary
  :ensure t
  :init
  (setq url-automatic-caching t)
  :config
  (global-set-key (kbd "C-c y") 'youdao-dictionary-search-at-point+))

问题如图:

1 个赞

改用posframe就没问题了

能否贴下具体配置呢?感谢。

有道翻译没有posframe 提示需要自己添加

可以试试 M-x youdao-dictionary-search-at-point-tooltip ,

是需要改代码,晚些时候我贴上来你参考下。

这个似乎不会错位,就是样式太丑

好的,感谢先😁

https://github.com/cnsunyour/youdao-dictionary.el/commit/61d81cbbb92d139775dbb00797b07e1cbcb3717e

你看一下,这是改用posframe的修改部分。整个文件的全部代码改动还包含改用了新的API,但是要要自己申请app_key和app_secret,暂时不需要。

楼上的看起来改动挺复杂啊,我这儿有个简单的供你参考。

1 个赞

主要是因为水平有限,另外想和原来的代码风格保持一致。不过我脸皮厚,不怕笑话,还能学习大佬的改动作品,涨知识不吃亏呢。

我钻牛角尖了,为什么我非要改原先的代码呢,自己再写一个方法不就可以了吗,看了你的代码真是有醍醐灌顶的感觉,发现我自己的想法真是太窄了

厉害了,原来还可以这么写的。我还跑去改了下源码。。:sweat:看来以后直接从大佬的配置中拷贝拷贝就可以

如果想成为一个贡献者,改源代码提交是正确途径,如果只是个人使用,改自己配置就ok,目的不同而已

如果是 PR 就从源代码入手,这没有什么问题的。只是针对这个 case,只需要增加一个函数,而不用修改已有的代码。这就是功能扩展,而且不会破坏原有的逻辑。

大佬的配置代码有个问题,就是会有闪烁,可能是由于清空buffer之后再insert造成的。我改成直接修改posframe内容了。

欢迎 PR 哈,我使用中没有发现这个问题。有个疑问,如果知己修改 posframe 内容,我的理解就是用:string,那就没法设置youdao-dirctionary-mode了啊。

我刚学习elisp没几天,不敢提PR😂。很多代码我也是看不懂,靠猜的。 你的配置:

(with-eval-after-load 'posframe
    (defun youdao-dictionary-search-at-point-posframe ()
      "Search word at point and display result with posframe."
      (interactive)
      (let ((word (youdao-dictionary--region-or-word)))
        (if word
            (progn
              (with-current-buffer (get-buffer-create youdao-dictionary-buffer-name)
                (let ((inhibit-read-only t))
                  (erase-buffer)
                  (youdao-dictionary-mode)
                  (insert (youdao-dictionary--format-result word))
                  (goto-char (point-min))
                  (set (make-local-variable 'youdao-dictionary-current-buffer-word) word)))
              (posframe-show youdao-dictionary-buffer-name :position (point))
              (unwind-protect
                  (push (read-event) unread-command-events)
                (posframe-hide youdao-dictionary-buffer-name)))
          (message "Nothing to look up")))))

我的修改如下:

  (with-eval-after-load 'posframe
    (defun youdao-dictionary-search-at-point-posframe ()
      "Search word at point and display result with posframe."
      (interactive)
      (let ((word (youdao-dictionary--region-or-word)))
        (if word
            (progn
              (posframe-show "youdao-dict-buffer"
			     :foreground-color "green"
			     :background-color "#222"
			     :string (youdao-dictionary--format-result word)
			     :position (point))
              (unwind-protect
                  (push (read-event) unread-command-events)
                (posframe-hide "youdao-dict-buffer")))
          (message "Nothing to look up")))))
1 个赞

对的,我就是用:string属性,不知道设置youdao-dirctionary-mode的用处是什么

在 tip 中主要是为了显示美观吧,是继承自org-mode。额外还有一些功能。

就别谦虚了,如果你真的认为有必要,还是欢迎提 PR。几天也可能比学几年的强啊。闪烁应该是由于 erase-buffer造成的。这是为了效率,用的 hide 而不是 delete,所以每次都要清空一次。