emacs-eaf / emacs-application-framework

EAF, an extensible framework that revolutionizes the graphical capabilities of Emacs
GNU General Public License v3.0
3.07k stars 232 forks source link

Can't bind keys for zoom in/out/reset in EAF PDF viewer #637

Closed ianyepan closed 3 years ago

ianyepan commented 3 years ago

Describe the bug Binding keys for zoom/in/out/reset won't work, while binding keys for scrolling up/down works flawlessly.

To Reproduce Use the following snippet to reproduce:

;; Won't work
  (eaf-bind-key zoom-out    "C--" eaf-pdf-viewer-keybinding)
  (eaf-bind-key zoom-in     "C-=" eaf-pdf-viewer-keybinding)
  (eaf-bind-key zoom-reset  "C-0" eaf-pdf-viewer-keybinding)

;; Works
  (eaf-bind-key scroll_up   "C-d" eaf-pdf-viewer-keybinding)
  (eaf-bind-key scroll_up   "d"   eaf-pdf-viewer-keybinding)
  (eaf-bind-key scroll_down "C-u" eaf-pdf-viewer-keybinding)
  (eaf-bind-key scroll_down "u"   eaf-pdf-viewer-keybinding)

Expected behavior I expect binding keys for zooming in/out/reset to work.

Versions (please complete the following info):

Additional context These are the first couple of lines of the variable "eaf-pdf-viewer-keybinding". Note that the zoom in/out/reset that I personally bound does NOT have double quotes around them. This is perhaps the entry point to the bug.

(("u" . #1="scroll_down")
 ("C-u" . #1#)
 ("d" . #2="scroll_up")
 ("C-d" . #2#)
 ("C-0" . zoom-reset)        ; <-- this line!
 ("C-=" . zoom-in)           ; <-- this line!
 ("C--" . zoom-out)          ; <-- this line!
 ("j" . "scroll_up")
 ("<down>" . "scroll_up")
 ("C-n" . #2#)
 ("k" . "scroll_down")
 ("<up>" . "scroll_down")
 ("C-p" . #1#)
 ("h" . "scroll_left")
 ("<left>" . "scroll_left")
 ("C-b" . "scroll_left")
 ("l" . "scroll_right")
 ("<right>" . "scroll_right")
 ("C-f" . "scroll_right")
 ("SPC" . "scroll_up_page")
 ("b" . "scroll_down_page")
 ("C-v" . "scroll_up_page")
 ("M-v" . "scroll_down_page")
 ("t" . "toggle_read_mode")
 ("0" . "zoom_reset")
 ("=" . "zoom_in")
 ("-" . "zoom_out")
...
MatthewZMD commented 3 years ago
;; Won't work
  (eaf-bind-key zoom-out    "C--" eaf-pdf-viewer-keybinding)
  (eaf-bind-key zoom-in     "C-=" eaf-pdf-viewer-keybinding)
  (eaf-bind-key zoom-reset  "C-0" eaf-pdf-viewer-keybinding)

;; Works
  (eaf-bind-key scroll_up   "C-d" eaf-pdf-viewer-keybinding)
  (eaf-bind-key scroll_up   "d"   eaf-pdf-viewer-keybinding)
  (eaf-bind-key scroll_down "C-u" eaf-pdf-viewer-keybinding)
  (eaf-bind-key scroll_down "u"   eaf-pdf-viewer-keybinding)

Have a closer look, you need zoom_out/zoom_in/zoom_reset instead of zoom-out/zoom-in/zoom-reset. I see you were checking out M-EMACS the other day, you can have a look at its EAF section.

This is because they're Python function bindings, you shouldn't use the Elisp function naming conventions, it was intentionally set this way so one can clearly differentiate Python functions from ELisp functions.

Maybe, maybe we should give an option to internally convert - to _, to avoid further confusion.

ianyepan commented 3 years ago

you need zoom_out/zoom_in/zoom_reset instead of zoom-out/zoom-in/zoom-reset

Oh man, of course! How did I miss that typo (😅)

Thanks, changing "-" to "_" completely fixed it!