Skip to content

Commit

Permalink
Merge cc54cc8 into 10ce277
Browse files Browse the repository at this point in the history
  • Loading branch information
twobrowin committed Mar 6, 2019
2 parents 10ce277 + cc54cc8 commit a52be49
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -146,6 +146,20 @@ To define new item in the context menu, launch `Preferences: AlignTab Context Me
]
```

Made by [Dubrovin Egor](https://github.com/twobrowin)

## Beautify the Code

If you want to apply AlignTab to all lines independently, use `align_beautify` command:

```
"command": "align_beautify",
"args" : {
"user_input" : "=/f",
"block_no_align_rows" : "1" // Number of rows from block start to witch AlignTab will not be applied
}
```


## CJK Support

Expand Down
80 changes: 80 additions & 0 deletions alignbeautify.py
@@ -0,0 +1,80 @@
import sublime
import sublime_plugin
from .aligner import Aligner

# Got it from align.py - Put it into class in future!
def resolve_input(user_input):
if isinstance(user_input, str):
s = sublime.load_settings('AlignTab.sublime-settings')
patterns = s.get('named_patterns', {})
if user_input == 'last_regex' and history.last():
user_input = history.last()
if user_input in patterns:
user_input = patterns[user_input]
if isinstance(user_input, str):
user_input = [user_input]
return user_input

########################################################
# This class applies Aligner to all of the buffer lines
########################################################

class AlignBeautifyCommand(sublime_plugin.TextCommand):
def run(self, edit, user_input, block_no_align_rows = 0):
view = self.view
sel = view.sel()
orig_sel = None

# Trying to find current selection
try:
orig_sel = sel[0]
orig_sel_begin = orig_sel.begin()
orig_sel_x, orig_sel_y = view.rowcol(orig_sel_begin)

except IndexError:
sublime.status_message("There was no selection")

finally:
# Get all of lines regions
last_point = view.size()
buffer_region = sublime.Region(0, last_point)
lines = view.lines(buffer_region)

# Computing all the rows
rows = []
for line in lines:
line_begin = line.begin()
row = view.rowcol(line_begin)[0]
rows.append(row)

# Iterate in rows
for row in rows:
# Calculating block region
linepoint = view.text_point(row, 0)

# Selecting block
sel.clear()
sel.add(linepoint)

# Let the AlignTab do it`s work
user_input = resolve_input(user_input)
error = []
for uinput in user_input:
# apply align_tab
aligner = Aligner(view, uinput, mode = False)
self.aligned = aligner.run(edit)

if self.aligned:
sublime.status_message("")
else:
error.append(uinput)

if error:
errors = ' '.join(error)
sublime.status_message("[Patterns not Found: " + errors + " ]")

sel.clear()
# Return selection to a place
if (orig_sel):
orig_sel = view.text_point(orig_sel_x, orig_sel_y)
sel.add(orig_sel)

0 comments on commit a52be49

Please sign in to comment.