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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:30:32+00:00 2026-05-23T11:30:32+00:00

Using emacs for multiple projects from legacy to current ones, I have to use

  • 0

Using emacs for multiple projects from legacy to current ones, I have to use multiple conventions, e.g. for comments or file headers. For example, I use this function to insert file headers for C++ files:

(defun mg-c-file-header()
  "Inserts a c/c++ file header"
  (if (boundp 'mg-auto-insert-style)
      (case mg-auto-insert-style
    (project-a
     (insert
      " * @file "(file-name-nondirectory buffer-file-name)"\n"
      " * \n"
      " * (c) 2000 - "( format-time-string "%Y" )" by someone\n"))
    (project-b
     (insert "/** another header*/\n"))
    (otherwise (message "Meh.")))))

I call this function in this context:

(setq auto-insert-alist
      '(
        (("\\.\\([C]\\|cc\\|cpp\\)\\'" . "C++ Program")
         nil
         ( mg-c-file-header )
         "// --- includes --- \n"
;; and do on....

I can set mg-auto-insert-style with M-x set-variable, that’s ok. But I would like to automatically set the variable depending on the path of the file for the current buffer. So if I open a buffer or visit a new file in ~/projects/project-a, mg-auto-insert-style should be project-a.

This would work, but not perfectly:

(ede-cpp-root-project "project-a"
 :file "~/projects/project-a/trunk/src/Makefile"
 :local-variables (list
   (cons 'mg-auto-insert-style 'project-a )))

If I create a new file, mg-auto-insert-style is not bound when the auto-insertion is done. Later, there’s no problem…

Do you have an idea?

cu, Markus

  • 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-23T11:30:33+00:00Added an answer on May 23, 2026 at 11:30 am

    I use auto-insert package, together with different templates to implement this. See my config as example (+ templates)

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

Sidebar

Related Questions

I am using emacs on MacOS 10.6 with Terminal. I have a white background.
I have just started using Emacs for the specific purpose of editing latex documents.
I am using emacs 23.2 with the GTK toolkit. I built emacs from source
I have been using emacs for a while for mainly python programming, and have
I have started using emacs org-mode recently to maintain my TODO lists. I have
I'm using emacs for python, and I'd like to have a nice useable shell
I am using emacs org-mode for managing my notes. Often I wish to use
I am a fairly new user of R and have started using Emacs Speaks
I am using Emacs 23 and php-mode.el 1.5.0. When I have this in my
I have been using emacs for some time now and am slowly getting the

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.