Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9033007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:07:09+00:00 2026-06-16T08:07:09+00:00

Emacs doesn’t automatically indent line for me. For example: int main() { int a;

  • 0

Emacs doesn’t automatically indent line for me. For example:

int main() {
   int a;
int b; // this line still don't indent with int a
}

So, how to indent line in Emacs ? And moreover, each time I type {, how to make Emacs automatically indent a tab like other IDEs (eclipse, netbean …) ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:07:10+00:00Added an answer on June 16, 2026 at 8:07 am

    Emacs normal behaviour is to reserve the RET (Enter) key for inserting the carriage return literally, while it uses C-j (Ctrl+J) for entering and indenting. This is also so because of a range of other keys that can cause line to be re-indented. By tradition, the commands that cause re-indentation have “electric” as part of their name. c-mode has a bunch of “electric” commands. To find them, when editing a C source, you can do:

    • C-h b (Ctrl+H B) – list all key bindings in the buffer.

    • M-s o (Alt PC or Option Mac + S O) – invoke occur command, alternatively, you can M-xoccur.

    • Type “electric” when occur prompts you for input (after the previous step, the point will be in minibuffer, so just continue typing).

    It will open an additional buffer with the content similar to this:

    12 matches for "electric" in buffer: *Help*
        706:C-d             c-electric-delete-forward
        709:#               c-electric-pound
        710:( .. )          c-electric-paren
        711:*               c-electric-star
        712:,               c-electric-semi&comma
        713:/               c-electric-slash
        714::               c-electric-colon
        715:;               c-electric-semi&comma
        716:{               c-electric-brace
        717:}               c-electric-brace
        718:DEL             c-electric-backspace
        726:C-c C-l         c-toggle-electric-state
    

    This lists all the commands and the keys assigned to them, which do some “electric” action. You can move point to any of them and by pressing C-h f (Ctrl+H F) RET it will open the help page describing what exactly the command does. For example, if you request help on c-electric-colon it will show you this:

    c-electric-colon is an interactive compiled Lisp function in
    `cc-cmds.el'.
    
    (c-electric-colon ARG)
    
    Insert a colon.
    
    If `c-electric-flag' is non-nil, the colon is not inside a literal and a
    numeric ARG hasn't been supplied, the command performs several electric
    actions:
    
    (a) If the auto-newline feature is turned on (indicated by "/la" on
    the mode line) newlines are inserted before and after the colon based on
    the settings in `c-hanging-colons-alist'.
    
    (b) Any auto-newlines are indented.  The original line is also
    reindented unless `c-syntactic-indentation' is nil.
    
    (c) If auto-newline is turned on, whitespace between two colons will be
    "cleaned up" leaving a scope operator, if this action is set in
    `c-cleanup-list'.
    
    [back]
    

    You can continue reading the manual from here by moving the point to the item which looks like a hyperlink (usually it is underlined, or has different visual appearance, then the rest of the text), and hit RET. You can use C-b and C-f in *Help* mode to navigate back and forward between the pages you’ve already visited (or move the point to the [back] or [forward] buttons and press RET).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I indent if-then-else construct in emacs lisp, the else block doesn't indent properly.
Emacs doesn't properly indent C++ class definitions for allocators that have initializers with colons
This .gitignore doesn't ignore .emacs.d .* !.emacs.d but the following does ignore it: *
I currently use emacs to edit .java files and run eclipse. Eclipse doesn't automatically
How do you use line-wrap in emacs? So that the portion that doesn't fit
I'm editing a text-document styled on its own way of which Emacs doesn't recognize
I'm using emacs and auctex to write LaTeX documents. For some reason, M-e doesn't
Does emacs have support for big numbers that don't fit in integers? If it
I edit .ml in Emacs . tab key indents well one line. But when
In Emacs, how can I avoid line breaks within |...| when using M-q (fill-paragraph)?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.