Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the prefix keys #7

Open
a12l opened this issue May 23, 2023 · 4 comments
Open

Change the prefix keys #7

a12l opened this issue May 23, 2023 · 4 comments

Comments

@a12l
Copy link

a12l commented May 23, 2023

Is there a nicer way to change the rebinding of C-c and C-x from C-d and C-e to s-c and s-x respectively?

(use-package wakib-keys
  :config
  (define-key wakib-keys-overriding-map (kbd "C-d") nil)
  (define-key wakib-keys-overriding-map (kbd "C-e") nil)
  (define-key wakib-keys-overriding-map (kbd "s-c") (wakib-dynamic-binding "C-c"))
  (define-key wakib-keys-overriding-map (kbd "s-x") (wakib-dynamic-binding "C-x"))
  (wakib-keys 1))
@darkstego
Copy link
Owner

Does the above code not work? That is the first method that comes to mind for me.

@nameiwillforget
Copy link

I tried to evaluate the code by a12l and it didn't spit out any error message in the newest version of Emacs, but it lso didn't seem to work, because it says "s-c" is unbound. More generally I'm working on a similar project where I'd like to reconfigure C-c, and I tried evaluating your keys.el with C-d replaced by C-p and with the keys list emptied, and it didn't give an error but also it didn't change the behavior of C-p. If I don't interfere with it otherwise it still sends backward-char and if I unbind it and then try the evaluation again it just says the key is unbound. Can you maybe take a quick look at this? As I said, I tried by replacing C-d and emptying the key list in your keys.el just to be sure it didn't work then, but before I tried to strip down the code to what should be necessary and used that:

(defun wakib-minor-mode-key-binding (key)
  "Function return all keymaps defind to KEY within minor modes.
This function ignores the overriding maps that will be used to override
KEY"
  (let ((active-maps nil))
    (mapc (lambda (x)
	    (when (and (symbolp (car x)) (symbol-value (car x)))
	      (add-to-list 'active-maps  (lookup-key (cdr x) (kbd key)))))
	  minor-mode-map-alist )
    (make-composed-keymap active-maps)))

(defun wakib-key-binding (key)
  "Return the full keymap bindings of KEY."
  (make-composed-keymap (list (wakib-minor-mode-key-binding key) (local-key-binding (kbd key)) (global-key-binding (kbd key)))))


(defun wakib-dynamic-binding (key)
  "Act as KEY in the current context.
This uses an extended menu item's capability of dynamically computing a
definition.  This idea came from general.el"
  `(menu-item
	 ,""
	 nil
	 :filter
	 ,(lambda (&optional _)
	    (wakib-key-binding key))))


(define-key override-global-map (kbd "C-p") (wakib-dynamic-binding "C-c"))

Where override-global-map is the map bind-key* uses, which works similar to yours. If I use instead global-map and try C-p it says "C-p is undefined". Why could this be?

@darkstego
Copy link
Owner

If you only want to rebind the prefix key, then I suggest you look at my other project, rebinder. It is basically the rebinding part extracted out.

@nameiwillforget
Copy link

nameiwillforget commented Oct 11, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants