diff --git a/.travis.yml b/.travis.yml index 63221edd..04231a78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: generic env: matrix: + - EMACS=emacs23 - EMACS=emacs24 - EMACS=emacs-snapshot diff --git a/README.md b/README.md index 24470c25..6823f8b8 100644 --- a/README.md +++ b/README.md @@ -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.) diff --git a/rust-mode-tests.el b/rust-mode-tests.el index a0e27b05..36e59dfb 100644 --- a/rust-mode-tests.el +++ b/rust-mode-tests.el @@ -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 + ;; not set. This only happens when font-lock fontifies the buffer. + (font-lock-fontify-buffer) + (indent-region 1 (buffer-size))) indented))) @@ -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() +} +" + ))) diff --git a/rust-mode.el b/rust-mode.el index b2e0d5dc..43afd9ac 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -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 @@ -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))))) @@ -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 @@ -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 "// ") @@ -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))