Skip to content

package.el rust-mode (update) #3196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion src/etc/emacs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ rust-mode: A major emacs mode for editing Rust source code
`rust-mode` makes editing [Rust](http://rust-lang.org) code with emacs
enjoyable.

To install, check out this repository and add this to your .emacs

### Manual Installation

To install manually, check out this repository and add this to your .emacs
file:

(add-to-list 'load-path "/path/to/rust-mode/")
Expand All @@ -25,3 +28,60 @@ it, and pressing `C-j`:

Rust mode will automatically be associated with .rs and .rc files. To
enable it explicitly, do `M-x rust-mode`.

### package.el installation via Marmalade

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, the community package source,
yet, add this to ~/.emacs.d/init.el:

```lisp
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(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 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.

From there 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 i. This
will mark the packages for installation. When you're done with
marking, press x, and ELPA will install the packages for you (under
~/.emacs.d/elpa/).

* or using <kbd>M-x package-install rust-mode

#### Important

In order to have cm-mode properly initialized after compilation prior
to rust-mode.el compilation you will need to add these `advices` to
your init file or if you are a melpa user install the `melpa` package.

```lisp
(defadvice package-download-tar
(after package-download-tar-initialize activate compile)
"initialize the package after compilation"
(package-initialize))

(defadvice package-download-single
(after package-download-single-initialize activate compile)
"initialize the package after compilation"
(package-initialize))
```
20 changes: 14 additions & 6 deletions src/etc/emacs/cm-mode.el
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
;; Wrapper for CodeMirror-style emacs modes. Highlighting is done by
;; running a stateful parser (with first-class state object) over the
;; buffer, line by line, using the output to add 'face properties, and
;; storing the parser state at the end of each line. Indentation is
;; done based on the parser state at the start of the line.
;;; cm-mode.el --- Wrapper for CodeMirror-style Emacs modes

;; Version: 0.1.0
;; Author: Mozilla
;; Url: https://github.com/mozilla/rust
;; Highlighting is done by running a stateful parser (with first-class
;; state object) over the buffer, line by line, using the output to
;; add 'face properties, and storing the parser state at the end of
;; each line. Indentation is done based on the parser state at the
;; start of the line.

(eval-when-compile (require 'cl))

Expand Down Expand Up @@ -163,7 +168,7 @@
(cm-schedule-work 0.05)))))

(defun cm-do-some-work ()
(save-excursion
(save-excursion
(condition-case cnd (cm-do-some-work-inner)
(error (print cnd) (error cnd)))))

Expand All @@ -174,6 +179,7 @@

;; Entry function

;;;###autoload
(defun cm-mode (mode)
(set (make-local-variable 'cm-cur-mode) mode)
(set (make-local-variable 'cm-worklist) (list (copy-marker 1)))
Expand All @@ -184,3 +190,5 @@
(cm-schedule-work 0.05))

(provide 'cm-mode)

;;; cm-mode.el ends here
10 changes: 10 additions & 0 deletions src/etc/emacs/rust-mode.el
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
;;; rust-mode.el --- A major emacs mode for editing Rust source code

;; Version: 0.1.0
;; Author: Mozilla
;; Package-Requires: ((cm-mode "0.1.0"))
;; Url: https://github.com/mozilla/rust

(require 'cm-mode)
(require 'cc-mode)

Expand Down Expand Up @@ -277,6 +284,7 @@
((eq (rust-context-align cx) t) (+ (rust-context-column cx) (if closing -1 0)))
(t (+ base (if closing 0 unit)))))))

;;;###autoload
(define-derived-mode rust-mode fundamental-mode "Rust"
"Major mode for editing Rust source files."
(set-syntax-table rust-syntax-table)
Expand All @@ -293,3 +301,5 @@
(define-key rust-mode-map "{" 'rust-electric-brace)

(provide 'rust-mode)

;;; rust-mode.el ends here