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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:59:40+00:00 2026-05-17T06:59:40+00:00

I have a emacs mode hook code (defun php-mode-hook () (setq tab-width 4 c-basic-offset

  • 0

I have a emacs mode hook code

(defun php-mode-hook ()
  (setq tab-width 4
        c-basic-offset 4
        c-hanging-comment-ender-p nil
        indent-tabs-mode
          (not
            (and (string-match "/\\(PEAR\\|pear\\)/" (buffer-file-name))
              (string-match "\.php$" (buffer-file-name))))))

I need to ensure to call this function whenever i open a php file within emacs..
i have installed php-mode for emacs as well as added this code in .emacs file but it seems not to be working.. can anyone tell me how to add such customization code for emacs?

NOTE: I have recently migrated to emacs.. please be more descriptive while answering.. 🙂

Updated code1

(add-hook 'php-mode-hook
   '(lambda()
     (setq tab-width 4
      c-basic-offset 4
      c-hanging-comment-ender-p nil
      indent-tabs-mode
      (not
       (and (string-match "/\\(PEAR\\|pear\\)/" (buffer-file-name))
            (string-match "\.php$" (buffer-file-name)))))))
  • 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-17T06:59:41+00:00Added an answer on May 17, 2026 at 6:59 am

    Adding hooks to places provided by various modes usually works using the add-hook function. You defined a function with the name of the hook you wanted to use. Instead, you should define a function with another name, add add-hook that to the php-mode-hook:

    (defun my-php-settings ()
      ...)
    
    (add-hook 'php-mode-hook 'my-php-settings)
    

    In fact, you don’t even need to create a named function at all:

    (add-hook 'php-mode-hook
              (lambda ()
                (setq tab-width 4 ...)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my .emacs file, I have a c-common-mode-hook that sets c-basic-offset to 4, but
In my .emacs file, I have (setq transient-mark-mode nil) and yet transient-mark-mode is activated
I'm using the actionscript-mode-connors.el for indenting Actionscript 3 code in emacs. I have most
Here is the content from my .emacs file. (add-hook 'php-mode-hook (lambda () (c-set-style bsd)
I have emacs 23.3.1, running on windows. php-mode 1.5 from http://php-mode.sourceforge.net/ , Modified: 2008-11-04
I use Cocoa Emacs 23.1.91 and I want to always have hl-line-mode turned off
I have started using emacs org-mode recently to maintain my TODO lists. I have
I am writing a minor mode for HTML/PHP templates. I have a var with
Normally when you hit tab on an empty line in emacs python mode it
By scrutinizing the documentation , I have learned that Emacs haskell-mode ships with three

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.