Sublime Forum

Plugin to hlep with img tags in HTML

#35

working perfectly for me now on os x.

thanks again for a really useful plugin.

0 Likes

#36

Wow, good work everyone. Unfortunately I don’t visit the forum enough to have actually kept up to date on this matter, but I’m so glad the community’s taken the idea on!

This looks promising. I’m currently awaiting the code to be merged into master so I can use Package Manager so test the functionality but it looks like it’s going to be about right. It’s a shame there’s no scope specifically for src-attribute-in-img-tag (I’m aware this could almost certainly be added to the tmLanguage definition, but would rather not use anything custom other than a plugin) and that we have to rely on completions that start with a slash in an HTML double quoted string, but hey. In fact because all our images go in a directory called ‘images’ and we use properly relative links (not site-relative) then I can presumably change the AutoFileName completion key to “i” rather than “/”. Is there a nice to way to make it recurse into directories without having to accept the completion and then re-autocomplete? As I said, all our images are in “images/”, so I’d like it to be able to find anything in there and allow Sublime’s fuzzy matching to do its work on that. Is there a setting or anything to allow it to return all files for this case?

My guess is that the plugin is not supposed to be used just for img tag src attributes, hence not being able to satisfy my specific requirements without ruining the other functionality of the plugin. For instance, I’d be happy if it just returned all *.png, *.jpg and *.gif files under the project root (or even a specific directory under project root (images)) but that’d gimp the plugin for other types of file inclusion, presumably? Maybe there could be a specific auto-completion command for being inside an img tag that can use this functionality, paired with some settings for other peoples’ specific needs. I’m certainly no Python developer but I’ll try to have a look into messing around with the plugin to so something like this. Like I said, I’d rather not mess with the tmLanguage file, as clean as that would be for knowing when I’m in an img tag and src attribute, so it’ll probably have to do some searching, or maybe the keybinding can do what’s required.

0 Likes

#37

What OS are you using? If you’re on windows, would you be willing to test the beta branch? I’m not going to merge to the master branch until is tested a little more thoroughly, especially because windows always has trouble with paths.

This is no longer an issue. In the latest version, I made some pretty big changes to how paths are found. Now you can even have an empty string and AutoFileName will activate.

This has also changed in the latest version. Now when you insert a folder, it will not insert the slash. So pressing a slash again will trigger the autocomplete.

With the new path handling, AutoFileName has support for wildcards. So it you type in |.png with | as your cursor, and trigger the autocomplete, it will only display pngs.

Let me know if that suits your needs. I’m playing on changing a few things later, so somethings are subject to change. That’s why I have it in the beta branch, so people aren’t confused as to why I keep changing everything :smile:

0 Likes

#38

Hmm… I must be doing something wrong because I can’t get it to work. I grabbed the latest beta and now when I try to select an image it I get an error: unable to open commit-and-trim.sublime-macro. However I only get this error when I use the keyboard to select an image. When I directly select the image with the mouse pointer I get no image. In both cases I don’t get dimensions (either in the popup or in the output). No other errors in the console.

Weird, since it was working.

edit: Ok, I knew why I got the error. I forgot I installed in AutoFileNameBeta directory and forgot to update the path in user keybindings. However, it still is not giving the dimensions.

0 Likes

#39

@skube, what OS are you on?

0 Likes

#40

OSX Lion

0 Likes

#41

when you say “no dimensions,” do you mean it doesn’t insert ‘width and height’ attributes in the img tag? Do the height and width appear next to images in the autocomplete popup?

0 Likes

#42

Neither. Nothing in the popup, and no attributes.

0 Likes

#43

hmm… not sure what the problem could be. It might help if you gave me more info. Could you send me a basic snippet of code you’re using it with?

Also, could you humor me by re-downloading the beta branch, making the branch is set to ‘beta’ in git (this has caused some problems in the past. When you download a branch from github, it could still be set to master.) You mentioned having AutoFileNameBeta as the folder. Do you still have AutoFileName (master) installed? Make sure that’s not installed too. Also, I don’t think its a problem but it might help, could you disable ZenCoding?

If there are no errors in the console, I’m not really sure what the problem is. Sorry.

0 Likes

#44

Yeah, it’s weird cause it was working (aside from writing out the attributes). This is what I did:

  • re-grabbed beta from Github (461b5dc),
  • removed ZenCoding,
  • updated autofilename.sublime-settings: “afn_proj_root”: “/Users/skube/Desktop”
  • made sure the User keybindings had the code you posted earlier
  • restarted ST2
  • created an HTML file as listed below and saved to the desktop
  • within the IMG tag typed “/” then Ctrl+Spacebar

[code]

