diff options
| author | Tom Tromey <tom@tromey.com> | 2017-08-04 09:01:37 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-04 09:01:37 -0600 |
| commit | afeddec5a4755418cde1537364cfc30ae280354e (patch) | |
| tree | 24ce93dcd92458682eb66c7c02cc3a5a55303a3e /rust-mode.el | |
| parent | 30a9d398fbdb88af16725248656956cb350c821d (diff) | |
| parent | 1d4a75f84865356a3cf6dbc1b0b32ec43496446e (diff) | |
| download | rust-mode-afeddec5a4755418cde1537364cfc30ae280354e.tar.gz | |
Merge pull request #224 from tromey/beginning-of-defun
Make rust-beginning-of-defun ignore comments and strings
Diffstat (limited to 'rust-mode.el')
| -rw-r--r-- | rust-mode.el | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/rust-mode.el b/rust-mode.el index 46231fd..33e6b28 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -1198,8 +1198,22 @@ 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))) + (let* ((arg (or arg 1)) + (magnitude (abs arg)) + (sign (if (< arg 0) -1 1))) + ;; If moving forward, don't find the defun we might currently be + ;; on. + (when (< sign 0) + (end-of-line)) + (catch 'done + (dotimes (_ magnitude) + ;; Search until we find a match that is not in a string or comment. + (while (if (re-search-backward (concat "^\\(" rust-top-item-beg-re "\\)") + nil 'move sign) + (rust-in-str-or-cmnt) + ;; Did not find it. + (throw 'done nil))))) + t)) (defun rust-end-of-defun () "Move forward to the next end of defun. |
