-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathxelf.el
138 lines (116 loc) · 4.71 KB
/
xelf.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
;;; xelf.el --- Emacs tools for xelf
;; Copyright (C) 2006, 2007, 2008, 2009, 2010 David O'Toole
;; Author: David O'Toole <dto@gnu.org>
;; 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 xelf-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 xelf activate)
(eval-in-cl "(xelf:update-parameters)")))
;; (xelf-insinuate-lisp)
;;; Font-locking
;; Put this in your emacs initialization file to get the highlighting:
;; (add-hook 'emacs-lisp-mode-hook #'xelf-do-font-lock)
(defvar xelf-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 xelf-do-font-lock ()
(interactive)
"Highlight the keywords used in prototype-oriented programming."
(font-lock-add-keywords nil xelf-font-lock-keywords))
;;; Grabbing UUIDs and inspecting the corresponding objects
(defvar xelf-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 xelf-inspect-uuid (uuid)
(interactive "sInspect xelf UUID: ")
(if (null uuid)
(message "No UUID provided.")
(progn
(assert (stringp uuid))
(slime-inspect
(format "(xelf::find-object %S)" uuid)))))
(defun xelf-uuid-at-point ()
(let ((thing (thing-at-point 'word)))
(when (and (not (null thing))
(string-match xelf-uuid-regexp thing))
thing)))
(defun xelf-uuid-on-this-line ()
(string-match xelf-uuid-regexp
(buffer-substring-no-properties
(point-at-bol)
(point-at-eol))))
(defun xelf-inspect ()
(interactive)
(xelf-inspect-uuid (or (xelf-uuid-at-point)
(xelf-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 'xelf)
;;; xelf.el ends here