Skip to content

Commit d908c85

Browse files
committed
prettier_src
1 parent 105a627 commit d908c85

File tree

1 file changed

+51
-42
lines changed

1 file changed

+51
-42
lines changed

lib_src/misc/blocks.ts

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,56 @@
1-
'use babel'
1+
"use babel"
22
// TODO: docstrings
33

4-
import { forLines } from './scopes'
4+
import { forLines } from "./scopes"
55

6-
export function getLine (ed, l) {
6+
export function getLine(ed, l) {
77
return {
88
scope: ed.scopeDescriptorForBufferPosition([l, 0]).scopes,
9-
line: ed.getTextInBufferRange([[l, 0], [l, Infinity]])
9+
line: ed.getTextInBufferRange([
10+
[l, 0],
11+
[l, Infinity]
12+
])
1013
}
1114
}
1215

13-
function isBlank ({line, scope}, allowDocstrings = false) {
16+
function isBlank({ line, scope }, allowDocstrings = false) {
1417
for (const s of scope) {
1518
if (/\bcomment\b/.test(s) || (!allowDocstrings && /\bdocstring\b/.test(s))) {
1619
return true
1720
}
1821
}
1922
return /^\s*(#.*)?$/.test(line)
2023
}
21-
function isEnd ({ line, scope }) {
24+
function isEnd({ line, scope }) {
2225
if (isStringEnd({ line, scope })) {
2326
return true
2427
}
2528
return /^(end\b|\)|\]|\})/.test(line)
2629
}
27-
function isStringEnd ({ line, scope }) {
28-
scope = scope.join(' ')
29-
return /\bstring\.multiline\.end\b/.test(scope) ||
30-
(/\bstring\.end\b/.test(scope) && /\bbacktick\b/.test(scope))
30+
function isStringEnd({ line, scope }) {
31+
scope = scope.join(" ")
32+
return /\bstring\.multiline\.end\b/.test(scope) || (/\bstring\.end\b/.test(scope) && /\bbacktick\b/.test(scope))
3133
}
32-
function isCont ({ line, scope }) {
33-
scope = scope.join(' ')
34-
if (/\bstring\b/.test(scope) && !(/\bpunctuation\.definition\.string\b/.test(scope))) {
34+
function isCont({ line, scope }) {
35+
scope = scope.join(" ")
36+
if (/\bstring\b/.test(scope) && !/\bpunctuation\.definition\.string\b/.test(scope)) {
3537
return true
3638
}
3739

3840
return line.match(/^(else|elseif|catch|finally)\b/)
3941
}
40-
function isStart (lineInfo) {
42+
function isStart(lineInfo) {
4143
return !(/^\s/.test(lineInfo.line) || isBlank(lineInfo) || isEnd(lineInfo) || isCont(lineInfo))
4244
}
4345

4446
function walkBack(ed, row) {
45-
while ((row > 0) && !isStart(getLine(ed, row))) {
47+
while (row > 0 && !isStart(getLine(ed, row))) {
4648
row--
4749
}
4850
return row
4951
}
5052

51-
function walkForward (ed, start) {
53+
function walkForward(ed, start) {
5254
let end = start
5355
let mark = start
5456
while (mark < ed.getLastBufferRow()) {
@@ -62,10 +64,7 @@ function walkForward (ed, start) {
6264
// An `end` only counts when there still are unclosed blocks (indicated by `forLines`
6365
// returning a non-empty array).
6466
// If the line closes a multiline string we also take that as ending the block.
65-
if (
66-
!(forLines(ed, start, mark-1).length === 0) ||
67-
isStringEnd(lineInfo)
68-
) {
67+
if (!(forLines(ed, start, mark - 1).length === 0) || isStringEnd(lineInfo)) {
6968
end = mark
7069
}
7170
} else if (!(isBlank(lineInfo) || isStart(lineInfo))) {
@@ -75,63 +74,73 @@ function walkForward (ed, start) {
7574
return end
7675
}
7776

78-
function getRange (ed, row) {
77+
function getRange(ed, row) {
7978
const start = walkBack(ed, row)
8079
const end = walkForward(ed, start)
8180
if (start <= row && row <= end) {
82-
return [[start, 0], [end, Infinity]]
81+
return [
82+
[start, 0],
83+
[end, Infinity]
84+
]
8385
}
8486
}
8587

86-
function getSelection (ed, sel) {
87-
const {start, end} = sel.getBufferRange()
88-
const range = [[start.row, start.column], [end.row, end.column]]
89-
while (isBlank(getLine(ed, range[0][0]), true) && (range[0][0] <= range[1][0])) {
88+
function getSelection(ed, sel) {
89+
const { start, end } = sel.getBufferRange()
90+
const range = [
91+
[start.row, start.column],
92+
[end.row, end.column]
93+
]
94+
while (isBlank(getLine(ed, range[0][0]), true) && range[0][0] <= range[1][0]) {
9095
range[0][0]++
9196
range[0][1] = 0
9297
}
93-
while (isBlank(getLine(ed, range[1][0]), true) && (range[1][0] >= range[0][0])) {
98+
while (isBlank(getLine(ed, range[1][0]), true) && range[1][0] >= range[0][0]) {
9499
range[1][0]--
95100
range[1][1] = Infinity
96101
}
97102
return range
98103
}
99104

100-
export function moveNext (ed, sel, range) {
105+
export function moveNext(ed, sel, range) {
101106
// Ensure enough room at the end of the buffer
102107
const row = range[1][0]
103108
let last
104-
while ((last = ed.getLastBufferRow()) < (row+2)) {
105-
if ((last !== row) && !isBlank(getLine(ed, last))) {
109+
while ((last = ed.getLastBufferRow()) < row + 2) {
110+
if (last !== row && !isBlank(getLine(ed, last))) {
106111
break
107112
}
108-
sel.setBufferRange([[last, Infinity], [last, Infinity]])
109-
sel.insertText('\n')
113+
sel.setBufferRange([
114+
[last, Infinity],
115+
[last, Infinity]
116+
])
117+
sel.insertText("\n")
110118
}
111119
// Move the cursor
112120
let to = row + 1
113-
while ((to < ed.getLastBufferRow()) && isBlank(getLine(ed, to))) {
121+
while (to < ed.getLastBufferRow() && isBlank(getLine(ed, to))) {
114122
to++
115123
}
116124
to = walkForward(ed, to)
117-
return sel.setBufferRange([[to, Infinity], [to, Infinity]])
125+
return sel.setBufferRange([
126+
[to, Infinity],
127+
[to, Infinity]
128+
])
118129
}
119130

120-
function getRanges (ed) {
131+
function getRanges(ed) {
121132
const ranges = ed.getSelections().map(sel => {
122133
return {
123134
selection: sel,
124-
range: sel.isEmpty() ?
125-
getRange(ed, sel.getHeadBufferPosition().row) :
126-
getSelection(ed, sel)
135+
range: sel.isEmpty() ? getRange(ed, sel.getHeadBufferPosition().row) : getSelection(ed, sel)
127136
}
128137
})
129138
return ranges.filter(({ range }) => {
130139
return range && ed.getTextInBufferRange(range).trim()
131140
})
132141
}
133142

134-
export function get (ed) {
143+
export function get(ed) {
135144
return getRanges(ed).map(({ range, selection }) => {
136145
return {
137146
range,
@@ -142,9 +151,9 @@ export function get (ed) {
142151
})
143152
}
144153

145-
export function getLocalContext (editor, row) {
154+
export function getLocalContext(editor, row) {
146155
const range = getRange(editor, row)
147-
const context = range ? editor.getTextInBufferRange(range) : ''
156+
const context = range ? editor.getTextInBufferRange(range) : ""
148157
// NOTE:
149158
// backend code expects startRow to be number for most cases, e.g.: `row = row - startRow`
150159
// so let's just return `0` when there is no local context
@@ -156,7 +165,7 @@ export function getLocalContext (editor, row) {
156165
}
157166
}
158167

159-
export function select (ed = atom.workspace.getActiveTextEditor()) {
168+
export function select(ed = atom.workspace.getActiveTextEditor()) {
160169
if (!ed) return
161170
return ed.mutateSelectedText(selection => {
162171
const range = getRange(ed, selection.getHeadBufferPosition().row)

0 commit comments

Comments
 (0)