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 | ||
6132bc01 MW |
24 | ;;;-------------------------------------------------------------------------- |
25 | ;;; Check command-line. | |
c7a8da49 MW |
26 | |
27 | (defvar mdw-fast-startup nil | |
28 | "Whether .emacs should optimize for rapid startup. | |
29 | This may be at the expense of cool features.") | |
30 | (let ((probe nil) (next command-line-args)) | |
c7a8da49 MW |
31 | (while next |
32 | (cond ((string= (car next) "--mdw-fast-startup") | |
33 | (setq mdw-fast-startup t) | |
34 | (if probe | |
35 | (rplacd probe (cdr next)) | |
36 | (setq command-line-args (cdr next)))) | |
37 | (t | |
38 | (setq probe next))) | |
39 | (setq next (cdr next)))) | |
40 | ||
6132bc01 MW |
41 | ;;;-------------------------------------------------------------------------- |
42 | ;;; Some general utilities. | |
f617db13 | 43 | |
417dcddd MW |
44 | (eval-when-compile |
45 | (unless (fboundp 'make-regexp) | |
46 | (load "make-regexp")) | |
47 | (require 'cl)) | |
c7a8da49 MW |
48 | |
49 | (defmacro mdw-regexps (&rest list) | |
50 | "Turn a LIST of strings into a single regular expression at compile-time." | |
9e789ed5 MW |
51 | (declare (indent nil) |
52 | (debug 0)) | |
417dcddd | 53 | `',(make-regexp list)) |
c7a8da49 | 54 | |
a1b01eb3 MW |
55 | (defun mdw-wrong () |
56 | "This is not the key sequence you're looking for." | |
57 | (interactive) | |
58 | (error "wrong button")) | |
59 | ||
e8ea88ba MW |
60 | (defun mdw-emacs-version-p (major &optional minor) |
61 | "Return non-nil if the running Emacs is at least version MAJOR.MINOR." | |
62 | (or (> emacs-major-version major) | |
63 | (and (= emacs-major-version major) | |
64 | (>= emacs-minor-version (or minor 0))))) | |
65 | ||
6132bc01 | 66 | ;; Some error trapping. |
f617db13 MW |
67 | ;; |
68 | ;; If individual bits of this file go tits-up, we don't particularly want | |
69 | ;; the whole lot to stop right there and then, because it's bloody annoying. | |
70 | ||
71 | (defmacro trap (&rest forms) | |
72 | "Execute FORMS without allowing errors to propagate outside." | |
9e789ed5 MW |
73 | (declare (indent 0) |
74 | (debug t)) | |
f617db13 MW |
75 | `(condition-case err |
76 | ,(if (cdr forms) (cons 'progn forms) (car forms)) | |
8df912e4 MW |
77 | (error (message "Error (trapped): %s in %s" |
78 | (error-message-string err) | |
79 | ',forms)))) | |
f617db13 | 80 | |
6132bc01 | 81 | ;; Configuration reading. |
f141fe0f MW |
82 | |
83 | (defvar mdw-config nil) | |
84 | (defun mdw-config (sym) | |
85 | "Read the configuration variable named SYM." | |
86 | (unless mdw-config | |
daff679f MW |
87 | (setq mdw-config |
88 | (flet ((replace (what with) | |
89 | (goto-char (point-min)) | |
90 | (while (re-search-forward what nil t) | |
91 | (replace-match with t)))) | |
92 | (with-temp-buffer | |
93 | (insert-file-contents "~/.mdw.conf") | |
94 | (replace "^[ \t]*\\(#.*\\|\\)\n" "") | |
95 | (replace (concat "^[ \t]*" | |
96 | "\\([-a-zA-Z0-9_.]*\\)" | |
97 | "[ \t]*=[ \t]*" | |
98 | "\\(.*[^ \t\n]\\|\\)" | |
99 | "[ \t]**\\(\n\\|$\\)") | |
100 | "(\\1 . \"\\2\")\n") | |
101 | (car (read-from-string | |
102 | (concat "(" (buffer-string) ")"))))))) | |
f141fe0f MW |
103 | (cdr (assq sym mdw-config))) |
104 | ||
18bb0f77 MW |
105 | ;; Local variables hacking. |
106 | ||
107 | (defun run-local-vars-mode-hook () | |
108 | "Run a hook for the major-mode after local variables have been processed." | |
109 | (run-hooks (intern (concat (symbol-name major-mode) | |
110 | "-local-variables-hook")))) | |
111 | (add-hook 'hack-local-variables-hook 'run-local-vars-mode-hook) | |
112 | ||
6132bc01 | 113 | ;; Set up the load path convincingly. |
eac7b622 MW |
114 | |
115 | (dolist (dir (append (and (boundp 'debian-emacs-flavor) | |
116 | (list (concat "/usr/share/" | |
117 | (symbol-name debian-emacs-flavor) | |
118 | "/site-lisp"))))) | |
119 | (dolist (sub (directory-files dir t)) | |
120 | (when (and (file-accessible-directory-p sub) | |
121 | (not (member sub load-path))) | |
122 | (setq load-path (nconc load-path (list sub)))))) | |
123 | ||
6132bc01 | 124 | ;; Is an Emacs library available? |
cb6e2cd1 MW |
125 | |
126 | (defun library-exists-p (name) | |
6132bc01 MW |
127 | "Return non-nil if NAME is an available library. |
128 | Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs | |
129 | load path. The non-nil value is the filename we found for the | |
130 | library." | |
cb6e2cd1 MW |
131 | (let ((path load-path) elt (foundp nil)) |
132 | (while (and path (not foundp)) | |
133 | (setq elt (car path)) | |
134 | (setq path (cdr path)) | |
135 | (setq foundp (or (let ((file (concat elt "/" name ".elc"))) | |
136 | (and (file-exists-p file) file)) | |
137 | (let ((file (concat elt "/" name ".el"))) | |
138 | (and (file-exists-p file) file))))) | |
139 | foundp)) | |
140 | ||
141 | (defun maybe-autoload (symbol file &optional docstring interactivep type) | |
142 | "Set an autoload if the file actually exists." | |
143 | (and (library-exists-p file) | |
144 | (autoload symbol file docstring interactivep type))) | |
145 | ||
8183de08 MW |
146 | (defun mdw-kick-menu-bar (&optional frame) |
147 | "Regenerate FRAME's menu bar so it doesn't have empty menus." | |
148 | (interactive) | |
149 | (unless frame (setq frame (selected-frame))) | |
150 | (let ((old (frame-parameter frame 'menu-bar-lines))) | |
151 | (set-frame-parameter frame 'menu-bar-lines 0) | |
152 | (set-frame-parameter frame 'menu-bar-lines old))) | |
153 | ||
6132bc01 | 154 | ;; Splitting windows. |
f617db13 | 155 | |
8c2b05d5 MW |
156 | (unless (fboundp 'scroll-bar-columns) |
157 | (defun scroll-bar-columns (side) | |
158 | (cond ((eq side 'left) 0) | |
159 | (window-system 3) | |
160 | (t 1)))) | |
161 | (unless (fboundp 'fringe-columns) | |
162 | (defun fringe-columns (side) | |
163 | (cond ((not window-system) 0) | |
164 | ((eq side 'left) 1) | |
165 | (t 2)))) | |
166 | ||
3ba0b777 MW |
167 | (defun mdw-horizontal-window-overhead () |
168 | "Computes the horizontal window overhead. | |
169 | This is the number of columns used by fringes, scroll bars and other such | |
170 | cruft." | |
171 | (if (not window-system) | |
172 | 1 | |
173 | (let ((tot 0)) | |
174 | (dolist (what '(scroll-bar fringe)) | |
175 | (dolist (side '(left right)) | |
176 | (incf tot (funcall (intern (concat (symbol-name what) "-columns")) | |
177 | side)))) | |
178 | tot))) | |
179 | ||
180 | (defun mdw-split-window-horizontally (&optional width) | |
181 | "Split a window horizontally. | |
182 | Without a numeric argument, split the window approximately in | |
183 | half. With a numeric argument WIDTH, allocate WIDTH columns to | |
184 | the left-hand window (if positive) or -WIDTH columns to the | |
185 | right-hand window (if negative). Space for scroll bars and | |
186 | fringes is not taken out of the allowance for WIDTH, unlike | |
187 | \\[split-window-horizontally]." | |
188 | (interactive "P") | |
189 | (split-window-horizontally | |
190 | (cond ((null width) nil) | |
191 | ((>= width 0) (+ width (mdw-horizontal-window-overhead))) | |
192 | ((< width 0) width)))) | |
193 | ||
8c2b05d5 | 194 | (defun mdw-divvy-window (&optional width) |
f617db13 | 195 | "Split a wide window into appropriate widths." |
8c2b05d5 MW |
196 | (interactive "P") |
197 | (setq width (cond (width (prefix-numeric-value width)) | |
e8ea88ba | 198 | ((and window-system (mdw-emacs-version-p 22)) |
8c2b05d5 MW |
199 | 77) |
200 | (t 78))) | |
b5d724dd | 201 | (let* ((win (selected-window)) |
3ba0b777 | 202 | (sb-width (mdw-horizontal-window-overhead)) |
b5d724dd | 203 | (c (/ (+ (window-width) sb-width) |
8c2b05d5 | 204 | (+ width sb-width)))) |
f617db13 MW |
205 | (while (> c 1) |
206 | (setq c (1- c)) | |
8c2b05d5 | 207 | (split-window-horizontally (+ width sb-width)) |
f617db13 MW |
208 | (other-window 1)) |
209 | (select-window win))) | |
210 | ||
cc2be23e MW |
211 | ;; Don't raise windows unless I say so. |
212 | ||
213 | (defvar mdw-inhibit-raise-frame nil | |
214 | "*Whether `raise-frame' should do nothing when the frame is mapped.") | |
215 | ||
216 | (defadvice raise-frame | |
217 | (around mdw-inhibit (&optional frame) activate compile) | |
218 | "Don't actually do anything if `mdw-inhibit-raise-frame' is true, and the | |
219 | frame is actually mapped on the screen." | |
220 | (if mdw-inhibit-raise-frame | |
221 | (make-frame-visible frame) | |
222 | ad-do-it)) | |
223 | ||
224 | (defmacro mdw-advise-to-inhibit-raise-frame (function) | |
225 | "Advise the FUNCTION not to raise frames, even if it wants to." | |
226 | `(defadvice ,function | |
227 | (around mdw-inhibit-raise (&rest hunoz) activate compile) | |
228 | "Don't raise the window unless you have to." | |
229 | (let ((mdw-inhibit-raise-frame t)) | |
230 | ad-do-it))) | |
231 | ||
232 | (mdw-advise-to-inhibit-raise-frame select-frame-set-input-focus) | |
233 | ||
a1e4004c MW |
234 | ;; Bug fix for markdown-mode, which breaks point positioning during |
235 | ;; `query-replace'. | |
236 | (defadvice markdown-check-change-for-wiki-link | |
237 | (around mdw-save-match activate compile) | |
238 | "Save match data around the `markdown-mode' `after-change-functions' hook." | |
239 | (save-match-data ad-do-it)) | |
240 | ||
d54a4cf3 MW |
241 | ;; Bug fix for `bbdb-canonicalize-address': on Emacs 24, `run-hook-with-args' |
242 | ;; always returns nil, with the result that all email addresses are lost. | |
243 | ;; Replace the function entirely. | |
244 | (defadvice bbdb-canonicalize-address | |
245 | (around mdw-bug-fix activate compile) | |
246 | "Don't use `run-hook-with-args', because that doesn't work." | |
247 | (let ((net (ad-get-arg 0))) | |
248 | ||
249 | ;; Make sure this is a proper hook list. | |
250 | (if (functionp bbdb-canonicalize-net-hook) | |
251 | (setq bbdb-canonicalize-net-hook (list bbdb-canonicalize-net-hook))) | |
252 | ||
253 | ;; Iterate over the hooks until things converge. | |
254 | (let ((donep nil)) | |
255 | (while (not donep) | |
256 | (let (next (changep nil) | |
257 | hook (hooks bbdb-canonicalize-net-hook)) | |
258 | (while hooks | |
259 | (setq hook (pop hooks)) | |
260 | (setq next (funcall hook net)) | |
261 | (if (not (equal next net)) | |
262 | (setq changep t | |
263 | net next))) | |
264 | (setq donep (not changep))))) | |
265 | (setq ad-return-value net))) | |
266 | ||
c4b18360 MW |
267 | ;; Transient mark mode hacks. |
268 | ||
269 | (defadvice exchange-point-and-mark | |
270 | (around mdw-highlight (&optional arg) activate compile) | |
271 | "Maybe don't actually exchange point and mark. | |
272 | If `transient-mark-mode' is on and the mark is inactive, then | |
273 | just activate it. A non-trivial prefix argument will force the | |
274 | usual behaviour. A trivial prefix argument (i.e., just C-u) will | |
275 | activate the mark and temporarily enable `transient-mark-mode' if | |
276 | it's currently off." | |
277 | (cond ((or mark-active | |
278 | (and (not transient-mark-mode) (not arg)) | |
279 | (and arg (or (not (consp arg)) | |
280 | (not (= (car arg) 4))))) | |
281 | ad-do-it) | |
282 | (t | |
283 | (or transient-mark-mode (setq transient-mark-mode 'only)) | |
284 | (set-mark (mark t))))) | |
285 | ||
6132bc01 | 286 | ;; Functions for sexp diary entries. |
f617db13 | 287 | |
aede9fd7 MW |
288 | (defun mdw-not-org-mode (form) |
289 | "As FORM, but not in Org mode agenda." | |
290 | (and (not mdw-diary-for-org-mode-p) | |
291 | (eval form))) | |
292 | ||
f617db13 MW |
293 | (defun mdw-weekday (l) |
294 | "Return non-nil if `date' falls on one of the days of the week in L. | |
6132bc01 MW |
295 | L is a list of day numbers (from 0 to 6 for Sunday through to |
296 | Saturday) or symbols `sunday', `monday', etc. (or a mixture). If | |
297 | the date stored in `date' falls on a listed day, then the | |
298 | function returns non-nil." | |
f617db13 MW |
299 | (let ((d (calendar-day-of-week date))) |
300 | (or (memq d l) | |
301 | (memq (nth d '(sunday monday tuesday wednesday | |
302 | thursday friday saturday)) l)))) | |
303 | ||
d401f71b MW |
304 | (defun mdw-discordian-date (date) |
305 | "Return the Discordian calendar date corresponding to DATE. | |
306 | ||
307 | The return value is (YOLD . st-tibs-day) or (YOLD SEASON DAYNUM DOW). | |
308 | ||
309 | The original is by David Pearson. I modified it to produce date components | |
310 | as output rather than a string." | |
311 | (let* ((days ["Sweetmorn" "Boomtime" "Pungenday" | |
312 | "Prickle-Prickle" "Setting Orange"]) | |
313 | (months ["Chaos" "Discord" "Confusion" | |
314 | "Bureaucracy" "Aftermath"]) | |
315 | (day-count [0 31 59 90 120 151 181 212 243 273 304 334]) | |
316 | (year (- (extract-calendar-year date) 1900)) | |
317 | (month (1- (extract-calendar-month date))) | |
318 | (day (1- (extract-calendar-day date))) | |
319 | (julian (+ (aref day-count month) day)) | |
320 | (dyear (+ year 3066))) | |
321 | (if (and (= month 1) (= day 28)) | |
322 | (cons dyear 'st-tibs-day) | |
323 | (list dyear | |
324 | (aref months (floor (/ julian 73))) | |
325 | (1+ (mod julian 73)) | |
326 | (aref days (mod julian 5)))))) | |
327 | ||
328 | (defun mdw-diary-discordian-date () | |
329 | "Convert the date in `date' to a string giving the Discordian date." | |
330 | (let* ((ddate (mdw-discordian-date date)) | |
331 | (tail (format "in the YOLD %d" (car ddate)))) | |
332 | (if (eq (cdr ddate) 'st-tibs-day) | |
333 | (format "St Tib's Day %s" tail) | |
334 | (let ((season (cadr ddate)) | |
335 | (daynum (caddr ddate)) | |
336 | (dayname (cadddr ddate))) | |
337 | (format "%s, the %d%s day of %s %s" | |
338 | dayname | |
339 | daynum | |
340 | (let ((ldig (mod daynum 10))) | |
341 | (cond ((= ldig 1) "st") | |
342 | ((= ldig 2) "nd") | |
343 | ((= ldig 3) "rd") | |
344 | (t "th"))) | |
345 | season | |
346 | tail))))) | |
347 | ||
f617db13 MW |
348 | (defun mdw-todo (&optional when) |
349 | "Return non-nil today, or on WHEN, whichever is later." | |
350 | (let ((w (calendar-absolute-from-gregorian (calendar-current-date))) | |
351 | (d (calendar-absolute-from-gregorian date))) | |
352 | (if when | |
353 | (setq w (max w (calendar-absolute-from-gregorian | |
354 | (cond | |
355 | ((not european-calendar-style) | |
356 | when) | |
357 | ((> (car when) 100) | |
358 | (list (nth 1 when) | |
359 | (nth 2 when) | |
360 | (nth 0 when))) | |
361 | (t | |
362 | (list (nth 1 when) | |
363 | (nth 0 when) | |
364 | (nth 2 when)))))))) | |
365 | (eq w d))) | |
366 | ||
aede9fd7 MW |
367 | (defvar mdw-diary-for-org-mode-p nil) |
368 | ||
369 | (defadvice org-agenda-list (around mdw-preserve-links activate) | |
370 | (let ((mdw-diary-for-org-mode-p t)) | |
371 | ad-do-it)) | |
372 | ||
9f58a8d2 MW |
373 | (defadvice diary-add-to-list (before mdw-trim-leading-space activate) |
374 | "Trim leading space from the diary entry string." | |
375 | (save-match-data | |
2745469d MW |
376 | (let ((str (ad-get-arg 1)) |
377 | (done nil) old) | |
378 | (while (not done) | |
379 | (setq old str) | |
380 | (setq str (cond ((null str) nil) | |
381 | ((string-match "\\(^\\|\n\\)[ \t]+" str) | |
382 | (replace-match "\\1" nil nil str)) | |
aede9fd7 MW |
383 | ((and mdw-diary-for-org-mode-p |
384 | (string-match (concat | |
2745469d | 385 | "\\(^\\|\n\\)" |
aede9fd7 MW |
386 | "\\(" diary-time-regexp |
387 | "\\(-" diary-time-regexp "\\)?" | |
2745469d MW |
388 | "\\)" |
389 | "\\(\t[ \t]*\\| [ \t]+\\)") | |
aede9fd7 | 390 | str)) |
2745469d | 391 | (replace-match "\\1\\2 " nil nil str)) |
aede9fd7 MW |
392 | ((and (not mdw-diary-for-org-mode-p) |
393 | (string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]" | |
394 | str)) | |
395 | (replace-match "\\1" nil nil str)) | |
2745469d MW |
396 | (t str))) |
397 | (if (equal str old) (setq done t))) | |
398 | (ad-set-arg 1 str)))) | |
9f58a8d2 | 399 | |
6132bc01 | 400 | ;; Fighting with Org-mode's evil key maps. |
16fe7c41 MW |
401 | |
402 | (defvar mdw-evil-keymap-keys | |
403 | '(([S-up] . [?\C-c up]) | |
404 | ([S-down] . [?\C-c down]) | |
405 | ([S-left] . [?\C-c left]) | |
406 | ([S-right] . [?\C-c right]) | |
407 | (([M-up] [?\e up]) . [C-up]) | |
408 | (([M-down] [?\e down]) . [C-down]) | |
409 | (([M-left] [?\e left]) . [C-left]) | |
410 | (([M-right] [?\e right]) . [C-right])) | |
411 | "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'. | |
412 | The value is an alist mapping evil keys (as a list, or singleton) | |
413 | to good keys (in the same form).") | |
414 | ||
415 | (defun mdw-clobber-evil-keymap (keymap) | |
416 | "Replace evil key bindings in the KEYMAP. | |
417 | Evil key bindings are defined in `mdw-evil-keymap-keys'." | |
418 | (dolist (entry mdw-evil-keymap-keys) | |
419 | (let ((binding nil) | |
420 | (keys (if (listp (car entry)) | |
421 | (car entry) | |
422 | (list (car entry)))) | |
423 | (replacements (if (listp (cdr entry)) | |
424 | (cdr entry) | |
425 | (list (cdr entry))))) | |
426 | (catch 'found | |
427 | (dolist (key keys) | |
428 | (setq binding (lookup-key keymap key)) | |
429 | (when binding | |
430 | (throw 'found nil)))) | |
431 | (when binding | |
432 | (dolist (key keys) | |
433 | (define-key keymap key nil)) | |
434 | (dolist (key replacements) | |
435 | (define-key keymap key binding)))))) | |
436 | ||
0f6be0b1 | 437 | (eval-after-load "org-latex" |
f0dbee84 MW |
438 | '(progn |
439 | (push '("strayman" | |
440 | "\\documentclass{strayman} | |
441 | \\usepackage[utf8]{inputenc} | |
442 | \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts} | |
443 | \\usepackage[T1]{fontenc} | |
444 | \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}" | |
445 | ("\\section{%s}" . "\\section*{%s}") | |
446 | ("\\subsection{%s}" . "\\subsection*{%s}") | |
447 | ("\\subsubsection{%s}" . "\\subsubsection*{%s}") | |
448 | ("\\paragraph{%s}" . "\\paragraph*{%s}") | |
449 | ("\\subparagraph{%s}" . "\\subparagraph*{%s}")) | |
450 | org-export-latex-classes))) | |
451 | ||
8ba985cb MW |
452 | (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i" |
453 | org-export-docbook-xsl-fo-proc-command "fop %i.safe %o" | |
454 | org-export-docbook-xslt-stylesheet | |
455 | "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl") | |
456 | ||
5dccbe61 MW |
457 | ;; Some hacks to do with window placement. |
458 | ||
459 | (defun mdw-clobber-other-windows-showing-buffer (buffer-or-name) | |
460 | "Arrange that no windows on other frames are showing BUFFER-OR-NAME." | |
461 | (interactive "bBuffer: ") | |
462 | (let ((home-frame (selected-frame)) | |
463 | (buffer (get-buffer buffer-or-name)) | |
464 | (safe-buffer (get-buffer "*scratch*"))) | |
465 | (mapc (lambda (frame) | |
466 | (or (eq frame home-frame) | |
467 | (mapc (lambda (window) | |
468 | (and (eq (window-buffer window) buffer) | |
469 | (set-window-buffer window safe-buffer))) | |
470 | (window-list frame)))) | |
471 | (frame-list)))) | |
472 | ||
473 | (defvar mdw-inhibit-walk-windows nil | |
474 | "If non-nil, then `walk-windows' does nothing. | |
475 | This is used by advice on `switch-to-buffer-other-frame' to inhibit finding | |
476 | buffers in random frames.") | |
477 | ||
478 | (defadvice walk-windows (around mdw-inhibit activate) | |
479 | "If `mdw-inhibit-walk-windows' is non-nil, then do nothing." | |
480 | (and (not mdw-inhibit-walk-windows) | |
481 | ad-do-it)) | |
482 | ||
483 | (defadvice switch-to-buffer-other-frame | |
484 | (around mdw-always-new-frame activate) | |
485 | "Always make a new frame. | |
486 | Even if an existing window in some random frame looks tempting." | |
487 | (let ((mdw-inhibit-walk-windows t)) ad-do-it)) | |
488 | ||
489 | (defadvice display-buffer (before mdw-inhibit-other-frames activate) | |
490 | "Don't try to do anything fancy with other frames. | |
491 | Pretend they don't exist. They might be on other display devices." | |
492 | (ad-set-arg 2 nil)) | |
493 | ||
6132bc01 MW |
494 | ;;;-------------------------------------------------------------------------- |
495 | ;;; Mail and news hacking. | |
a3bdb4d9 MW |
496 | |
497 | (define-derived-mode mdwmail-mode mail-mode "[mdw] mail" | |
6132bc01 | 498 | "Major mode for editing news and mail messages from external programs. |
a3bdb4d9 MW |
499 | Not much right now. Just support for doing MailCrypt stuff." |
500 | :syntax-table nil | |
501 | :abbrev-table nil | |
502 | (run-hooks 'mail-setup-hook)) | |
503 | ||
504 | (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation) | |
505 | ||
506 | (add-hook 'mdwail-mode-hook | |
507 | (lambda () | |
508 | (set-buffer-file-coding-system 'utf-8) | |
509 | (make-local-variable 'paragraph-separate) | |
510 | (make-local-variable 'paragraph-start) | |
511 | (setq paragraph-start | |
512 | (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|" | |
513 | paragraph-start)) | |
514 | (setq paragraph-separate | |
515 | (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|" | |
516 | paragraph-separate)))) | |
517 | ||
6132bc01 | 518 | ;; How to encrypt in mdwmail. |
a3bdb4d9 MW |
519 | |
520 | (defun mdwmail-mc-encrypt (&optional recip scm start end from sign) | |
521 | (or start | |
522 | (setq start (save-excursion | |
523 | (goto-char (point-min)) | |
524 | (or (search-forward "\n\n" nil t) (point-min))))) | |
525 | (or end | |
526 | (setq end (point-max))) | |
527 | (mc-encrypt-generic recip scm start end from sign)) | |
528 | ||
6132bc01 | 529 | ;; How to sign in mdwmail. |
a3bdb4d9 MW |
530 | |
531 | (defun mdwmail-mc-sign (key scm start end uclr) | |
532 | (or start | |
533 | (setq start (save-excursion | |
534 | (goto-char (point-min)) | |
535 | (or (search-forward "\n\n" nil t) (point-min))))) | |
536 | (or end | |
537 | (setq end (point-max))) | |
538 | (mc-sign-generic key scm start end uclr)) | |
539 | ||
6132bc01 | 540 | ;; Some signature mangling. |
a3bdb4d9 MW |
541 | |
542 | (defun mdwmail-mangle-signature () | |
543 | (save-excursion | |
544 | (goto-char (point-min)) | |
545 | (perform-replace "\n-- \n" "\n-- " nil nil nil))) | |
546 | (add-hook 'mail-setup-hook 'mdwmail-mangle-signature) | |
547 | (add-hook 'message-setup-hook 'mdwmail-mangle-signature) | |
548 | ||
6132bc01 | 549 | ;; Insert my login name into message-ids, so I can score replies. |
a3bdb4d9 MW |
550 | |
551 | (defadvice message-unique-id (after mdw-user-name last activate compile) | |
552 | "Ensure that the user's name appears at the end of the message-id string, | |
553 | so that it can be used for convenient filtering." | |
554 | (setq ad-return-value (concat ad-return-value "." (user-login-name)))) | |
555 | ||
6132bc01 | 556 | ;; Tell my movemail hack where movemail is. |
a3bdb4d9 MW |
557 | ;; |
558 | ;; This is needed to shup up warnings about LD_PRELOAD. | |
559 | ||
560 | (let ((path exec-path)) | |
561 | (while path | |
562 | (let ((try (expand-file-name "movemail" (car path)))) | |
563 | (if (file-executable-p try) | |
564 | (setenv "REAL_MOVEMAIL" try)) | |
565 | (setq path (cdr path))))) | |
566 | ||
4d5799eb MW |
567 | ;; AUTHINFO GENERIC kludge. |
568 | ||
569 | (defvar nntp-authinfo-generic nil | |
570 | "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'. | |
571 | ||
572 | Use this to arrange for per-server settings.") | |
573 | ||
574 | (defun nntp-open-authinfo-kludge (buffer) | |
575 | "Open a connection to SERVER using `authinfo-kludge'." | |
576 | (let ((proc (start-process "nntpd" buffer | |
577 | "env" (concat "NNTPAUTH=" | |
578 | (or nntp-authinfo-generic | |
579 | (getenv "NNTPAUTH") | |
580 | (error "NNTPAUTH unset"))) | |
581 | "authinfo-kludge" nntp-address))) | |
582 | (set-buffer buffer) | |
583 | (nntp-wait-for-string "^\r*200") | |
584 | (beginning-of-line) | |
585 | (delete-region (point-min) (point)) | |
586 | proc)) | |
587 | ||
d17c6756 MW |
588 | (eval-after-load "erc" |
589 | '(load "~/.ercrc.el")) | |
590 | ||
6132bc01 MW |
591 | ;;;-------------------------------------------------------------------------- |
592 | ;;; Utility functions. | |
f617db13 | 593 | |
b5d724dd MW |
594 | (or (fboundp 'line-number-at-pos) |
595 | (defun line-number-at-pos (&optional pos) | |
596 | (let ((opoint (or pos (point))) start) | |
597 | (save-excursion | |
598 | (save-restriction | |
599 | (goto-char (point-min)) | |
600 | (widen) | |
601 | (forward-line 0) | |
602 | (setq start (point)) | |
603 | (goto-char opoint) | |
604 | (forward-line 0) | |
605 | (1+ (count-lines 1 (point)))))))) | |
459c9fb2 | 606 | |
f617db13 | 607 | (defun mdw-uniquify-alist (&rest alists) |
f617db13 | 608 | "Return the concatenation of the ALISTS with duplicate elements removed. |
6132bc01 MW |
609 | The first association with a given key prevails; others are |
610 | ignored. The input lists are not modified, although they'll | |
611 | probably become garbage." | |
f617db13 MW |
612 | (and alists |
613 | (let ((start-list (cons nil nil))) | |
614 | (mdw-do-uniquify start-list | |
615 | start-list | |
616 | (car alists) | |
617 | (cdr alists))))) | |
618 | ||
f617db13 | 619 | (defun mdw-do-uniquify (done end l rest) |
6132bc01 MW |
620 | "A helper function for mdw-uniquify-alist. |
621 | The DONE argument is a list whose first element is `nil'. It | |
622 | contains the uniquified alist built so far. The leading `nil' is | |
623 | stripped off at the end of the operation; it's only there so that | |
624 | DONE always references a cons cell. END refers to the final cons | |
625 | cell in the DONE list; it is modified in place each time to avoid | |
626 | the overheads of `append'ing all the time. The L argument is the | |
627 | alist we're currently processing; the remaining alists are given | |
628 | in REST." | |
629 | ||
630 | ;; There are several different cases to deal with here. | |
f617db13 MW |
631 | (cond |
632 | ||
6132bc01 MW |
633 | ;; Current list isn't empty. Add the first item to the DONE list if |
634 | ;; there's not an item with the same KEY already there. | |
f617db13 MW |
635 | (l (or (assoc (car (car l)) done) |
636 | (progn | |
637 | (setcdr end (cons (car l) nil)) | |
638 | (setq end (cdr end)))) | |
639 | (mdw-do-uniquify done end (cdr l) rest)) | |
640 | ||
6132bc01 MW |
641 | ;; The list we were working on is empty. Shunt the next list into the |
642 | ;; current list position and go round again. | |
f617db13 MW |
643 | (rest (mdw-do-uniquify done end (car rest) (cdr rest))) |
644 | ||
6132bc01 MW |
645 | ;; Everything's done. Remove the leading `nil' from the DONE list and |
646 | ;; return it. Finished! | |
f617db13 MW |
647 | (t (cdr done)))) |
648 | ||
f617db13 MW |
649 | (defun date () |
650 | "Insert the current date in a pleasing way." | |
651 | (interactive) | |
652 | (insert (save-excursion | |
653 | (let ((buffer (get-buffer-create "*tmp*"))) | |
654 | (unwind-protect (progn (set-buffer buffer) | |
655 | (erase-buffer) | |
656 | (shell-command "date +%Y-%m-%d" t) | |
657 | (goto-char (mark)) | |
658 | (delete-backward-char 1) | |
659 | (buffer-string)) | |
660 | (kill-buffer buffer)))))) | |
661 | ||
f617db13 MW |
662 | (defun uuencode (file &optional name) |
663 | "UUencodes a file, maybe calling it NAME, into the current buffer." | |
664 | (interactive "fInput file name: ") | |
665 | ||
6132bc01 | 666 | ;; If NAME isn't specified, then guess from the filename. |
f617db13 MW |
667 | (if (not name) |
668 | (setq name | |
669 | (substring file | |
670 | (or (string-match "[^/]*$" file) 0)))) | |
f617db13 MW |
671 | (print (format "uuencode `%s' `%s'" file name)) |
672 | ||
6132bc01 | 673 | ;; Now actually do the thing. |
f617db13 MW |
674 | (call-process "uuencode" file t nil name)) |
675 | ||
676 | (defvar np-file "~/.np" | |
677 | "*Where the `now-playing' file is.") | |
678 | ||
679 | (defun np (&optional arg) | |
680 | "Grabs a `now-playing' string." | |
681 | (interactive) | |
682 | (save-excursion | |
683 | (or arg (progn | |
852cd5fb | 684 | (goto-char (point-max)) |
f617db13 | 685 | (insert "\nNP: ") |
daff679f | 686 | (insert-file-contents np-file))))) |
f617db13 | 687 | |
ae7460d4 MW |
688 | (defun mdw-version-< (ver-a ver-b) |
689 | "Answer whether VER-A is strictly earlier than VER-B. | |
690 | VER-A and VER-B are version numbers, which are strings containing digit | |
691 | sequences separated by `.'." | |
692 | (let* ((la (mapcar (lambda (x) (car (read-from-string x))) | |
693 | (split-string ver-a "\\."))) | |
694 | (lb (mapcar (lambda (x) (car (read-from-string x))) | |
695 | (split-string ver-b "\\.")))) | |
696 | (catch 'done | |
697 | (while t | |
698 | (cond ((null la) (throw 'done lb)) | |
699 | ((null lb) (throw 'done nil)) | |
700 | ((< (car la) (car lb)) (throw 'done t)) | |
701 | ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))))))) | |
702 | ||
c7a8da49 | 703 | (defun mdw-check-autorevert () |
6132bc01 MW |
704 | "Sets global-auto-revert-ignore-buffer appropriately for this buffer. |
705 | This takes into consideration whether it's been found using | |
706 | tramp, which seems to get itself into a twist." | |
46e69f55 MW |
707 | (cond ((not (boundp 'global-auto-revert-ignore-buffer)) |
708 | nil) | |
709 | ((and (buffer-file-name) | |
710 | (fboundp 'tramp-tramp-file-p) | |
c7a8da49 MW |
711 | (tramp-tramp-file-p (buffer-file-name))) |
712 | (unless global-auto-revert-ignore-buffer | |
713 | (setq global-auto-revert-ignore-buffer 'tramp))) | |
714 | ((eq global-auto-revert-ignore-buffer 'tramp) | |
715 | (setq global-auto-revert-ignore-buffer nil)))) | |
716 | ||
717 | (defadvice find-file (after mdw-autorevert activate) | |
718 | (mdw-check-autorevert)) | |
719 | (defadvice write-file (after mdw-autorevert activate) | |
4d9f2d65 | 720 | (mdw-check-autorevert)) |
eae0aa6d | 721 | |
6132bc01 MW |
722 | ;;;-------------------------------------------------------------------------- |
723 | ;;; Dired hacking. | |
5195cbc3 MW |
724 | |
725 | (defadvice dired-maybe-insert-subdir | |
726 | (around mdw-marked-insertion first activate) | |
6132bc01 MW |
727 | "The DIRNAME may be a list of directory names to insert. |
728 | Interactively, if files are marked, then insert all of them. | |
729 | With a numeric prefix argument, select that many entries near | |
730 | point; with a non-numeric prefix argument, prompt for listing | |
731 | options." | |
5195cbc3 MW |
732 | (interactive |
733 | (list (dired-get-marked-files nil | |
734 | (and (integerp current-prefix-arg) | |
735 | current-prefix-arg) | |
736 | #'file-directory-p) | |
737 | (and current-prefix-arg | |
738 | (not (integerp current-prefix-arg)) | |
739 | (read-string "Switches for listing: " | |
740 | (or dired-subdir-switches | |
741 | dired-actual-switches))))) | |
742 | (let ((dirs (ad-get-arg 0))) | |
743 | (dolist (dir (if (listp dirs) dirs (list dirs))) | |
744 | (ad-set-arg 0 dir) | |
745 | ad-do-it))) | |
746 | ||
6132bc01 MW |
747 | ;;;-------------------------------------------------------------------------- |
748 | ;;; URL viewing. | |
a203fba8 MW |
749 | |
750 | (defun mdw-w3m-browse-url (url &optional new-session-p) | |
751 | "Invoke w3m on the URL in its current window, or at least a different one. | |
752 | If NEW-SESSION-P, start a new session." | |
753 | (interactive "sURL: \nP") | |
754 | (save-excursion | |
63fb20c1 MW |
755 | (let ((window (selected-window))) |
756 | (unwind-protect | |
757 | (progn | |
758 | (select-window (or (and (not new-session-p) | |
759 | (get-buffer-window "*w3m*")) | |
760 | (progn | |
761 | (if (one-window-p t) (split-window)) | |
762 | (get-lru-window)))) | |
763 | (w3m-browse-url url new-session-p)) | |
764 | (select-window window))))) | |
a203fba8 MW |
765 | |
766 | (defvar mdw-good-url-browsers | |
a0d16e44 MW |
767 | '(browse-url-mozilla |
768 | browse-url-generic | |
ed5e20a5 | 769 | (w3m . mdw-w3m-browse-url) |
a0d16e44 | 770 | browse-url-w3) |
6132bc01 MW |
771 | "List of good browsers for mdw-good-url-browsers. |
772 | Each item is a browser function name, or a cons (CHECK . FUNC). | |
773 | A symbol FOO stands for (FOO . FOO).") | |
a203fba8 MW |
774 | |
775 | (defun mdw-good-url-browser () | |
6132bc01 MW |
776 | "Return a good URL browser. |
777 | Trundle the list of such things, finding the first item for which | |
778 | CHECK is fboundp, and returning the correponding FUNC." | |
a203fba8 MW |
779 | (let ((bs mdw-good-url-browsers) b check func answer) |
780 | (while (and bs (not answer)) | |
781 | (setq b (car bs) | |
782 | bs (cdr bs)) | |
783 | (if (consp b) | |
784 | (setq check (car b) func (cdr b)) | |
785 | (setq check b func b)) | |
786 | (if (fboundp check) | |
787 | (setq answer func))) | |
788 | answer)) | |
789 | ||
f36cdb77 MW |
790 | (eval-after-load "w3m-search" |
791 | '(progn | |
792 | (dolist | |
793 | (item | |
794 | '(("g" "Google" "http://www.google.co.uk/search?q=%s") | |
795 | ("gd" "Google Directory" | |
796 | "http://www.google.com/search?cat=gwd/Top&q=%s") | |
797 | ("gg" "Google Groups" "http://groups.google.com/groups?q=%s") | |
798 | ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s") | |
799 | ("gi" "Images" "http://images.google.com/images?q=%s") | |
800 | ("rfc" "RFC" | |
801 | "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz") | |
802 | ("wp" "Wikipedia" | |
803 | "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s") | |
804 | ("imdb" "IMDb" "http://www.imdb.com/Find?%s") | |
805 | ("nc-wiki" "nCipher wiki" | |
806 | "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s") | |
807 | ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en") | |
808 | ("lp" "Launchpad bug by number" | |
809 | "https://bugs.launchpad.net/bugs/%s") | |
810 | ("lppkg" "Launchpad bugs by package" | |
811 | "https://bugs.launchpad.net/%s") | |
812 | ("msdn" "MSDN" | |
813 | "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8") | |
814 | ("debbug" "Debian bug by number" | |
815 | "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s") | |
816 | ("debbugpkg" "Debian bugs by package" | |
817 | "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s") | |
818 | ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml"))) | |
819 | (add-to-list 'w3m-search-engine-alist | |
820 | (list (cadr item) (caddr item) nil)) | |
821 | (add-to-list 'w3m-uri-replace-alist | |
822 | (list (concat "\\`" (car item) ":") | |
823 | 'w3m-search-uri-replace | |
824 | (cadr item)))))) | |
825 | ||
6132bc01 MW |
826 | ;;;-------------------------------------------------------------------------- |
827 | ;;; Paragraph filling. | |
f617db13 | 828 | |
6132bc01 | 829 | ;; Useful variables. |
f617db13 MW |
830 | |
831 | (defvar mdw-fill-prefix nil | |
6132bc01 MW |
832 | "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'. |
833 | If there's no fill prefix currently set (by the `fill-prefix' | |
834 | variable) and there's a match from one of the regexps here, it | |
835 | gets used to set the fill-prefix for the current operation. | |
f617db13 | 836 | |
6132bc01 MW |
837 | The variable is a list of items of the form `REGEXP . PREFIX'; if |
838 | the REGEXP matches, the PREFIX is used to set the fill prefix. | |
839 | It in turn is a list of things: | |
f617db13 MW |
840 | |
841 | STRING -- insert a literal string | |
842 | (match . N) -- insert the thing matched by bracketed subexpression N | |
843 | (pad . N) -- a string of whitespace the same width as subexpression N | |
844 | (expr . FORM) -- the result of evaluating FORM") | |
845 | ||
846 | (make-variable-buffer-local 'mdw-fill-prefix) | |
847 | ||
848 | (defvar mdw-hanging-indents | |
10fa2414 | 849 | (concat "\\(\\(" |
f8bfe560 | 850 | "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)" |
10fa2414 MW |
851 | "[ \t]+" |
852 | "\\)?\\)") | |
6132bc01 MW |
853 | "*Standard regexp matching parts of a hanging indent. |
854 | This is mainly useful in `auto-fill-mode'.") | |
f617db13 | 855 | |
6132bc01 | 856 | ;; Setting things up. |
f617db13 MW |
857 | |
858 | (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill)) | |
859 | ||
6132bc01 | 860 | ;; Utility functions. |
f617db13 | 861 | |
cd07f97f MW |
862 | (defun mdw-maybe-tabify (s) |
863 | "Tabify or untabify the string S, according to `indent-tabs-mode'." | |
c736b08b MW |
864 | (let ((tabfun (if indent-tabs-mode #'tabify #'untabify))) |
865 | (with-temp-buffer | |
866 | (save-match-data | |
f617db13 | 867 | (insert s "\n") |
cd07f97f | 868 | (let ((start (point-min)) (end (point-max))) |
c736b08b MW |
869 | (funcall tabfun (point-min) (point-max)) |
870 | (setq s (buffer-substring (point-min) (1- (point-max))))))))) | |
f617db13 MW |
871 | |
872 | (defun mdw-examine-fill-prefixes (l) | |
6132bc01 MW |
873 | "Given a list of dynamic fill prefixes, pick one which matches |
874 | context and return the static fill prefix to use. Point must be | |
875 | at the start of a line, and match data must be saved." | |
f617db13 MW |
876 | (cond ((not l) nil) |
877 | ((looking-at (car (car l))) | |
cd07f97f MW |
878 | (mdw-maybe-tabify (apply #'concat |
879 | (mapcar #'mdw-do-prefix-match | |
880 | (cdr (car l)))))) | |
f617db13 MW |
881 | (t (mdw-examine-fill-prefixes (cdr l))))) |
882 | ||
883 | (defun mdw-maybe-car (p) | |
884 | "If P is a pair, return (car P), otherwise just return P." | |
885 | (if (consp p) (car p) p)) | |
886 | ||
887 | (defun mdw-padding (s) | |
888 | "Return a string the same width as S but made entirely from whitespace." | |
889 | (let* ((l (length s)) (i 0) (n (make-string l ? ))) | |
890 | (while (< i l) | |
891 | (if (= 9 (aref s i)) | |
892 | (aset n i 9)) | |
893 | (setq i (1+ i))) | |
894 | n)) | |
895 | ||
896 | (defun mdw-do-prefix-match (m) | |
6132bc01 MW |
897 | "Expand a dynamic prefix match element. |
898 | See `mdw-fill-prefix' for details." | |
f617db13 MW |
899 | (cond ((not (consp m)) (format "%s" m)) |
900 | ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m)))) | |
901 | ((eq (car m) 'pad) (mdw-padding (match-string | |
902 | (mdw-maybe-car (cdr m))))) | |
903 | ((eq (car m) 'eval) (eval (cdr m))) | |
904 | (t ""))) | |
905 | ||
906 | (defun mdw-choose-dynamic-fill-prefix () | |
907 | "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'." | |
908 | (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix) | |
909 | ((not mdw-fill-prefix) fill-prefix) | |
910 | (t (save-excursion | |
911 | (beginning-of-line) | |
912 | (save-match-data | |
913 | (mdw-examine-fill-prefixes mdw-fill-prefix)))))) | |
914 | ||
915 | (defun do-auto-fill () | |
6132bc01 MW |
916 | "Handle auto-filling, working out a dynamic fill prefix in the |
917 | case where there isn't a sensible static one." | |
f617db13 MW |
918 | (let ((fill-prefix (mdw-choose-dynamic-fill-prefix))) |
919 | (mdw-do-auto-fill))) | |
920 | ||
921 | (defun mdw-fill-paragraph () | |
922 | "Fill paragraph, getting a dynamic fill prefix." | |
923 | (interactive) | |
924 | (let ((fill-prefix (mdw-choose-dynamic-fill-prefix))) | |
925 | (fill-paragraph nil))) | |
926 | ||
927 | (defun mdw-standard-fill-prefix (rx &optional mat) | |
928 | "Set the dynamic fill prefix, handling standard hanging indents and stuff. | |
6132bc01 MW |
929 | This is just a short-cut for setting the thing by hand, and by |
930 | design it doesn't cope with anything approximating a complicated | |
931 | case." | |
f617db13 MW |
932 | (setq mdw-fill-prefix |
933 | `((,(concat rx mdw-hanging-indents) | |
934 | (match . 1) | |
935 | (pad . ,(or mat 2)))))) | |
936 | ||
6132bc01 MW |
937 | ;;;-------------------------------------------------------------------------- |
938 | ;;; Other common declarations. | |
f617db13 | 939 | |
6132bc01 | 940 | ;; Common mode settings. |
f617db13 MW |
941 | |
942 | (defvar mdw-auto-indent t | |
943 | "Whether to indent automatically after a newline.") | |
944 | ||
0e58a7c2 MW |
945 | (defun mdw-whitespace-mode (&optional arg) |
946 | "Turn on/off whitespace mode, but don't highlight trailing space." | |
947 | (interactive "P") | |
948 | (when (and (boundp 'whitespace-style) | |
949 | (fboundp 'whitespace-mode)) | |
950 | (let ((whitespace-style (remove 'trailing whitespace-style))) | |
558fc014 MW |
951 | (whitespace-mode arg)) |
952 | (setq show-trailing-whitespace whitespace-mode))) | |
0e58a7c2 | 953 | |
21beda17 MW |
954 | (defvar mdw-do-misc-mode-hacking nil) |
955 | ||
f617db13 MW |
956 | (defun mdw-misc-mode-config () |
957 | (and mdw-auto-indent | |
958 | (cond ((eq major-mode 'lisp-mode) | |
959 | (local-set-key "\C-m" 'mdw-indent-newline-and-indent)) | |
30c8a8fb MW |
960 | ((or (eq major-mode 'slime-repl-mode) |
961 | (eq major-mode 'asm-mode)) | |
962 | nil) | |
f617db13 MW |
963 | (t |
964 | (local-set-key "\C-m" 'newline-and-indent)))) | |
2e7c6a86 | 965 | (set (make-local-variable 'mdw-do-misc-mode-hacking) t) |
f617db13 | 966 | (local-set-key [C-return] 'newline) |
8a425bd7 | 967 | (make-local-variable 'page-delimiter) |
8cb7626b | 968 | (setq page-delimiter "\f\\|^.*-\\{6\\}.*$") |
f617db13 MW |
969 | (setq comment-column 40) |
970 | (auto-fill-mode 1) | |
971 | (setq fill-column 77) | |
253f61b4 MW |
972 | (and (fboundp 'gtags-mode) |
973 | (gtags-mode)) | |
ddf6e116 | 974 | (if (fboundp 'hs-minor-mode) |
612717ec | 975 | (trap (hs-minor-mode t)) |
ddf6e116 | 976 | (outline-minor-mode t)) |
49b2646e | 977 | (reveal-mode t) |
1e7a9479 | 978 | (trap (turn-on-font-lock))) |
f617db13 | 979 | |
2e7c6a86 | 980 | (defun mdw-post-local-vars-misc-mode-config () |
2717a191 MW |
981 | (when (and mdw-do-misc-mode-hacking |
982 | (not buffer-read-only)) | |
2e7c6a86 MW |
983 | (setq show-trailing-whitespace t) |
984 | (mdw-whitespace-mode 1))) | |
985 | (add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config) | |
ed7b46b9 | 986 | |
2c1ccbb9 MW |
987 | (defmacro mdw-advise-update-angry-fruit-salad (&rest funcs) |
988 | `(progn ,@(mapcar (lambda (func) | |
989 | `(defadvice ,func | |
990 | (after mdw-angry-fruit-salad activate) | |
991 | (when mdw-do-misc-mode-hacking | |
992 | (setq show-trailing-whitespace | |
993 | (not buffer-read-only)) | |
994 | (mdw-whitespace-mode (if buffer-read-only 0 1))))) | |
995 | funcs))) | |
996 | (mdw-advise-update-angry-fruit-salad toggle-read-only | |
997 | read-only-mode | |
998 | view-mode | |
999 | view-mode-enable | |
1000 | view-mode-disable) | |
2717a191 | 1001 | |
253f61b4 | 1002 | (eval-after-load 'gtags |
506bada9 MW |
1003 | '(progn |
1004 | (dolist (key '([mouse-2] [mouse-3])) | |
1005 | (define-key gtags-mode-map key nil)) | |
1006 | (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event) | |
1007 | (define-key gtags-select-mode-map [C-S-mouse-2] | |
1008 | 'gtags-select-tag-by-event) | |
1009 | (dolist (map (list gtags-mode-map gtags-select-mode-map)) | |
1010 | (define-key map [C-S-mouse-3] 'gtags-pop-stack)))) | |
253f61b4 | 1011 | |
6132bc01 | 1012 | ;; Backup file handling. |
2ae647c4 MW |
1013 | |
1014 | (defvar mdw-backup-disable-regexps nil | |
6132bc01 MW |
1015 | "*List of regular expressions: if a file name matches any of |
1016 | these then the file is not backed up.") | |
2ae647c4 MW |
1017 | |
1018 | (defun mdw-backup-enable-predicate (name) | |
6132bc01 MW |
1019 | "[mdw]'s default backup predicate. |
1020 | Allows a backup if the standard predicate would allow it, and it | |
1021 | doesn't match any of the regular expressions in | |
1022 | `mdw-backup-disable-regexps'." | |
2ae647c4 MW |
1023 | (and (normal-backup-enable-predicate name) |
1024 | (let ((answer t) (list mdw-backup-disable-regexps)) | |
1025 | (save-match-data | |
1026 | (while list | |
1027 | (if (string-match (car list) name) | |
1028 | (setq answer nil)) | |
1029 | (setq list (cdr list))) | |
1030 | answer)))) | |
1031 | (setq backup-enable-predicate 'mdw-backup-enable-predicate) | |
1032 | ||
7bb78c67 MW |
1033 | ;; Frame cleanup. |
1034 | ||
1035 | (defun mdw-last-one-out-turn-off-the-lights (frame) | |
1036 | "Disconnect from an X display if this was the last frame on that display." | |
1037 | (let ((frame-display (frame-parameter frame 'display))) | |
1038 | (when (and frame-display | |
1039 | (eq window-system 'x) | |
1040 | (not (some (lambda (fr) | |
7bb78c67 | 1041 | (and (not (eq fr frame)) |
a04d8f3d | 1042 | (string= (frame-parameter fr 'display) |
d70716b5 | 1043 | frame-display))) |
7bb78c67 | 1044 | (frame-list)))) |
7bb78c67 MW |
1045 | (run-with-idle-timer 0 nil #'x-close-connection frame-display)))) |
1046 | (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights) | |
1047 | ||
6132bc01 | 1048 | ;;;-------------------------------------------------------------------------- |
cfa1824e MW |
1049 | ;;; Where is point? |
1050 | ||
1051 | (defvar mdw-point-overlay | |
1052 | (let ((ov (make-overlay 0 0)) | |
1053 | (s ".")) | |
1054 | (overlay-put ov 'priority 2) | |
1055 | (put-text-property 0 1 'display '(left-fringe vertical-bar) s) | |
1056 | (overlay-put ov 'before-string s) | |
1057 | (delete-overlay ov) | |
1058 | ov) | |
1059 | "An overlay used for showing where point is in the selected window.") | |
1060 | ||
1061 | (defun mdw-remove-point-overlay () | |
1062 | "Remove the current-point overlay." | |
1063 | (delete-overlay mdw-point-overlay)) | |
1064 | ||
1065 | (defun mdw-update-point-overlay () | |
1066 | "Mark the current point position with an overlay." | |
1067 | (if (not mdw-point-overlay-mode) | |
1068 | (mdw-remove-point-overlay) | |
1069 | (overlay-put mdw-point-overlay 'window (selected-window)) | |
f3674a83 MW |
1070 | (if (bolp) |
1071 | (move-overlay mdw-point-overlay | |
1072 | (point) (1+ (point)) (current-buffer)) | |
1073 | (move-overlay mdw-point-overlay | |
1074 | (1- (point)) (point) (current-buffer))))) | |
cfa1824e MW |
1075 | |
1076 | (defvar mdw-point-overlay-buffers nil | |
1077 | "List of buffers using `mdw-point-overlay-mode'.") | |
1078 | ||
1079 | (define-minor-mode mdw-point-overlay-mode | |
1080 | "Indicate current line with an overlay." | |
1081 | :global nil | |
1082 | (let ((buffer (current-buffer))) | |
1083 | (setq mdw-point-overlay-buffers | |
1084 | (mapcan (lambda (buf) | |
1085 | (if (and (buffer-live-p buf) | |
1086 | (not (eq buf buffer))) | |
1087 | (list buf))) | |
1088 | mdw-point-overlay-buffers)) | |
1089 | (if mdw-point-overlay-mode | |
1090 | (setq mdw-point-overlay-buffers | |
1091 | (cons buffer mdw-point-overlay-buffers)))) | |
1092 | (cond (mdw-point-overlay-buffers | |
1093 | (add-hook 'pre-command-hook 'mdw-remove-point-overlay) | |
1094 | (add-hook 'post-command-hook 'mdw-update-point-overlay)) | |
1095 | (t | |
1096 | (mdw-remove-point-overlay) | |
1097 | (remove-hook 'pre-command-hook 'mdw-remove-point-overlay) | |
1098 | (remove-hook 'post-command-hook 'mdw-update-point-overlay)))) | |
1099 | ||
1100 | (define-globalized-minor-mode mdw-global-point-overlay-mode | |
1101 | mdw-point-overlay-mode | |
1102 | (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t)))) | |
1103 | ||
1104 | ;;;-------------------------------------------------------------------------- | |
f3674a83 MW |
1105 | ;;; Fullscreen-ness. |
1106 | ||
1107 | (defvar mdw-full-screen-parameters | |
1108 | '((menu-bar-lines . 0) | |
1109 | ;(vertical-scroll-bars . nil) | |
1110 | ) | |
1111 | "Frame parameters to set when making a frame fullscreen.") | |
1112 | ||
1113 | (defvar mdw-full-screen-save | |
1114 | '(width height) | |
1115 | "Extra frame parameters to save when setting fullscreen.") | |
1116 | ||
1117 | (defun mdw-toggle-full-screen (&optional frame) | |
1118 | "Show the FRAME fullscreen." | |
1119 | (interactive) | |
1120 | (when window-system | |
1121 | (cond ((frame-parameter frame 'fullscreen) | |
1122 | (set-frame-parameter frame 'fullscreen nil) | |
1123 | (modify-frame-parameters | |
1124 | nil | |
1125 | (or (frame-parameter frame 'mdw-full-screen-saved) | |
1126 | (mapcar (lambda (assoc) | |
1127 | (assq (car assoc) default-frame-alist)) | |
1128 | mdw-full-screen-parameters)))) | |
1129 | (t | |
1130 | (let ((saved (mapcar (lambda (param) | |
1131 | (cons param (frame-parameter frame param))) | |
1132 | (append (mapcar #'car | |
1133 | mdw-full-screen-parameters) | |
1134 | mdw-full-screen-save)))) | |
1135 | (set-frame-parameter frame 'mdw-full-screen-saved saved)) | |
1136 | (modify-frame-parameters frame mdw-full-screen-parameters) | |
1137 | (set-frame-parameter frame 'fullscreen 'fullboth))))) | |
1138 | ||
1139 | ;;;-------------------------------------------------------------------------- | |
6132bc01 | 1140 | ;;; General fontification. |
f617db13 | 1141 | |
bc149706 MW |
1142 | (make-face 'mdw-virgin-face) |
1143 | ||
1e7a9479 MW |
1144 | (defmacro mdw-define-face (name &rest body) |
1145 | "Define a face, and make sure it's actually set as the definition." | |
1146 | (declare (indent 1) | |
1147 | (debug 0)) | |
1148 | `(progn | |
bc149706 | 1149 | (copy-face 'mdw-virgin-face ',name) |
1e7a9479 MW |
1150 | (defvar ,name ',name) |
1151 | (put ',name 'face-defface-spec ',body) | |
88cb9c2b | 1152 | (face-spec-set ',name ',body nil))) |
1e7a9479 MW |
1153 | |
1154 | (mdw-define-face default | |
1155 | (((type w32)) :family "courier new" :height 85) | |
caa63513 | 1156 | (((type x)) :family "6x13" :foundry "trad" :height 130) |
db10ce0a MW |
1157 | (((type color)) :foreground "white" :background "black") |
1158 | (t nil)) | |
1e7a9479 MW |
1159 | (mdw-define-face fixed-pitch |
1160 | (((type w32)) :family "courier new" :height 85) | |
caa63513 | 1161 | (((type x)) :family "6x13" :foundry "trad" :height 130) |
1e7a9479 | 1162 | (t :foreground "white" :background "black")) |
e8ea88ba | 1163 | (if (mdw-emacs-version-p 23) |
c383eb8a MW |
1164 | (mdw-define-face variable-pitch |
1165 | (((type x)) :family "sans" :height 100)) | |
1166 | (mdw-define-face variable-pitch | |
3f001ff6 | 1167 | (((type x)) :family "helvetica" :height 90))) |
1e7a9479 | 1168 | (mdw-define-face region |
db10ce0a MW |
1169 | (((type tty) (class color)) :background "blue") |
1170 | (((type tty) (class mono)) :inverse-video t) | |
1171 | (t :background "grey30")) | |
fa156643 MW |
1172 | (mdw-define-face match |
1173 | (((type tty) (class color)) :background "blue") | |
1174 | (((type tty) (class mono)) :inverse-video t) | |
1175 | (t :background "blue")) | |
c6fe19d5 MW |
1176 | (mdw-define-face mc/cursor-face |
1177 | (((type tty) (class mono)) :inverse-video t) | |
1178 | (t :background "red")) | |
1e7a9479 MW |
1179 | (mdw-define-face minibuffer-prompt |
1180 | (t :weight bold)) | |
1181 | (mdw-define-face mode-line | |
db10ce0a MW |
1182 | (((class color)) :foreground "blue" :background "yellow" |
1183 | :box (:line-width 1 :style released-button)) | |
1184 | (t :inverse-video t)) | |
1e7a9479 | 1185 | (mdw-define-face mode-line-inactive |
db10ce0a MW |
1186 | (((class color)) :foreground "yellow" :background "blue" |
1187 | :box (:line-width 1 :style released-button)) | |
1188 | (t :inverse-video t)) | |
ae0a853f MW |
1189 | (mdw-define-face nobreak-space |
1190 | (((type tty))) | |
1191 | (t :inherit escape-glyph :underline t)) | |
1e7a9479 MW |
1192 | (mdw-define-face scroll-bar |
1193 | (t :foreground "black" :background "lightgrey")) | |
1194 | (mdw-define-face fringe | |
1195 | (t :foreground "yellow")) | |
c383eb8a | 1196 | (mdw-define-face show-paren-match |
db10ce0a MW |
1197 | (((class color)) :background "darkgreen") |
1198 | (t :underline t)) | |
c383eb8a | 1199 | (mdw-define-face show-paren-mismatch |
db10ce0a MW |
1200 | (((class color)) :background "red") |
1201 | (t :inverse-video t)) | |
1e7a9479 | 1202 | (mdw-define-face highlight |
b31f422b MW |
1203 | (((type x) (class color)) :background "DarkSeaGreen4") |
1204 | (((type tty) (class color)) :background "cyan") | |
db10ce0a | 1205 | (t :inverse-video t)) |
1e7a9479 MW |
1206 | |
1207 | (mdw-define-face holiday-face | |
1208 | (t :background "red")) | |
1209 | (mdw-define-face calendar-today-face | |
1210 | (t :foreground "yellow" :weight bold)) | |
1211 | ||
1212 | (mdw-define-face comint-highlight-prompt | |
1213 | (t :weight bold)) | |
5fd055c2 MW |
1214 | (mdw-define-face comint-highlight-input |
1215 | (t nil)) | |
1e7a9479 | 1216 | |
e0e2aca3 MW |
1217 | (mdw-define-face dired-directory |
1218 | (t :foreground "cyan" :weight bold)) | |
1219 | (mdw-define-face dired-symlink | |
1220 | (t :foreground "cyan")) | |
1221 | (mdw-define-face dired-perm-write | |
1222 | (t nil)) | |
1223 | ||
1e7a9479 | 1224 | (mdw-define-face trailing-whitespace |
db10ce0a MW |
1225 | (((class color)) :background "red") |
1226 | (t :inverse-video t)) | |
1e7a9479 MW |
1227 | (mdw-define-face mdw-punct-face |
1228 | (((type tty)) :foreground "yellow") (t :foreground "burlywood2")) | |
1229 | (mdw-define-face mdw-number-face | |
1230 | (t :foreground "yellow")) | |
52bcde59 | 1231 | (mdw-define-face mdw-trivial-face) |
1e7a9479 | 1232 | (mdw-define-face font-lock-function-name-face |
c383eb8a | 1233 | (t :slant italic)) |
1e7a9479 MW |
1234 | (mdw-define-face font-lock-keyword-face |
1235 | (t :weight bold)) | |
1236 | (mdw-define-face font-lock-constant-face | |
1237 | (t :slant italic)) | |
1238 | (mdw-define-face font-lock-builtin-face | |
1239 | (t :weight bold)) | |
07965a39 MW |
1240 | (mdw-define-face font-lock-type-face |
1241 | (t :weight bold :slant italic)) | |
1e7a9479 MW |
1242 | (mdw-define-face font-lock-reference-face |
1243 | (t :weight bold)) | |
1244 | (mdw-define-face font-lock-variable-name-face | |
1245 | (t :slant italic)) | |
1246 | (mdw-define-face font-lock-comment-delimiter-face | |
db10ce0a MW |
1247 | (((class mono)) :weight bold) |
1248 | (((type tty) (class color)) :foreground "green") | |
1249 | (t :slant italic :foreground "SeaGreen1")) | |
1e7a9479 | 1250 | (mdw-define-face font-lock-comment-face |
db10ce0a MW |
1251 | (((class mono)) :weight bold) |
1252 | (((type tty) (class color)) :foreground "green") | |
1253 | (t :slant italic :foreground "SeaGreen1")) | |
1e7a9479 | 1254 | (mdw-define-face font-lock-string-face |
db10ce0a MW |
1255 | (((class mono)) :weight bold) |
1256 | (((class color)) :foreground "SkyBlue1")) | |
898c7efb | 1257 | |
1e7a9479 MW |
1258 | (mdw-define-face message-separator |
1259 | (t :background "red" :foreground "white" :weight bold)) | |
1260 | (mdw-define-face message-cited-text | |
1261 | (default :slant italic) | |
4790fcb7 | 1262 | (((type tty)) :foreground "cyan") (t :foreground "SkyBlue1")) |
1e7a9479 | 1263 | (mdw-define-face message-header-cc |
4790fcb7 | 1264 | (default :slant italic) |
1e7a9479 MW |
1265 | (((type tty)) :foreground "green") (t :foreground "SeaGreen1")) |
1266 | (mdw-define-face message-header-newsgroups | |
4790fcb7 | 1267 | (default :slant italic) |
1e7a9479 MW |
1268 | (((type tty)) :foreground "green") (t :foreground "SeaGreen1")) |
1269 | (mdw-define-face message-header-subject | |
1e7a9479 MW |
1270 | (((type tty)) :foreground "green") (t :foreground "SeaGreen1")) |
1271 | (mdw-define-face message-header-to | |
1e7a9479 MW |
1272 | (((type tty)) :foreground "green") (t :foreground "SeaGreen1")) |
1273 | (mdw-define-face message-header-xheader | |
4790fcb7 | 1274 | (default :slant italic) |
1e7a9479 MW |
1275 | (((type tty)) :foreground "green") (t :foreground "SeaGreen1")) |
1276 | (mdw-define-face message-header-other | |
4790fcb7 | 1277 | (default :slant italic) |
1e7a9479 MW |
1278 | (((type tty)) :foreground "green") (t :foreground "SeaGreen1")) |
1279 | (mdw-define-face message-header-name | |
4790fcb7 | 1280 | (default :weight bold) |
1e7a9479 | 1281 | (((type tty)) :foreground "green") (t :foreground "SeaGreen1")) |
4790fcb7 | 1282 | |
69498691 MW |
1283 | (mdw-define-face which-func |
1284 | (t nil)) | |
1e7a9479 | 1285 | |
4790fcb7 MW |
1286 | (mdw-define-face gnus-header-name |
1287 | (default :weight bold) | |
1288 | (((type tty)) :foreground "green") (t :foreground "SeaGreen1")) | |
1289 | (mdw-define-face gnus-header-subject | |
1290 | (((type tty)) :foreground "green") (t :foreground "SeaGreen1")) | |
1291 | (mdw-define-face gnus-header-from | |
1292 | (((type tty)) :foreground "green") (t :foreground "SeaGreen1")) | |
1293 | (mdw-define-face gnus-header-to | |
1294 | (((type tty)) :foreground "green") (t :foreground "SeaGreen1")) | |
1295 | (mdw-define-face gnus-header-content | |
1296 | (default :slant italic) | |
1297 | (((type tty)) :foreground "green") (t :foreground "SeaGreen1")) | |
1298 | ||
1299 | (mdw-define-face gnus-cite-1 | |
1300 | (((type tty)) :foreground "cyan") (t :foreground "SkyBlue1")) | |
1301 | (mdw-define-face gnus-cite-2 | |
1302 | (((type tty)) :foreground "blue") (t :foreground "RoyalBlue2")) | |
1303 | (mdw-define-face gnus-cite-3 | |
1304 | (((type tty)) :foreground "magenta") (t :foreground "MediumOrchid")) | |
1305 | (mdw-define-face gnus-cite-4 | |
1306 | (((type tty)) :foreground "red") (t :foreground "firebrick2")) | |
1307 | (mdw-define-face gnus-cite-5 | |
1308 | (((type tty)) :foreground "yellow") (t :foreground "burlywood2")) | |
1309 | (mdw-define-face gnus-cite-6 | |
1310 | (((type tty)) :foreground "green") (t :foreground "SeaGreen1")) | |
1311 | (mdw-define-face gnus-cite-7 | |
1312 | (((type tty)) :foreground "cyan") (t :foreground "SlateBlue1")) | |
1313 | (mdw-define-face gnus-cite-8 | |
1314 | (((type tty)) :foreground "blue") (t :foreground "RoyalBlue2")) | |
1315 | (mdw-define-face gnus-cite-9 | |
1316 | (((type tty)) :foreground "magenta") (t :foreground "purple2")) | |
1317 | (mdw-define-face gnus-cite-10 | |
1318 | (((type tty)) :foreground "red") (t :foreground "DarkOrange2")) | |
1319 | (mdw-define-face gnus-cite-11 | |
1320 | (t :foreground "grey")) | |
1321 | ||
2f238de8 MW |
1322 | (mdw-define-face diff-header |
1323 | (t nil)) | |
1e7a9479 MW |
1324 | (mdw-define-face diff-index |
1325 | (t :weight bold)) | |
1326 | (mdw-define-face diff-file-header | |
1327 | (t :weight bold)) | |
1328 | (mdw-define-face diff-hunk-header | |
1329 | (t :foreground "SkyBlue1")) | |
1330 | (mdw-define-face diff-function | |
1331 | (t :foreground "SkyBlue1" :weight bold)) | |
1332 | (mdw-define-face diff-header | |
1333 | (t :background "grey10")) | |
1334 | (mdw-define-face diff-added | |
1335 | (t :foreground "green")) | |
1336 | (mdw-define-face diff-removed | |
1337 | (t :foreground "red")) | |
5fd055c2 MW |
1338 | (mdw-define-face diff-context |
1339 | (t nil)) | |
2f238de8 | 1340 | (mdw-define-face diff-refine-change |
b31f422b MW |
1341 | (((class color) (type x)) :background "RoyalBlue4") |
1342 | (t :underline t)) | |
1e7a9479 | 1343 | |
ad305d7e MW |
1344 | (mdw-define-face dylan-header-background |
1345 | (((class color) (type x)) :background "NavyBlue") | |
1346 | (t :background "blue")) | |
1347 | ||
df082bab MW |
1348 | (mdw-define-face magit-diff-add |
1349 | (t :foreground "green")) | |
1350 | (mdw-define-face magit-diff-del | |
1351 | (t :foreground "red")) | |
1352 | (mdw-define-face magit-diff-file-header | |
1353 | (t :weight bold)) | |
1354 | (mdw-define-face magit-diff-hunk-header | |
1355 | (t :foreground "SkyBlue1")) | |
fb690b64 MW |
1356 | (mdw-define-face magit-item-highlight |
1357 | (((type tty)) :background "blue") | |
cc71d815 | 1358 | (t :background "grey11")) |
8afc6956 MW |
1359 | (mdw-define-face magit-log-head-label-remote |
1360 | (((type tty)) :background "cyan" :foreground "green") | |
1361 | (t :background "grey11" :foreground "DarkSeaGreen2" :box t)) | |
1362 | (mdw-define-face magit-log-head-label-local | |
1363 | (((type tty)) :background "cyan" :foreground "yellow") | |
1364 | (t :background "grey11" :foreground "LightSkyBlue1" :box t)) | |
1365 | (mdw-define-face magit-log-head-label-tags | |
1366 | (((type tty)) :background "red" :foreground "yellow") | |
1367 | (t :background "LemonChiffon1" :foreground "goldenrod4" :box t)) | |
1368 | (mdw-define-face magit-log-graph | |
1369 | (((type tty)) :foreground "magenta") | |
1370 | (t :foreground "grey80")) | |
df082bab | 1371 | |
e1b8de18 MW |
1372 | (mdw-define-face erc-input-face |
1373 | (t :foreground "red")) | |
1374 | ||
1e7a9479 MW |
1375 | (mdw-define-face woman-bold |
1376 | (t :weight bold)) | |
1377 | (mdw-define-face woman-italic | |
1378 | (t :slant italic)) | |
1379 | ||
5a83259f MW |
1380 | (eval-after-load "rst" |
1381 | '(progn | |
1382 | (mdw-define-face rst-level-1-face | |
1383 | (t :foreground "SkyBlue1" :weight bold)) | |
1384 | (mdw-define-face rst-level-2-face | |
1385 | (t :foreground "SeaGreen1" :weight bold)) | |
1386 | (mdw-define-face rst-level-3-face | |
1387 | (t :weight bold)) | |
1388 | (mdw-define-face rst-level-4-face | |
1389 | (t :slant italic)) | |
1390 | (mdw-define-face rst-level-5-face | |
1391 | (t :underline t)) | |
1392 | (mdw-define-face rst-level-6-face | |
1393 | ()))) | |
4f251391 | 1394 | |
1e7a9479 MW |
1395 | (mdw-define-face p4-depot-added-face |
1396 | (t :foreground "green")) | |
1397 | (mdw-define-face p4-depot-branch-op-face | |
1398 | (t :foreground "yellow")) | |
1399 | (mdw-define-face p4-depot-deleted-face | |
1400 | (t :foreground "red")) | |
1401 | (mdw-define-face p4-depot-unmapped-face | |
1402 | (t :foreground "SkyBlue1")) | |
1403 | (mdw-define-face p4-diff-change-face | |
1404 | (t :foreground "yellow")) | |
1405 | (mdw-define-face p4-diff-del-face | |
1406 | (t :foreground "red")) | |
1407 | (mdw-define-face p4-diff-file-face | |
1408 | (t :foreground "SkyBlue1")) | |
1409 | (mdw-define-face p4-diff-head-face | |
1410 | (t :background "grey10")) | |
1411 | (mdw-define-face p4-diff-ins-face | |
1412 | (t :foreground "green")) | |
1413 | ||
4c39e530 MW |
1414 | (mdw-define-face w3m-anchor-face |
1415 | (t :foreground "SkyBlue1" :underline t)) | |
1416 | (mdw-define-face w3m-arrived-anchor-face | |
1417 | (t :foreground "SkyBlue1" :underline t)) | |
1418 | ||
1e7a9479 MW |
1419 | (mdw-define-face whizzy-slice-face |
1420 | (t :background "grey10")) | |
1421 | (mdw-define-face whizzy-error-face | |
1422 | (t :background "darkred")) | |
f617db13 | 1423 | |
5fedb342 MW |
1424 | ;; Ellipses used to indicate hidden text (and similar). |
1425 | (mdw-define-face mdw-ellipsis-face | |
1426 | (((type tty)) :foreground "blue") (t :foreground "grey60")) | |
c11ac343 | 1427 | (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face)) |
a8a7976a | 1428 | (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face)) |
c11ac343 MW |
1429 | (dot (make-glyph-code ?. 'mdw-ellipsis-face)) |
1430 | (bar (make-glyph-code ?| mdw-ellipsis-face))) | |
1431 | (set-display-table-slot standard-display-table 0 dollar) | |
1432 | (set-display-table-slot standard-display-table 1 backslash) | |
5fedb342 | 1433 | (set-display-table-slot standard-display-table 4 |
c11ac343 MW |
1434 | (vector dot dot dot)) |
1435 | (set-display-table-slot standard-display-table 5 bar)) | |
5fedb342 | 1436 | |
6132bc01 MW |
1437 | ;;;-------------------------------------------------------------------------- |
1438 | ;;; C programming configuration. | |
f617db13 | 1439 | |
6132bc01 | 1440 | ;; Make C indentation nice. |
f617db13 | 1441 | |
f50c1bed MW |
1442 | (defun mdw-c-lineup-arglist (langelem) |
1443 | "Hack for DWIMmery in c-lineup-arglist." | |
1444 | (if (save-excursion | |
1445 | (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element))) | |
1446 | 0 | |
1447 | (c-lineup-arglist langelem))) | |
1448 | ||
1449 | (defun mdw-c-indent-extern-mumble (langelem) | |
1450 | "Indent `extern \"...\" {' lines." | |
1451 | (save-excursion | |
1452 | (back-to-indentation) | |
1453 | (if (looking-at | |
1454 | "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{") | |
1455 | c-basic-offset | |
1456 | nil))) | |
1457 | ||
b521d36a MW |
1458 | (defun mdw-c-indent-arglist-nested (langelem) |
1459 | "Indent continued argument lists. | |
1460 | If we've nested more than one argument list, then only introduce a single | |
1461 | indentation anyway." | |
1462 | (let ((context c-syntactic-context) | |
1463 | (pos (c-langelem-2nd-pos c-syntactic-element)) | |
1464 | (should-indent-p t)) | |
1465 | (while (and context | |
1466 | (eq (caar context) 'arglist-cont-nonempty)) | |
1467 | (when (and (= (caddr (pop context)) pos) | |
1468 | context | |
1469 | (memq (caar context) '(arglist-intro | |
1470 | arglist-cont-nonempty))) | |
1471 | (setq should-indent-p nil))) | |
1472 | (if should-indent-p '+ 0))) | |
1473 | ||
c56296d0 MW |
1474 | (defvar mdw-define-c-styles-hook nil |
1475 | "Hook run when `cc-mode' starts up to define styles.") | |
1476 | ||
1477 | (defmacro mdw-define-c-style (name &rest assocs) | |
1478 | "Define a C style, called NAME (a symbol), setting ASSOCs. | |
1479 | A function, named `mdw-define-c-style/NAME', is defined to actually install | |
1480 | the style using `c-add-style', and added to the hook | |
1481 | `mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is | |
1482 | set." | |
1483 | (declare (indent defun)) | |
1484 | (let* ((name-string (symbol-name name)) | |
1485 | (func (intern (concat "mdw-define-c-style/" name-string)))) | |
1486 | `(progn | |
1487 | (defun ,func () (c-add-style ,name-string ',assocs)) | |
1488 | (and (featurep 'cc-mode) (,func)) | |
1489 | (add-hook 'mdw-define-c-styles-hook ',func)))) | |
1490 | ||
1491 | (eval-after-load "cc-mode" | |
1492 | '(run-hooks 'mdw-define-c-styles-hook)) | |
1493 | ||
b521d36a MW |
1494 | (mdw-define-c-style mdw-trustonic-c |
1495 | (c-basic-offset . 4) | |
1496 | (comment-column . 0) | |
1497 | (c-indent-comment-alist (anchored-comment . (column . 0)) | |
1498 | (end-block . (space . 1)) | |
1499 | (cpp-end-block . (space . 1)) | |
1500 | (other . (space . 1))) | |
1501 | (c-class-key . "class") | |
1502 | (c-backslash-column . 0) | |
1503 | (c-auto-align-backslashes . nil) | |
1504 | (c-label-minimum-indentation . 0) | |
1505 | (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block)) | |
1506 | (defun-open . (add 0 c-indent-one-line-block)) | |
1507 | (arglist-cont-nonempty . mdw-c-indent-arglist-nested) | |
1508 | (topmost-intro . mdw-c-indent-extern-mumble) | |
1509 | (cpp-define-intro . 0) | |
1510 | (knr-argdecl . 0) | |
1511 | (inextern-lang . [0]) | |
1512 | (label . 0) | |
1513 | (case-label . +) | |
1514 | (access-label . -) | |
1515 | (inclass . +) | |
1516 | (inline-open . ++) | |
1517 | (statement-cont . +) | |
1518 | (statement-case-intro . +))) | |
1519 | ||
c56296d0 MW |
1520 | (mdw-define-c-style mdw-c |
1521 | (c-basic-offset . 2) | |
1522 | (comment-column . 40) | |
1523 | (c-class-key . "class") | |
1524 | (c-backslash-column . 72) | |
1525 | (c-label-minimum-indentation . 0) | |
1526 | (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block)) | |
1527 | (defun-open . (add 0 c-indent-one-line-block)) | |
1528 | (arglist-cont-nonempty . mdw-c-lineup-arglist) | |
1529 | (topmost-intro . mdw-c-indent-extern-mumble) | |
1530 | (cpp-define-intro . 0) | |
1531 | (knr-argdecl . 0) | |
1532 | (inextern-lang . [0]) | |
1533 | (label . 0) | |
1534 | (case-label . +) | |
1535 | (access-label . -) | |
1536 | (inclass . +) | |
1537 | (inline-open . ++) | |
1538 | (statement-cont . +) | |
1539 | (statement-case-intro . +))) | |
1540 | ||
1541 | (defun mdw-set-default-c-style (modes style) | |
1542 | "Update the default CC Mode style for MODES to be STYLE. | |
1543 | ||
1544 | MODES may be a list of major mode names or a singleton. STYLE is a style | |
1545 | name, as a symbol." | |
1546 | (let ((modes (if (listp modes) modes (list modes))) | |
1547 | (style (symbol-name style))) | |
1548 | (setq c-default-style | |
1549 | (append (mapcar (lambda (mode) | |
1550 | (cons mode style)) | |
1551 | modes) | |
1552 | (remove-if (lambda (assoc) | |
1553 | (memq (car assoc) modes)) | |
1554 | (if (listp c-default-style) | |
1555 | c-default-style | |
1556 | (list (cons 'other c-default-style)))))))) | |
1557 | (setq c-default-style "mdw-c") | |
1558 | ||
1559 | (mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c) | |
f617db13 | 1560 | |
0e7d960b MW |
1561 | (defvar mdw-c-comment-fill-prefix |
1562 | `((,(concat "\\([ \t]*/?\\)" | |
1563 | "\\(\*\\|//]\\)" | |
1564 | "\\([ \t]*\\)" | |
1565 | "\\([A-Za-z]+:[ \t]*\\)?" | |
1566 | mdw-hanging-indents) | |
1567 | (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5))) | |
1568 | "Fill prefix matching C comments (both kinds).") | |
1569 | ||
f617db13 MW |
1570 | (defun mdw-fontify-c-and-c++ () |
1571 | ||
6132bc01 | 1572 | ;; Fiddle with some syntax codes. |
f617db13 MW |
1573 | (modify-syntax-entry ?* ". 23") |
1574 | (modify-syntax-entry ?/ ". 124b") | |
1575 | (modify-syntax-entry ?\n "> b") | |
1576 | ||
6132bc01 | 1577 | ;; Other stuff. |
c56296d0 | 1578 | (setq mdw-fill-prefix mdw-c-comment-fill-prefix) |
f617db13 | 1579 | |
6132bc01 | 1580 | ;; Now define things to be fontified. |
02109a0d | 1581 | (make-local-variable 'font-lock-keywords) |
f617db13 | 1582 | (let ((c-keywords |
fe307a8c MW |
1583 | (mdw-regexps "alignas" ;C11 macro, C++11 |
1584 | "alignof" ;C++11 | |
1585 | "and" ;C++, C95 macro | |
0681f29e | 1586 | "and_eq" ;C++, C95 macro |
7b84c078 | 1587 | "asm" ;K&R, C++, GCC |
fe307a8c | 1588 | "atomic" ;C11 macro, C++11 template type |
26f18bd1 | 1589 | "auto" ;K&R, C89 |
0681f29e MW |
1590 | "bitand" ;C++, C95 macro |
1591 | "bitor" ;C++, C95 macro | |
d4783d9c | 1592 | "bool" ;C++, C99 macro |
26f18bd1 MW |
1593 | "break" ;K&R, C89 |
1594 | "case" ;K&R, C89 | |
1595 | "catch" ;C++ | |
1596 | "char" ;K&R, C89 | |
fe307a8c MW |
1597 | "char16_t" ;C++11, C11 library type |
1598 | "char32_t" ;C++11, C11 library type | |
26f18bd1 | 1599 | "class" ;C++ |
d4783d9c | 1600 | "complex" ;C99 macro, C++ template type |
0681f29e | 1601 | "compl" ;C++, C95 macro |
26f18bd1 | 1602 | "const" ;C89 |
fe307a8c | 1603 | "constexpr" ;C++11 |
26f18bd1 MW |
1604 | "const_cast" ;C++ |
1605 | "continue" ;K&R, C89 | |
fe307a8c | 1606 | "decltype" ;C++11 |
26f18bd1 MW |
1607 | "defined" ;C89 preprocessor |
1608 | "default" ;K&R, C89 | |
1609 | "delete" ;C++ | |
1610 | "do" ;K&R, C89 | |
1611 | "double" ;K&R, C89 | |
1612 | "dynamic_cast" ;C++ | |
1613 | "else" ;K&R, C89 | |
1614 | ;; "entry" ;K&R -- never used | |
1615 | "enum" ;C89 | |
1616 | "explicit" ;C++ | |
1617 | "export" ;C++ | |
1618 | "extern" ;K&R, C89 | |
1619 | "float" ;K&R, C89 | |
1620 | "for" ;K&R, C89 | |
1621 | ;; "fortran" ;K&R | |
1622 | "friend" ;C++ | |
1623 | "goto" ;K&R, C89 | |
1624 | "if" ;K&R, C89 | |
d4783d9c MW |
1625 | "imaginary" ;C99 macro |
1626 | "inline" ;C++, C99, GCC | |
26f18bd1 MW |
1627 | "int" ;K&R, C89 |
1628 | "long" ;K&R, C89 | |
1629 | "mutable" ;C++ | |
1630 | "namespace" ;C++ | |
1631 | "new" ;C++ | |
fe307a8c MW |
1632 | "noexcept" ;C++11 |
1633 | "noreturn" ;C11 macro | |
0681f29e MW |
1634 | "not" ;C++, C95 macro |
1635 | "not_eq" ;C++, C95 macro | |
fe307a8c | 1636 | "nullptr" ;C++11 |
26f18bd1 | 1637 | "operator" ;C++ |
0681f29e MW |
1638 | "or" ;C++, C95 macro |
1639 | "or_eq" ;C++, C95 macro | |
26f18bd1 MW |
1640 | "private" ;C++ |
1641 | "protected" ;C++ | |
1642 | "public" ;C++ | |
1643 | "register" ;K&R, C89 | |
8d6d55b9 | 1644 | "reinterpret_cast" ;C++ |
d4783d9c | 1645 | "restrict" ;C99 |
8d6d55b9 MW |
1646 | "return" ;K&R, C89 |
1647 | "short" ;K&R, C89 | |
1648 | "signed" ;C89 | |
1649 | "sizeof" ;K&R, C89 | |
1650 | "static" ;K&R, C89 | |
fe307a8c | 1651 | "static_assert" ;C11 macro, C++11 |
8d6d55b9 MW |
1652 | "static_cast" ;C++ |
1653 | "struct" ;K&R, C89 | |
1654 | "switch" ;K&R, C89 | |
1655 | "template" ;C++ | |
8d6d55b9 | 1656 | "throw" ;C++ |
8d6d55b9 | 1657 | "try" ;C++ |
fe307a8c | 1658 | "thread_local" ;C11 macro, C++11 |
8d6d55b9 MW |
1659 | "typedef" ;C89 |
1660 | "typeid" ;C++ | |
1661 | "typeof" ;GCC | |
1662 | "typename" ;C++ | |
1663 | "union" ;K&R, C89 | |
1664 | "unsigned" ;K&R, C89 | |
1665 | "using" ;C++ | |
1666 | "virtual" ;C++ | |
1667 | "void" ;C89 | |
1668 | "volatile" ;C89 | |
1669 | "wchar_t" ;C++, C89 library type | |
1670 | "while" ;K&R, C89 | |
0681f29e MW |
1671 | "xor" ;C++, C95 macro |
1672 | "xor_eq" ;C++, C95 macro | |
fe307a8c MW |
1673 | "_Alignas" ;C11 |
1674 | "_Alignof" ;C11 | |
1675 | "_Atomic" ;C11 | |
d4783d9c MW |
1676 | "_Bool" ;C99 |
1677 | "_Complex" ;C99 | |
fe307a8c | 1678 | "_Generic" ;C11 |
d4783d9c | 1679 | "_Imaginary" ;C99 |
fe307a8c | 1680 | "_Noreturn" ;C11 |
d4783d9c | 1681 | "_Pragma" ;C99 preprocessor |
fe307a8c MW |
1682 | "_Static_assert" ;C11 |
1683 | "_Thread_local" ;C11 | |
8d6d55b9 MW |
1684 | "__alignof__" ;GCC |
1685 | "__asm__" ;GCC | |
1686 | "__attribute__" ;GCC | |
1687 | "__complex__" ;GCC | |
1688 | "__const__" ;GCC | |
1689 | "__extension__" ;GCC | |
1690 | "__imag__" ;GCC | |
1691 | "__inline__" ;GCC | |
1692 | "__label__" ;GCC | |
1693 | "__real__" ;GCC | |
1694 | "__signed__" ;GCC | |
1695 | "__typeof__" ;GCC | |
1696 | "__volatile__" ;GCC | |
1697 | )) | |
165cecf8 | 1698 | (c-constants |
26f18bd1 | 1699 | (mdw-regexps "false" ;C++, C99 macro |
165cecf8 | 1700 | "this" ;C++ |
26f18bd1 | 1701 | "true" ;C++, C99 macro |
165cecf8 | 1702 | )) |
f617db13 | 1703 | (preprocessor-keywords |
8d6d55b9 MW |
1704 | (mdw-regexps "assert" "define" "elif" "else" "endif" "error" |
1705 | "ident" "if" "ifdef" "ifndef" "import" "include" | |
1706 | "line" "pragma" "unassert" "undef" "warning")) | |
f617db13 | 1707 | (objc-keywords |
8d6d55b9 MW |
1708 | (mdw-regexps "class" "defs" "encode" "end" "implementation" |
1709 | "interface" "private" "protected" "protocol" "public" | |
1710 | "selector"))) | |
f617db13 MW |
1711 | |
1712 | (setq font-lock-keywords | |
1713 | (list | |
f617db13 | 1714 | |
6132bc01 | 1715 | ;; Fontify include files as strings. |
f617db13 MW |
1716 | (list (concat "^[ \t]*\\#[ \t]*" |
1717 | "\\(include\\|import\\)" | |
1718 | "[ \t]*\\(<[^>]+\\(>\\|\\)\\)") | |
1719 | '(2 font-lock-string-face)) | |
1720 | ||
6132bc01 | 1721 | ;; Preprocessor directives are `references'?. |
f617db13 MW |
1722 | (list (concat "^\\([ \t]*#[ \t]*\\(\\(" |
1723 | preprocessor-keywords | |
1724 | "\\)\\>\\|[0-9]+\\|$\\)\\)") | |
1725 | '(1 font-lock-keyword-face)) | |
1726 | ||
6132bc01 | 1727 | ;; Handle the keywords defined above. |
f617db13 MW |
1728 | (list (concat "@\\<\\(" objc-keywords "\\)\\>") |
1729 | '(0 font-lock-keyword-face)) | |
1730 | ||
1731 | (list (concat "\\<\\(" c-keywords "\\)\\>") | |
1732 | '(0 font-lock-keyword-face)) | |
1733 | ||
165cecf8 MW |
1734 | (list (concat "\\<\\(" c-constants "\\)\\>") |
1735 | '(0 font-lock-variable-name-face)) | |
1736 | ||
6132bc01 | 1737 | ;; Handle numbers too. |
f617db13 MW |
1738 | ;; |
1739 | ;; This looks strange, I know. It corresponds to the | |
1740 | ;; preprocessor's idea of what a number looks like, rather than | |
1741 | ;; anything sensible. | |
f617db13 MW |
1742 | (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)" |
1743 | "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*") | |
1744 | '(0 mdw-number-face)) | |
1745 | ||
6132bc01 | 1746 | ;; And anything else is punctuation. |
f617db13 | 1747 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" |
2e7c6a86 | 1748 | '(0 mdw-punct-face)))))) |
f617db13 | 1749 | |
6132bc01 MW |
1750 | ;;;-------------------------------------------------------------------------- |
1751 | ;;; AP calc mode. | |
f617db13 | 1752 | |
e7186cbe MW |
1753 | (define-derived-mode apcalc-mode c-mode "AP Calc" |
1754 | "Major mode for editing Calc code.") | |
f617db13 MW |
1755 | |
1756 | (defun mdw-fontify-apcalc () | |
1757 | ||
6132bc01 | 1758 | ;; Fiddle with some syntax codes. |
f617db13 MW |
1759 | (modify-syntax-entry ?* ". 23") |
1760 | (modify-syntax-entry ?/ ". 14") | |
1761 | ||
6132bc01 | 1762 | ;; Other stuff. |
f617db13 MW |
1763 | (setq comment-start "/* ") |
1764 | (setq comment-end " */") | |
0e7d960b | 1765 | (setq mdw-fill-prefix mdw-c-comment-fill-prefix) |
f617db13 | 1766 | |
6132bc01 | 1767 | ;; Now define things to be fontified. |
02109a0d | 1768 | (make-local-variable 'font-lock-keywords) |
f617db13 | 1769 | (let ((c-keywords |
8d6d55b9 MW |
1770 | (mdw-regexps "break" "case" "cd" "continue" "define" "default" |
1771 | "do" "else" "exit" "for" "global" "goto" "help" "if" | |
1772 | "local" "mat" "obj" "print" "quit" "read" "return" | |
1773 | "show" "static" "switch" "while" "write"))) | |
f617db13 MW |
1774 | |
1775 | (setq font-lock-keywords | |
1776 | (list | |
f617db13 | 1777 | |
6132bc01 | 1778 | ;; Handle the keywords defined above. |
f617db13 MW |
1779 | (list (concat "\\<\\(" c-keywords "\\)\\>") |
1780 | '(0 font-lock-keyword-face)) | |
1781 | ||
6132bc01 | 1782 | ;; Handle numbers too. |
f617db13 MW |
1783 | ;; |
1784 | ;; This looks strange, I know. It corresponds to the | |
1785 | ;; preprocessor's idea of what a number looks like, rather than | |
1786 | ;; anything sensible. | |
f617db13 MW |
1787 | (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)" |
1788 | "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*") | |
1789 | '(0 mdw-number-face)) | |
1790 | ||
6132bc01 | 1791 | ;; And anything else is punctuation. |
f617db13 | 1792 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" |
2e7c6a86 | 1793 | '(0 mdw-punct-face)))))) |
f617db13 | 1794 | |
6132bc01 MW |
1795 | ;;;-------------------------------------------------------------------------- |
1796 | ;;; Java programming configuration. | |
f617db13 | 1797 | |
6132bc01 | 1798 | ;; Make indentation nice. |
f617db13 | 1799 | |
c56296d0 MW |
1800 | (mdw-define-c-style mdw-java |
1801 | (c-basic-offset . 2) | |
1802 | (c-backslash-column . 72) | |
1803 | (c-offsets-alist (substatement-open . 0) | |
1804 | (label . +) | |
1805 | (case-label . +) | |
1806 | (access-label . 0) | |
1807 | (inclass . +) | |
1808 | (statement-case-intro . +))) | |
1809 | (mdw-set-default-c-style 'java-mode 'mdw-java) | |
f617db13 | 1810 | |
6132bc01 | 1811 | ;; Declare Java fontification style. |
f617db13 MW |
1812 | |
1813 | (defun mdw-fontify-java () | |
1814 | ||
6132bc01 | 1815 | ;; Other stuff. |
0e7d960b | 1816 | (setq mdw-fill-prefix mdw-c-comment-fill-prefix) |
f617db13 | 1817 | |
6132bc01 | 1818 | ;; Now define things to be fontified. |
02109a0d | 1819 | (make-local-variable 'font-lock-keywords) |
f617db13 | 1820 | (let ((java-keywords |
8d6d55b9 MW |
1821 | (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch" |
1822 | "char" "class" "const" "continue" "default" "do" | |
1823 | "double" "else" "extends" "final" "finally" "float" | |
1824 | "for" "goto" "if" "implements" "import" "instanceof" | |
1825 | "int" "interface" "long" "native" "new" "package" | |
1826 | "private" "protected" "public" "return" "short" | |
165cecf8 MW |
1827 | "static" "switch" "synchronized" "throw" "throws" |
1828 | "transient" "try" "void" "volatile" "while")) | |
8d6d55b9 | 1829 | |
165cecf8 MW |
1830 | (java-constants |
1831 | (mdw-regexps "false" "null" "super" "this" "true"))) | |
f617db13 MW |
1832 | |
1833 | (setq font-lock-keywords | |
1834 | (list | |
f617db13 | 1835 | |
6132bc01 | 1836 | ;; Handle the keywords defined above. |
f617db13 MW |
1837 | (list (concat "\\<\\(" java-keywords "\\)\\>") |
1838 | '(0 font-lock-keyword-face)) | |
1839 | ||
165cecf8 MW |
1840 | ;; Handle the magic constants defined above. |
1841 | (list (concat "\\<\\(" java-constants "\\)\\>") | |
1842 | '(0 font-lock-variable-name-face)) | |
1843 | ||
6132bc01 | 1844 | ;; Handle numbers too. |
f617db13 MW |
1845 | ;; |
1846 | ;; The following isn't quite right, but it's close enough. | |
f617db13 MW |
1847 | (list (concat "\\<\\(" |
1848 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
1849 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
1850 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
1851 | "[lLfFdD]?") | |
1852 | '(0 mdw-number-face)) | |
1853 | ||
6132bc01 | 1854 | ;; And anything else is punctuation. |
f617db13 | 1855 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" |
2e7c6a86 | 1856 | '(0 mdw-punct-face)))))) |
f617db13 | 1857 | |
6132bc01 | 1858 | ;;;-------------------------------------------------------------------------- |
61d63206 MW |
1859 | ;;; Javascript programming configuration. |
1860 | ||
1861 | (defun mdw-javascript-style () | |
1862 | (setq js-indent-level 2) | |
1863 | (setq js-expr-indent-offset 0)) | |
1864 | ||
1865 | (defun mdw-fontify-javascript () | |
1866 | ||
1867 | ;; Other stuff. | |
1868 | (mdw-javascript-style) | |
1869 | (setq js-auto-indent-flag t) | |
1870 | ||
1871 | ;; Now define things to be fontified. | |
1872 | (make-local-variable 'font-lock-keywords) | |
1873 | (let ((javascript-keywords | |
1874 | (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch" | |
1875 | "char" "class" "const" "continue" "debugger" "default" | |
1876 | "delete" "do" "double" "else" "enum" "export" "extends" | |
1877 | "final" "finally" "float" "for" "function" "goto" "if" | |
1878 | "implements" "import" "in" "instanceof" "int" | |
1879 | "interface" "let" "long" "native" "new" "package" | |
1880 | "private" "protected" "public" "return" "short" | |
1881 | "static" "super" "switch" "synchronized" "throw" | |
1882 | "throws" "transient" "try" "typeof" "var" "void" | |
1883 | "volatile" "while" "with" "yield" | |
1884 | ||
1885 | "boolean" "byte" "char" "double" "float" "int" "long" | |
1886 | "short" "void")) | |
1887 | (javascript-constants | |
1888 | (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true" | |
1889 | "arguments" "this"))) | |
1890 | ||
1891 | (setq font-lock-keywords | |
1892 | (list | |
1893 | ||
1894 | ;; Handle the keywords defined above. | |
f7856acd | 1895 | (list (concat "\\_<\\(" javascript-keywords "\\)\\_>") |
61d63206 MW |
1896 | '(0 font-lock-keyword-face)) |
1897 | ||
1898 | ;; Handle the predefined constants defined above. | |
f7856acd | 1899 | (list (concat "\\_<\\(" javascript-constants "\\)\\_>") |
61d63206 MW |
1900 | '(0 font-lock-variable-name-face)) |
1901 | ||
1902 | ;; Handle numbers too. | |
1903 | ;; | |
1904 | ;; The following isn't quite right, but it's close enough. | |
f7856acd | 1905 | (list (concat "\\_<\\(" |
61d63206 MW |
1906 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" |
1907 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
1908 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
1909 | "[lLfFdD]?") | |
1910 | '(0 mdw-number-face)) | |
1911 | ||
1912 | ;; And anything else is punctuation. | |
1913 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
2e7c6a86 | 1914 | '(0 mdw-punct-face)))))) |
61d63206 MW |
1915 | |
1916 | ;;;-------------------------------------------------------------------------- | |
ee7c3dea MW |
1917 | ;;; Scala programming configuration. |
1918 | ||
1919 | (defun mdw-fontify-scala () | |
1920 | ||
7b5903d8 MW |
1921 | ;; Comment filling. |
1922 | (setq mdw-fill-prefix mdw-c-comment-fill-prefix) | |
1923 | ||
ee7c3dea MW |
1924 | ;; Define things to be fontified. |
1925 | (make-local-variable 'font-lock-keywords) | |
1926 | (let ((scala-keywords | |
1927 | (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else" | |
1928 | "extends" "final" "finally" "for" "forSome" "if" | |
1929 | "implicit" "import" "lazy" "match" "new" "object" | |
3f017188 MW |
1930 | "override" "package" "private" "protected" "return" |
1931 | "sealed" "throw" "trait" "try" "type" "val" | |
ee7c3dea MW |
1932 | "var" "while" "with" "yield")) |
1933 | (scala-constants | |
3f017188 | 1934 | (mdw-regexps "false" "null" "super" "this" "true")) |
7b5903d8 | 1935 | (punctuation "[-!%^&*=+:@#~/?\\|`]")) |
ee7c3dea MW |
1936 | |
1937 | (setq font-lock-keywords | |
1938 | (list | |
1939 | ||
1940 | ;; Magical identifiers between backticks. | |
1941 | (list (concat "`\\([^`]+\\)`") | |
1942 | '(1 font-lock-variable-name-face)) | |
1943 | ||
1944 | ;; Handle the keywords defined above. | |
1945 | (list (concat "\\_<\\(" scala-keywords "\\)\\_>") | |
1946 | '(0 font-lock-keyword-face)) | |
1947 | ||
1948 | ;; Handle the constants defined above. | |
1949 | (list (concat "\\_<\\(" scala-constants "\\)\\_>") | |
1950 | '(0 font-lock-variable-name-face)) | |
1951 | ||
1952 | ;; Magical identifiers between backticks. | |
1953 | (list (concat "`\\([^`]+\\)`") | |
1954 | '(1 font-lock-variable-name-face)) | |
1955 | ||
1956 | ;; Handle numbers too. | |
1957 | ;; | |
1958 | ;; As usual, not quite right. | |
1959 | (list (concat "\\_<\\(" | |
1960 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
1961 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
1962 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
1963 | "[lLfFdD]?") | |
1964 | '(0 mdw-number-face)) | |
1965 | ||
1966 | ;; Identifiers with trailing operators. | |
1967 | (list (concat "_\\(" punctuation "\\)+") | |
1968 | '(0 mdw-trivial-face)) | |
1969 | ||
1970 | ;; And everything else is punctuation. | |
1971 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1972 | '(0 mdw-punct-face))) | |
1973 | ||
1974 | font-lock-syntactic-keywords | |
1975 | (list | |
1976 | ||
1977 | ;; Single quotes around characters. But not when used to quote | |
1978 | ;; symbol names. Ugh. | |
1979 | (list (concat "\\('\\)" | |
1980 | "\\(" "." | |
1981 | "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*" | |
1982 | "u+" "[0-9a-fA-F]\\{4\\}" | |
1983 | "\\|" "\\\\" "[0-7]\\{1,3\\}" | |
1984 | "\\|" "\\\\" "." "\\)" | |
1985 | "\\('\\)") | |
1986 | '(1 "\"") | |
2e7c6a86 | 1987 | '(4 "\"")))))) |
ee7c3dea MW |
1988 | |
1989 | ;;;-------------------------------------------------------------------------- | |
6132bc01 | 1990 | ;;; C# programming configuration. |
e808c1e5 | 1991 | |
6132bc01 | 1992 | ;; Make indentation nice. |
e808c1e5 | 1993 | |
c56296d0 MW |
1994 | (mdw-define-c-style mdw-csharp |
1995 | (c-basic-offset . 2) | |
1996 | (c-backslash-column . 72) | |
1997 | (c-offsets-alist (substatement-open . 0) | |
1998 | (label . 0) | |
1999 | (case-label . +) | |
2000 | (access-label . 0) | |
2001 | (inclass . +) | |
2002 | (statement-case-intro . +))) | |
2003 | (mdw-set-default-c-style 'csharp-mode 'mdw-csharp) | |
e808c1e5 | 2004 | |
6132bc01 | 2005 | ;; Declare C# fontification style. |
e808c1e5 MW |
2006 | |
2007 | (defun mdw-fontify-csharp () | |
2008 | ||
6132bc01 | 2009 | ;; Other stuff. |
0e7d960b | 2010 | (setq mdw-fill-prefix mdw-c-comment-fill-prefix) |
e808c1e5 | 2011 | |
6132bc01 | 2012 | ;; Now define things to be fontified. |
e808c1e5 MW |
2013 | (make-local-variable 'font-lock-keywords) |
2014 | (let ((csharp-keywords | |
165cecf8 MW |
2015 | (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch" |
2016 | "char" "checked" "class" "const" "continue" "decimal" | |
2017 | "default" "delegate" "do" "double" "else" "enum" | |
2018 | "event" "explicit" "extern" "finally" "fixed" "float" | |
2019 | "for" "foreach" "goto" "if" "implicit" "in" "int" | |
2020 | "interface" "internal" "is" "lock" "long" "namespace" | |
2021 | "new" "object" "operator" "out" "override" "params" | |
2022 | "private" "protected" "public" "readonly" "ref" | |
2023 | "return" "sbyte" "sealed" "short" "sizeof" | |
2024 | "stackalloc" "static" "string" "struct" "switch" | |
2025 | "throw" "try" "typeof" "uint" "ulong" "unchecked" | |
2026 | "unsafe" "ushort" "using" "virtual" "void" "volatile" | |
2027 | "while" "yield")) | |
2028 | ||
2029 | (csharp-constants | |
2030 | (mdw-regexps "base" "false" "null" "this" "true"))) | |
e808c1e5 MW |
2031 | |
2032 | (setq font-lock-keywords | |
2033 | (list | |
e808c1e5 | 2034 | |
6132bc01 | 2035 | ;; Handle the keywords defined above. |
e808c1e5 MW |
2036 | (list (concat "\\<\\(" csharp-keywords "\\)\\>") |
2037 | '(0 font-lock-keyword-face)) | |
2038 | ||
165cecf8 MW |
2039 | ;; Handle the magic constants defined above. |
2040 | (list (concat "\\<\\(" csharp-constants "\\)\\>") | |
2041 | '(0 font-lock-variable-name-face)) | |
2042 | ||
6132bc01 | 2043 | ;; Handle numbers too. |
e808c1e5 MW |
2044 | ;; |
2045 | ;; The following isn't quite right, but it's close enough. | |
e808c1e5 MW |
2046 | (list (concat "\\<\\(" |
2047 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
2048 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
2049 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
2050 | "[lLfFdD]?") | |
2051 | '(0 mdw-number-face)) | |
2052 | ||
6132bc01 | 2053 | ;; And anything else is punctuation. |
e808c1e5 | 2054 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" |
2e7c6a86 | 2055 | '(0 mdw-punct-face)))))) |
e808c1e5 | 2056 | |
103c5923 MW |
2057 | (define-derived-mode csharp-mode java-mode "C#" |
2058 | "Major mode for editing C# code.") | |
e808c1e5 | 2059 | |
6132bc01 | 2060 | ;;;-------------------------------------------------------------------------- |
81fb08fc MW |
2061 | ;;; F# programming configuration. |
2062 | ||
2063 | (setq fsharp-indent-offset 2) | |
2064 | ||
2065 | (defun mdw-fontify-fsharp () | |
2066 | ||
2067 | (let ((punct "=<>+-*/|&%!@?")) | |
2068 | (do ((i 0 (1+ i))) | |
2069 | ((>= i (length punct))) | |
2070 | (modify-syntax-entry (aref punct i) "."))) | |
2071 | ||
2072 | (modify-syntax-entry ?_ "_") | |
2073 | (modify-syntax-entry ?( "(") | |
2074 | (modify-syntax-entry ?) ")") | |
2075 | ||
2076 | (setq indent-tabs-mode nil) | |
2077 | ||
2078 | (let ((fsharp-keywords | |
2079 | (mdw-regexps "abstract" "and" "as" "assert" "atomic" | |
165cecf8 | 2080 | "begin" "break" |
81fb08fc MW |
2081 | "checked" "class" "component" "const" "constraint" |
2082 | "constructor" "continue" | |
2083 | "default" "delegate" "do" "done" "downcast" "downto" | |
2084 | "eager" "elif" "else" "end" "exception" "extern" | |
165cecf8 | 2085 | "finally" "fixed" "for" "fori" "fun" "function" |
81fb08fc MW |
2086 | "functor" |
2087 | "global" | |
2088 | "if" "in" "include" "inherit" "inline" "interface" | |
2089 | "internal" | |
2090 | "lazy" "let" | |
2091 | "match" "measure" "member" "method" "mixin" "module" | |
2092 | "mutable" | |
165cecf8 MW |
2093 | "namespace" "new" |
2094 | "object" "of" "open" "or" "override" | |
81fb08fc MW |
2095 | "parallel" "params" "private" "process" "protected" |
2096 | "public" "pure" | |
2097 | "rec" "recursive" "return" | |
2098 | "sealed" "sig" "static" "struct" | |
165cecf8 | 2099 | "tailcall" "then" "to" "trait" "try" "type" |
81fb08fc MW |
2100 | "upcast" "use" |
2101 | "val" "virtual" "void" "volatile" | |
2102 | "when" "while" "with" | |
2103 | "yield")) | |
2104 | ||
2105 | (fsharp-builtins | |
165cecf8 MW |
2106 | (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod" |
2107 | "base" "false" "null" "true")) | |
81fb08fc MW |
2108 | |
2109 | (bang-keywords | |
2110 | (mdw-regexps "do" "let" "return" "use" "yield")) | |
2111 | ||
2112 | (preprocessor-keywords | |
2113 | (mdw-regexps "if" "indent" "else" "endif"))) | |
2114 | ||
2115 | (setq font-lock-keywords | |
2116 | (list (list (concat "\\(^\\|[^\"]\\)" | |
2117 | "\\(" "(\\*" | |
2118 | "[^*]*\\*+" | |
2119 | "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*" | |
2120 | ")" | |
2121 | "\\|" | |
2122 | "//.*" | |
2123 | "\\)") | |
2124 | '(2 font-lock-comment-face)) | |
2125 | ||
2126 | (list (concat "'" "\\(" | |
2127 | "\\\\" | |
2128 | "\\(" "[ntbr'\\]" | |
2129 | "\\|" "[0-9][0-9][0-9]" | |
2130 | "\\|" "u" "[0-9a-fA-F]\\{4\\}" | |
2131 | "\\|" "U" "[0-9a-fA-F]\\{8\\}" | |
2132 | "\\)" | |
2133 | "\\|" | |
2134 | "." "\\)" "'" | |
2135 | "\\|" | |
2136 | "\"" "[^\"\\]*" | |
2137 | "\\(" "\\\\" "\\(.\\|\n\\)" | |
2138 | "[^\"\\]*" "\\)*" | |
2139 | "\\(\"\\|\\'\\)") | |
2140 | '(0 font-lock-string-face)) | |
2141 | ||
2142 | (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|" | |
2143 | "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>" | |
2144 | "\\|" | |
2145 | "\\_<\\(" fsharp-keywords "\\)\\_>") | |
2146 | '(0 font-lock-keyword-face)) | |
2147 | (list (concat "\\<\\(" fsharp-builtins "\\)\\_>") | |
2148 | '(0 font-lock-variable-name-face)) | |
2149 | ||
2150 | (list (concat "\\_<" | |
2151 | "\\(" "0[bB][01]+" "\\|" | |
2152 | "0[oO][0-7]+" "\\|" | |
2153 | "0[xX][0-9a-fA-F]+" "\\)" | |
2154 | "\\(" "lf\\|LF" "\\|" | |
2155 | "[uU]?[ysnlL]?" "\\)" | |
2156 | "\\|" | |
2157 | "\\_<" | |
2158 | "[0-9]+" "\\(" | |
2159 | "[mMQRZING]" | |
2160 | "\\|" | |
2161 | "\\(\\.[0-9]*\\)?" | |
2162 | "\\([eE][-+]?[0-9]+\\)?" | |
2163 | "[fFmM]?" | |
2164 | "\\|" | |
2165 | "[uU]?[ysnlL]?" | |
2166 | "\\)") | |
2167 | '(0 mdw-number-face)) | |
2168 | ||
2169 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
2e7c6a86 | 2170 | '(0 mdw-punct-face)))))) |
81fb08fc MW |
2171 | |
2172 | (defun mdw-fontify-inferior-fsharp () | |
2173 | (mdw-fontify-fsharp) | |
2174 | (setq font-lock-keywords | |
2175 | (append (list (list "^[#-]" '(0 font-lock-comment-face)) | |
2176 | (list "^>" '(0 font-lock-keyword-face))) | |
2177 | font-lock-keywords))) | |
2178 | ||
2179 | ;;;-------------------------------------------------------------------------- | |
07965a39 MW |
2180 | ;;; Go programming configuration. |
2181 | ||
2182 | (defun mdw-fontify-go () | |
2183 | ||
2184 | (make-local-variable 'font-lock-keywords) | |
2185 | (let ((go-keywords | |
2186 | (mdw-regexps "break" "case" "chan" "const" "continue" | |
2187 | "default" "defer" "else" "fallthrough" "for" | |
2188 | "func" "go" "goto" "if" "import" | |
2189 | "interface" "map" "package" "range" "return" | |
fc79ff88 MW |
2190 | "select" "struct" "switch" "type" "var")) |
2191 | (go-intrinsics | |
2192 | (mdw-regexps "bool" "byte" "complex64" "complex128" "error" | |
2193 | "float32" "float64" "int" "uint8" "int16" "int32" | |
2194 | "int64" "rune" "string" "uint" "uint8" "uint16" | |
2195 | "uint32" "uint64" "uintptr" "void" | |
2196 | "false" "iota" "nil" "true" | |
2197 | "init" "main" | |
2198 | "append" "cap" "copy" "delete" "imag" "len" "make" | |
2199 | "new" "panic" "real" "recover"))) | |
07965a39 MW |
2200 | |
2201 | (setq font-lock-keywords | |
2202 | (list | |
2203 | ||
2204 | ;; Handle the keywords defined above. | |
2205 | (list (concat "\\<\\(" go-keywords "\\)\\>") | |
2206 | '(0 font-lock-keyword-face)) | |
fc79ff88 MW |
2207 | (list (concat "\\<\\(" go-intrinsics "\\)\\>") |
2208 | '(0 font-lock-variable-name-face)) | |
07965a39 | 2209 | |
cbbea94e MW |
2210 | ;; Strings and characters. |
2211 | (list (concat "'" | |
2212 | "\\(" "[^\\']" "\\|" | |
2213 | "\\\\" | |
2214 | "\\(" "[abfnrtv\\'\"]" "\\|" | |
2215 | "[0-7]\\{3\\}" "\\|" | |
2216 | "x" "[0-9A-Fa-f]\\{2\\}" "\\|" | |
2217 | "u" "[0-9A-Fa-f]\\{4\\}" "\\|" | |
2218 | "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)" | |
2219 | "'" | |
2220 | "\\|" | |
2221 | "\"" | |
2222 | "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*" | |
2223 | "\\(\"\\|$\\)" | |
2224 | "\\|" | |
2225 | "`" "[^`]+" "`") | |
2226 | '(0 font-lock-string-face)) | |
2227 | ||
07965a39 MW |
2228 | ;; Handle numbers too. |
2229 | ;; | |
2230 | ;; The following isn't quite right, but it's close enough. | |
2231 | (list (concat "\\<\\(" | |
2232 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
2233 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
2234 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)") | |
2235 | '(0 mdw-number-face)) | |
2236 | ||
2237 | ;; And anything else is punctuation. | |
2238 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
2e7c6a86 | 2239 | '(0 mdw-punct-face)))))) |
07965a39 MW |
2240 | |
2241 | ;;;-------------------------------------------------------------------------- | |
36db1ea7 MW |
2242 | ;;; Rust programming configuration. |
2243 | ||
2244 | (setq-default rust-indent-offset 2) | |
2245 | ||
2246 | (defun mdw-self-insert-and-indent (count) | |
2247 | (interactive "p") | |
2248 | (self-insert-command count) | |
2249 | (indent-according-to-mode)) | |
2250 | ||
2251 | (defun mdw-fontify-rust () | |
2252 | ||
2253 | ;; Hack syntax categories. | |
2254 | (modify-syntax-entry ?= ".") | |
2255 | ||
2256 | ;; Fontify keywords and things. | |
2257 | (make-local-variable 'font-lock-keywords) | |
2258 | (let ((rust-keywords | |
2259 | (mdw-regexps "abstract" "alignof" "as" | |
2260 | "become" "box" "break" | |
2261 | "const" "continue" "create" | |
2262 | "do" | |
2263 | "else" "enum" "extern" | |
2264 | "false" "final" "fn" "for" | |
2265 | "if" "impl" "in" | |
2266 | "let" "loop" | |
2267 | "macro" "match" "mod" "move" "mut" | |
2268 | "offsetof" "override" | |
2269 | "priv" "pub" "pure" | |
2270 | "ref" "return" | |
2271 | "self" "sizeof" "static" "struct" "super" | |
2272 | "true" "trait" "type" "typeof" | |
2273 | "unsafe" "unsized" "use" | |
2274 | "virtual" | |
2275 | "where" "while" | |
2276 | "yield")) | |
2277 | (rust-builtins | |
2278 | (mdw-regexps "array" "pointer" "slice" "tuple" | |
2279 | "bool" "true" "false" | |
2280 | "f32" "f64" | |
2281 | "i8" "i16" "i32" "i64" "isize" | |
2282 | "u8" "u16" "u32" "u64" "usize" | |
2283 | "char" "str"))) | |
2284 | (setq font-lock-keywords | |
2285 | (list | |
2286 | ||
2287 | ;; Handle the keywords defined above. | |
2288 | (list (concat "\\<\\(" rust-keywords "\\)\\>") | |
2289 | '(0 font-lock-keyword-face)) | |
2290 | (list (concat "\\<\\(" rust-builtins "\\)\\>") | |
2291 | '(0 font-lock-variable-name-face)) | |
2292 | ||
2293 | ;; Handle numbers too. | |
2294 | (list (concat "\\<\\(" | |
2295 | "[0-9][0-9_]*" | |
2296 | "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+" | |
2297 | "\\|" "\\.[0-9_]+" | |
2298 | "\\)" | |
2299 | "\\(f32\\|f64\\)?" | |
2300 | "\\|" "\\(" "[0-9][0-9_]*" | |
2301 | "\\|" "0x[0-9a-fA-F_]+" | |
2302 | "\\|" "0o[0-7_]+" | |
2303 | "\\|" "0b[01_]+" | |
2304 | "\\)" | |
2305 | "\\([ui]\\(8\\|16\\|32\\|64\\|s\\|size\\)\\)?" | |
2306 | "\\)\\>") | |
2307 | '(0 mdw-number-face)) | |
2308 | ||
2309 | ;; And anything else is punctuation. | |
2310 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
2311 | '(0 mdw-punct-face))))) | |
2312 | ||
2313 | ;; Hack key bindings. | |
d2f85967 | 2314 | (local-set-key [?{] 'mdw-self-insert-and-indent) |
2e7c6a86 | 2315 | (local-set-key [?}] 'mdw-self-insert-and-indent)) |
36db1ea7 MW |
2316 | |
2317 | ;;;-------------------------------------------------------------------------- | |
6132bc01 | 2318 | ;;; Awk programming configuration. |
f617db13 | 2319 | |
6132bc01 | 2320 | ;; Make Awk indentation nice. |
f617db13 | 2321 | |
c56296d0 MW |
2322 | (mdw-define-c-style mdw-awk |
2323 | (c-basic-offset . 2) | |
2324 | (c-offsets-alist (substatement-open . 0) | |
2325 | (c-backslash-column . 72) | |
2326 | (statement-cont . 0) | |
2327 | (statement-case-intro . +))) | |
2328 | (mdw-set-default-c-style 'awk-mode 'mdw-awk) | |
f617db13 | 2329 | |
6132bc01 | 2330 | ;; Declare Awk fontification style. |
f617db13 MW |
2331 | |
2332 | (defun mdw-fontify-awk () | |
2333 | ||
6132bc01 | 2334 | ;; Miscellaneous fiddling. |
f617db13 MW |
2335 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") |
2336 | ||
6132bc01 | 2337 | ;; Now define things to be fontified. |
02109a0d | 2338 | (make-local-variable 'font-lock-keywords) |
f617db13 | 2339 | (let ((c-keywords |
8d6d55b9 MW |
2340 | (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT" |
2341 | "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR" | |
2342 | "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS" | |
2343 | "RSTART" "RLENGTH" "RT" "SUBSEP" | |
2344 | "atan2" "break" "close" "continue" "cos" "delete" | |
2345 | "do" "else" "exit" "exp" "fflush" "file" "for" "func" | |
2346 | "function" "gensub" "getline" "gsub" "if" "in" | |
2347 | "index" "int" "length" "log" "match" "next" "rand" | |
2348 | "return" "print" "printf" "sin" "split" "sprintf" | |
2349 | "sqrt" "srand" "strftime" "sub" "substr" "system" | |
2350 | "systime" "tolower" "toupper" "while"))) | |
f617db13 MW |
2351 | |
2352 | (setq font-lock-keywords | |
2353 | (list | |
f617db13 | 2354 | |
6132bc01 | 2355 | ;; Handle the keywords defined above. |
f617db13 MW |
2356 | (list (concat "\\<\\(" c-keywords "\\)\\>") |
2357 | '(0 font-lock-keyword-face)) | |
2358 | ||
6132bc01 | 2359 | ;; Handle numbers too. |
f617db13 MW |
2360 | ;; |
2361 | ;; The following isn't quite right, but it's close enough. | |
f617db13 MW |
2362 | (list (concat "\\<\\(" |
2363 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
2364 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
2365 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
2366 | "[uUlL]*") | |
2367 | '(0 mdw-number-face)) | |
2368 | ||
6132bc01 | 2369 | ;; And anything else is punctuation. |
f617db13 | 2370 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" |
2e7c6a86 | 2371 | '(0 mdw-punct-face)))))) |
f617db13 | 2372 | |
6132bc01 MW |
2373 | ;;;-------------------------------------------------------------------------- |
2374 | ;;; Perl programming style. | |
f617db13 | 2375 | |
6132bc01 | 2376 | ;; Perl indentation style. |
f617db13 | 2377 | |
88158daf MW |
2378 | (setq perl-indent-level 2) |
2379 | ||
f617db13 MW |
2380 | (setq cperl-indent-level 2) |
2381 | (setq cperl-continued-statement-offset 2) | |
2382 | (setq cperl-continued-brace-offset 0) | |
2383 | (setq cperl-brace-offset -2) | |
2384 | (setq cperl-brace-imaginary-offset 0) | |
2385 | (setq cperl-label-offset 0) | |
2386 | ||
6132bc01 | 2387 | ;; Define perl fontification style. |
f617db13 MW |
2388 | |
2389 | (defun mdw-fontify-perl () | |
2390 | ||
6132bc01 | 2391 | ;; Miscellaneous fiddling. |
f617db13 MW |
2392 | (modify-syntax-entry ?$ "\\") |
2393 | (modify-syntax-entry ?$ "\\" font-lock-syntax-table) | |
a3b8176f | 2394 | (modify-syntax-entry ?: "." font-lock-syntax-table) |
f617db13 MW |
2395 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") |
2396 | ||
6132bc01 | 2397 | ;; Now define fontification things. |
02109a0d | 2398 | (make-local-variable 'font-lock-keywords) |
f617db13 | 2399 | (let ((perl-keywords |
821c4945 MW |
2400 | (mdw-regexps "and" |
2401 | "break" | |
2402 | "cmp" "continue" | |
2403 | "default" "do" | |
2404 | "else" "elsif" "eq" | |
2405 | "for" "foreach" | |
2406 | "ge" "given" "gt" "goto" | |
2407 | "if" | |
2408 | "last" "le" "local" "lt" | |
2409 | "my" | |
2410 | "ne" "next" | |
2411 | "or" "our" | |
2412 | "package" | |
2413 | "redo" "require" "return" | |
2414 | "sub" | |
2415 | "undef" "unless" "until" "use" | |
2416 | "when" "while"))) | |
f617db13 MW |
2417 | |
2418 | (setq font-lock-keywords | |
2419 | (list | |
f617db13 | 2420 | |
6132bc01 | 2421 | ;; Set up the keywords defined above. |
f617db13 MW |
2422 | (list (concat "\\<\\(" perl-keywords "\\)\\>") |
2423 | '(0 font-lock-keyword-face)) | |
2424 | ||
6132bc01 | 2425 | ;; At least numbers are simpler than C. |
f617db13 MW |
2426 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" |
2427 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
2428 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
2429 | '(0 mdw-number-face)) | |
2430 | ||
6132bc01 | 2431 | ;; And anything else is punctuation. |
f617db13 | 2432 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" |
2e7c6a86 | 2433 | '(0 mdw-punct-face)))))) |
f617db13 MW |
2434 | |
2435 | (defun perl-number-tests (&optional arg) | |
2436 | "Assign consecutive numbers to lines containing `#t'. With ARG, | |
2437 | strip numbers instead." | |
2438 | (interactive "P") | |
2439 | (save-excursion | |
2440 | (goto-char (point-min)) | |
2441 | (let ((i 0) (fmt (if arg "" " %4d"))) | |
2442 | (while (search-forward "#t" nil t) | |
2443 | (delete-region (point) (line-end-position)) | |
2444 | (setq i (1+ i)) | |
2445 | (insert (format fmt i))) | |
2446 | (goto-char (point-min)) | |
2447 | (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t) | |
2448 | (replace-match (format "\\1%d" i)))))) | |
2449 | ||
6132bc01 MW |
2450 | ;;;-------------------------------------------------------------------------- |
2451 | ;;; Python programming style. | |
f617db13 | 2452 | |
99fe6ef5 | 2453 | (defun mdw-fontify-pythonic (keywords) |
f617db13 | 2454 | |
6132bc01 | 2455 | ;; Miscellaneous fiddling. |
f617db13 | 2456 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") |
7c0fcfde | 2457 | (setq indent-tabs-mode nil) |
f617db13 | 2458 | |
6132bc01 | 2459 | ;; Now define fontification things. |
02109a0d | 2460 | (make-local-variable 'font-lock-keywords) |
99fe6ef5 MW |
2461 | (setq font-lock-keywords |
2462 | (list | |
f617db13 | 2463 | |
be2cc788 | 2464 | ;; Set up the keywords defined above. |
4b037109 | 2465 | (list (concat "\\_<\\(" keywords "\\)\\_>") |
99fe6ef5 | 2466 | '(0 font-lock-keyword-face)) |
f617db13 | 2467 | |
be2cc788 | 2468 | ;; At least numbers are simpler than C. |
4b037109 MW |
2469 | (list (concat "\\_<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" |
2470 | "\\_<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
99fe6ef5 MW |
2471 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)") |
2472 | '(0 mdw-number-face)) | |
f617db13 | 2473 | |
be2cc788 | 2474 | ;; And anything else is punctuation. |
99fe6ef5 | 2475 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" |
2e7c6a86 | 2476 | '(0 mdw-punct-face))))) |
99fe6ef5 | 2477 | |
be2cc788 | 2478 | ;; Define Python fontification styles. |
99fe6ef5 MW |
2479 | |
2480 | (defun mdw-fontify-python () | |
2481 | (mdw-fontify-pythonic | |
2482 | (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def" | |
2483 | "del" "elif" "else" "except" "exec" "finally" "for" | |
2484 | "from" "global" "if" "import" "in" "is" "lambda" | |
2485 | "not" "or" "pass" "print" "raise" "return" "try" | |
2486 | "while" "with" "yield"))) | |
2487 | ||
2488 | (defun mdw-fontify-pyrex () | |
2489 | (mdw-fontify-pythonic | |
2490 | (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue" | |
2491 | "ctypedef" "def" "del" "elif" "else" "except" "exec" | |
2492 | "extern" "finally" "for" "from" "global" "if" | |
2493 | "import" "in" "is" "lambda" "not" "or" "pass" "print" | |
2494 | "raise" "return" "struct" "try" "while" "with" | |
2495 | "yield"))) | |
f617db13 | 2496 | |
6132bc01 MW |
2497 | ;;;-------------------------------------------------------------------------- |
2498 | ;;; Icon programming style. | |
cc1980e1 | 2499 | |
6132bc01 | 2500 | ;; Icon indentation style. |
cc1980e1 MW |
2501 | |
2502 | (setq icon-brace-offset 0 | |
2503 | icon-continued-brace-offset 0 | |
2504 | icon-continued-statement-offset 2 | |
2505 | icon-indent-level 2) | |
2506 | ||
6132bc01 | 2507 | ;; Define Icon fontification style. |
cc1980e1 MW |
2508 | |
2509 | (defun mdw-fontify-icon () | |
2510 | ||
6132bc01 | 2511 | ;; Miscellaneous fiddling. |
cc1980e1 MW |
2512 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") |
2513 | ||
6132bc01 | 2514 | ;; Now define fontification things. |
cc1980e1 MW |
2515 | (make-local-variable 'font-lock-keywords) |
2516 | (let ((icon-keywords | |
2517 | (mdw-regexps "break" "by" "case" "create" "default" "do" "else" | |
2518 | "end" "every" "fail" "global" "if" "initial" | |
2519 | "invocable" "link" "local" "next" "not" "of" | |
2520 | "procedure" "record" "repeat" "return" "static" | |
2521 | "suspend" "then" "to" "until" "while")) | |
2522 | (preprocessor-keywords | |
2523 | (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef" | |
2524 | "include" "line" "undef"))) | |
2525 | (setq font-lock-keywords | |
2526 | (list | |
2527 | ||
6132bc01 | 2528 | ;; Set up the keywords defined above. |
cc1980e1 MW |
2529 | (list (concat "\\<\\(" icon-keywords "\\)\\>") |
2530 | '(0 font-lock-keyword-face)) | |
2531 | ||
6132bc01 | 2532 | ;; The things that Icon calls keywords. |
cc1980e1 MW |
2533 | (list "&\\sw+\\>" '(0 font-lock-variable-name-face)) |
2534 | ||
6132bc01 | 2535 | ;; At least numbers are simpler than C. |
cc1980e1 MW |
2536 | (list (concat "\\<[0-9]+" |
2537 | "\\([rR][0-9a-zA-Z]+\\|" | |
2538 | "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|" | |
2539 | "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>") | |
2540 | '(0 mdw-number-face)) | |
2541 | ||
6132bc01 | 2542 | ;; Preprocessor. |
cc1980e1 MW |
2543 | (list (concat "^[ \t]*$[ \t]*\\<\\(" |
2544 | preprocessor-keywords | |
2545 | "\\)\\>") | |
2546 | '(0 font-lock-keyword-face)) | |
2547 | ||
6132bc01 | 2548 | ;; And anything else is punctuation. |
cc1980e1 | 2549 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" |
2e7c6a86 | 2550 | '(0 mdw-punct-face)))))) |
cc1980e1 | 2551 | |
6132bc01 | 2552 | ;;;-------------------------------------------------------------------------- |
6132bc01 | 2553 | ;;; Assembler mode. |
30c8a8fb MW |
2554 | |
2555 | (defun mdw-fontify-asm () | |
2556 | (modify-syntax-entry ?' "\"") | |
2557 | (modify-syntax-entry ?. "w") | |
9032280b | 2558 | (modify-syntax-entry ?\n ">") |
30c8a8fb MW |
2559 | (setf fill-prefix nil) |
2560 | (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")) | |
2561 | ||
227b2b2b MW |
2562 | (defun mdw-asm-set-comment () |
2563 | (modify-syntax-entry ?; "." | |
2564 | ) | |
2565 | (modify-syntax-entry asm-comment-char "<b") | |
2566 | (setq comment-start (string asm-comment-char ? ))) | |
2567 | (add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment) | |
2568 | (put 'asm-comment-char 'safe-local-variable 'characterp) | |
9032280b | 2569 | |
6132bc01 MW |
2570 | ;;;-------------------------------------------------------------------------- |
2571 | ;;; TCL configuration. | |
f617db13 MW |
2572 | |
2573 | (defun mdw-fontify-tcl () | |
2574 | (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$)) | |
2575 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
02109a0d | 2576 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
2577 | (setq font-lock-keywords |
2578 | (list | |
f617db13 MW |
2579 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" |
2580 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
2581 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
2582 | '(0 mdw-number-face)) | |
2583 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
2e7c6a86 | 2584 | '(0 mdw-punct-face))))) |
f617db13 | 2585 | |
6132bc01 | 2586 | ;;;-------------------------------------------------------------------------- |
ad305d7e MW |
2587 | ;;; Dylan programming configuration. |
2588 | ||
2589 | (defun mdw-fontify-dylan () | |
2590 | ||
2591 | (make-local-variable 'font-lock-keywords) | |
2592 | ||
2593 | ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this | |
2594 | ;; hook, which undoes all of our configuration. | |
2595 | (setq major-mode 'dylan-mode) | |
2596 | (font-lock-set-defaults) | |
2597 | ||
2598 | (let* ((word "[-_a-zA-Z!*@<>$%]+") | |
2599 | (dylan-keywords (mdw-regexps | |
2600 | ||
2601 | "C-address" "C-callable-wrapper" "C-function" | |
2602 | "C-mapped-subtype" "C-pointer-type" "C-struct" | |
2603 | "C-subtype" "C-union" "C-variable" | |
2604 | ||
2605 | "above" "abstract" "afterwards" "all" | |
2606 | "begin" "below" "block" "by" | |
2607 | "case" "class" "cleanup" "constant" "create" | |
2608 | "define" "domain" | |
2609 | "else" "elseif" "end" "exception" "export" | |
2610 | "finally" "for" "from" "function" | |
2611 | "generic" | |
2612 | "handler" | |
2613 | "if" "in" "instance" "interface" "iterate" | |
2614 | "keyed-by" | |
2615 | "let" "library" "local" | |
2616 | "macro" "method" "module" | |
2617 | "otherwise" | |
2618 | "profiling" | |
2619 | "select" "slot" "subclass" | |
2620 | "table" "then" "to" | |
2621 | "unless" "until" "use" | |
2622 | "variable" "virtual" | |
2623 | "when" "while")) | |
2624 | (sharp-keywords (mdw-regexps | |
2625 | "all-keys" "key" "next" "rest" "include" | |
2626 | "t" "f"))) | |
2627 | (setq font-lock-keywords | |
2628 | (list (list (concat "\\<\\(" dylan-keywords | |
ce29694e | 2629 | "\\|" "with\\(out\\)?-" word |
ad305d7e MW |
2630 | "\\)\\>") |
2631 | '(0 font-lock-keyword-face)) | |
ce29694e MW |
2632 | (list (concat "\\<" word ":" "\\|" |
2633 | "#\\(" sharp-keywords "\\)\\>") | |
ad305d7e MW |
2634 | '(0 font-lock-variable-name-face)) |
2635 | (list (concat "\\(" | |
2636 | "\\([-+]\\|\\<\\)[0-9]+" "\\(" | |
2637 | "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?" | |
2638 | "\\|" "/[0-9]+" | |
2639 | "\\)" | |
2640 | "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?" | |
2641 | "\\|" "#b[01]+" | |
2642 | "\\|" "#o[0-7]+" | |
2643 | "\\|" "#x[0-9a-zA-Z]+" | |
2644 | "\\)\\>") | |
2645 | '(0 mdw-number-face)) | |
2646 | (list (concat "\\(" | |
2647 | "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|" | |
2648 | "\\_<[-+*/=<>:&|]+\\_>" | |
2649 | "\\)") | |
2e7c6a86 | 2650 | '(0 mdw-punct-face)))))) |
ad305d7e MW |
2651 | |
2652 | ;;;-------------------------------------------------------------------------- | |
7fce54c3 MW |
2653 | ;;; Algol 68 configuration. |
2654 | ||
2655 | (setq a68-indent-step 2) | |
2656 | ||
2657 | (defun mdw-fontify-algol-68 () | |
2658 | ||
2659 | ;; Fix up the syntax table. | |
2660 | (modify-syntax-entry ?# "!" a68-mode-syntax-table) | |
2661 | (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&)) | |
2662 | (modify-syntax-entry ch "." a68-mode-syntax-table)) | |
2663 | ||
2664 | (make-local-variable 'font-lock-keywords) | |
2665 | ||
2666 | (let ((not-comment | |
2667 | (let ((word "COMMENT")) | |
2668 | (do ((regexp (concat "[^" (substring word 0 1) "]+") | |
2669 | (concat regexp "\\|" | |
2670 | (substring word 0 i) | |
2671 | "[^" (substring word i (1+ i)) "]")) | |
2672 | (i 1 (1+ i))) | |
2673 | ((>= i (length word)) regexp))))) | |
2674 | (setq font-lock-keywords | |
2675 | (list (list (concat "\\<COMMENT\\>" | |
2676 | "\\(" not-comment "\\)\\{0,5\\}" | |
2677 | "\\(\\'\\|\\<COMMENT\\>\\)") | |
2678 | '(0 font-lock-comment-face)) | |
2679 | (list (concat "\\<CO\\>" | |
2680 | "\\([^C]+\\|C[^O]\\)\\{0,5\\}" | |
2681 | "\\($\\|\\<CO\\>\\)") | |
2682 | '(0 font-lock-comment-face)) | |
2683 | (list "\\<[A-Z_]+\\>" | |
2684 | '(0 font-lock-keyword-face)) | |
2685 | (list (concat "\\<" | |
2686 | "[0-9]+" | |
2687 | "\\(\\.[0-9]+\\)?" | |
2688 | "\\([eE][-+]?[0-9]+\\)?" | |
2689 | "\\>") | |
2690 | '(0 mdw-number-face)) | |
2691 | (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/" | |
2e7c6a86 | 2692 | '(0 mdw-punct-face)))))) |
7fce54c3 MW |
2693 | |
2694 | ;;;-------------------------------------------------------------------------- | |
6132bc01 | 2695 | ;;; REXX configuration. |
f617db13 MW |
2696 | |
2697 | (defun mdw-rexx-electric-* () | |
2698 | (interactive) | |
2699 | (insert ?*) | |
2700 | (rexx-indent-line)) | |
2701 | ||
2702 | (defun mdw-rexx-indent-newline-indent () | |
2703 | (interactive) | |
2704 | (rexx-indent-line) | |
2705 | (if abbrev-mode (expand-abbrev)) | |
2706 | (newline-and-indent)) | |
2707 | ||
2708 | (defun mdw-fontify-rexx () | |
2709 | ||
6132bc01 | 2710 | ;; Various bits of fiddling. |
f617db13 MW |
2711 | (setq mdw-auto-indent nil) |
2712 | (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent) | |
2713 | (local-set-key [?*] 'mdw-rexx-electric-*) | |
2714 | (mapcar #'(lambda (ch) (modify-syntax-entry ch "w")) | |
e443a4cd | 2715 | '(?! ?? ?# ?@ ?$)) |
f617db13 MW |
2716 | (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)") |
2717 | ||
6132bc01 | 2718 | ;; Set up keywords and things for fontification. |
f617db13 MW |
2719 | (make-local-variable 'font-lock-keywords-case-fold-search) |
2720 | (setq font-lock-keywords-case-fold-search t) | |
2721 | ||
2722 | (setq rexx-indent 2) | |
2723 | (setq rexx-end-indent rexx-indent) | |
f617db13 MW |
2724 | (setq rexx-cont-indent rexx-indent) |
2725 | ||
02109a0d | 2726 | (make-local-variable 'font-lock-keywords) |
f617db13 | 2727 | (let ((rexx-keywords |
8d6d55b9 MW |
2728 | (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop" |
2729 | "else" "end" "engineering" "exit" "expose" "for" | |
2730 | "forever" "form" "fuzz" "if" "interpret" "iterate" | |
2731 | "leave" "linein" "name" "nop" "numeric" "off" "on" | |
2732 | "options" "otherwise" "parse" "procedure" "pull" | |
2733 | "push" "queue" "return" "say" "select" "signal" | |
2734 | "scientific" "source" "then" "trace" "to" "until" | |
2735 | "upper" "value" "var" "version" "when" "while" | |
2736 | "with" | |
2737 | ||
2738 | "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x" | |
2739 | "center" "center" "charin" "charout" "chars" | |
2740 | "compare" "condition" "copies" "c2d" "c2x" | |
2741 | "datatype" "date" "delstr" "delword" "d2c" "d2x" | |
2742 | "errortext" "format" "fuzz" "insert" "lastpos" | |
2743 | "left" "length" "lineout" "lines" "max" "min" | |
2744 | "overlay" "pos" "queued" "random" "reverse" "right" | |
2745 | "sign" "sourceline" "space" "stream" "strip" | |
2746 | "substr" "subword" "symbol" "time" "translate" | |
2747 | "trunc" "value" "verify" "word" "wordindex" | |
2748 | "wordlength" "wordpos" "words" "xrange" "x2b" "x2c" | |
2749 | "x2d"))) | |
f617db13 MW |
2750 | |
2751 | (setq font-lock-keywords | |
2752 | (list | |
f617db13 | 2753 | |
6132bc01 | 2754 | ;; Set up the keywords defined above. |
f617db13 MW |
2755 | (list (concat "\\<\\(" rexx-keywords "\\)\\>") |
2756 | '(0 font-lock-keyword-face)) | |
2757 | ||
6132bc01 | 2758 | ;; Fontify all symbols the same way. |
f617db13 MW |
2759 | (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|" |
2760 | "[A-Za-z0-9.!?_#@$]+\\)") | |
2761 | '(0 font-lock-variable-name-face)) | |
2762 | ||
6132bc01 | 2763 | ;; And everything else is punctuation. |
f617db13 | 2764 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" |
2e7c6a86 | 2765 | '(0 mdw-punct-face)))))) |
f617db13 | 2766 | |
6132bc01 MW |
2767 | ;;;-------------------------------------------------------------------------- |
2768 | ;;; Standard ML programming style. | |
f617db13 MW |
2769 | |
2770 | (defun mdw-fontify-sml () | |
2771 | ||
6132bc01 | 2772 | ;; Make underscore an honorary letter. |
f617db13 MW |
2773 | (modify-syntax-entry ?' "w") |
2774 | ||
6132bc01 | 2775 | ;; Set fill prefix. |
f617db13 MW |
2776 | (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)") |
2777 | ||
6132bc01 | 2778 | ;; Now define fontification things. |
02109a0d | 2779 | (make-local-variable 'font-lock-keywords) |
f617db13 | 2780 | (let ((sml-keywords |
8d6d55b9 MW |
2781 | (mdw-regexps "abstype" "and" "andalso" "as" |
2782 | "case" | |
2783 | "datatype" "do" | |
2784 | "else" "end" "eqtype" "exception" | |
2785 | "fn" "fun" "functor" | |
2786 | "handle" | |
2787 | "if" "in" "include" "infix" "infixr" | |
2788 | "let" "local" | |
2789 | "nonfix" | |
2790 | "of" "op" "open" "orelse" | |
2791 | "raise" "rec" | |
2792 | "sharing" "sig" "signature" "struct" "structure" | |
2793 | "then" "type" | |
2794 | "val" | |
2795 | "where" "while" "with" "withtype"))) | |
f617db13 MW |
2796 | |
2797 | (setq font-lock-keywords | |
2798 | (list | |
f617db13 | 2799 | |
6132bc01 | 2800 | ;; Set up the keywords defined above. |
f617db13 MW |
2801 | (list (concat "\\<\\(" sml-keywords "\\)\\>") |
2802 | '(0 font-lock-keyword-face)) | |
2803 | ||
6132bc01 | 2804 | ;; At least numbers are simpler than C. |
f617db13 MW |
2805 | (list (concat "\\<\\(\\~\\|\\)" |
2806 | "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|" | |
852cd5fb MW |
2807 | "[wW][0-9]+\\)\\|" |
2808 | "\\([0-9]+\\(\\.[0-9]+\\|\\)" | |
2809 | "\\([eE]\\(\\~\\|\\)" | |
2810 | "[0-9]+\\|\\)\\)\\)") | |
f617db13 MW |
2811 | '(0 mdw-number-face)) |
2812 | ||
6132bc01 | 2813 | ;; And anything else is punctuation. |
f617db13 | 2814 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" |
2e7c6a86 | 2815 | '(0 mdw-punct-face)))))) |
f617db13 | 2816 | |
6132bc01 MW |
2817 | ;;;-------------------------------------------------------------------------- |
2818 | ;;; Haskell configuration. | |
f617db13 MW |
2819 | |
2820 | (defun mdw-fontify-haskell () | |
2821 | ||
6132bc01 | 2822 | ;; Fiddle with syntax table to get comments right. |
5952a020 MW |
2823 | (modify-syntax-entry ?' "_") |
2824 | (modify-syntax-entry ?- ". 12") | |
f617db13 MW |
2825 | (modify-syntax-entry ?\n ">") |
2826 | ||
4d90cf3d MW |
2827 | ;; Make punctuation be punctuation |
2828 | (let ((punct "=<>+-*/|&%!@?$.^:#`")) | |
2829 | (do ((i 0 (1+ i))) | |
2830 | ((>= i (length punct))) | |
2831 | (modify-syntax-entry (aref punct i) "."))) | |
2832 | ||
6132bc01 | 2833 | ;; Set fill prefix. |
f617db13 MW |
2834 | (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)") |
2835 | ||
6132bc01 | 2836 | ;; Fiddle with fontification. |
02109a0d | 2837 | (make-local-variable 'font-lock-keywords) |
f617db13 | 2838 | (let ((haskell-keywords |
5952a020 MW |
2839 | (mdw-regexps "as" |
2840 | "case" "ccall" "class" | |
2841 | "data" "default" "deriving" "do" | |
2842 | "else" "exists" | |
2843 | "forall" "foreign" | |
2844 | "hiding" | |
2845 | "if" "import" "in" "infix" "infixl" "infixr" "instance" | |
2846 | "let" | |
2847 | "mdo" "module" | |
2848 | "newtype" | |
2849 | "of" | |
2850 | "proc" | |
2851 | "qualified" | |
2852 | "rec" | |
2853 | "safe" "stdcall" | |
2854 | "then" "type" | |
2855 | "unsafe" | |
2856 | "where")) | |
2857 | (control-sequences | |
2858 | (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4" | |
2859 | "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF" | |
2860 | "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH" | |
2861 | "SP" "STX" "SUB" "SYN" "US" "VT"))) | |
f617db13 MW |
2862 | |
2863 | (setq font-lock-keywords | |
2864 | (list | |
5952a020 MW |
2865 | (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*" |
2866 | "\\(-+}\\|-*\\'\\)" | |
2867 | "\\|" | |
2868 | "--.*$") | |
f617db13 | 2869 | '(0 font-lock-comment-face)) |
5952a020 | 2870 | (list (concat "\\_<\\(" haskell-keywords "\\)\\_>") |
f617db13 | 2871 | '(0 font-lock-keyword-face)) |
5952a020 MW |
2872 | (list (concat "'\\(" |
2873 | "[^\\]" | |
2874 | "\\|" | |
2875 | "\\\\" | |
2876 | "\\(" "[abfnrtv\\\"']" "\\|" | |
2877 | "^" "\\(" control-sequences "\\|" | |
2878 | "[]A-Z@[\\^_]" "\\)" "\\|" | |
2879 | "\\|" | |
2880 | "[0-9]+" "\\|" | |
2881 | "[oO][0-7]+" "\\|" | |
2882 | "[xX][0-9A-Fa-f]+" | |
2883 | "\\)" | |
2884 | "\\)'") | |
2885 | '(0 font-lock-string-face)) | |
2886 | (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>" | |
2887 | '(0 font-lock-variable-name-face)) | |
2888 | (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|" | |
2889 | "\\_<[0-9]+\\(\\.[0-9]*\\|\\)" | |
f617db13 MW |
2890 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)") |
2891 | '(0 mdw-number-face)) | |
2892 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
2e7c6a86 | 2893 | '(0 mdw-punct-face)))))) |
f617db13 | 2894 | |
6132bc01 MW |
2895 | ;;;-------------------------------------------------------------------------- |
2896 | ;;; Erlang configuration. | |
2ded9493 | 2897 | |
52941dec | 2898 | (setq erlang-electric-commands nil) |
2ded9493 MW |
2899 | |
2900 | (defun mdw-fontify-erlang () | |
2901 | ||
6132bc01 | 2902 | ;; Set fill prefix. |
2ded9493 MW |
2903 | (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)") |
2904 | ||
6132bc01 | 2905 | ;; Fiddle with fontification. |
2ded9493 MW |
2906 | (make-local-variable 'font-lock-keywords) |
2907 | (let ((erlang-keywords | |
2908 | (mdw-regexps "after" "and" "andalso" | |
2909 | "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor" | |
2910 | "case" "catch" "cond" | |
2911 | "div" "end" "fun" "if" "let" "not" | |
2912 | "of" "or" "orelse" | |
2913 | "query" "receive" "rem" "try" "when" "xor"))) | |
2914 | ||
2915 | (setq font-lock-keywords | |
2916 | (list | |
2917 | (list "%.*$" | |
2918 | '(0 font-lock-comment-face)) | |
2919 | (list (concat "\\<\\(" erlang-keywords "\\)\\>") | |
2920 | '(0 font-lock-keyword-face)) | |
2921 | (list (concat "^-\\sw+\\>") | |
2922 | '(0 font-lock-keyword-face)) | |
2923 | (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>" | |
2924 | '(0 mdw-number-face)) | |
2925 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
2e7c6a86 | 2926 | '(0 mdw-punct-face)))))) |
2ded9493 | 2927 | |
6132bc01 MW |
2928 | ;;;-------------------------------------------------------------------------- |
2929 | ;;; Texinfo configuration. | |
f617db13 MW |
2930 | |
2931 | (defun mdw-fontify-texinfo () | |
2932 | ||
6132bc01 | 2933 | ;; Set fill prefix. |
f617db13 MW |
2934 | (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)") |
2935 | ||
6132bc01 | 2936 | ;; Real fontification things. |
02109a0d | 2937 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
2938 | (setq font-lock-keywords |
2939 | (list | |
f617db13 | 2940 | |
6132bc01 | 2941 | ;; Environment names are keywords. |
f617db13 MW |
2942 | (list "@\\(end\\) *\\([a-zA-Z]*\\)?" |
2943 | '(2 font-lock-keyword-face)) | |
2944 | ||
6132bc01 | 2945 | ;; Unmark escaped magic characters. |
f617db13 MW |
2946 | (list "\\(@\\)\\([@{}]\\)" |
2947 | '(1 font-lock-keyword-face) | |
2948 | '(2 font-lock-variable-name-face)) | |
2949 | ||
6132bc01 | 2950 | ;; Make sure we get comments properly. |
f617db13 MW |
2951 | (list "@c\\(\\|omment\\)\\( .*\\)?$" |
2952 | '(0 font-lock-comment-face)) | |
2953 | ||
6132bc01 | 2954 | ;; Command names are keywords. |
f617db13 MW |
2955 | (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)" |
2956 | '(0 font-lock-keyword-face)) | |
2957 | ||
6132bc01 | 2958 | ;; Fontify TeX special characters as punctuation. |
f617db13 | 2959 | (list "[{}]+" |
2e7c6a86 | 2960 | '(0 mdw-punct-face))))) |
f617db13 | 2961 | |
6132bc01 MW |
2962 | ;;;-------------------------------------------------------------------------- |
2963 | ;;; TeX and LaTeX configuration. | |
f617db13 MW |
2964 | |
2965 | (defun mdw-fontify-tex () | |
2966 | (setq ispell-parser 'tex) | |
55f80fae | 2967 | (turn-on-reftex) |
f617db13 | 2968 | |
6132bc01 | 2969 | ;; Don't make maths into a string. |
f617db13 MW |
2970 | (modify-syntax-entry ?$ ".") |
2971 | (modify-syntax-entry ?$ "." font-lock-syntax-table) | |
2972 | (local-set-key [?$] 'self-insert-command) | |
2973 | ||
df200ecd MW |
2974 | ;; Make `tab' be useful, given that tab stops in TeX don't work well. |
2975 | (local-set-key "\C-i" 'indent-relative) | |
2976 | (setq indent-tabs-mode nil) | |
2977 | ||
6132bc01 | 2978 | ;; Set fill prefix. |
f617db13 MW |
2979 | (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)") |
2980 | ||
6132bc01 | 2981 | ;; Real fontification things. |
02109a0d | 2982 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
2983 | (setq font-lock-keywords |
2984 | (list | |
f617db13 | 2985 | |
6132bc01 | 2986 | ;; Environment names are keywords. |
f617db13 MW |
2987 | (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)" |
2988 | "{\\([^}\n]*\\)}") | |
2989 | '(2 font-lock-keyword-face)) | |
2990 | ||
6132bc01 | 2991 | ;; Suspended environment names are keywords too. |
f617db13 MW |
2992 | (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?" |
2993 | "{\\([^}\n]*\\)}") | |
2994 | '(3 font-lock-keyword-face)) | |
2995 | ||
6132bc01 | 2996 | ;; Command names are keywords. |
f617db13 MW |
2997 | (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)" |
2998 | '(0 font-lock-keyword-face)) | |
2999 | ||
6132bc01 | 3000 | ;; Handle @/.../ for italics. |
f617db13 | 3001 | ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)" |
852cd5fb MW |
3002 | ;; '(1 font-lock-keyword-face) |
3003 | ;; '(3 font-lock-keyword-face)) | |
f617db13 | 3004 | |
6132bc01 | 3005 | ;; Handle @*...* for boldness. |
f617db13 | 3006 | ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)" |
852cd5fb MW |
3007 | ;; '(1 font-lock-keyword-face) |
3008 | ;; '(3 font-lock-keyword-face)) | |
f617db13 | 3009 | |
6132bc01 | 3010 | ;; Handle @`...' for literal syntax things. |
f617db13 | 3011 | ;; (list "\\(@`\\)\\([^']*\\)\\('\\)" |
852cd5fb MW |
3012 | ;; '(1 font-lock-keyword-face) |
3013 | ;; '(3 font-lock-keyword-face)) | |
f617db13 | 3014 | |
6132bc01 | 3015 | ;; Handle @<...> for nonterminals. |
f617db13 | 3016 | ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)" |
852cd5fb MW |
3017 | ;; '(1 font-lock-keyword-face) |
3018 | ;; '(3 font-lock-keyword-face)) | |
f617db13 | 3019 | |
6132bc01 | 3020 | ;; Handle other @-commands. |
f617db13 | 3021 | ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)" |
852cd5fb | 3022 | ;; '(0 font-lock-keyword-face)) |
f617db13 | 3023 | |
6132bc01 | 3024 | ;; Make sure we get comments properly. |
f617db13 MW |
3025 | (list "%.*" |
3026 | '(0 font-lock-comment-face)) | |
3027 | ||
6132bc01 | 3028 | ;; Fontify TeX special characters as punctuation. |
f617db13 | 3029 | (list "[$^_{}#&]" |
2e7c6a86 | 3030 | '(0 mdw-punct-face))))) |
f617db13 | 3031 | |
6132bc01 MW |
3032 | ;;;-------------------------------------------------------------------------- |
3033 | ;;; SGML hacking. | |
f25cf300 MW |
3034 | |
3035 | (defun mdw-sgml-mode () | |
3036 | (interactive) | |
3037 | (sgml-mode) | |
3038 | (mdw-standard-fill-prefix "") | |
8a425bd7 | 3039 | (make-local-variable 'sgml-delimiters) |
f25cf300 MW |
3040 | (setq sgml-delimiters |
3041 | '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]" | |
3042 | "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\"" | |
3043 | "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{" | |
3044 | "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?" | |
3045 | "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":" | |
3046 | "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>" | |
3047 | "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>" | |
3048 | "NULL" "")) | |
3049 | (setq major-mode 'mdw-sgml-mode) | |
3050 | (setq mode-name "[mdw] SGML") | |
3051 | (run-hooks 'mdw-sgml-mode-hook)) | |
6cb52f8b MW |
3052 | |
3053 | ;;;-------------------------------------------------------------------------- | |
3054 | ;;; Configuration files. | |
3055 | ||
3056 | (defvar mdw-conf-quote-normal nil | |
3057 | "*Control syntax category of quote characters `\"' and `''. | |
3058 | If this is `t', consider quote characters to be normal | |
3059 | punctuation, as for `conf-quote-normal'. If this is `nil' then | |
3060 | leave quote characters as quotes. If this is a list, then | |
3061 | consider the quote characters in the list to be normal | |
3062 | punctuation. If this is a single quote character, then consider | |
3063 | that character only to be normal punctuation.") | |
3064 | (defun mdw-conf-quote-normal-acceptable-value-p (value) | |
3065 | "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?" | |
3066 | (or (booleanp value) | |
3067 | (every (lambda (v) (memq v '(?\" ?'))) | |
3068 | (if (listp value) value (list value))))) | |
18bb0f77 MW |
3069 | (put 'mdw-conf-quote-normal 'safe-local-variable |
3070 | 'mdw-conf-quote-normal-acceptable-value-p) | |
6cb52f8b MW |
3071 | |
3072 | (defun mdw-fix-up-quote () | |
3073 | "Apply the setting of `mdw-conf-quote-normal'." | |
3074 | (let ((flag mdw-conf-quote-normal)) | |
3075 | (cond ((eq flag t) | |
3076 | (conf-quote-normal t)) | |
3077 | ((not flag) | |
3078 | nil) | |
3079 | (t | |
3080 | (let ((table (copy-syntax-table (syntax-table)))) | |
3081 | (mapc (lambda (ch) (modify-syntax-entry ch "." table)) | |
3082 | (if (listp flag) flag (list flag))) | |
3083 | (set-syntax-table table) | |
3084 | (and font-lock-mode (font-lock-fontify-buffer))))))) | |
18bb0f77 | 3085 | (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t) |
f25cf300 | 3086 | |
6132bc01 MW |
3087 | ;;;-------------------------------------------------------------------------- |
3088 | ;;; Shell scripts. | |
f617db13 MW |
3089 | |
3090 | (defun mdw-setup-sh-script-mode () | |
3091 | ||
6132bc01 | 3092 | ;; Fetch the shell interpreter's name. |
f617db13 MW |
3093 | (let ((shell-name sh-shell-file)) |
3094 | ||
6132bc01 | 3095 | ;; Try reading the hash-bang line. |
f617db13 MW |
3096 | (save-excursion |
3097 | (goto-char (point-min)) | |
3098 | (if (looking-at "#![ \t]*\\([^ \t\n]*\\)") | |
3099 | (setq shell-name (match-string 1)))) | |
3100 | ||
6132bc01 | 3101 | ;; Now try to set the shell. |
f617db13 MW |
3102 | ;; |
3103 | ;; Don't let `sh-set-shell' bugger up my script. | |
f617db13 MW |
3104 | (let ((executable-set-magic #'(lambda (s &rest r) s))) |
3105 | (sh-set-shell shell-name))) | |
3106 | ||
10c51541 MW |
3107 | ;; Don't insert here-document scaffolding automatically. |
3108 | (local-set-key "<" 'self-insert-command) | |
3109 | ||
6132bc01 | 3110 | ;; Now enable my keys and the fontification. |
f617db13 MW |
3111 | (mdw-misc-mode-config) |
3112 | ||
6132bc01 | 3113 | ;; Set the indentation level correctly. |
f617db13 MW |
3114 | (setq sh-indentation 2) |
3115 | (setq sh-basic-offset 2)) | |
3116 | ||
070c1dca MW |
3117 | (setq sh-shell-file "/bin/sh") |
3118 | ||
6d6e095a MW |
3119 | ;; Awful hacking to override the shell detection for particular scripts. |
3120 | (defmacro define-custom-shell-mode (name shell) | |
3121 | `(defun ,name () | |
3122 | (interactive) | |
3123 | (set (make-local-variable 'sh-shell-file) ,shell) | |
3124 | (sh-mode))) | |
3125 | (define-custom-shell-mode bash-mode "/bin/bash") | |
3126 | (define-custom-shell-mode rc-mode "/usr/bin/rc") | |
3127 | (put 'sh-shell-file 'permanent-local t) | |
3128 | ||
3129 | ;; Hack the rc syntax table. Backquotes aren't paired in rc. | |
3130 | (eval-after-load "sh-script" | |
3131 | '(or (assq 'rc sh-mode-syntax-table-input) | |
3132 | (let ((frag '(nil | |
3133 | ?# "<" | |
3134 | ?\n ">#" | |
3135 | ?\" "\"\"" | |
3136 | ?\' "\"\'" | |
3137 | ?$ "'" | |
3138 | ?\` "." | |
3139 | ?! "_" | |
3140 | ?% "_" | |
3141 | ?. "_" | |
3142 | ?^ "_" | |
3143 | ?~ "_" | |
3144 | ?, "_" | |
3145 | ?= "." | |
3146 | ?< "." | |
3147 | ?> ".")) | |
3148 | (assoc (assq 'rc sh-mode-syntax-table-input))) | |
3149 | (if assoc | |
3150 | (rplacd assoc frag) | |
3151 | (setq sh-mode-syntax-table-input | |
3152 | (cons (cons 'rc frag) | |
3153 | sh-mode-syntax-table-input)))))) | |
3154 | ||
6132bc01 | 3155 | ;;;-------------------------------------------------------------------------- |
092f0a38 MW |
3156 | ;;; Emacs shell mode. |
3157 | ||
3158 | (defun mdw-eshell-prompt () | |
3159 | (let ((left "[") (right "]")) | |
3160 | (when (= (user-uid) 0) | |
3161 | (setq left "«" right "»")) | |
3162 | (concat left | |
3163 | (save-match-data | |
3164 | (replace-regexp-in-string "\\..*$" "" (system-name))) | |
3165 | " " | |
2d8b2924 MW |
3166 | (let* ((pwd (eshell/pwd)) (npwd (length pwd)) |
3167 | (home (expand-file-name "~")) (nhome (length home))) | |
3168 | (if (and (>= npwd nhome) | |
3169 | (or (= nhome npwd) | |
5801e199 MW |
3170 | (= (elt pwd nhome) ?/)) |
3171 | (string= (substring pwd 0 nhome) home)) | |
2d8b2924 MW |
3172 | (concat "~" (substring pwd (length home))) |
3173 | pwd)) | |
092f0a38 MW |
3174 | right))) |
3175 | (setq eshell-prompt-function 'mdw-eshell-prompt) | |
ac4ae7cd | 3176 | (setq eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)") |
092f0a38 | 3177 | |
2d8b2924 MW |
3178 | (defun eshell/e (file) (find-file file) nil) |
3179 | (defun eshell/ee (file) (find-file-other-window file) nil) | |
3180 | (defun eshell/w3m (url) (w3m-goto-url url) nil) | |
415a23dd | 3181 | |
092f0a38 MW |
3182 | (mdw-define-face eshell-prompt (t :weight bold)) |
3183 | (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red")) | |
3184 | (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic)) | |
3185 | (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic)) | |
3186 | (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic)) | |
3187 | (mdw-define-face eshell-ls-executable (t :weight bold)) | |
3188 | (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold)) | |
3189 | (mdw-define-face eshell-ls-readonly (t nil)) | |
3190 | (mdw-define-face eshell-ls-symlink (t :foreground "cyan")) | |
3191 | ||
3192 | ;;;-------------------------------------------------------------------------- | |
6132bc01 | 3193 | ;;; Messages-file mode. |
f617db13 | 3194 | |
4bb22eea | 3195 | (defun messages-mode-guts () |
f617db13 MW |
3196 | (setq messages-mode-syntax-table (make-syntax-table)) |
3197 | (set-syntax-table messages-mode-syntax-table) | |
f617db13 MW |
3198 | (modify-syntax-entry ?0 "w" messages-mode-syntax-table) |
3199 | (modify-syntax-entry ?1 "w" messages-mode-syntax-table) | |
3200 | (modify-syntax-entry ?2 "w" messages-mode-syntax-table) | |
3201 | (modify-syntax-entry ?3 "w" messages-mode-syntax-table) | |
3202 | (modify-syntax-entry ?4 "w" messages-mode-syntax-table) | |
3203 | (modify-syntax-entry ?5 "w" messages-mode-syntax-table) | |
3204 | (modify-syntax-entry ?6 "w" messages-mode-syntax-table) | |
3205 | (modify-syntax-entry ?7 "w" messages-mode-syntax-table) | |
3206 | (modify-syntax-entry ?8 "w" messages-mode-syntax-table) | |
3207 | (modify-syntax-entry ?9 "w" messages-mode-syntax-table) | |
3208 | (make-local-variable 'comment-start) | |
3209 | (make-local-variable 'comment-end) | |
3210 | (make-local-variable 'indent-line-function) | |
3211 | (setq indent-line-function 'indent-relative) | |
3212 | (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)") | |
3213 | (make-local-variable 'font-lock-defaults) | |
4bb22eea | 3214 | (make-local-variable 'messages-mode-keywords) |
f617db13 | 3215 | (let ((keywords |
8d6d55b9 MW |
3216 | (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum" |
3217 | "export" "enum" "fixed-octetstring" "flags" | |
3218 | "harmless" "map" "nested" "optional" | |
3219 | "optional-tagged" "package" "primitive" | |
3220 | "primitive-nullfree" "relaxed[ \t]+enum" | |
3221 | "set" "table" "tagged-optional" "union" | |
3222 | "variadic" "vector" "version" "version-tag"))) | |
4bb22eea | 3223 | (setq messages-mode-keywords |
f617db13 MW |
3224 | (list |
3225 | (list (concat "\\<\\(" keywords "\\)\\>:") | |
3226 | '(0 font-lock-keyword-face)) | |
3227 | '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face)) | |
3228 | '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)" | |
3229 | (0 font-lock-variable-name-face)) | |
3230 | '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face)) | |
3231 | '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
3232 | (0 mdw-punct-face))))) | |
3233 | (setq font-lock-defaults | |
4bb22eea | 3234 | '(messages-mode-keywords nil nil nil nil)) |
f617db13 MW |
3235 | (run-hooks 'messages-file-hook)) |
3236 | ||
3237 | (defun messages-mode () | |
3238 | (interactive) | |
3239 | (fundamental-mode) | |
3240 | (setq major-mode 'messages-mode) | |
3241 | (setq mode-name "Messages") | |
4bb22eea | 3242 | (messages-mode-guts) |
f617db13 MW |
3243 | (modify-syntax-entry ?# "<" messages-mode-syntax-table) |
3244 | (modify-syntax-entry ?\n ">" messages-mode-syntax-table) | |
3245 | (setq comment-start "# ") | |
3246 | (setq comment-end "") | |
f617db13 MW |
3247 | (run-hooks 'messages-mode-hook)) |
3248 | ||
3249 | (defun cpp-messages-mode () | |
3250 | (interactive) | |
3251 | (fundamental-mode) | |
3252 | (setq major-mode 'cpp-messages-mode) | |
3253 | (setq mode-name "CPP Messages") | |
4bb22eea | 3254 | (messages-mode-guts) |
f617db13 MW |
3255 | (modify-syntax-entry ?* ". 23" messages-mode-syntax-table) |
3256 | (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table) | |
3257 | (setq comment-start "/* ") | |
3258 | (setq comment-end " */") | |
3259 | (let ((preprocessor-keywords | |
8d6d55b9 MW |
3260 | (mdw-regexps "assert" "define" "elif" "else" "endif" "error" |
3261 | "ident" "if" "ifdef" "ifndef" "import" "include" | |
3262 | "line" "pragma" "unassert" "undef" "warning"))) | |
4bb22eea | 3263 | (setq messages-mode-keywords |
f617db13 MW |
3264 | (append (list (list (concat "^[ \t]*\\#[ \t]*" |
3265 | "\\(include\\|import\\)" | |
3266 | "[ \t]*\\(<[^>]+\\(>\\|\\)\\)") | |
3267 | '(2 font-lock-string-face)) | |
3268 | (list (concat "^\\([ \t]*#[ \t]*\\(\\(" | |
3269 | preprocessor-keywords | |
852cd5fb | 3270 | "\\)\\>\\|[0-9]+\\|$\\)\\)") |
f617db13 | 3271 | '(1 font-lock-keyword-face))) |
4bb22eea | 3272 | messages-mode-keywords))) |
297d60aa | 3273 | (run-hooks 'cpp-messages-mode-hook)) |
f617db13 | 3274 | |
297d60aa MW |
3275 | (add-hook 'messages-mode-hook 'mdw-misc-mode-config t) |
3276 | (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t) | |
f617db13 MW |
3277 | ; (add-hook 'messages-file-hook 'mdw-fontify-messages t) |
3278 | ||
6132bc01 MW |
3279 | ;;;-------------------------------------------------------------------------- |
3280 | ;;; Messages-file mode. | |
f617db13 MW |
3281 | |
3282 | (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face | |
3283 | "Face to use for subsittution directives.") | |
3284 | (make-face 'mallow-driver-substitution-face) | |
3285 | (defvar mallow-driver-text-face 'mallow-driver-text-face | |
3286 | "Face to use for body text.") | |
3287 | (make-face 'mallow-driver-text-face) | |
3288 | ||
3289 | (defun mallow-driver-mode () | |
3290 | (interactive) | |
3291 | (fundamental-mode) | |
3292 | (setq major-mode 'mallow-driver-mode) | |
3293 | (setq mode-name "Mallow driver") | |
3294 | (setq mallow-driver-mode-syntax-table (make-syntax-table)) | |
3295 | (set-syntax-table mallow-driver-mode-syntax-table) | |
3296 | (make-local-variable 'comment-start) | |
3297 | (make-local-variable 'comment-end) | |
3298 | (make-local-variable 'indent-line-function) | |
3299 | (setq indent-line-function 'indent-relative) | |
3300 | (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)") | |
3301 | (make-local-variable 'font-lock-defaults) | |
3302 | (make-local-variable 'mallow-driver-mode-keywords) | |
3303 | (let ((keywords | |
8d6d55b9 MW |
3304 | (mdw-regexps "each" "divert" "file" "if" |
3305 | "perl" "set" "string" "type" "write"))) | |
f617db13 MW |
3306 | (setq mallow-driver-mode-keywords |
3307 | (list | |
3308 | (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$") | |
3309 | '(0 font-lock-keyword-face)) | |
3310 | (list "^%\\s *\\(#.*\\|\\)$" | |
3311 | '(0 font-lock-comment-face)) | |
3312 | (list "^%" | |
3313 | '(0 font-lock-keyword-face)) | |
3314 | (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face)) | |
3315 | (list "\\${[^}]*}" | |
3316 | '(0 mallow-driver-substitution-face t))))) | |
3317 | (setq font-lock-defaults | |
3318 | '(mallow-driver-mode-keywords nil nil nil nil)) | |
3319 | (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table) | |
3320 | (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table) | |
3321 | (setq comment-start "%# ") | |
3322 | (setq comment-end "") | |
f617db13 MW |
3323 | (run-hooks 'mallow-driver-mode-hook)) |
3324 | ||
3325 | (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t) | |
3326 | ||
6132bc01 MW |
3327 | ;;;-------------------------------------------------------------------------- |
3328 | ;;; NFast debugs. | |
f617db13 MW |
3329 | |
3330 | (defun nfast-debug-mode () | |
3331 | (interactive) | |
3332 | (fundamental-mode) | |
3333 | (setq major-mode 'nfast-debug-mode) | |
3334 | (setq mode-name "NFast debug") | |
3335 | (setq messages-mode-syntax-table (make-syntax-table)) | |
3336 | (set-syntax-table messages-mode-syntax-table) | |
3337 | (make-local-variable 'font-lock-defaults) | |
3338 | (make-local-variable 'nfast-debug-mode-keywords) | |
3339 | (setq truncate-lines t) | |
3340 | (setq nfast-debug-mode-keywords | |
3341 | (list | |
3342 | '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)" | |
3343 | (0 font-lock-keyword-face)) | |
3344 | (list (concat "^[ \t]+\\(\\(" | |
3345 | "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]" | |
3346 | "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]" | |
3347 | "[ \t]+\\)*" | |
3348 | "[0-9a-fA-F]+\\)[ \t]*$") | |
3349 | '(0 mdw-number-face)) | |
3350 | '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>" | |
3351 | (1 font-lock-keyword-face)) | |
3352 | '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>" | |
3353 | (1 font-lock-warning-face)) | |
3354 | '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>" | |
3355 | (1 nil)) | |
3356 | (list (concat "^[ \t]+\\.cmd=[ \t]+" | |
3357 | "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>") | |
3358 | '(1 font-lock-keyword-face)) | |
3359 | '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face)) | |
3360 | '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face)) | |
3361 | '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face)) | |
3362 | '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face)))) | |
3363 | (setq font-lock-defaults | |
3364 | '(nfast-debug-mode-keywords nil nil nil nil)) | |
f617db13 MW |
3365 | (run-hooks 'nfast-debug-mode-hook)) |
3366 | ||
6132bc01 MW |
3367 | ;;;-------------------------------------------------------------------------- |
3368 | ;;; Other languages. | |
f617db13 | 3369 | |
6132bc01 | 3370 | ;; Smalltalk. |
f617db13 MW |
3371 | |
3372 | (defun mdw-setup-smalltalk () | |
3373 | (and mdw-auto-indent | |
3374 | (local-set-key "\C-m" 'smalltalk-newline-and-indent)) | |
8a425bd7 | 3375 | (make-local-variable 'mdw-auto-indent) |
f617db13 MW |
3376 | (setq mdw-auto-indent nil) |
3377 | (local-set-key "\C-i" 'smalltalk-reindent)) | |
3378 | ||
3379 | (defun mdw-fontify-smalltalk () | |
02109a0d | 3380 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
3381 | (setq font-lock-keywords |
3382 | (list | |
f617db13 MW |
3383 | (list "\\<[A-Z][a-zA-Z0-9]*\\>" |
3384 | '(0 font-lock-keyword-face)) | |
3385 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
3386 | "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
3387 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
3388 | '(0 mdw-number-face)) | |
3389 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
2e7c6a86 | 3390 | '(0 mdw-punct-face))))) |
f617db13 | 3391 | |
6132bc01 | 3392 | ;; Lispy languages. |
f617db13 | 3393 | |
873d87df MW |
3394 | ;; Unpleasant bodge. |
3395 | (unless (boundp 'slime-repl-mode-map) | |
3396 | (setq slime-repl-mode-map (make-sparse-keymap))) | |
3397 | ||
f617db13 MW |
3398 | (defun mdw-indent-newline-and-indent () |
3399 | (interactive) | |
3400 | (indent-for-tab-command) | |
3401 | (newline-and-indent)) | |
3402 | ||
3403 | (eval-after-load "cl-indent" | |
3404 | '(progn | |
3405 | (mapc #'(lambda (pair) | |
3406 | (put (car pair) | |
3407 | 'common-lisp-indent-function | |
3408 | (cdr pair))) | |
3409 | '((destructuring-bind . ((&whole 4 &rest 1) 4 &body)) | |
3410 | (multiple-value-bind . ((&whole 4 &rest 1) 4 &body)))))) | |
3411 | ||
3412 | (defun mdw-common-lisp-indent () | |
8a425bd7 | 3413 | (make-local-variable 'lisp-indent-function) |
f617db13 MW |
3414 | (setq lisp-indent-function 'common-lisp-indent-function)) |
3415 | ||
037be6de | 3416 | (setq lisp-simple-loop-indentation 2 |
95575d1f MW |
3417 | lisp-loop-keyword-indentation 6 |
3418 | lisp-loop-forms-indentation 6) | |
3419 | ||
f617db13 MW |
3420 | (defun mdw-fontify-lispy () |
3421 | ||
6132bc01 | 3422 | ;; Set fill prefix. |
f617db13 MW |
3423 | (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)") |
3424 | ||
6132bc01 | 3425 | ;; Not much fontification needed. |
02109a0d | 3426 | (make-local-variable 'font-lock-keywords) |
f617db13 | 3427 | (setq font-lock-keywords |
2287504f MW |
3428 | (list (list (concat "\\(" |
3429 | "\\_<[-+]?" | |
3430 | "\\(" "[0-9]+/[0-9]+" | |
3431 | "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|" | |
3432 | "\\.[0-9]+" "\\)" | |
3433 | "\\([dDeEfFlLsS][-+]?[0-9]+\\)?" | |
3434 | "\\)" | |
3435 | "\\|" | |
3436 | "#" | |
3437 | "\\(" "x" "[-+]?" | |
3438 | "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?" | |
3439 | "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?" | |
3440 | "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?" | |
3441 | "\\|" "[0-9]+" "r" "[-+]?" | |
3442 | "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?" | |
3443 | "\\)" | |
3444 | "\\)\\_>") | |
3445 | '(0 mdw-number-face)) | |
3446 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
2e7c6a86 | 3447 | '(0 mdw-punct-face))))) |
f617db13 MW |
3448 | |
3449 | (defun comint-send-and-indent () | |
3450 | (interactive) | |
3451 | (comint-send-input) | |
3452 | (and mdw-auto-indent | |
3453 | (indent-for-tab-command))) | |
3454 | ||
ec007bea | 3455 | (defun mdw-setup-m4 () |
ed5d93a4 MW |
3456 | |
3457 | ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very | |
3458 | ;; annoying: fix it. | |
3459 | (modify-syntax-entry ?{ "(") | |
3460 | (modify-syntax-entry ?} ")") | |
3461 | ||
3462 | ;; Fill prefix. | |
ec007bea MW |
3463 | (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)")) |
3464 | ||
6132bc01 MW |
3465 | ;;;-------------------------------------------------------------------------- |
3466 | ;;; Text mode. | |
f617db13 MW |
3467 | |
3468 | (defun mdw-text-mode () | |
3469 | (setq fill-column 72) | |
3470 | (flyspell-mode t) | |
3471 | (mdw-standard-fill-prefix | |
c7a8da49 | 3472 | "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3) |
f617db13 MW |
3473 | (auto-fill-mode 1)) |
3474 | ||
6132bc01 | 3475 | ;;;-------------------------------------------------------------------------- |
faf2cef7 | 3476 | ;;; Outline and hide/show modes. |
5de5db48 MW |
3477 | |
3478 | (defun mdw-outline-collapse-all () | |
3479 | "Completely collapse everything in the entire buffer." | |
3480 | (interactive) | |
3481 | (save-excursion | |
3482 | (goto-char (point-min)) | |
3483 | (while (< (point) (point-max)) | |
3484 | (hide-subtree) | |
3485 | (forward-line)))) | |
3486 | ||
faf2cef7 MW |
3487 | (setq hs-hide-comments-when-hiding-all nil) |
3488 | ||
b200af26 | 3489 | (defadvice hs-hide-all (after hide-first-comment activate) |
941c29ba | 3490 | (save-excursion (hs-hide-initial-comment-block))) |
b200af26 | 3491 | |
6132bc01 MW |
3492 | ;;;-------------------------------------------------------------------------- |
3493 | ;;; Shell mode. | |
f617db13 MW |
3494 | |
3495 | (defun mdw-sh-mode-setup () | |
3496 | (local-set-key [?\C-a] 'comint-bol) | |
3497 | (add-hook 'comint-output-filter-functions | |
3498 | 'comint-watch-for-password-prompt)) | |
3499 | ||
3500 | (defun mdw-term-mode-setup () | |
3d9147ea | 3501 | (setq term-prompt-regexp shell-prompt-pattern) |
f617db13 MW |
3502 | (make-local-variable 'mouse-yank-at-point) |
3503 | (make-local-variable 'transient-mark-mode) | |
3504 | (setq mouse-yank-at-point t) | |
f617db13 MW |
3505 | (auto-fill-mode -1) |
3506 | (setq tab-width 8)) | |
3507 | ||
3d9147ea MW |
3508 | (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C")) |
3509 | (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D")) | |
3510 | (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_")) | |
3511 | (defun term-send-meta-meta-something () | |
3512 | (interactive) | |
3513 | (term-send-raw-string "\e\e") | |
3514 | (term-send-raw)) | |
3515 | (eval-after-load 'term | |
3516 | '(progn | |
3517 | (define-key term-raw-map [?\e ?\e] nil) | |
3518 | (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something) | |
3519 | (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore) | |
3520 | (define-key term-raw-map [M-right] 'term-send-meta-right) | |
3521 | (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right) | |
3522 | (define-key term-raw-map [M-left] 'term-send-meta-left) | |
3523 | (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left))) | |
3524 | ||
c4434c20 MW |
3525 | (defadvice term-exec (before program-args-list compile activate) |
3526 | "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES). | |
3527 | This allows you to pass a list of arguments through `ansi-term'." | |
3528 | (let ((program (ad-get-arg 2))) | |
3529 | (if (listp program) | |
3530 | (progn | |
3531 | (ad-set-arg 2 (car program)) | |
3532 | (ad-set-arg 4 (cdr program)))))) | |
3533 | ||
3534 | (defun ssh (host) | |
3535 | "Open a terminal containing an ssh session to the HOST." | |
3536 | (interactive "sHost: ") | |
3537 | (ansi-term (list "ssh" host) (format "ssh@%s" host))) | |
3538 | ||
5aa1b95f MW |
3539 | (defvar git-grep-command |
3540 | "env PAGER=cat git grep --no-color -nH -e " | |
3541 | "*The default command for \\[git-grep].") | |
3542 | ||
3543 | (defvar git-grep-history nil) | |
3544 | ||
3545 | (defun git-grep (command-args) | |
3546 | "Run `git grep' with user-specified args and collect output in a buffer." | |
3547 | (interactive | |
3548 | (list (read-shell-command "Run git grep (like this): " | |
3549 | git-grep-command 'git-grep-history))) | |
3550 | (grep command-args)) | |
3551 | ||
e07e3320 MW |
3552 | ;;;-------------------------------------------------------------------------- |
3553 | ;;; Inferior Emacs Lisp. | |
3554 | ||
3555 | (setq comint-prompt-read-only t) | |
3556 | ||
3557 | (eval-after-load "comint" | |
3558 | '(progn | |
3559 | (define-key comint-mode-map "\C-w" 'comint-kill-region) | |
3560 | (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line))) | |
3561 | ||
3562 | (eval-after-load "ielm" | |
3563 | '(progn | |
3564 | (define-key ielm-map "\C-w" 'comint-kill-region) | |
3565 | (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line))) | |
3566 | ||
f617db13 MW |
3567 | ;;;----- That's all, folks -------------------------------------------------- |
3568 | ||
3569 | (provide 'dot-emacs) |