Skip to content

Commit 9b8a926

Browse files
committed
1 parent 975e256 commit 9b8a926

File tree

4 files changed

+435
-37
lines changed

4 files changed

+435
-37
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ var x = foo
172172

173173
Both are syntactically correct code. We cannot handle this case properly. This is also a future work.
174174

175+
Other example is regex literals and custom operators. The following example is valid Swift code with regex literals and custom operators.
176+
177+
```swift
178+
let x = /^/ /^/ /^/
179+
```
180+
181+
We parse them as regex literals rather than custom operators for now.
182+
183+
175184
## Hacking
176185

177186
To build the package locally, run `make package`.

swift-mode-indent.el

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,15 @@ declaration and its offset is `swift-mode:basic-offset'."
225225
(swift-mode:indentation (point) 0)))))
226226

227227
(defun swift-mode:calculate-indent-of-multiline-string ()
228-
"Return the indentation of the current line inside a multiline string."
228+
"Return the indentation of the current line inside a multiline string.
229+
230+
Also used for regexes."
229231
(back-to-indentation)
230232
(let ((string-beginning-position
231233
(save-excursion (swift-mode:beginning-of-string))))
232-
(if (looking-at "\"\"\"")
234+
(if (and (looking-at "\\(\"\"\"\\|/\\)#*")
235+
(equal (get-text-property (1- (match-end 0)) 'syntax-table)
236+
(string-to-syntax "|")))
233237
;; The last line.
234238
(progn
235239
(goto-char string-beginning-position)
@@ -240,13 +244,13 @@ declaration and its offset is `swift-mode:basic-offset'."
240244
(swift-mode:goto-non-interpolated-expression-bol)
241245
(back-to-indentation)
242246
(if (<= (point) string-beginning-position)
243-
;; The cursor was on the 2nd line of the comment, so aligns with
247+
;; The cursor was on the 2nd line of the string, so aligns with
244248
;; that line with offset.
245249
(progn
246250
(goto-char string-beginning-position)
247251
(swift-mode:calculate-indent-of-expression
248252
swift-mode:multiline-statement-offset))
249-
;; The cursor was on the 3rd or following lines of the comment, so
253+
;; The cursor was on the 3rd or following lines of the string, so
250254
;; aligns with a non-empty preceding line.
251255
(if (and (bolp) (eolp))
252256
;; The cursor is on an empty line, so seeks a non-empty-line.

0 commit comments

Comments
 (0)