-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocky.el
138 lines (116 loc) · 4.75 KB
/
blocky.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
;;; blocky.el --- Emacs tools for blocky
;; Copyright (C) 2006, 2007, 2008, 2009, 2010 David O'Toole
;; Author: David O'Toole <[email protected]>
;; Keywords: lisp, oop, extensions
;; Version: 0.1
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Code:
(require 'rx)
(require 'cl)
(defun eval-in-cl (cl-expression-string &optional process-result-values)
(slime-eval-async `(swank:eval-and-grab-output ,cl-expression-string)
(lexical-let ((here (current-buffer))
(process-result-values process-result-values))
(lambda (result-values)
(when process-result-values
(set-buffer here)
(funcall process-result-values (rest result-values)))))))
(defun blocky-insinuate-lisp ()
(interactive)
(add-hook 'lisp-mode-hook
#'(lambda ()
(add-to-list 'imenu-generic-expression
`("Methods" ,(rx (sequence "(" (group "define-method")
(one-or-more space)
(group (one-or-more (not (any space)))
(one-or-more space)
(one-or-more (not (any space))))))
2))
(add-to-list 'imenu-generic-expression
`("Blocks" ,(rx (sequence "(" (group "define-block")
(zero-or-more "-macro")
(one-or-more space)
(zero-or-one "(")
(group (one-or-more (or "-" (any word))))))
2))
(imenu-add-menubar-index)))
(defadvice slime-compile-defun (after blocky activate)
(eval-in-cl "(blocky:update-parameters)")))
;; (blocky-insinuate-lisp)
;;; Font-locking
;; Put this in your emacs initialization file to get the highlighting:
;; (add-hook 'emacs-lisp-mode-hook #'blocky-do-font-lock)
(defvar blocky-font-lock-keywords
`((,(rx (sequence "(" (group "define-method")
(one-or-more space)
(group (one-or-more (not (any space))))
(one-or-more space)
(group (one-or-more (not (any space))))))
(1 font-lock-keyword-face)
(2 font-lock-function-name-face) ;; this still doesn't work
;; properly.
(3 font-lock-type-face))
(,(rx (sequence "(" (group "define-prototype")
(one-or-more space)
(group (one-or-more (not (any space))))))
(1 font-lock-keyword-face)
(2 font-lock-type-face))
(,(rx (sequence "(" (group "define-block-macro")
(one-or-more space)
(group (one-or-more (not (any space))))))
(1 font-lock-keyword-face)
(2 font-lock-type-face))
(,(rx (sequence "(" (group "define-block")
(one-or-more space)
(group (one-or-more (not (any space))))))
(1 font-lock-keyword-face)
(2 font-lock-type-face))
; ("\\<\\(\<[^<>]*\>\\)\\>" (1 font-lock-preprocessor-face))
("(.*\\(\>\>\\>\\)" (1 font-lock-type-face))))
(defun blocky-do-font-lock ()
(interactive)
"Highlight the keywords used in prototype-oriented programming."
(font-lock-add-keywords nil blocky-font-lock-keywords))
;;; Grabbing UUIDs and inspecting the corresponding objects
(defvar blocky-uuid-regexp
"[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]")
(defun blocky-inspect-uuid (uuid)
(interactive "sInspect blocky UUID: ")
(if (null uuid)
(message "No UUID provided.")
(progn
(assert (stringp uuid))
(slime-inspect
(format "(blocky::find-object %S)" uuid)))))
(defun blocky-uuid-at-point ()
(let ((thing (thing-at-point 'word)))
(when (and (not (null thing))
(string-match blocky-uuid-regexp thing))
thing)))
(defun blocky-uuid-on-this-line ()
(string-match blocky-uuid-regexp
(buffer-substring-no-properties
(point-at-bol)
(point-at-eol))))
(defun blocky-inspect ()
(interactive)
(blocky-inspect-uuid (or (blocky-uuid-at-point)
(blocky-uuid-on-this-line))))
;; (set-frame-parameter nil 'background-mode 'dark)
;; (set-frame-parameter nil 'background-color "gray40")
;; (set-frame-parameter nil 'foreground-color "white")
;; (set-frame-parameter nil 'border-color "gray20")
;; (set-frame-parameter nil 'cursor-color "magenta"))
(provide 'blocky)
;;; blocky.el ends here