I would like to bind my TAB key in emacs to clang-format-region when in C/C++ mode. How do I achieve this without affecting other modes? In particular, global-set-key doesn't achieve what I want, since it makes editing text with emacs a tad difficult.
You can use define-key
on c-mode-base-map (C, C++ ...)
(define-key c-mode-base-map (kbd "<tab>") 'clang-format-region)
You may use local-set-key
(add-hook
'c++-mode-hook
(lambda ()
(local-set-key (kbd "<tab>") #'clang-format-region)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With