all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: [jet@gyve.org: Re: C preprocessor directives in asm-mode and ld-script-mode]
       [not found] <E1EukO5-0005tQ-Vs@fencepost.gnu.org>
@ 2006-01-06 13:39 ` Eli Zaretskii
  2006-01-06 17:12   ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2006-01-06 13:39 UTC (permalink / raw)
  Cc: bug-cc-mode, emacs-devel, rms

> Date: Fri, 06 Jan 2006 04:00:06 +0900 (JST)
> To: rms@gnu.org
> Cc: bug-cc-mode@gnu.org, emacs-devel@gnu.org
> Subject: Re: C preprocessor directives in asm-mode and ld-script-mode
> From: Masatake YAMATO <jet@gyve.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.

Unfortunately, I couldn't install this: your definition of
cpp-font-lock-keywords in font-lock.el causes regex-opt to be loaded,
and that in turn triggers an error message from eval.c:do_autoload,
like this:

    Loading font-lock...
    Attempt to autoload regexp-opt-depth while preparing to dump

because regex-opt is not preloaded.  This breaks the build of Emacs,
since font-lock is now preloaded in loadup.el.

So I think you need to slightly change your code to defer the calls to
regex-opt to run time.


-------------------------------------------------------
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [jet@gyve.org: Re: C preprocessor directives in asm-mode and ld-script-mode]
  2006-01-06 13:39 ` [jet@gyve.org: Re: C preprocessor directives in asm-mode and ld-script-mode] Eli Zaretskii
@ 2006-01-06 17:12   ` Stefan Monnier
  2006-01-06 20:49     ` Masatake YAMATO
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2006-01-06 17:12 UTC (permalink / raw)
  Cc: Masatake YAMATO, bug-cc-mode, rms, emacs-devel

> So I think you need to slightly change your code to defer the calls to
> regex-opt to run time.

Or move it to compile-time.


        Stefan


-------------------------------------------------------
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [jet@gyve.org: Re: C preprocessor directives in asm-mode and ld-script-mode]
  2006-01-06 17:12   ` Stefan Monnier
@ 2006-01-06 20:49     ` Masatake YAMATO
  0 siblings, 0 replies; 3+ messages in thread
From: Masatake YAMATO @ 2006-01-06 20:49 UTC (permalink / raw)
  Cc: eliz, bug-cc-mode, rms, emacs-devel

> > So I think you need to slightly change your code to defer the calls to
> > regex-opt to run time.
> 
> Or move it to compile-time.

I cannot image `compile-time'. 
What kind of technique can I use?
eval-when-compile may not be suitable here.
I have modified the code to use pre-calculated value.

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.

	* progmodes/ld-script.el (auto-mode-alist): Use \\> instead
	of $ for "\\.ld[s]?". 


Index: lisp/progmodes/ld-script.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/progmodes/ld-script.el,v
retrieving revision 1.9
diff -u -r1.9 ld-script.el
--- lisp/progmodes/ld-script.el	6 Jan 2006 13:55:16 -0000	1.9
+++ lisp/progmodes/ld-script.el	6 Jan 2006 18:10:34 -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 '("\\.ld[s]?\\>" . ld-script-mode))
 ;;;###autoload
 (add-to-list 'auto-mode-alist '("\\.x[bdsru]?[cn]?$" . ld-script-mode))
 
Index: lisp/progmodes/asm-mode.el
===================================================================
RCS file: /sources/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	6 Jan 2006 18:10:34 -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: /sources/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	6 Jan 2006 18:10:35 -0000
@@ -1963,6 +1963,77 @@
 	      (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"))
+;;
+;; `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-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'.")
+(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'.")
+
 \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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-01-06 20:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <E1EukO5-0005tQ-Vs@fencepost.gnu.org>
2006-01-06 13:39 ` [jet@gyve.org: Re: C preprocessor directives in asm-mode and ld-script-mode] Eli Zaretskii
2006-01-06 17:12   ` Stefan Monnier
2006-01-06 20:49     ` Masatake YAMATO

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.