Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 90 lines (85 sloc) 4.189 kb
837fb6c first commit; was stolen from somewhere on the web as-is
Nicholas E. May (on Enterprise) authored
1 ;;; tj-parenface.el --- Provide a face for parens and square brackets in
2 ;; numerous modes.
3 ;; Based on parenface By Dave Pearson <davep@davep.org>
4 ;; Bracket support and additional hookds added by
5 ;; Tim Johnson <tim@johnsons-web.com>
6 ;;; Credits:
7 ;; Thanks to Dave Pearson who indicates that his code was
8 ;; based on some code that Boris Schaefer <boris@uncommon-sense.net> posted
9 ;; to comp.lang.scheme in message <87hf8g9nw5.fsf@qiwi.uncommon-sense.net>.
10 ;;
11 ;; $Revision: 1.1 $
12
13 ;; Add a paren-face to emacs and add support for it to various modes.
14 ;; Add a bracket-face to emacs and add support for it to various modes.
15 ;;
16 (defvar paren-face 'paren-face)
17 (defvar bracket-face 'bracket-face)
18 (defvar brace-face 'brace-face)
19 (defvar fslash-face 'fslash-face)
20 (defface fslash-face
21 '((((class color)) (background dark)(:foreground "white"))
22 (((class color)) (background light)(:foreground "blue")))
23 "Face for displaying a forward slash."
24 :group 'faces)
25 (defface paren-face
26 '((((class color)) (background dark)(:foreground "white"))
27 (((class color)) (background light)(:foreground "blue")))
28 "Face for displaying a paren."
29 :group 'faces)
30 (defface bracket-face
31 '((((class color)) (background dark)(:foreground "yellow2"))
32 (((class color)) (background light)(:foreground "#8B6508")))
33 "Face for displaying a square bracket."
34 :group 'faces)
35 (defface brace-face
36 '((((class color)) (background dark)(:foreground "yellow2"))
37 (((class color)) (background light)(:foreground "#8B6508")))
38 "Face for displaying braces."
39 :group 'faces)
40 (defmacro paren-face-add-support (keywords)
41 "Generate a lambda expression for use in a hook."
42 `(lambda ()
43 (let* ((regexp "(\\|)")
44 (match (assoc regexp ,keywords)))
45 (unless (eq (cdr match) paren-face)
46 (setq ,keywords (append (list (cons regexp paren-face)) ,keywords))))))
47 (defmacro bracket-face-add-support (keywords)
48 "Generate a lambda expression for use in a hook."
49 `(lambda ()
50 (let* ((regexp "\\[\\|\\]")
51 (match (assoc regexp ,keywords)))
52 (unless (eq (cdr match) bracket-face)
53 (setq ,keywords (append (list (cons regexp bracket-face)) ,keywords))))))
54 (defmacro brace-face-add-support (keywords)
55 "Generate a lambda expression for use in a hook."
56 `(lambda ()
57 (let* ((regexp "{\\|}")
58 (match (assoc regexp ,keywords)))
59 (unless (eq (cdr match) brace-face)
60 (setq ,keywords (append (list (cons regexp brace-face)) ,keywords))))))
61 ;(defmacro fslash-face-add-support (keywords)
62 ; "Generate a lambda expression for use in a hook."
63 ; `(lambda ()
64 ; (let* ((regexp "\\/")
65 ; (match (assoc regexp ,keywords)))
66 ; (unless (eq (cdr match) bracket-face)
67 ; (setq ,keywords (append (list (cons regexp fslash-face)) ,keywords))))))
68 ;; Keep the compiler quiet.
69 (eval-when-compile
70 (defvar scheme-font-lock-keywords-2 nil)
71 (defvar lisp-font-lock-keywords-2 nil))
72
73 (add-hook 'scheme-mode-hook (paren-face-add-support scheme-font-lock-keywords-2))
74 (add-hook 'newlisp-mode-hook (paren-face-add-support newlisp-font-lock-keywords))
75 (add-hook 'lisp-mode-hook (paren-face-add-support lisp-font-lock-keywords-2))
76 (add-hook 'lisp1-mode-hook (paren-face-add-support lisp1-font-lock-keywords))
77 (add-hook 'rebol-mode-hook (bracket-face-add-support rebol-font-lock-keywords))
78 (add-hook 'rebol-mode-hook (paren-face-add-support rebol-font-lock-keywords))
79 (add-hook 'tj-lua-mode-hook (bracket-face-add-support tj-lua-font-lock-keywords))
80 (add-hook 'tj-lua-mode-hook (paren-face-add-support tj-lua-font-lock-keywords))
81 (add-hook 'tj-lua-mode-hook (brace-face-add-support tj-lua-font-lock-keywords))
82 ;(add-hook 'rebol-mode-hook (fslash-face-add-support rebol-font-lock-keywords))
83 (add-hook 'python-mode-hook (paren-face-add-support python-font-lock-keywords))
84 (add-hook 'emacs-lisp-mode-hook (paren-face-add-support lisp-font-lock-keywords-2))
85 (add-hook 'lisp-interaction-mode-hook (paren-face-add-support lisp-font-lock-keywords-2))
86
87 (provide 'tj-parenface)
88
89 ;; tj-parenface.el ends here
Something went wrong with that request. Please try again.