4
|
1 ;;; m4-mode.el --- m4 code editing commands for Emacs
|
|
2
|
|
3 ;; Author: Andrew Csillag (drew@staff.prodigy.com)
|
|
4 ;; Maintainer: Andrew Csillag (drew@staff.prodigy.com)
|
|
5 ;; Keywords: languages, faces
|
|
6
|
|
7 ;; This file is (not yet) part of GNU Emacs.
|
|
8
|
|
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
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 ;; GNU General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Commentary:
|
|
25
|
|
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).
|
|
28 ;; It also sets the font-lock syntax stuff for colorization
|
|
29
|
|
30 ;; By Drew Csillag (drew@staff.prodigy.com)
|
16
|
31 ;; $Id: m4-mode.el,v 1.2 1997/02/02 05:05:40 steve Exp $
|
4
|
32
|
|
33 ;; History:
|
|
34
|
|
35 ;; Date Version Who Action
|
|
36 ;; -------- ------- --- ----
|
|
37 ;; 09/13/96 1.0 DC Created
|
|
38 ;; 09/26/96 1.1 DC added syntax table stuff so now matches `'s
|
|
39 ;; now can use C-c C-b to m4 on buffer,C-c C-r for region
|
|
40 ;; added m4-comment-region (C-c C-c)
|
|
41 ;; 09/27/96 1.2 DC Redid header comment
|
|
42 ;; 1.3 DC more cosmetic fixes
|
|
43 ;; 1.4 DC removed m4-comment-region, using comment-region instead
|
|
44 ;; 10/03/96 DC added provide line
|
|
45 ;; 10/24/96 1.5 DC fixed keyword regexp
|
|
46 ;; 10/29/96 1.6 DC added m4_keywords for --prefix-builtins
|
|
47 ;; fixed syntax table so _define_ isn't keywordified
|
|
48 ;; 10/29/96 1.8 DC fixed a problem where comments go fontified incorrectly
|
|
49 ;; if they had quotes in them
|
|
50 ;; To Do's:
|
|
51
|
|
52 ;; * 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
|
|
54
|
|
55 ;; to autoload m4 lisp code:
|
|
56 ;; (autoload 'm4-mode "m4-mode" nil t)
|
|
57 ;;
|
|
58 ;; or can use (load "m4-mode") or (require 'm4-mode) to just load it
|
|
59 ;;
|
|
60 ;; to try to "auto-detect" m4 files:
|
|
61 ;; (setq auto-mode-alist
|
|
62 ;; (cons '(".*\\.m4$" . m4-mode)
|
|
63 ;; auto-mode-alist))
|
|
64
|
|
65
|
|
66 ;;; Thanks:
|
|
67 ;;; to Akim Demaille and Terry Jones for the bug reports
|
|
68
|
|
69 ;;; Code:
|
|
70
|
|
71 ;;path to the m4 program
|
16
|
72 (defvar m4-program "/usr/bin/m4")
|
4
|
73
|
|
74 ;;thank god for make-regexp.el!
|
|
75 (defvar m4-font-lock-keywords
|
|
76 `(
|
|
77 ("^\\\#.*" . font-lock-comment-face)
|
|
78 ("\\\$\\\*" . font-lock-variable-name-face)
|
|
79 ("\\\$[0-9]" . font-lock-variable-name-face)
|
|
80 ("\\\$\\\#" . font-lock-variable-name-face)
|
|
81 ("\\\$\\\@" . font-lock-variable-name-face)
|
|
82 ("\\\$\\\*" . font-lock-variable-name-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)
|
|
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)
|
|
85 "default font-lock-keywords")
|
|
86 )
|
|
87
|
|
88 ;;this may still need some work
|
|
89 (defvar m4-mode-syntax-table nil
|
|
90 "syntax table used in m4 mode")
|
|
91 (setq m4-mode-syntax-table (make-syntax-table))
|
|
92 (modify-syntax-entry ?` "('" m4-mode-syntax-table)
|
|
93 (modify-syntax-entry ?' ")`" m4-mode-syntax-table)
|
|
94 (modify-syntax-entry ?# "<\n" m4-mode-syntax-table)
|
|
95 (modify-syntax-entry ?\n ">#" m4-mode-syntax-table)
|
|
96 (modify-syntax-entry ?{ "_" m4-mode-syntax-table)
|
|
97 (modify-syntax-entry ?} "_" m4-mode-syntax-table)
|
|
98 (modify-syntax-entry ?* "w" m4-mode-syntax-table)
|
|
99 (modify-syntax-entry ?_ "w" m4-mode-syntax-table)
|
|
100 (modify-syntax-entry ?\" "w" m4-mode-syntax-table)
|
|
101
|
|
102 (defvar m4-mode-map
|
|
103 (let ((map (make-sparse-keymap)))
|
|
104 (define-key map "\C-c\C-b" 'm4-m4-buffer)
|
|
105 (define-key map "\C-c\C-r" 'm4-m4-region)
|
|
106 (define-key map "\C-c\C-c" 'comment-region)
|
|
107 map))
|
|
108
|
|
109 (defun m4-m4-buffer ()
|
|
110 "send contents of the current buffer to m4"
|
|
111 (interactive)
|
|
112 (start-process "m4process" "*m4 output*" m4-program "-e")
|
|
113 (process-send-region "m4process" (point-min) (point-max))
|
|
114 (process-send-eof "m4process")
|
|
115 (switch-to-buffer "*m4 output*")
|
|
116 )
|
|
117
|
|
118 (defun m4-m4-region ()
|
|
119 "send contents of the current region to m4"
|
|
120 (interactive)
|
|
121 (start-process "m4process" "*m4 output*" m4-program "-e")
|
|
122 (process-send-region "m4process" (point) (mark))
|
|
123 (process-send-eof "m4process")
|
|
124 (switch-to-buffer "*m4 output*")
|
|
125 )
|
|
126
|
|
127 ;;;###autoload
|
|
128 (defun m4-mode ()
|
|
129 "A major-mode to edit m4 macro files
|
|
130 \\{m4-mode-map}
|
|
131 "
|
|
132 (interactive)
|
|
133 (kill-all-local-variables)
|
|
134 (use-local-map m4-mode-map)
|
|
135
|
|
136 (make-local-variable 'comment-start)
|
|
137 (setq comment-start "#")
|
|
138 (make-local-variable 'parse-sexp-ignore-comments)
|
|
139 (setq parse-sexp-ignore-comments t)
|
|
140
|
|
141
|
|
142 (make-local-variable 'font-lock-defaults)
|
|
143 (setq major-mode 'm4-mode
|
|
144 mode-name "m4"
|
|
145 font-lock-defaults `(m4-font-lock-keywords nil)
|
|
146 )
|
|
147 (set-syntax-table m4-mode-syntax-table)
|
|
148 (run-hooks 'm4-mode-hook))
|
|
149
|
|
150 (provide 'm4-mode)
|
|
151 ;;stuff to play with for debugging
|
|
152 ;(char-to-string (char-syntax ?`))
|
|
153
|
|
154 ;;;how I generate the nasty looking regexps at the top
|
|
155 ;;;(make-regexp '("builtin" "changecom" "changequote" "changeword" "debugfile"
|
|
156 ;;; "debugmode" "decr" "define" "defn" "divert" "divnum" "dnl"
|
|
157 ;;; "dumpdef" "errprint" "esyscmd" "eval" "file" "format" "gnu"
|
|
158 ;;; "ifdef" "ifelse" "include" "incr" "index" "indir" "len" "line"
|
|
159 ;;; "m4exit" "m4wrap" "maketemp" "patsubst" "popdef" "pushdef" "regexp"
|
|
160 ;;; "shift" "sinclude" "substr" "syscmd" "sysval" "traceoff" "traceon"
|
|
161 ;;; "translit" "undefine" "undivert" "unix"))
|
|
162 ;;;(make-regexp '("m4_builtin" "m4_changecom" "m4_changequote" "m4_changeword"
|
|
163 ;;; "m4_debugfile" "m4_debugmode" "m4_decr" "m4_define" "m4_defn"
|
|
164 ;;; "m4_divert" "m4_divnum" "m4_dnl" "m4_dumpdef" "m4_errprint"
|
|
165 ;;; "m4_esyscmd" "m4_eval" "m4_file" "m4_format" "m4_ifdef" "m4_ifelse"
|
|
166 ;;; "m4_include" "m4_incr" "m4_index" "m4_indir" "m4_len" "m4_line"
|
|
167 ;;; "m4_m4exit" "m4_m4wrap" "m4_maketemp" "m4_patsubst" "m4_popdef"
|
|
168 ;;; "m4_pushdef" "m4_regexp" "m4_shift" "m4_sinclude" "m4_substr"
|
|
169 ;;; "m4_syscmd" "m4_sysval" "m4_traceoff" "m4_traceon" "m4_translit"
|
|
170 ;;; "m4_m4_undefine" "m4_undivert"))
|