From 8f48d131819e34322f27d1202bfb8a723ce93983 Mon Sep 17 00:00:00 2001 From: Cameron Desautels Date: Mon, 9 Dec 2013 05:43:34 +0200 Subject: [PATCH] * lisp/progmodes/ruby-mode.el (ruby-forward-string): Document. Handle caret-delimited strings. Fixes: debbugs:16079 --- lisp/ChangeLog | 5 +++++ lisp/progmodes/ruby-mode.el | 25 +++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2e36fdbe4c..6e2631887a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2013-12-09 Cameron Desautels (tiny change) + + * progmodes/ruby-mode.el (ruby-forward-string): Document. Handle + caret-delimited strings (Bug#16079). + 2013-12-09 Dmitry Gutov * progmodes/ruby-mode.el (ruby-accurate-end-of-block): When diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 0f5a2a5b2a..fe36e72542 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -795,11 +795,28 @@ Can be one of `heredoc', `modifier', `expr-qstr', `expr-re'." (t nil))))))))) (defun ruby-forward-string (term &optional end no-error expand) - "TODO: document." + "Move forward across one balanced pair of string delimiters. +Skips escaped delimiters. If EXPAND is non-nil, also ignores +delimiters in interpolated strings. + +TERM should be a string containing either a single, self-matching +delimiter (e.g. \"/\"), or a pair of matching delimiters with the +close delimiter first (e.g. \"][\"). + +When non-nil, search is bounded by position END. + +Throws an error if a balanced match is not found, unless NO-ERROR +is non-nil, in which case nil will be returned. + +This command assumes the character after point is an opening +delimiter." (let ((n 1) (c (string-to-char term)) - (re (if expand - (concat "[^\\]\\(\\\\\\\\\\)*\\([" term "]\\|\\(#{\\)\\)") - (concat "[^\\]\\(\\\\\\\\\\)*[" term "]")))) + (re (concat "[^\\]\\(\\\\\\\\\\)*\\(" + (if (string= term "^") ;[^] is not a valid regexp + "\\^" + (concat "[" term "]")) + (when expand "\\|\\(#{\\)") + "\\)"))) (while (and (re-search-forward re end no-error) (if (match-beginning 3) (ruby-forward-string "}{" end no-error nil) -- 2.20.1