Function: ruby-forward-string

ruby-forward-string is a byte-compiled function defined in ruby-mode.el.gz.

Signature

(ruby-forward-string TERM &optional END NO-ERROR EXPAND)

Documentation

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.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/ruby-mode.el.gz
(defun ruby-forward-string (term &optional end no-error expand)
  "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 (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)
                  (> (setq n (if (eq (char-before (point)) c)
                                     (1- n) (1+ n))) 0)))
      (forward-char -1))
    (cond ((zerop n))
          (no-error nil)
          ((error "Unterminated string")))))