Can't access snippets from all files of the same type


#1

I’m trying to use the snippet feature in atom, and I’m basically just using the default snippet modified for the php language. Here is what I have in snippets.cson.

'.text.html.php':
  'Snippet Name':
    'prefix': 'hello'
    'body': 'Hello World!'

The problem is that I can’t access this snippet from every php file within php tags. Am I missing something here? As I understand it, the .text.html.php sets which file type or tag context the snippet will work in, which should hold true for all of my PHP file. The file that I have been able to use the snippets in has all PHP code throughout, but the other file has a big HTML section, but is still a PHP file type.

I had a ton of snippets a couple of days ago that worked perfectly accross multiple files, but now nothing. Any idea what could be going wrong here?


#2

If you are initiating the snippet inside of php tags (<?php ?>), then use:

'.source.php':
  'Snippet Name':
    'prefix': 'hello'
    'body': 'Hello World!'

Outside of tags, use what you have.


#3

Shouldn’t the scope for the snippet basically be the language packages scope with a period before it like suggested in the flight manual? The scope shown by the php language package showed text.html.php.

Also I just tried with the following as the snippet, and it still wasn’t accessable even within the php tags.

'.source.php':
  'Snippet Name':
    'prefix': 'hello'
    'body': 'Hello World!'

I’m not sure if this could be a sign of something related to the problem, but I just noticed that two of my php files are being highlighted differently though both are php extensions. One colors the php tag, and the other doesn’t. In the file that colors the php tags, I can use the snippet, but in the file without colored tags, the snippets aren’t usable. Here’s a pic of the code as I see it.


#4

I’m not sure why it’s like that, but I know it works. Also, it’s handy to have separate snippets so you’re not adding php tags inside of php tags.


#5

Yes, seems related. Are the file extensions the same? Is there invalid code inside of the file that is causing the corruption? I would delete all text and gradually add lines back to see where it goes awry. (Make backups first.)


#6

I just did a little more checking, and I switched the scope for the snippet from .source.php to .text.html.basic which should be the scope for HTML language. Now the snippet is available in the files that wouldn’t work for the .text.html.php scope.

@dsandstrom, to answer your question, both files are PHP extension files. Four of the files I’m working with are master.php, routes.php, accounts.php, and newAccounts.php. The snippets set for the PHP scope are only working in routes.php and accounts.php. All files have a ton of HTML AND PHP in them except for the routes.php file.

This makes me think that there’s some issue with how atom is figuring out what language I’m using to apply snippet scope and syntax highlighting… At least that’s how it is starting to appear to me.


#7

GAH!!!

I just closed and opened the files and the syntax highlighting was corrected and the snippets were accessible. Maybe the parser or whatever needed to just reload or something… weird…

In the interest of covering information that could be super useful for new users of atom… I was gonna say that the scope you suggested seems like it’s supposed to point at source files since it’s documented in the flight manual that the scope should be made using the language package scope. But the repository for the snippets package built into atom suggests your method… So I’m not sure which one is proper, but after reloading those files that weren’t working, I tried both, and they both work.