Sublime Forum

Plugin to hlep with img tags in HTML

#15

If you look at the source of my plugin, I built my own custom callback for competions. SAY WHAT!?! The plugin uses a combination of macros, keybindings, and on_query_context to intercept completions and call my own custom textCommand on completion (MAGIC!). From there I can just hook a call to the get_image_size form zen. The problem isn’t the integration with the plugin. I can do that just fine. The problem: I can’t get get_image_size to work. Feeding it a path just causes a bunch of errors. So if you can get that to do anything, let me know. If not, I’ll just yell at @castles until he fixes it :smile:

0 Likes

#16

[quote=“C0D312”]

If you look at the source of my plugin, I built my own custom callback for competions. SAY WHAT!?! The plugin uses a combination of macros, keybindings, and on_query_context to intercept completions and call my own custom textCommand on completion (MAGIC!). From there I can just hook a call to the get_image_size form zen. The problem isn’t the integration with the plugin. I can do that just fine. The problem: I can’t get get_image_size to work. Feeding it a path just causes a bunch of errors. So if you can get that to do anything, let me know. If not, I’ll just yell at @castles until he fixes it :smile:[/quote]

i didn’t look but i think i might know what the problem is – get_image_size doesn’t want a path – it wants the byte stream of the file. so instead of sending it the path, do a python file.read() and send get_image_size the output. tell me if you don’t get what i’m saying or if it doesn’t work and i’ll play with it.

0 Likes

#17

Silly me. I got it working :smiley:

Now I just need to add everything together.

0 Likes

#18

[quote=“C0D312”]Silly me. I got it working :smiley:

Now I just need to add everything together.[/quote]

BTW. This got me thinking. Perhaps Will Bond should consider adding a way to list dependencies in Package Control. While I’ll probably just taking the get_image_size out of zen and putting it in a separate folder, if more developers start wanting to build off one another, it would be awesome to have something a way to do so. It could work kind of like Cydia for jailbroken iPhones; when downloading a plugin, it would say: this plugin requires x and y, install those too?

0 Likes

#19

Just added image dimensions to the beta branch of AutoFileName. I’d like some feedback before I add it to the main branch though. Thanks.

0 Likes

#20

It’s nice to be able to see the image dimensions in the popup. I still don’t see the absolute path working as I require. Ideally, one should be able to define any directory as root.

0 Likes

#21

Are you using the beta branch? If so, those are options in the sublime-settings file.

It should use the root of the current project now. Is that not the case? Or are you looking for something else? Also, changing “afn_proj_root” allows for a custom root.

0 Likes

#22

nice work. i just pulled the beta [6b6ffda] and i can see the image dimensions in the auto-complete popup.

now all we need is for the height/width attributes of the tag to be written/updated and this will truly rock.

EDIT: in other words… that part isn’t working for me.

0 Likes

#23

Ah ok, I didn’t see that. I did enter a custom root, keeping auto_file_name_use_project_root to true, but it still doesn’t seem to work, even when I define a Project.

Also, like pjv, I see the dimensions, they just aren’t written.

Using: ST2 2181, OS X Lion

0 Likes

#24

more info: when i do the completion, nothing happens. and nothing in the console either. my test is a simple .html file and i am just entering a vanilla img tag and auto-completing with a .png image. i see the dimensions in the popup, so the problem is confined to what happens after i do the completion.

looking through your code in the AfnCommitCompCommand Class and typing bits and pieces into the console with the cursor inside the img tag after doing the completion, path = u'"/Volumes/hd/Users/paul/development/projects/belligerent act.org/site/img/ba-banner8.png"' could it be that path is ending in .png" rather than just .png that is making it not fire the append?

0 Likes

#25

apparently not. i tried changing to:

if 'img' in view.substr(view.line(sel)) and path.endswith(('.png"','.jpg"','.jpeg"','.gif"'))

and it still doesn’t write those attributes.

i guess it just looks like the custom post-completion callback isn’t running. i stuck a print command in the run function of Class AfnCommitCompCommand and it never prints to the console.

i’m on mac, ST2 2194

0 Likes

#26

Don’t worry. I see the problem. I’ll push a fix in a bit.

0 Likes

#27

Just pushed a much improved update that dynamically changes the width and height elements if they’re present. Let me know if it works this time. Thanks.

0 Likes

#28

[quote=“skube”]
Ah ok, I didn’t see that. I did enter a custom root, keeping auto_file_name_use_project_root to true, but it still doesn’t seem to work, even when I define a Project.

Using: ST2 2181, OS X Lion[/quote]

Could you describe what happens when you have an empty string and type ‘/’? Does it show the root of your disk or the root of your project? If there are no folders added to Sublime, it should show the root of your disk. Also, the custom root has to be an absolute path. Could you be more specific about what’s happening and what you would expect? Thanks.

0 Likes

#29

still no height and width attributes for me.

0 Likes

#30

Really? Anything in the console?

0 Likes

#31

OH!!! Just reallized why its not working for you. Silly me. You’ll have to add this to your user keybindings: [code] { “keys”: “tab”], “command”: “run_macro_file”, “args”: {“file”: “Packages/AutoFileName/commit-and-trim.sublime-macro”}, “context”:

{ “key”: “setting.auto_complete_commit_on_tab” },
{ “operand”: true, “operator”: “equal”, “match_all”: true, “key”: “afn_commit-n-trim” }
]
},
{ “keys”: “enter”], “command”: “run_macro_file”, “args”: {“file”: “Packages/AutoFileName/commit-and-trim.sublime-macro”}, “context”:

 { "key": "setting.auto_complete_commit_on_tab", "operator": "equal", "operand": false },
 { "operand": true, "operator": "equal", "match_all": true, "key": "afn_commit-n-trim" }

]
}[/code]

0 Likes

#32

aha, so that’s how you made the “callback” magic work.

excellent. working now.

one more request on this: can you put the dimension values inside double-qotes so they match the HTML spec? the tag would look like this:

<img src="/img/banner.png" height="44" width="420" alt="">

instead of this:

<img src="/img/banner.png" height=44 width=420 alt="">

thanks so much for all your work on this – this is one thing that i have really missed in ST2 (from espresso and textmate) when writing html code.

0 Likes

#33

My bad. Just pushed a fix. Been a while since I’ve written any HTML…

0 Likes

#34

If there are no outstanding bugs, I’ll move this to the main branch. @skube: let me know if you’re still having problems.

I’d also like someone using Windows to test it. Usually causes some problems when working with paths.

0 Likes