lewislepton Posted May 10, 2015 Posted May 10, 2015 howdy all, this is just a quick question, but im working on using alfred as a text expander, which is working very well. but i will mainly be using it for coding. but one thing that happens in coding is that you change function names etc, and what im trying to do right now is work out how to make it even more special. now what i am thinking on is, is that i have a line of code, or even an entire keyboard function that is ready to go, but instead of the text being put in and then editing out what i need to change, i instead use alfred to put in arguments that change specific things in the text right away. ill post some code up to show exactly what i mean but just say i tap 'cmd-spacebar' to bring up alfred. i then type in something like '-keyboardmovement' and tap enter to put it in sublime text, it will put in this exact text function DEFAULT:key_down(key) if key == string.byte('LEFT') then DEFAULT-X = DEFAULT-X - DEFAULT-SPEED elseif key == string.byte('RIGHT') then DEFAULT-X = DEFAULT-X + DEFAULT-SPEED end if key == string.byte('UP') then DEFAULT-Y = DEFAULT-Y + DEFAULT-SPEED elseif key == string.byte('DOWN') then DEFAULT-Y = DEFAULT-Y - DEFAULT-SPEED end end now as you can see, i would now need to start editing everything that says 'DEFAULT', 'DEFAULT-X/Y' and 'DEFAULT-SPEED'. whilst its alright, it still means going back to edit. but, what i would like some sage like advice on, is how could i set arguments when first typing in '-keyboardmovement', that would then affect each 'DEFAULT' to my own liking. so when alfred is open, i type in '-keyboardmovement' then right after it asks for the first argument, which would be 'playerMove', the next argument would be for 'playerPosX', the next would be for 'playerPosY'... and so on. but then the output with my inputted arguments in alfred would then make the code look like this function playerMove:key_down(key) if key == string.byte('LEFT') then playerPosX = playerPosX - playerSpeed elseif key == string.byte('RIGHT') then playerPosX = playerPosX + playerSpeed end if key == string.byte('UP') then playerPosY = playerPosY + playerSpeed elseif key == string.byte('DOWN') then playerPosY = playerPosY - playerSpeed end end so, how could i work on something like that using alfred as the text expander? i know in sublime text when making cheap auto-complete in JSON, is that its has this type of way 'function(${1:first}, ${2:second})', but ive never used alfred to do this type of thing this will take me some time to make in the end. but id like to work on it as im going along in my coding, so i can put things in a take things out as im making stuff thanks to anyone who can point me in the right direction best
deanishe Posted May 11, 2015 Posted May 11, 2015 (edited) function(${1:first}, ${2:second}) is the format understood by Sublime's snippet expansion engine. UltiSnips uses something similar, while TextExpander uses an odd %-based format. Point is, to do what you want to do, you're first going to need a snippet expansion engine that can extract the placeholders from your snippet and replace them with user-provided text. This is not a super-easy thing to write, especially if you need support for nested snippets. Unless this is something you want to do as an interesting exercise, I'd recommend using a tool specifically designed for expanding snippets, like Text Expander. It does a much better job that Alfred could, as it's built specifically for that task. This is an example of the window that pops up if you type the trigger for a snippet that has placeholders: Edited May 11, 2015 by deanishe dfay 1
lewislepton Posted May 11, 2015 Author Posted May 11, 2015 (edited) cock balls. well i had a feeling it would be something like that since nobody had gotten back to me but i have been looking at textexpander, think i just wanted to keep to alfred and not have a second application running. but oh well. what i am asking for is quite big. maybe ill get back on the alfred one one day in the future. but i need to just get work underway really i more than likely will kepp on trying with alfred, because i love it so so any ideas on this for further study would be amazing to look at. though on talking about this. other text editors would be fine wont they? guessing since the snippets thing does squash the mutiple arguments with sublime? because im actually just using sublime until a text editor i want to use gets its much needed update, which is peppermint editor. its lovely, and only for mac, much like alfred. ill have a test thanks for your help. and if anyone else has any ideas then by all means please let me know thanks again *EDIT* i did post that wouldnt use textexpander, but i will give it a go. may as well because it will still be easier right now Edited May 11, 2015 by lewislepton
deanishe Posted May 11, 2015 Posted May 11, 2015 In my experience, all snippet/expansion software works fine with almost all applications with the exception of Java apps. AFAIK, all expansion apps work by manipulating the clipboard, and Java doesn't work with the system clipboard well enough for Text Expander etc. to work reliably. I imagine an Alfred-based snippet engine would work better with Java apps, depending on how energetically you change the clipboard. I can understand not wanting to have another app running (I'd love to be able to dump some of the many utilities I always have running), but unfortunately, most apps that also do XYZ tend not to do it as well as apps for whom XYZ is their raison d'être, which may or may not be an issue for a given user. FWIW, you might be able to pull the snippet expansion engine out of UltiSnips (it's written in Python, not vimscript, so it may be portable). If you could use that as a basis, implementing your own snippet expansion via Alfred would be a lot simpler to do. My main reservation about it would be the inability to see the entire snippet while you're filling in the placeholders in Alfred. That lack of context could be a little confusing for larger snippets.
lewislepton Posted May 11, 2015 Author Posted May 11, 2015 i have tried textexpander now. setup a few things. and i do quite like it. it does have some charm too it. i will still try and do something in alfred, just because. but for the time being i will stick to TE for what i need just now until i can get alfred to do my bidding see, the one thing that makes alfred perfect is that it pops up with a list of my functions when i type in, so i at least remember, you know. but oh well. it is what it is
dfay Posted May 11, 2015 Posted May 11, 2015 Just to add to deanishe's point, TE is built to do this stuff & it's much easier to set up there than to try to rig it up in Alfred.
lewislepton Posted May 11, 2015 Author Posted May 11, 2015 TE has been quite nice, and do see why many like it. shame i cant have a list pop up to show my list i have made, which will be more and more as i go on. but hey, its the trade off
deanishe Posted May 11, 2015 Posted May 11, 2015 (edited) TE has been quite nice, and do see why many like it. shame i cant have a list pop up to show my list i have made, which will be more and more as i go on. but hey, its the trade off Then write a TextExpander workflow (and send me a copy when you do!) It has excellent AppleScript support. You can get a list of all snippets pretty easily and also tell it to expand snippets. Best of both worlds. Edited May 11, 2015 by deanishe
lewislepton Posted May 11, 2015 Author Posted May 11, 2015 i gues actually yeah. that would be good. ill have to find something to help me get started. but sounds lije a good idea. and of course ill let you know and have it
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now