From: Ulrich Kuettler Date: 2002-04-04T21:58:50+09:00 Subject: emacs font-lock --------------Boundary-00=_3ZN1HYRN5EYR9YFYED3A Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8bit Hi, the other day I tried to get to know ruby a little better. But after a while I found that ruby-mode didn't highlight those char codes quite correct. The problem occurred in lines such as tokenString << "\\" if ch == ?" or ch == ?\\ It seems as if the expressions `ruby-font-lock-syntactic-keywords' considered `\\"' not to be the end of a string. Another thing that seems strange to me is the character class at the begin of these regular expressions. I guess the `\\s' there is supposed to match whitespaces. But this doesn't seem to work: (string-match "[[\\s <+(,=]" "s") => 0 (string-match "[[\\s <+(,=]" "\\") => 0 (string-match "[[\\s <+(,=]" "\t") => nil (string-match "[[\\s <+(,=]" "\n") => nil I've tried this with GNU Emacs 20.7.1 and XEmacs 21.4.6. However, `\s' doesn't seem to work either. OK. Attached is a patch that fixes this for me. I don't know though whether it introduces new problems. The strange thing here is that I had to say `\\(\\.\\)\\|\\(\\\\\\)' to match `\.' (where `.' means any char including backslash). I didn't find a better way to express this. The other patch makes `font-lock-syntactic-keywords' work for the xemacs, too. At least for me, so you better use it with care. If you apply it you need to (setq font-lock-syntactic-keywords ruby-font-lock-syntactic-keywords) somewhere in your `ruby-mode-hook' to get xemacs to look as good as emacs. Hope you like it. :) Greetings, Uli --------------Boundary-00=_3ZN1HYRN5EYR9YFYED3A Content-Type: text/x-diff; charset="us-ascii"; name="ruby-mode.el.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ruby-mode.el.diff" --- ruby-mode.el.old Mon Feb 25 10:16:42 2002 +++ ruby-mode.el Thu Apr 4 14:08:25 2002 @@ -697,19 +697,28 @@ ("\\(#\\)[{$@]" 1 (1 . nil)) ;; the last $' in the string ,'...$' is not variable ;; the last ?' in the string ,'...?' is not ascii code - ("\\(^\\|[[\\s <+(,=]\\)\\('\\)[^'\n\\\\]*\\(\\\\.[^'\n\\\\]*\\)*[?$]\\('\\)" + ;("\\(^\\|[[\\s <+(,=]\\)\\('\\)[^'\n\\\\]*\\(\\\\.[^'\n\\\\]*\\)*[?$]\\('\\)" + ; (2 (7 . nil)) + ; (4 (7 . nil))) + ("\\(^\\|[[ <+(,=]\\)\\('\\)[^'\n\\\\]*\\(\\(\\.\\)\\|\\(\\\\\\)[^'\n\\\\]*\\)*[?$]\\('\\)" (2 (7 . nil)) - (4 (7 . nil))) + (6 (7 . nil))) ;; the last $` in the string ,`...$` is not variable ;; the last ?` in the string ,`...?` is not ascii code - ("\\(^\\|[[\\s <+(,=]\\)\\(`\\)[^`\n\\\\]*\\(\\\\.[^`\n\\\\]*\\)*[?$]\\(`\\)" + ;("\\(^\\|[[\\s <+(,=]\\)\\(`\\)[^`\n\\\\]*\\(\\\\.[^`\n\\\\]*\\)*[?$]\\(`\\)" + ; (2 (7 . nil)) + ; (4 (7 . nil))) + ("\\(^\\|[[ <+(,=]\\)\\(`\\)[^`\n\\\\]*\\(\\(\\.\\)\\|\\(\\\\\\)[^`\n\\\\]*\\)*[?$]\\(`\\)" (2 (7 . nil)) - (4 (7 . nil))) + (6 (7 . nil))) ;; the last $" in the string ,"...$" is not variable ;; the last ?" in the string ,"...?" is not ascii code - ("\\(^\\|[[\\s <+(,=]\\)\\(\"\\)[^\"\n\\\\]*\\(\\\\.[^\"\n\\\\]*\\)*[?$]\\(\"\\)" + ;("\\(^\\|[[\\s <+(,=]\\)\\(\"\\)[^\"\n\\\\]*\\(\\\\.[^\"\n\\\\]*\\)*[?$]\\(\"\\)" + ; (2 (7 . nil)) + ; (4 (7 . nil))) + ("\\(^\\|[[ <+(,=]\\)\\(\"\\)[^\"\n\\\\]*\\(\\(\\.\\)\\|\\(\\\\\\)[^\"\n\\\\]*\\)*[?$]\\(\"\\)" (2 (7 . nil)) - (4 (7 . nil))) + (6 (7 . nil))) ;; $' $" $` .... are variables ;; ?' ?" ?` are ascii codes ("[?$][#\"'`]" 0 (1 . nil)) --------------Boundary-00=_3ZN1HYRN5EYR9YFYED3A Content-Type: text/x-diff; charset="us-ascii"; name="font-lock.el.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="font-lock.el.diff" --- font-lock.el.old Thu Apr 4 00:45:29 2002 +++ font-lock.el Thu Apr 4 00:42:23 2002 @@ -1511,7 +1511,7 @@ font-lock-syntactic-keywords))) ;; If `font-lock-syntactic-keywords' is not compiled, compile it. (unless (eq (car font-lock-syntactic-keywords) t) - (setq font-lock-syntactic-keywords (font-lock-compile-keywords + (setq font-lock-syntactic-keywords (font-lock-compile-syntactic-keywords font-lock-syntactic-keywords))) ;; Get down to business. (let ((case-fold-search font-lock-keywords-case-fold-search) @@ -1681,6 +1681,15 @@ ;; is the (MATCHER HIGHLIGHT ...) shown in the variable's doc string. (let ((keywords (or keywords font-lock-keywords))) (setq font-lock-keywords + (if (eq (car-safe keywords) t) + keywords + (cons t (mapcar 'font-lock-compile-keyword keywords)))))) + +(defun font-lock-compile-syntactic-keywords (&optional keywords) + ;; Compile `font-lock-keywords' into the form (t KEYWORD ...) where KEYWORD + ;; is the (MATCHER HIGHLIGHT ...) shown in the variable's doc string. + (let ((keywords (or keywords font-lock-syntactic-keywords))) + (setq font-lock-syntactic-keywords (if (eq (car-safe keywords) t) keywords (cons t (mapcar 'font-lock-compile-keyword keywords)))))) --------------Boundary-00=_3ZN1HYRN5EYR9YFYED3A--