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
270 stars 37 forks source link

Feature request: define a specific minor mode for the prompted buffer #76

Closed gynamics closed 1 week ago

gynamics commented 3 weeks ago

I found that there is no specific mode defined for the prompt buffer with :pick 'buffer (e. g. something like gt-prompt-buffer-mode), and there is no specific keybinds for it to switch languages or doing something else.

I know the minibuffer prompt supports keybindings, but, I think using a buffer for processing intermediate text is a good intersect to the whole workflow (you can run arbitrary text processing ultilities in it, or interact with other data before the translation is done), and it is just so attractive to edit in a separate buffer ... for example, when you want to switch the input method everytime you enter that buffer automatically _(` · ω <`_)

lorniu commented 2 weeks ago

there is no specific keybinds for it to switch languages or doing something else

There is. You can view or change the bindings through gt-buffer-prompt-map (M-x describe-keymap gt-buffer-prompt-map). Or you can read the source code in gt-extension.el:

(set-local-keys ()
   (local-set-key (kbd "C-c C-n") #'cycle-next-target)
   (local-set-key (kbd "C-c C-p") #'cycle-prev-target)
   (local-set-key (kbd "C-c C-e") #'set-engines)
   (local-set-key (kbd "C-c C-r") #'set-render))

I think using a buffer for processing intermediate text is a good intersect to the whole workflow ...

Agree.

This is what I am doing in chat branch, it implement the chat flow with ChatGPT in the buffer. Try it if you are interested.

I found that there is no specific mode.. switch the input method everytime you enter that buffer automatically..

Maybe hooks are more suitable for the cases. I will submit a commit later for it.

lorniu commented 2 weeks ago

Now can use gt-buffer-prompt-after-init-function to setup buffer. Such like:

  (defvar gt-buffer-prompt-after-init-function
    (lambda ()
      (insert "hello")
      (message "hello %s" (time-to-seconds))))

Please try.