Skip to content

Commit e12510c

Browse files
author
matz
committed
do not depend on font-lock.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 01a24da commit e12510c

File tree

1 file changed

+69
-65
lines changed

1 file changed

+69
-65
lines changed

misc/ruby-mode.el

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,6 @@ The variable ruby-indent-level controls the amount of indentation.
152152
(setq mode-name "Ruby")
153153
(setq major-mode 'ruby-mode)
154154
(ruby-mode-variables)
155-
;; for font-lock
156-
(make-local-variable 'font-lock-syntactic-keywords)
157-
(setq font-lock-syntactic-keywords
158-
'(("\\$\\([#\"'`$\\]\\)" 1 (1 . nil))
159-
("\\(#\\)[{$@]" 1 (1 . nil))))
160-
(make-local-variable 'font-lock-defaults)
161-
(setq font-lock-defaults '((ruby-font-lock-keywords) nil nil))
162-
(setq font-lock-keywords ruby-font-lock-keywords)
163155

164156
(run-hooks 'ruby-mode-hook))
165157

@@ -619,43 +611,35 @@ An end of a defun is found by moving forward from the beginning of one."
619611
(re-search-backward "^\n" (- (point) 1) t))
620612

621613
(cond
622-
((featurep 'hilit19)
623-
(hilit-set-mode-patterns
624-
'ruby-mode
625-
'(("[^$\\?]\\(\"[^\\\"]*\\(\\\\\\(.\\|\n\\)[^\\\"]*\\)*\"\\)" 1 string)
626-
("[^$\\?]\\('[^\\']*\\(\\\\\\(.\\|\n\\)[^\\']*\\)*'\\)" 1 string)
627-
("[^$\\?]\\(`[^\\`]*\\(\\\\\\(.\\|\n\\)[^\\`]*\\)*`\\)" 1 string)
628-
("^\\s *#.*$" nil comment)
629-
("[^$@?\\]\\(#[^$@{\n].*$\\)" 1 comment)
630-
("[^a-zA-Z_]\\(\\?\\(\\\\[CM]-\\)*.\\)" 1 string)
631-
("^\\s *\\(require\\|load\\).*$" nil include)
632-
("^\\s *\\(include\\|alias\\|undef\\).*$" nil decl)
633-
("^\\s *\\<\\(class\\|def\\|module\\)\\>" "[)\n;]" defun)
634-
("[^_]\\<\\(begin\\|case\\|else\\|elsif\\|end\\|ensure\\|for\\|if\\|unless\\|rescue\\|then\\|when\\|while\\|until\\|do\\)\\>[^_]" 1 defun)
635-
("[^_]\\<\\(and\\|break\\|next\\|raise\\|fail\\|in\\|not\\|or\\|redo\\|retry\\|return\\|super\\|yield\\|catch\\|throw\\|self\\|nil\\)\\>[^_]" 1 keyword)
636-
("\\$\\(.\\|\\sw+\\)" nil type)
637-
("[$@].[a-zA-Z_0-9]*" nil struct)
638-
("^__END__" nil label))))
639-
)
640-
641-
(or (boundp 'font-lock-variable-name-face)
642-
(setq font-lock-variable-name-face font-lock-type-face))
643-
644-
(defun ruby-font-lock-docs (limit)
645-
(if (re-search-forward "^=begin\\s *" limit t)
646-
(let (beg)
647-
(beginning-of-line)
648-
(setq beg (point))
649-
(forward-line 1)
650-
(if (re-search-forward "^=end\\s *" limit t)
651-
(progn
652-
(set-match-data (list beg (point)))
653-
t)))))
654-
655-
(defvar ruby-font-lock-keywords
656-
(list
657-
(cons (concat
658-
"\\(^\\|[^_:.]\\|\\.\\.\\)\\b\\("
614+
((featurep 'font-lock)
615+
(or (boundp 'font-lock-variable-name-face)
616+
(setq font-lock-variable-name-face font-lock-type-face))
617+
618+
(add-hook 'ruby-mode-hook
619+
'(lambda ()
620+
(make-local-variable 'font-lock-syntactic-keywords)
621+
(setq font-lock-syntactic-keywords
622+
'(("\\$\\([#\"'`$\\]\\)" 1 (1 . nil))
623+
("\\(#\\)[{$@]" 1 (1 . nil))))
624+
(make-local-variable 'font-lock-defaults)
625+
(setq font-lock-defaults '((ruby-font-lock-keywords) nil nil))
626+
(setq font-lock-keywords ruby-font-lock-keywords)))
627+
628+
(defun ruby-font-lock-docs (limit)
629+
(if (re-search-forward "^=begin\\s *$" limit t)
630+
(let (beg)
631+
(beginning-of-line)
632+
(setq beg (point))
633+
(forward-line 1)
634+
(if (re-search-forward "^=end\\s *$" limit t)
635+
(progn
636+
(set-match-data (list beg (point)))
637+
t)))))
638+
639+
(defvar ruby-font-lock-keywords
640+
(list
641+
(cons (concat
642+
"\\(^\\|[^_:.]\\|\\.\\.\\)\\b\\("
659643
(mapconcat
660644
'identity
661645
'("alias"
@@ -696,25 +680,45 @@ An end of a defun is found by moving forward from the beginning of one."
696680
)
697681
"\\|")
698682
"\\)\\b")
699-
2)
700-
;; variables
701-
'("\\b\\(nil\\|self\\|true\\|false\\)\\b"
702-
1 font-lock-variable-name-face)
703-
;; variables
704-
'("[$@].\\(\\w\\|_\\)*"
705-
0 font-lock-variable-name-face)
706-
;; embedded document
707-
'(ruby-font-lock-docs
708-
0 font-lock-comment-face t)
709-
;; constants
710-
'("\\(^\\|[^_]\\)\\b\\([A-Z]+\\(\\w\\|_\\)*\\)"
711-
2 font-lock-type-face)
712-
;; functions
713-
'("^\\s *def\\s *\\<\\(\\(\\w\\|_\\)+\\(\\.\\|::\\)\\)?\\(\\(\\w\\|_\\)+\\??\\)\\>"
714-
4 font-lock-function-name-face t)
715-
;; symbols
716-
'("\\(^\\|[^:]\\)\\(:\\(\\w\\|_\\)+\\??\\)\\b"
717-
2 font-lock-reference-face t))
718-
"*Additional expressions to highlight in ruby mode.")
683+
2)
684+
;; variables
685+
'("\\b\\(nil\\|self\\|true\\|false\\)\\b"
686+
1 font-lock-variable-name-face)
687+
;; variables
688+
'("[$@].\\(\\w\\|_\\)*"
689+
0 font-lock-variable-name-face)
690+
;; embedded document
691+
'(ruby-font-lock-docs
692+
0 font-lock-comment-face t)
693+
;; constants
694+
'("\\(^\\|[^_]\\)\\b\\([A-Z]+\\(\\w\\|_\\)*\\)"
695+
2 font-lock-type-face)
696+
;; functions
697+
'("^\\s *def\\s *\\<\\(\\(\\w\\|_\\)+\\(\\.\\|::\\)\\)?\\(\\(\\w\\|_\\)+\\??\\)\\>"
698+
4 font-lock-function-name-face t)
699+
;; symbols
700+
'("\\(^\\|[^:]\\)\\(:\\(\\w\\|_\\)+\\??\\)\\b"
701+
2 font-lock-reference-face))
702+
"*Additional expressions to highlight in ruby mode."))
703+
704+
((featurep 'hilit19)
705+
(hilit-set-mode-patterns
706+
'ruby-mode
707+
'(("[^$\\?]\\(\"[^\\\"]*\\(\\\\\\(.\\|\n\\)[^\\\"]*\\)*\"\\)" 1 string)
708+
("[^$\\?]\\('[^\\']*\\(\\\\\\(.\\|\n\\)[^\\']*\\)*'\\)" 1 string)
709+
("[^$\\?]\\(`[^\\`]*\\(\\\\\\(.\\|\n\\)[^\\`]*\\)*`\\)" 1 string)
710+
("^\\s *#.*$" nil comment)
711+
("[^$@?\\]\\(#[^$@{\n].*$\\)" 1 comment)
712+
("[^a-zA-Z_]\\(\\?\\(\\\\[CM]-\\)*.\\)" 1 string)
713+
("^\\s *\\(require\\|load\\).*$" nil include)
714+
("^\\s *\\(include\\|alias\\|undef\\).*$" nil decl)
715+
("^\\s *\\<\\(class\\|def\\|module\\)\\>" "[)\n;]" defun)
716+
("[^_]\\<\\(begin\\|case\\|else\\|elsif\\|end\\|ensure\\|for\\|if\\|unless\\|rescue\\|then\\|when\\|while\\|until\\|do\\)\\>[^_]" 1 defun)
717+
("[^_]\\<\\(and\\|break\\|next\\|raise\\|fail\\|in\\|not\\|or\\|redo\\|retry\\|return\\|super\\|yield\\|catch\\|throw\\|self\\|nil\\)\\>[^_]" 1 keyword)
718+
("\\$\\(.\\|\\sw+\\)" nil type)
719+
("[$@].[a-zA-Z_0-9]*" nil struct)
720+
("^__END__" nil label))))
721+
)
722+
719723

720724
(provide 'ruby-mode)

0 commit comments

Comments
 (0)