<img src="/">
[/code]

The result:

  • the popup takes me to OS root (not the expected Desktop)
  • even after navigating to Desktop, the image file doesn’t show dimensions

In any case, thanks for all the work, perhaps it’s something silly and will be fine after you merge branches.

0 Likes

#45

COD312: I have git cloned the repo and checked out the beta branch (all in {packages}/AutoFileName) and there’s definitely one bug but not a big deal.

If you’re editing a new, unsaved document, the completions don’t work and the following comes up on the console:

Traceback (most recent call last):
  File "/Applications/Sublime Text 2.app/Contents/MacOS/sublime_plugin.py", line 236, in on_query_completions
    res = callback.on_query_completions(v, prefix, locations)
  File "./autofilename.py", line 83, in on_query_completions
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/posixpath.py", line 82, in split
    i = p.rfind('/') + 1
AttributeError: 'NoneType' object has no attribute 'rfind'

My guess is due to the ‘path’ of the current document being “” or None or something similar. As I said, not a big deal but something to consider.

As for use, I’ll have a proper test (OSX I’m afraid, though) but it’s great the beta version actually addresses my points. I have noticed, however, that there’s no automatic completions popup. I still have to to <img src="{ctrl+space} in order to get the popup. Is that correct? I haven’t done the suggested keybinding step in the README as it sounded like you said that is no longer required. Correct me if I’m wrong.

Finally, regarding my comment on png/jpg/gif, the only reason I said that (as I realise ST’s fuzzy completion negates the requirement there though) was to stop it having to load too many files for completion.

0 Likes

#46

This has already be addressed in an unpushlished ‘experimental’ branch.

Just added this :smile: (and it’s pretty awesome)

AutoFileName has more uses than just img insertion. So there is no reason to limit it. Was there a problem with using the wildcard to hide some results? Also, from a technical standpoint, if I told AutoFileName to only show images, it wouldn’t speed anything up because it would still need to look at every file to check the extension. The only really time killer is loading the image dimensions because it has to read in the image byte stream to get the dimensions :frowning: but don’t you worry about that.

Well, I added the wildcard because sometimes fuzzy completion isn’t enough. Typing in png will display results for pingpong.html or this_is_not_a_png.jpg. So instead you can have |.png.

Thank you. The more testers the better. That way I can find all the bugs and use cases before I merge.

@skube: Fortunately, the image dimensions stopped working for me too. So I can now better diagnose what the problem is.

0 Likes

#47

MERGED!

0 Likes

#48

Still doesn’t work for me :cry:

0 Likes

#49

Just the image dimensions? or the whole plugin?

0 Likes

#50

[quote=“C0D312”]

Just the image dimensions? or the whole plugin?[/quote]

just pulled the latest merged version and the behavior is all quite nice now. love how it autotriggers and i don’t even have to type the / anymore to keep digging down into directories.

alas, the writing of the height and width attributes is broken now. i can see the height and width in the autocomplete menu, but when i do the completion the attributes are not written into the img tag.

EDIT: in case you were wondering @C0D312, i got rid of the old keymap settings and am using the new ones from the latest commit.

0 Likes

#51

I’m investigating now. Any errors in the console?

EDIT: I found the bug. It was very stupid on my part. Hopefully it will work now. let me know

0 Likes

#52

Thanks. I’m actually impressed by how it feels. Almost native :smile: It’s the little things that count, not the fact that the image dimensions have taken me ages to get working…

0 Likes

#53

[quote=“C0D312”]I’m investigating now. Any errors in the console?

EDIT: I found the bug. It was very stupid on my part. Hopefully it will work now. let me know[/quote]

yes, working for me on the latest pull [f132583].

thanks again for all your work on this really useful plugin.

0 Likes

#54

Yay! Latest version works (sorta) for me again. It seems to work for one or two directories but then seems to fail.

I made sure to set the following in autofilename.sublime-settings:
“auto_file_name_use_project_root”: true,
“afn_proj_root”: “/mywebserverroot/”
and set the User Keybindings as before.

But I’m getting the following error in the console:

Traceback (most recent call last): File ".\sublime_plugin.py", line 236, in on_query_completions res = callback.on_query_completions(v, prefix, locations) File ".\autofilename.py", line 134, in on_query_completions File ".\autofilename.py", line 76, in fix_dir AttributeError: 'NoneType' object has no attribute 'get'

Also, I’m having another problem since updating where ST2 gives an intermittent error (not sure if it’s related*):
“Sublime Text 2 has stopped working
A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.”

Using ST2 2181 on Win7

*edit: I tried disabling the AutoFileName package and I didn’t get the error, so it’s definitely related.

0 Likes