سؤال

I'm trying to write a keybinding to comment current line which goes something like this for python.

(fset 'comment 
      (lambda (&optional arg)
    "Keyboard macro."
    (interactive "p")
    (kmacro-exec-ring-item (quote ("^A^[f^[b#" 0 "%d")) arg)))

(global-set-key (kbd "C-x /") 'comment)

How can I use the same keybinding on multiple languages say python and cpp? Is there anyway to identify the filetype and execute the keybinding accordingly?

هل كانت مفيدة؟

المحلول

You can save the keybinding only to a specific keymap:

(eval-after-load "python-mode"
    '(define-key python-mode-map "\C-x/" 'comment))
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top