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

  • Home
  • SEARCH
  • 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 4531116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:52:22+00:00 2026-05-21T13:52:22+00:00

I want to load my file named my-c-setup.el when the c-mode is loading. So,

  • 0

I want to load my file named “my-c-setup.el” when the c-mode is loading. So, I’m using the function “autoload”.

With my python setup, it works well :

lang.el

(autoload 'python-mode "my-python-setup" "" t)

my-python-setup.el

(require 'python)
; ...

I’m trying to do the same with the c-mode, but i does not work :

lang.el

(autoload 'c-mode "my-c-setup" "" t)

my-c-setup.el

(setq c-basic-offset 4)
; ...

When I try to open a file in c-mode (test.c for example), I have the following error :

File mode specification error: (error "Autoloading failed to define function c-mode")
  • 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-21T13:52:23+00:00Added an answer on May 21, 2026 at 1:52 pm

    Autoload is not what you’re looking for. What it does is simply load some code the first time it is needed, which is a handy way to extend Emacs’ functionality while still keeping the start-up time low.

    To solve your problem, we gotta think about what you really want to do: do you simply want some of your code to be loaded at some point, or do you want buffer-local customizations for ever buffer that is in c-mode?

    If you simply want Emacs to load your code at start-up, either put your code directly into your .emacs file or use load-file or require instead of autoload:

    load-file simply takes a file name, loads the lisp code in that file and evaluates it. So if your code is in a file named “/path/to/my-c-setup.el”, you could put the following line in your .emacs, and the code will be loaded on every start-up:

    (load-file "/path/to/my-c-setup.el")
    

    Perhaps you don’t want to give the absolute path name for every file you load. In that case, you could use the function load-library instead which is similar to load-file but tries to find the given filename in any of the directories stored in the variable load-path:

    (add-to-list 'load-path "/path/to")
    (load-library "my-c-setup.el")
    

    The advantage is that you have to do the add-to-list part only once, and all subsequent calls to load-library will be able to find code in that directory.

    An alternative way is the provide/require mechanism: you can make your .el-file “provide” some feature by putting a (provide 'feature) call in it, e.g.

    (provide 'my-c-mode-customizations)
    

    Then put an according (require 'feature) in your .emacs file, and your code will be loaded as well:

    (require 'my-c-mode-customizations)
    

    However, if you want your code only be loaded when c-mode is activated on a buffer, the way to achieve that is through Emacs’ Hook mechanism:

    A hook is a variable where you can
    store a function or functions to be
    called on a particular occasion by an
    existing program.

    Most major modes provide a customizable hook variable to which you can add functions that will be called whenever the major mode is invoked. For instance, c-mode provides c-mode-hook. In order for your own customizations to be called whenever c-mode is turned on for a buffer, put them in a function, say, my-c-mode-customizations and add the following line to your .emacs file:

    (add-hook 'c-mode-hook 'my-c-mode-customizations)
    

    Of course, you still need autoload for Emacs to actually find the definition of that function.

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

Sidebar

Related Questions

I want to load a static text file from an HTML document without using
I want to do a simple thing - load a start file named other
I want to load a local file, example.pages in UIWebview. I tried with this
I want to load a local jqmobile html file into a webview. I am
I want to load the contents of a php file to an already existing
I want to load some images into my application from the file system. There's
I want to load key/values configuration pairs stored in XML file. To bind a
I have a CSV file I want to load at boot of my Lift
We are receiving an XML file from our client. I want to load the
I want to use the ClassLoader to load a properties file for the Properties

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.