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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:51:39+00:00 2026-05-13T09:51:39+00:00

how would I figure this out? I added delete-trailing-whitespace to the before-save-hook in my

  • 0

how would I figure this out?

I added delete-trailing-whitespace to the before-save-hook in my c-mode-common-hook, but it looks like delete-trailing-whitespace is getting called for every file, not just buffers using c-mode and derivatives.

Can I make the before-save-hook buffer local?

  • 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-13T09:51:39+00:00Added an answer on May 13, 2026 at 9:51 am

    Add it to write-contents-functions instead:

    (add-hook 'c-mode-common-hook
      (lambda()
        (add-hook 'write-contents-functions
          (lambda()
            (save-excursion
              (delete-trailing-whitespace)))
          nil t)))
    

    As the Emacs Lisp Reference Manual explains:

    This works just like write-file-functions, but it is intended for hooks that pertain to
    the buffer’s contents, not to the particular visited file or its location. Such hooks are
    usually set up by major modes, as buffer-local bindings for this variable. This variable
    automatically becomes buffer-local whenever it is set; switching to a new major mode
    always resets this variable, but calling set-visited-file-name does not.

    This works properly for me in Emacs 24.2.1 (i.e., it deletes all trailing whitespace from C files but preserves trailing whitespace in all other file types).

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

Sidebar

Related Questions

I'm trying to figure out how this would be done in practice, so as
I can't quite figure out why this Linq Statement isn't working as i would
Why does this issue a badmatch error? I can't figure out why this would
I know almost nothing about cryptography, but I would like to figure out how
I have been trying to figure this out for several hours but have had
I figured this would be simple, but being new to SSRS I'm not sure.
I am a TDD newb and I would like to figure out how to
I'm trying to figure out what would be the most efficient (with respect to
I'm trying to figure out what would be causing a 1 minute delay in
I can't figure out what would be the best way to use Bucket Sort

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.