From: Masatake YAMATO Date: Wed, 11 Jan 2006 14:29:44 +0000 (+0000) Subject: 2006-01-06 Masatake YAMATO X-Git-Tag: emacs-pretest-22.0.90~4799 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4076cbf66cef35e6682dbdef56eb127d0bb0fdbf;p=emacs.git 2006-01-06 Masatake YAMATO * font-lock.el (cpp-font-lock-keywords): Font lock keywords for C preprocessor forward ported from GNU Emacs 21.2. * progmodes/asm-mode.el (asm-font-lock-keywords): Use `cpp-font-lock-keywords'. * progmodes/ld-script.el (ld-script-font-lock-keywords): Ditto. * progmodes/ld-script.el (auto-mode-alist): Use \\> instead of $ for "\\.ld[s]?". --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d4876ee3d94..0e4d34248f3 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,16 @@ +2006-01-06 Masatake YAMATO + + * font-lock.el (cpp-font-lock-keywords): Font lock keywords for + C preprocessor forward ported from GNU Emacs 21.2. + + * progmodes/asm-mode.el (asm-font-lock-keywords): Use + `cpp-font-lock-keywords'. + + * progmodes/ld-script.el (ld-script-font-lock-keywords): Ditto. + + * progmodes/ld-script.el (auto-mode-alist): Use \\> instead + of $ for "\\.ld[s]?". + 2006-01-10 Stefan Monnier * progmodes/tcl.el (tcl-indent-command): Use indent-for-tab-command. diff --git a/lisp/font-lock.el b/lisp/font-lock.el index 032b8fb04f8..00394e86762 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el @@ -1963,6 +1963,78 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item." (goto-char (or (scan-sexps (point) 1) (point-max)))) (goto-char (match-end 2))) (error t))))) + +;; C preprocessor(cpp) is used outside of C, C++ and Objective-C source file. +;; e.g. assembler code and GNU linker script in Linux kernel. +;; `cpp-font-lock-keywords' is handy for modes for the files. +;; +;; Here we cannot use `regexp-opt' because because regex-opt is not preloaded +;; while font-lock.el is preloaded to emacs. So values pre-calculated with +;; regexp-opt are used here. + +;; `cpp-font-lock-keywords-source-directives' is calculated from: +;; +;; (regexp-opt +;; '("define" "elif" "else" "endif" "error" "file" "if" "ifdef" +;; "ifndef" "include" "line" "pragma" "undef")) +;; +(defconst cpp-font-lock-keywords-source-directives + "define\\|e\\(?:l\\(?:if\\|se\\)\\|ndif\\|rror\\)\\|file\\|i\\(?:f\\(?:n?def\\)?\\|nclude\\)\\|line\\|pragma\\|undef" + "Regular expressoin used in `cpp-font-lock-keywords'.") + +;; `cpp-font-lock-keywords-source-depth' is calculated from: +;; +;; (regexp-opt-depth (regexp-opt +;; '("define" "elif" "else" "endif" "error" "file" "if" "ifdef" +;; "ifndef" "include" "line" "pragma" "undef"))) +;; +(defconst cpp-font-lock-keywords-source-depth 0 + "An integer representing regular expression depth of `cpp-font-lock-keywords-source-directives'. +Used in `cpp-font-lock-keywords'.") + +(defconst cpp-font-lock-keywords + (let* ((directives cpp-font-lock-keywords-source-directives) + (directives-depth cpp-font-lock-keywords-source-depth)) + (list + ;; + ;; Fontify error directives. + '("^#[ \t]*error[ \t]+\\(.+\\)" 1 font-lock-warning-face prepend) + ;; + ;; Fontify filenames in #include <...> preprocessor directives as strings. + '("^#[ \t]*\\(?:import\\|include\\)[ \t]*\\(<[^>\"\n]*>?\\)" + 1 font-lock-string-face prepend) + ;; + ;; Fontify function macro names. + '("^#[ \t]*define[ \t]+\\([[:alpha:]_][[:alnum:]_$]*\\)(" + (1 font-lock-function-name-face prepend) + ;; + ;; Macro arguments. + ((lambda (limit) + (re-search-forward + "\\(?:\\([[:alpha:]_][[:alnum:]_]*\\)[,]?\\)" + (or (save-excursion (re-search-forward ")" limit t)) + limit) + t)) + nil nil (1 font-lock-variable-name-face prepend))) + ;; + ;; Fontify symbol names in #elif or #if ... defined preprocessor directives. + '("^#[ \t]*\\(?:elif\\|if\\)\\>" + ("\\<\\(defined\\)\\>[ \t]*(?\\([[:alpha:]_][[:alnum:]_]*\\)?" nil nil + (1 font-lock-builtin-face prepend) (2 font-lock-variable-name-face prepend t))) + ;; + ;; Fontify otherwise as symbol names, and the preprocessor directive names. + (list + (concat "^\\(#[ \t]*\\(?:" directives + "\\)\\)\\>[ \t!]*\\([[:alpha:]_][[:alnum:]_]*\\)?") + '(1 font-lock-preprocessor-face prepend) + (list (+ 2 directives-depth) + 'font-lock-variable-name-face nil t)))) + "Font lock keyords for C preprocessor directives. +`c-mode', `c++-mode' and `objc-mode' have their own +font lock keyords for C preprocessor directives. This definition is for the +other modes in which C preprocessor directives are used. e.g. `asm-mode' and +`ld-script-mode'.") + ;; Lisp. diff --git a/lisp/progmodes/asm-mode.el b/lisp/progmodes/asm-mode.el index 51d58d7c7a9..44605b1fa9a 100644 --- a/lisp/progmodes/asm-mode.el +++ b/lisp/progmodes/asm-mode.el @@ -83,19 +83,21 @@ "Keymap for Asm mode.") (defconst asm-font-lock-keywords - '(("^\\(\\(\\sw\\|\\s_\\)+\\)\\>:?[ \t]*\\(\\sw+\\(\\.\\sw+\\)*\\)?" - (1 font-lock-function-name-face) (3 font-lock-keyword-face nil t)) - ;; label started from ".". - ("^\\(\\.\\(\\sw\\|\\s_\\)+\\)\\>:" - 1 font-lock-function-name-face) - ("^\\((\\sw+)\\)?\\s +\\(\\(\\.?\\sw\\|\\s_\\)+\\(\\.\\sw+\\)*\\)" - 2 font-lock-keyword-face) - ;; directive started from ".". - ("^\\(\\.\\(\\sw\\|\\s_\\)+\\)\\>[^:]?" - 1 font-lock-keyword-face) - ;; %register - ("%\\sw+" . font-lock-variable-name-face)) - "Additional expressions to highlight in Assembler mode.") + (append + '(("^\\(\\(\\sw\\|\\s_\\)+\\)\\>:?[ \t]*\\(\\sw+\\(\\.\\sw+\\)*\\)?" + (1 font-lock-function-name-face) (3 font-lock-keyword-face nil t)) + ;; label started from ".". + ("^\\(\\.\\(\\sw\\|\\s_\\)+\\)\\>:" + 1 font-lock-function-name-face) + ("^\\((\\sw+)\\)?\\s +\\(\\(\\.?\\sw\\|\\s_\\)+\\(\\.\\sw+\\)*\\)" + 2 font-lock-keyword-face) + ;; directive started from ".". + ("^\\(\\.\\(\\sw\\|\\s_\\)+\\)\\>[^:]?" + 1 font-lock-keyword-face) + ;; %register + ("%\\sw+" . font-lock-variable-name-face)) + cpp-font-lock-keywords) + "Additional expressions to highlight in Assembler mode.") ;;;###autoload (defun asm-mode () diff --git a/lisp/progmodes/ld-script.el b/lisp/progmodes/ld-script.el index 99477b73c63..4dbbe0faa18 100644 --- a/lisp/progmodes/ld-script.el +++ b/lisp/progmodes/ld-script.el @@ -114,18 +114,19 @@ "Builtin functions of GNU ld script.") (defvar ld-script-font-lock-keywords - `((,(regexp-opt ld-script-keywords 'words) - 1 font-lock-keyword-face) - (,(regexp-opt ld-script-builtins 'words) - 1 font-lock-builtin-face) - ("/DISCARD/" . font-lock-warning-face) - ("##\\|#[^#\n]+$" . font-lock-preprocessor-face) - ("\\W\\(\\.\\)\\W" 1 ld-script-location-counter-face) - ) + (append + `((,(regexp-opt ld-script-keywords 'words) + 1 font-lock-keyword-face) + (,(regexp-opt ld-script-builtins 'words) + 1 font-lock-builtin-face) + ("/DISCARD/" . font-lock-warning-face) + ("\\W\\(\\.\\)\\W" 1 ld-script-location-counter-face) + ) + cpp-font-lock-keywords) "Default font-lock-keywords for `ld-script-mode'.") ;;;###autoload -(add-to-list 'auto-mode-alist '("\\.ld[s]?\\(\\.in\\)?$" . ld-script-mode)) +(add-to-list 'auto-mode-alist '("\\.ld[s]?\\>" . ld-script-mode)) ;;;###autoload (add-to-list 'auto-mode-alist '("\\.x[bdsru]?[cn]?$" . ld-script-mode))