help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [emacs] tabs, spaces, and indentation


From: Nerius Landys
Subject: Re: [emacs] tabs, spaces, and indentation
Date: Mon, 11 Oct 2010 13:19:40 -0700


CC-mode gives you a lot of options for controlling indentation.

 M-x Info-goto-node RET (ccmode)Commands RET

The subsections "Indentation commands", "Minor Modes" and "Electric
keys" will probably be the most relevant for what you're trying to
accomplish.

For (1) something like

 (setq c-basic-offset 8
      indent-tabs-mode t
      c-insert-tab-function 'tab-to-tab-stop)

 (setq c-syntactic-indentation nil) ; maybe, or maybe not this one

should be close to the behavior you're looking for.

For (2), try

 (c-toggle-electric-state -1)



Thanks a lot for this information.  I have taken your tips and done additional online research.  I came up with the following .emacs file for this project that has absolutely horrid indentation and use of tabs:

  (defun my-c-mode-common-hook ()
    (c-toggle-electric-state -1)
    (define-key c-mode-base-map (kbd "TAB") 'self-insert-command))
  (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)


It almost behaves how I want now.  I hit Tab, it creates a tab.  It does not start indenting stuff when I type a special character such as a paren or a semicolon.  However, there is still one thing needed to make it behave just like Notepad.  Let's say my cursor is positioned immediately following a tab character.  When I hit Backspace (I believe that causes a function "backward-delete-char" to be called), it converts that tab character into a bunch of spaces, then deletes the last space.  I would really like Backspace to just delete the tab character.  Is there any way to do this?  I suppose I'd have to rebind Backspace to a function other than backward-delete-char, but I'm not sure which function.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]