Skip to content

Commit b025383

Browse files
author
Dave Abrahams
committed
[emacs-support] Basic flymake support
Still need to make this work with gyb files.
1 parent 66da45b commit b025383

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

utils/swift-mode.el

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ Use `M-x hs-show-all' to show them again."
341341
(move-to-column target-column)))
342342
)
343343

344-
345344
;; Compilation error parsing
346345
(push 'swift0 compilation-error-regexp-alist)
347346
(push 'swift1 compilation-error-regexp-alist)
@@ -407,6 +406,61 @@ Use `M-x hs-show-all' to show them again."
407406
1 2 nil 2)
408407
compilation-error-regexp-alist-alist)
409408

409+
;; Flymake support
410+
411+
(require 'flymake)
412+
413+
(defvar swift-find-executable-function 'executable-find
414+
"Function to find a command executable.
415+
The function is called with one argument, the name of the executable to find.
416+
Might be useful if you want to use a swiftc that you built instead
417+
of the one in your PATH.")
418+
(make-variable-buffer-local 'swift-find-executable-function)
419+
420+
(defvar swift-syntax-check-function 'swift-syntax-check-directory
421+
"Function to create the swift command-line that syntax-checks the current buffer.
422+
The function is called with two arguments, the swiftc executable, and
423+
the name of a temporary file that will contain the contents of the
424+
current buffer.
425+
Set to 'swift-syntax-check-single-file to ignore other files in the current directory.")
426+
(make-variable-buffer-local 'swift-syntax-check-function)
427+
428+
(defun swift-syntax-check-single-file (swiftc temp-file)
429+
"Return a flymake command-line list for syntax-checking the current buffer in isolation"
430+
`(,swiftc ("-parse" ,temp-file)))
431+
432+
(defun swift-syntax-check-directory (swiftc temp-file)
433+
"Return a flymake command-line list for syntax-checking the
434+
current buffer along with the other swift files in the same
435+
directory."
436+
(let* ((sources nil))
437+
(dolist (x (directory-files (file-name-directory (buffer-file-name))))
438+
(when (and (string-equal "swift" (file-name-extension x))
439+
(not (file-equal-p x (buffer-file-name))))
440+
(setq sources (cons x sources))))
441+
`(,swiftc ("-parse" ,temp-file ,@sources))))
442+
443+
(defun flymake-swift-init ()
444+
(let* ((temp-file
445+
(flymake-init-create-temp-buffer-copy
446+
(lambda (x y)
447+
(make-temp-file
448+
(concat (file-name-nondirectory x) "-" y)
449+
(not :DIR_FLAG)
450+
(concat "." (file-name-extension (buffer-file-name))))))))
451+
(funcall swift-syntax-check-function
452+
(funcall swift-find-executable-function "swiftc")
453+
temp-file)))
454+
455+
(add-to-list 'flymake-allowed-file-name-masks '(".+\\.swift$" flymake-swift-init))
456+
457+
(setq flymake-err-line-patterns
458+
(append
459+
(flymake-reformat-err-line-patterns-from-compile-el
460+
(mapcar (lambda (x) (assoc x compilation-error-regexp-alist-alist))
461+
'(swift0 swift1 swift-fatal)))
462+
flymake-err-line-patterns))
463+
410464
(defgroup swift nil
411465
"Major mode for editing swift source files."
412466
:prefix "swift-")

0 commit comments

Comments
 (0)