Skip to content
Newer
Older
100644 152 lines (122 sloc) 5.08 KB
3d3edb9 @jscheid Rename kite-repl to kite-scratch
authored Sep 23, 2012
1 ;;; kite-scratch.el --- Kite scratch buffer implementation
1d47367 @jscheid Add license
authored Aug 24, 2012
2
3 ;; Copyright (C) 2012 Julian Scheid
4
5eebac9 @jscheid Add email address to author name
authored Aug 25, 2012
5 ;; Author: Julian Scheid <julians37@gmail.com>
afe1642 @jscheid Remove 'WWW' keyword
authored Aug 25, 2012
6 ;; Keywords: tools
3deba10 @jscheid Improve package meta-data
authored Aug 25, 2012
7 ;; Package: kite
8 ;; Compatibility: GNU Emacs 24
9
dc768cf @jscheid Add note that kite is not part of Emacs
authored Aug 25, 2012
10 ;; This file is not part of GNU Emacs.
1d47367 @jscheid Add license
authored Aug 25, 2012
11
12 ;; Kite is free software: you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
16
17 ;; Kite is distributed in the hope that it will be useful, but WITHOUT
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
20 ;; License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with Kite. If not, see <http://www.gnu.org/licenses/>.
24
25 ;;; Commentary:
26
3d3edb9 @jscheid Rename kite-repl to kite-scratch
authored Sep 23, 2012
27 ;; This package implements a buffer suitable for evaluating JavaScript
28 ;; code, akin to the Emacs *scratch* buffer for evaluating Lisp code.
1d47367 @jscheid Add license
authored Aug 25, 2012
29 ;;
30 ;; It is part of Kite, a WebKit inspector front-end.
31
32
33 ;;; Code:
d2e9b2c Move REPL stuff into kite-repl.el
Julian Scheid authored Jul 6, 2012
34
e5131c3 @jscheid Add missing requirements
authored Sep 23, 2012
35 (require 'js)
36
37 (require 'kite-global)
40e90bf @jscheid Add CL compat layer, fix remaining byte compilation issues
authored Sep 24, 2012
38 (require 'kite-object)
e5131c3 @jscheid Add missing requirements
authored Sep 23, 2012
39 (require 'kite-util)
40
54536cb @jscheid Rejiggle everything for new session handling and global hotkeys; port…
authored Aug 24, 2012
41 (defface kite-link-face
42 '((t (:inherit change-log-file)))
43 "Face used for links to source code locations."
44 :group 'kite-highlighting-faces)
45
3d3edb9 @jscheid Rename kite-repl to kite-scratch
authored Sep 23, 2012
46 (defvar kite-scratch-mode-map
d2e9b2c Move REPL stuff into kite-repl.el
Julian Scheid authored Jul 6, 2012
47 (let ((map (make-keymap))
48 (menu-map (make-sparse-keymap)))
49 (define-key map (kbd "C-M-x") 'kite-eval-defun)
3d3edb9 @jscheid Rename kite-repl to kite-scratch
authored Sep 23, 2012
50 (define-key map (kbd "C-c C-c") 'kite-scratch-eval)
d2e9b2c Move REPL stuff into kite-repl.el
Julian Scheid authored Jul 6, 2012
51 map)
3d3edb9 @jscheid Rename kite-repl to kite-scratch
authored Sep 23, 2012
52 "Local keymap for `kite-scratch-mode' buffers.")
d2e9b2c Move REPL stuff into kite-repl.el
Julian Scheid authored Jul 6, 2012
53
3d3edb9 @jscheid Rename kite-repl to kite-scratch
authored Sep 23, 2012
54 (defvar kite-scratch-mode-link-map
54536cb @jscheid Rejiggle everything for new session handling and global hotkeys; port…
authored Aug 25, 2012
55 (let ((map (make-sparse-keymap)))
56 (define-key map [mouse-2] 'kite-goto-link)
57 (define-key map (kbd "RET") 'kite-goto-link)
58 map))
59
60 (defun kite-goto-link ()
61 (interactive)
62 (message "kite-goto-link"))
63
3d3edb9 @jscheid Rename kite-repl to kite-scratch
authored Sep 23, 2012
64 (define-derived-mode kite-scratch-mode javascript-mode "kite-scratch"
65 "Toggle kite scratch mode."
1f80f47 @jscheid Set customization group for all kite modes
authored Aug 25, 2012
66 :group 'kite
54536cb @jscheid Rejiggle everything for new session handling and global hotkeys; port…
authored Aug 25, 2012
67 (set (make-local-variable 'font-lock-extra-managed-props) '(keymap))
c94abb4 @jscheid Ensure scratch buffer output is fontified
authored Sep 23, 2012
68
69 (set (make-local-variable 'font-lock-fontify-region-function)
70 (lambda (beginning end &optional verbose)
71 "Override to ensure our preset font face isn't changed
72 by font locking"
73 (prog1
74 (font-lock-default-fontify-region beginning end verbose)
75 (loop for i from beginning to end do
76 (let ((face (get-text-property i 'font-lock-face)))
77 (when face
78 (put-text-property i (1+ i) 'face face)))))))
79
3d3edb9 @jscheid Rename kite-repl to kite-scratch
authored Sep 23, 2012
80 (run-mode-hooks 'kite-scratch-mode-hook))
d2e9b2c Move REPL stuff into kite-repl.el
Julian Scheid authored Jul 6, 2012
81
82 (defun kite-eval-defun ()
83 (save-excursion
84 (let (begin end pstate defun-info temp-name defun-body)
85 (js-end-of-defun)
86 (setq end (point))
87 (js--ensure-cache)
88 (js-beginning-of-defun)
89 (re-search-forward "\\_<function\\_>")
90 (setq begin (match-beginning 0))
91 (setq pstate (js--forward-pstate))
92
93 (when (or (null pstate)
94 (> (point) end))
95 (error "Could not locate function definition"))
96
97 (setq defun-info (js--guess-eval-defun-info pstate))
cb36ffa @jscheid Remove bogus debug output
authored Sep 23, 2012
98 (setq defun-body (buffer-substring-no-properties begin end)))))
d2e9b2c Move REPL stuff into kite-repl.el
Julian Scheid authored Jul 6, 2012
99
3d3edb9 @jscheid Rename kite-repl to kite-scratch
authored Sep 23, 2012
100 (defun kite-scratch-eval ()
d2e9b2c Move REPL stuff into kite-repl.el
Julian Scheid authored Jul 6, 2012
101 (interactive)
102 (save-excursion
54536cb @jscheid Rejiggle everything for new session handling and global hotkeys; port…
authored Aug 25, 2012
103 (lexical-let* ((begin
d2e9b2c Move REPL stuff into kite-repl.el
Julian Scheid authored Jul 6, 2012
104 (progn
105 (if (re-search-backward "^///" nil t)
106 (progn
b85d03d @jscheid Use forward-line instead of next-line and previous-line
authored Aug 25, 2012
107 (forward-line)
d2e9b2c Move REPL stuff into kite-repl.el
Julian Scheid authored Jul 6, 2012
108 (beginning-of-line))
109 (goto-char (point-min)))
110 (point)))
111 (end
112 (progn
113 (if (re-search-forward "^///" nil t)
114 (beginning-of-line)
115 (goto-char (point-max)))
116 (point)))
117
118 (code (buffer-substring-no-properties begin end)))
119
c44c92e @jscheid Refactor kite-send to accept keyword arguments; consistent use of pli…
authored Sep 23, 2012
120 (kite-send "Runtime.evaluate"
121 :params
122 (list :expression code)
123 :success-function
32cfff7 @jscheid Invoke JSON-RPC success callback with result instead of response
authored Sep 23, 2012
124 (lambda (result)
125 (if (eq :json-false (plist-get result :wasThrown))
126 (save-excursion
127 (goto-char end)
0a56cbe @jscheid Fix kite-scratch mode
authored Sep 23, 2012
128 (insert
129 (concat "\n/// -> "
130 (kite--format-object (plist-get result :result))
131 "\n")))
132 (kite--get-formatted-stack-trace
133 (kite--get result :result :objectId)
134 (lambda (stack-trace)
135 (save-excursion
136 (goto-char end)
137 (insert (concat
138 "\n"
139 (mapconcat
140 (lambda (line)
141 (concat "/// " line))
142 (split-string stack-trace "\n")
143 "\n")
144 "\n")))))))))))
54536cb @jscheid Rejiggle everything for new session handling and global hotkeys; port…
authored Aug 25, 2012
145
3d3edb9 @jscheid Rename kite-repl to kite-scratch
authored Sep 23, 2012
146 (font-lock-add-keywords 'kite-scratch-mode '(("(\\([a-zA-Z]+:.*?:[0-9]+:[0-9]+\\))$" 1 `(face kite-link-face keymap ,kite-scratch-mode-link-map) t)))
54536cb @jscheid Rejiggle everything for new session handling and global hotkeys; port…
authored Aug 25, 2012
147
d2e9b2c Move REPL stuff into kite-repl.el
Julian Scheid authored Jul 6, 2012
148
3d3edb9 @jscheid Rename kite-repl to kite-scratch
authored Sep 23, 2012
149 (provide 'kite-scratch)
015dfbb @jscheid Add end-of-file markers
authored Aug 25, 2012
150
3d3edb9 @jscheid Rename kite-repl to kite-scratch
authored Sep 23, 2012
151 ;;; kite-scratch.el ends here
Something went wrong with that request. Please try again.