PURPOSE:
• Detect and Set the scripting language used by the script on the Clipboard.
AUTHOR: JMichaelTX
HOW TO USE: • This is a Sub-Macro that is intended to be called from a main Macro.
• Add a "Execute Macro" Action to your main Macro
• The KM Variable "ScriptLang" will be set by this Sub-Macro
METHOD:
• Uses a RegEx pattern that is (hopefully) unique to each language, to detect the probable language of the script
NEED PATTERNS FOR OTHER LANGUAGES
• I have started this with patterns for AppleScript and JavaScript
(Suggestions/Improvements welcomed)
• If you have patterns for other languages, please post below and I will update macro.
I like the concept, but I wonder what you use this for?
And as far as the regex is concerned, surely somewhere out there someone has already come up with a regex to detect languages. There are editors that have this feature, so wouldn’t you think…?
Oh wait, I just figured out one use for this. To make it easier to paste code into Markdown documents, like this forum. Depending on the clipboard format, you can surround it with the proper tags. You could even change the indentation if you wanted. How’s that?
I also use it when clipping to Quiver to set the Notebook and tag for language, and language of the code cell. I build a set of header comments, which are, of course, language specific.
You would think. But after having searched for a while, and found nothing, I decided to roll my own. If you know of some RegEx patterns already built, please advise.
I said "or you can roll your own solution" to a client once who was a pretty open minded guy and he rose his eyebrows and exclaimed at me: "Roll Your Own?", in an offended tone that hinted at shock and awe.
I decided to never use that expression with clients ever again.
“Roll your own” is such an intrinsic part of a developer’s language, at least where I come from, that to stop using it would be like cutting off my nose to spite my face, whatever that means.
The expression may have come from rolling your own tobacco cigarettes in the depression days, when many could not afford brand names. So they were creating their own custom cigarettes.