At Fri, 4 Jan 2002 23:32:37 +0900,
Ville Mattila <mulperi / iki.fi> wrote:
> Could you please send a diff that includes all your the recent fixes
> against the ruby-mode.el version 1.39.

A patch to version 1.40.


Index: ruby-mode.el =================================================================== RCS file: /cvs/ruby/src/ruby/misc/ruby-mode.el,v retrieving revision 1.40 diff -u -2 -p -w -r1.40 ruby-mode.el --- ruby-mode.el 2002/01/04 14:15:33 1.40 +++ ruby-mode.el 2002/01/04 15:12:41 @@ -254,4 +254,19 @@ The variable ruby-indent-level controls (looking-at "[a-zA-Z][a-zA-z0-9_]* +/[^ \t]")))))))))) +(defun ruby-forward-string (term &optional end no-error expand) + (let ((n 1) (c (string-to-char term)) + (re (if expand + (concat "[^\\]\\(\\\\\\\\\\)*\\([" term "]\\|\\(#{\\)\\)") + (concat "[^\\]\\(\\\\\\\\\\)*[" term "]")))) + (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")))) + (defun ruby-parse-region (start end) (let ((indent-point end) @@ -271,14 +286,20 @@ The variable ruby-indent-level controls (re-search-forward ruby-delimiter indent-point t)) (or depth (setq depth 0)) - (let ((pnt (point)) w re) + (let ((pnt (point)) w re expand) (goto-char (match-beginning 0)) (cond ((or (looking-at "\"") ;skip string - (looking-at "'") (looking-at "`")) - (setq w (char-after (point))) + (cond + ((and (not (eobp)) + (ruby-forward-string (buffer-substring (point) (1+ (point))) indent-point t t)) + nil) + (t + (setq in-string (point)) + (goto-char indent-point)))) + ((looking-at "'") (cond ((and (not (eobp)) - (re-search-forward (format "[^\\]\\(\\\\\\\\\\)*%c" w) indent-point t)) + (re-search-forward "[^\\]\\(\\\\\\\\\\)*'" indent-point t)) nil) (t @@ -288,5 +309,5 @@ The variable ruby-indent-level controls (cond ((and (not (eobp)) (ruby-expr-beg)) - (if (re-search-forward "[^\\]\\(\\\\\\\\\\)*/" indent-point t) + (if (ruby-forward-string "/" indent-point t t) nil (setq in-string (point)) @@ -300,4 +321,5 @@ The variable ruby-indent-level controls (looking-at "%[Qqrxw]?\\(.\\)")) (goto-char (match-beginning 1)) + (setq expand (not (eq (char-before) ?q))) (setq w (buffer-substring (match-beginning 1) (match-end 1))) @@ -307,22 +329,14 @@ The variable ruby-indent-level controls ((string= w "(") (setq re ")(")) ((string= w "<") (setq re "><")) - ((member w '("*" "." "+" "?" "^" "$")) + ((or (and expand (string= w "\\")) + (member w '("*" "." "+" "?" "^" "$"))) (setq w (concat "\\" w)))) - (if (if re - (let ((n 1)) - (setq re (concat "[^\\]\\(\\\\\\\\\\)*[" re "]")) - (while (and (re-search-forward re indent-point t) - (> (setq n (if (eq (char-before (point)) - (string-to-char w)) - (1+ n) (1- n))) - 0)) - (forward-char -1)) - (zerop n)) - (re-search-forward + (unless (cond (re (ruby-forward-string re indent-point t expand)) + (expand (ruby-forward-string w indent-point t t)) + (t (re-search-forward (if (string= w "\\") "\\\\[^\\]*\\\\" (concat "[^\\]\\(\\\\\\\\\\)*" w)) - indent-point t)) - nil + indent-point t))) (setq in-string (point)) (goto-char indent-point))) @@ -529,17 +543,9 @@ The variable ruby-indent-level controls (skip-chars-backward " \t") (let ((pos (point))) - (and - (re-search-backward "#" (save-excursion - (beginning-of-line) - (point)) t) - (if (not (= (point) (point-min))) - (save-excursion - (forward-char -1) - (not (looking-at "\\?")))) + (while (and (re-search-backward "#" bol t) + (= (char-before) ??)) + (forward-char -1)) (skip-chars-backward " \t") - (if (save-excursion - (forward-char -1) - (looking-at "\\?")) - (skip-chars-forward " \t")) + (and (setq state (ruby-parse-region parse-start (point))) (nth 0 state) @@ -682,8 +688,4 @@ An end of a defun is found by moving for (setq font-lock-variable-name-face font-lock-type-face)) - - (add-hook 'ruby-mode-hook - '(lambda () - (make-local-variable 'ruby-font-lock-syntactic-keywords) (setq ruby-font-lock-syntactic-keywords '( @@ -718,7 +720,11 @@ An end of a defun is found by moving for ("^\\(=\\)begin\\(\\s \\|$\\)" 1 (7 . nil)) ("^\\(=\\)end\\(\\s \\|$\\)" 1 (7 . nil)))) - (make-local-variable 'font-lock-defaults) - (setq font-lock-defaults '((ruby-font-lock-keywords) nil nil)) - (setq font-lock-keywords ruby-font-lock-keywords))) + + (put 'ruby-mode 'font-lock-defaults + '((ruby-font-lock-keywords) + nil nil nil + beginning-of-line + (font-lock-syntactic-keywords + . ruby-font-lock-syntactic-keywords))) (defun ruby-font-lock-docs (limit)
-- Nobu Nakada