Commit | Line | Data |
---|---|---|
502f4699 | 1 | ;;; -*- mode: emacs-lisp; coding: utf-8 -*- |
f617db13 | 2 | ;;; |
f617db13 MW |
3 | ;;; Functions and macros for .emacs |
4 | ;;; | |
5 | ;;; (c) 2004 Mark Wooding | |
6 | ;;; | |
7 | ||
8 | ;;;----- Licensing notice --------------------------------------------------- | |
9 | ;;; | |
10 | ;;; This program is free software; you can redistribute it and/or modify | |
11 | ;;; it under the terms of the GNU General Public License as published by | |
12 | ;;; the Free Software Foundation; either version 2 of the License, or | |
13 | ;;; (at your option) any later version. | |
852cd5fb | 14 | ;;; |
f617db13 MW |
15 | ;;; This program is distributed in the hope that it will be useful, |
16 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;;; GNU General Public License for more details. | |
852cd5fb | 19 | ;;; |
f617db13 MW |
20 | ;;; You should have received a copy of the GNU General Public License |
21 | ;;; along with this program; if not, write to the Free Software Foundation, | |
22 | ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
23 | ||
c7a8da49 MW |
24 | ;;;----- Check command-line ------------------------------------------------- |
25 | ||
26 | (defvar mdw-fast-startup nil | |
27 | "Whether .emacs should optimize for rapid startup. | |
28 | This may be at the expense of cool features.") | |
29 | (let ((probe nil) (next command-line-args)) | |
c7a8da49 MW |
30 | (while next |
31 | (cond ((string= (car next) "--mdw-fast-startup") | |
32 | (setq mdw-fast-startup t) | |
33 | (if probe | |
34 | (rplacd probe (cdr next)) | |
35 | (setq command-line-args (cdr next)))) | |
36 | (t | |
37 | (setq probe next))) | |
38 | (setq next (cdr next)))) | |
39 | ||
f617db13 MW |
40 | ;;;----- Some general utilities --------------------------------------------- |
41 | ||
417dcddd MW |
42 | (eval-when-compile |
43 | (unless (fboundp 'make-regexp) | |
44 | (load "make-regexp")) | |
45 | (require 'cl)) | |
c7a8da49 MW |
46 | |
47 | (defmacro mdw-regexps (&rest list) | |
48 | "Turn a LIST of strings into a single regular expression at compile-time." | |
417dcddd | 49 | `',(make-regexp list)) |
c7a8da49 | 50 | |
f617db13 MW |
51 | ;; --- Some error trapping --- |
52 | ;; | |
53 | ;; If individual bits of this file go tits-up, we don't particularly want | |
54 | ;; the whole lot to stop right there and then, because it's bloody annoying. | |
55 | ||
56 | (defmacro trap (&rest forms) | |
57 | "Execute FORMS without allowing errors to propagate outside." | |
58 | `(condition-case err | |
59 | ,(if (cdr forms) (cons 'progn forms) (car forms)) | |
8df912e4 MW |
60 | (error (message "Error (trapped): %s in %s" |
61 | (error-message-string err) | |
62 | ',forms)))) | |
f617db13 | 63 | |
f141fe0f MW |
64 | ;; --- Configuration reading --- |
65 | ||
66 | (defvar mdw-config nil) | |
67 | (defun mdw-config (sym) | |
68 | "Read the configuration variable named SYM." | |
69 | (unless mdw-config | |
daff679f MW |
70 | (setq mdw-config |
71 | (flet ((replace (what with) | |
72 | (goto-char (point-min)) | |
73 | (while (re-search-forward what nil t) | |
74 | (replace-match with t)))) | |
75 | (with-temp-buffer | |
76 | (insert-file-contents "~/.mdw.conf") | |
77 | (replace "^[ \t]*\\(#.*\\|\\)\n" "") | |
78 | (replace (concat "^[ \t]*" | |
79 | "\\([-a-zA-Z0-9_.]*\\)" | |
80 | "[ \t]*=[ \t]*" | |
81 | "\\(.*[^ \t\n]\\|\\)" | |
82 | "[ \t]**\\(\n\\|$\\)") | |
83 | "(\\1 . \"\\2\")\n") | |
84 | (car (read-from-string | |
85 | (concat "(" (buffer-string) ")"))))))) | |
f141fe0f MW |
86 | (cdr (assq sym mdw-config))) |
87 | ||
cb6e2cd1 MW |
88 | ;; --- Is an Emacs library available? --- |
89 | ||
90 | (defun library-exists-p (name) | |
91 | "Return non-nil if NAME.el (or NAME.elc) is somewhere on the Emacs load | |
92 | path. The non-nil value is the filename we found for the library." | |
93 | (let ((path load-path) elt (foundp nil)) | |
94 | (while (and path (not foundp)) | |
95 | (setq elt (car path)) | |
96 | (setq path (cdr path)) | |
97 | (setq foundp (or (let ((file (concat elt "/" name ".elc"))) | |
98 | (and (file-exists-p file) file)) | |
99 | (let ((file (concat elt "/" name ".el"))) | |
100 | (and (file-exists-p file) file))))) | |
101 | foundp)) | |
102 | ||
103 | (defun maybe-autoload (symbol file &optional docstring interactivep type) | |
104 | "Set an autoload if the file actually exists." | |
105 | (and (library-exists-p file) | |
106 | (autoload symbol file docstring interactivep type))) | |
107 | ||
f617db13 MW |
108 | ;; --- Splitting windows --- |
109 | ||
8c2b05d5 MW |
110 | (unless (fboundp 'scroll-bar-columns) |
111 | (defun scroll-bar-columns (side) | |
112 | (cond ((eq side 'left) 0) | |
113 | (window-system 3) | |
114 | (t 1)))) | |
115 | (unless (fboundp 'fringe-columns) | |
116 | (defun fringe-columns (side) | |
117 | (cond ((not window-system) 0) | |
118 | ((eq side 'left) 1) | |
119 | (t 2)))) | |
120 | ||
121 | (defun mdw-divvy-window (&optional width) | |
f617db13 | 122 | "Split a wide window into appropriate widths." |
8c2b05d5 MW |
123 | (interactive "P") |
124 | (setq width (cond (width (prefix-numeric-value width)) | |
125 | ((and window-system | |
126 | (>= emacs-major-version 22)) | |
127 | 77) | |
128 | (t 78))) | |
b5d724dd MW |
129 | (let* ((win (selected-window)) |
130 | (sb-width (if (not window-system) | |
131 | 1 | |
8c2b05d5 MW |
132 | (let ((tot 0)) |
133 | (dolist (what '(scroll-bar fringe)) | |
134 | (dolist (side '(left right)) | |
135 | (incf tot | |
136 | (funcall (intern (concat (symbol-name what) | |
137 | "-columns")) | |
138 | side)))) | |
139 | tot))) | |
b5d724dd | 140 | (c (/ (+ (window-width) sb-width) |
8c2b05d5 | 141 | (+ width sb-width)))) |
f617db13 MW |
142 | (while (> c 1) |
143 | (setq c (1- c)) | |
8c2b05d5 | 144 | (split-window-horizontally (+ width sb-width)) |
f617db13 MW |
145 | (other-window 1)) |
146 | (select-window win))) | |
147 | ||
148 | ;; --- Functions for sexp diary entries --- | |
149 | ||
150 | (defun mdw-weekday (l) | |
151 | "Return non-nil if `date' falls on one of the days of the week in L. | |
152 | ||
153 | L is a list of day numbers (from 0 to 6 for Sunday through to Saturday) or | |
154 | symbols `sunday', `monday', etc. (or a mixture). If the date stored in | |
155 | `date' falls on a listed day, then the function returns non-nil." | |
156 | (let ((d (calendar-day-of-week date))) | |
157 | (or (memq d l) | |
158 | (memq (nth d '(sunday monday tuesday wednesday | |
159 | thursday friday saturday)) l)))) | |
160 | ||
161 | (defun mdw-todo (&optional when) | |
162 | "Return non-nil today, or on WHEN, whichever is later." | |
163 | (let ((w (calendar-absolute-from-gregorian (calendar-current-date))) | |
164 | (d (calendar-absolute-from-gregorian date))) | |
165 | (if when | |
166 | (setq w (max w (calendar-absolute-from-gregorian | |
167 | (cond | |
168 | ((not european-calendar-style) | |
169 | when) | |
170 | ((> (car when) 100) | |
171 | (list (nth 1 when) | |
172 | (nth 2 when) | |
173 | (nth 0 when))) | |
174 | (t | |
175 | (list (nth 1 when) | |
176 | (nth 0 when) | |
177 | (nth 2 when)))))))) | |
178 | (eq w d))) | |
179 | ||
180 | ;;;----- Utility functions -------------------------------------------------- | |
181 | ||
b5d724dd MW |
182 | (or (fboundp 'line-number-at-pos) |
183 | (defun line-number-at-pos (&optional pos) | |
184 | (let ((opoint (or pos (point))) start) | |
185 | (save-excursion | |
186 | (save-restriction | |
187 | (goto-char (point-min)) | |
188 | (widen) | |
189 | (forward-line 0) | |
190 | (setq start (point)) | |
191 | (goto-char opoint) | |
192 | (forward-line 0) | |
193 | (1+ (count-lines 1 (point)))))))) | |
459c9fb2 | 194 | |
f617db13 MW |
195 | ;; --- mdw-uniquify-alist --- |
196 | ||
197 | (defun mdw-uniquify-alist (&rest alists) | |
198 | ||
199 | "Return the concatenation of the ALISTS with duplicate elements removed. | |
200 | ||
201 | The first association with a given key prevails; others are ignored. The | |
202 | input lists are not modified, although they'll probably become garbage." | |
203 | ||
204 | (and alists | |
205 | (let ((start-list (cons nil nil))) | |
206 | (mdw-do-uniquify start-list | |
207 | start-list | |
208 | (car alists) | |
209 | (cdr alists))))) | |
210 | ||
211 | ;; --- mdw-do-uniquify --- | |
212 | ;; | |
213 | ;; The DONE argument is a list whose first element is `nil'. It contains the | |
214 | ;; uniquified alist built so far. The leading `nil' is stripped off at the | |
215 | ;; end of the operation; it's only there so that DONE always references a | |
216 | ;; cons cell. END refers to the final cons cell in the DONE list; it is | |
217 | ;; modified in place each time to avoid the overheads of `append'ing all the | |
218 | ;; time. The L argument is the alist we're currently processing; the | |
219 | ;; remaining alists are given in REST. | |
220 | ||
221 | (defun mdw-do-uniquify (done end l rest) | |
222 | "A helper function for mdw-uniquify-alist." | |
223 | ||
224 | ;; --- There are several different cases to deal with here --- | |
225 | ||
226 | (cond | |
227 | ||
228 | ;; --- Current list isn't empty --- | |
229 | ;; | |
230 | ;; Add the first item to the DONE list if there's not an item with the | |
231 | ;; same KEY already there. | |
232 | ||
233 | (l (or (assoc (car (car l)) done) | |
234 | (progn | |
235 | (setcdr end (cons (car l) nil)) | |
236 | (setq end (cdr end)))) | |
237 | (mdw-do-uniquify done end (cdr l) rest)) | |
238 | ||
239 | ;; --- The list we were working on is empty --- | |
240 | ;; | |
241 | ;; Shunt the next list into the current list position and go round again. | |
242 | ||
243 | (rest (mdw-do-uniquify done end (car rest) (cdr rest))) | |
244 | ||
245 | ;; --- Everything's done --- | |
246 | ;; | |
247 | ;; Remove the leading `nil' from the DONE list and return it. Finished! | |
248 | ||
249 | (t (cdr done)))) | |
250 | ||
251 | ;; --- Insert a date --- | |
252 | ||
253 | (defun date () | |
254 | "Insert the current date in a pleasing way." | |
255 | (interactive) | |
256 | (insert (save-excursion | |
257 | (let ((buffer (get-buffer-create "*tmp*"))) | |
258 | (unwind-protect (progn (set-buffer buffer) | |
259 | (erase-buffer) | |
260 | (shell-command "date +%Y-%m-%d" t) | |
261 | (goto-char (mark)) | |
262 | (delete-backward-char 1) | |
263 | (buffer-string)) | |
264 | (kill-buffer buffer)))))) | |
265 | ||
266 | ;; --- UUencoding --- | |
267 | ||
268 | (defun uuencode (file &optional name) | |
269 | "UUencodes a file, maybe calling it NAME, into the current buffer." | |
270 | (interactive "fInput file name: ") | |
271 | ||
272 | ;; --- If NAME isn't specified, then guess from the filename --- | |
273 | ||
274 | (if (not name) | |
275 | (setq name | |
276 | (substring file | |
277 | (or (string-match "[^/]*$" file) 0)))) | |
278 | ||
279 | (print (format "uuencode `%s' `%s'" file name)) | |
280 | ||
281 | ;; --- Now actually do the thing --- | |
282 | ||
283 | (call-process "uuencode" file t nil name)) | |
284 | ||
285 | (defvar np-file "~/.np" | |
286 | "*Where the `now-playing' file is.") | |
287 | ||
288 | (defun np (&optional arg) | |
289 | "Grabs a `now-playing' string." | |
290 | (interactive) | |
291 | (save-excursion | |
292 | (or arg (progn | |
852cd5fb | 293 | (goto-char (point-max)) |
f617db13 | 294 | (insert "\nNP: ") |
daff679f | 295 | (insert-file-contents np-file))))) |
f617db13 | 296 | |
c7a8da49 MW |
297 | (defun mdw-check-autorevert () |
298 | "Sets global-auto-revert-ignore-buffer appropriately for this buffer, | |
299 | taking into consideration whether it's been found using tramp, which seems to | |
300 | get itself into a twist." | |
46e69f55 MW |
301 | (cond ((not (boundp 'global-auto-revert-ignore-buffer)) |
302 | nil) | |
303 | ((and (buffer-file-name) | |
304 | (fboundp 'tramp-tramp-file-p) | |
c7a8da49 MW |
305 | (tramp-tramp-file-p (buffer-file-name))) |
306 | (unless global-auto-revert-ignore-buffer | |
307 | (setq global-auto-revert-ignore-buffer 'tramp))) | |
308 | ((eq global-auto-revert-ignore-buffer 'tramp) | |
309 | (setq global-auto-revert-ignore-buffer nil)))) | |
310 | ||
311 | (defadvice find-file (after mdw-autorevert activate) | |
312 | (mdw-check-autorevert)) | |
313 | (defadvice write-file (after mdw-autorevert activate) | |
4d9f2d65 | 314 | (mdw-check-autorevert)) |
f617db13 MW |
315 | |
316 | (defun mdwmail-mode () | |
317 | "Major mode for editing news and mail messages from external programs | |
318 | Not much right now. Just support for doing MailCrypt stuff." | |
319 | (interactive) | |
320 | (kill-all-local-variables) | |
321 | (use-local-map text-mode-map) | |
322 | (setq local-abbrev-table text-mode-abbrev-table) | |
323 | (setq major-mode 'mdwmail-mode) | |
324 | (setq mode-name "[mdw] mail") | |
bc091e80 | 325 | (set-buffer-file-coding-system 'utf-8) |
f617db13 MW |
326 | (make-local-variable 'paragraph-separate) |
327 | (make-local-variable 'paragraph-start) | |
328 | (setq paragraph-start (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|" | |
329 | paragraph-start)) | |
330 | (setq paragraph-separate (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|" | |
331 | paragraph-separate)) | |
332 | (run-hooks 'text-mode-hook 'mdwmail-mode-hook 'mail-setup-hook)) | |
333 | ||
334 | ;; --- How to encrypt in mdwmail --- | |
335 | ||
336 | (defun mdwmail-mc-encrypt (&optional recip scm start end from sign) | |
337 | (or start | |
338 | (setq start (save-excursion | |
339 | (goto-char (point-min)) | |
340 | (or (search-forward "\n\n" nil t) (point-min))))) | |
341 | (or end | |
342 | (setq end (point-max))) | |
343 | (mc-encrypt-generic recip scm start end from sign)) | |
344 | ||
345 | ;; --- How to sign in mdwmail --- | |
346 | ||
347 | (defun mdwmail-mc-sign (key scm start end uclr) | |
348 | (or start | |
349 | (setq start (save-excursion | |
350 | (goto-char (point-min)) | |
351 | (or (search-forward "\n\n" nil t) (point-min))))) | |
352 | (or end | |
353 | (setq end (point-max))) | |
354 | (mc-sign-generic key scm start end uclr)) | |
355 | ||
356 | ;; --- Some signature mangling --- | |
357 | ||
358 | (defun mdwmail-mangle-signature () | |
359 | (save-excursion | |
360 | (goto-char (point-min)) | |
361 | (perform-replace "\n-- \n" "\n-- " nil nil nil))) | |
362 | (add-hook 'mail-setup-hook 'mdwmail-mangle-signature) | |
363 | ||
5195cbc3 MW |
364 | ;;;----- Dired hacking ------------------------------------------------------ |
365 | ||
366 | (defadvice dired-maybe-insert-subdir | |
367 | (around mdw-marked-insertion first activate) | |
368 | "The DIRNAME may be a list of directory names to insert. Interactively, if | |
369 | files are marked, then insert all of them. With a numeric prefix argument, | |
370 | select that many entries near point; with a non-numeric prefix argument, | |
371 | prompt for listing options." | |
372 | (interactive | |
373 | (list (dired-get-marked-files nil | |
374 | (and (integerp current-prefix-arg) | |
375 | current-prefix-arg) | |
376 | #'file-directory-p) | |
377 | (and current-prefix-arg | |
378 | (not (integerp current-prefix-arg)) | |
379 | (read-string "Switches for listing: " | |
380 | (or dired-subdir-switches | |
381 | dired-actual-switches))))) | |
382 | (let ((dirs (ad-get-arg 0))) | |
383 | (dolist (dir (if (listp dirs) dirs (list dirs))) | |
384 | (ad-set-arg 0 dir) | |
385 | ad-do-it))) | |
386 | ||
a203fba8 MW |
387 | ;;;----- URL viewing -------------------------------------------------------- |
388 | ||
389 | (defun mdw-w3m-browse-url (url &optional new-session-p) | |
390 | "Invoke w3m on the URL in its current window, or at least a different one. | |
391 | If NEW-SESSION-P, start a new session." | |
392 | (interactive "sURL: \nP") | |
393 | (save-excursion | |
63fb20c1 MW |
394 | (let ((window (selected-window))) |
395 | (unwind-protect | |
396 | (progn | |
397 | (select-window (or (and (not new-session-p) | |
398 | (get-buffer-window "*w3m*")) | |
399 | (progn | |
400 | (if (one-window-p t) (split-window)) | |
401 | (get-lru-window)))) | |
402 | (w3m-browse-url url new-session-p)) | |
403 | (select-window window))))) | |
a203fba8 MW |
404 | |
405 | (defvar mdw-good-url-browsers | |
406 | '((w3m . mdw-w3m-browse-url) | |
407 | browse-url-w3 | |
408 | browse-url-mozilla) | |
409 | "List of good browsers for mdw-good-url-browsers; each item is a browser | |
410 | function name, or a cons (CHECK . FUNC). A symbol FOO stands for (FOO | |
411 | . FOO).") | |
412 | ||
413 | (defun mdw-good-url-browser () | |
414 | "Return a good URL browser. Trundle the list of such things, finding the | |
415 | first item for which CHECK is fboundp, and returning the correponding FUNC." | |
416 | (let ((bs mdw-good-url-browsers) b check func answer) | |
417 | (while (and bs (not answer)) | |
418 | (setq b (car bs) | |
419 | bs (cdr bs)) | |
420 | (if (consp b) | |
421 | (setq check (car b) func (cdr b)) | |
422 | (setq check b func b)) | |
423 | (if (fboundp check) | |
424 | (setq answer func))) | |
425 | answer)) | |
426 | ||
f617db13 MW |
427 | ;;;----- Paragraph filling -------------------------------------------------- |
428 | ||
429 | ;; --- Useful variables --- | |
430 | ||
431 | (defvar mdw-fill-prefix nil | |
432 | "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'. If there's | |
433 | no fill prefix currently set (by the `fill-prefix' variable) and there's | |
434 | a match from one of the regexps here, it gets used to set the fill-prefix | |
435 | for the current operation. | |
436 | ||
437 | The variable is a list of items of the form `REGEXP . PREFIX'; if the | |
438 | REGEXP matches, the PREFIX is used to set the fill prefix. It in turn is | |
439 | a list of things: | |
440 | ||
441 | STRING -- insert a literal string | |
442 | (match . N) -- insert the thing matched by bracketed subexpression N | |
443 | (pad . N) -- a string of whitespace the same width as subexpression N | |
444 | (expr . FORM) -- the result of evaluating FORM") | |
445 | ||
446 | (make-variable-buffer-local 'mdw-fill-prefix) | |
447 | ||
448 | (defvar mdw-hanging-indents | |
10fa2414 MW |
449 | (concat "\\(\\(" |
450 | "\\([*o]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)" | |
451 | "[ \t]+" | |
452 | "\\)?\\)") | |
f617db13 MW |
453 | "*Standard regular expression matching things which might be part of a |
454 | hanging indent. This is mainly useful in `auto-fill-mode'.") | |
455 | ||
456 | ;; --- Setting things up --- | |
457 | ||
458 | (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill)) | |
459 | ||
460 | ;; --- Utility functions --- | |
461 | ||
462 | (defun mdw-tabify (s) | |
463 | "Tabify the string S. This is a horrid hack." | |
464 | (save-excursion | |
465 | (save-match-data | |
466 | (let (start end) | |
467 | (beginning-of-line) | |
468 | (setq start (point-marker)) | |
469 | (insert s "\n") | |
470 | (setq end (point-marker)) | |
471 | (tabify start end) | |
472 | (setq s (buffer-substring start (1- end))) | |
473 | (delete-region start end) | |
474 | (set-marker start nil) | |
475 | (set-marker end nil) | |
476 | s)))) | |
477 | ||
478 | (defun mdw-examine-fill-prefixes (l) | |
479 | "Given a list of dynamic fill prefixes, pick one which matches context and | |
480 | return the static fill prefix to use. Point must be at the start of a line, | |
481 | and match data must be saved." | |
482 | (cond ((not l) nil) | |
483 | ((looking-at (car (car l))) | |
484 | (mdw-tabify (apply (function concat) | |
485 | (mapcar (function mdw-do-prefix-match) | |
486 | (cdr (car l)))))) | |
487 | (t (mdw-examine-fill-prefixes (cdr l))))) | |
488 | ||
489 | (defun mdw-maybe-car (p) | |
490 | "If P is a pair, return (car P), otherwise just return P." | |
491 | (if (consp p) (car p) p)) | |
492 | ||
493 | (defun mdw-padding (s) | |
494 | "Return a string the same width as S but made entirely from whitespace." | |
495 | (let* ((l (length s)) (i 0) (n (make-string l ? ))) | |
496 | (while (< i l) | |
497 | (if (= 9 (aref s i)) | |
498 | (aset n i 9)) | |
499 | (setq i (1+ i))) | |
500 | n)) | |
501 | ||
502 | (defun mdw-do-prefix-match (m) | |
503 | "Expand a dynamic prefix match element. See `mdw-fill-prefix' for | |
504 | details." | |
505 | (cond ((not (consp m)) (format "%s" m)) | |
506 | ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m)))) | |
507 | ((eq (car m) 'pad) (mdw-padding (match-string | |
508 | (mdw-maybe-car (cdr m))))) | |
509 | ((eq (car m) 'eval) (eval (cdr m))) | |
510 | (t ""))) | |
511 | ||
512 | (defun mdw-choose-dynamic-fill-prefix () | |
513 | "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'." | |
514 | (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix) | |
515 | ((not mdw-fill-prefix) fill-prefix) | |
516 | (t (save-excursion | |
517 | (beginning-of-line) | |
518 | (save-match-data | |
519 | (mdw-examine-fill-prefixes mdw-fill-prefix)))))) | |
520 | ||
521 | (defun do-auto-fill () | |
522 | "Handle auto-filling, working out a dynamic fill prefix in the case where | |
523 | there isn't a sensible static one." | |
524 | (let ((fill-prefix (mdw-choose-dynamic-fill-prefix))) | |
525 | (mdw-do-auto-fill))) | |
526 | ||
527 | (defun mdw-fill-paragraph () | |
528 | "Fill paragraph, getting a dynamic fill prefix." | |
529 | (interactive) | |
530 | (let ((fill-prefix (mdw-choose-dynamic-fill-prefix))) | |
531 | (fill-paragraph nil))) | |
532 | ||
533 | (defun mdw-standard-fill-prefix (rx &optional mat) | |
534 | "Set the dynamic fill prefix, handling standard hanging indents and stuff. | |
535 | This is just a short-cut for setting the thing by hand, and by design it | |
536 | doesn't cope with anything approximating a complicated case." | |
537 | (setq mdw-fill-prefix | |
538 | `((,(concat rx mdw-hanging-indents) | |
539 | (match . 1) | |
540 | (pad . ,(or mat 2)))))) | |
541 | ||
542 | ;;;----- Other common declarations ------------------------------------------ | |
543 | ||
544 | (defun mdw-set-frame-transparency (&optional n) | |
545 | (interactive "P") | |
546 | (let* ((alist (frame-parameters)) | |
547 | (trans (assq 'transparency alist))) | |
548 | (if trans | |
549 | (rplacd trans (not (if n (zerop n) (cdr trans)))) | |
550 | (setq trans (cons 'transparency (not (equal 0 n))))) | |
551 | (modify-frame-parameters (selected-frame) (list trans)))) | |
552 | ||
553 | ;; --- Mouse wheel support --- | |
554 | ||
555 | (defconst mdw-wheel-scroll-amount 15) | |
556 | (defun mdw-wheel-up (click) | |
557 | (interactive "@e") | |
558 | (mdw-wheel-scroll click (function scroll-down))) | |
559 | (defun mdw-wheel-down (click) | |
560 | (interactive "@e") | |
561 | (mdw-wheel-scroll click (function scroll-up))) | |
562 | ||
563 | (defun mdw-wheel-scroll (click func) | |
564 | (let ((win (selected-window))) | |
565 | (unwind-protect | |
566 | (progn | |
567 | (select-window (posn-window (event-start click))) | |
568 | (let ((arg 2)) | |
569 | (funcall func (/ (window-height) 2)))) | |
570 | (select-window win)))) | |
571 | ||
572 | ;; --- Going backwards --- | |
573 | ||
574 | (defun other-window-backwards (arg) | |
575 | (interactive "p") | |
576 | (other-window (- arg))) | |
577 | ||
578 | ;; --- Common mode settings --- | |
579 | ||
580 | (defvar mdw-auto-indent t | |
581 | "Whether to indent automatically after a newline.") | |
582 | ||
583 | (defun mdw-misc-mode-config () | |
584 | (and mdw-auto-indent | |
585 | (cond ((eq major-mode 'lisp-mode) | |
586 | (local-set-key "\C-m" 'mdw-indent-newline-and-indent)) | |
30c8a8fb MW |
587 | ((or (eq major-mode 'slime-repl-mode) |
588 | (eq major-mode 'asm-mode)) | |
589 | nil) | |
f617db13 MW |
590 | (t |
591 | (local-set-key "\C-m" 'newline-and-indent)))) | |
592 | (local-set-key [C-return] 'newline) | |
30c8a8fb MW |
593 | (or (eq major-mode 'asm-mode) |
594 | (local-set-key [?\;] 'self-insert-command)) | |
f617db13 MW |
595 | (local-set-key [?\#] 'self-insert-command) |
596 | (local-set-key [?\"] 'self-insert-command) | |
597 | (setq comment-column 40) | |
598 | (auto-fill-mode 1) | |
599 | (setq fill-column 77) | |
473ff3b0 | 600 | (setq show-trailing-whitespace t) |
f617db13 MW |
601 | (mdw-set-font)) |
602 | ||
603 | ;; --- Set up all sorts of faces --- | |
604 | ||
605 | (defvar mdw-set-font nil) | |
606 | ||
607 | (defvar mdw-punct-face 'mdw-punct-face "Face to use for punctuation") | |
608 | (make-face 'mdw-punct-face) | |
609 | (defvar mdw-number-face 'mdw-number-face "Face to use for numbers") | |
610 | (make-face 'mdw-number-face) | |
611 | ||
612 | ;;;----- General fontification ---------------------------------------------- | |
613 | ||
473ff3b0 MW |
614 | (defun mdw-set-fonts (frame faces) |
615 | (while faces | |
616 | (let ((face (caar faces))) | |
617 | (or (facep face) (make-face face)) | |
618 | (set-face-attribute face frame | |
619 | :family 'unspecified | |
620 | :width 'unspecified | |
621 | :height 'unspecified | |
622 | :weight 'unspecified | |
623 | :slant 'unspecified | |
624 | :foreground 'unspecified | |
625 | :background 'unspecified | |
626 | :underline 'unspecified | |
627 | :overline 'unspecified | |
628 | :strike-through 'unspecified | |
629 | :box 'unspecified | |
630 | :inverse-video 'unspecified | |
631 | :stipple 'unspecified | |
632 | ;:font 'unspecified | |
633 | :inherit 'unspecified) | |
634 | (apply 'set-face-attribute face frame (cdar faces)) | |
635 | (setq faces (cdr faces))))) | |
f617db13 MW |
636 | |
637 | (defun mdw-do-set-font (&optional frame) | |
638 | (interactive) | |
639 | (mdw-set-fonts (and (boundp 'frame) frame) `( | |
640 | (default :foreground "white" :background "black" | |
641 | ,@(cond ((eq window-system 'w32) | |
642 | '(:family "courier new" :height 85)) | |
643 | ((eq window-system 'x) | |
9cbbe332 | 644 | '(:family "misc-fixed" :height 130 :width semi-condensed)))) |
b5d724dd MW |
645 | (fixed-pitch) |
646 | (minibuffer-prompt) | |
668e254c MW |
647 | (mode-line :foreground "blue" :background "yellow" |
648 | :box (:line-width 1 :style released-button)) | |
414d8484 | 649 | (mode-line-inactive :foreground "yellow" :background "blue" |
668e254c | 650 | :box (:line-width 1 :style released-button)) |
f617db13 | 651 | (scroll-bar :foreground "black" :background "lightgrey") |
414d8484 | 652 | (fringe :foreground "yellow" :background "black") |
f617db13 MW |
653 | (show-paren-match-face :background "darkgreen") |
654 | (show-paren-mismatch-face :background "red") | |
655 | (font-lock-warning-face :background "red" :weight bold) | |
656 | (highlight :background "DarkSeaGreen4") | |
657 | (holiday-face :background "red") | |
658 | (calendar-today-face :foreground "yellow" :weight bold) | |
659 | (comint-highlight-prompt :weight bold) | |
660 | (comint-highlight-input) | |
661 | (font-lock-builtin-face :weight bold) | |
662 | (font-lock-type-face :weight bold) | |
663 | (region :background "grey30") | |
664 | (isearch :background "palevioletred2") | |
665 | (mdw-punct-face :foreground ,(if window-system "burlywood2" "yellow")) | |
666 | (mdw-number-face :foreground "yellow") | |
667 | (font-lock-function-name-face :weight bold) | |
668 | (font-lock-variable-name-face :slant italic) | |
52696e46 MW |
669 | (font-lock-comment-delimiter-face |
670 | :foreground ,(if window-system "SeaGreen1" "green") | |
671 | :slant italic) | |
f617db13 MW |
672 | (font-lock-comment-face |
673 | :foreground ,(if window-system "SeaGreen1" "green") | |
674 | :slant italic) | |
675 | (font-lock-string-face :foreground ,(if window-system "SkyBlue1" "cyan")) | |
676 | (font-lock-keyword-face :weight bold) | |
677 | (font-lock-constant-face :weight bold) | |
678 | (font-lock-reference-face :weight bold) | |
8c521a22 MW |
679 | (woman-bold :weight bold) |
680 | (woman-italic :slant italic) | |
8b6bc589 MW |
681 | (diff-index :weight bold) |
682 | (diff-file-header :weight bold) | |
683 | (diff-hunk-header :foreground "SkyBlue1") | |
684 | (diff-function :foreground "SkyBlue1" :weight bold) | |
685 | (diff-header :background "grey10") | |
686 | (diff-added :foreground "green") | |
687 | (diff-removed :foreground "red") | |
688 | (diff-context) | |
f617db13 MW |
689 | (whizzy-slice-face :background "grey10") |
690 | (whizzy-error-face :background "darkred") | |
473ff3b0 | 691 | (trailing-whitespace :background "red") |
f617db13 MW |
692 | ))) |
693 | ||
694 | (defun mdw-set-font () | |
695 | (trap | |
696 | (turn-on-font-lock) | |
697 | (if (not mdw-set-font) | |
698 | (progn | |
699 | (setq mdw-set-font t) | |
700 | (mdw-do-set-font nil))))) | |
701 | ||
702 | ;;;----- C programming configuration ---------------------------------------- | |
703 | ||
704 | ;; --- Linux kernel hacking --- | |
705 | ||
706 | (defvar linux-c-mode-hook) | |
707 | ||
708 | (defun linux-c-mode () | |
709 | (interactive) | |
710 | (c-mode) | |
711 | (setq major-mode 'linux-c-mode) | |
712 | (setq mode-name "Linux C") | |
713 | (run-hooks 'linux-c-mode-hook)) | |
714 | ||
715 | ;; --- Make C indentation nice --- | |
716 | ||
717 | (defun mdw-c-style () | |
718 | (c-add-style "[mdw] C and C++ style" | |
719 | '((c-basic-offset . 2) | |
720 | (c-tab-always-indent . nil) | |
721 | (comment-column . 40) | |
722 | (c-class-key . "class") | |
723 | (c-offsets-alist (substatement-open . 0) | |
724 | (label . 0) | |
725 | (case-label . +) | |
726 | (access-label . -) | |
87c7cecb | 727 | (inclass . +) |
f617db13 MW |
728 | (inline-open . ++) |
729 | (statement-cont . 0) | |
730 | (statement-case-intro . +))) | |
731 | t)) | |
732 | ||
733 | (defun mdw-fontify-c-and-c++ () | |
734 | ||
735 | ;; --- Fiddle with some syntax codes --- | |
736 | ||
737 | (modify-syntax-entry ?_ "w") | |
738 | (modify-syntax-entry ?* ". 23") | |
739 | (modify-syntax-entry ?/ ". 124b") | |
740 | (modify-syntax-entry ?\n "> b") | |
741 | ||
742 | ;; --- Other stuff --- | |
743 | ||
744 | (mdw-c-style) | |
745 | (setq c-hanging-comment-ender-p nil) | |
746 | (setq c-backslash-column 72) | |
747 | (setq c-label-minimum-indentation 0) | |
f617db13 MW |
748 | (setq mdw-fill-prefix |
749 | `((,(concat "\\([ \t]*/?\\)" | |
750 | "\\([\*/][ \t]*\\)" | |
751 | "\\([A-Za-z]+:[ \t]*\\)?" | |
752 | mdw-hanging-indents) | |
753 | (pad . 1) (match . 2) (pad . 3) (pad . 4)))) | |
754 | ||
755 | ;; --- Now define things to be fontified --- | |
756 | ||
02109a0d | 757 | (make-local-variable 'font-lock-keywords) |
f617db13 | 758 | (let ((c-keywords |
8d6d55b9 MW |
759 | (mdw-regexps "and" ;C++ |
760 | "and_eq" ;C++ | |
761 | "asm" ;K&R, GCC | |
762 | "auto" ;K&R, C89 | |
763 | "bitand" ;C++ | |
764 | "bitor" ;C++ | |
765 | "bool" ;C++, C9X macro | |
766 | "break" ;K&R, C89 | |
767 | "case" ;K&R, C89 | |
768 | "catch" ;C++ | |
769 | "char" ;K&R, C89 | |
770 | "class" ;C++ | |
771 | "complex" ;C9X macro, C++ template type | |
772 | "compl" ;C++ | |
773 | "const" ;C89 | |
774 | "const_cast" ;C++ | |
775 | "continue" ;K&R, C89 | |
776 | "defined" ;C89 preprocessor | |
777 | "default" ;K&R, C89 | |
778 | "delete" ;C++ | |
779 | "do" ;K&R, C89 | |
780 | "double" ;K&R, C89 | |
781 | "dynamic_cast" ;C++ | |
782 | "else" ;K&R, C89 | |
783 | ;; "entry" ;K&R -- never used | |
784 | "enum" ;C89 | |
785 | "explicit" ;C++ | |
786 | "export" ;C++ | |
787 | "extern" ;K&R, C89 | |
788 | "false" ;C++, C9X macro | |
789 | "float" ;K&R, C89 | |
790 | "for" ;K&R, C89 | |
791 | ;; "fortran" ;K&R | |
792 | "friend" ;C++ | |
793 | "goto" ;K&R, C89 | |
794 | "if" ;K&R, C89 | |
795 | "imaginary" ;C9X macro | |
796 | "inline" ;C++, C9X, GCC | |
797 | "int" ;K&R, C89 | |
798 | "long" ;K&R, C89 | |
799 | "mutable" ;C++ | |
800 | "namespace" ;C++ | |
801 | "new" ;C++ | |
802 | "operator" ;C++ | |
803 | "or" ;C++ | |
804 | "or_eq" ;C++ | |
805 | "private" ;C++ | |
806 | "protected" ;C++ | |
807 | "public" ;C++ | |
808 | "register" ;K&R, C89 | |
809 | "reinterpret_cast" ;C++ | |
810 | "restrict" ;C9X | |
811 | "return" ;K&R, C89 | |
812 | "short" ;K&R, C89 | |
813 | "signed" ;C89 | |
814 | "sizeof" ;K&R, C89 | |
815 | "static" ;K&R, C89 | |
816 | "static_cast" ;C++ | |
817 | "struct" ;K&R, C89 | |
818 | "switch" ;K&R, C89 | |
819 | "template" ;C++ | |
820 | "this" ;C++ | |
821 | "throw" ;C++ | |
822 | "true" ;C++, C9X macro | |
823 | "try" ;C++ | |
824 | "this" ;C++ | |
825 | "typedef" ;C89 | |
826 | "typeid" ;C++ | |
827 | "typeof" ;GCC | |
828 | "typename" ;C++ | |
829 | "union" ;K&R, C89 | |
830 | "unsigned" ;K&R, C89 | |
831 | "using" ;C++ | |
832 | "virtual" ;C++ | |
833 | "void" ;C89 | |
834 | "volatile" ;C89 | |
835 | "wchar_t" ;C++, C89 library type | |
836 | "while" ;K&R, C89 | |
837 | "xor" ;C++ | |
838 | "xor_eq" ;C++ | |
839 | "_Bool" ;C9X | |
840 | "_Complex" ;C9X | |
841 | "_Imaginary" ;C9X | |
842 | "_Pragma" ;C9X preprocessor | |
843 | "__alignof__" ;GCC | |
844 | "__asm__" ;GCC | |
845 | "__attribute__" ;GCC | |
846 | "__complex__" ;GCC | |
847 | "__const__" ;GCC | |
848 | "__extension__" ;GCC | |
849 | "__imag__" ;GCC | |
850 | "__inline__" ;GCC | |
851 | "__label__" ;GCC | |
852 | "__real__" ;GCC | |
853 | "__signed__" ;GCC | |
854 | "__typeof__" ;GCC | |
855 | "__volatile__" ;GCC | |
856 | )) | |
f617db13 | 857 | (preprocessor-keywords |
8d6d55b9 MW |
858 | (mdw-regexps "assert" "define" "elif" "else" "endif" "error" |
859 | "ident" "if" "ifdef" "ifndef" "import" "include" | |
860 | "line" "pragma" "unassert" "undef" "warning")) | |
f617db13 | 861 | (objc-keywords |
8d6d55b9 MW |
862 | (mdw-regexps "class" "defs" "encode" "end" "implementation" |
863 | "interface" "private" "protected" "protocol" "public" | |
864 | "selector"))) | |
f617db13 MW |
865 | |
866 | (setq font-lock-keywords | |
867 | (list | |
f617db13 MW |
868 | |
869 | ;; --- Fontify include files as strings --- | |
870 | ||
871 | (list (concat "^[ \t]*\\#[ \t]*" | |
872 | "\\(include\\|import\\)" | |
873 | "[ \t]*\\(<[^>]+\\(>\\|\\)\\)") | |
874 | '(2 font-lock-string-face)) | |
875 | ||
876 | ;; --- Preprocessor directives are `references'? --- | |
877 | ||
878 | (list (concat "^\\([ \t]*#[ \t]*\\(\\(" | |
879 | preprocessor-keywords | |
880 | "\\)\\>\\|[0-9]+\\|$\\)\\)") | |
881 | '(1 font-lock-keyword-face)) | |
882 | ||
883 | ;; --- Handle the keywords defined above --- | |
884 | ||
885 | (list (concat "@\\<\\(" objc-keywords "\\)\\>") | |
886 | '(0 font-lock-keyword-face)) | |
887 | ||
888 | (list (concat "\\<\\(" c-keywords "\\)\\>") | |
889 | '(0 font-lock-keyword-face)) | |
890 | ||
891 | ;; --- Handle numbers too --- | |
892 | ;; | |
893 | ;; This looks strange, I know. It corresponds to the | |
894 | ;; preprocessor's idea of what a number looks like, rather than | |
895 | ;; anything sensible. | |
896 | ||
897 | (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)" | |
898 | "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*") | |
899 | '(0 mdw-number-face)) | |
900 | ||
901 | ;; --- And anything else is punctuation --- | |
902 | ||
903 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
904 | '(0 mdw-punct-face)))))) | |
905 | ||
906 | ;;;----- AP calc mode ------------------------------------------------------- | |
907 | ||
908 | (defun apcalc-mode () | |
909 | (interactive) | |
910 | (c-mode) | |
911 | (setq major-mode 'apcalc-mode) | |
912 | (setq mode-name "AP Calc") | |
913 | (run-hooks 'apcalc-mode-hook)) | |
914 | ||
915 | (defun mdw-fontify-apcalc () | |
916 | ||
917 | ;; --- Fiddle with some syntax codes --- | |
918 | ||
919 | (modify-syntax-entry ?_ "w") | |
920 | (modify-syntax-entry ?* ". 23") | |
921 | (modify-syntax-entry ?/ ". 14") | |
922 | ||
923 | ;; --- Other stuff --- | |
924 | ||
925 | (mdw-c-style) | |
926 | (setq c-hanging-comment-ender-p nil) | |
927 | (setq c-backslash-column 72) | |
928 | (setq comment-start "/* ") | |
929 | (setq comment-end " */") | |
930 | (setq mdw-fill-prefix | |
931 | `((,(concat "\\([ \t]*/?\\)" | |
932 | "\\([\*/][ \t]*\\)" | |
933 | "\\([A-Za-z]+:[ \t]*\\)?" | |
934 | mdw-hanging-indents) | |
935 | (pad . 1) (match . 2) (pad . 3) (pad . 4)))) | |
936 | ||
937 | ;; --- Now define things to be fontified --- | |
938 | ||
02109a0d | 939 | (make-local-variable 'font-lock-keywords) |
f617db13 | 940 | (let ((c-keywords |
8d6d55b9 MW |
941 | (mdw-regexps "break" "case" "cd" "continue" "define" "default" |
942 | "do" "else" "exit" "for" "global" "goto" "help" "if" | |
943 | "local" "mat" "obj" "print" "quit" "read" "return" | |
944 | "show" "static" "switch" "while" "write"))) | |
f617db13 MW |
945 | |
946 | (setq font-lock-keywords | |
947 | (list | |
f617db13 MW |
948 | |
949 | ;; --- Handle the keywords defined above --- | |
950 | ||
951 | (list (concat "\\<\\(" c-keywords "\\)\\>") | |
952 | '(0 font-lock-keyword-face)) | |
953 | ||
954 | ;; --- Handle numbers too --- | |
955 | ;; | |
956 | ;; This looks strange, I know. It corresponds to the | |
957 | ;; preprocessor's idea of what a number looks like, rather than | |
958 | ;; anything sensible. | |
959 | ||
960 | (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)" | |
961 | "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*") | |
962 | '(0 mdw-number-face)) | |
963 | ||
964 | ;; --- And anything else is punctuation --- | |
965 | ||
966 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
967 | '(0 mdw-punct-face)))))) | |
968 | ||
969 | ;;;----- Java programming configuration ------------------------------------- | |
970 | ||
971 | ;; --- Make indentation nice --- | |
972 | ||
973 | (defun mdw-java-style () | |
974 | (c-add-style "[mdw] Java style" | |
975 | '((c-basic-offset . 2) | |
976 | (c-tab-always-indent . nil) | |
977 | (c-offsets-alist (substatement-open . 0) | |
978 | (label . +) | |
979 | (case-label . +) | |
980 | (access-label . 0) | |
981 | (inclass . +) | |
982 | (statement-case-intro . +))) | |
983 | t)) | |
984 | ||
985 | ;; --- Declare Java fontification style --- | |
986 | ||
987 | (defun mdw-fontify-java () | |
988 | ||
989 | ;; --- Other stuff --- | |
990 | ||
991 | (mdw-java-style) | |
992 | (modify-syntax-entry ?_ "w") | |
993 | (setq c-hanging-comment-ender-p nil) | |
994 | (setq c-backslash-column 72) | |
995 | (setq comment-start "/* ") | |
996 | (setq comment-end " */") | |
997 | (setq mdw-fill-prefix | |
998 | `((,(concat "\\([ \t]*/?\\)" | |
999 | "\\([\*/][ \t]*\\)" | |
1000 | "\\([A-Za-z]+:[ \t]*\\)?" | |
1001 | mdw-hanging-indents) | |
1002 | (pad . 1) (match . 2) (pad . 3) (pad . 4)))) | |
1003 | ||
1004 | ;; --- Now define things to be fontified --- | |
1005 | ||
02109a0d | 1006 | (make-local-variable 'font-lock-keywords) |
f617db13 | 1007 | (let ((java-keywords |
8d6d55b9 MW |
1008 | (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch" |
1009 | "char" "class" "const" "continue" "default" "do" | |
1010 | "double" "else" "extends" "final" "finally" "float" | |
1011 | "for" "goto" "if" "implements" "import" "instanceof" | |
1012 | "int" "interface" "long" "native" "new" "package" | |
1013 | "private" "protected" "public" "return" "short" | |
1014 | "static" "super" "switch" "synchronized" "this" | |
1015 | "throw" "throws" "transient" "try" "void" "volatile" | |
1016 | "while" | |
1017 | ||
1018 | "false" "null" "true"))) | |
f617db13 MW |
1019 | |
1020 | (setq font-lock-keywords | |
1021 | (list | |
f617db13 MW |
1022 | |
1023 | ;; --- Handle the keywords defined above --- | |
1024 | ||
1025 | (list (concat "\\<\\(" java-keywords "\\)\\>") | |
1026 | '(0 font-lock-keyword-face)) | |
1027 | ||
1028 | ;; --- Handle numbers too --- | |
1029 | ;; | |
1030 | ;; The following isn't quite right, but it's close enough. | |
1031 | ||
1032 | (list (concat "\\<\\(" | |
1033 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
1034 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
1035 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
1036 | "[lLfFdD]?") | |
1037 | '(0 mdw-number-face)) | |
1038 | ||
1039 | ;; --- And anything else is punctuation --- | |
1040 | ||
1041 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1042 | '(0 mdw-punct-face)))))) | |
1043 | ||
e808c1e5 MW |
1044 | ;;;----- C# programming configuration --------------------------------------- |
1045 | ||
1046 | ;; --- Make indentation nice --- | |
1047 | ||
1048 | (defun mdw-csharp-style () | |
1049 | (c-add-style "[mdw] C# style" | |
1050 | '((c-basic-offset . 2) | |
1051 | (c-tab-always-indent . nil) | |
1052 | (c-offsets-alist (substatement-open . 0) | |
1053 | (label . 0) | |
1054 | (case-label . +) | |
1055 | (access-label . 0) | |
1056 | (inclass . +) | |
1057 | (statement-case-intro . +))) | |
1058 | t)) | |
1059 | ||
1060 | ;; --- Declare C# fontification style --- | |
1061 | ||
1062 | (defun mdw-fontify-csharp () | |
1063 | ||
1064 | ;; --- Other stuff --- | |
1065 | ||
1066 | (mdw-csharp-style) | |
1067 | (modify-syntax-entry ?_ "w") | |
1068 | (setq c-hanging-comment-ender-p nil) | |
1069 | (setq c-backslash-column 72) | |
1070 | (setq comment-start "/* ") | |
1071 | (setq comment-end " */") | |
1072 | (setq mdw-fill-prefix | |
1073 | `((,(concat "\\([ \t]*/?\\)" | |
1074 | "\\([\*/][ \t]*\\)" | |
1075 | "\\([A-Za-z]+:[ \t]*\\)?" | |
1076 | mdw-hanging-indents) | |
1077 | (pad . 1) (match . 2) (pad . 3) (pad . 4)))) | |
1078 | ||
1079 | ;; --- Now define things to be fontified --- | |
1080 | ||
1081 | (make-local-variable 'font-lock-keywords) | |
1082 | (let ((csharp-keywords | |
8d6d55b9 MW |
1083 | (mdw-regexps "abstract" "as" "base" "bool" "break" |
1084 | "byte" "case" "catch" "char" "checked" | |
1085 | "class" "const" "continue" "decimal" "default" | |
1086 | "delegate" "do" "double" "else" "enum" | |
1087 | "event" "explicit" "extern" "false" "finally" | |
1088 | "fixed" "float" "for" "foreach" "goto" | |
1089 | "if" "implicit" "in" "int" "interface" | |
1090 | "internal" "is" "lock" "long" "namespace" | |
1091 | "new" "null" "object" "operator" "out" | |
1092 | "override" "params" "private" "protected" "public" | |
1093 | "readonly" "ref" "return" "sbyte" "sealed" | |
1094 | "short" "sizeof" "stackalloc" "static" "string" | |
1095 | "struct" "switch" "this" "throw" "true" | |
1096 | "try" "typeof" "uint" "ulong" "unchecked" | |
1097 | "unsafe" "ushort" "using" "virtual" "void" | |
1098 | "volatile" "while" "yield"))) | |
e808c1e5 MW |
1099 | |
1100 | (setq font-lock-keywords | |
1101 | (list | |
e808c1e5 MW |
1102 | |
1103 | ;; --- Handle the keywords defined above --- | |
1104 | ||
1105 | (list (concat "\\<\\(" csharp-keywords "\\)\\>") | |
1106 | '(0 font-lock-keyword-face)) | |
1107 | ||
1108 | ;; --- Handle numbers too --- | |
1109 | ;; | |
1110 | ;; The following isn't quite right, but it's close enough. | |
1111 | ||
1112 | (list (concat "\\<\\(" | |
1113 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
1114 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
1115 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
1116 | "[lLfFdD]?") | |
1117 | '(0 mdw-number-face)) | |
1118 | ||
1119 | ;; --- And anything else is punctuation --- | |
1120 | ||
1121 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1122 | '(0 mdw-punct-face)))))) | |
1123 | ||
1124 | (defun csharp-mode () | |
1125 | (interactive) | |
1126 | (java-mode) | |
1127 | (setq major-mode 'csharp-mode) | |
1128 | (setq mode-name "C#") | |
1129 | (mdw-fontify-csharp) | |
1130 | (run-hooks 'csharp-mode-hook)) | |
1131 | ||
f617db13 MW |
1132 | ;;;----- Awk programming configuration -------------------------------------- |
1133 | ||
1134 | ;; --- Make Awk indentation nice --- | |
1135 | ||
1136 | (defun mdw-awk-style () | |
1137 | (c-add-style "[mdw] Awk style" | |
1138 | '((c-basic-offset . 2) | |
1139 | (c-tab-always-indent . nil) | |
1140 | (c-offsets-alist (substatement-open . 0) | |
1141 | (statement-cont . 0) | |
1142 | (statement-case-intro . +))) | |
1143 | t)) | |
1144 | ||
1145 | ;; --- Declare Awk fontification style --- | |
1146 | ||
1147 | (defun mdw-fontify-awk () | |
1148 | ||
1149 | ;; --- Miscellaneous fiddling --- | |
1150 | ||
1151 | (modify-syntax-entry ?_ "w") | |
1152 | (mdw-awk-style) | |
1153 | (setq c-backslash-column 72) | |
1154 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
1155 | ||
1156 | ;; --- Now define things to be fontified --- | |
1157 | ||
02109a0d | 1158 | (make-local-variable 'font-lock-keywords) |
f617db13 | 1159 | (let ((c-keywords |
8d6d55b9 MW |
1160 | (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT" |
1161 | "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR" | |
1162 | "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS" | |
1163 | "RSTART" "RLENGTH" "RT" "SUBSEP" | |
1164 | "atan2" "break" "close" "continue" "cos" "delete" | |
1165 | "do" "else" "exit" "exp" "fflush" "file" "for" "func" | |
1166 | "function" "gensub" "getline" "gsub" "if" "in" | |
1167 | "index" "int" "length" "log" "match" "next" "rand" | |
1168 | "return" "print" "printf" "sin" "split" "sprintf" | |
1169 | "sqrt" "srand" "strftime" "sub" "substr" "system" | |
1170 | "systime" "tolower" "toupper" "while"))) | |
f617db13 MW |
1171 | |
1172 | (setq font-lock-keywords | |
1173 | (list | |
f617db13 MW |
1174 | |
1175 | ;; --- Handle the keywords defined above --- | |
1176 | ||
1177 | (list (concat "\\<\\(" c-keywords "\\)\\>") | |
1178 | '(0 font-lock-keyword-face)) | |
1179 | ||
1180 | ;; --- Handle numbers too --- | |
1181 | ;; | |
1182 | ;; The following isn't quite right, but it's close enough. | |
1183 | ||
1184 | (list (concat "\\<\\(" | |
1185 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
1186 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
1187 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
1188 | "[uUlL]*") | |
1189 | '(0 mdw-number-face)) | |
1190 | ||
1191 | ;; --- And anything else is punctuation --- | |
1192 | ||
1193 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1194 | '(0 mdw-punct-face)))))) | |
1195 | ||
1196 | ;;;----- Perl programming style --------------------------------------------- | |
1197 | ||
1198 | ;; --- Perl indentation style --- | |
1199 | ||
1200 | (setq cperl-tab-always-indent nil) | |
1201 | ||
1202 | (setq cperl-indent-level 2) | |
1203 | (setq cperl-continued-statement-offset 2) | |
1204 | (setq cperl-continued-brace-offset 0) | |
1205 | (setq cperl-brace-offset -2) | |
1206 | (setq cperl-brace-imaginary-offset 0) | |
1207 | (setq cperl-label-offset 0) | |
1208 | ||
1209 | ;; --- Define perl fontification style --- | |
1210 | ||
1211 | (defun mdw-fontify-perl () | |
1212 | ||
1213 | ;; --- Miscellaneous fiddling --- | |
1214 | ||
1215 | (modify-syntax-entry ?_ "w") | |
1216 | (modify-syntax-entry ?$ "\\") | |
1217 | (modify-syntax-entry ?$ "\\" font-lock-syntax-table) | |
1218 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
1219 | ||
1220 | ;; --- Now define fontification things --- | |
1221 | ||
02109a0d | 1222 | (make-local-variable 'font-lock-keywords) |
f617db13 | 1223 | (let ((perl-keywords |
8d6d55b9 MW |
1224 | (mdw-regexps "and" "cmp" "continue" "do" "else" "elsif" "eq" |
1225 | "for" "foreach" "ge" "gt" "goto" "if" | |
1226 | "last" "le" "lt" "local" "my" "ne" "next" "or" | |
1227 | "package" "redo" "require" "return" "sub" | |
1228 | "undef" "unless" "until" "use" "while"))) | |
f617db13 MW |
1229 | |
1230 | (setq font-lock-keywords | |
1231 | (list | |
f617db13 MW |
1232 | |
1233 | ;; --- Set up the keywords defined above --- | |
1234 | ||
1235 | (list (concat "\\<\\(" perl-keywords "\\)\\>") | |
1236 | '(0 font-lock-keyword-face)) | |
1237 | ||
1238 | ;; --- At least numbers are simpler than C --- | |
1239 | ||
1240 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1241 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1242 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
1243 | '(0 mdw-number-face)) | |
1244 | ||
1245 | ;; --- And anything else is punctuation --- | |
1246 | ||
1247 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1248 | '(0 mdw-punct-face)))))) | |
1249 | ||
1250 | (defun perl-number-tests (&optional arg) | |
1251 | "Assign consecutive numbers to lines containing `#t'. With ARG, | |
1252 | strip numbers instead." | |
1253 | (interactive "P") | |
1254 | (save-excursion | |
1255 | (goto-char (point-min)) | |
1256 | (let ((i 0) (fmt (if arg "" " %4d"))) | |
1257 | (while (search-forward "#t" nil t) | |
1258 | (delete-region (point) (line-end-position)) | |
1259 | (setq i (1+ i)) | |
1260 | (insert (format fmt i))) | |
1261 | (goto-char (point-min)) | |
1262 | (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t) | |
1263 | (replace-match (format "\\1%d" i)))))) | |
1264 | ||
1265 | ;;;----- Python programming style ------------------------------------------- | |
1266 | ||
1267 | ;; --- Define Python fontification style --- | |
1268 | ||
f617db13 MW |
1269 | (defun mdw-fontify-python () |
1270 | ||
1271 | ;; --- Miscellaneous fiddling --- | |
1272 | ||
1273 | (modify-syntax-entry ?_ "w") | |
1274 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
1275 | ||
1276 | ;; --- Now define fontification things --- | |
1277 | ||
02109a0d | 1278 | (make-local-variable 'font-lock-keywords) |
f617db13 | 1279 | (let ((python-keywords |
8d6d55b9 MW |
1280 | (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def" |
1281 | "del" "elif" "else" "except" "exec" "finally" "for" | |
1282 | "from" "global" "if" "import" "in" "is" "lambda" | |
1283 | "not" "or" "pass" "print" "raise" "return" "try" | |
e61fa1ae | 1284 | "while" "with" "yield"))) |
f617db13 MW |
1285 | (setq font-lock-keywords |
1286 | (list | |
f617db13 MW |
1287 | |
1288 | ;; --- Set up the keywords defined above --- | |
1289 | ||
1290 | (list (concat "\\<\\(" python-keywords "\\)\\>") | |
1291 | '(0 font-lock-keyword-face)) | |
1292 | ||
1293 | ;; --- At least numbers are simpler than C --- | |
1294 | ||
1295 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1296 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1297 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)") | |
1298 | '(0 mdw-number-face)) | |
1299 | ||
1300 | ;; --- And anything else is punctuation --- | |
1301 | ||
1302 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1303 | '(0 mdw-punct-face)))))) | |
1304 | ||
1305 | ;;;----- ARM assembler programming configuration ---------------------------- | |
1306 | ||
1307 | ;; --- There doesn't appear to be an Emacs mode for this yet --- | |
1308 | ;; | |
1309 | ;; Better do something about that, I suppose. | |
1310 | ||
1311 | (defvar arm-assembler-mode-map nil) | |
1312 | (defvar arm-assembler-abbrev-table nil) | |
1313 | (defvar arm-assembler-mode-syntax-table (make-syntax-table)) | |
1314 | ||
1315 | (or arm-assembler-mode-map | |
1316 | (progn | |
1317 | (setq arm-assembler-mode-map (make-sparse-keymap)) | |
1318 | (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline) | |
1319 | (define-key arm-assembler-mode-map [C-return] 'newline) | |
1320 | (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop))) | |
1321 | ||
1322 | (defun arm-assembler-mode () | |
1323 | "Major mode for ARM assembler programs" | |
1324 | (interactive) | |
1325 | ||
1326 | ;; --- Do standard major mode things --- | |
1327 | ||
1328 | (kill-all-local-variables) | |
1329 | (use-local-map arm-assembler-mode-map) | |
1330 | (setq local-abbrev-table arm-assembler-abbrev-table) | |
1331 | (setq major-mode 'arm-assembler-mode) | |
1332 | (setq mode-name "ARM assembler") | |
1333 | ||
1334 | ;; --- Set up syntax table --- | |
1335 | ||
1336 | (set-syntax-table arm-assembler-mode-syntax-table) | |
1337 | (modify-syntax-entry ?; ; Nasty hack | |
1338 | "<" arm-assembler-mode-syntax-table) | |
1339 | (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table) | |
1340 | (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table) | |
1341 | ||
1342 | (make-local-variable 'comment-start) | |
1343 | (setq comment-start ";") | |
1344 | (make-local-variable 'comment-end) | |
1345 | (setq comment-end "") | |
1346 | (make-local-variable 'comment-column) | |
1347 | (setq comment-column 48) | |
1348 | (make-local-variable 'comment-start-skip) | |
1349 | (setq comment-start-skip ";+[ \t]*") | |
1350 | ||
1351 | ;; --- Play with indentation --- | |
1352 | ||
1353 | (make-local-variable 'indent-line-function) | |
1354 | (setq indent-line-function 'indent-relative-maybe) | |
1355 | ||
1356 | ;; --- Set fill prefix --- | |
1357 | ||
1358 | (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)") | |
1359 | ||
1360 | ;; --- Fiddle with fontification --- | |
1361 | ||
02109a0d | 1362 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1363 | (setq font-lock-keywords |
1364 | (list | |
f617db13 MW |
1365 | |
1366 | ;; --- Handle numbers too --- | |
1367 | ;; | |
1368 | ;; The following isn't quite right, but it's close enough. | |
1369 | ||
1370 | (list (concat "\\(" | |
1371 | "&[0-9a-fA-F]+\\|" | |
1372 | "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)" | |
1373 | "\\)") | |
1374 | '(0 mdw-number-face)) | |
1375 | ||
1376 | ;; --- Do something about operators --- | |
1377 | ||
1378 | (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)" | |
1379 | '(1 font-lock-keyword-face) | |
1380 | '(2 font-lock-string-face)) | |
1381 | (list ":[a-zA-Z]+:" | |
1382 | '(0 font-lock-keyword-face)) | |
1383 | ||
1384 | ;; --- Do menemonics and directives --- | |
1385 | ||
1386 | (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)" | |
1387 | '(1 font-lock-keyword-face)) | |
1388 | ||
1389 | ;; --- And anything else is punctuation --- | |
1390 | ||
1391 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1392 | '(0 mdw-punct-face)))) | |
1393 | ||
1394 | (run-hooks 'arm-assembler-mode-hook)) | |
1395 | ||
30c8a8fb MW |
1396 | ;;;----- Assembler mode ----------------------------------------------------- |
1397 | ||
1398 | (defun mdw-fontify-asm () | |
1399 | (modify-syntax-entry ?' "\"") | |
1400 | (modify-syntax-entry ?. "w") | |
1401 | (setf fill-prefix nil) | |
1402 | (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")) | |
1403 | ||
f617db13 MW |
1404 | ;;;----- TCL configuration -------------------------------------------------- |
1405 | ||
1406 | (defun mdw-fontify-tcl () | |
1407 | (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$)) | |
1408 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
02109a0d | 1409 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1410 | (setq font-lock-keywords |
1411 | (list | |
f617db13 MW |
1412 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" |
1413 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1414 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
1415 | '(0 mdw-number-face)) | |
1416 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1417 | '(0 mdw-punct-face))))) | |
1418 | ||
1419 | ;;;----- REXX configuration ------------------------------------------------- | |
1420 | ||
1421 | (defun mdw-rexx-electric-* () | |
1422 | (interactive) | |
1423 | (insert ?*) | |
1424 | (rexx-indent-line)) | |
1425 | ||
1426 | (defun mdw-rexx-indent-newline-indent () | |
1427 | (interactive) | |
1428 | (rexx-indent-line) | |
1429 | (if abbrev-mode (expand-abbrev)) | |
1430 | (newline-and-indent)) | |
1431 | ||
1432 | (defun mdw-fontify-rexx () | |
1433 | ||
1434 | ;; --- Various bits of fiddling --- | |
1435 | ||
1436 | (setq mdw-auto-indent nil) | |
1437 | (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent) | |
1438 | (local-set-key [?*] 'mdw-rexx-electric-*) | |
1439 | (mapcar #'(lambda (ch) (modify-syntax-entry ch "w")) | |
1440 | '(?. ?! ?? ?_ ?# ?@ ?$)) | |
1441 | (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)") | |
1442 | ||
1443 | ;; --- Set up keywords and things for fontification --- | |
1444 | ||
1445 | (make-local-variable 'font-lock-keywords-case-fold-search) | |
1446 | (setq font-lock-keywords-case-fold-search t) | |
1447 | ||
1448 | (setq rexx-indent 2) | |
1449 | (setq rexx-end-indent rexx-indent) | |
1450 | (setq rexx-tab-always-indent nil) | |
1451 | (setq rexx-cont-indent rexx-indent) | |
1452 | ||
02109a0d | 1453 | (make-local-variable 'font-lock-keywords) |
f617db13 | 1454 | (let ((rexx-keywords |
8d6d55b9 MW |
1455 | (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop" |
1456 | "else" "end" "engineering" "exit" "expose" "for" | |
1457 | "forever" "form" "fuzz" "if" "interpret" "iterate" | |
1458 | "leave" "linein" "name" "nop" "numeric" "off" "on" | |
1459 | "options" "otherwise" "parse" "procedure" "pull" | |
1460 | "push" "queue" "return" "say" "select" "signal" | |
1461 | "scientific" "source" "then" "trace" "to" "until" | |
1462 | "upper" "value" "var" "version" "when" "while" | |
1463 | "with" | |
1464 | ||
1465 | "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x" | |
1466 | "center" "center" "charin" "charout" "chars" | |
1467 | "compare" "condition" "copies" "c2d" "c2x" | |
1468 | "datatype" "date" "delstr" "delword" "d2c" "d2x" | |
1469 | "errortext" "format" "fuzz" "insert" "lastpos" | |
1470 | "left" "length" "lineout" "lines" "max" "min" | |
1471 | "overlay" "pos" "queued" "random" "reverse" "right" | |
1472 | "sign" "sourceline" "space" "stream" "strip" | |
1473 | "substr" "subword" "symbol" "time" "translate" | |
1474 | "trunc" "value" "verify" "word" "wordindex" | |
1475 | "wordlength" "wordpos" "words" "xrange" "x2b" "x2c" | |
1476 | "x2d"))) | |
f617db13 MW |
1477 | |
1478 | (setq font-lock-keywords | |
1479 | (list | |
f617db13 MW |
1480 | |
1481 | ;; --- Set up the keywords defined above --- | |
1482 | ||
1483 | (list (concat "\\<\\(" rexx-keywords "\\)\\>") | |
1484 | '(0 font-lock-keyword-face)) | |
1485 | ||
1486 | ;; --- Fontify all symbols the same way --- | |
1487 | ||
1488 | (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|" | |
1489 | "[A-Za-z0-9.!?_#@$]+\\)") | |
1490 | '(0 font-lock-variable-name-face)) | |
1491 | ||
1492 | ;; --- And everything else is punctuation --- | |
1493 | ||
1494 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1495 | '(0 mdw-punct-face)))))) | |
1496 | ||
1497 | ;;;----- Standard ML programming style -------------------------------------- | |
1498 | ||
1499 | (defun mdw-fontify-sml () | |
1500 | ||
1501 | ;; --- Make underscore an honorary letter --- | |
1502 | ||
1503 | (modify-syntax-entry ?_ "w") | |
1504 | (modify-syntax-entry ?' "w") | |
1505 | ||
1506 | ;; --- Set fill prefix --- | |
1507 | ||
1508 | (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)") | |
1509 | ||
1510 | ;; --- Now define fontification things --- | |
1511 | ||
02109a0d | 1512 | (make-local-variable 'font-lock-keywords) |
f617db13 | 1513 | (let ((sml-keywords |
8d6d55b9 MW |
1514 | (mdw-regexps "abstype" "and" "andalso" "as" |
1515 | "case" | |
1516 | "datatype" "do" | |
1517 | "else" "end" "eqtype" "exception" | |
1518 | "fn" "fun" "functor" | |
1519 | "handle" | |
1520 | "if" "in" "include" "infix" "infixr" | |
1521 | "let" "local" | |
1522 | "nonfix" | |
1523 | "of" "op" "open" "orelse" | |
1524 | "raise" "rec" | |
1525 | "sharing" "sig" "signature" "struct" "structure" | |
1526 | "then" "type" | |
1527 | "val" | |
1528 | "where" "while" "with" "withtype"))) | |
f617db13 MW |
1529 | |
1530 | (setq font-lock-keywords | |
1531 | (list | |
f617db13 MW |
1532 | |
1533 | ;; --- Set up the keywords defined above --- | |
1534 | ||
1535 | (list (concat "\\<\\(" sml-keywords "\\)\\>") | |
1536 | '(0 font-lock-keyword-face)) | |
1537 | ||
1538 | ;; --- At least numbers are simpler than C --- | |
1539 | ||
1540 | (list (concat "\\<\\(\\~\\|\\)" | |
1541 | "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|" | |
852cd5fb MW |
1542 | "[wW][0-9]+\\)\\|" |
1543 | "\\([0-9]+\\(\\.[0-9]+\\|\\)" | |
1544 | "\\([eE]\\(\\~\\|\\)" | |
1545 | "[0-9]+\\|\\)\\)\\)") | |
f617db13 MW |
1546 | '(0 mdw-number-face)) |
1547 | ||
1548 | ;; --- And anything else is punctuation --- | |
1549 | ||
1550 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1551 | '(0 mdw-punct-face)))))) | |
1552 | ||
1553 | ;;;----- Haskell configuration ---------------------------------------------- | |
1554 | ||
1555 | (defun mdw-fontify-haskell () | |
1556 | ||
1557 | ;; --- Fiddle with syntax table to get comments right --- | |
1558 | ||
1559 | (modify-syntax-entry ?_ "w") | |
1560 | (modify-syntax-entry ?' "\"") | |
1561 | (modify-syntax-entry ?- ". 123") | |
1562 | (modify-syntax-entry ?{ ". 1b") | |
1563 | (modify-syntax-entry ?} ". 4b") | |
1564 | (modify-syntax-entry ?\n ">") | |
1565 | ||
1566 | ;; --- Set fill prefix --- | |
1567 | ||
1568 | (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)") | |
1569 | ||
1570 | ;; --- Fiddle with fontification --- | |
1571 | ||
02109a0d | 1572 | (make-local-variable 'font-lock-keywords) |
f617db13 | 1573 | (let ((haskell-keywords |
8d6d55b9 MW |
1574 | (mdw-regexps "as" "case" "ccall" "class" "data" "default" |
1575 | "deriving" "do" "else" "foreign" "hiding" "if" | |
1576 | "import" "in" "infix" "infixl" "infixr" "instance" | |
1577 | "let" "module" "newtype" "of" "qualified" "safe" | |
1578 | "stdcall" "then" "type" "unsafe" "where"))) | |
f617db13 MW |
1579 | |
1580 | (setq font-lock-keywords | |
1581 | (list | |
f617db13 MW |
1582 | (list "--.*$" |
1583 | '(0 font-lock-comment-face)) | |
1584 | (list (concat "\\<\\(" haskell-keywords "\\)\\>") | |
1585 | '(0 font-lock-keyword-face)) | |
1586 | (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
1587 | "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)" | |
1588 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)") | |
1589 | '(0 mdw-number-face)) | |
1590 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1591 | '(0 mdw-punct-face)))))) | |
1592 | ||
1593 | ;;;----- Texinfo configuration ---------------------------------------------- | |
1594 | ||
1595 | (defun mdw-fontify-texinfo () | |
1596 | ||
1597 | ;; --- Set fill prefix --- | |
1598 | ||
1599 | (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)") | |
1600 | ||
1601 | ;; --- Real fontification things --- | |
1602 | ||
02109a0d | 1603 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1604 | (setq font-lock-keywords |
1605 | (list | |
f617db13 MW |
1606 | |
1607 | ;; --- Environment names are keywords --- | |
1608 | ||
1609 | (list "@\\(end\\) *\\([a-zA-Z]*\\)?" | |
1610 | '(2 font-lock-keyword-face)) | |
1611 | ||
1612 | ;; --- Unmark escaped magic characters --- | |
1613 | ||
1614 | (list "\\(@\\)\\([@{}]\\)" | |
1615 | '(1 font-lock-keyword-face) | |
1616 | '(2 font-lock-variable-name-face)) | |
1617 | ||
1618 | ;; --- Make sure we get comments properly --- | |
1619 | ||
1620 | (list "@c\\(\\|omment\\)\\( .*\\)?$" | |
1621 | '(0 font-lock-comment-face)) | |
1622 | ||
1623 | ;; --- Command names are keywords --- | |
1624 | ||
1625 | (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)" | |
1626 | '(0 font-lock-keyword-face)) | |
1627 | ||
1628 | ;; --- Fontify TeX special characters as punctuation --- | |
1629 | ||
1630 | (list "[{}]+" | |
1631 | '(0 mdw-punct-face))))) | |
1632 | ||
1633 | ;;;----- TeX and LaTeX configuration ---------------------------------------- | |
1634 | ||
1635 | (defun mdw-fontify-tex () | |
1636 | (setq ispell-parser 'tex) | |
1637 | ||
1638 | ;; --- Don't make maths into a string --- | |
1639 | ||
1640 | (modify-syntax-entry ?$ ".") | |
1641 | (modify-syntax-entry ?$ "." font-lock-syntax-table) | |
1642 | (local-set-key [?$] 'self-insert-command) | |
1643 | ||
1644 | ;; --- Set fill prefix --- | |
1645 | ||
1646 | (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)") | |
1647 | ||
1648 | ;; --- Real fontification things --- | |
1649 | ||
02109a0d | 1650 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1651 | (setq font-lock-keywords |
1652 | (list | |
f617db13 MW |
1653 | |
1654 | ;; --- Environment names are keywords --- | |
1655 | ||
1656 | (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)" | |
1657 | "{\\([^}\n]*\\)}") | |
1658 | '(2 font-lock-keyword-face)) | |
1659 | ||
1660 | ;; --- Suspended environment names are keywords too --- | |
1661 | ||
1662 | (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?" | |
1663 | "{\\([^}\n]*\\)}") | |
1664 | '(3 font-lock-keyword-face)) | |
1665 | ||
1666 | ;; --- Command names are keywords --- | |
1667 | ||
1668 | (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)" | |
1669 | '(0 font-lock-keyword-face)) | |
1670 | ||
1671 | ;; --- Handle @/.../ for italics --- | |
1672 | ||
1673 | ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)" | |
852cd5fb MW |
1674 | ;; '(1 font-lock-keyword-face) |
1675 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1676 | |
1677 | ;; --- Handle @*...* for boldness --- | |
1678 | ||
1679 | ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)" | |
852cd5fb MW |
1680 | ;; '(1 font-lock-keyword-face) |
1681 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1682 | |
1683 | ;; --- Handle @`...' for literal syntax things --- | |
1684 | ||
1685 | ;; (list "\\(@`\\)\\([^']*\\)\\('\\)" | |
852cd5fb MW |
1686 | ;; '(1 font-lock-keyword-face) |
1687 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1688 | |
1689 | ;; --- Handle @<...> for nonterminals --- | |
1690 | ||
1691 | ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)" | |
852cd5fb MW |
1692 | ;; '(1 font-lock-keyword-face) |
1693 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1694 | |
1695 | ;; --- Handle other @-commands --- | |
1696 | ||
1697 | ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)" | |
852cd5fb | 1698 | ;; '(0 font-lock-keyword-face)) |
f617db13 MW |
1699 | |
1700 | ;; --- Make sure we get comments properly --- | |
1701 | ||
1702 | (list "%.*" | |
1703 | '(0 font-lock-comment-face)) | |
1704 | ||
1705 | ;; --- Fontify TeX special characters as punctuation --- | |
1706 | ||
1707 | (list "[$^_{}#&]" | |
1708 | '(0 mdw-punct-face))))) | |
1709 | ||
f25cf300 MW |
1710 | ;;;----- SGML hacking ------------------------------------------------------- |
1711 | ||
1712 | (defun mdw-sgml-mode () | |
1713 | (interactive) | |
1714 | (sgml-mode) | |
1715 | (mdw-standard-fill-prefix "") | |
1716 | (make-variable-buffer-local 'sgml-delimiters) | |
1717 | (setq sgml-delimiters | |
1718 | '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]" | |
1719 | "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\"" | |
1720 | "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{" | |
1721 | "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?" | |
1722 | "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":" | |
1723 | "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>" | |
1724 | "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>" | |
1725 | "NULL" "")) | |
1726 | (setq major-mode 'mdw-sgml-mode) | |
1727 | (setq mode-name "[mdw] SGML") | |
1728 | (run-hooks 'mdw-sgml-mode-hook)) | |
1729 | ||
f617db13 MW |
1730 | ;;;----- Shell scripts ------------------------------------------------------ |
1731 | ||
1732 | (defun mdw-setup-sh-script-mode () | |
1733 | ||
1734 | ;; --- Fetch the shell interpreter's name --- | |
1735 | ||
1736 | (let ((shell-name sh-shell-file)) | |
1737 | ||
1738 | ;; --- Try reading the hash-bang line --- | |
1739 | ||
1740 | (save-excursion | |
1741 | (goto-char (point-min)) | |
1742 | (if (looking-at "#![ \t]*\\([^ \t\n]*\\)") | |
1743 | (setq shell-name (match-string 1)))) | |
1744 | ||
1745 | ;; --- Now try to set the shell --- | |
1746 | ;; | |
1747 | ;; Don't let `sh-set-shell' bugger up my script. | |
1748 | ||
1749 | (let ((executable-set-magic #'(lambda (s &rest r) s))) | |
1750 | (sh-set-shell shell-name))) | |
1751 | ||
1752 | ;; --- Now enable my keys and the fontification --- | |
1753 | ||
1754 | (mdw-misc-mode-config) | |
1755 | ||
1756 | ;; --- Set the indentation level correctly --- | |
1757 | ||
1758 | (setq sh-indentation 2) | |
1759 | (setq sh-basic-offset 2)) | |
1760 | ||
1761 | ;;;----- Messages-file mode ------------------------------------------------- | |
1762 | ||
1763 | (defun message-mode-guts () | |
1764 | (setq messages-mode-syntax-table (make-syntax-table)) | |
1765 | (set-syntax-table messages-mode-syntax-table) | |
1766 | (modify-syntax-entry ?_ "w" messages-mode-syntax-table) | |
1767 | (modify-syntax-entry ?- "w" messages-mode-syntax-table) | |
1768 | (modify-syntax-entry ?0 "w" messages-mode-syntax-table) | |
1769 | (modify-syntax-entry ?1 "w" messages-mode-syntax-table) | |
1770 | (modify-syntax-entry ?2 "w" messages-mode-syntax-table) | |
1771 | (modify-syntax-entry ?3 "w" messages-mode-syntax-table) | |
1772 | (modify-syntax-entry ?4 "w" messages-mode-syntax-table) | |
1773 | (modify-syntax-entry ?5 "w" messages-mode-syntax-table) | |
1774 | (modify-syntax-entry ?6 "w" messages-mode-syntax-table) | |
1775 | (modify-syntax-entry ?7 "w" messages-mode-syntax-table) | |
1776 | (modify-syntax-entry ?8 "w" messages-mode-syntax-table) | |
1777 | (modify-syntax-entry ?9 "w" messages-mode-syntax-table) | |
1778 | (make-local-variable 'comment-start) | |
1779 | (make-local-variable 'comment-end) | |
1780 | (make-local-variable 'indent-line-function) | |
1781 | (setq indent-line-function 'indent-relative) | |
1782 | (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)") | |
1783 | (make-local-variable 'font-lock-defaults) | |
1784 | (make-local-variable 'message-mode-keywords) | |
1785 | (let ((keywords | |
8d6d55b9 MW |
1786 | (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum" |
1787 | "export" "enum" "fixed-octetstring" "flags" | |
1788 | "harmless" "map" "nested" "optional" | |
1789 | "optional-tagged" "package" "primitive" | |
1790 | "primitive-nullfree" "relaxed[ \t]+enum" | |
1791 | "set" "table" "tagged-optional" "union" | |
1792 | "variadic" "vector" "version" "version-tag"))) | |
f617db13 MW |
1793 | (setq message-mode-keywords |
1794 | (list | |
1795 | (list (concat "\\<\\(" keywords "\\)\\>:") | |
1796 | '(0 font-lock-keyword-face)) | |
1797 | '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face)) | |
1798 | '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)" | |
1799 | (0 font-lock-variable-name-face)) | |
1800 | '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face)) | |
1801 | '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1802 | (0 mdw-punct-face))))) | |
1803 | (setq font-lock-defaults | |
1804 | '(message-mode-keywords nil nil nil nil)) | |
1805 | (run-hooks 'messages-file-hook)) | |
1806 | ||
1807 | (defun messages-mode () | |
1808 | (interactive) | |
1809 | (fundamental-mode) | |
1810 | (setq major-mode 'messages-mode) | |
1811 | (setq mode-name "Messages") | |
1812 | (message-mode-guts) | |
1813 | (modify-syntax-entry ?# "<" messages-mode-syntax-table) | |
1814 | (modify-syntax-entry ?\n ">" messages-mode-syntax-table) | |
1815 | (setq comment-start "# ") | |
1816 | (setq comment-end "") | |
1817 | (turn-on-font-lock-if-enabled) | |
1818 | (run-hooks 'messages-mode-hook)) | |
1819 | ||
1820 | (defun cpp-messages-mode () | |
1821 | (interactive) | |
1822 | (fundamental-mode) | |
1823 | (setq major-mode 'cpp-messages-mode) | |
1824 | (setq mode-name "CPP Messages") | |
1825 | (message-mode-guts) | |
1826 | (modify-syntax-entry ?* ". 23" messages-mode-syntax-table) | |
1827 | (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table) | |
1828 | (setq comment-start "/* ") | |
1829 | (setq comment-end " */") | |
1830 | (let ((preprocessor-keywords | |
8d6d55b9 MW |
1831 | (mdw-regexps "assert" "define" "elif" "else" "endif" "error" |
1832 | "ident" "if" "ifdef" "ifndef" "import" "include" | |
1833 | "line" "pragma" "unassert" "undef" "warning"))) | |
f617db13 MW |
1834 | (setq message-mode-keywords |
1835 | (append (list (list (concat "^[ \t]*\\#[ \t]*" | |
1836 | "\\(include\\|import\\)" | |
1837 | "[ \t]*\\(<[^>]+\\(>\\|\\)\\)") | |
1838 | '(2 font-lock-string-face)) | |
1839 | (list (concat "^\\([ \t]*#[ \t]*\\(\\(" | |
1840 | preprocessor-keywords | |
852cd5fb | 1841 | "\\)\\>\\|[0-9]+\\|$\\)\\)") |
f617db13 MW |
1842 | '(1 font-lock-keyword-face))) |
1843 | message-mode-keywords))) | |
f617db13 | 1844 | (turn-on-font-lock-if-enabled) |
297d60aa | 1845 | (run-hooks 'cpp-messages-mode-hook)) |
f617db13 | 1846 | |
297d60aa MW |
1847 | (add-hook 'messages-mode-hook 'mdw-misc-mode-config t) |
1848 | (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t) | |
f617db13 MW |
1849 | ; (add-hook 'messages-file-hook 'mdw-fontify-messages t) |
1850 | ||
1851 | ;;;----- Messages-file mode ------------------------------------------------- | |
1852 | ||
1853 | (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face | |
1854 | "Face to use for subsittution directives.") | |
1855 | (make-face 'mallow-driver-substitution-face) | |
1856 | (defvar mallow-driver-text-face 'mallow-driver-text-face | |
1857 | "Face to use for body text.") | |
1858 | (make-face 'mallow-driver-text-face) | |
1859 | ||
1860 | (defun mallow-driver-mode () | |
1861 | (interactive) | |
1862 | (fundamental-mode) | |
1863 | (setq major-mode 'mallow-driver-mode) | |
1864 | (setq mode-name "Mallow driver") | |
1865 | (setq mallow-driver-mode-syntax-table (make-syntax-table)) | |
1866 | (set-syntax-table mallow-driver-mode-syntax-table) | |
1867 | (make-local-variable 'comment-start) | |
1868 | (make-local-variable 'comment-end) | |
1869 | (make-local-variable 'indent-line-function) | |
1870 | (setq indent-line-function 'indent-relative) | |
1871 | (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)") | |
1872 | (make-local-variable 'font-lock-defaults) | |
1873 | (make-local-variable 'mallow-driver-mode-keywords) | |
1874 | (let ((keywords | |
8d6d55b9 MW |
1875 | (mdw-regexps "each" "divert" "file" "if" |
1876 | "perl" "set" "string" "type" "write"))) | |
f617db13 MW |
1877 | (setq mallow-driver-mode-keywords |
1878 | (list | |
1879 | (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$") | |
1880 | '(0 font-lock-keyword-face)) | |
1881 | (list "^%\\s *\\(#.*\\|\\)$" | |
1882 | '(0 font-lock-comment-face)) | |
1883 | (list "^%" | |
1884 | '(0 font-lock-keyword-face)) | |
1885 | (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face)) | |
1886 | (list "\\${[^}]*}" | |
1887 | '(0 mallow-driver-substitution-face t))))) | |
1888 | (setq font-lock-defaults | |
1889 | '(mallow-driver-mode-keywords nil nil nil nil)) | |
1890 | (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table) | |
1891 | (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table) | |
1892 | (setq comment-start "%# ") | |
1893 | (setq comment-end "") | |
1894 | (turn-on-font-lock-if-enabled) | |
1895 | (run-hooks 'mallow-driver-mode-hook)) | |
1896 | ||
1897 | (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t) | |
1898 | ||
1899 | ;;;----- NFast debugs ------------------------------------------------------- | |
1900 | ||
1901 | (defun nfast-debug-mode () | |
1902 | (interactive) | |
1903 | (fundamental-mode) | |
1904 | (setq major-mode 'nfast-debug-mode) | |
1905 | (setq mode-name "NFast debug") | |
1906 | (setq messages-mode-syntax-table (make-syntax-table)) | |
1907 | (set-syntax-table messages-mode-syntax-table) | |
1908 | (make-local-variable 'font-lock-defaults) | |
1909 | (make-local-variable 'nfast-debug-mode-keywords) | |
1910 | (setq truncate-lines t) | |
1911 | (setq nfast-debug-mode-keywords | |
1912 | (list | |
1913 | '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)" | |
1914 | (0 font-lock-keyword-face)) | |
1915 | (list (concat "^[ \t]+\\(\\(" | |
1916 | "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]" | |
1917 | "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]" | |
1918 | "[ \t]+\\)*" | |
1919 | "[0-9a-fA-F]+\\)[ \t]*$") | |
1920 | '(0 mdw-number-face)) | |
1921 | '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>" | |
1922 | (1 font-lock-keyword-face)) | |
1923 | '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>" | |
1924 | (1 font-lock-warning-face)) | |
1925 | '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>" | |
1926 | (1 nil)) | |
1927 | (list (concat "^[ \t]+\\.cmd=[ \t]+" | |
1928 | "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>") | |
1929 | '(1 font-lock-keyword-face)) | |
1930 | '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face)) | |
1931 | '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face)) | |
1932 | '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face)) | |
1933 | '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face)))) | |
1934 | (setq font-lock-defaults | |
1935 | '(nfast-debug-mode-keywords nil nil nil nil)) | |
1936 | (turn-on-font-lock-if-enabled) | |
1937 | (run-hooks 'nfast-debug-mode-hook)) | |
1938 | ||
1939 | ;;;----- Other languages ---------------------------------------------------- | |
1940 | ||
1941 | ;; --- Smalltalk --- | |
1942 | ||
1943 | (defun mdw-setup-smalltalk () | |
1944 | (and mdw-auto-indent | |
1945 | (local-set-key "\C-m" 'smalltalk-newline-and-indent)) | |
1946 | (make-variable-buffer-local 'mdw-auto-indent) | |
1947 | (setq mdw-auto-indent nil) | |
1948 | (local-set-key "\C-i" 'smalltalk-reindent)) | |
1949 | ||
1950 | (defun mdw-fontify-smalltalk () | |
02109a0d | 1951 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1952 | (setq font-lock-keywords |
1953 | (list | |
f617db13 MW |
1954 | (list "\\<[A-Z][a-zA-Z0-9]*\\>" |
1955 | '(0 font-lock-keyword-face)) | |
1956 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1957 | "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1958 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
1959 | '(0 mdw-number-face)) | |
1960 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1961 | '(0 mdw-punct-face))))) | |
1962 | ||
1963 | ;; --- Lispy languages --- | |
1964 | ||
1965 | (defun mdw-indent-newline-and-indent () | |
1966 | (interactive) | |
1967 | (indent-for-tab-command) | |
1968 | (newline-and-indent)) | |
1969 | ||
1970 | (eval-after-load "cl-indent" | |
1971 | '(progn | |
1972 | (mapc #'(lambda (pair) | |
1973 | (put (car pair) | |
1974 | 'common-lisp-indent-function | |
1975 | (cdr pair))) | |
1976 | '((destructuring-bind . ((&whole 4 &rest 1) 4 &body)) | |
1977 | (multiple-value-bind . ((&whole 4 &rest 1) 4 &body)))))) | |
1978 | ||
1979 | (defun mdw-common-lisp-indent () | |
1980 | (make-variable-buffer-local 'lisp-indent-function) | |
1981 | (setq lisp-indent-function 'common-lisp-indent-function)) | |
1982 | ||
1983 | (defun mdw-fontify-lispy () | |
1984 | ||
1985 | ;; --- Set fill prefix --- | |
1986 | ||
1987 | (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)") | |
1988 | ||
1989 | ;; --- Not much fontification needed --- | |
1990 | ||
02109a0d | 1991 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1992 | (setq font-lock-keywords |
1993 | (list | |
f617db13 MW |
1994 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" |
1995 | '(0 mdw-punct-face))))) | |
1996 | ||
1997 | (defun comint-send-and-indent () | |
1998 | (interactive) | |
1999 | (comint-send-input) | |
2000 | (and mdw-auto-indent | |
2001 | (indent-for-tab-command))) | |
2002 | ||
ec007bea MW |
2003 | (defun mdw-setup-m4 () |
2004 | (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)")) | |
2005 | ||
f617db13 MW |
2006 | ;;;----- Text mode ---------------------------------------------------------- |
2007 | ||
2008 | (defun mdw-text-mode () | |
2009 | (setq fill-column 72) | |
2010 | (flyspell-mode t) | |
2011 | (mdw-standard-fill-prefix | |
c7a8da49 | 2012 | "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3) |
f617db13 MW |
2013 | (auto-fill-mode 1)) |
2014 | ||
2015 | ;;;----- Shell mode --------------------------------------------------------- | |
2016 | ||
2017 | (defun mdw-sh-mode-setup () | |
2018 | (local-set-key [?\C-a] 'comint-bol) | |
2019 | (add-hook 'comint-output-filter-functions | |
2020 | 'comint-watch-for-password-prompt)) | |
2021 | ||
2022 | (defun mdw-term-mode-setup () | |
502f4699 | 2023 | (setq term-prompt-regexp "^[^]#$%>»}\n]*[]#$%>»}] *") |
f617db13 MW |
2024 | (make-local-variable 'mouse-yank-at-point) |
2025 | (make-local-variable 'transient-mark-mode) | |
2026 | (setq mouse-yank-at-point t) | |
2027 | (setq transient-mark-mode nil) | |
2028 | (auto-fill-mode -1) | |
2029 | (setq tab-width 8)) | |
2030 | ||
2031 | ;;;----- That's all, folks -------------------------------------------------- | |
2032 | ||
2033 | (provide 'dot-emacs) |