Sublime Forum

Word auto-completion

#1

Hi,

Is there any way to get auto-completion for words from other files than the file I am currently working on?

I’d want to auto complete CSS classes / IDs when working on php files.

Thank you.

0 Likes

#2

It’s not possible; however, it could be possible with a plugin. I try to make it…

0 Likes

#3

Since I’m not a PHP dev, could you answer a quick question(s)?

In your PHP, do you indicate the name of the css file anywhere (for example: UseThisAsCSS = "style.css), or does it look at anything in your directory that ends in .CSS?

EDIT: How is your project structure set up? (are php and css in the same directory)?

0 Likes

#4

Hi C0D312,

The plugin would be great!

[quote=“C0D312”]
In your PHP, do you indicate the name of the css file anywhere (for example: UseThisAsCSS = "style.css), or does it look at anything in your directory that ends in .CSS?

EDIT: How is your project structure set up? (are php and css in the same directory)?[/quote]

I use this feature in PHPdesigner when working on WordPress projects. I think it looks for .css files and scans directories recursively i.e it doesn’t matter where the css files are.

But if it is a problem, scanning directory of the current file (or using .css from the same directory) should be enough for the start :smile:

0 Likes

#5

I already had a plugin that did something similar so I just made some modifications. Since I’m not positive what your looking for just let me know if there’s something you’d like me to change. I put the plugin on Github: https://github.com/BoundInCode/CSS-completion-for-PHP because it uses several files and so anyone can make a change if they need to.

Usage: in a PHP file, press ‘#’ to open the autocomplete box which lists all the classes and ids from your css file (in the current directory). Let me know if it should be in a different directory.

Enjoy. Hope this helps!

0 Likes

#6

wow it was quick

Thank you!

I copied the plugin into the packages folder. Pressing ‘#’ didn’t open auto-completion box… I tried to remap the ‘#’ to something else but still no success.

Did I miss something? Any dependencies?

EDIT:

  1. It works but only between php delimiters
<?php ...here it works... ?>
when I have code like this
?> <div class="[here I'd like to open auto-compl. box]"></div> <?php 

nothing happens

  1. It scans only first .css file found in directory

  2. the classes and ids should be printed without ‘.’ or ‘#’
    like ‘myclass’, not ‘.myclass’

Thank you

0 Likes

#7
  1. The reason for the first problem is because it looks for a particular scope, in this case: source.php. I’ll get a fix for that.
  2. This one will take a little longer.
  3. That’s an easy fix. I’ll post it shortly.

EDIT: That was a lot easier to fix than I thought. See the new version here: https://github.com/BoundInCode/CSS-completion-for-PHP

0 Likes

#8

Magnifique! :smile:

We have a brand new plugin!

Now I am going to look at some regex tutorial and play with your plugin (it prints classes with empty space after word).

btw is there any way to avoid showing duplicated classes and ids (words)?

Thank you so much C0D312.

0 Likes

#9

I removed the spaces and removed the duplicates. Check github for the changes.

0 Likes

#10

It didn’t work.

When I removed this line, the autocompl. box appeeared but with duplicated words.

completions = list(set(completions))
0 Likes

#11

Sorry that was my bad… It should be fixed now. Let me know. https://github.com/BoundInCode/CSS-completion-for-PHP

0 Likes

#12

Works like a charm.

Thanks for your work and patience!

0 Likes