简体   繁体   English

Emacs扩展特定的键绑定

[英]Emacs extension specific keybinding

I'm trying to write a keybinding to comment current line which goes something like this for python. 我正在尝试编写一个键绑定来注释当前行,这对于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? 如何在python和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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM