Mercurial > hg > xemacs-beta
comparison lisp/modes/m4-mode.el @ 149:538048ae2ab8 r20-3b1
Import from CVS: tag r20-3b1
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:36:16 +0200 |
parents | 6a378aca36af |
children | 59463afc5666 |
comparison
equal
deleted
inserted
replaced
148:f659db2a1f73 | 149:538048ae2ab8 |
---|---|
2 | 2 |
3 ;; Author: Andrew Csillag (drew@staff.prodigy.com) | 3 ;; Author: Andrew Csillag (drew@staff.prodigy.com) |
4 ;; Maintainer: Andrew Csillag (drew@staff.prodigy.com) | 4 ;; Maintainer: Andrew Csillag (drew@staff.prodigy.com) |
5 ;; Keywords: languages, faces | 5 ;; Keywords: languages, faces |
6 | 6 |
7 ;; This file is (not yet) part of GNU Emacs. | 7 ;; This file is part of GNU Emacs. |
8 | 8 |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | 9 ;; GNU Emacs is free software; you can redistribute it and/or modify |
10 ;; it under the terms of the GNU General Public License as published by | 10 ;; it under the terms of the GNU General Public License as published by |
11 ;; the Free Software Foundation; either version 2, or (at your option) | 11 ;; the Free Software Foundation; either version 2, or (at your option) |
12 ;; any later version. | 12 ;; any later version. |
26 ;; A smart editing mode for m4 macro definitions. It seems to have most of the | 26 ;; A smart editing mode for m4 macro definitions. It seems to have most of the |
27 ;; syntax right (sexp motion commands work, but function motion commands don't). | 27 ;; syntax right (sexp motion commands work, but function motion commands don't). |
28 ;; It also sets the font-lock syntax stuff for colorization | 28 ;; It also sets the font-lock syntax stuff for colorization |
29 | 29 |
30 ;; By Drew Csillag (drew@staff.prodigy.com) | 30 ;; By Drew Csillag (drew@staff.prodigy.com) |
31 ;; $Id: m4-mode.el,v 1.2 1997/01/23 05:29:30 steve Exp $ | 31 ;; $Id: m4-mode.el,v 1.3 1997/05/18 03:39:57 steve Exp $ |
32 | 32 |
33 ;; History: | 33 ;; History: |
34 | 34 |
35 ;; Date Version Who Action | 35 ;; Date Version Who Action |
36 ;; -------- ------- --- ---- | 36 ;; -------- ------- --- ---- |
45 ;; 10/24/96 1.5 DC fixed keyword regexp | 45 ;; 10/24/96 1.5 DC fixed keyword regexp |
46 ;; 10/29/96 1.6 DC added m4_keywords for --prefix-builtins | 46 ;; 10/29/96 1.6 DC added m4_keywords for --prefix-builtins |
47 ;; fixed syntax table so _define_ isn't keywordified | 47 ;; fixed syntax table so _define_ isn't keywordified |
48 ;; 10/29/96 1.8 DC fixed a problem where comments go fontified incorrectly | 48 ;; 10/29/96 1.8 DC fixed a problem where comments go fontified incorrectly |
49 ;; if they had quotes in them | 49 ;; if they had quotes in them |
50 ;; 11/21/96 1.9 DC collapsed 4 regexps into 1 and removed a duplicate, | |
51 ;; removed a duplicate backslash | |
52 ;; 05/16/97 1.10 DC added contributed fixes and enhancements from | |
53 ;; Martin Buchholz | |
54 ;; Can now specify options to m4 via m4-program-options | |
55 ;; Now terminates m4 processes when the buffer send | |
56 is | |
57 ;; done | |
58 ;; dnl and m4_dnl recognized as comment starters | |
59 | |
50 ;; To Do's: | 60 ;; To Do's: |
51 | 61 |
52 ;; * want to make m4-m4-(buffer|region) look sorta like M-x compile look&feel ? | 62 ;; * want to make m4-m4-(buffer|region) look sorta like M-x compile look&feel ? |
53 ;; * sexp motion commands don't seem to work right | 63 ;; * sexp motion commands don't seem to work right |
54 | 64 |
60 ;; to try to "auto-detect" m4 files: | 70 ;; to try to "auto-detect" m4 files: |
61 ;; (setq auto-mode-alist | 71 ;; (setq auto-mode-alist |
62 ;; (cons '(".*\\.m4$" . m4-mode) | 72 ;; (cons '(".*\\.m4$" . m4-mode) |
63 ;; auto-mode-alist)) | 73 ;; auto-mode-alist)) |
64 | 74 |
65 | |
66 ;;; Thanks: | 75 ;;; Thanks: |
67 ;;; to Akim Demaille and Terry Jones for the bug reports | 76 ;;; to Akim Demaille and Terry Jones for the bug reports |
77 ;;; to Simon Marshall for the regexp tip | |
78 ;;; to Martin Buchholz for some general fixes | |
68 | 79 |
69 ;;; Code: | 80 ;;; Code: |
70 | 81 |
71 ;;path to the m4 program | 82 ;;path to the m4 program |
72 (defvar m4-program "/usr/bin/m4") | 83 (defvar m4-program |
84 (cond | |
85 ((file-exists-p "/usr/local/bin/m4") "/usr/local/bin/m4") | |
86 ((file-exists-p "/usr/bin/m4") "/usr/bin/m4") | |
87 ((file-exists-p "/bin/m4") "/bin/m4") | |
88 ((file-exists-p "/usr/ccs/bin/m4") "/usr/ccs/bin/m4") | |
89 ) | |
90 ) | |
91 | |
92 ;;options to m4 | |
93 (defconst m4-program-options nil) | |
94 ;;to use --prefix-builtins, you can use | |
95 ;;(defconst m4-program-options '("-P")) | |
96 ;;or | |
97 ;;(defconst m4-program-options '("--prefix-builtins")) | |
73 | 98 |
74 ;;thank god for make-regexp.el! | 99 ;;thank god for make-regexp.el! |
75 (defvar m4-font-lock-keywords | 100 (defvar m4-font-lock-keywords |
76 `( | 101 `( |
77 ("^\\\#.*" . font-lock-comment-face) | 102 ("\\(\\bdnl\\b\\|\\bm4_dnl\\b\\|^\\#\\).*$" . |
78 ("\\\$\\\*" . font-lock-variable-name-face) | 103 font-lock-comment-face) |
79 ("\\\$[0-9]" . font-lock-variable-name-face) | 104 ("\\$[*#@0-9]" . font-lock-variable-name-face) |
80 ("\\\$\\\#" . font-lock-variable-name-face) | 105 |
81 ("\\\$\\\@" . font-lock-variable-name-face) | 106 ("\\b\\(builtin\\|change\\(com\\|quote\\|word\\)\\|d\\(e\\(bug\\(file\\|mode\\)\\|cr\\|f\\(ine\\|n\\)\\)\\|iv\\(ert\\|num\\)\\|nl\\|umpdef\\)\\|e\\(rrprint\\|syscmd\\|val\\)\\|f\\(ile\\|ormat\\)\\|gnu\\|i\\(f\\(def\\|else\\)\\|n\\(c\\(lude\\|r\\)\\|d\\(ex\\|ir\\)\\)\\)\\|l\\(en\\|ine\\)\\|m\\(4\\(exit\\|wrap\\)\\|aketemp\\)\\|p\\(atsubst\\|opdef\\|ushdef\\)\\|regexp\\|s\\(hift\\|include\\|ubstr\\|ys\\(cmd\\|val\\)\\)\\|tra\\(ceo\\(ff\\|n\\)\\|nslit\\)\\|un\\(d\\(efine\\|ivert\\)\\|ix\\)\\)\\b" |
82 ("\\\$\\\*" . font-lock-variable-name-face) | 107 . font-lock-keyword-face) |
83 ("\\b\\(builtin\\|change\\(com\\|quote\\|word\\)\\|d\\(e\\(bug\\(file\\|mode\\)\\|cr\\|f\\(ine\\|n\\)\\)\\|iv\\(ert\\|num\\)\\|nl\\|umpdef\\)\\|e\\(rrprint\\|syscmd\\|val\\)\\|f\\(ile\\|ormat\\)\\|gnu\\|i\\(f\\(def\\|else\\)\\|n\\(c\\(lude\\|r\\)\\|d\\(ex\\|ir\\)\\)\\)\\|l\\(en\\|ine\\)\\|m\\(4\\(exit\\|wrap\\)\\|aketemp\\)\\|p\\(atsubst\\|opdef\\|ushdef\\)\\|regexp\\|s\\(hift\\|include\\|ubstr\\|ys\\(cmd\\|val\\)\\)\\|tra\\(ceo\\(ff\\|n\\)\\|nslit\\)\\|un\\(d\\(efine\\|ivert\\)\\|ix\\)\\)\\b" . font-lock-keyword-face) | 108 |
84 ("\\b\\(m4_\\(builtin\\|change\\(com\\|quote\\|word\\)\\|d\\(e\\(bug\\(file\\|mode\\)\\|cr\\|f\\(ine\\|n\\)\\)\\|iv\\(ert\\|num\\)\\|nl\\|umpdef\\)\\|e\\(rrprint\\|syscmd\\|val\\)\\|f\\(ile\\|ormat\\)\\|i\\(f\\(def\\|else\\)\\|n\\(c\\(lude\\|r\\)\\|d\\(ex\\|ir\\)\\)\\)\\|l\\(en\\|ine\\)\\|m\\(4\\(_undefine\\|exit\\|wrap\\)\\|aketemp\\)\\|p\\(atsubst\\|opdef\\|ushdef\\)\\|regexp\\|s\\(hift\\|include\\|ubstr\\|ys\\(cmd\\|val\\)\\)\\|tra\\(ceo\\(ff\\|n\\)\\|nslit\\)\\|undivert\\)\\)\\b" . font-lock-keyword-face) | 109 ("\\b\\(m4_\\(builtin\\|change\\(com\\|quote\\|word\\)\\|d\\(e\\(bug\\(file\\|mode\\)\\|cr\\|f\\(ine\\|n\\)\\)\\|iv\\(ert\\|num\\)\\|nl\\|umpdef\\)\\|e\\(rrprint\\|syscmd\\|val\\)\\|f\\(ile\\|ormat\\)\\|i\\(f\\(def\\|else\\)\\|n\\(c\\(lude\\|r\\)\\|d\\(ex\\|ir\\)\\)\\)\\|l\\(en\\|ine\\)\\|m\\(4\\(_undefine\\|exit\\|wrap\\)\\|aketemp\\)\\|p\\(atsubst\\|opdef\\|ushdef\\)\\|regexp\\|s\\(hift\\|include\\|ubstr\\|ys\\(cmd\\|val\\)\\)\\|tra\\(ceo\\(ff\\|n\\)\\|nslit\\)\\|undivert\\)\\)\\b" |
110 . font-lock-keyword-face) | |
85 "default font-lock-keywords") | 111 "default font-lock-keywords") |
86 ) | 112 ) |
87 | 113 |
88 ;;this may still need some work | 114 ;;this may still need some work |
89 (defvar m4-mode-syntax-table nil | 115 (defvar m4-mode-syntax-table nil |
104 (define-key map "\C-c\C-b" 'm4-m4-buffer) | 130 (define-key map "\C-c\C-b" 'm4-m4-buffer) |
105 (define-key map "\C-c\C-r" 'm4-m4-region) | 131 (define-key map "\C-c\C-r" 'm4-m4-region) |
106 (define-key map "\C-c\C-c" 'comment-region) | 132 (define-key map "\C-c\C-c" 'comment-region) |
107 map)) | 133 map)) |
108 | 134 |
135 (defun m4-end-m4 (process event) | |
136 (cond ((equal event "kill\n") (princ "m4 process done")) | |
137 (t (princ | |
138 (format "Process: %s had the event `%s'" process event))))) | |
139 | |
140 (defun m4-start-m4 () | |
141 (eval (append (append '(start-process "m4process" "*m4 output*" | |
142 m4-program) | |
143 m4-program-options) '("-e"))) | |
144 (set-process-sentinel (get-process "m4process") 'm4-end-m4) | |
145 ) | |
146 | |
109 (defun m4-m4-buffer () | 147 (defun m4-m4-buffer () |
110 "send contents of the current buffer to m4" | 148 "send contents of the current buffer to m4" |
111 (interactive) | 149 (interactive) |
112 (start-process "m4process" "*m4 output*" m4-program "-e") | 150 (m4-start-m4) |
113 (process-send-region "m4process" (point-min) (point-max)) | 151 (process-send-region "m4process" (point-min) (point-max)) |
114 (process-send-eof "m4process") | 152 (process-send-eof "m4process") |
115 (switch-to-buffer "*m4 output*") | 153 (switch-to-buffer-other-window "*m4 output*") |
116 ) | 154 (delete-process "m4process") |
155 ) | |
156 | |
117 | 157 |
118 (defun m4-m4-region () | 158 (defun m4-m4-region () |
119 "send contents of the current region to m4" | 159 "send contents of the current region to m4" |
120 (interactive) | 160 (interactive) |
121 (start-process "m4process" "*m4 output*" m4-program "-e") | 161 (m4-start-m4) |
122 (process-send-region "m4process" (point) (mark)) | 162 (process-send-region "m4process" (point) (mark)) |
123 (process-send-eof "m4process") | 163 (process-send-eof "m4process") |
124 (switch-to-buffer "*m4 output*") | 164 (switch-to-buffer-other-window "*m4 output*") |
125 ) | 165 ) |
126 | 166 |
127 ;;;###autoload | |
128 (defun m4-mode () | 167 (defun m4-mode () |
129 "A major-mode to edit m4 macro files | 168 "A major-mode to edit m4 macro files |
130 \\{m4-mode-map} | 169 \\{m4-mode-map} |
131 " | 170 " |
132 (interactive) | 171 (interactive) |
140 | 179 |
141 | 180 |
142 (make-local-variable 'font-lock-defaults) | 181 (make-local-variable 'font-lock-defaults) |
143 (setq major-mode 'm4-mode | 182 (setq major-mode 'm4-mode |
144 mode-name "m4" | 183 mode-name "m4" |
145 font-lock-defaults `(m4-font-lock-keywords nil) | 184 font-lock-defaults '(m4-font-lock-keywords nil) |
146 ) | 185 ) |
147 (set-syntax-table m4-mode-syntax-table) | 186 (set-syntax-table m4-mode-syntax-table) |
148 (run-hooks 'm4-mode-hook)) | 187 (run-hooks 'm4-mode-hook)) |
149 | 188 |
150 (provide 'm4-mode) | 189 (provide 'm4-mode) |