I have the coder module and the syntastic vim plugin installed. When I open a drupal file the content get's automatically formatted against the Drupal standard. Which is cool except I'm not told this happens. Then when I go to commit a change I see that I'm committing my change along with a bunch of formatting changes.

I like to separate my formatting commits from my fix or feature add commits.

I think that an option to disable this default behavior would be helpful.

Or in lieu of that, perhaps a comment that a format change happened would suffice.

Thanks for all your work with drupal vimrc. It's a really useful project!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

benjifisher’s picture

Status: Active » Postponed (maintainer needs more info)

This should not happen. I do not remember putting anything into the project that calls Coder automatically, so either I am forgetting something or else you have something in your setup that causes this behavior.

Either way, it will help if you can reproduce the problem on a clean system. (A fresh VM or a guest account should work.) Or if you can figure out which part of the code I am forgetting ...

dkinzer’s picture

Title: Add configuration to disable automatic coder feature. » Add configuration to disable automatic formatting feature.
Status: Postponed (maintainer needs more info) » Active

Well, I've taken a closer look at what is happening. Indeed coder is not being invoked automatically.

But there is automatic formatting happening.

in the drupal.vim plugin file line 6

PHP_removeCRwhenUnix = 1

It turns out the files I thought coder was reformatting had been saved with CRs in them. When they get removed, git sees that as a change in the file. When I disable this comment the CRs are not automatically removed. (I usually just run dos2unix on files like this and commit that as a change when I notice the CRs which I always highlight).

The other reason I thought coder was part of this issue was that syntastic was not being invoked on save like it usually is on my setup. But that was happening because the filetypes are being changed from php to php.drupal via the Drupalinit() function of the same file.

The latter of these I think I can fix just by configuring synstastic to work on php.drupal filetypes. But the former I was not able to override except by commenting out said line.

Anyway, I hope that clarifies it.

Thanks,

David

dkinzer’s picture

Status: Active » Closed (fixed)

OK, I figured out how to override that setting on my system.

I use pathogen and my .vimrc could not override your setting regardless of where I placed my local .vimrc override (i.e. before or after the call to pathogen#infect()). I guess that has something to do with the way pathogen works.

However using pathogen to add the override does work.

Create a dummy pathogen plugin with the following structure:

~\.vim\bundle
`--|z_overrides
     `--|plugin
          `--overrides.vim

And to the overrides.vim file add

let PHP_removeCRwhenUnix = 0

The z_overrides plugin gets called last by pathogen because pathogen#infect() loads the plugins in Asc alphabetical order (you can verify this by running the :scriptnames command).

If you run the command :echo PHP_removeCRwhenUnix, the result will now be 0 instead of 1, and Vim will not automatically replace the CR characters in Unix.

benjifisher’s picture

Status: Closed (fixed) » Needs review
FileSize
6.32 KB

I am re-opening the issue, since I think the process for overriding is too complicated. Basically, I agree with the original post (just not the source of the problem).

The attached patch moves the setting from plugin/drupal.vim to one of the example vimrc files.

While I was at it, I reversed one of the other options set in ftplugin/drupal.vim: the 'ignorecase' option. This affects tag searches and code completion as well as manual searches. It has been a constant annoyance to me that this script sets that option.

Related issue: the ftplugin file is :source'd each time we enter the buffer. This means that if you manually:set ignorecase
and change to another file, then come back, the ftplugin overrides your decision. I rearranged the file, putting global settings (Syntastic and tags) near the top, then added a conditional :finish to avoid this problem.

I will leave this issue as NR briefly, but I plan to commit the patch later today.

dkinzer’s picture

Status: Needs review » Needs work

I don't think this patch is going to work the way you intend it because by default vim scopes the variable in the global scope when it is declared outside of a function.

In your patch you are referencing a variable in the buffer scope.

+if exists("b:did_drupal_ftplugin") | finish | endif
+let did_drupal_ftplugin = 1

You need to change the second line above to
let b:did_drupal_ftplugin = 1

Or change the first line to
if exists("g:did_drupal_ftplugin") | finish | endif

benjifisher’s picture

Status: Needs work » Needs review
FileSize
6.32 KB

@dkinzer:

Thanks for catching that. I definitely want buffer-local, not global. Revised patch attached.

dkinzer’s picture

Status: Needs review » Reviewed & tested by the community

This is working for me.

benjifisher’s picture

Status: Reviewed & tested by the community » Fixed

@dkinzer:

Thanks for the review! Committed: 1847306.

benjifisher’s picture

FileSize
741 bytes

Follow-up:

First off all, the commit link in #8 should be 95d5f69. I accidentally linked to this very issue.

Second of all, the ftplugin should be reloaded if the user does

:let b:did_ftplugin = 1
:e!

so I will changeif exists("b:did_drupal_ftplugin") | finish | endiftoif exists("b:did_drupal_ftplugin") && exists("b:did_ftplugin") | finish | endif

I think it is safe to commit this without review: 955dba8. I have also attached the patch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

benjifisher’s picture

The changes discussed in #4—#9 (not the OP) caused other problems and were partially reverted. See #1892948: Options are reset when reloading a file.

benjifisher’s picture

Issue summary: View changes

Fix grammar.