lorniu / go-translate

Translator on Emacs. Supports multiple engines such as Google, Bing, deepL, ChatGPT, StarDict, Youdao and so on.
GNU General Public License v3.0
274 stars 37 forks source link

evil mode #65

Closed paum3 closed 1 month ago

paum3 commented 8 months ago

Hi, thanks for your work!

I am using evil mode so there is an issue with keyboard shortcuts in Go-Translate. Do you have any suggestions? thanks paum

lorniu commented 6 months ago

I submitted an update. Since I am not very familiar with evil-mode, please help test it.

Now you can using leading key (default as SPC) for the shotcuts.

aaa70 commented 5 months ago

Hello, thank you for your work!

gts-implements.el:242:10: Error: Symbol’s value as variable is void: gts-buffer-evil-leading-key

I got a byte compile error with this, I guess. How can I avoid it?

Thanks,

paum3 commented 5 months ago

Hi, thanks for looking on it. For me on doomemacs when running gts-do-translate , it prompts for a word and after it there is a message: Invalid function: evil-define-key

lorniu commented 5 months ago

For me on doomemacs when running gts-do-translate , it prompts for a word and after it there is a message: Invalid function: evil-define-key

I just downloaded and tried it on doom and everything works fine, no errors as you said.

Doom from https://github.com/doomemacs/doomemacs, with config (x as leading key):

(setq gts-buffer-evil-leading-key "x")

Can you reinstall this package and have a try again?

lorniu commented 5 months ago

gts-implements.el:242:10: Error: Symbol’s value as variable is void: gts-buffer-evil-leading-key

No such error found here. Can you delete and reinstall this package to have a try again?

aaa70 commented 5 months ago

Hello lorniu, Thank you for your reply.

I've tried deleting and reinstalling it.

I got byte compile warning:

gts-implements.el: Warning: the function ‘evil-define-key’ is not known to
    be defined.

and native compilation error:

...lpa/go-translate-20240311.822/gts-implements.el: Error Symbol’s value as variable is void: gts-buffer-evil-leading-key

this time.

So I tried with vanilla emacs 29.2 setup. I got the same problem above. Is this caused by the emacs compile option or something?

lorniu commented 5 months ago

@aaa70 I can't reproduct the issue, but maybe it's caused by the evil-define-key macro. I updated, and can you test again?

aaa70 commented 5 months ago

Thank you for your quick change.

I installed evil-mode, after that gts-implements.el: Warning: the function ‘evil-define-key’ is not known to be defined. warning has gone when byte compiling. Before installed evil-mode, I'm still getting the same warning though.

And I'm still getting this error when native compilation:

.../go-translate-20240313.356/gts-implements.el: Error Symbol’s value as variable is void: gts-buffer-evil-leading-key

Maybe, it's only my environment. So please ignore the issue.

Thank you.

paum3 commented 5 months ago

Hi, for me the second commit resolved the message Invalid function: evil-define-key but I have the same issue with keys as before - h,j,k,l behaves as arrows (as in evil mode should) but I can't figure out how to use the other functionalities of go translate - eg how to get into help? pressing 'h' is movement key in evil mode. EDIT: I dont't know what is the purpose of gts-buffer-evil-leading-key but it seems it has no effect on my side.

lorniu commented 5 months ago

I dont't know what is the purpose of gts-buffer-evil-leading-key

If you add this in your init file:

(setq gts-buffer-evil-leading-key "x")

Then use x h for help, x y for tts, x q for quit, that is, use x as leading key.

The default value of gts-buffer-evil-leading-key is SPC, it's ok in evil mode of vanilla emacs, but not working in doom, because doom use SPC as global leading key. Maybe you should custom gts-buffer-evil-leading-key yourself like above to use a different key, or give some advices on how to improve it.

Thanks.

paum3 commented 5 months ago

I see. For me the 'x' key nor the others don't work. Probably because at least all the keys have some function in evil mode. I have no ideas how to resolve this, but anyway, thank you.

nasseralkmim commented 5 months ago

I'm an evil mode user and I was happy with the old behavior without the leader key. Is there a way to opt out? I also wonder if there is an easy way to change the keybindings.

lorniu commented 5 months ago

@nasseralkmim You can execute (setq gts-buffer-evil-leading-key "") and then have a try.

fredericgiquel commented 3 months ago

What about support of evil-mode with v3 ?

The new variable to set seems to be gt-buffer-render-evil-leading-key. But as we can see on this line, it's only taken into account for keys prefixed by "<". Why ?

lorniu commented 3 months ago

@fredericgiquel I haven't found the best solution for evil-mode yet.

Now you can bind keys yourself to gt-buffer-render-local-map.

I am not familiar with evil-mode or doom, so PRs or suggestions are welcome.

Update: I push a new commit, currently use , as prefix to trigger the keys before any better solution.