Skip to content

Emacs 23 Fixups #30

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

Merged
merged 4 commits into from
Feb 7, 2015
Merged
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: generic

env:
matrix:
- EMACS=emacs23
- EMACS=emacs24
- EMACS=emacs-snapshot

Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ the packages for you (under `~/.emacs.d/elpa/`).
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`.
you set the environment variable EMACS to a program that runs emacs.

To test it under emacs 23, which does not ship with ERT, download ert.el from
https://raw.githubusercontent.com/ohler/ert/c619b56c5bc6a866e33787489545b87d79973205/lisp/emacs-lisp/ert.el
and put it in a place where emacs can find it. (ERT has shipped with emacs
since emacs 24.)
15 changes: 14 additions & 1 deletion rust-mode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,11 @@ very very very long string
(rust-test-manip-code
deindented
1
(lambda () (indent-region 1 (buffer-size)))
(lambda ()
;; The indentation will fial in some cases if the syntax properties are
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo here (but I'm not going to block merging the PR on this).

;; not set. This only happens when font-lock fontifies the buffer.
(font-lock-fontify-buffer)
(indent-region 1 (buffer-size)))
indented)))


Expand Down Expand Up @@ -1008,3 +1012,12 @@ fn main() {
}
"
)))

(ert-deftest indent-method-chains-after-comment ()
(let ((rust-indent-method-chain t)) (test-indent
"
fn main() { // comment here should not push next line out
foo.bar()
}
"
)))
43 changes: 13 additions & 30 deletions rust-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
;; be undone via tab.

(when (looking-at (concat "\s*\." rust-re-ident))
(previous-line)
(previous-logical-line)
(end-of-line)

(let
Expand All @@ -131,7 +131,7 @@
;;
((skip-dot-identifier
(lambda ()
(when (looking-back (concat "\." rust-re-ident))
(when (looking-back (concat "\\." rust-re-ident))
(backward-word 1)
(backward-char)
(- (current-column) rust-indent-offset)))))
Expand Down Expand Up @@ -311,6 +311,14 @@
("fn" . font-lock-function-name-face)
("static" . font-lock-constant-face)))))

(defvar rust-mode-font-lock-syntactic-keywords
(mapcar (lambda (re) (list re '(1 "\"") '(2 "\"")))
'("\\('\\)[^']\\('\\)"
"\\('\\)\\\\['nrt]\\('\\)"
"\\('\\)\\\\x[[:xdigit:]]\\{2\\}\\('\\)"
"\\('\\)\\\\u[[:xdigit:]]\\{4\\}\\('\\)"
"\\('\\)\\\\U[[:xdigit:]]\\{8\\}\\('\\)")))

(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
Expand Down Expand Up @@ -569,7 +577,7 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
(setq-local indent-line-function 'rust-mode-indent-line)

;; Fonts
(setq-local font-lock-defaults '(rust-mode-font-lock-keywords nil nil nil nil))
(setq-local font-lock-defaults '(rust-mode-font-lock-keywords nil nil nil nil (font-lock-syntactic-keywords . rust-mode-font-lock-syntactic-keywords)))

;; Misc
(setq-local comment-start "// ")
Expand All @@ -591,33 +599,8 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
(setq-local beginning-of-defun-function 'rust-beginning-of-defun)
(setq-local end-of-defun-function 'rust-end-of-defun)
(setq-local parse-sexp-lookup-properties t)
(add-hook 'syntax-propertize-extend-region-functions 'rust-syntax-propertize-extend-region)
(add-hook 'post-self-insert-hook 'rust-match-angle-bracket-hook)
(setq-local syntax-propertize-function 'rust-syntax-propertize))

(defun rust-syntax-propertize-extend-region (start end)
(save-excursion
(goto-char start)
(beginning-of-defun)
(cons
(point)
(progn
(goto-char end)
(end-of-defun)
(point)))))

(defun rust-syntax-propertize (start end)
;; Find character literals and make the syntax table recognize the single quote as the string delimiter
(dolist (char-lit-re
'("'[^']'"
"'\\\\['nrt]'"
"'\\\\x[[:xdigit:]]\\{2\\}'"
"'\\\\u[[:xdigit:]]\\{4\\}'"
"'\\\\U[[:xdigit:]]\\{8\\}'"))
(save-excursion
(goto-char start)
(while (re-search-forward char-lit-re end t)
(put-text-property (match-beginning 0) (match-end 0) 'syntax-table rust-mode-character-literal-syntax-table)))))
(setq-local syntax-begin-function 'beginning-of-defun)
(add-hook 'post-self-insert-hook 'rust-match-angle-bracket-hook))

;;;###autoload
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
Expand Down