diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-01-05 03:25:02 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-01-05 03:25:02 +0000 |
commit | a9363eab32f18b4ce8767c5962453299d3aceace (patch) | |
tree | 7c9f8d78d6508d3295bf53d8eae5d408e825accc | |
parent | 9cb9c5f7bda3865694adc936c0205e4cb4290e3e (diff) |
* 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/branches/ruby_1_6@1965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | misc/ruby-mode.el | 159 |
2 files changed, 102 insertions, 71 deletions
@@ -2,6 +2,15 @@ Sat Jan 5 00:19:12 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp> * parse.y (yycompile): strdup()'ed twice. +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. + Wed Jan 2 23:34:25 2002 WATANABE Hirofumi <eban@ruby-lang.org> * lib/mkmf.rb (create_makefile): add -I. to CPPFLAGS. @@ -61,6 +70,11 @@ Tue Dec 25 18:32:16 2001 K.Kosako <kosako@sofnec.co.jp> * re.c (rb_reg_search): initialize taint status of match object. +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]. + Fri Dec 21 20:33:34 2001 K.Kosako <kosako@sofnec.co.jp> * parse.y (str_extend): make up "#$;" handling. diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el index b03a1c92c3..a118a49587 100644 --- a/misc/ruby-mode.el +++ b/misc/ruby-mode.el @@ -253,6 +253,21 @@ The variable ruby-indent-level controls the amount of indentation. (and (not (eq option 'expr-arg)) (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) (indent 0) @@ -270,16 +285,22 @@ The variable ruby-indent-level controls the amount of indentation. (while (and (> indent-point (point)) (re-search-forward ruby-delimiter indent-point t)) (or depth (setq depth 0)) - (let ((pnt (point)) w) + (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)) - (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) (t (setq in-string (point)) @@ -287,7 +308,7 @@ The variable ruby-indent-level controls the amount of indentation. ((looking-at "/") (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)) (goto-char indent-point))) @@ -299,21 +320,24 @@ The variable ruby-indent-level controls the amount of indentation. (not (looking-at "%=")) (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))) (cond - ((string= w "[") (setq w "\\]")) - ((string= w "{") (setq w "}")) - ((string= w "(") (setq w ")")) - ((string= w "<") (setq w ">")) - ((member w '("*" "." "+" "?" "^" "$")) + ((string= w "[") (setq re "][")) + ((string= w "{") (setq re "}{")) + ((string= w "(") (setq re ")(")) + ((string= w "<") (setq re "><")) + ((or (and expand (string= w "\\")) + (member w '("*" "." "+" "?" "^" "$"))) (setq w (concat "\\" w)))) - (if (re-search-forward - (if (string= w "\\") - "\\\\[^\\]*\\\\" - (concat "[^\\]\\(\\\\\\\\\\)*" w)) - indent-point t) - nil + (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))) (setq in-string (point)) (goto-char indent-point))) (t @@ -452,7 +476,7 @@ The variable ruby-indent-level controls the amount of indentation. (goto-char (cdr (nth 1 s))) (forward-word -1) (setq indent (ruby-indent-size (current-column) (nth 2 state)))) - (t + (t (setq indent (current-column))))) (cond ((nth 3 state) @@ -462,7 +486,7 @@ The variable ruby-indent-level controls the amount of indentation. (goto-char parse-start) (back-to-indentation) (setq indent (ruby-indent-size (current-column) (nth 2 state))))) - )) + )) ((and (nth 2 state)(> (nth 2 state) 0)) ; in nest (if (null (cdr (nth 1 state))) (error "invalid nest")) @@ -490,7 +514,7 @@ The variable ruby-indent-level controls the amount of indentation. (end-of-line) (setq eol (point)) (beginning-of-line) - (cond + (cond ((re-search-forward ruby-negative eol t) (and (not (eq ?_ (char-after (match-end 0)))) (setq indent (- indent ruby-indent-level)))) @@ -518,18 +542,11 @@ The variable ruby-indent-level controls the amount of indentation. (end-of-line) (skip-chars-backward " \t") (let ((pos (point))) - (and - (re-search-backward "#" (save-excursion - (beginning-of-line) - (point)) t) - (save-excursion - (forward-char -1) - (not (looking-at "\\?"))) - (skip-chars-backward " \t") - (if (save-excursion - (forward-char -1) - (looking-at "\\?")) - (skip-chars-forward " \t")) + (while (and (re-search-backward "#" bol t) + (= (char-before) ??)) + (forward-char -1)) + (skip-chars-backward " \t") + (and (setq state (ruby-parse-region parse-start (point))) (nth 0 state) (goto-char pos))) @@ -670,45 +687,45 @@ An end of a defun is found by moving forward from the beginning of one." (or (boundp 'font-lock-variable-name-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 - '( - ;; #{ }, #$hoge, #@foo are not comments - ("\\(#\\)[{$@]" 1 (1 . nil)) - ;; the last $' in the string ,'...$' is not variable - ;; the last ?' in the string ,'...?' is not ascii code - ("\\(^\\|[[\\s <+(,=]\\)\\('\\)[^'\n\\\\]*\\(\\\\.[^'\n\\\\]*\\)*[?$]\\('\\)" - (2 (7 . nil)) - (4 (7 . nil))) - ;; the last $` in the string ,`...$` is not variable - ;; the last ?` in the string ,`...?` is not ascii code - ("\\(^\\|[[\\s <+(,=]\\)\\(`\\)[^`\n\\\\]*\\(\\\\.[^`\n\\\\]*\\)*[?$]\\(`\\)" - (2 (7 . nil)) - (4 (7 . nil))) - ;; the last $" in the string ,"...$" is not variable - ;; the last ?" in the string ,"...?" is not ascii code - ("\\(^\\|[[\\s <+(,=]\\)\\(\"\\)[^\"\n\\\\]*\\(\\\\.[^\"\n\\\\]*\\)*[?$]\\(\"\\)" - (2 (7 . nil)) - (4 (7 . nil))) - ;; $' $" $` .... are variables - ;; ?' ?" ?` are ascii codes - ("[?$][#\"'`]" 0 (1 . nil)) - ;; regexps - ("\\(^\\|[=(,~?:;]\\|\\(^\\|\\s \\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|g?sub!?\\|scan\\|split!?\\)\\s *\\(/\\)[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*\\(/\\)" - (4 (7 . ?/)) - (6 (7 . ?/))) - ;; %Q!...! - ("\\(^\\|[[\\s <+(,=]\\)%[xrqQ]?\\([^a-zA-Z0-9 \n]\\)[^\n\\\\]*\\(\\\\.[^\n\\\\]*\\)*\\(\\2\\)" - (2 (7 . nil)) - (4 (7 . nil))) - ("^\\(=\\)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))) + (setq ruby-font-lock-syntactic-keywords + '( + ;; #{ }, #$hoge, #@foo are not comments + ("\\(#\\)[{$@]" 1 (1 . nil)) + ;; the last $' in the string ,'...$' is not variable + ;; the last ?' in the string ,'...?' is not ascii code + ("\\(^\\|[[\\s <+(,=]\\)\\('\\)[^'\n\\\\]*\\(\\\\.[^'\n\\\\]*\\)*[?$]\\('\\)" + (2 (7 . nil)) + (4 (7 . nil))) + ;; the last $` in the string ,`...$` is not variable + ;; the last ?` in the string ,`...?` is not ascii code + ("\\(^\\|[[\\s <+(,=]\\)\\(`\\)[^`\n\\\\]*\\(\\\\.[^`\n\\\\]*\\)*[?$]\\(`\\)" + (2 (7 . nil)) + (4 (7 . nil))) + ;; the last $" in the string ,"...$" is not variable + ;; the last ?" in the string ,"...?" is not ascii code + ("\\(^\\|[[\\s <+(,=]\\)\\(\"\\)[^\"\n\\\\]*\\(\\\\.[^\"\n\\\\]*\\)*[?$]\\(\"\\)" + (2 (7 . nil)) + (4 (7 . nil))) + ;; $' $" $` .... are variables + ;; ?' ?" ?` are ascii codes + ("[?$][#\"'`]" 0 (1 . nil)) + ;; regexps + ("\\(^\\|[=(,~?:;]\\|\\(^\\|\\s \\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|g?sub!?\\|scan\\|split!?\\)\\s *\\(/\\)[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*\\(/\\)" + (4 (7 . ?/)) + (6 (7 . ?/))) + ;; %Q!...! + ("\\(^\\|[[\\s <+(,=]\\)%[xrqQ]?\\([^a-zA-Z0-9 \n]\\)[^\n\\\\]*\\(\\\\.[^\n\\\\]*\\)*\\(\\2\\)" + (2 (7 . nil)) + (4 (7 . nil))) + ("^\\(=\\)begin\\(\\s \\|$\\)" 1 (7 . nil)) + ("^\\(=\\)end\\(\\s \\|$\\)" 1 (7 . nil)))) + + (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) (if (re-search-forward "^=begin\\(\\s \\|$\\)" limit t) @@ -786,7 +803,7 @@ An end of a defun is found by moving forward from the beginning of one." 2 font-lock-variable-name-face) ;; variables '("\\(\\$\\([^a-zA-Z0-9 \n]\\|[0-9]\\)\\)\\W" - 1 font-lock-variable-name-face) + 1 font-lock-variable-name-face) '("\\(\\$\\|@\\|@@\\)\\(\\w\\(\\w\\|_\\)*\\|#{\\)" 0 font-lock-variable-name-face) ;; embedded document |