Skip to content

Instantly share code, notes, and snippets.

@OdatNurd
Created June 18, 2018 23:22
Show Gist options
  • Save OdatNurd/dc308c18804d7a7cd7a83314a6982937 to your computer and use it in GitHub Desktop.
Save OdatNurd/dc308c18804d7a7cd7a83314a6982937 to your computer and use it in GitHub Desktop.
Sample Sublime Plugin for a buzzword lorem ipsum that can generate multiple paragraphs at once
import sublime
import sublime_plugin
import textwrap
class BuzzwordIpsumCommand(sublime_plugin.TextCommand):
def __init__(self, view):
super().__init__(view)
self.index = -1
def run(self, edit):
# Get the last word of the line the cursor is on, then discard the word
# "lorem" from the start, leaving the remainder
point = self.view.sel()[0].b
line = self.view.substr(self.view.line(point))
word = line.split()[-1][5:]
repeats = int(word if word != "" else "1")
# Remove the trigger word
self.view.replace(edit, sublime.Region(point, point - 5 - len(word)), "")
for _ in range(repeats):
self.view.run_command("insert", {"characters": self.text()})
if _ + 1 < repeats:
self.view.run_command("insert", {"characters": "\n\n"})
def text(self):
point = self.view.sel()[0].b
col = self.view.rowcol(point)[1]
width = next(iter(self.view.settings().get('rulers', [])), 72) - col
self.index += 1
if self.index == len(_paragraphs):
self.index = 0
return textwrap.fill(_paragraphs[self.index], 10 if width < 10 else width)
def _prep(str):
return textwrap.dedent(str).strip()
_paragraphs = [
_prep("""
Leverage agile frameworks to provide a robust synopsis for high level overviews.
Iterative approaches to corporate strategy foster collaborative thinking to
further the overall value proposition. Organically grow the holistic world view
of disruptive innovation via workplace diversity and empowerment.
"""),
_prep("""
Bring to the table win-win survival strategies to ensure proactive domination.
At the end of the day, going forward, a new normal that has evolved from
generation X is on the runway heading towards a streamlined cloud solution. User
generated content in real-time will have multiple touchpoints for offshoring.
"""),
_prep("""
Capitalize on low hanging fruit to identify a ballpark value added activity to
beta test. Override the digital divide with additional clickthroughs from
DevOps. Nanotechnology immersion along the information highway will close the
loop on focusing solely on the bottom line.
"""),
_prep("""
Podcasting operational change management inside of workflows to establish a
framework. Taking seamless key performance indicators offline to maximise the
long tail. Keeping your eye on the ball while performing a deep dive on the
start-up mentality to derive convergence on cross-platform integration.
"""),
_prep("""
Collaboratively administrate empowered markets via plug-and-play networks.
Dynamically procrastinate B2C users after installed base benefits. Dramatically
visualize customer directed convergence without revolutionary ROI.
""")
]
[
// Use our own buzzword lorem ipsum generator. It generates buzzword lorem
// using a rolling stock of 5 paragraphs and lets you generate multiple
// items at once.
{
"keys": ["tab"],
"command": "buzzword_ipsum",
"context": [
{ "key": "selection_empty", "operator": "equal", "operand": "true", "match_all": true },
{ "key": "preceding_text", "operator": "regex_match", "operand": "^.*lorem\\d*$", "match_all": true },
{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true },
]
},
]
@OdatNurd
Copy link
Author

This implements a replacement for the built in lorem snippet in Sublime text. The main differences are:

  1. There are five different paragraphs of potential ipsum so multiple invocations will get you different text
  2. The expansion allows the lorem keyword to be followed by an optional number to insert that many lorem instances at once (i.e. lorem5 generates five lorem paragraphs
  3. The lorem tries to stay aligned with the column that the cursor is in when the expansion happens
  4. It's not a snippet and doesn't appear in the autocomplete list

In practice this works because the supplied key context knows to make the Tab key only use this binding when it can detect that the buffer is in an appropriate state.

While this is active, the regular lorem snippet is available by typing the trigger text and manually invoking the autocomplete popup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment