I'm switching over to Emacs as my C++ editor, and what I miss the most is when I use tab, it would write 8 spaces, I could use tab more than once and use it in the middle of code, when I pressed back space it would remove the whole tab area, and it wouldn't auto indent. How can I make this happen? Thanks.
First, backspace. If you want to delete all whitespaces before point, try hungry-delete mode. If you would like to delete some whitespaces according to some indentation level, you could try to add this in you init.el:
(defun get-deletion-count (arg) "Return the amount of spaces to be deleted, ARG is indentation border." (if (eq (current-column) 0) 0 (let ((result (mod (current-column) arg))) (if (eq result 0) arg result)))) (defun backspace-some (arg) "Deletes some backspaces, ARG unused." (interactive "*P") (if (use-region-p) (backward-delete-char-untabify 1) (let ((here (point))) (if (eq 0 (skip-chars-backward " " (- (point) (get-deletion-count 4)))) (backward-delete-char-untabify 1) (delete-region (point) here))))) (global-set-key [backspace] 'backspace-some)
In my config I assume indentation level == 4. It will delete all whitespaces before point until next indentation level (..., 16, 12, 8, 4, 0).
Second, tab. By default emacs indents all code according to your c-default-style and c-basic-offset variables. Try to configure them via (setq c-basic-offset 8) and your code will be indented with 8 spaces. Also you can override TAB key with some function which will insert 8 spaces like that:
(defun insert-some-spaces () "Inserts 8 spaces after point" (interactive) (insert " ") ) (global-set-key [tab] 'insert-some-spaces)