Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move lisp bindings and add in JS stuff.

  • Loading branch information...
commit eb9eeb5c1bf679452ce9ece540dc554651f376cf 1 parent 680a6d6
@technomancy authored
View
169 elpa-to-submit/moz.el
@@ -0,0 +1,169 @@
+;;; moz.el --- Lets current buffer interact with inferior mozilla.
+
+;; Copyright (C) 2006 by Massimiliano Mirra
+;;
+;; This program 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 2 of the License, or
+;; (at your option) any later version.
+;;
+;; This program 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 this program; if not, write to the Free Software
+;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+;;
+;; Author: Massimiliano Mirra, <bard [at] hyperstruct [dot] net>
+
+;;; Code:
+
+(require 'comint)
+
+;;;###autoload
+(define-minor-mode moz-minor-mode
+ "Toggle Mozilla mode.
+With no argument, this command toggles the mode.
+Non-null prefix argument turns on the mode.
+Null prefix argument turns off the mode.
+
+When Mozilla mode is enabled, some commands become available to
+send current code area (as understood by c-mark-function) or
+region or buffer to an inferior mozilla process (which will be
+started as needed)."
+ nil
+ " Moz"
+ '(("\C-c\C-s" . run-mozilla)
+ ("\C-\M-x" . moz-send-defun)
+ ("\C-c\C-c" . moz-send-defun-and-go)
+ ("\C-c\C-r" . moz-send-region)
+ ("\C-c\C-l" . moz-save-buffer-and-send)))
+
+(defalias 'run-mozilla 'inferior-moz-switch-to-mozilla)
+
+(defvar moz-repl-name "repl"
+ "The current name of the repl.")
+
+(defvar moz-input-separator "\n--end-remote-input\n")
+
+(defvar moz-repl-host "localhost")
+
+(defvar moz-repl-port 4242)
+
+(defun moz-temporary-file ()
+ (if (and moz-temporary-file
+ (file-readable-p moz-temporary-file))
+ moz-temporary-file
+ (setq moz-temporary-file (make-temp-file "emacs-mozrepl"))))
+
+(defun moz-send-region (start end)
+ (interactive "r")
+ (comint-send-string (inferior-moz-process)
+ (concat moz-repl-name ".pushenv('printPrompt', 'inputMode'); "
+ moz-repl-name ".setenv('printPrompt', false); "
+ moz-repl-name ".setenv('inputMode', 'multiline'); "
+ "undefined; \n"))
+ ;; Give the previous line a chance to be evaluated on its own. If
+ ;; it gets concatenated to the following ones, we are doomed.
+ (sleep-for 0 1)
+ (comint-send-region (inferior-moz-process)
+ start end)
+ (comint-send-string (inferior-moz-process)
+ "\n--end-remote-input\n")
+ (comint-send-string (inferior-moz-process)
+ (concat moz-repl-name ".popenv('inputMode', 'printPrompt'); "
+ "undefined; \n"))
+ (comint-send-string (inferior-moz-process)
+ "\n--end-remote-input\n")
+ (display-buffer (process-buffer (inferior-moz-process))))
+
+(defun moz-send-defun ()
+ (interactive)
+ (save-excursion
+ (c-mark-function)
+ (moz-send-region (point) (mark))))
+
+(defun moz-send-defun-and-go ()
+ (interactive)
+ (moz-send-defun)
+ (inferior-moz-switch-to-mozilla))
+
+(defun moz-save-buffer-and-send ()
+ (interactive)
+ (save-buffer)
+ (comint-send-string (inferior-moz-process)
+ (concat moz-repl-name ".pushenv('printPrompt', 'inputMode'); "
+ moz-repl-name ".setenv('inputMode', 'line'); "
+ moz-repl-name ".setenv('printPrompt', false); undefined; "))
+ (comint-send-string (inferior-moz-process)
+ (concat moz-repl-name ".load('file://localhost/" (buffer-file-name) "');\n"
+ moz-repl-name ".popenv('inputMode', 'printPrompt'); undefined;\n"))
+ (display-buffer (process-buffer (inferior-moz-process))))
+
+;;; Inferior Mode
+
+(defvar inferior-moz-buffer nil
+ "The buffer in which the inferior process is running.")
+
+(define-derived-mode inferior-moz-mode comint-mode "Inf-Mozilla"
+ "Major mode for interacting with a Mozilla browser."
+ (setq comint-input-sender 'inferior-moz-input-sender)
+ (define-key inferior-moz-mode-map "\C-cc" (lambda () (interactive) (insert moz-repl-name ".")))
+ (add-hook 'comint-output-filter-functions 'inferior-moz-track-repl-name nil t))
+
+(defun inferior-moz-track-repl-name (comint-output)
+ (when (string-match "\\(\\w+\\)> $" comint-output)
+ (setq moz-repl-name (match-string 1 comint-output))))
+
+(defun inferior-moz-self-insert-or-repl-name ()
+ (interactive)
+ (if (looking-back "\\(\\w+\\)> $")
+ (insert moz-repl-name ".")
+ (insert last-command-char)))
+
+(defun inferior-moz-input-sender (proc string)
+ "Custom function to send input with comint-send-input.
+Instead of sending input and newline separately like in
+comint-simple-send, here we *first* concatenate input and
+newline, then send it all together. This prevents newline to be
+interpreted on its own."
+ (comint-send-string proc (concat string "\n")))
+
+(defun inferior-moz-switch-to-mozilla (arg)
+ "Show the inferior mozilla buffer. Start the process if needed."
+ (interactive "P")
+ (when arg
+ (setq moz-repl-host (read-string "Host: " "localhost"))
+ (setq moz-repl-port (read-number "Port: " 4242)))
+ (pop-to-buffer (process-buffer (inferior-moz-process)))
+ (goto-char (process-mark (inferior-moz-process))))
+
+(defun inferior-moz-process ()
+ "Return inferior mozilla process. Start it if necessary."
+ (or (if (buffer-live-p inferior-moz-buffer)
+ (get-buffer-process inferior-moz-buffer))
+ (progn
+ (inferior-moz-start-process)
+ (inferior-moz-process))))
+
+(defun inferior-moz-start-process ()
+ "Start an inferior mozilla process.
+It runs the hook `inferior-moz-hook' after starting the process
+and setting up the inferior-mozilla buffer."
+ (interactive)
+ (setq inferior-moz-buffer
+ (apply 'make-comint "Moz" (cons moz-repl-host moz-repl-port) nil nil))
+ (sleep-for 0 100)
+ (with-current-buffer inferior-moz-buffer
+ (inferior-moz-mode)
+ (run-hooks 'inferior-moz-hook)))
+
+;;;###autoload
+(eval-after-load 'js2-mode
+ '(add-hook 'js2-mode-hook 'moz-minor-mode))
+
+(provide 'moz)
+
+;;; moz.el ends here
View
3  init.el
@@ -35,13 +35,14 @@
;; Load up starter kit customizations:
-(require 'starter-kit-lisp)
(require 'starter-kit-defuns)
(require 'starter-kit-bindings)
(require 'starter-kit-misc)
(require 'starter-kit-registers)
(require 'starter-kit-eshell)
+(require 'starter-kit-lisp)
(require 'starter-kit-ruby)
+(require 'starter-kit-js)
(regen-autoloads)
View
10 starter-kit-bindings.el
@@ -46,13 +46,6 @@
(global-set-key "\C-xO" (lambda () (interactive) (other-window -1))) ;; back one
(global-set-key "\C-x\C-o" (lambda () (interactive) (other-window 2))) ;; forward two
-;; Lisp
-(define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol)
-(define-key lisp-mode-shared-map (kbd "RET") 'reindent-then-newline-and-indent)
-(define-key lisp-mode-shared-map (kbd "C-\\") 'lisp-complete-symbol)
-(define-key lisp-mode-shared-map (kbd "C-c s") 'eval-and-replace)
-(define-key lisp-mode-shared-map (kbd "C-c v") 'eval-buffer)
-
;; Start eshell or switch to it if it's active.
(global-set-key (kbd "C-x m") 'eshell)
@@ -68,6 +61,9 @@
;; Help should search more than just commands
(global-set-key (kbd "C-h a") 'apropos)
+;; Should be able to eval-and-replace anywhere.
+(global-set-key (kbd "C-c e") 'eval-and-replace)
+
;; Applications
(global-set-key (kbd "C-c j") (lambda () (interactive) (switch-or-start 'jabber-connect "*-jabber-*")))
View
4 starter-kit-defuns.el
@@ -59,7 +59,9 @@
(auto-fill-mode) ;; in comments only
(if window-system (hl-line-mode t))
(pretty-lambdas)
- (if (functionp 'idle-highlight) (idle-highlight)))
+ ;; TODO: this breaks in js2-mode!
+ ;;(if (functionp 'idle-highlight) (idle-highlight))
+ )
(defun untabify-buffer ()
(interactive)
View
31 starter-kit-js.el
@@ -0,0 +1,31 @@
+;;; starter-kit-js.el --- Some helpful Javascript helpers
+;;
+;; Part of the Emacs Starter Kit
+
+(eval-after-load 'js2-mode
+ '(progn
+
+ ;; Cosmetics
+ (font-lock-add-keywords
+ 'js2-mode `(("\\(function *\\)("
+ (0 (progn (compose-region (match-beginning 1) (match-end 1)
+ ,(make-char 'greek-iso8859-7 107))
+ nil)))))
+
+ (font-lock-add-keywords
+ 'js2-mode
+ '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\):"
+ 1 font-lock-warning-face t)))
+
+ (defun js-lambda () (interactive) (insert "function () {\n};")
+ (backward-char 6))
+
+ (define-key js2-mode-map (kbd "C-c l") 'js-lambda)
+ (define-key js2-mode-map "\C-\M-h" 'backward-kill-word)
+
+ (add-hook 'js2-mode-hook 'coding-hook)
+ (setq js2-bounce-indent-flag nil
+ js2-indent-on-enter-key t)))
+
+(provide 'starter-kit-js)
+;;; starter-kit-js.el ends here
View
4 starter-kit-lisp.el
@@ -27,6 +27,10 @@
'(("(\\|)" . 'paren-face)))
(define-key lisp-mode-shared-map (kbd "C-c l") "lambda")
+(define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol)
+(define-key lisp-mode-shared-map (kbd "RET") 'reindent-then-newline-and-indent)
+(define-key lisp-mode-shared-map (kbd "C-\\") 'lisp-complete-symbol)
+(define-key lisp-mode-shared-map (kbd "C-c v") 'eval-buffer)
(defface paren-face
'((((class color) (background dark))
Please sign in to comment.
Something went wrong with that request. Please try again.