global minor mode 设置 map 有问题,请教帮忙看看什么地方不对

我试图创建一个 global minor mode,mode的map总是不对,当我 enable multi-screens-mode 的时候,定义的那些命令的快捷键变成了 []。快捷键应该是 C-M-] ] 这样的。不知道是我哪里写得不对么?代码如下:

(defgroup multi-screens nil
  "Multi-screens minor mode customization options."
  :prefix "multi-screens-"
  :group 'multi-screens)

(defcustom multi-screens-keybinding-prefix (kbd "C-M-]")
  "Specify multi-screens-mode keybindings prefix before loading."
  :type 'kbd
  :group 'multi-screens)

(defun multi-screens-scroll-other-frame ()
  "Scroll other frame.
This is helpful for multiple monitor screens."
  (interactive)
  (other-frame +1)
  (call-interactively 'scroll-up-command)
  (other-frame -1))

(defun multi-screens-scroll-other-frame-down ()
  "Scroll other frame down.
This is helpful for multiple monitor screens."
  (interactive)
  (other-frame +1)
  (call-interactively 'scroll-down-command)
  (other-frame -1))

(defvar multi-screens-mode-map
  (let ((map (make-sparse-keymap)))
    (unless (keymapp map)
      (global-set-key multi-screens-keybinding-prefix map)
      (define-key map (kbd "]") 'multi-screens-scroll-other-frame)
      (define-key map (kbd "[") 'multi-screens-scroll-other-frame-down))
    map)
  "Multi-screens-mode map.")

;;;###autoload
(define-minor-mode multi-screens-mode
  "Multi-screens global minor mode to controlling frames for multiple screens."
  :require "multi-screens"
  :global t
  :group 'multi-screens
  :keymap multi-screens-mode-map
  (if multi-screens-mode
      (message "multi-screens-mode enabled.")
    (message "multi-screens-mode disabled.")))
(defcustom multi-screens-keybinding-prefix (kbd "C-M-]")
  "Specify multi-screens-mode keybindings prefix before loading."
  :type 'kbd
  :group 'multi-screens)

(defvar multi-screens-prefix-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "]") 'multi-screens-scroll-other-frame)
    (define-key map (kbd "[") 'multi-screens-scroll-other-frame-down)
    map))

(defvar multi-screens-mode-map
  (make-sparse-keymap))

(define-minor-mode multi-screens-mode
  "Multi-screens global minor mode to controlling frames for multiple screens."
  :require "multi-screens"
  :global t
  :group 'multi-screens
  :keymap multi-screens-mode-map
  (define-key multi-screens-mode-map
    multi-screens-keybinding-prefix multi-screens-prefix-map))

建议这么写。但是你真的需要动态改prefix么?

谢谢,测试好用。 这其中是啥原因呢?

因为默认的prefix可能用户不喜欢所以,所以写成动态修改的了。