rollup merge of #21738: steveklabnik/move_out_editors
As we grow, these don't belong in-tree. http://internals.rust-lang.org/t/moving-editor-highlighting-into-their-own-repos/1395 * https://github.com/rust-lang/rust.vim * https://github.com/rust-lang/rust-mode * https://github.com/rust-lang/gedit-config * https://github.com/rust-lang/kate-config * https://github.com/rust-lang/nano-config * https://github.com/rust-lang/zsh-config
This commit is contained in:
commit
e2282f9cfb
21 changed files with 0 additions and 3617 deletions
|
|
@ -1,79 +0,0 @@
|
|||
`rust-mode`: A major Emacs mode for editing Rust source code
|
||||
============================================================
|
||||
|
||||
`rust-mode` makes editing [Rust](http://rust-lang.org) code with Emacs
|
||||
enjoyable.
|
||||
|
||||
|
||||
### Manual Installation
|
||||
|
||||
To install manually, check out this repository and add this to your
|
||||
`.emacs` file:
|
||||
|
||||
```lisp
|
||||
(add-to-list 'load-path "/path/to/rust-mode/")
|
||||
(autoload 'rust-mode "rust-mode" nil t)
|
||||
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
|
||||
```
|
||||
|
||||
This associates `rust-mode` with `.rs` files. To enable it explicitly, do
|
||||
<kbd>M-x rust-mode</kbd>.
|
||||
|
||||
### `package.el` installation via Marmalade or MELPA
|
||||
|
||||
It can be more convenient to use Emacs's package manager to handle
|
||||
installation for you if you use many elisp libraries. If you have
|
||||
`package.el` but haven't added Marmalade or MELPA, the community
|
||||
package source, yet, add this to `~/.emacs.d/init.el`:
|
||||
|
||||
Using Marmalade:
|
||||
|
||||
```lisp
|
||||
(require 'package)
|
||||
(add-to-list 'package-archives
|
||||
'("marmalade" . "http://marmalade-repo.org/packages/"))
|
||||
(package-initialize)
|
||||
```
|
||||
|
||||
Using MELPA:
|
||||
|
||||
```lisp
|
||||
(require 'package)
|
||||
(add-to-list 'package-archives
|
||||
'("melpa" . "http://melpa.milkbox.net/packages/") t)
|
||||
(package-initialize)
|
||||
```
|
||||
|
||||
Then do this to load the package listing:
|
||||
|
||||
* <kbd>M-x eval-buffer</kbd>
|
||||
* <kbd>M-x package-refresh-contents</kbd>
|
||||
|
||||
If you use a version of Emacs prior to 24 that doesn't include
|
||||
`package.el`, you can get it from [here](http://bit.ly/pkg-el23).
|
||||
|
||||
If you have an older ELPA `package.el` installed from tromey.com, you
|
||||
should upgrade in order to support installation from multiple sources.
|
||||
The ELPA archive is deprecated and no longer accepting new packages,
|
||||
so the version there (1.7.1) is very outdated.
|
||||
|
||||
#### Install `rust-mode`
|
||||
|
||||
One you have `package.el`, you can install `rust-mode` or any other
|
||||
modes by choosing them from a list:
|
||||
|
||||
* <kbd>M-x package-list-packages</kbd>
|
||||
|
||||
Now, to install packages, move your cursor to them and press
|
||||
<kbd>i</kbd>. This will mark the packages for installation. When
|
||||
you're done with marking, press <kbd>x</kbd>, and ELPA will install
|
||||
the packages for you (under `~/.emacs.d/elpa/`).
|
||||
|
||||
* or using <kbd>M-x package-install rust-mode</kbd>
|
||||
|
||||
### Tests via ERT
|
||||
|
||||
The file `rust-mode-tests.el` contains tests that can be run via
|
||||
[ERT](http://www.gnu.org/software/emacs/manual/html_node/ert/index.html).
|
||||
You can use `run_rust_emacs_tests.sh` to run them in batch mode, if
|
||||
Emacs is somewhere in your `$PATH`.
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
# file at the top-level directory of this distribution and at
|
||||
# http://rust-lang.org/COPYRIGHT.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
# option. This file may not be copied, modified, or distributed
|
||||
# except according to those terms.
|
||||
#
|
||||
# This runs the test for emacs rust-mode.
|
||||
# It must be possible to find emacs via PATH.
|
||||
emacs -batch -l rust-mode.el -l rust-mode-tests.el -f ert-run-tests-batch-and-exit
|
||||
|
|
@ -1,896 +0,0 @@
|
|||
;;; rust-mode-tests.el --- ERT tests for rust-mode.el
|
||||
|
||||
(require 'rust-mode)
|
||||
(require 'ert)
|
||||
(require 'cl)
|
||||
|
||||
(setq rust-test-fill-column 32)
|
||||
|
||||
(defun rust-compare-code-after-manip (original point-pos manip-func expected got)
|
||||
(equal expected got))
|
||||
|
||||
(defun rust-test-explain-bad-manip (original point-pos manip-func expected got)
|
||||
(if (equal expected got)
|
||||
nil
|
||||
(list
|
||||
;; The (goto-char) and (insert) business here is just for
|
||||
;; convenience--after an error, you can copy-paste that into emacs eval to
|
||||
;; insert the bare strings into a buffer
|
||||
"Rust code was manipulated wrong after:"
|
||||
`(insert ,original)
|
||||
`(goto-char ,point-pos)
|
||||
'expected `(insert ,expected)
|
||||
'got `(insert ,got)
|
||||
(loop for i from 0 to (max (length original) (length expected))
|
||||
for oi = (if (< i (length got)) (elt got i))
|
||||
for ei = (if (< i (length expected)) (elt expected i))
|
||||
while (equal oi ei)
|
||||
finally return `(first-difference-at
|
||||
(goto-char ,(+ 1 i))
|
||||
expected ,(char-to-string ei)
|
||||
got ,(char-to-string oi))))))
|
||||
(put 'rust-compare-code-after-manip 'ert-explainer
|
||||
'rust-test-explain-bad-manip)
|
||||
|
||||
(defun rust-test-manip-code (original point-pos manip-func expected)
|
||||
(with-temp-buffer
|
||||
(rust-mode)
|
||||
(insert original)
|
||||
(goto-char point-pos)
|
||||
(funcall manip-func)
|
||||
(should (rust-compare-code-after-manip
|
||||
original point-pos manip-func expected (buffer-string)))))
|
||||
|
||||
(defun test-fill-paragraph (unfilled expected &optional start-pos end-pos)
|
||||
"We're going to run through many scenarios here--the point should be able to be anywhere from the start-pos (defaults to 1) through end-pos (defaults to the length of what was passed in) and (fill-paragraph) should return the same result.
|
||||
|
||||
Also, the result should be the same regardless of whether the code is at the beginning or end of the file. (If you're not careful, that can make a difference.) So we test each position given above with the passed code at the beginning, the end, neither and both. So we do this a total of (end-pos - start-pos)*4 times. Oy."
|
||||
(let* ((start-pos (or start-pos 1))
|
||||
(end-pos (or end-pos (length unfilled)))
|
||||
(padding "\n \n")
|
||||
(padding-len (length padding)))
|
||||
(loop
|
||||
for pad-at-beginning from 0 to 1
|
||||
do (loop for pad-at-end from 0 to 1
|
||||
with padding-beginning = (if (= 0 pad-at-beginning) "" padding)
|
||||
with padding-end = (if (= 0 pad-at-end) "" padding)
|
||||
with padding-adjust = (* padding-len pad-at-beginning)
|
||||
with padding-beginning = (if (= 0 pad-at-beginning) "" padding)
|
||||
with padding-end = (if (= 0 pad-at-end) "" padding)
|
||||
;; If we're adding space to the beginning, and our start position
|
||||
;; is at the very beginning, we want to test within the added space.
|
||||
;; Otherwise adjust the start and end for the beginning padding.
|
||||
with start-pos = (if (= 1 start-pos) 1 (+ padding-adjust start-pos))
|
||||
with end-pos = (+ end-pos padding-adjust)
|
||||
do (loop for pos from start-pos to end-pos
|
||||
do (rust-test-manip-code
|
||||
(concat padding-beginning unfilled padding-end)
|
||||
pos
|
||||
(lambda ()
|
||||
(let ((fill-column rust-test-fill-column))
|
||||
(fill-paragraph)))
|
||||
(concat padding-beginning expected padding-end)))))))
|
||||
|
||||
(ert-deftest fill-paragraph-top-level-multi-line-style-doc-comment-second-line ()
|
||||
(test-fill-paragraph
|
||||
"/**
|
||||
* This is a very very very very very very very long string
|
||||
*/"
|
||||
"/**
|
||||
* This is a very very very very
|
||||
* very very very long string
|
||||
*/"))
|
||||
|
||||
|
||||
(ert-deftest fill-paragraph-top-level-multi-line-style-doc-comment-first-line ()
|
||||
(test-fill-paragraph
|
||||
"/** This is a very very very very very very very long string
|
||||
*/"
|
||||
"/** This is a very very very
|
||||
* very very very very long
|
||||
* string
|
||||
*/"))
|
||||
|
||||
(ert-deftest fill-paragraph-multi-paragraph-multi-line-style-doc-comment ()
|
||||
(let
|
||||
((multi-paragraph-unfilled
|
||||
"/**
|
||||
* This is the first really really really really really really really long paragraph
|
||||
*
|
||||
* This is the second really really really really really really long paragraph
|
||||
*/"))
|
||||
(test-fill-paragraph
|
||||
multi-paragraph-unfilled
|
||||
"/**
|
||||
* This is the first really
|
||||
* really really really really
|
||||
* really really long paragraph
|
||||
*
|
||||
* This is the second really really really really really really long paragraph
|
||||
*/"
|
||||
1 89)
|
||||
(test-fill-paragraph
|
||||
multi-paragraph-unfilled
|
||||
"/**
|
||||
* This is the first really really really really really really really long paragraph
|
||||
*
|
||||
* This is the second really
|
||||
* really really really really
|
||||
* really long paragraph
|
||||
*/"
|
||||
90)))
|
||||
|
||||
(ert-deftest fill-paragraph-multi-paragraph-single-line-style-doc-comment ()
|
||||
(let
|
||||
((multi-paragraph-unfilled
|
||||
"/// This is the first really really really really really really really long paragraph
|
||||
///
|
||||
/// This is the second really really really really really really long paragraph"))
|
||||
(test-fill-paragraph
|
||||
multi-paragraph-unfilled
|
||||
"/// This is the first really
|
||||
/// really really really really
|
||||
/// really really long paragraph
|
||||
///
|
||||
/// This is the second really really really really really really long paragraph"
|
||||
1 86)
|
||||
(test-fill-paragraph
|
||||
multi-paragraph-unfilled
|
||||
"/// This is the first really really really really really really really long paragraph
|
||||
///
|
||||
/// This is the second really
|
||||
/// really really really really
|
||||
/// really long paragraph"
|
||||
87)))
|
||||
|
||||
(ert-deftest fill-paragraph-multi-paragraph-single-line-style-indented ()
|
||||
(test-fill-paragraph
|
||||
" // This is the first really really really really really really really long paragraph
|
||||
//
|
||||
// This is the second really really really really really really long paragraph"
|
||||
" // This is the first really
|
||||
// really really really
|
||||
// really really really
|
||||
// long paragraph
|
||||
//
|
||||
// This is the second really really really really really really long paragraph" 1 89))
|
||||
|
||||
(ert-deftest fill-paragraph-multi-line-style-inner-doc-comment ()
|
||||
(test-fill-paragraph
|
||||
"/*! This is a very very very very very very very long string
|
||||
*/"
|
||||
"/*! This is a very very very
|
||||
* very very very very long
|
||||
* string
|
||||
*/"))
|
||||
|
||||
(ert-deftest fill-paragraph-single-line-style-inner-doc-comment ()
|
||||
(test-fill-paragraph
|
||||
"//! This is a very very very very very very very long string"
|
||||
"//! This is a very very very
|
||||
//! very very very very long
|
||||
//! string"))
|
||||
|
||||
(ert-deftest fill-paragraph-prefixless-multi-line-doc-comment ()
|
||||
(test-fill-paragraph
|
||||
"/**
|
||||
This is my summary. Blah blah blah blah blah. Dilly dally dilly dally dilly dally doo.
|
||||
|
||||
This is some more text. Fee fie fo fum. Humpty dumpty sat on a wall.
|
||||
*/"
|
||||
"/**
|
||||
This is my summary. Blah blah
|
||||
blah blah blah. Dilly dally
|
||||
dilly dally dilly dally doo.
|
||||
|
||||
This is some more text. Fee fie fo fum. Humpty dumpty sat on a wall.
|
||||
*/" 4 90))
|
||||
|
||||
(ert-deftest fill-paragraph-with-no-space-after-star-prefix ()
|
||||
(test-fill-paragraph
|
||||
"/**
|
||||
*This is a very very very very very very very long string
|
||||
*/"
|
||||
"/**
|
||||
*This is a very very very very
|
||||
*very very very long string
|
||||
*/"))
|
||||
|
||||
(ert-deftest fill-paragraph-single-line-style-with-code-before ()
|
||||
(test-fill-paragraph
|
||||
"fn foo() { }
|
||||
/// This is my comment. This is more of my comment. This is even more."
|
||||
"fn foo() { }
|
||||
/// This is my comment. This is
|
||||
/// more of my comment. This is
|
||||
/// even more." 14))
|
||||
|
||||
(ert-deftest fill-paragraph-single-line-style-with-code-after ()
|
||||
(test-fill-paragraph
|
||||
"/// This is my comment. This is more of my comment. This is even more.
|
||||
fn foo() { }"
|
||||
"/// This is my comment. This is
|
||||
/// more of my comment. This is
|
||||
/// even more.
|
||||
fn foo() { }" 1 73))
|
||||
|
||||
(ert-deftest fill-paragraph-single-line-style-code-before-and-after ()
|
||||
(test-fill-paragraph
|
||||
"fn foo() { }
|
||||
/// This is my comment. This is more of my comment. This is even more.
|
||||
fn bar() { }"
|
||||
"fn foo() { }
|
||||
/// This is my comment. This is
|
||||
/// more of my comment. This is
|
||||
/// even more.
|
||||
fn bar() { }" 14 67))
|
||||
|
||||
(defun test-auto-fill (initial position inserted expected)
|
||||
(rust-test-manip-code
|
||||
initial
|
||||
position
|
||||
(lambda ()
|
||||
(unwind-protect
|
||||
(progn
|
||||
(let ((fill-column rust-test-fill-column))
|
||||
(auto-fill-mode)
|
||||
(goto-char position)
|
||||
(insert inserted)
|
||||
(syntax-ppss-flush-cache 1)
|
||||
(funcall auto-fill-function)))
|
||||
(auto-fill-mode t)))
|
||||
expected))
|
||||
|
||||
(ert-deftest auto-fill-multi-line-doc-comment ()
|
||||
(test-auto-fill
|
||||
"/**
|
||||
*
|
||||
*/"
|
||||
8
|
||||
"This is a very very very very very very very long string"
|
||||
"/**
|
||||
* This is a very very very very
|
||||
* very very very long string
|
||||
*/"))
|
||||
|
||||
(ert-deftest auto-fill-single-line-doc-comment ()
|
||||
(test-auto-fill
|
||||
"/// This is the first really
|
||||
/// really really really really
|
||||
/// really really long paragraph
|
||||
///
|
||||
/// "
|
||||
103
|
||||
"This is the second really really really really really really long paragraph"
|
||||
"/// This is the first really
|
||||
/// really really really really
|
||||
/// really really long paragraph
|
||||
///
|
||||
/// This is the second really
|
||||
/// really really really really
|
||||
/// really long paragraph"
|
||||
))
|
||||
|
||||
(ert-deftest auto-fill-multi-line-prefixless ()
|
||||
(test-auto-fill
|
||||
"/*
|
||||
|
||||
*/"
|
||||
4
|
||||
"This is a very very very very very very very long string"
|
||||
"/*
|
||||
This is a very very very very
|
||||
very very very long string
|
||||
*/"
|
||||
))
|
||||
|
||||
(defun test-indent (indented)
|
||||
(let ((deindented (replace-regexp-in-string "^[[:blank:]]*" " " indented)))
|
||||
(rust-test-manip-code
|
||||
deindented
|
||||
1
|
||||
(lambda () (indent-region 1 (buffer-size)))
|
||||
indented)))
|
||||
|
||||
|
||||
(ert-deftest indent-struct-fields-aligned ()
|
||||
(test-indent
|
||||
"
|
||||
struct Foo { bar: int,
|
||||
baz: int }
|
||||
|
||||
struct Blah {x:int,
|
||||
y:int,
|
||||
z:String"))
|
||||
|
||||
(ert-deftest indent-doc-comments ()
|
||||
(test-indent
|
||||
"
|
||||
/**
|
||||
* This is a doc comment
|
||||
*
|
||||
*/
|
||||
|
||||
/// So is this
|
||||
|
||||
fn foo() {
|
||||
/*!
|
||||
* this is a nested doc comment
|
||||
*/
|
||||
|
||||
//! And so is this
|
||||
}"))
|
||||
|
||||
(ert-deftest indent-inside-braces ()
|
||||
(test-indent
|
||||
"
|
||||
// struct fields out one level:
|
||||
struct foo {
|
||||
a:int,
|
||||
// comments too
|
||||
b:char
|
||||
}
|
||||
|
||||
fn bar(x:Box<int>) { // comment here should not affect the next indent
|
||||
bla();
|
||||
bla();
|
||||
}"))
|
||||
|
||||
(ert-deftest indent-top-level ()
|
||||
(test-indent
|
||||
"
|
||||
// Everything here is at the top level and should not be indented
|
||||
#[attrib]
|
||||
mod foo;
|
||||
|
||||
pub static bar = Quux{a: b()}
|
||||
|
||||
use foo::bar::baz;
|
||||
|
||||
fn foo() { }
|
||||
"))
|
||||
|
||||
(ert-deftest indent-params-no-align ()
|
||||
(test-indent
|
||||
"
|
||||
// Indent out one level because no params appear on the first line
|
||||
fn xyzzy(
|
||||
a:int,
|
||||
b:char) { }
|
||||
|
||||
fn abcdef(
|
||||
a:int,
|
||||
b:char)
|
||||
-> char
|
||||
{ }"))
|
||||
|
||||
(ert-deftest indent-params-align ()
|
||||
(test-indent
|
||||
"
|
||||
// Align the second line of params to the first
|
||||
fn foo(a:int,
|
||||
b:char) { }
|
||||
|
||||
fn bar( a:int,
|
||||
b:char)
|
||||
-> int
|
||||
{ }
|
||||
|
||||
fn baz( a:int, // should work with a comment here
|
||||
b:char)
|
||||
-> int
|
||||
{ }
|
||||
"))
|
||||
|
||||
(ert-deftest indent-square-bracket-alignment ()
|
||||
(test-indent
|
||||
"
|
||||
fn args_on_the_next_line( // with a comment
|
||||
a:int,
|
||||
b:String) {
|
||||
let aaaaaa = [
|
||||
1,
|
||||
2,
|
||||
3];
|
||||
let bbbbbbb = [1, 2, 3,
|
||||
4, 5, 6];
|
||||
let ccc = [ 10, 9, 8,
|
||||
7, 6, 5];
|
||||
}
|
||||
"))
|
||||
|
||||
(ert-deftest indent-nested-fns ()
|
||||
(test-indent
|
||||
"
|
||||
fn nexted_fns(a: fn(b:int,
|
||||
c:char)
|
||||
-> int,
|
||||
d: int)
|
||||
-> uint
|
||||
{
|
||||
0
|
||||
}
|
||||
"
|
||||
))
|
||||
|
||||
(ert-deftest indent-multi-line-expr ()
|
||||
(test-indent
|
||||
"
|
||||
fn foo()
|
||||
{
|
||||
x();
|
||||
let a =
|
||||
b();
|
||||
}
|
||||
"
|
||||
))
|
||||
|
||||
(ert-deftest indent-match ()
|
||||
(test-indent
|
||||
"
|
||||
fn foo() {
|
||||
match blah {
|
||||
Pattern => stuff(),
|
||||
_ => whatever
|
||||
}
|
||||
}
|
||||
"
|
||||
))
|
||||
|
||||
(ert-deftest indent-match-multiline-pattern ()
|
||||
(test-indent
|
||||
"
|
||||
fn foo() {
|
||||
match blah {
|
||||
Pattern |
|
||||
Pattern2 => {
|
||||
hello()
|
||||
},
|
||||
_ => whatever
|
||||
}
|
||||
}
|
||||
"
|
||||
))
|
||||
|
||||
(ert-deftest indent-indented-match ()
|
||||
(test-indent
|
||||
"
|
||||
fn foo() {
|
||||
let x =
|
||||
match blah {
|
||||
Pattern |
|
||||
Pattern2 => {
|
||||
hello()
|
||||
},
|
||||
_ => whatever
|
||||
};
|
||||
y();
|
||||
}
|
||||
"
|
||||
))
|
||||
|
||||
(ert-deftest indent-curly-braces-within-parens ()
|
||||
(test-indent
|
||||
"
|
||||
fn foo() {
|
||||
let x =
|
||||
foo(bar(|x| {
|
||||
only_one_indent_here();
|
||||
}));
|
||||
y();
|
||||
}
|
||||
"
|
||||
))
|
||||
|
||||
(ert-deftest indent-weirdly-indented-block ()
|
||||
(rust-test-manip-code
|
||||
"
|
||||
fn foo() {
|
||||
{
|
||||
this_block_is_over_to_the_left_for_some_reason();
|
||||
}
|
||||
|
||||
}
|
||||
"
|
||||
16
|
||||
#'indent-for-tab-command
|
||||
"
|
||||
fn foo() {
|
||||
{
|
||||
this_block_is_over_to_the_left_for_some_reason();
|
||||
}
|
||||
|
||||
}
|
||||
"
|
||||
))
|
||||
|
||||
(ert-deftest indent-multi-line-attrib ()
|
||||
(test-indent
|
||||
"
|
||||
#[attrib(
|
||||
this,
|
||||
that,
|
||||
theotherthing)]
|
||||
fn function_with_multiline_attribute() {}
|
||||
"
|
||||
))
|
||||
|
||||
|
||||
;; Make sure that in effort to cover match patterns we don't mistreat || or expressions
|
||||
(ert-deftest indent-nonmatch-or-expression ()
|
||||
(test-indent
|
||||
"
|
||||
fn foo() {
|
||||
let x = foo() ||
|
||||
bar();
|
||||
}
|
||||
"
|
||||
))
|
||||
|
||||
(setq rust-test-motion-string
|
||||
"
|
||||
fn fn1(arg: int) -> bool {
|
||||
let x = 5;
|
||||
let y = b();
|
||||
true
|
||||
}
|
||||
|
||||
fn fn2(arg: int) -> bool {
|
||||
let x = 5;
|
||||
let y = b();
|
||||
true
|
||||
}
|
||||
|
||||
pub fn fn3(arg: int) -> bool {
|
||||
let x = 5;
|
||||
let y = b();
|
||||
true
|
||||
}
|
||||
|
||||
struct Foo {
|
||||
x: int
|
||||
}
|
||||
"
|
||||
rust-test-region-string rust-test-motion-string
|
||||
rust-test-indent-motion-string
|
||||
"
|
||||
fn blank_line(arg:int) -> bool {
|
||||
|
||||
}
|
||||
|
||||
fn indenting_closing_brace() {
|
||||
if(true) {
|
||||
}
|
||||
}
|
||||
|
||||
fn indenting_middle_of_line() {
|
||||
if(true) {
|
||||
push_me_out();
|
||||
} else {
|
||||
pull_me_back_in();
|
||||
}
|
||||
}
|
||||
|
||||
fn indented_already() {
|
||||
|
||||
// The previous line already has its spaces
|
||||
}
|
||||
"
|
||||
|
||||
;; Symbol -> (line column)
|
||||
rust-test-positions-alist '((start-of-fn1 (2 0))
|
||||
(start-of-fn1-middle-of-line (2 15))
|
||||
(middle-of-fn1 (3 7))
|
||||
(end-of-fn1 (6 0))
|
||||
(between-fn1-fn2 (7 0))
|
||||
(start-of-fn2 (8 0))
|
||||
(middle-of-fn2 (10 4))
|
||||
(before-start-of-fn1 (1 0))
|
||||
(after-end-of-fn2 (13 0))
|
||||
(beginning-of-fn3 (14 0))
|
||||
(middle-of-fn3 (16 4))
|
||||
(middle-of-struct (21 10))
|
||||
(before-start-of-struct (19 0))
|
||||
(after-end-of-struct (23 0))
|
||||
(blank-line-indent-start (3 0))
|
||||
(blank-line-indent-target (3 4))
|
||||
(closing-brace-indent-start (8 1))
|
||||
(closing-brace-indent-target (8 5))
|
||||
(middle-push-indent-start (13 2))
|
||||
(middle-push-indent-target (13 9))
|
||||
(after-whitespace-indent-start (13 1))
|
||||
(after-whitespace-indent-target (13 8))
|
||||
(middle-pull-indent-start (15 19))
|
||||
(middle-pull-indent-target (15 12))
|
||||
(blank-line-indented-already-bol-start (20 0))
|
||||
(blank-line-indented-already-bol-target (20 4))
|
||||
(blank-line-indented-already-middle-start (20 2))
|
||||
(blank-line-indented-already-middle-target (20 4))
|
||||
(nonblank-line-indented-already-bol-start (21 0))
|
||||
(nonblank-line-indented-already-bol-target (21 4))
|
||||
(nonblank-line-indented-already-middle-start (21 2))
|
||||
(nonblank-line-indented-already-middle-target (21 4))))
|
||||
|
||||
(defun rust-get-buffer-pos (pos-symbol)
|
||||
"Get buffer position from POS-SYMBOL.
|
||||
|
||||
POS-SYMBOL is a symbol found in `rust-test-positions-alist'.
|
||||
Convert the line-column information from that list into a buffer position value."
|
||||
(interactive "P")
|
||||
(pcase-let ((`(,line ,column) (cadr (assoc pos-symbol rust-test-positions-alist))))
|
||||
(save-excursion
|
||||
(goto-line line)
|
||||
(move-to-column column)
|
||||
(point))))
|
||||
|
||||
;;; FIXME: Maybe add an ERT explainer function (something that shows the
|
||||
;;; surrounding code of the final point, not just the position).
|
||||
(defun rust-test-motion (source-code init-pos final-pos manip-func &optional &rest args)
|
||||
"Test that MANIP-FUNC moves point from INIT-POS to FINAL-POS.
|
||||
|
||||
If ARGS are provided, send them to MANIP-FUNC.
|
||||
|
||||
INIT-POS, FINAL-POS are position symbols found in `rust-test-positions-alist'."
|
||||
(with-temp-buffer
|
||||
(rust-mode)
|
||||
(insert source-code)
|
||||
(goto-char (rust-get-buffer-pos init-pos))
|
||||
(apply manip-func args)
|
||||
(should (equal (point) (rust-get-buffer-pos final-pos)))))
|
||||
|
||||
(defun rust-test-region (source-code init-pos reg-beg reg-end manip-func &optional &rest args)
|
||||
"Test that MANIP-FUNC marks region from REG-BEG to REG-END.
|
||||
|
||||
INIT-POS is the initial position of point.
|
||||
If ARGS are provided, send them to MANIP-FUNC.
|
||||
All positions are position symbols found in `rust-test-positions-alist'."
|
||||
(with-temp-buffer
|
||||
(rust-mode)
|
||||
(insert source-code)
|
||||
(goto-char (rust-get-buffer-pos init-pos))
|
||||
(apply manip-func args)
|
||||
(should (equal (list (region-beginning) (region-end))
|
||||
(list (rust-get-buffer-pos reg-beg)
|
||||
(rust-get-buffer-pos reg-end))))))
|
||||
|
||||
(ert-deftest rust-beginning-of-defun-from-middle-of-fn ()
|
||||
(rust-test-motion
|
||||
rust-test-motion-string
|
||||
'middle-of-fn1
|
||||
'start-of-fn1
|
||||
#'beginning-of-defun))
|
||||
|
||||
(ert-deftest rust-beginning-of-defun-from-end ()
|
||||
(rust-test-motion
|
||||
rust-test-motion-string
|
||||
'end-of-fn1
|
||||
'start-of-fn1
|
||||
#'beginning-of-defun))
|
||||
|
||||
(ert-deftest rust-beginning-of-defun-before-open-brace ()
|
||||
(rust-test-motion
|
||||
rust-test-motion-string
|
||||
'start-of-fn1-middle-of-line
|
||||
'start-of-fn1
|
||||
#'beginning-of-defun))
|
||||
|
||||
(ert-deftest rust-beginning-of-defun-between-fns ()
|
||||
(rust-test-motion
|
||||
rust-test-motion-string
|
||||
'between-fn1-fn2
|
||||
'start-of-fn1
|
||||
#'beginning-of-defun))
|
||||
|
||||
(ert-deftest rust-beginning-of-defun-with-arg ()
|
||||
(rust-test-motion
|
||||
rust-test-motion-string
|
||||
'middle-of-fn2
|
||||
'start-of-fn1
|
||||
#'beginning-of-defun 2))
|
||||
|
||||
(ert-deftest rust-beginning-of-defun-with-negative-arg ()
|
||||
(rust-test-motion
|
||||
rust-test-motion-string
|
||||
'middle-of-fn1
|
||||
'beginning-of-fn3
|
||||
#'beginning-of-defun -2))
|
||||
|
||||
(ert-deftest rust-beginning-of-defun-pub-fn ()
|
||||
(rust-test-motion
|
||||
rust-test-motion-string
|
||||
'middle-of-fn3
|
||||
'beginning-of-fn3
|
||||
#'beginning-of-defun))
|
||||
|
||||
(ert-deftest rust-end-of-defun-from-middle-of-fn ()
|
||||
(rust-test-motion
|
||||
rust-test-motion-string
|
||||
'middle-of-fn1
|
||||
'between-fn1-fn2
|
||||
#'end-of-defun))
|
||||
|
||||
(ert-deftest rust-end-of-defun-from-beg ()
|
||||
(rust-test-motion
|
||||
rust-test-motion-string
|
||||
'start-of-fn1
|
||||
'between-fn1-fn2
|
||||
#'end-of-defun))
|
||||
|
||||
(ert-deftest rust-end-of-defun-before-open-brace ()
|
||||
(rust-test-motion
|
||||
rust-test-motion-string
|
||||
'start-of-fn1-middle-of-line
|
||||
'between-fn1-fn2
|
||||
#'end-of-defun))
|
||||
|
||||
(ert-deftest rust-end-of-defun-between-fns ()
|
||||
(rust-test-motion
|
||||
rust-test-motion-string
|
||||
'between-fn1-fn2
|
||||
'after-end-of-fn2
|
||||
#'end-of-defun))
|
||||
|
||||
(ert-deftest rust-end-of-defun-with-arg ()
|
||||
(rust-test-motion
|
||||
rust-test-motion-string
|
||||
'middle-of-fn1
|
||||
'after-end-of-fn2
|
||||
#'end-of-defun 2))
|
||||
|
||||
(ert-deftest rust-end-of-defun-with-negative-arg ()
|
||||
(rust-test-motion
|
||||
rust-test-motion-string
|
||||
'middle-of-fn3
|
||||
'between-fn1-fn2
|
||||
#'end-of-defun -2))
|
||||
|
||||
(ert-deftest rust-mark-defun-from-middle-of-fn ()
|
||||
(rust-test-region
|
||||
rust-test-region-string
|
||||
'middle-of-fn2
|
||||
'between-fn1-fn2 'after-end-of-fn2
|
||||
#'mark-defun))
|
||||
|
||||
(ert-deftest rust-mark-defun-from-end ()
|
||||
(rust-test-region
|
||||
rust-test-region-string
|
||||
'end-of-fn1
|
||||
'before-start-of-fn1 'between-fn1-fn2
|
||||
#'mark-defun))
|
||||
|
||||
(ert-deftest rust-mark-defun-start-of-defun ()
|
||||
(rust-test-region
|
||||
rust-test-region-string
|
||||
'start-of-fn2
|
||||
'between-fn1-fn2 'after-end-of-fn2
|
||||
#'mark-defun))
|
||||
|
||||
(ert-deftest rust-mark-defun-from-middle-of-struct ()
|
||||
(rust-test-region
|
||||
rust-test-region-string
|
||||
'middle-of-struct
|
||||
'before-start-of-struct 'after-end-of-struct
|
||||
#'mark-defun))
|
||||
|
||||
(ert-deftest indent-line-blank-line-motion ()
|
||||
(rust-test-motion
|
||||
rust-test-indent-motion-string
|
||||
'blank-line-indent-start
|
||||
'blank-line-indent-target
|
||||
#'indent-for-tab-command))
|
||||
|
||||
(ert-deftest indent-line-closing-brace-motion ()
|
||||
(rust-test-motion
|
||||
rust-test-indent-motion-string
|
||||
'closing-brace-indent-start
|
||||
'closing-brace-indent-target
|
||||
#'indent-for-tab-command))
|
||||
|
||||
(ert-deftest indent-line-middle-push-motion ()
|
||||
(rust-test-motion
|
||||
rust-test-indent-motion-string
|
||||
'middle-push-indent-start
|
||||
'middle-push-indent-target
|
||||
#'indent-for-tab-command))
|
||||
|
||||
(ert-deftest indent-line-after-whitespace-motion ()
|
||||
(rust-test-motion
|
||||
rust-test-indent-motion-string
|
||||
'after-whitespace-indent-start
|
||||
'after-whitespace-indent-target
|
||||
#'indent-for-tab-command))
|
||||
|
||||
(ert-deftest indent-line-middle-pull-motion ()
|
||||
(rust-test-motion
|
||||
rust-test-indent-motion-string
|
||||
'middle-pull-indent-start
|
||||
'middle-pull-indent-target
|
||||
#'indent-for-tab-command))
|
||||
|
||||
(ert-deftest indent-line-blank-line-indented-already-bol ()
|
||||
(rust-test-motion
|
||||
rust-test-indent-motion-string
|
||||
'blank-line-indented-already-bol-start
|
||||
'blank-line-indented-already-bol-target
|
||||
#'indent-for-tab-command))
|
||||
|
||||
(ert-deftest indent-line-blank-line-indented-already-middle ()
|
||||
(rust-test-motion
|
||||
rust-test-indent-motion-string
|
||||
'blank-line-indented-already-middle-start
|
||||
'blank-line-indented-already-middle-target
|
||||
#'indent-for-tab-command))
|
||||
|
||||
(ert-deftest indent-line-nonblank-line-indented-already-bol ()
|
||||
(rust-test-motion
|
||||
rust-test-indent-motion-string
|
||||
'nonblank-line-indented-already-bol-start
|
||||
'nonblank-line-indented-already-bol-target
|
||||
#'indent-for-tab-command))
|
||||
|
||||
(ert-deftest indent-line-nonblank-line-indented-already-middle ()
|
||||
(rust-test-motion
|
||||
rust-test-indent-motion-string
|
||||
'nonblank-line-indented-already-middle-start
|
||||
'nonblank-line-indented-already-middle-target
|
||||
#'indent-for-tab-command))
|
||||
|
||||
(defun rust-test-fontify-string (str)
|
||||
(with-temp-buffer
|
||||
(rust-mode)
|
||||
(insert str)
|
||||
(font-lock-fontify-buffer)
|
||||
(buffer-string)))
|
||||
|
||||
(defun rust-test-group-str-by-face (str)
|
||||
"Fontify `STR' in rust-mode and group it by face, returning a
|
||||
list of substrings of `STR' each followed by its face."
|
||||
(cl-loop with fontified = (rust-test-fontify-string str)
|
||||
for start = 0 then end
|
||||
while start
|
||||
for end = (next-single-property-change start 'face fontified)
|
||||
for prop = (get-text-property start 'face fontified)
|
||||
for text = (substring-no-properties fontified start end)
|
||||
if prop
|
||||
append (list text prop)))
|
||||
|
||||
(defun rust-test-font-lock (source face-groups)
|
||||
"Test that `SOURCE' fontifies to the expected `FACE-GROUPS'"
|
||||
(should (equal (rust-test-group-str-by-face source)
|
||||
face-groups)))
|
||||
|
||||
(ert-deftest font-lock-attribute-simple ()
|
||||
(rust-test-font-lock
|
||||
"#[foo]"
|
||||
'("#[foo]" font-lock-preprocessor-face)))
|
||||
|
||||
(ert-deftest font-lock-attribute-inner ()
|
||||
(rust-test-font-lock
|
||||
"#![foo]"
|
||||
'("#![foo]" font-lock-preprocessor-face)))
|
||||
|
||||
(ert-deftest font-lock-attribute-key-value ()
|
||||
(rust-test-font-lock
|
||||
"#[foo = \"bar\"]"
|
||||
'("#[foo = " font-lock-preprocessor-face
|
||||
"\"bar\"" font-lock-string-face
|
||||
"]" font-lock-preprocessor-face)))
|
||||
|
||||
(ert-deftest font-lock-attribute-around-comment ()
|
||||
(rust-test-font-lock
|
||||
"#[foo /* bar */]"
|
||||
'("#[foo " font-lock-preprocessor-face
|
||||
"/* " font-lock-comment-delimiter-face
|
||||
"bar */" font-lock-comment-face
|
||||
"]" font-lock-preprocessor-face)))
|
||||
|
||||
(ert-deftest font-lock-attribute-inside-string ()
|
||||
(rust-test-font-lock
|
||||
"\"#[foo]\""
|
||||
'("\"#[foo]\"" font-lock-string-face)))
|
||||
|
||||
(ert-deftest font-lock-attribute-inside-comment ()
|
||||
(rust-test-font-lock
|
||||
"/* #[foo] */"
|
||||
'("/* " font-lock-comment-delimiter-face
|
||||
"#[foo] */" font-lock-comment-face)))
|
||||
|
|
@ -1,520 +0,0 @@
|
|||
;;; rust-mode.el --- A major emacs mode for editing Rust source code
|
||||
|
||||
;; Version: 0.2.0
|
||||
;; Author: Mozilla
|
||||
;; Url: https://github.com/rust-lang/rust
|
||||
;; Keywords: languages
|
||||
|
||||
;;; Commentary:
|
||||
;;
|
||||
|
||||
;;; Code:
|
||||
|
||||
(eval-when-compile (require 'misc))
|
||||
|
||||
;; for GNU Emacs < 24.3
|
||||
(eval-when-compile
|
||||
(unless (fboundp 'setq-local)
|
||||
(defmacro setq-local (var val)
|
||||
"Set variable VAR to value VAL in current buffer."
|
||||
(list 'set (list 'make-local-variable (list 'quote var)) val))))
|
||||
|
||||
;; Syntax definitions and helpers
|
||||
(defvar rust-mode-syntax-table
|
||||
(let ((table (make-syntax-table)))
|
||||
|
||||
;; Operators
|
||||
(dolist (i '(?+ ?- ?* ?/ ?& ?| ?^ ?! ?< ?> ?~ ?@))
|
||||
(modify-syntax-entry i "." table))
|
||||
|
||||
;; Strings
|
||||
(modify-syntax-entry ?\" "\"" table)
|
||||
(modify-syntax-entry ?\\ "\\" table)
|
||||
|
||||
;; mark _ as a word constituent so that identifiers
|
||||
;; such as xyz_type don't cause type to be highlighted
|
||||
;; as a keyword
|
||||
(modify-syntax-entry ?_ "w" table)
|
||||
|
||||
;; Comments
|
||||
(modify-syntax-entry ?/ ". 124b" table)
|
||||
(modify-syntax-entry ?* ". 23" table)
|
||||
(modify-syntax-entry ?\n "> b" table)
|
||||
(modify-syntax-entry ?\^m "> b" table)
|
||||
|
||||
table))
|
||||
|
||||
(defgroup rust-mode nil
|
||||
"Support for Rust code."
|
||||
:link '(url-link "http://www.rust-lang.org/")
|
||||
:group 'languages)
|
||||
|
||||
(defcustom rust-indent-offset 4
|
||||
"Indent Rust code by this number of spaces."
|
||||
:type 'integer
|
||||
:group 'rust-mode)
|
||||
|
||||
(defcustom rust-indent-method-chain nil
|
||||
"Indent Rust method chains, aligned by the '.' operators"
|
||||
:type 'boolean
|
||||
:group 'rust-mode)
|
||||
|
||||
(defun rust-paren-level () (nth 0 (syntax-ppss)))
|
||||
(defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss)))
|
||||
(defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss))))
|
||||
(defun rust-rewind-irrelevant ()
|
||||
(let ((starting (point)))
|
||||
(skip-chars-backward "[:space:]\n")
|
||||
(if (looking-back "\\*/") (backward-char))
|
||||
(if (rust-in-str-or-cmnt)
|
||||
(rust-rewind-past-str-cmnt))
|
||||
(if (/= starting (point))
|
||||
(rust-rewind-irrelevant))))
|
||||
|
||||
(defun rust-align-to-expr-after-brace ()
|
||||
(save-excursion
|
||||
(forward-char)
|
||||
;; We don't want to indent out to the open bracket if the
|
||||
;; open bracket ends the line
|
||||
(when (not (looking-at "[[:blank:]]*\\(?://.*\\)?$"))
|
||||
(when (looking-at "[[:space:]]")
|
||||
(forward-word 1)
|
||||
(backward-word 1))
|
||||
(current-column))))
|
||||
|
||||
(defun rust-align-to-method-chain ()
|
||||
(save-excursion
|
||||
(previous-line)
|
||||
(end-of-line)
|
||||
(backward-word 1)
|
||||
(backward-char)
|
||||
(when (looking-at "\\..+\(.*\)\n")
|
||||
(- (current-column) rust-indent-offset))))
|
||||
|
||||
(defun rust-rewind-to-beginning-of-current-level-expr ()
|
||||
(let ((current-level (rust-paren-level)))
|
||||
(back-to-indentation)
|
||||
(while (> (rust-paren-level) current-level)
|
||||
(backward-up-list)
|
||||
(back-to-indentation))))
|
||||
|
||||
(defun rust-mode-indent-line ()
|
||||
(interactive)
|
||||
(let ((indent
|
||||
(save-excursion
|
||||
(back-to-indentation)
|
||||
;; Point is now at beginning of current line
|
||||
(let* ((level (rust-paren-level))
|
||||
(baseline
|
||||
;; Our "baseline" is one level out from the indentation of the expression
|
||||
;; containing the innermost enclosing opening bracket. That
|
||||
;; way if we are within a block that has a different
|
||||
;; indentation than this mode would give it, we still indent
|
||||
;; the inside of it correctly relative to the outside.
|
||||
(if (= 0 level)
|
||||
0
|
||||
(or
|
||||
(when rust-indent-method-chain
|
||||
(rust-align-to-method-chain))
|
||||
(save-excursion
|
||||
(backward-up-list)
|
||||
(rust-rewind-to-beginning-of-current-level-expr)
|
||||
(+ (current-column) rust-indent-offset))))))
|
||||
(cond
|
||||
;; A function return type is indented to the corresponding function arguments
|
||||
((looking-at "->")
|
||||
(save-excursion
|
||||
(backward-list)
|
||||
(or (rust-align-to-expr-after-brace)
|
||||
(+ baseline rust-indent-offset))))
|
||||
|
||||
;; A closing brace is 1 level unindended
|
||||
((looking-at "}") (- baseline rust-indent-offset))
|
||||
|
||||
;;Line up method chains by their .'s
|
||||
((when (and rust-indent-method-chain
|
||||
(looking-at "\..+\(.*\);?\n"))
|
||||
(or
|
||||
(let ((method-indent (rust-align-to-method-chain)))
|
||||
(when method-indent
|
||||
(+ method-indent rust-indent-offset)))
|
||||
(+ baseline rust-indent-offset))))
|
||||
|
||||
|
||||
;; Doc comments in /** style with leading * indent to line up the *s
|
||||
((and (nth 4 (syntax-ppss)) (looking-at "*"))
|
||||
(+ 1 baseline))
|
||||
|
||||
;; If we're in any other token-tree / sexp, then:
|
||||
(t
|
||||
(or
|
||||
;; If we are inside a pair of braces, with something after the
|
||||
;; open brace on the same line and ending with a comma, treat
|
||||
;; it as fields and align them.
|
||||
(when (> level 0)
|
||||
(save-excursion
|
||||
(rust-rewind-irrelevant)
|
||||
(backward-up-list)
|
||||
;; Point is now at the beginning of the containing set of braces
|
||||
(rust-align-to-expr-after-brace)))
|
||||
|
||||
(progn
|
||||
(back-to-indentation)
|
||||
;; Point is now at the beginning of the current line
|
||||
(if (or
|
||||
;; If this line begins with "else" or "{", stay on the
|
||||
;; baseline as well (we are continuing an expression,
|
||||
;; but the "else" or "{" should align with the beginning
|
||||
;; of the expression it's in.)
|
||||
(looking-at "\\<else\\>\\|{")
|
||||
|
||||
(save-excursion
|
||||
(rust-rewind-irrelevant)
|
||||
;; Point is now at the end of the previous ine
|
||||
(or
|
||||
;; If we are at the first line, no indentation is needed, so stay at baseline...
|
||||
(= 1 (line-number-at-pos (point)))
|
||||
;; ..or if the previous line ends with any of these:
|
||||
;; { ? : ( , ; [ }
|
||||
;; then we are at the beginning of an expression, so stay on the baseline...
|
||||
(looking-back "[(,:;?[{}]\\|[^|]|")
|
||||
;; or if the previous line is the end of an attribute, stay at the baseline...
|
||||
(progn (rust-rewind-to-beginning-of-current-level-expr) (looking-at "#")))))
|
||||
baseline
|
||||
|
||||
;; Otherwise, we are continuing the same expression from the previous line,
|
||||
;; so add one additional indent level
|
||||
(+ baseline rust-indent-offset))))))))))
|
||||
|
||||
;; If we're at the beginning of the line (before or at the current
|
||||
;; indentation), jump with the indentation change. Otherwise, save the
|
||||
;; excursion so that adding the indentations will leave us at the
|
||||
;; equivalent position within the line to where we were before.
|
||||
(if (<= (current-column) (current-indentation))
|
||||
(indent-line-to indent)
|
||||
(save-excursion (indent-line-to indent)))))
|
||||
|
||||
|
||||
;; Font-locking definitions and helpers
|
||||
(defconst rust-mode-keywords
|
||||
'("as"
|
||||
"box" "break"
|
||||
"const" "continue" "crate"
|
||||
"do"
|
||||
"else" "enum" "extern"
|
||||
"false" "fn" "for"
|
||||
"if" "impl" "in"
|
||||
"let" "loop"
|
||||
"match" "mod" "move" "mut"
|
||||
"priv" "pub"
|
||||
"ref" "return"
|
||||
"self" "static" "struct" "super"
|
||||
"true" "trait" "type"
|
||||
"unsafe" "use"
|
||||
"virtual"
|
||||
"where" "while"))
|
||||
|
||||
(defconst rust-special-types
|
||||
'("u8" "i8"
|
||||
"u16" "i16"
|
||||
"u32" "i32"
|
||||
"u64" "i64"
|
||||
|
||||
"f32" "f64"
|
||||
"float" "int" "uint" "isize" "usize"
|
||||
"bool"
|
||||
"str" "char"))
|
||||
|
||||
(defconst rust-re-ident "[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
|
||||
(defconst rust-re-CamelCase "[[:upper:]][[:word:][:multibyte:]_[:digit:]]*")
|
||||
(defun rust-re-word (inner) (concat "\\<" inner "\\>"))
|
||||
(defun rust-re-grab (inner) (concat "\\(" inner "\\)"))
|
||||
(defun rust-re-grabword (inner) (rust-re-grab (rust-re-word inner)))
|
||||
(defun rust-re-item-def (itype)
|
||||
(concat (rust-re-word itype) "[[:space:]]+" (rust-re-grab rust-re-ident)))
|
||||
|
||||
(defvar rust-mode-font-lock-keywords
|
||||
(append
|
||||
`(
|
||||
;; Keywords proper
|
||||
(,(regexp-opt rust-mode-keywords 'words) . font-lock-keyword-face)
|
||||
|
||||
;; Special types
|
||||
(,(regexp-opt rust-special-types 'words) . font-lock-type-face)
|
||||
|
||||
;; Attributes like `#[bar(baz)]` or `#![bar(baz)]` or `#[bar = "baz"]`
|
||||
(,(rust-re-grab (concat "#\\!?\\[" rust-re-ident "[^]]*\\]"))
|
||||
1 font-lock-preprocessor-face keep)
|
||||
|
||||
;; Syntax extension invocations like `foo!`, highlight including the !
|
||||
(,(concat (rust-re-grab (concat rust-re-ident "!")) "[({[:space:][]")
|
||||
1 font-lock-preprocessor-face)
|
||||
|
||||
;; Field names like `foo:`, highlight excluding the :
|
||||
(,(concat (rust-re-grab rust-re-ident) ":[^:]") 1 font-lock-variable-name-face)
|
||||
|
||||
;; Module names like `foo::`, highlight including the ::
|
||||
(,(rust-re-grab (concat rust-re-ident "::")) 1 font-lock-type-face)
|
||||
|
||||
;; Lifetimes like `'foo`
|
||||
(,(concat "'" (rust-re-grab rust-re-ident) "[^']") 1 font-lock-variable-name-face)
|
||||
|
||||
;; Character constants, since they're not treated as strings
|
||||
;; in order to have sufficient leeway to parse 'lifetime above.
|
||||
(,(rust-re-grab "'[^']'") 1 font-lock-string-face)
|
||||
(,(rust-re-grab "'\\\\[nrt]'") 1 font-lock-string-face)
|
||||
(,(rust-re-grab "'\\\\x[[:xdigit:]]\\{2\\}'") 1 font-lock-string-face)
|
||||
(,(rust-re-grab "'\\\\u[[:xdigit:]]\\{4\\}'") 1 font-lock-string-face)
|
||||
(,(rust-re-grab "'\\\\U[[:xdigit:]]\\{8\\}'") 1 font-lock-string-face)
|
||||
|
||||
;; CamelCase Means Type Or Constructor
|
||||
(,(rust-re-grabword rust-re-CamelCase) 1 font-lock-type-face)
|
||||
)
|
||||
|
||||
;; Item definitions
|
||||
(mapcar #'(lambda (x)
|
||||
(list (rust-re-item-def (car x))
|
||||
1 (cdr x)))
|
||||
'(("enum" . font-lock-type-face)
|
||||
("struct" . font-lock-type-face)
|
||||
("type" . font-lock-type-face)
|
||||
("mod" . font-lock-type-face)
|
||||
("use" . font-lock-type-face)
|
||||
("fn" . font-lock-function-name-face)
|
||||
("static" . font-lock-constant-face)))))
|
||||
|
||||
(defun rust-fill-prefix-for-comment-start (line-start)
|
||||
"Determine what to use for `fill-prefix' based on what is at the beginning of a line."
|
||||
(let ((result
|
||||
;; Replace /* with same number of spaces
|
||||
(replace-regexp-in-string
|
||||
"\\(?:/\\*+\\)[!*]"
|
||||
(lambda (s)
|
||||
;; We want the * to line up with the first * of the comment start
|
||||
(concat (make-string (- (length s) 2) ?\x20) "*"))
|
||||
line-start)))
|
||||
;; Make sure we've got at least one space at the end
|
||||
(if (not (= (aref result (- (length result) 1)) ?\x20))
|
||||
(setq result (concat result " ")))
|
||||
result))
|
||||
|
||||
(defun rust-in-comment-paragraph (body)
|
||||
;; We might move the point to fill the next comment, but we don't want it
|
||||
;; seeming to jump around on the user
|
||||
(save-excursion
|
||||
;; If we're outside of a comment, with only whitespace and then a comment
|
||||
;; in front, jump to the comment and prepare to fill it.
|
||||
(when (not (nth 4 (syntax-ppss)))
|
||||
(beginning-of-line)
|
||||
(when (looking-at (concat "[[:space:]\n]*" comment-start-skip))
|
||||
(goto-char (match-end 0))))
|
||||
|
||||
;; We need this when we're moving the point around and then checking syntax
|
||||
;; while doing paragraph fills, because the cache it uses isn't always
|
||||
;; invalidated during this.
|
||||
(syntax-ppss-flush-cache 1)
|
||||
;; If we're at the beginning of a comment paragraph with nothing but
|
||||
;; whitespace til the next line, jump to the next line so that we use the
|
||||
;; existing prefix to figure out what the new prefix should be, rather than
|
||||
;; inferring it from the comment start.
|
||||
(let ((next-bol (line-beginning-position 2)))
|
||||
(while (save-excursion
|
||||
(end-of-line)
|
||||
(syntax-ppss-flush-cache 1)
|
||||
(and (nth 4 (syntax-ppss))
|
||||
(save-excursion
|
||||
(beginning-of-line)
|
||||
(looking-at paragraph-start))
|
||||
(looking-at "[[:space:]]*$")
|
||||
(nth 4 (syntax-ppss next-bol))))
|
||||
(goto-char next-bol)))
|
||||
|
||||
(syntax-ppss-flush-cache 1)
|
||||
;; If we're on the last line of a multiline-style comment that started
|
||||
;; above, back up one line so we don't mistake the * of the */ that ends
|
||||
;; the comment for a prefix.
|
||||
(when (save-excursion
|
||||
(and (nth 4 (syntax-ppss (line-beginning-position 1)))
|
||||
(looking-at "[[:space:]]*\\*/")))
|
||||
(goto-char (line-end-position 0)))
|
||||
(funcall body)))
|
||||
|
||||
(defun rust-with-comment-fill-prefix (body)
|
||||
(let*
|
||||
((line-string (buffer-substring-no-properties
|
||||
(line-beginning-position) (line-end-position)))
|
||||
(line-comment-start
|
||||
(when (nth 4 (syntax-ppss))
|
||||
(cond
|
||||
;; If we're inside the comment and see a * prefix, use it
|
||||
((string-match "^\\([[:space:]]*\\*+[[:space:]]*\\)"
|
||||
line-string)
|
||||
(match-string 1 line-string))
|
||||
;; If we're at the start of a comment, figure out what prefix
|
||||
;; to use for the subsequent lines after it
|
||||
((string-match (concat "[[:space:]]*" comment-start-skip) line-string)
|
||||
(rust-fill-prefix-for-comment-start
|
||||
(match-string 0 line-string))))))
|
||||
(fill-prefix
|
||||
(or line-comment-start
|
||||
fill-prefix)))
|
||||
(funcall body)))
|
||||
|
||||
(defun rust-find-fill-prefix ()
|
||||
(rust-with-comment-fill-prefix (lambda () fill-prefix)))
|
||||
|
||||
(defun rust-fill-paragraph (&rest args)
|
||||
"Special wrapping for `fill-paragraph' to handle multi-line comments with a * prefix on each line."
|
||||
(rust-in-comment-paragraph
|
||||
(lambda ()
|
||||
(rust-with-comment-fill-prefix
|
||||
(lambda ()
|
||||
(let
|
||||
((fill-paragraph-function
|
||||
(if (not (eq fill-paragraph-function 'rust-fill-paragraph))
|
||||
fill-paragraph-function))
|
||||
(fill-paragraph-handle-comment t))
|
||||
(apply 'fill-paragraph args)
|
||||
t))))))
|
||||
|
||||
(defun rust-do-auto-fill (&rest args)
|
||||
"Special wrapping for `do-auto-fill' to handle multi-line comments with a * prefix on each line."
|
||||
(rust-with-comment-fill-prefix
|
||||
(lambda ()
|
||||
(apply 'do-auto-fill args)
|
||||
t)))
|
||||
|
||||
(defun rust-fill-forward-paragraph (arg)
|
||||
;; This is to work around some funny behavior when a paragraph separator is
|
||||
;; at the very top of the file and there is a fill prefix.
|
||||
(let ((fill-prefix nil)) (forward-paragraph arg)))
|
||||
|
||||
(defun rust-comment-indent-new-line (&optional arg)
|
||||
(rust-with-comment-fill-prefix
|
||||
(lambda () (comment-indent-new-line arg))))
|
||||
|
||||
;;; Imenu support
|
||||
(defvar rust-imenu-generic-expression
|
||||
(append (mapcar #'(lambda (x)
|
||||
(list nil (rust-re-item-def x) 1))
|
||||
'("enum" "struct" "type" "mod" "fn" "trait"))
|
||||
`(("Impl" ,(rust-re-item-def "impl") 1)))
|
||||
"Value for `imenu-generic-expression' in Rust mode.
|
||||
|
||||
Create a flat index of the item definitions in a Rust file.
|
||||
|
||||
Imenu will show all the enums, structs, etc. at the same level.
|
||||
Implementations will be shown under the `Impl` subheading. Use
|
||||
idomenu (imenu with `ido-mode') for best mileage.")
|
||||
|
||||
;;; Defun Motions
|
||||
|
||||
;;; Start of a Rust item
|
||||
(defvar rust-top-item-beg-re
|
||||
(concat "^\\s-*\\(?:priv\\|pub\\)?\\s-*"
|
||||
(regexp-opt
|
||||
'("enum" "struct" "type" "mod" "use" "fn" "static" "impl"
|
||||
"extern" "impl" "static" "trait"))))
|
||||
|
||||
(defun rust-beginning-of-defun (&optional arg)
|
||||
"Move backward to the beginning of the current defun.
|
||||
|
||||
With ARG, move backward multiple defuns. Negative ARG means
|
||||
move forward.
|
||||
|
||||
This is written mainly to be used as `beginning-of-defun-function' for Rust.
|
||||
Don't move to the beginning of the line. `beginning-of-defun',
|
||||
which calls this, does that afterwards."
|
||||
(interactive "p")
|
||||
(re-search-backward (concat "^\\(" rust-top-item-beg-re "\\)\\_>")
|
||||
nil 'move (or arg 1)))
|
||||
|
||||
(defun rust-end-of-defun ()
|
||||
"Move forward to the next end of defun.
|
||||
|
||||
With argument, do it that many times.
|
||||
Negative argument -N means move back to Nth preceding end of defun.
|
||||
|
||||
Assume that this is called after beginning-of-defun. So point is
|
||||
at the beginning of the defun body.
|
||||
|
||||
This is written mainly to be used as `end-of-defun-function' for Rust."
|
||||
(interactive "p")
|
||||
;; Find the opening brace
|
||||
(re-search-forward "[{]" nil t)
|
||||
(goto-char (match-beginning 0))
|
||||
;; Go to the closing brace
|
||||
(forward-sexp))
|
||||
|
||||
;; For compatibility with Emacs < 24, derive conditionally
|
||||
(defalias 'rust-parent-mode
|
||||
(if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
|
||||
|
||||
|
||||
;;;###autoload
|
||||
(define-derived-mode rust-mode rust-parent-mode "Rust"
|
||||
"Major mode for Rust code."
|
||||
:group 'rust-mode
|
||||
:syntax-table rust-mode-syntax-table
|
||||
|
||||
;; Indentation
|
||||
(setq-local indent-line-function 'rust-mode-indent-line)
|
||||
|
||||
;; Fonts
|
||||
(setq-local font-lock-defaults '(rust-mode-font-lock-keywords nil nil nil nil))
|
||||
|
||||
;; Misc
|
||||
(setq-local comment-start "// ")
|
||||
(setq-local comment-end "")
|
||||
(setq-local indent-tabs-mode nil)
|
||||
|
||||
;; Allow paragraph fills for comments
|
||||
(setq-local comment-start-skip "\\(?://[/!]*\\|/\\*[*!]?\\)[[:space:]]*")
|
||||
(setq-local paragraph-start
|
||||
(concat "[[:space:]]*\\(?:" comment-start-skip "\\|\\*/?[[:space:]]*\\|\\)$"))
|
||||
(setq-local paragraph-separate paragraph-start)
|
||||
(setq-local normal-auto-fill-function 'rust-do-auto-fill)
|
||||
(setq-local fill-paragraph-function 'rust-fill-paragraph)
|
||||
(setq-local fill-forward-paragraph-function 'rust-fill-forward-paragraph)
|
||||
(setq-local adaptive-fill-function 'rust-find-fill-prefix)
|
||||
(setq-local comment-multi-line t)
|
||||
(setq-local comment-line-break-function 'rust-comment-indent-new-line)
|
||||
(setq-local imenu-generic-expression rust-imenu-generic-expression)
|
||||
(setq-local beginning-of-defun-function 'rust-beginning-of-defun)
|
||||
(setq-local end-of-defun-function 'rust-end-of-defun))
|
||||
|
||||
;;;###autoload
|
||||
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
|
||||
|
||||
(defun rust-mode-reload ()
|
||||
(interactive)
|
||||
(unload-feature 'rust-mode)
|
||||
(require 'rust-mode)
|
||||
(rust-mode))
|
||||
|
||||
;; Issue #6887: Rather than inheriting the 'gnu compilation error
|
||||
;; regexp (which is broken on a few edge cases), add our own 'rust
|
||||
;; compilation error regexp and use it instead.
|
||||
(defvar rustc-compilation-regexps
|
||||
(let ((file "\\([^\n]+\\)")
|
||||
(start-line "\\([0-9]+\\)")
|
||||
(start-col "\\([0-9]+\\)")
|
||||
(end-line "\\([0-9]+\\)")
|
||||
(end-col "\\([0-9]+\\)")
|
||||
(error-or-warning "\\(?:[Ee]rror\\|\\([Ww]arning\\)\\)"))
|
||||
(let ((re (concat "^" file ":" start-line ":" start-col
|
||||
": " end-line ":" end-col
|
||||
" \\(?:[Ee]rror\\|\\([Ww]arning\\)\\):")))
|
||||
(cons re '(1 (2 . 4) (3 . 5) (6)))))
|
||||
"Specifications for matching errors in rustc invocations.
|
||||
See `compilation-error-regexp-alist for help on their format.")
|
||||
|
||||
(eval-after-load 'compile
|
||||
'(progn
|
||||
(add-to-list 'compilation-error-regexp-alist-alist
|
||||
(cons 'rustc rustc-compilation-regexps))
|
||||
(add-to-list 'compilation-error-regexp-alist 'rustc)))
|
||||
|
||||
(provide 'rust-mode)
|
||||
|
||||
;;; rust-mode.el ends here
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
Add syntax highlighting for Mozilla Rust in GtkSourceView (used by GEdit).
|
||||
|
||||
|
||||
Instructions for Ubuntu Linux 12.04+
|
||||
|
||||
1) Close all instances of GEdit
|
||||
|
||||
2) Copy the included "share" folder into "~/.local/"
|
||||
|
||||
3) Open a shell in "~/.local/share/" and run "update-mime-database mime"
|
||||
|
|
@ -1,340 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- Syntax highlighting for the under-development Mozilla Rust language -->
|
||||
|
||||
<language id="rust" _name="Rust" version="2.0" _section="Sources">
|
||||
<metadata>
|
||||
<property name="mimetypes">text/x-rust</property>
|
||||
<property name="globs">*.rs</property>
|
||||
<property name="line-comment-start">//</property>
|
||||
<property name="block-comment-start">/*</property>
|
||||
<property name="block-comment-end">*/</property>
|
||||
</metadata>
|
||||
|
||||
<styles>
|
||||
<style id="comment" _name="Comment" map-to="def:comment"/>
|
||||
<style id="string" _name="String" map-to="def:string"/>
|
||||
<style id="char" _name="Character" map-to="def:character"/>
|
||||
<style id="keyword" _name="Keyword" map-to="def:keyword"/>
|
||||
<style id="type" _name="Data Type" map-to="def:type"/>
|
||||
<style id="constant" _name="Constant" map-to="def:constant"/>
|
||||
<style id="identifier" _name="Identifier" map-to="def:identifier"/>
|
||||
<style id="number" _name="Number" map-to="def:number"/>
|
||||
<style id="scope" _name="Scope" map-to="def:preprocessor"/>
|
||||
<style id="attribute" _name="Attribute" map-to="def:preprocessor"/>
|
||||
<style id="macro" _name="Macro" map-to="def:preprocessor"/>
|
||||
</styles>
|
||||
|
||||
<definitions>
|
||||
|
||||
<context id="function" style-ref="keyword">
|
||||
<keyword>fn</keyword>
|
||||
</context>
|
||||
|
||||
<context id="type" style-ref="keyword">
|
||||
<keyword>type</keyword>
|
||||
</context>
|
||||
|
||||
<context id="keywords" style-ref="keyword">
|
||||
<keyword>as</keyword>
|
||||
<keyword>assert</keyword>
|
||||
<keyword>break</keyword>
|
||||
<keyword>box</keyword>
|
||||
<keyword>const</keyword>
|
||||
<keyword>continue</keyword>
|
||||
<keyword>crate</keyword>
|
||||
<keyword>do</keyword>
|
||||
<keyword>drop</keyword>
|
||||
<keyword>else</keyword>
|
||||
<keyword>enum</keyword>
|
||||
<keyword>export</keyword>
|
||||
<keyword>extern</keyword>
|
||||
<keyword>fail</keyword>
|
||||
<keyword>for</keyword>
|
||||
<keyword>if</keyword>
|
||||
<keyword>impl</keyword>
|
||||
<keyword>in</keyword>
|
||||
<keyword>let</keyword>
|
||||
<keyword>log</keyword>
|
||||
<keyword>loop</keyword>
|
||||
<keyword>match</keyword>
|
||||
<keyword>mod</keyword>
|
||||
<keyword>move</keyword>
|
||||
<keyword>mut</keyword>
|
||||
<keyword>priv</keyword>
|
||||
<keyword>pub</keyword>
|
||||
<keyword>pure</keyword>
|
||||
<keyword>ref</keyword>
|
||||
<keyword>return</keyword>
|
||||
<keyword>static</keyword>
|
||||
<keyword>struct</keyword>
|
||||
<keyword>trait</keyword>
|
||||
<keyword>unsafe</keyword>
|
||||
<keyword>use</keyword>
|
||||
<keyword>virtual</keyword>
|
||||
<keyword>where</keyword>
|
||||
<keyword>while</keyword>
|
||||
</context>
|
||||
|
||||
<context id="types" style-ref="type">
|
||||
<keyword>bool</keyword>
|
||||
<keyword>int</keyword>
|
||||
<keyword>isize</keyword>
|
||||
<keyword>uint</keyword>
|
||||
<keyword>usize</keyword>
|
||||
<keyword>i8</keyword>
|
||||
<keyword>i16</keyword>
|
||||
<keyword>i32</keyword>
|
||||
<keyword>i64</keyword>
|
||||
<keyword>u8</keyword>
|
||||
<keyword>u16</keyword>
|
||||
<keyword>u32</keyword>
|
||||
<keyword>u64</keyword>
|
||||
<keyword>f32</keyword>
|
||||
<keyword>f64</keyword>
|
||||
<keyword>char</keyword>
|
||||
<keyword>str</keyword>
|
||||
<keyword>Option</keyword>
|
||||
<keyword>Result</keyword>
|
||||
</context>
|
||||
|
||||
<context id="ctypes" style-ref="type">
|
||||
<keyword>c_float</keyword>
|
||||
<keyword>c_double</keyword>
|
||||
<keyword>c_void</keyword>
|
||||
<keyword>FILE</keyword>
|
||||
<keyword>fpos_t</keyword>
|
||||
<keyword>DIR</keyword>
|
||||
<keyword>dirent</keyword>
|
||||
<keyword>c_char</keyword>
|
||||
<keyword>c_schar</keyword>
|
||||
<keyword>c_uchar</keyword>
|
||||
<keyword>c_short</keyword>
|
||||
<keyword>c_ushort</keyword>
|
||||
<keyword>c_int</keyword>
|
||||
<keyword>c_uint</keyword>
|
||||
<keyword>c_long</keyword>
|
||||
<keyword>c_ulong</keyword>
|
||||
<keyword>size_t</keyword>
|
||||
<keyword>ptrdiff_t</keyword>
|
||||
<keyword>clock_t</keyword>
|
||||
<keyword>time_t</keyword>
|
||||
<keyword>c_longlong</keyword>
|
||||
<keyword>c_ulonglong</keyword>
|
||||
<keyword>intptr_t</keyword>
|
||||
<keyword>uintptr_t</keyword>
|
||||
<keyword>off_t</keyword>
|
||||
<keyword>dev_t</keyword>
|
||||
<keyword>ino_t</keyword>
|
||||
<keyword>pid_t</keyword>
|
||||
<keyword>mode_t</keyword>
|
||||
<keyword>ssize_t</keyword>
|
||||
</context>
|
||||
|
||||
<context id="self" style-ref="identifier">
|
||||
<keyword>self</keyword>
|
||||
</context>
|
||||
|
||||
<context id="constants" style-ref="constant">
|
||||
<keyword>true</keyword>
|
||||
<keyword>false</keyword>
|
||||
<keyword>Some</keyword>
|
||||
<keyword>None</keyword>
|
||||
<keyword>Ok</keyword>
|
||||
<keyword>Err</keyword>
|
||||
<keyword>Success</keyword>
|
||||
<keyword>Failure</keyword>
|
||||
<keyword>Cons</keyword>
|
||||
<keyword>Nil</keyword>
|
||||
</context>
|
||||
|
||||
<context id="cconstants" style-ref="constant">
|
||||
<keyword>EXIT_FAILURE</keyword>
|
||||
<keyword>EXIT_SUCCESS</keyword>
|
||||
<keyword>RAND_MAX</keyword>
|
||||
<keyword>EOF</keyword>
|
||||
<keyword>SEEK_SET</keyword>
|
||||
<keyword>SEEK_CUR</keyword>
|
||||
<keyword>SEEK_END</keyword>
|
||||
<keyword>_IOFBF</keyword>
|
||||
<keyword>_IONBF</keyword>
|
||||
<keyword>_IOLBF</keyword>
|
||||
<keyword>BUFSIZ</keyword>
|
||||
<keyword>FOPEN_MAX</keyword>
|
||||
<keyword>FILENAME_MAX</keyword>
|
||||
<keyword>L_tmpnam</keyword>
|
||||
<keyword>TMP_MAX</keyword>
|
||||
<keyword>O_RDONLY</keyword>
|
||||
<keyword>O_WRONLY</keyword>
|
||||
<keyword>O_RDWR</keyword>
|
||||
<keyword>O_APPEND</keyword>
|
||||
<keyword>O_CREAT</keyword>
|
||||
<keyword>O_EXCL</keyword>
|
||||
<keyword>O_TRUNC</keyword>
|
||||
<keyword>S_IFIFO</keyword>
|
||||
<keyword>S_IFCHR</keyword>
|
||||
<keyword>S_IFBLK</keyword>
|
||||
<keyword>S_IFDIR</keyword>
|
||||
<keyword>S_IFREG</keyword>
|
||||
<keyword>S_IFMT</keyword>
|
||||
<keyword>S_IEXEC</keyword>
|
||||
<keyword>S_IWRITE</keyword>
|
||||
<keyword>S_IREAD</keyword>
|
||||
<keyword>S_IRWXU</keyword>
|
||||
<keyword>S_IXUSR</keyword>
|
||||
<keyword>S_IWUSR</keyword>
|
||||
<keyword>S_IRUSR</keyword>
|
||||
<keyword>F_OK</keyword>
|
||||
<keyword>R_OK</keyword>
|
||||
<keyword>W_OK</keyword>
|
||||
<keyword>X_OK</keyword>
|
||||
<keyword>STDIN_FILENO</keyword>
|
||||
<keyword>STDOUT_FILENO</keyword>
|
||||
<keyword>STDERR_FILENO</keyword>
|
||||
</context>
|
||||
|
||||
<context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment" class-disabled="no-spell-check">
|
||||
<start>//</start>
|
||||
<include>
|
||||
<context ref="def:in-line-comment"/>
|
||||
</include>
|
||||
</context>
|
||||
|
||||
<context id="block-comment" style-ref="comment" class="comment" class-disabled="no-spell-check">
|
||||
<start>/\*</start>
|
||||
<end>\*/</end>
|
||||
<include>
|
||||
<context ref="def:in-comment"/>
|
||||
</include>
|
||||
</context>
|
||||
|
||||
<define-regex id="int_suffix" extended="true">
|
||||
(i8|i16|i32|i64|i|u8|u16|u32|u64|u)
|
||||
</define-regex>
|
||||
|
||||
<define-regex id="exponent" extended="true">
|
||||
([eE][+-]?[0-9_]+)
|
||||
</define-regex>
|
||||
|
||||
<define-regex id="float_suffix" extended="true">
|
||||
(\%{exponent}?(f32|f64)?)|(\.[0-9][0-9_]*\%{exponent}?)?(f32|f64)?|\.
|
||||
</define-regex>
|
||||
|
||||
<define-regex id="num_suffix" extended="true">
|
||||
\%{int_suffix}|\%{float_suffix}
|
||||
</define-regex>
|
||||
|
||||
<define-regex id="hex_digit" extended="true">
|
||||
[0-9a-fA-F]
|
||||
</define-regex>
|
||||
|
||||
<define-regex id="oct_digit" extended="true">
|
||||
[0-7]
|
||||
</define-regex>
|
||||
|
||||
<context id="number" style-ref="number">
|
||||
<match extended="true">
|
||||
((?<=\.\.)|(?<![\w\.]))
|
||||
(
|
||||
[1-9][0-9_]*\%{num_suffix}?|
|
||||
0[0-9_]*\%{num_suffix}?|
|
||||
0b[01_]+\%{int_suffix}?|
|
||||
0o(\%{oct_digit}|_)+\%{int_suffix}?|
|
||||
0x(\%{hex_digit}|_)+\%{int_suffix}?
|
||||
)
|
||||
((?![\w\.].)|(?=\.\.))
|
||||
</match>
|
||||
</context>
|
||||
|
||||
<define-regex id="ident" extended="true">
|
||||
([^[:cntrl:][:space:][:punct:][:digit:]]|_)([^[:cntrl:][:punct:][:space:]]|_)*
|
||||
</define-regex>
|
||||
|
||||
<context id="scope" style-ref="scope">
|
||||
<match extended="true">
|
||||
\%{ident}::
|
||||
</match>
|
||||
</context>
|
||||
|
||||
<context id="macro" style-ref="macro">
|
||||
<match extended="true">
|
||||
\%{ident}!
|
||||
</match>
|
||||
</context>
|
||||
|
||||
<context id="lifetime" style-ref="keyword">
|
||||
<match extended="true">
|
||||
'\%{ident}
|
||||
</match>
|
||||
</context>
|
||||
|
||||
<define-regex id="common_escape" extended="true">
|
||||
'|"|
|
||||
\\|n|r|t|0|
|
||||
x\%{hex_digit}{2}|
|
||||
u{\%{hex_digit}{1,6}}|
|
||||
u\%{hex_digit}{4}|
|
||||
U\%{hex_digit}{8}
|
||||
</define-regex>
|
||||
|
||||
<context id="string_escape" style-ref="def:special-char">
|
||||
<match>\\\%{common_escape}</match>
|
||||
</context>
|
||||
|
||||
<context id="raw-string" style-ref="string" class="string" class-disabled="no-spell-check">
|
||||
<start>r(#*)"</start>
|
||||
<end>"\%{1@start}</end>
|
||||
<include>
|
||||
<context ref="def:line-continue"/>
|
||||
</include>
|
||||
</context>
|
||||
|
||||
<context id="string" style-ref="string" class="string" class-disabled="no-spell-check">
|
||||
<start>"</start>
|
||||
<end>"</end>
|
||||
<include>
|
||||
<context ref="string_escape"/>
|
||||
<context ref="def:line-continue"/>
|
||||
</include>
|
||||
</context>
|
||||
|
||||
<context id="char" style-ref="char">
|
||||
<match extended="true">'([^\\']|\\\%{common_escape})'</match>
|
||||
</context>
|
||||
|
||||
<context id="attribute" style-ref="attribute" class="attribute">
|
||||
<start extended="true">\#!?\[</start>
|
||||
<end>\]</end>
|
||||
<include>
|
||||
<context ref="def:in-comment"/>
|
||||
<context ref="string"/>
|
||||
<context ref="raw-string"/>
|
||||
</include>
|
||||
</context>
|
||||
|
||||
<context id="rust" class="no-spell-check">
|
||||
<include>
|
||||
<context ref="function"/>
|
||||
<context ref="type"/>
|
||||
<context ref="keywords"/>
|
||||
<context ref="types"/>
|
||||
<context ref="ctypes"/>
|
||||
<context ref="self"/>
|
||||
<context ref="macro"/>
|
||||
<context ref="constants"/>
|
||||
<context ref="cconstants"/>
|
||||
<context ref="line-comment"/>
|
||||
<context ref="block-comment"/>
|
||||
<context ref="number"/>
|
||||
<context ref="scope"/>
|
||||
<context ref="string"/>
|
||||
<context ref="raw-string"/>
|
||||
<context ref="char"/>
|
||||
<context ref="lifetime"/>
|
||||
<context ref="attribute"/>
|
||||
</include>
|
||||
</context>
|
||||
|
||||
</definitions>
|
||||
|
||||
</language>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
|
||||
<mime-type type="text/x-rust">
|
||||
<comment>Rust Source</comment>
|
||||
<glob pattern="*.rs"/>
|
||||
</mime-type>
|
||||
</mime-info>
|
||||
|
|
@ -1,304 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE language SYSTEM "language.dtd"
|
||||
[
|
||||
<!-- FIXME: Kate's regex engine has very limited support for
|
||||
predefined char classes, so making rustIdent consistent with actual
|
||||
Rust identifiers will be a bit difficult -->
|
||||
<!ENTITY rustIdent "[a-zA-Z_][a-zA-Z_0-9]*">
|
||||
<!ENTITY rustIntSuf "([iu](8|16|32|64)?)?">
|
||||
]>
|
||||
<language name="Rust" version="1.0.0" kateversion="2.4" section="Sources" extensions="*.rs" mimetype="text/x-rust" priority="15">
|
||||
<highlighting>
|
||||
<list name="fn">
|
||||
<item> fn </item>
|
||||
</list>
|
||||
<list name="type">
|
||||
<item> type </item>
|
||||
</list>
|
||||
<list name="reserved">
|
||||
<item> abstract </item>
|
||||
<item> alignof </item>
|
||||
<item> be </item>
|
||||
<item> do </item>
|
||||
<item> final </item>
|
||||
<item> offsetof </item>
|
||||
<item> override </item>
|
||||
<item> priv </item>
|
||||
<item> pure </item>
|
||||
<item> sizeof </item>
|
||||
<item> typeof </item>
|
||||
<item> unsized </item>
|
||||
<item> yield </item>
|
||||
</list>
|
||||
<list name="keywords">
|
||||
<item> as </item>
|
||||
<item> box </item>
|
||||
<item> break </item>
|
||||
<item> const </item>
|
||||
<item> continue </item>
|
||||
<item> crate </item>
|
||||
<item> else </item>
|
||||
<item> enum </item>
|
||||
<item> extern </item>
|
||||
<item> for </item>
|
||||
<item> if </item>
|
||||
<item> impl </item>
|
||||
<item> in </item>
|
||||
<item> let </item>
|
||||
<item> loop </item>
|
||||
<item> match </item>
|
||||
<item> mod </item>
|
||||
<item> move </item>
|
||||
<item> mut </item>
|
||||
<item> pub </item>
|
||||
<item> ref </item>
|
||||
<item> return </item>
|
||||
<item> static </item>
|
||||
<item> struct </item>
|
||||
<item> super </item>
|
||||
<item> trait </item>
|
||||
<item> unsafe </item>
|
||||
<item> use </item>
|
||||
<item> virtual </item>
|
||||
<item> where </item>
|
||||
<item> while </item>
|
||||
</list>
|
||||
<list name="traits">
|
||||
<item> Const </item>
|
||||
<item> Copy </item>
|
||||
<item> Send </item>
|
||||
<item> Owned </item>
|
||||
<item> Sized </item>
|
||||
<item> Eq </item>
|
||||
<item> Ord </item>
|
||||
<item> Num </item>
|
||||
<item> Ptr </item>
|
||||
<item> Drop </item>
|
||||
<item> Add </item>
|
||||
<item> Sub </item>
|
||||
<item> Mul </item>
|
||||
<item> Quot </item>
|
||||
<item> Rem </item>
|
||||
<item> Neg </item>
|
||||
<item> BitAnd </item>
|
||||
<item> BitOr </item>
|
||||
<item> BitXor </item>
|
||||
<item> Shl </item>
|
||||
<item> Shr </item>
|
||||
<item> Index </item>
|
||||
<item> Not </item>
|
||||
</list>
|
||||
<list name="types">
|
||||
<item> bool </item>
|
||||
<item> int </item>
|
||||
<item> isize </item>
|
||||
<item> uint </item>
|
||||
<item> usize </item>
|
||||
<item> i8 </item>
|
||||
<item> i16 </item>
|
||||
<item> i32 </item>
|
||||
<item> i64 </item>
|
||||
<item> u8 </item>
|
||||
<item> u16 </item>
|
||||
<item> u32 </item>
|
||||
<item> u64 </item>
|
||||
<item> f32 </item>
|
||||
<item> f64 </item>
|
||||
<item> float </item>
|
||||
<item> char </item>
|
||||
<item> str </item>
|
||||
<item> Option </item>
|
||||
<item> Result </item>
|
||||
<item> Self </item>
|
||||
</list>
|
||||
<list name="ctypes">
|
||||
<item> c_float </item>
|
||||
<item> c_double </item>
|
||||
<item> c_void </item>
|
||||
<item> FILE </item>
|
||||
<item> fpos_t </item>
|
||||
<item> DIR </item>
|
||||
<item> dirent </item>
|
||||
<item> c_char </item>
|
||||
<item> c_schar </item>
|
||||
<item> c_uchar </item>
|
||||
<item> c_short </item>
|
||||
<item> c_ushort </item>
|
||||
<item> c_int </item>
|
||||
<item> c_uint </item>
|
||||
<item> c_long </item>
|
||||
<item> c_ulong </item>
|
||||
<item> size_t </item>
|
||||
<item> ptrdiff_t </item>
|
||||
<item> clock_t </item>
|
||||
<item> time_t </item>
|
||||
<item> c_longlong </item>
|
||||
<item> c_ulonglong </item>
|
||||
<item> intptr_t </item>
|
||||
<item> uintptr_t </item>
|
||||
<item> off_t </item>
|
||||
<item> dev_t </item>
|
||||
<item> ino_t </item>
|
||||
<item> pid_t </item>
|
||||
<item> mode_t </item>
|
||||
<item> ssize_t </item>
|
||||
</list>
|
||||
<list name="self">
|
||||
<item> self </item>
|
||||
</list>
|
||||
<list name="constants">
|
||||
<item> true </item>
|
||||
<item> false </item>
|
||||
<item> Some </item>
|
||||
<item> None </item>
|
||||
<item> Ok </item>
|
||||
<item> Err </item>
|
||||
<item> Success </item>
|
||||
<item> Failure </item>
|
||||
<item> Cons </item>
|
||||
<item> Nil </item>
|
||||
</list>
|
||||
<list name="cconstants">
|
||||
<item> EXIT_FAILURE </item>
|
||||
<item> EXIT_SUCCESS </item>
|
||||
<item> RAND_MAX </item>
|
||||
<item> EOF </item>
|
||||
<item> SEEK_SET </item>
|
||||
<item> SEEK_CUR </item>
|
||||
<item> SEEK_END </item>
|
||||
<item> _IOFBF </item>
|
||||
<item> _IONBF </item>
|
||||
<item> _IOLBF </item>
|
||||
<item> BUFSIZ </item>
|
||||
<item> FOPEN_MAX </item>
|
||||
<item> FILENAME_MAX </item>
|
||||
<item> L_tmpnam </item>
|
||||
<item> TMP_MAX </item>
|
||||
<item> O_RDONLY </item>
|
||||
<item> O_WRONLY </item>
|
||||
<item> O_RDWR </item>
|
||||
<item> O_APPEND </item>
|
||||
<item> O_CREAT </item>
|
||||
<item> O_EXCL </item>
|
||||
<item> O_TRUNC </item>
|
||||
<item> S_IFIFO </item>
|
||||
<item> S_IFCHR </item>
|
||||
<item> S_IFBLK </item>
|
||||
<item> S_IFDIR </item>
|
||||
<item> S_IFREG </item>
|
||||
<item> S_IFMT </item>
|
||||
<item> S_IEXEC </item>
|
||||
<item> S_IWRITE </item>
|
||||
<item> S_IREAD </item>
|
||||
<item> S_IRWXU </item>
|
||||
<item> S_IXUSR </item>
|
||||
<item> S_IWUSR </item>
|
||||
<item> S_IRUSR </item>
|
||||
<item> F_OK </item>
|
||||
<item> R_OK </item>
|
||||
<item> W_OK </item>
|
||||
<item> X_OK </item>
|
||||
<item> STDIN_FILENO </item>
|
||||
<item> STDOUT_FILENO </item>
|
||||
<item> STDERR_FILENO </item>
|
||||
</list>
|
||||
<contexts>
|
||||
<context attribute="Normal Text" lineEndContext="#stay" name="Normal">
|
||||
<DetectSpaces/>
|
||||
<keyword String="fn" attribute="Keyword" context="Function"/>
|
||||
<keyword String="type" attribute="Keyword" context="Type"/>
|
||||
<keyword String="reserved" attribute="Keyword" context="#stay"/>
|
||||
<keyword String="keywords" attribute="Keyword" context="#stay"/>
|
||||
<keyword String="types" attribute="Type" context="#stay"/>
|
||||
<keyword String="traits" attribute="Trait" context="#stay"/>
|
||||
<keyword String="ctypes" attribute="CType" context="#stay"/>
|
||||
<keyword String="self" attribute="Self" context="#stay"/>
|
||||
<keyword String="constants" attribute="Constant" context="#stay"/>
|
||||
<keyword String="cconstants" attribute="CConstant" context="#stay"/>
|
||||
<Detect2Chars char="/" char1="/" attribute="Comment" context="Commentar 1"/>
|
||||
<Detect2Chars char="/" char1="*" attribute="Comment" context="Commentar 2" beginRegion="Comment"/>
|
||||
<RegExpr String="0x[0-9a-fA-F_]+&rustIntSuf;" attribute="Number" context="#stay"/>
|
||||
<RegExpr String="0o[0-7_]+&rustIntSuf;" attribute="Number" context="#stay"/>
|
||||
<RegExpr String="0b[0-1_]+&rustIntSuf;" attribute="Number" context="#stay"/>
|
||||
<RegExpr String="[0-9][0-9_]*\.[0-9_]*([eE][+-]?[0-9_]+)?(f32|f64|f)?" attribute="Number" context="#stay"/>
|
||||
<RegExpr String="[0-9][0-9_]*&rustIntSuf;" attribute="Number" context="#stay"/>
|
||||
<Detect2Chars char="#" char1="[" attribute="Attribute" context="Attribute" beginRegion="Attribute"/>
|
||||
<StringDetect String="#![" attribute="Attribute" context="Attribute" beginRegion="Attribute"/>
|
||||
<RegExpr String="&rustIdent;::" attribute="Scope"/>
|
||||
<RegExpr String="&rustIdent;!" attribute="Macro"/>
|
||||
<RegExpr String="'&rustIdent;(?!')" attribute="Lifetime"/>
|
||||
<DetectChar char="{" attribute="Symbol" context="#stay" beginRegion="Brace" />
|
||||
<DetectChar char="}" attribute="Symbol" context="#stay" endRegion="Brace" />
|
||||
<DetectChar char=""" attribute="String" context="String"/>
|
||||
<DetectChar char="'" attribute="Character" context="Character"/>
|
||||
<DetectChar char="[" attribute="Symbol" context="#stay" beginRegion="Bracket" />
|
||||
<DetectChar char="]" attribute="Symbol" context="#stay" endRegion="Bracket" />
|
||||
<DetectIdentifier/>
|
||||
</context>
|
||||
<context attribute="Attribute" lineEndContext="#stay" name="Attribute">
|
||||
<DetectChar char="]" attribute="Attribute" context="#pop" endRegion="Attribute"/>
|
||||
<IncludeRules context="Normal"/>
|
||||
</context>
|
||||
<context attribute="Definition" lineEndContext="#stay" name="Function">
|
||||
<DetectSpaces/>
|
||||
<DetectChar char="(" attribute="Normal Text" context="#pop"/>
|
||||
<DetectChar char="<" attribute="Normal Text" context="#pop"/>
|
||||
</context>
|
||||
<context attribute="Definition" lineEndContext="#stay" name="Type">
|
||||
<DetectSpaces/>
|
||||
<DetectChar char="=" attribute="Normal Text" context="#pop"/>
|
||||
<DetectChar char="<" attribute="Normal Text" context="#pop"/>
|
||||
</context>
|
||||
<context attribute="String" lineEndContext="#pop" name="String">
|
||||
<LineContinue attribute="String" context="#stay"/>
|
||||
<DetectChar char="\" attribute="CharEscape" context="CharEscape"/>
|
||||
<DetectChar attribute="String" context="#pop" char="""/>
|
||||
</context>
|
||||
<context attribute="Character" lineEndContext="#pop" name="Character">
|
||||
<DetectChar char="\" attribute="CharEscape" context="CharEscape"/>
|
||||
<DetectChar attribute="Character" context="#pop" char="'"/>
|
||||
</context>
|
||||
<context attribute="CharEscape" lineEndContext="#pop" name="CharEscape">
|
||||
<AnyChar String="nrt\'"" attribute="CharEscape" context="#pop"/>
|
||||
<RegExpr String="x[0-9a-fA-F]{2}" attribute="CharEscape" context="#pop"/>
|
||||
<RegExpr String="u\{[0-9a-fA-F]{1,6}\}" attribute="CharEscape" context="#pop"/>
|
||||
<RegExpr String="u[0-9a-fA-F]{4}" attribute="CharEscape" context="#pop"/>
|
||||
<RegExpr String="U[0-9a-fA-F]{8}" attribute="CharEscape" context="#pop"/>
|
||||
<RegExpr String="." attribute="Error" context="#pop"/>
|
||||
</context>
|
||||
<context attribute="Comment" lineEndContext="#pop" name="Commentar 1"/>
|
||||
<context attribute="Comment" lineEndContext="#stay" name="Commentar 2">
|
||||
<DetectSpaces/>
|
||||
<Detect2Chars char="*" char1="/" attribute="Comment" context="#pop" endRegion="Comment"/>
|
||||
</context>
|
||||
</contexts>
|
||||
<itemDatas>
|
||||
<itemData name="Normal Text" defStyleNum="dsNormal"/>
|
||||
<itemData name="Keyword" defStyleNum="dsKeyword" color="#770088" bold="1"/>
|
||||
<itemData name="Self" defStyleNum="dsKeyword" color="#FF0000" bold="1"/>
|
||||
<itemData name="Type" defStyleNum="dsKeyword" color="#4e9a06" bold="1"/>
|
||||
<itemData name="Trait" defStyleNum="dsKeyword" color="#4e9a06" bold="1"/>
|
||||
<itemData name="CType" defStyleNum="dsNormal" color="#4e9a06"/>
|
||||
<itemData name="Constant" defStyleNum="dsKeyword" color="#116644"/>
|
||||
<itemData name="CConstant" defStyleNum="dsNormal" color="#116644"/>
|
||||
<itemData name="Definition" defStyleNum="dsNormal" color="#0000FF"/>
|
||||
<itemData name="Comment" defStyleNum="dsComment" color="#AA5500"/>
|
||||
<itemData name="Scope" defStyleNum="dsNormal" color="#0055AA"/>
|
||||
<itemData name="Number" defStyleNum="dsDecVal" color="#116644"/>
|
||||
<itemData name="String" defStyleNum="dsString" color="#FF0000"/>
|
||||
<itemData name="CharEscape" defStyleNum="dsChar" color="#FF0000" bold="1"/>
|
||||
<itemData name="Character" defStyleNum="dsChar" color="#FF0000"/>
|
||||
<itemData name="Macro" defStyleNum="dsOthers"/>
|
||||
<itemData name="Attribute" defStyleNum="dsOthers"/>
|
||||
<itemData name="Lifetime" defStyleNum="dsOthers" bold="1"/>
|
||||
<itemData name="Error" defStyleNum="dsError"/>
|
||||
</itemDatas>
|
||||
</highlighting>
|
||||
<general>
|
||||
<comments>
|
||||
<comment name="singleLine" start="//" />
|
||||
<comment name="multiLine" start="/*" end="*/" region="Comment"/>
|
||||
</comments>
|
||||
<keywords casesensitive="1" />
|
||||
</general>
|
||||
</language>
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
# Nano configuration for Rust
|
||||
# Copyright 2015 The Rust Project Developers.
|
||||
#
|
||||
# NOTE: Rules are applied in order: later rules re-colorize matching text.
|
||||
syntax "rust" "\.rs"
|
||||
|
||||
# function definition
|
||||
color magenta "fn [a-z0-9_]+"
|
||||
|
||||
# Reserved words
|
||||
color yellow "\<(abstract|alignof|as|be|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|offsetof|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|unsafe|unsized|use|virtual|where|while|yield)\>"
|
||||
|
||||
# macros
|
||||
color red "[a-z_]+!"
|
||||
|
||||
# Constants
|
||||
color magenta "[A-Z][A-Z_]+"
|
||||
|
||||
# Traits/Enums/Structs/Types/etc.
|
||||
color magenta "[A-Z][a-z]+"
|
||||
|
||||
# Strings
|
||||
color green "\".*\""
|
||||
color green start="\".*\\$" end=".*\""
|
||||
# NOTE: This isn't accurate but matching "#{0,} for the end of the string is too liberal
|
||||
color green start="r#+\"" end="\"#+"
|
||||
|
||||
# Comments
|
||||
color blue "//.*"
|
||||
|
||||
# Attributes
|
||||
color magenta start="#!\[" end="\]"
|
||||
|
||||
# Some common markers
|
||||
color brightcyan "(XXX|TODO|FIXME|\?\?\?)"
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
if !exists('g:rust_conceal') || !has('conceal') || &enc != 'utf-8'
|
||||
finish
|
||||
endif
|
||||
|
||||
" For those who don't want to see `::`...
|
||||
if exists('g:rust_conceal_mod_path')
|
||||
syn match rustNiceOperator "::" conceal cchar=ㆍ
|
||||
endif
|
||||
|
||||
syn match rustRightArrowHead contained ">" conceal cchar=
|
||||
syn match rustRightArrowTail contained "-" conceal cchar=⟶
|
||||
syn match rustNiceOperator "->" contains=rustRightArrowHead,rustRightArrowTail
|
||||
|
||||
syn match rustFatRightArrowHead contained ">" conceal cchar=
|
||||
syn match rustFatRightArrowTail contained "=" conceal cchar=⟹
|
||||
syn match rustNiceOperator "=>" contains=rustFatRightArrowHead,rustFatRightArrowTail
|
||||
|
||||
syn match rustNiceOperator /\<\@!_\(_*\>\)\@=/ conceal cchar=′
|
||||
|
||||
" For those who don't want to see `pub`...
|
||||
if exists('g:rust_conceal_pub')
|
||||
syn match rustPublicSigil contained "pu" conceal cchar=*
|
||||
syn match rustPublicRest contained "b" conceal cchar=
|
||||
syn match rustNiceOperator "pub " contains=rustPublicSigil,rustPublicRest
|
||||
endif
|
||||
|
||||
hi link rustNiceOperator Operator
|
||||
|
||||
if !exists('g:rust_conceal_mod_path')
|
||||
hi! link Conceal Operator
|
||||
endif
|
||||
|
|
@ -1,225 +0,0 @@
|
|||
" Author: Kevin Ballard
|
||||
" Description: Helper functions for Rust commands/mappings
|
||||
" Last Modified: May 27, 2014
|
||||
|
||||
" Jump {{{1
|
||||
|
||||
function! rust#Jump(mode, function) range
|
||||
let cnt = v:count1
|
||||
normal! m'
|
||||
if a:mode ==# 'v'
|
||||
norm! gv
|
||||
endif
|
||||
let foldenable = &foldenable
|
||||
set nofoldenable
|
||||
while cnt > 0
|
||||
execute "call <SID>Jump_" . a:function . "()"
|
||||
let cnt = cnt - 1
|
||||
endwhile
|
||||
let &foldenable = foldenable
|
||||
endfunction
|
||||
|
||||
function! s:Jump_Back()
|
||||
call search('{', 'b')
|
||||
keepjumps normal! w99[{
|
||||
endfunction
|
||||
|
||||
function! s:Jump_Forward()
|
||||
normal! j0
|
||||
call search('{', 'b')
|
||||
keepjumps normal! w99[{%
|
||||
call search('{')
|
||||
endfunction
|
||||
|
||||
" Run {{{1
|
||||
|
||||
function! rust#Run(bang, args)
|
||||
if a:bang
|
||||
let idx = index(a:args, '--')
|
||||
if idx != -1
|
||||
let rustc_args = idx == 0 ? [] : a:args[:idx-1]
|
||||
let args = a:args[idx+1:]
|
||||
else
|
||||
let rustc_args = a:args
|
||||
let args = []
|
||||
endif
|
||||
else
|
||||
let rustc_args = []
|
||||
let args = a:args
|
||||
endif
|
||||
|
||||
let b:rust_last_rustc_args = rustc_args
|
||||
let b:rust_last_args = args
|
||||
|
||||
call s:WithPath(function("s:Run"), rustc_args, args)
|
||||
endfunction
|
||||
|
||||
function! s:Run(path, rustc_args, args)
|
||||
try
|
||||
let exepath = tempname()
|
||||
if has('win32')
|
||||
let exepath .= '.exe'
|
||||
endif
|
||||
|
||||
let rustc_args = [a:path, '-o', exepath] + a:rustc_args
|
||||
|
||||
let rustc = exists("g:rustc_path") ? g:rustc_path : "rustc"
|
||||
|
||||
let output = system(shellescape(rustc) . " " . join(map(rustc_args, 'shellescape(v:val)')))
|
||||
if output != ''
|
||||
echohl WarningMsg
|
||||
echo output
|
||||
echohl None
|
||||
endif
|
||||
if !v:shell_error
|
||||
exe '!' . shellescape(exepath) . " " . join(map(a:args, 'shellescape(v:val)'))
|
||||
endif
|
||||
finally
|
||||
if exists("exepath")
|
||||
silent! call delete(exepath)
|
||||
endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" Expand {{{1
|
||||
|
||||
function! rust#Expand(bang, args)
|
||||
if a:bang && !empty(a:args)
|
||||
let pretty = a:args[0]
|
||||
let args = a:args[1:]
|
||||
else
|
||||
let pretty = "expanded"
|
||||
let args = a:args
|
||||
endif
|
||||
call s:WithPath(function("s:Expand"), pretty, args)
|
||||
endfunction
|
||||
|
||||
function! s:Expand(path, pretty, args)
|
||||
try
|
||||
let rustc = exists("g:rustc_path") ? g:rustc_path : "rustc"
|
||||
|
||||
let args = [a:path, '--pretty', a:pretty] + a:args
|
||||
let output = system(shellescape(rustc) . " " . join(map(args, "shellescape(v:val)")))
|
||||
if v:shell_error
|
||||
echohl WarningMsg
|
||||
echo output
|
||||
echohl None
|
||||
else
|
||||
new
|
||||
silent put =output
|
||||
1
|
||||
d
|
||||
setl filetype=rust
|
||||
setl buftype=nofile
|
||||
setl bufhidden=hide
|
||||
setl noswapfile
|
||||
endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! rust#CompleteExpand(lead, line, pos)
|
||||
if a:line[: a:pos-1] =~ '^RustExpand!\s*\S*$'
|
||||
" first argument and it has a !
|
||||
let list = ["normal", "expanded", "typed", "expanded,identified", "flowgraph="]
|
||||
if !empty(a:lead)
|
||||
call filter(list, "v:val[:len(a:lead)-1] == a:lead")
|
||||
endif
|
||||
return list
|
||||
endif
|
||||
|
||||
return glob(escape(a:lead, "*?[") . '*', 0, 1)
|
||||
endfunction
|
||||
|
||||
" Emit {{{1
|
||||
|
||||
function! rust#Emit(type, args)
|
||||
call s:WithPath(function("s:Emit"), a:type, a:args)
|
||||
endfunction
|
||||
|
||||
function! s:Emit(path, type, args)
|
||||
try
|
||||
let rustc = exists("g:rustc_path") ? g:rustc_path : "rustc"
|
||||
|
||||
let args = [a:path, '--emit', a:type, '-o', '-'] + a:args
|
||||
let output = system(shellescape(rustc) . " " . join(map(args, "shellescape(v:val)")))
|
||||
if v:shell_error
|
||||
echohl WarningMsg
|
||||
echo output
|
||||
echohl None
|
||||
else
|
||||
new
|
||||
silent put =output
|
||||
1
|
||||
d
|
||||
if a:type == "ir"
|
||||
setl filetype=llvm
|
||||
elseif a:type == "asm"
|
||||
setl filetype=asm
|
||||
endif
|
||||
setl buftype=nofile
|
||||
setl bufhidden=hide
|
||||
setl noswapfile
|
||||
endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" Utility functions {{{1
|
||||
|
||||
function! s:WithPath(func, ...)
|
||||
try
|
||||
let save_write = &write
|
||||
set write
|
||||
let path = expand('%')
|
||||
let pathisempty = empty(path)
|
||||
if pathisempty || !save_write
|
||||
" use a temporary file named 'unnamed.rs' inside a temporary
|
||||
" directory. This produces better error messages
|
||||
let tmpdir = tempname()
|
||||
call mkdir(tmpdir)
|
||||
|
||||
let save_cwd = getcwd()
|
||||
silent exe 'lcd' fnameescape(tmpdir)
|
||||
|
||||
let path = 'unnamed.rs'
|
||||
|
||||
let save_mod = &mod
|
||||
set nomod
|
||||
|
||||
silent exe 'keepalt write! ' . fnameescape(path)
|
||||
if pathisempty
|
||||
silent keepalt 0file
|
||||
endif
|
||||
else
|
||||
update
|
||||
endif
|
||||
|
||||
call call(a:func, [path] + a:000)
|
||||
finally
|
||||
if exists("save_mod") | let &mod = save_mod | endif
|
||||
if exists("save_write") | let &write = save_write | endif
|
||||
if exists("save_cwd") | silent exe 'lcd' fnameescape(save_cwd) | endif
|
||||
if exists("tmpdir") | silent call s:RmDir(tmpdir) | endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! rust#AppendCmdLine(text)
|
||||
call setcmdpos(getcmdpos())
|
||||
let cmd = getcmdline() . a:text
|
||||
return cmd
|
||||
endfunction
|
||||
|
||||
function! s:RmDir(path)
|
||||
" sanity check; make sure it's not empty, /, or $HOME
|
||||
if empty(a:path)
|
||||
echoerr 'Attempted to delete empty path'
|
||||
return 0
|
||||
elseif a:path == '/' || a:path == $HOME
|
||||
echoerr 'Attempted to delete protected path: ' . a:path
|
||||
return 0
|
||||
endif
|
||||
silent exe "!rm -rf " . shellescape(a:path)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
" vim: set noet sw=4 ts=4:
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
" Vim compiler file
|
||||
" Compiler: Cargo Compiler
|
||||
" Maintainer: Damien Radtke <damienradtke@gmail.com>
|
||||
" Latest Revision: 2014 Sep 24
|
||||
|
||||
if exists('current_compiler')
|
||||
finish
|
||||
endif
|
||||
runtime compiler/rustc.vim
|
||||
let current_compiler = "cargo"
|
||||
|
||||
if exists(':CompilerSet') != 2
|
||||
command -nargs=* CompilerSet setlocal <args>
|
||||
endif
|
||||
|
||||
if exists('g:cargo_makeprg_params')
|
||||
execute 'CompilerSet makeprg=cargo\ '.escape(g:cargo_makeprg_params, ' \|"').'\ $*'
|
||||
else
|
||||
CompilerSet makeprg=cargo\ $*
|
||||
endif
|
||||
|
||||
" Allow a configurable global Cargo.toml name. This makes it easy to
|
||||
" support variations like 'cargo.toml'.
|
||||
let s:cargo_manifest_name = get(g:, 'cargo_manifest_name', 'Cargo.toml')
|
||||
|
||||
function! s:is_absolute(path)
|
||||
return a:path[0] == '/' || a:path =~ '[A-Z]\+:'
|
||||
endfunction
|
||||
|
||||
let s:local_manifest = findfile(s:cargo_manifest_name, '.;')
|
||||
if s:local_manifest != ''
|
||||
let s:local_manifest = fnamemodify(s:local_manifest, ':p:h').'/'
|
||||
augroup cargo
|
||||
au!
|
||||
au QuickfixCmdPost make call s:FixPaths()
|
||||
augroup END
|
||||
|
||||
" FixPaths() is run after Cargo, and is used to change the file paths
|
||||
" to be relative to the current directory instead of Cargo.toml.
|
||||
function! s:FixPaths()
|
||||
let qflist = getqflist()
|
||||
let manifest = s:local_manifest
|
||||
for qf in qflist
|
||||
if !qf.valid
|
||||
let m = matchlist(qf.text, '(file://\(.*\))$')
|
||||
if !empty(m)
|
||||
let manifest = m[1].'/'
|
||||
" Manually strip another slash if needed; usually just an
|
||||
" issue on Windows.
|
||||
if manifest =~ '^/[A-Z]\+:/'
|
||||
let manifest = manifest[1:]
|
||||
endif
|
||||
endif
|
||||
continue
|
||||
endif
|
||||
let filename = bufname(qf.bufnr)
|
||||
if s:is_absolute(filename)
|
||||
continue
|
||||
endif
|
||||
let qf.filename = simplify(manifest.filename)
|
||||
call remove(qf, 'bufnr')
|
||||
endfor
|
||||
call setqflist(qflist, 'r')
|
||||
endfunction
|
||||
endif
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
" Vim compiler file
|
||||
" Compiler: Rust Compiler
|
||||
" Maintainer: Chris Morgan <me@chrismorgan.info>
|
||||
" Latest Revision: 2013 Jul 12
|
||||
|
||||
if exists("current_compiler")
|
||||
finish
|
||||
endif
|
||||
let current_compiler = "rustc"
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
if exists(":CompilerSet") != 2
|
||||
command -nargs=* CompilerSet setlocal <args>
|
||||
endif
|
||||
|
||||
if exists("g:rustc_makeprg_no_percent") && g:rustc_makeprg_no_percent == 1
|
||||
CompilerSet makeprg=rustc
|
||||
else
|
||||
CompilerSet makeprg=rustc\ \%
|
||||
endif
|
||||
|
||||
CompilerSet errorformat=
|
||||
\%f:%l:%c:\ %t%*[^:]:\ %m,
|
||||
\%f:%l:%c:\ %*\\d:%*\\d\ %t%*[^:]:\ %m,
|
||||
\%-G%f:%l\ %s,
|
||||
\%-G%*[\ ]^,
|
||||
\%-G%*[\ ]^%*[~],
|
||||
\%-G%*[\ ]...
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
|
@ -1,178 +0,0 @@
|
|||
*rust.txt* Filetype plugin for Rust
|
||||
|
||||
==============================================================================
|
||||
CONTENTS *rust* *ft-rust*
|
||||
|
||||
1. Introduction |rust-intro|
|
||||
2. Settings |rust-settings|
|
||||
3. Commands |rust-commands|
|
||||
4. Mappings |rust-mappings|
|
||||
|
||||
==============================================================================
|
||||
INTRODUCTION *rust-intro*
|
||||
|
||||
This plugin provides syntax and supporting functionality for the Rust
|
||||
filetype.
|
||||
|
||||
==============================================================================
|
||||
SETTINGS *rust-settings*
|
||||
|
||||
This plugin has a few variables you can define in your vimrc that change the
|
||||
behavior of the plugin.
|
||||
|
||||
*g:rustc_path*
|
||||
g:rustc_path~
|
||||
Set this option to the path to rustc for use in the |:RustRun| and
|
||||
|:RustExpand| commands. If unset, "rustc" will be located in $PATH: >
|
||||
let g:rustc_path = $HOME."/bin/rustc"
|
||||
<
|
||||
|
||||
*g:rustc_makeprg_no_percent*
|
||||
g:rustc_makeprg_no_percent~
|
||||
Set this option to 1 to have 'makeprg' default to "rustc" instead of
|
||||
"rustc %": >
|
||||
let g:rustc_makeprg_no_percent = 1
|
||||
<
|
||||
|
||||
*g:rust_conceal*
|
||||
g:rust_conceal~
|
||||
Set this option to turn on the basic |conceal| support: >
|
||||
let g:rust_conceal = 1
|
||||
<
|
||||
|
||||
*g:rust_conceal_mod_path*
|
||||
g:rust_conceal_mod_path~
|
||||
Set this option to turn on |conceal| for the path connecting token
|
||||
"::": >
|
||||
let g:rust_conceal_mod_path = 1
|
||||
<
|
||||
|
||||
*g:rust_conceal_pub*
|
||||
g:rust_conceal_pub~
|
||||
Set this option to turn on |conceal| for the "pub" token: >
|
||||
let g:rust_conceal_pub = 1
|
||||
<
|
||||
|
||||
*g:rust_recommended_style*
|
||||
g:rust_recommended_style~
|
||||
Set this option to enable vim indentation and textwidth settings to
|
||||
conform to style conventions of the rust standard library (i.e. use 4
|
||||
spaces for indents and sets 'textwidth' to 99). This option is enabled
|
||||
by default. To disable it: >
|
||||
let g:rust_recommended_style = 0
|
||||
<
|
||||
|
||||
*g:rust_fold*
|
||||
g:rust_fold~
|
||||
Set this option to turn on |folding|: >
|
||||
let g:rust_fold = 1
|
||||
<
|
||||
Value Effect ~
|
||||
0 No folding
|
||||
1 Braced blocks are folded. All folds are open by
|
||||
default.
|
||||
2 Braced blocks are folded. 'foldlevel' is left at the
|
||||
global value (all folds are closed by default).
|
||||
|
||||
*g:rust_bang_comment_leader*
|
||||
g:rust_bang_comment_leader~
|
||||
Set this option to 1 to preserve the leader on multi-line doc comments
|
||||
using the /*! syntax: >
|
||||
let g:rust_bang_comment_leader = 1
|
||||
<
|
||||
|
||||
*g:ftplugin_rust_source_path*
|
||||
g:ftplugin_rust_source_path~
|
||||
Set this option to a path that should be prepended to 'path' for Rust
|
||||
source files: >
|
||||
let g:ftplugin_rust_source_path = $HOME.'/dev/rust'
|
||||
<
|
||||
|
||||
*g:cargo_manifest_name*
|
||||
g:cargo_manifest_name~
|
||||
Set this option to the name of the manifest file for your projects. If
|
||||
not specified it defaults to 'Cargo.toml' : >
|
||||
let g:cargo_manifest_name = 'Cargo.toml'
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
COMMANDS *rust-commands*
|
||||
|
||||
:RustRun [args] *:RustRun*
|
||||
:RustRun! [rustc-args] [--] [args]
|
||||
Compiles and runs the current file. If it has unsaved changes,
|
||||
it will be saved first using |:update|. If the current file is
|
||||
an unnamed buffer, it will be written to a temporary file
|
||||
first. The compiled binary is always placed in a temporary
|
||||
directory, but is run from the current directory.
|
||||
|
||||
The arguments given to |:RustRun| will be passed to the
|
||||
compiled binary.
|
||||
|
||||
If ! is specified, the arguments are passed to rustc instead.
|
||||
A "--" argument will separate the rustc arguments from the
|
||||
arguments passed to the binary.
|
||||
|
||||
If |g:rustc_path| is defined, it is used as the path to rustc.
|
||||
Otherwise it is assumed rustc can be found in $PATH.
|
||||
|
||||
:RustExpand [args] *:RustExpand*
|
||||
:RustExpand! [TYPE] [args]
|
||||
Expands the current file using --pretty and displays the
|
||||
results in a new split. If the current file has unsaved
|
||||
changes, it will be saved first using |:update|. If the
|
||||
current file is an unnamed buffer, it will be written to a
|
||||
temporary file first.
|
||||
|
||||
The arguments given to |:RustExpand| will be passed to rustc.
|
||||
This is largely intended for specifying various --cfg
|
||||
configurations.
|
||||
|
||||
If ! is specified, the first argument is the expansion type to
|
||||
pass to rustc --pretty. Otherwise it will default to
|
||||
"expanded".
|
||||
|
||||
If |g:rustc_path| is defined, it is used as the path to rustc.
|
||||
Otherwise it is assumed rustc can be found in $PATH.
|
||||
|
||||
:RustEmitIr [args] *:RustEmitIr*
|
||||
Compiles the current file to LLVM IR and displays the results
|
||||
in a new split. If the current file has unsaved changes, it
|
||||
will be saved first using |:update|. If the current file is an
|
||||
unnamed buffer, it will be written to a temporary file first.
|
||||
|
||||
The arguments given to |:RustEmitIr| will be passed to rustc.
|
||||
|
||||
If |g:rustc_path| is defined, it is used as the path to rustc.
|
||||
Otherwise it is assumed rustc can be found in $PATH.
|
||||
|
||||
:RustEmitAsm [args] *:RustEmitAsm*
|
||||
Compiles the current file to assembly and displays the results
|
||||
in a new split. If the current file has unsaved changes, it
|
||||
will be saved first using |:update|. If the current file is an
|
||||
unnamed buffer, it will be written to a temporary file first.
|
||||
|
||||
The arguments given to |:RustEmitAsm| will be passed to rustc.
|
||||
|
||||
If |g:rustc_path| is defined, it is used as the path to rustc.
|
||||
Otherwise it is assumed rustc can be found in $PATH.
|
||||
|
||||
==============================================================================
|
||||
MAPPINGS *rust-mappings*
|
||||
|
||||
This plugin defines mappings for |[[| and |]]| to support hanging indents.
|
||||
|
||||
It also has a few other mappings:
|
||||
|
||||
*rust_<D-r>*
|
||||
<D-r> Executes |:RustRun| with no arguments.
|
||||
Note: This binding is only available in MacVim.
|
||||
|
||||
*rust_<D-R>*
|
||||
<D-R> Populates the command line with |:RustRun|! using the
|
||||
arguments given to the last invocation, but does not
|
||||
execute it.
|
||||
Note: This binding is only available in MacVim.
|
||||
|
||||
==============================================================================
|
||||
vim:tw=78:sw=4:noet:ts=8:ft=help:norl:
|
||||
|
|
@ -1 +0,0 @@
|
|||
au BufRead,BufNewFile *.rs set filetype=rust
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
" Language: Rust
|
||||
" Description: Vim syntax file for Rust
|
||||
" Maintainer: Chris Morgan <me@chrismorgan.info>
|
||||
" Maintainer: Kevin Ballard <kevin@sb.org>
|
||||
" Last Change: Jul 07, 2014
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" Variables {{{1
|
||||
|
||||
" The rust source code at present seems to typically omit a leader on /*!
|
||||
" comments, so we'll use that as our default, but make it easy to switch.
|
||||
" This does not affect indentation at all (I tested it with and without
|
||||
" leader), merely whether a leader is inserted by default or not.
|
||||
if exists("g:rust_bang_comment_leader") && g:rust_bang_comment_leader == 1
|
||||
" Why is the `,s0:/*,mb:\ ,ex:*/` there, you ask? I don't understand why,
|
||||
" but without it, */ gets indented one space even if there were no
|
||||
" leaders. I'm fairly sure that's a Vim bug.
|
||||
setlocal comments=s1:/*,mb:*,ex:*/,s0:/*,mb:\ ,ex:*/,:///,://!,://
|
||||
else
|
||||
setlocal comments=s0:/*!,m:\ ,ex:*/,s1:/*,mb:*,ex:*/,:///,://!,://
|
||||
endif
|
||||
setlocal commentstring=//%s
|
||||
setlocal formatoptions-=t formatoptions+=croqnl
|
||||
" j was only added in 7.3.541, so stop complaints about its nonexistence
|
||||
silent! setlocal formatoptions+=j
|
||||
|
||||
" smartindent will be overridden by indentexpr if filetype indent is on, but
|
||||
" otherwise it's better than nothing.
|
||||
setlocal smartindent nocindent
|
||||
|
||||
if !exists("g:rust_recommended_style") || g:rust_recommended_style == 1
|
||||
setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab
|
||||
setlocal textwidth=99
|
||||
endif
|
||||
|
||||
" This includeexpr isn't perfect, but it's a good start
|
||||
setlocal includeexpr=substitute(v:fname,'::','/','g')
|
||||
|
||||
" NOT adding .rc as it's being phased out (0.7)
|
||||
setlocal suffixesadd=.rs
|
||||
|
||||
if exists("g:ftplugin_rust_source_path")
|
||||
let &l:path=g:ftplugin_rust_source_path . ',' . &l:path
|
||||
endif
|
||||
|
||||
if exists("g:loaded_delimitMate")
|
||||
if exists("b:delimitMate_excluded_regions")
|
||||
let b:rust_original_delimitMate_excluded_regions = b:delimitMate_excluded_regions
|
||||
endif
|
||||
let b:delimitMate_excluded_regions = delimitMate#Get("excluded_regions") . ',rustLifetimeCandidate,rustGenericLifetimeCandidate'
|
||||
endif
|
||||
|
||||
if has("folding") && exists('g:rust_fold') && g:rust_fold != 0
|
||||
let b:rust_set_foldmethod=1
|
||||
setlocal foldmethod=syntax
|
||||
if g:rust_fold == 2
|
||||
setlocal foldlevel<
|
||||
else
|
||||
setlocal foldlevel=99
|
||||
endif
|
||||
endif
|
||||
|
||||
if has('conceal') && exists('g:rust_conceal')
|
||||
let b:rust_set_conceallevel=1
|
||||
setlocal conceallevel=2
|
||||
endif
|
||||
|
||||
" Motion Commands {{{1
|
||||
|
||||
" Bind motion commands to support hanging indents
|
||||
nnoremap <silent> <buffer> [[ :call rust#Jump('n', 'Back')<CR>
|
||||
nnoremap <silent> <buffer> ]] :call rust#Jump('n', 'Forward')<CR>
|
||||
xnoremap <silent> <buffer> [[ :call rust#Jump('v', 'Back')<CR>
|
||||
xnoremap <silent> <buffer> ]] :call rust#Jump('v', 'Forward')<CR>
|
||||
onoremap <silent> <buffer> [[ :call rust#Jump('o', 'Back')<CR>
|
||||
onoremap <silent> <buffer> ]] :call rust#Jump('o', 'Forward')<CR>
|
||||
|
||||
" Commands {{{1
|
||||
|
||||
" See |:RustRun| for docs
|
||||
command! -nargs=* -complete=file -bang -bar -buffer RustRun call rust#Run(<bang>0, [<f-args>])
|
||||
|
||||
" See |:RustExpand| for docs
|
||||
command! -nargs=* -complete=customlist,rust#CompleteExpand -bang -bar -buffer RustExpand call rust#Expand(<bang>0, [<f-args>])
|
||||
|
||||
" See |:RustEmitIr| for docs
|
||||
command! -nargs=* -bar -buffer RustEmitIr call rust#Emit("ir", [<f-args>])
|
||||
|
||||
" See |:RustEmitAsm| for docs
|
||||
command! -nargs=* -bar -buffer RustEmitAsm call rust#Emit("asm", [<f-args>])
|
||||
|
||||
" Mappings {{{1
|
||||
|
||||
" Bind ⌘R in MacVim to :RustRun
|
||||
nnoremap <silent> <buffer> <D-r> :RustRun<CR>
|
||||
" Bind ⌘⇧R in MacVim to :RustRun! pre-filled with the last args
|
||||
nnoremap <buffer> <D-R> :RustRun! <C-r>=join(b:rust_last_rustc_args)<CR><C-\>erust#AppendCmdLine(' -- ' . join(b:rust_last_args))<CR>
|
||||
|
||||
if !exists("b:rust_last_rustc_args") || !exists("b:rust_last_args")
|
||||
let b:rust_last_rustc_args = []
|
||||
let b:rust_last_args = []
|
||||
endif
|
||||
|
||||
" Cleanup {{{1
|
||||
|
||||
let b:undo_ftplugin = "
|
||||
\ setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd<
|
||||
\|setlocal tabstop< shiftwidth< softtabstop< expandtab< textwidth<
|
||||
\|if exists('b:rust_original_delimitMate_excluded_regions')
|
||||
\|let b:delimitMate_excluded_regions = b:rust_original_delimitMate_excluded_regions
|
||||
\|unlet b:rust_original_delimitMate_excluded_regions
|
||||
\|else
|
||||
\|unlet! b:delimitMate_excluded_regions
|
||||
\|endif
|
||||
\|if exists('b:rust_set_foldmethod')
|
||||
\|setlocal foldmethod< foldlevel<
|
||||
\|unlet b:rust_set_foldmethod
|
||||
\|endif
|
||||
\|if exists('b:rust_set_conceallevel')
|
||||
\|setlocal conceallevel<
|
||||
\|unlet b:rust_set_conceallevel
|
||||
\|endif
|
||||
\|unlet! b:rust_last_rustc_args b:rust_last_args
|
||||
\|delcommand RustRun
|
||||
\|delcommand RustExpand
|
||||
\|delcommand RustEmitIr
|
||||
\|delcommand RustEmitAsm
|
||||
\|nunmap <buffer> <D-r>
|
||||
\|nunmap <buffer> <D-R>
|
||||
\|nunmap <buffer> [[
|
||||
\|nunmap <buffer> ]]
|
||||
\|xunmap <buffer> [[
|
||||
\|xunmap <buffer> ]]
|
||||
\|ounmap <buffer> [[
|
||||
\|ounmap <buffer> ]]
|
||||
\"
|
||||
|
||||
" }}}1
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim: set noet sw=4 ts=4:
|
||||
|
|
@ -1,196 +0,0 @@
|
|||
" Vim indent file
|
||||
" Language: Rust
|
||||
" Author: Chris Morgan <me@chrismorgan.info>
|
||||
" Last Change: 2014 Sep 13
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal cindent
|
||||
setlocal cinoptions=L0,(0,Ws,J1,j1
|
||||
setlocal cinkeys=0{,0},!^F,o,O,0[,0]
|
||||
" Don't think cinwords will actually do anything at all... never mind
|
||||
setlocal cinwords=for,if,else,while,loop,impl,mod,unsafe,trait,struct,enum,fn,extern
|
||||
|
||||
" Some preliminary settings
|
||||
setlocal nolisp " Make sure lisp indenting doesn't supersede us
|
||||
setlocal autoindent " indentexpr isn't much help otherwise
|
||||
" Also do indentkeys, otherwise # gets shoved to column 0 :-/
|
||||
setlocal indentkeys=0{,0},!^F,o,O,0[,0]
|
||||
|
||||
setlocal indentexpr=GetRustIndent(v:lnum)
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetRustIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
" Come here when loading the script the first time.
|
||||
|
||||
function! s:get_line_trimmed(lnum)
|
||||
" Get the line and remove a trailing comment.
|
||||
" Use syntax highlighting attributes when possible.
|
||||
" NOTE: this is not accurate; /* */ or a line continuation could trick it
|
||||
let line = getline(a:lnum)
|
||||
let line_len = strlen(line)
|
||||
if has('syntax_items')
|
||||
" If the last character in the line is a comment, do a binary search for
|
||||
" the start of the comment. synID() is slow, a linear search would take
|
||||
" too long on a long line.
|
||||
if synIDattr(synID(a:lnum, line_len, 1), "name") =~ 'Comment\|Todo'
|
||||
let min = 1
|
||||
let max = line_len
|
||||
while min < max
|
||||
let col = (min + max) / 2
|
||||
if synIDattr(synID(a:lnum, col, 1), "name") =~ 'Comment\|Todo'
|
||||
let max = col
|
||||
else
|
||||
let min = col + 1
|
||||
endif
|
||||
endwhile
|
||||
let line = strpart(line, 0, min - 1)
|
||||
endif
|
||||
return substitute(line, "\s*$", "", "")
|
||||
else
|
||||
" Sorry, this is not complete, nor fully correct (e.g. string "//").
|
||||
" Such is life.
|
||||
return substitute(line, "\s*//.*$", "", "")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:is_string_comment(lnum, col)
|
||||
if has('syntax_items')
|
||||
for id in synstack(a:lnum, a:col)
|
||||
let synname = synIDattr(id, "name")
|
||||
if synname == "rustString" || synname =~ "^rustComment"
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
" without syntax, let's not even try
|
||||
return 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function GetRustIndent(lnum)
|
||||
|
||||
" Starting assumption: cindent (called at the end) will do it right
|
||||
" normally. We just want to fix up a few cases.
|
||||
|
||||
let line = getline(a:lnum)
|
||||
|
||||
if has('syntax_items')
|
||||
let synname = synIDattr(synID(a:lnum, 1, 1), "name")
|
||||
if synname == "rustString"
|
||||
" If the start of the line is in a string, don't change the indent
|
||||
return -1
|
||||
elseif synname =~ '\(Comment\|Todo\)'
|
||||
\ && line !~ '^\s*/\*' " not /* opening line
|
||||
if synname =~ "CommentML" " multi-line
|
||||
if line !~ '^\s*\*' && getline(a:lnum - 1) =~ '^\s*/\*'
|
||||
" This is (hopefully) the line after a /*, and it has no
|
||||
" leader, so the correct indentation is that of the
|
||||
" previous line.
|
||||
return GetRustIndent(a:lnum - 1)
|
||||
endif
|
||||
endif
|
||||
" If it's in a comment, let cindent take care of it now. This is
|
||||
" for cases like "/*" where the next line should start " * ", not
|
||||
" "* " as the code below would otherwise cause for module scope
|
||||
" Fun fact: " /*\n*\n*/" takes two calls to get right!
|
||||
return cindent(a:lnum)
|
||||
endif
|
||||
endif
|
||||
|
||||
" cindent gets second and subsequent match patterns/struct members wrong,
|
||||
" as it treats the comma as indicating an unfinished statement::
|
||||
"
|
||||
" match a {
|
||||
" b => c,
|
||||
" d => e,
|
||||
" f => g,
|
||||
" };
|
||||
|
||||
" Search backwards for the previous non-empty line.
|
||||
let prevlinenum = prevnonblank(a:lnum - 1)
|
||||
let prevline = s:get_line_trimmed(prevlinenum)
|
||||
while prevlinenum > 1 && prevline !~ '[^[:blank:]]'
|
||||
let prevlinenum = prevnonblank(prevlinenum - 1)
|
||||
let prevline = s:get_line_trimmed(prevlinenum)
|
||||
endwhile
|
||||
if prevline[len(prevline) - 1] == ","
|
||||
\ && s:get_line_trimmed(a:lnum) !~ '^\s*[\[\]{}]'
|
||||
\ && prevline !~ '^\s*fn\s'
|
||||
\ && prevline !~ '([^()]\+,$'
|
||||
" Oh ho! The previous line ended in a comma! I bet cindent will try to
|
||||
" take this too far... For now, let's normally use the previous line's
|
||||
" indent.
|
||||
|
||||
" One case where this doesn't work out is where *this* line contains
|
||||
" square or curly brackets; then we normally *do* want to be indenting
|
||||
" further.
|
||||
"
|
||||
" Another case where we don't want to is one like a function
|
||||
" definition with arguments spread over multiple lines:
|
||||
"
|
||||
" fn foo(baz: Baz,
|
||||
" baz: Baz) // <-- cindent gets this right by itself
|
||||
"
|
||||
" Another case is similar to the previous, except calling a function
|
||||
" instead of defining it, or any conditional expression that leaves
|
||||
" an open paren:
|
||||
"
|
||||
" foo(baz,
|
||||
" baz);
|
||||
"
|
||||
" if baz && (foo ||
|
||||
" bar) {
|
||||
"
|
||||
" There are probably other cases where we don't want to do this as
|
||||
" well. Add them as needed.
|
||||
return indent(prevlinenum)
|
||||
endif
|
||||
|
||||
if !has("patch-7.4.355")
|
||||
" cindent before 7.4.355 doesn't do the module scope well at all; e.g.::
|
||||
"
|
||||
" static FOO : &'static [bool] = [
|
||||
" true,
|
||||
" false,
|
||||
" false,
|
||||
" true,
|
||||
" ];
|
||||
"
|
||||
" uh oh, next statement is indented further!
|
||||
|
||||
" Note that this does *not* apply the line continuation pattern properly;
|
||||
" that's too hard to do correctly for my liking at present, so I'll just
|
||||
" start with these two main cases (square brackets and not returning to
|
||||
" column zero)
|
||||
|
||||
call cursor(a:lnum, 1)
|
||||
if searchpair('{\|(', '', '}\|)', 'nbW',
|
||||
\ 's:is_string_comment(line("."), col("."))') == 0
|
||||
if searchpair('\[', '', '\]', 'nbW',
|
||||
\ 's:is_string_comment(line("."), col("."))') == 0
|
||||
" Global scope, should be zero
|
||||
return 0
|
||||
else
|
||||
" At the module scope, inside square brackets only
|
||||
"if getline(a:lnum)[0] == ']' || search('\[', '', '\]', 'nW') == a:lnum
|
||||
if line =~ "^\\s*]"
|
||||
" It's the closing line, dedent it
|
||||
return 0
|
||||
else
|
||||
return &shiftwidth
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
" Fall back on cindent, which does it mostly right
|
||||
return cindent(a:lnum)
|
||||
endfunction
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
" Vim syntastic plugin helper
|
||||
" Language: Rust
|
||||
" Maintainer: Andrew Gallant <jamslam@gmail.com>
|
||||
|
||||
if exists("g:loaded_syntastic_rust_filetype")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_syntastic_rust_filetype = 1
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" This is to let Syntastic know about the Rust filetype.
|
||||
" It enables tab completion for the 'SyntasticInfo' command.
|
||||
" (This does not actually register the syntax checker.)
|
||||
if exists('g:syntastic_extra_filetypes')
|
||||
call add(g:syntastic_extra_filetypes, 'rust')
|
||||
else
|
||||
let g:syntastic_extra_filetypes = ['rust']
|
||||
endif
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
|
@ -1,262 +0,0 @@
|
|||
" Vim syntax file
|
||||
" Language: Rust
|
||||
" Maintainer: Patrick Walton <pcwalton@mozilla.com>
|
||||
" Maintainer: Ben Blum <bblum@cs.cmu.edu>
|
||||
" Maintainer: Chris Morgan <me@chrismorgan.info>
|
||||
" Last Change: January 5, 2015
|
||||
|
||||
if version < 600
|
||||
syntax clear
|
||||
elseif exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
" Syntax definitions {{{1
|
||||
" Basic keywords {{{2
|
||||
syn keyword rustConditional match if else
|
||||
syn keyword rustOperator as
|
||||
|
||||
syn match rustAssert "\<assert\(\w\)*!" contained
|
||||
syn match rustPanic "\<panic\(\w\)*!" contained
|
||||
syn keyword rustKeyword break
|
||||
syn keyword rustKeyword box nextgroup=rustBoxPlacement skipwhite skipempty
|
||||
syn keyword rustKeyword continue
|
||||
syn keyword rustKeyword extern nextgroup=rustExternCrate,rustObsoleteExternMod skipwhite skipempty
|
||||
syn keyword rustKeyword fn nextgroup=rustFuncName skipwhite skipempty
|
||||
syn keyword rustKeyword for in if impl let
|
||||
syn keyword rustKeyword loop once pub
|
||||
syn keyword rustKeyword return super
|
||||
syn keyword rustKeyword unsafe virtual where while
|
||||
syn keyword rustKeyword use nextgroup=rustModPath skipwhite skipempty
|
||||
" FIXME: Scoped impl's name is also fallen in this category
|
||||
syn keyword rustKeyword mod trait struct enum type nextgroup=rustIdentifier skipwhite skipempty
|
||||
syn keyword rustStorage move mut ref static const
|
||||
|
||||
syn keyword rustInvalidBareKeyword crate
|
||||
|
||||
syn keyword rustExternCrate crate contained nextgroup=rustIdentifier,rustExternCrateString skipwhite skipempty
|
||||
" This is to get the `bar` part of `extern crate "foo" as bar;` highlighting.
|
||||
syn match rustExternCrateString /".*"\_s*as/ contained nextgroup=rustIdentifier skipwhite transparent skipempty contains=rustString,rustOperator
|
||||
syn keyword rustObsoleteExternMod mod contained nextgroup=rustIdentifier skipwhite skipempty
|
||||
|
||||
syn match rustIdentifier contains=rustIdentifierPrime "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
|
||||
syn match rustFuncName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
|
||||
|
||||
syn region rustBoxPlacement matchgroup=rustBoxPlacementParens start="(" end=")" contains=TOP contained
|
||||
syn keyword rustBoxPlacementExpr GC containedin=rustBoxPlacement
|
||||
" Ideally we'd have syntax rules set up to match arbitrary expressions. Since
|
||||
" we don't, we'll just define temporary contained rules to handle balancing
|
||||
" delimiters.
|
||||
syn region rustBoxPlacementBalance start="(" end=")" containedin=rustBoxPlacement transparent
|
||||
syn region rustBoxPlacementBalance start="\[" end="\]" containedin=rustBoxPlacement transparent
|
||||
" {} are handled by rustFoldBraces
|
||||
|
||||
syn region rustMacroRepeat matchgroup=rustMacroRepeatDelimiters start="$(" end=")" contains=TOP nextgroup=rustMacroRepeatCount
|
||||
syn match rustMacroRepeatCount ".\?[*+]" contained
|
||||
syn match rustMacroVariable "$\w\+"
|
||||
|
||||
" Reserved (but not yet used) keywords {{{2
|
||||
syn keyword rustReservedKeyword alignof be do offsetof priv pure sizeof typeof unsized yield abstract final override macro
|
||||
|
||||
" Built-in types {{{2
|
||||
syn keyword rustType isize usize float char bool u8 u16 u32 u64 f32
|
||||
syn keyword rustType f64 i8 i16 i32 i64 str Self
|
||||
|
||||
" Things from the prelude (src/libstd/prelude.rs) {{{2
|
||||
" This section is just straight transformation of the contents of the prelude,
|
||||
" to make it easy to update.
|
||||
|
||||
" Reexported core operators {{{3
|
||||
syn keyword rustTrait Copy Send Sized Sync
|
||||
syn keyword rustTrait Drop Fn FnMut FnOnce
|
||||
|
||||
" Reexported functions {{{3
|
||||
syn keyword rustFunction drop
|
||||
|
||||
" Reexported types and traits {{{3
|
||||
syn keyword rustTrait Box
|
||||
syn keyword rustTrait CharExt
|
||||
syn keyword rustTrait Clone
|
||||
syn keyword rustTrait PartialEq PartialOrd Eq Ord
|
||||
syn keyword rustTrait DoubleEndedIterator
|
||||
syn keyword rustTrait ExactSizeIterator
|
||||
syn keyword rustTrait Iterator IteratorExt Extend
|
||||
syn keyword rustEnum Option
|
||||
syn keyword rustEnumVariant Some None
|
||||
syn keyword rustTrait PtrExt MutPtrExt
|
||||
syn keyword rustEnum Result
|
||||
syn keyword rustEnumVariant Ok Err
|
||||
syn keyword rustTrait AsSlice
|
||||
syn keyword rustTrait SliceExt SliceConcatExt
|
||||
syn keyword rustTrait Str StrExt
|
||||
syn keyword rustTrait String ToString
|
||||
syn keyword rustTrait Vec
|
||||
" FIXME: remove when path reform lands
|
||||
syn keyword rustTrait Path GenericPath
|
||||
" FIXME: remove when I/O reform lands
|
||||
syn keyword rustTrait Buffer Writer Reader Seek BufferPrelude
|
||||
|
||||
" Other syntax {{{2
|
||||
syn keyword rustSelf self
|
||||
syn keyword rustBoolean true false
|
||||
|
||||
" If foo::bar changes to foo.bar, change this ("::" to "\.").
|
||||
" If foo::bar changes to Foo::bar, change this (first "\w" to "\u").
|
||||
syn match rustModPath "\w\(\w\)*::[^<]"he=e-3,me=e-3
|
||||
syn match rustModPathSep "::"
|
||||
|
||||
syn match rustFuncCall "\w\(\w\)*("he=e-1,me=e-1
|
||||
syn match rustFuncCall "\w\(\w\)*::<"he=e-3,me=e-3 " foo::<T>();
|
||||
|
||||
" This is merely a convention; note also the use of [A-Z], restricting it to
|
||||
" latin identifiers rather than the full Unicode uppercase. I have not used
|
||||
" [:upper:] as it depends upon 'noignorecase'
|
||||
"syn match rustCapsIdent display "[A-Z]\w\(\w\)*"
|
||||
|
||||
syn match rustOperator display "\%(+\|-\|/\|*\|=\|\^\|&\||\|!\|>\|<\|%\)=\?"
|
||||
" This one isn't *quite* right, as we could have binary-& with a reference
|
||||
syn match rustSigil display /&\s\+[&~@*][^)= \t\r\n]/he=e-1,me=e-1
|
||||
syn match rustSigil display /[&~@*][^)= \t\r\n]/he=e-1,me=e-1
|
||||
" This isn't actually correct; a closure with no arguments can be `|| { }`.
|
||||
" Last, because the & in && isn't a sigil
|
||||
syn match rustOperator display "&&\|||"
|
||||
|
||||
syn match rustMacro '\w\(\w\)*!' contains=rustAssert,rustPanic
|
||||
syn match rustMacro '#\w\(\w\)*' contains=rustAssert,rustPanic
|
||||
|
||||
syn match rustEscapeError display contained /\\./
|
||||
syn match rustEscape display contained /\\\([nrt0\\'"]\|x\x\{2}\)/
|
||||
syn match rustEscapeUnicode display contained /\\\(u\x\{4}\|U\x\{8}\)/
|
||||
syn match rustEscapeUnicode display contained /\\u{\x\{1,6}}/
|
||||
syn match rustStringContinuation display contained /\\\n\s*/
|
||||
syn region rustString start=+b"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeError,rustStringContinuation
|
||||
syn region rustString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustStringContinuation,@Spell
|
||||
syn region rustString start='b\?r\z(#*\)"' end='"\z1' contains=@Spell
|
||||
|
||||
syn region rustAttribute start="#!\?\[" end="\]" contains=rustString,rustDerive
|
||||
syn region rustDerive start="derive(" end=")" contained contains=rustTrait
|
||||
|
||||
" Number literals
|
||||
syn match rustDecNumber display "\<[0-9][0-9_]*\%([iu]\%(s\|8\|16\|32\|64\)\)\="
|
||||
syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\%([iu]\%(s\|8\|16\|32\|64\)\)\="
|
||||
syn match rustOctNumber display "\<0o[0-7_]\+\%([iu]\%(s\|8\|16\|32\|64\)\)\="
|
||||
syn match rustBinNumber display "\<0b[01_]\+\%([iu]\%(s\|8\|16\|32\|64\)\)\="
|
||||
|
||||
" Special case for numbers of the form "1." which are float literals, unless followed by
|
||||
" an identifier, which makes them integer literals with a method call or field access,
|
||||
" or by another ".", which makes them integer literals followed by the ".." token.
|
||||
" (This must go first so the others take precedence.)
|
||||
syn match rustFloat display "\<[0-9][0-9_]*\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\|\.\)\@!"
|
||||
" To mark a number as a normal float, it must have at least one of the three things integral values don't have:
|
||||
" a decimal point and more numbers; an exponent; and a type suffix.
|
||||
syn match rustFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\%([eE][+-]\=[0-9_]\+\)\=\(f32\|f64\)\="
|
||||
syn match rustFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\=\%([eE][+-]\=[0-9_]\+\)\(f32\|f64\)\="
|
||||
syn match rustFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\=\%([eE][+-]\=[0-9_]\+\)\=\(f32\|f64\)"
|
||||
|
||||
" For the benefit of delimitMate
|
||||
syn region rustLifetimeCandidate display start=/&'\%(\([^'\\]\|\\\(['nrt0\\\"]\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'\)\@!/ end=/[[:cntrl:][:space:][:punct:]]\@=\|$/ contains=rustSigil,rustLifetime
|
||||
syn region rustGenericRegion display start=/<\%('\|[^[cntrl:][:space:][:punct:]]\)\@=')\S\@=/ end=/>/ contains=rustGenericLifetimeCandidate
|
||||
syn region rustGenericLifetimeCandidate display start=/\%(<\|,\s*\)\@<='/ end=/[[:cntrl:][:space:][:punct:]]\@=\|$/ contains=rustSigil,rustLifetime
|
||||
|
||||
"rustLifetime must appear before rustCharacter, or chars will get the lifetime highlighting
|
||||
syn match rustLifetime display "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*"
|
||||
syn match rustCharacterInvalid display contained /b\?'\zs[\n\r\t']\ze'/
|
||||
" The groups negated here add up to 0-255 but nothing else (they do not seem to go beyond ASCII).
|
||||
syn match rustCharacterInvalidUnicode display contained /b'\zs[^[:cntrl:][:graph:][:alnum:][:space:]]\ze'/
|
||||
syn match rustCharacter /b'\([^\\]\|\\\(.\|x\x\{2}\)\)'/ contains=rustEscape,rustEscapeError,rustCharacterInvalid,rustCharacterInvalidUnicode
|
||||
syn match rustCharacter /'\([^\\]\|\\\(.\|x\x\{2}\|u\x\{4}\|U\x\{8}\|u{\x\{1,6}}\)\)'/ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustCharacterInvalid
|
||||
|
||||
syn region rustCommentLine start="//" end="$" contains=rustTodo,@Spell
|
||||
syn region rustCommentLineDoc start="//\%(//\@!\|!\)" end="$" contains=rustTodo,@Spell
|
||||
syn region rustCommentBlock matchgroup=rustCommentBlock start="/\*\%(!\|\*[*/]\@!\)\@!" end="\*/" contains=rustTodo,rustCommentBlockNest,@Spell
|
||||
syn region rustCommentBlockDoc matchgroup=rustCommentBlockDoc start="/\*\%(!\|\*[*/]\@!\)" end="\*/" contains=rustTodo,rustCommentBlockDocNest,@Spell
|
||||
syn region rustCommentBlockNest matchgroup=rustCommentBlock start="/\*" end="\*/" contains=rustTodo,rustCommentBlockNest,@Spell contained transparent
|
||||
syn region rustCommentBlockDocNest matchgroup=rustCommentBlockDoc start="/\*" end="\*/" contains=rustTodo,rustCommentBlockDocNest,@Spell contained transparent
|
||||
" FIXME: this is a really ugly and not fully correct implementation. Most
|
||||
" importantly, a case like ``/* */*`` should have the final ``*`` not being in
|
||||
" a comment, but in practice at present it leaves comments open two levels
|
||||
" deep. But as long as you stay away from that particular case, I *believe*
|
||||
" the highlighting is correct. Due to the way Vim's syntax engine works
|
||||
" (greedy for start matches, unlike Rust's tokeniser which is searching for
|
||||
" the earliest-starting match, start or end), I believe this cannot be solved.
|
||||
" Oh you who would fix it, don't bother with things like duplicating the Block
|
||||
" rules and putting ``\*\@<!`` at the start of them; it makes it worse, as
|
||||
" then you must deal with cases like ``/*/**/*/``. And don't try making it
|
||||
" worse with ``\%(/\@<!\*\)\@<!``, either...
|
||||
|
||||
syn keyword rustTodo contained TODO FIXME XXX NB NOTE
|
||||
|
||||
" Folding rules {{{2
|
||||
" Trivial folding rules to begin with.
|
||||
" FIXME: use the AST to make really good folding
|
||||
syn region rustFoldBraces start="{" end="}" transparent fold
|
||||
|
||||
" Default highlighting {{{1
|
||||
hi def link rustDecNumber rustNumber
|
||||
hi def link rustHexNumber rustNumber
|
||||
hi def link rustOctNumber rustNumber
|
||||
hi def link rustBinNumber rustNumber
|
||||
hi def link rustIdentifierPrime rustIdentifier
|
||||
hi def link rustTrait rustType
|
||||
|
||||
hi def link rustMacroRepeatCount rustMacroRepeatDelimiters
|
||||
hi def link rustMacroRepeatDelimiters Macro
|
||||
hi def link rustMacroVariable Define
|
||||
hi def link rustSigil StorageClass
|
||||
hi def link rustEscape Special
|
||||
hi def link rustEscapeUnicode rustEscape
|
||||
hi def link rustEscapeError Error
|
||||
hi def link rustStringContinuation Special
|
||||
hi def link rustString String
|
||||
hi def link rustCharacterInvalid Error
|
||||
hi def link rustCharacterInvalidUnicode rustCharacterInvalid
|
||||
hi def link rustCharacter Character
|
||||
hi def link rustNumber Number
|
||||
hi def link rustBoolean Boolean
|
||||
hi def link rustEnum rustType
|
||||
hi def link rustEnumVariant rustConstant
|
||||
hi def link rustConstant Constant
|
||||
hi def link rustSelf Constant
|
||||
hi def link rustFloat Float
|
||||
hi def link rustOperator Operator
|
||||
hi def link rustKeyword Keyword
|
||||
hi def link rustReservedKeyword Error
|
||||
hi def link rustConditional Conditional
|
||||
hi def link rustIdentifier Identifier
|
||||
hi def link rustCapsIdent rustIdentifier
|
||||
hi def link rustModPath Include
|
||||
hi def link rustModPathSep Delimiter
|
||||
hi def link rustFunction Function
|
||||
hi def link rustFuncName Function
|
||||
hi def link rustFuncCall Function
|
||||
hi def link rustCommentLine Comment
|
||||
hi def link rustCommentLineDoc SpecialComment
|
||||
hi def link rustCommentBlock rustCommentLine
|
||||
hi def link rustCommentBlockDoc rustCommentLineDoc
|
||||
hi def link rustAssert PreCondit
|
||||
hi def link rustPanic PreCondit
|
||||
hi def link rustMacro Macro
|
||||
hi def link rustType Type
|
||||
hi def link rustTodo Todo
|
||||
hi def link rustAttribute PreProc
|
||||
hi def link rustDerive PreProc
|
||||
hi def link rustStorage StorageClass
|
||||
hi def link rustObsoleteStorage Error
|
||||
hi def link rustLifetime Special
|
||||
hi def link rustInvalidBareKeyword Error
|
||||
hi def link rustExternCrate rustKeyword
|
||||
hi def link rustObsoleteExternMod Error
|
||||
hi def link rustBoxPlacementParens Delimiter
|
||||
hi def link rustBoxPlacementExpr rustKeyword
|
||||
|
||||
" Other Suggestions:
|
||||
" hi rustAttribute ctermfg=cyan
|
||||
" hi rustDerive ctermfg=cyan
|
||||
" hi rustAssert ctermfg=yellow
|
||||
" hi rustPanic ctermfg=red
|
||||
" hi rustMacro ctermfg=magenta
|
||||
|
||||
syn sync minlines=200
|
||||
syn sync maxlines=500
|
||||
|
||||
let b:current_syntax = "rust"
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
" Vim syntastic plugin
|
||||
" Language: Rust
|
||||
" Maintainer: Andrew Gallant <jamslam@gmail.com>
|
||||
"
|
||||
" See for details on how to add an external Syntastic checker:
|
||||
" https://github.com/scrooloose/syntastic/wiki/Syntax-Checker-Guide#external
|
||||
|
||||
if exists("g:loaded_syntastic_rust_rustc_checker")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_syntastic_rust_rustc_checker = 1
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function! SyntaxCheckers_rust_rustc_GetLocList() dict
|
||||
let makeprg = self.makeprgBuild({ 'args': '-Zparse-only' })
|
||||
|
||||
let errorformat =
|
||||
\ '%E%f:%l:%c: %\d%#:%\d%# %.%\{-}error:%.%\{-} %m,' .
|
||||
\ '%W%f:%l:%c: %\d%#:%\d%# %.%\{-}warning:%.%\{-} %m,' .
|
||||
\ '%C%f:%l %m,' .
|
||||
\ '%-Z%.%#'
|
||||
|
||||
return SyntasticMake({
|
||||
\ 'makeprg': makeprg,
|
||||
\ 'errorformat': errorformat })
|
||||
endfunction
|
||||
|
||||
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
||||
\ 'filetype': 'rust',
|
||||
\ 'name': 'rustc'})
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
|
@ -1,215 +0,0 @@
|
|||
#compdef rustc
|
||||
|
||||
local -a _rustc_opts_switches _rustc_opts_lint _rustc_opts_debug
|
||||
|
||||
typeset -A opt_args
|
||||
|
||||
_rustc_debuginfo_levels=(
|
||||
"0[no debug info]"
|
||||
"1[line-tables only (for stacktraces and breakpoints)]"
|
||||
"2[full debug info with variable and type information (same as -g)]"
|
||||
)
|
||||
|
||||
_rustc_crate_types=(
|
||||
'bin'
|
||||
'lib'
|
||||
'rlib'
|
||||
'dylib'
|
||||
'staticlib'
|
||||
)
|
||||
|
||||
_rustc_emit_types=(
|
||||
'asm'
|
||||
'llvm-bc'
|
||||
'llvm-ir'
|
||||
'obj'
|
||||
'link'
|
||||
'dep-info'
|
||||
)
|
||||
_rustc_pretty_types=(
|
||||
'normal[un-annotated source]'
|
||||
'expanded[crates expanded]'
|
||||
'typed[crates expanded, with type annotations]'
|
||||
'identified[fully parenthesized, AST nodes and blocks with IDs]'
|
||||
'flowgraph[graphviz formatted flowgraph for node]:NODEID:'
|
||||
)
|
||||
_rustc_color_types=(
|
||||
'auto[colorize, if output goes to a tty (default)]'
|
||||
'always[always colorize output]'
|
||||
'never[never colorize output]'
|
||||
)
|
||||
_rustc_info_types=(
|
||||
'crate-name[Output the crate name and exit]'
|
||||
'file-names[Output the file(s) that would be written if compilation continued and exited]'
|
||||
'sysroot[Output the sysroot and exit]'
|
||||
)
|
||||
|
||||
_rustc_opts_vals=(
|
||||
--crate-name='[Specify the name of the crate being built]'
|
||||
--crate-type='[Comma separated list of types of crates for the compiler to emit]:TYPES:_values -s "," "Crate types" "$_rustc_crate_types[@]"'
|
||||
--emit='[Comma separated list of types of output for the compiler to emit]:TYPES:_values -s "," "Emit Targets" "$_rustc_emit_types[@]"'
|
||||
--cfg='[Configure the compilation environment]:SPEC:'
|
||||
--out-dir='[Write output to compiler-chosen filename in <dir>. Ignored if -o is specified. (default the current directory)]:DIR:_files -/'
|
||||
-o'[Write output to <filename>. Ignored if more than one --emit is specified.]:FILENAME:_files'
|
||||
--pretty='[Pretty-print the input instead of compiling]::TYPE:_values "TYPES" "$_rustc_pretty_types[@]"'
|
||||
-L'[Add a directory to the library search path]:DIR:_files -/'
|
||||
--target='[Target triple cpu-manufacturer-kernel\[-os\] to compile]:TRIPLE:'
|
||||
--color='[Configure coloring of output]:CONF:_values "COLORS" "$_rustc_color_types[@]"'
|
||||
{-v,--version}'[Print version info and exit]::VERBOSE:(verbose)'
|
||||
--explain='[Provide a detailed explanation of an error message]:OPT:'
|
||||
--extern'[Specify where an external rust library is located]:ARG:'
|
||||
--print='[Comma separated list of compiler information to print on stdout]:TYPES:_values -s "," "Compiler Information" "$_rustc_info_types[@]"'
|
||||
)
|
||||
|
||||
_rustc_opts_switches=(
|
||||
-g'[Equivalent to -C debuginfo=2]'
|
||||
{-h,--help}'[Display the help message]'
|
||||
{-V,--verbose}'[use verbose output]'
|
||||
-O'[Equivalent to -C opt-level=2]'
|
||||
--test'[Build a test harness]'
|
||||
)
|
||||
|
||||
|
||||
_rustc_opts_link=(
|
||||
'static[Path to the library to link statically]:PATH:_files -/'
|
||||
'dylib[Path to the library to link dynamically]:PATH:_files -/'
|
||||
'framework[Path to the library to link as a framework]:PATH:_files -/'
|
||||
)
|
||||
|
||||
_rustc_opts_codegen=(
|
||||
'ar[Path to the archive utility to use when assembling archives.]:BIN:_path_files'
|
||||
'linker[Path to the linker utility to use when linking libraries, executables, and objects.]:BIN:_path_files'
|
||||
'link-args[A space-separated list of extra arguments to pass to the linker when the linker is invoked.]:ARGS:'
|
||||
'lto[Perform LLVM link-time optimizations]'
|
||||
'target-cpu[Selects a target processor. If the value is "help", then a list of available CPUs is printed.]:CPU:'
|
||||
'target-feature[A space-separated list of features to enable or disable for the target. A preceding "+" enables a feature while a preceding "-" disables it. Available features can be discovered through target-cpu=help.]:FEATURE:'
|
||||
'passes[A space-separated list of extra LLVM passes to run. A value of "list" will cause rustc to print all known passes and exit. The passes specified are appended at the end of the normal pass manager.]:LIST:'
|
||||
'llvm-args[A space-separated list of arguments to pass through to LLVM.]:ARGS:'
|
||||
'save-temps[If specified, the compiler will save more files (.bc, .o, .no-opt.bc) generated throughout compilation in the output directory.]'
|
||||
'rpath[If specified, then the rpath value for dynamic libraries will be set in either dynamic library or executable outputs.]'
|
||||
'no-prepopulate-passes[Suppresses pre-population of the LLVM pass manager that is run over the module.]'
|
||||
'no-vectorize-loops[Suppresses running the loop vectorization LLVM pass, regardless of optimization level.]'
|
||||
'no-vectorize-slp[Suppresses running the LLVM SLP vectorization pass, regardless of optimization level.]'
|
||||
'soft-float[Generates software floating point library calls instead of hardware instructions.]'
|
||||
'prefer-dynamic[Prefers dynamic linking to static linking.]'
|
||||
"no-integrated-as[Force usage of an external assembler rather than LLVM's integrated one.]"
|
||||
'no-redzone[disable the use of the redzone]'
|
||||
'relocation-model[The relocation model to use. (default: pic)]:MODEL:(pic static dynamic-no-pic)'
|
||||
'code-model[choose the code model to use (llc -code-model for details)]:MODEL:'
|
||||
'metadata[metadata to mangle symbol names with]:VAL:'
|
||||
'extra-filenames[extra data to put in each output filename]:VAL:'
|
||||
'codegen-units[divide crate into N units to optimize in parallel]:N:'
|
||||
'remark[print remarks for these optimization passes (space separated, or "all")]:TYPE:'
|
||||
'debuginfo[debug info emission level, 0 = no debug info, 1 = line tables only, 2 = full debug info with variable and type information]:LEVEL:_values "Debug Levels" "$_rustc_debuginfo_levels[@]"'
|
||||
'opt-level[Optimize with possible levels 0-3]:LEVEL:(0 1 2 3)'
|
||||
'help[Show all codegen options]'
|
||||
)
|
||||
|
||||
_rustc_opts_lint=(
|
||||
'help[Show a list of all lints]'
|
||||
'box-pointers[(default: allow) use of owned (Box type) heap memory]'
|
||||
'experimental[(default: allow) detects use of #\[experimental\] items]'
|
||||
'fat-ptr-transmutes[(default: allow) detects transmutes of fat pointers]'
|
||||
'missing-docs[(default: allow) detects missing documentation for public members]'
|
||||
'unsafe-blocks[(default: allow) usage of an "unsafe" block]'
|
||||
'unstable[(default: allow) detects use of #\[unstable\] items (incl. items with no stability attribute)]'
|
||||
'unused-extern-crates[(default: allow) extern crates that are never used]'
|
||||
'unused-import-braces[(default: allow) unnecessary braces around an imported item]'
|
||||
'unused-qualifications[(default: allow) detects unnecessarily qualified names]'
|
||||
'unused-results[(default: allow) unused result of an expression in a statement]'
|
||||
'unused-typecasts[(default: allow) detects unnecessary type casts that can be removed]'
|
||||
'variant-size-differences[(default: allow) detects enums with widely varying variant sizes]'
|
||||
'dead-code[(default: warn) detect unused, unexported items]'
|
||||
'deprecated[(default: warn) detects use of #\[deprecated\] items]'
|
||||
'improper-ctypes[(default: warn) proper use of libc types in foreign modules]'
|
||||
'missing-copy-implementations[(default: warn) detects potentially-forgotten implementations of "Copy"]'
|
||||
'non-camel-case-types[(default: warn) types, variants, traits and type parameters should have camel case names]'
|
||||
'non-shorthand-field-patterns[(default: warn) using "Struct { x: x }" instead of "Struct { x }"]'
|
||||
'non-snake-case[(default: warn) methods, functions, lifetime parameters and modules should have snake case names]'
|
||||
'non-upper-case-globals[(default: warn) static constants should have uppercase identifiers]'
|
||||
'overflowing-literals[(default: warn) literal out of range for its type]'
|
||||
'path-statements[(default: warn) path statements with no effect]'
|
||||
'raw-pointer-deriving[(default: warn) uses of #\[derive\] with raw pointers are rarely correct]'
|
||||
'unknown-lints[(default: warn) unrecognized lint attribute]'
|
||||
'unreachable-code[(default: warn) detects unreachable code paths]'
|
||||
'unsigned-negation[(default: warn) using an unary minus operator on unsigned type]'
|
||||
'unused-allocation[(default: warn) detects unnecessary allocations that can be eliminated]'
|
||||
'unused-assignments[(default: warn) detect assignments that will never be read]'
|
||||
'unused-attributes[(default: warn) detects attributes that were not used by the compiler]'
|
||||
'unused-comparisons[(default: warn) comparisons made useless by limits of the types involved]'
|
||||
'unused-imports[(default: warn) imports that are never used]'
|
||||
'unused-must-use[(default: warn) unused result of a type flagged as must_use]'
|
||||
"unused-mut[(default: warn) detect mut variables which don't need to be mutable]"
|
||||
'unused-parens[(default: warn) "if", "match", "while" and "return" do not need parentheses]'
|
||||
'unused-unsafe[(default: warn) unnecessary use of an "unsafe" block]'
|
||||
'unused-variables[(default: warn) detect variables which are not used in any way]'
|
||||
'warnings[(default: warn) mass-change the level for lints which produce warnings]'
|
||||
'while-true[(default: warn) suggest using "loop { }" instead of "while true { }"]'
|
||||
"exceeding-bitshifts[(default: deny) shift exceeds the type's number of bits]"
|
||||
'unknown-crate-types[(default: deny) unknown crate type found in #\[crate_type\] directive]'
|
||||
'unknown-features[(default: deny) unknown features found in crate-level #\[feature\] directives]'
|
||||
'bad-style[non-camel-case-types, non-snake-case, non-upper-case-globals]'
|
||||
'unused[unused-imports, unused-variables, unused-assignments, dead-code, unused-mut, unreachable-code, unused-must-use, unused-unsafe, path-statements]'
|
||||
)
|
||||
|
||||
_rustc_opts_debug=(
|
||||
'verbose[in general, enable more debug printouts]'
|
||||
'time-passes[measure time of each rustc pass]'
|
||||
'count-llvm-insns[count where LLVM instrs originate]'
|
||||
'time-llvm-passes[measure time of each LLVM pass]'
|
||||
'trans-stats[gather trans statistics]'
|
||||
'asm-comments[generate comments into the assembly (may change behavior)]'
|
||||
'no-verify[skip LLVM verification]'
|
||||
'borrowck-stats[gather borrowck statistics]'
|
||||
'no-landing-pads[omit landing pads for unwinding]'
|
||||
'debug-llvm[enable debug output from LLVM]'
|
||||
'show-span[show spans for compiler debugging]'
|
||||
'count-type-sizes[count the sizes of aggregate types]'
|
||||
'meta-stats[gather metadata statistics]'
|
||||
'print-link-args[Print the arguments passed to the linker]'
|
||||
'gc[Garbage collect shared data (experimental)]'
|
||||
'print-llvm-passes[Prints the llvm optimization passes being run]'
|
||||
'ast-json[Print the AST as JSON and halt]'
|
||||
'ast-json-noexpand[Print the pre-expansion AST as JSON and halt]'
|
||||
'ls[List the symbols defined by a library crate]'
|
||||
'save-analysis[Write syntax and type analysis information in addition to normal output]'
|
||||
'flowgraph-print-loans[Include loan analysis data in --pretty flowgraph output]'
|
||||
'flowgraph-print-moves[Include move analysis data in --pretty flowgraph output]'
|
||||
'flowgraph-print-assigns[Include assignment analysis data in --pretty flowgraph output]'
|
||||
'flowgraph-print-all[Include all dataflow analysis data in --pretty flowgraph output]'
|
||||
'print-regiion-graph[Prints region inference graph. Use with RUST_REGION_GRAPH=help for more info]'
|
||||
'parse-only[Parse only; do not compile, assemble, or link]'
|
||||
'no-trans[Run all passes except translation; no output]'
|
||||
'no-analysis[Parse and expand the source, but run no analysis]'
|
||||
'unstable-options[Adds unstable command line options to rustc interface]'
|
||||
'print-enum-sizes[Print the size of enums and their variants]'
|
||||
)
|
||||
|
||||
_rustc_opts_fun_lint(){
|
||||
_values -s , 'options' \
|
||||
"$_rustc_opts_lint[@]"
|
||||
}
|
||||
|
||||
_rustc_opts_fun_debug(){
|
||||
_values 'options' "$_rustc_opts_debug[@]"
|
||||
}
|
||||
|
||||
_rustc_opts_fun_codegen(){
|
||||
_values 'options' "$_rustc_opts_codegen[@]"
|
||||
}
|
||||
|
||||
_rustc_opts_fun_link(){
|
||||
_values 'options' "$_rustc_opts_link[@]"
|
||||
}
|
||||
|
||||
_arguments -s : \
|
||||
'(-W --warn)'{-W,--warn=}'[Set lint warnings]:lint options:_rustc_opts_fun_lint' \
|
||||
'(-A --allow)'{-A,--allow=}'[Set lint allowed]:lint options:_rustc_opts_fun_lint' \
|
||||
'(-D --deny)'{-D,--deny=}'[Set lint denied]:lint options:_rustc_opts_fun_lint' \
|
||||
'(-F --forbid)'{-F,--forbid=}'[Set lint forbidden]:lint options:_rustc_opts_fun_lint' \
|
||||
'*-Z[Set internal debugging options]:debug options:_rustc_opts_fun_debug' \
|
||||
'(-C --codegen)'{-C,--codegen}'[Set internal Codegen options]:codegen options:_rustc_opts_fun_codegen' \
|
||||
'*-l[Link the generated crates to the specified native library NAME. the optional KIND can be one of, static, dylib, or framework. If omitted, dylib is assumed.]:ARG:_rustc_opts_fun_link' \
|
||||
"$_rustc_opts_switches[@]" \
|
||||
"$_rustc_opts_vals[@]" \
|
||||
'::files:_files -g "*.rs"'
|
||||
Loading…
Add table
Add a link
Reference in a new issue