unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Masatake YAMATO <jet@gyve.org>
Cc: bug-cc-mode@gnu.org, emacs-devel@gnu.org
Subject: Re: C preprocessor directives in asm-mode and ld-script-mode
Date: Fri, 06 Jan 2006 04:00:06 +0900 (JST)	[thread overview]
Message-ID: <20060106.040006.63122971.jet@gyve.org> (raw)
In-Reply-To: <E1Es1Iv-0000ig-Vr@fencepost.gnu.org>

> Please forgive my delay in responding.
> 
>     >     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'.
> 
> I guess we should do this.  Could you send the patch
> and change log entries?

Sorry to be late. A bit busy now.

I have changed nothing since my last post.
Here, I send my patch again.


2006-01-06  Masatake YAMATO  <jet@gyve.org>

	* 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	5 Jan 2006 18:56:38 -0000
@@ -114,14 +114,15 @@
   "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
Index: lisp/progmodes/asm-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/asm-mode.el,v
retrieving revision 1.34
diff -u -r1.34 asm-mode.el
--- lisp/progmodes/asm-mode.el	17 Nov 2005 07:36:46 -0000	1.34
+++ lisp/progmodes/asm-mode.el	5 Jan 2006 18:56:38 -0000
@@ -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 ()
Index: lisp/font-lock.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/font-lock.el,v
retrieving revision 1.290
diff -u -r1.290 font-lock.el
--- lisp/font-lock.el	3 Jan 2006 17:00:35 -0000	1.290
+++ lisp/font-lock.el	5 Jan 2006 18:56:38 -0000
@@ -1963,6 +1963,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'.")
+
 \f
 ;; Lisp.
 


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click


      reply	other threads:[~2006-01-05 19:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-12  4:45 C preprocessor directives in asm-mode and ld-script-mode Masatake YAMATO
2005-11-12 21:22 ` Richard M. Stallman
2005-11-14 15:45   ` Masatake YAMATO
2005-12-29 17:11     ` Richard M. Stallman
2006-01-05 19:00       ` Masatake YAMATO [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060106.040006.63122971.jet@gyve.org \
    --to=jet@gyve.org \
    --cc=bug-cc-mode@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).