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 475379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:22:57+00:00 2026-05-13T00:22:57+00:00

I usually use 4 white spaces to indent C programs, but in order to

  • 0

I usually use 4 white spaces to indent C programs, but in order to keep in consistent with some open source projects, I have to change to 2-white-space indenting sometimes.

Currently my indenting style is assigned in my .emacs file with

(setq c-basic-offset 4)

And when I want to work on those 2-white-space indenting projects. I have to close my Emacs, modify the value, and start again. Is there any simpler way to do this?

Many thanks.


PS.
Setting c-basic-offset variable every time I open a source file is too much work, is it possible to choose different value depending on working directory?

  • 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-05-13T00:22:57+00:00Added an answer on May 13, 2026 at 12:22 am

    Create a file in the directory you want to customize named .dir-locals.el, and edit it to contain:

    ((c-mode . ((c-basic-offset . 4))))
    

    Note: This is new functionality in Emacs 23.1.

    This takes advantage of the Per-Directory Local Variables. From the documentation in the link:

    The .dir-locals.el file should
    hold a specially-constructed list.
    This list maps Emacs mode names
    (symbols) to alists; each alist
    specifies values for variables to use
    when the respective mode is turned on.
    The special mode name `nil’ means that
    its alist applies to any mode.
    Instead of a mode name, you can
    specify a string that is a name of a
    subdirectory of the project’s
    directory; then the corresponding
    alist applies to all the files in that
    subdirectory.

    Here’s an example of a
    .dir-locals.el file:

     ((nil . ((indent-tabs-mode . t)
              (tab-width . 4)
              (fill-column . 80)))
      (c-mode . ((c-file-style . "BSD")))
      (java-mode . ((c-file-style . "BSD")))
      ("src/imported"
       . ((nil . ((change-log-default-name . "ChangeLog.local"))))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I usually use Visual Studio Team System 2008 Source Control Explorer with TFS, but
While doing performance testing on windows, i usually use perfmon. But when i put
I usually use Vim, and its great for the ability to do faster some
I have an input PDF file (usually, but not always generated by pdfTeX), which
This is driving me nuts. I usually use Tkinter for gui stuff, but just
I usually use XCode but was having a problem opening a file with this
Hi Just started learning c for uni (usually use objective c) and have run
I usually use the Hibernate ThreadLocal session management pattern in Java web projects: The
I usually use forward declaration predominantly, if I have a class that does not
I usually use a boolean 'firstTime' like this: in C++: bool firsTime = true;

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.