From 8f06accefa669c323731525946eeaef4a3decf6d Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Fri, 7 Sep 2012 09:06:05 +0400 Subject: [PATCH] * lisp/progmodes/ruby-mode.el (ruby-beginning-of-defun): Only consider 3 keywords defun beginners. (ruby-end-of-defun): Expect that the point is at the beginning of the defun. --- lisp/ChangeLog | 3 +++ lisp/progmodes/ruby-mode.el | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 219fd382e5..179d5be11c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -8,6 +8,9 @@ * progmodes/ruby-mode.el (ruby-end-of-defun) (ruby-beginning-of-defun): Simplify, allow indentation before block beginning and end keywords. + (ruby-beginning-of-defun): Only consider 3 keywords defun beginners. + (ruby-end-of-defun): Expect that the point is at the beginning of + the defun. 2012-09-06 Stefan Monnier diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index e8e6b3dbae..ef1daa5e93 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -98,6 +98,10 @@ (defconst ruby-block-end-re "\\_") +(defconst ruby-defun-beg-re + '"\\(def\\|class\\|module\\)" + "Regexp to match the beginning of a defun, in the general sense.") + (eval-and-compile (defconst ruby-here-doc-beg-re "\\(<\\)<\\(-\\)?\\(\\([a-zA-Z0-9_]+\\)\\|[\"]\\([^\"]+\\)[\"]\\|[']\\([^']+\\)[']\\)" @@ -833,13 +837,12 @@ and `\\' when preceded by `?'." (+ indent ruby-indent-level) indent)))) -;; TODO: Why isn't one ruby-*-of-defun written in terms of the other? (defun ruby-beginning-of-defun (&optional arg) "Move backward to the beginning of the current top-level defun. With ARG, move backward multiple defuns. Negative ARG means move forward." (interactive "p") - (and (re-search-backward (concat "^\\s *\\(" ruby-block-beg-re "\\)\\_>") + (and (re-search-backward (concat "^\\s *" ruby-defun-beg-re "\\_>") nil t (or arg 1)) (beginning-of-line))) @@ -848,9 +851,9 @@ move forward." With ARG, move forward multiple defuns. Negative ARG means move backward." (interactive "p") - (and (re-search-forward (concat "^\\s *" ruby-block-end-re) nil t (or arg 1)) - (beginning-of-line)) - (forward-line 1)) + (ruby-forward-sexp) + (when (looking-back (concat "^\\s *" ruby-block-end-re)) + (forward-line 1))) (defun ruby-beginning-of-indent () "Backtrack to a line which can be used as a reference for @@ -1050,7 +1053,7 @@ See `add-log-current-defun-function'." (let (mname mlist (indent 0)) ;; get current method (or class/module) (if (re-search-backward - (concat "^[ \t]*\\(def\\|class\\|module\\)[ \t]+" + (concat "^[ \t]*" ruby-defun-beg-re "[ \t]+" "\\(" ;; \\. and :: for class method "\\([A-Za-z_]" ruby-symbol-re "*\\|\\.\\|::" "\\)" -- 2.20.1