* misc/ruby-mode.el (ruby-forward-string): forward a string. [new]

* misc/ruby-mode.el (ruby-parse-region): handle nested parentheses
  in a string and terminators in #{}.

* misc/ruby-mode.el (ruby-calculate-indent): ditto.

* misc/ruby-mode.el (ruby-font-lock-syntactic-keywords):
  fix font-lock problem [ruby-talk:29296].


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2002-01-05 03:25:02 +00:00
parent 0ad520443c
commit 8090c2f214
2 changed files with 97 additions and 77 deletions

View File

@ -1,3 +1,12 @@
Fri Jan 4 17:23:49 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* misc/ruby-mode.el (ruby-forward-string): forward a string. [new]
* misc/ruby-mode.el (ruby-parse-region): handle nested parentheses
in a string and terminators in #{}.
* misc/ruby-mode.el (ruby-calculate-indent): ditto.
Sat Jan 5 00:19:12 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp> Sat Jan 5 00:19:12 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* parse.y (yycompile): strdup()'ed twice. * parse.y (yycompile): strdup()'ed twice.
@ -95,6 +104,11 @@ Tue Dec 25 02:11:17 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (rb_check_convert_type): ditto. * object.c (rb_check_convert_type): ditto.
Mon Dec 24 02:37:40 2001 Le Wang <lewang@bigfoot.com>
* misc/ruby-mode.el (ruby-font-lock-syntactic-keywords):
fix font-lock problem [ruby-talk:29296].
Sat Dec 22 22:52:14 2001 Yukihiro Matsumoto <matz@ruby-lang.org> Sat Dec 22 22:52:14 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* time.c (time_timeval): wrong cast to time_t. * time.c (time_timeval): wrong cast to time_t.

View File

@ -253,6 +253,21 @@ The variable ruby-indent-level controls the amount of indentation.
(and (not (eq option 'expr-arg)) (and (not (eq option 'expr-arg))
(looking-at "[a-zA-Z][a-zA-z0-9_]* +/[^ \t]")))))))))) (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) (defun ruby-parse-region (start end)
(let ((indent-point end) (let ((indent-point end)
(indent 0) (indent 0)
@ -270,16 +285,22 @@ The variable ruby-indent-level controls the amount of indentation.
(while (and (> indent-point (point)) (while (and (> indent-point (point))
(re-search-forward ruby-delimiter indent-point t)) (re-search-forward ruby-delimiter indent-point t))
(or depth (setq depth 0)) (or depth (setq depth 0))
(let ((pnt (point)) w re) (let ((pnt (point)) w re expand)
(goto-char (match-beginning 0)) (goto-char (match-beginning 0))
(cond (cond
((or (looking-at "\"") ;skip string ((or (looking-at "\"") ;skip string
(looking-at "'")
(looking-at "`")) (looking-at "`"))
(setq w (char-after (point)))
(cond (cond
((and (not (eobp)) ((and (not (eobp))
(re-search-forward (format "[^\\]\\(\\\\\\\\\\)*%c" w) indent-point t)) (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 "[^\\]\\(\\\\\\\\\\)*'" indent-point t))
nil) nil)
(t (t
(setq in-string (point)) (setq in-string (point))
@ -287,7 +308,7 @@ The variable ruby-indent-level controls the amount of indentation.
((looking-at "/") ((looking-at "/")
(cond (cond
((and (not (eobp)) (ruby-expr-beg)) ((and (not (eobp)) (ruby-expr-beg))
(if (re-search-forward "[^\\]\\(\\\\\\\\\\)*/" indent-point t) (if (ruby-forward-string "/" indent-point t t)
nil nil
(setq in-string (point)) (setq in-string (point))
(goto-char indent-point))) (goto-char indent-point)))
@ -299,6 +320,7 @@ The variable ruby-indent-level controls the amount of indentation.
(not (looking-at "%=")) (not (looking-at "%="))
(looking-at "%[Qqrxw]?\\(.\\)")) (looking-at "%[Qqrxw]?\\(.\\)"))
(goto-char (match-beginning 1)) (goto-char (match-beginning 1))
(setq expand (not (eq (char-before) ?q)))
(setq w (buffer-substring (match-beginning 1) (setq w (buffer-substring (match-beginning 1)
(match-end 1))) (match-end 1)))
(cond (cond
@ -306,24 +328,16 @@ The variable ruby-indent-level controls the amount of indentation.
((string= w "{") (setq re "}{")) ((string= w "{") (setq re "}{"))
((string= w "(") (setq re ")(")) ((string= w "(") (setq re ")("))
((string= w "<") (setq re "><")) ((string= w "<") (setq re "><"))
((member w '("*" "." "+" "?" "^" "$")) ((or (and expand (string= w "\\"))
(member w '("*" "." "+" "?" "^" "$")))
(setq w (concat "\\" w)))) (setq w (concat "\\" w))))
(if (if re (unless (cond (re (ruby-forward-string re indent-point t expand))
(let ((n 1)) (expand (ruby-forward-string w indent-point t t))
(setq re (concat "[^\\]\\(\\\\\\\\\\)*[" re "]")) (t (re-search-forward
(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
(if (string= w "\\") (if (string= w "\\")
"\\\\[^\\]*\\\\" "\\\\[^\\]*\\\\"
(concat "[^\\]\\(\\\\\\\\\\)*" w)) (concat "[^\\]\\(\\\\\\\\\\)*" w))
indent-point t)) indent-point t)))
nil
(setq in-string (point)) (setq in-string (point))
(goto-char indent-point))) (goto-char indent-point)))
(t (t
@ -528,19 +542,11 @@ The variable ruby-indent-level controls the amount of indentation.
(end-of-line) (end-of-line)
(skip-chars-backward " \t") (skip-chars-backward " \t")
(let ((pos (point))) (let ((pos (point)))
(and (while (and (re-search-backward "#" bol t)
(re-search-backward "#" (save-excursion (= (char-before) ??))
(beginning-of-line) (forward-char -1))
(point)) t)
(if (not (= (point) (point-min)))
(save-excursion
(forward-char -1)
(not (looking-at "\\?"))))
(skip-chars-backward " \t") (skip-chars-backward " \t")
(if (save-excursion (and
(forward-char -1)
(looking-at "\\?"))
(skip-chars-forward " \t"))
(setq state (ruby-parse-region parse-start (point))) (setq state (ruby-parse-region parse-start (point)))
(nth 0 state) (nth 0 state)
(goto-char pos))) (goto-char pos)))
@ -681,10 +687,6 @@ An end of a defun is found by moving forward from the beginning of one."
(or (boundp 'font-lock-variable-name-face) (or (boundp 'font-lock-variable-name-face)
(setq font-lock-variable-name-face font-lock-type-face)) (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 (setq ruby-font-lock-syntactic-keywords
'( '(
;; #{ }, #$hoge, #@foo are not comments ;; #{ }, #$hoge, #@foo are not comments
@ -717,9 +719,13 @@ An end of a defun is found by moving forward from the beginning of one."
(4 (7 . nil))) (4 (7 . nil)))
("^\\(=\\)begin\\(\\s \\|$\\)" 1 (7 . nil)) ("^\\(=\\)begin\\(\\s \\|$\\)" 1 (7 . nil))
("^\\(=\\)end\\(\\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)) (put 'ruby-mode 'font-lock-defaults
(setq font-lock-keywords ruby-font-lock-keywords))) '((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) (defun ruby-font-lock-docs (limit)
(if (re-search-forward "^=begin\\(\\s \\|$\\)" limit t) (if (re-search-forward "^=begin\\(\\s \\|$\\)" limit t)