How can I code in C ++ with the same indentation style in both Vi and Emacs?

How can two developers work on the same C ++ code base so that they can work transparently? Is there a common indentation style for C ++ code that, once installed, two developers can create code with the same level of indentation.

I found Emacs very aggressive for indentation, it is trying to break through, and Vi is quite forgiving. But emacs styles (mixed tabs and spaces) are not so Vim friendly.

+3
source share
2 answers

Get Emacs to do what you want.

From my ~ / .emacs file:

(defun my-c-mode-common-hook ()
  (local-set-key "\C-h" 'backward-delete-char)
  ;; this will make sure spaces are used instead of tabs
  (setq tab-width 4 indent-tabs-mode nil)
  (setq indent-tabs-mode 'nil)
  (setq c-basic-offset 4)
  (c-set-offset 'substatement-open 0)
  (c-set-offset 'statement-case-open 0)
  (c-set-offset 'case-label 0)
  (c-set-offset 'brace-list-open 0)
)

(add-hook 'c-mode-hook 'my-c-mode-common-hook)
(add-hook 'c++-mode-hook 'my-c-mode-common-hook)
(add-hook 'perl-mode-hook 'my-c-mode-common-hook)
(add-hook 'cperl-mode-hook 'my-c-mode-common-hook)
(add-hook 'emacs-lisp-mode-hook 'my-c-mode-common-hook)
(add-hook 'nroff-mode-hook 'my-c-mode-common-hook)
(add-hook 'tcl-mode-hook 'my-c-mode-common-hook)
(add-hook 'makefile-mode-hook 'my-c-mode-common-hook)
+11
source

, , , , BSD "indent", . .

+7

Source: https://habr.com/ru/post/1717820/


All Articles