From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Masatake YAMATO Newsgroups: gmane.emacs.devel Subject: C preprocessor directives in asm-mode and ld-script-mode Date: Sat, 12 Nov 2005 13:45:24 +0900 (JST) Message-ID: <20051112.134524.155831738.jet@gyve.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1131770755 13427 80.91.229.2 (12 Nov 2005 04:45:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 12 Nov 2005 04:45:55 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Nov 12 05:45:54 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EanGm-0006Sb-Ju for ged-emacs-devel@m.gmane.org; Sat, 12 Nov 2005 05:45:41 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EanGm-0007uQ-1u for ged-emacs-devel@m.gmane.org; Fri, 11 Nov 2005 23:45:40 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EanGV-0007sT-FZ for emacs-devel@gnu.org; Fri, 11 Nov 2005 23:45:23 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EanGU-0007sB-Iq for emacs-devel@gnu.org; Fri, 11 Nov 2005 23:45:23 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EanGU-0007s6-FW for emacs-devel@gnu.org; Fri, 11 Nov 2005 23:45:22 -0500 Original-Received: from [210.130.136.40] (helo=r-maa.spacetown.ne.jp) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EanGU-0001Co-9W for emacs-devel@gnu.org; Fri, 11 Nov 2005 23:45:22 -0500 Original-Received: from localhost (h219-110-074-001.catv01.itscom.jp [219.110.74.1]) by r-maa.spacetown.ne.jp (8.11.6) with ESMTP id jAC4jKL06080 for ; Sat, 12 Nov 2005 13:45:20 +0900 (JST) Original-To: emacs-devel@gnu.org X-Mailer: Mew version 4.2.53 on Emacs 22.0.51 / Mule 5.0 (SAKAKI) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:45800 Archived-At: Hi, In order to fontificate C preprocessor directives well in asm-mode and ld-script-mode, I'd like to make c-font-lock-keywords-1 in GNU Emacs 21.2 revive as `cpp-font-lock-keywords'. `cpp-font-lock-keywords' may be handy to implement a new mode in which C preprocessor directives is used. Mode for Imakefile is one of such modes. Masatake YAMATO 2005-11-12 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. Index: lisp/progmodes/ld-script.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/ld-script.el,v retrieving revision 1.8 diff -u -r1.8 ld-script.el --- lisp/progmodes/ld-script.el 1 Nov 2005 15:45:32 -0000 1.8 +++ lisp/progmodes/ld-script.el 12 Nov 2005 04:26:03 -0000 @@ -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 '("\\.lds?\\>" . ld-script-mode)) ;;;###autoload (define-derived-mode ld-script-mode nil "LD-Script" Index: lisp/progmodes/asm-mode.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/asm-mode.el,v retrieving revision 1.33 diff -u -r1.33 asm-mode.el --- lisp/progmodes/asm-mode.el 1 Aug 2005 08:37:49 -0000 1.33 +++ lisp/progmodes/asm-mode.el 12 Nov 2005 04:26:03 -0000 @@ -82,19 +82,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 () Index: lisp/font-lock.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/font-lock.el,v retrieving revision 1.282 diff -u -r1.282 font-lock.el --- lisp/font-lock.el 5 Nov 2005 07:29:45 -0000 1.282 +++ lisp/font-lock.el 12 Nov 2005 04:26:03 -0000 @@ -1956,6 +1956,58 @@ (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. +(defconst cpp-font-lock-keywords + (let* ((cpp-directives + (eval-when-compile + (regexp-opt + '("define" "elif" "else" "endif" "error" "file" "if" "ifdef" + "ifndef" "include" "line" "pragma" "undef")))) + (cpp-directives-depth + (regexp-opt-depth cpp-directives))) + (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]*\\(?:" cpp-directives + "\\)\\)\\>[ \t!]*\\([[:alpha:]_][[:alnum:]_]*\\)?") + '(1 font-lock-preprocessor-face prepend) + (list (+ 2 cpp-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.