[Update mozrepl clinton@unknownlamer.org**20081216084934] { hunk ./init.d/moz.el 1 -;;; 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, - -;;; Code: - -(require 'comint) - -(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") - -(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." - :syntax-table js-mode-syntax-table - (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 () - "Show the inferior mozilla buffer. Start the process if needed." - (interactive) - (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" '("localhost" . 4242) nil nil)) - (sleep-for 0 100) - (with-current-buffer inferior-moz-buffer - (inferior-moz-mode) - (run-hooks 'inferior-moz-hook))) - -(provide 'moz) - -;;; moz.el ends here + rmfile ./init.d/moz.el hunk ./site-lisp/javascript.el 7 -;; Version: 2.0 Beta 4 +;; Version: 2.0 Beta 8 +;; Date: 2006-12-26 hunk ./site-lisp/javascript.el 63 -(defcustom javascript-indent-level 3 - "Number of spaces for each indentation step.") +(defgroup javascript nil + "Customization variables for `javascript-mode'." + :tag "JavaScript" + :group 'languages) + +(defcustom javascript-indent-level 4 + "Number of spaces for each indentation step." + :type 'integer + :group 'javascript) hunk ./site-lisp/javascript.el 75 -current line is indented when certain punctuations are inserted.") +current line is indented when certain punctuations are inserted." + :type 'boolean + :group 'javascript) hunk ./site-lisp/javascript.el 165 + (when (and (> (point) (point-min)) + (save-excursion (backward-char) (looking-at "/[/*]"))) + (forward-char)) hunk ./site-lisp/javascript.el 203 +(defun js-continued-var-decl-list-p () + "Return non-nil if point is inside a continued variable declaration +list." + (interactive) + (let ((start (save-excursion (js-re-search-backward "\\" nil t)))) + (and start + (save-excursion (re-search-backward "\n" start t)) + (not (save-excursion + (js-re-search-backward + ";\\|[^, \t][ \t]*\\(/[/*]\\|$\\)" start t)))))) + + hunk ./site-lisp/javascript.el 217 +(defun js-inside-param-list-p () + "Return non-nil if point is inside a function parameter list." + (condition-case err + (save-excursion + (up-list -1) + (and (looking-at "(") + (progn (backward-word 1) + (or (looking-at "function") + (progn (backward-word 1) (looking-at "function")))))) + (error nil))) + + hunk ./site-lisp/javascript.el 247 - "volatile" "while" "with") 'words) + "volatile" "while" "with" + "let") 'words) hunk ./site-lisp/javascript.el 266 - (list "[[:punct:]][[:blank:]]*\\(/.*?/\\w*\\)" 1 font-lock-string-face)) + (list "[=(][ \t]*\\(/.*?[^\\]/\\w*\\)" 1 font-lock-string-face)) hunk ./site-lisp/javascript.el 276 + +;; Limitations with variable declarations: There seems to be no +;; sensible way to highlight variables occuring after an initialized +;; variable in a variable list. For instance, in +;; +;; var x, y = f(a, b), z +;; +;; z will not be highlighted. + hunk ./site-lisp/javascript.el 286 - (append js-font-lock-keywords-2 - (list - (list - (concat "\\<\\(const\\|var\\)\\>\\|" js-basic-type-re "\\|" - js-function-heading-1-re "\\|" js-function-heading-2-re) - (list "\\(\\w+\\)[ \t]*\\(,\\|=[ \t]*\\(\".*?\"\\|'.*?'\\|{.*?}\\|.*?,\\)\\|.*\\)" - nil - nil - '(1 font-lock-variable-name-face))))) + (append + js-font-lock-keywords-2 + (list + + ;; variable declarations + (list + (concat "\\<\\(const\\|var\\)\\>\\|" js-basic-type-re) + (list "\\(\\w+\\)[ \t]*\\([=;].*\\|,\\|/[/*]\\|$\\)" + nil + nil + '(1 font-lock-variable-name-face))) + + ;; continued variable declaration list + (list + (concat "^[ \t]*\\w+[ \t]*\\([,;=]\\|/[/*]\\|$\\)") + (list "\\(\\w+\\)[ \t]*\\([=;].*\\|,\\|/[/*]\\|$\\)" + '(if (save-excursion (backward-char) (js-continued-var-decl-list-p)) + (backward-word 1) + (end-of-line)) + '(end-of-line) + '(1 font-lock-variable-name-face))) + + ;; formal parameters + (list + (concat "\\\\([ \t]+\\w+\\)?[ \t]*([ \t]*\\w") + (list "\\(\\w+\\)\\([ \t]*).*\\)?" + '(backward-char) + '(end-of-line) + '(1 font-lock-variable-name-face))) + + ;; continued formal parameter list + (list + (concat "^[ \t]*\\w+[ \t]*[,)]") + (list "\\w+" + '(if (save-excursion (backward-char) (js-inside-param-list-p)) + (backward-word 1) + (end-of-line)) + '(end-of-line) + '(0 font-lock-variable-name-face))))) hunk ./site-lisp/javascript.el 337 - '("catch" "do" "else" "finally" "for" "if" "try" "while" "with") + '("catch" "do" "else" "finally" "for" "if" "try" "while" "with" "let") hunk ./site-lisp/javascript.el 343 - (concat "[-+*/%<>=&^|?:]\\([^-+*/]\\|$\\)\\|" + (concat "[-+*/%<>=&^|?:.]\\([^-+*/]\\|$\\)\\|" hunk ./site-lisp/javascript.el 369 - (and (js-looking-at-operator-p) + (and (> (point) (point-min)) + (save-excursion (backward-char) (not (looking-at "[/*]/"))) + (js-looking-at-operator-p) hunk ./site-lisp/javascript.el 408 - (and (> (count-lines (point-min) (point)) 1) - (not (looking-at "{")) - (js-re-search-backward "[[:graph:]]" nil t) - (not (looking-at "[{([]")) + (and (not (looking-at "[{]")) hunk ./site-lisp/javascript.el 410 - (forward-char) - (backward-sexp) - (when (looking-at "(") (backward-word 1)) - (and (save-excursion - (skip-chars-backward " \t}" (point-at-bol)) - (bolp)) - (looking-at js-possibly-braceless-keyword-re) - (not (js-end-of-do-while-loop-p)))))) + (js-re-search-backward "[[:graph:]]" nil t) + (forward-char) + (when (= (char-before) ?\)) (backward-list)) + (skip-syntax-backward " ") + (skip-syntax-backward "w") + (looking-at js-possibly-braceless-keyword-re)) + (not (js-end-of-do-while-loop-p)))) hunk ./site-lisp/javascript.el 430 + ((js-continued-var-decl-list-p) + (js-re-search-backward "\\" nil t) + (+ (current-indentation) javascript-indent-level)) hunk ./site-lisp/javascript.el 436 - (let ((p (parse-partial-sexp (point-at-bol) (point)))) - (when (save-excursion (skip-chars-backward " \t)") - (looking-at ")")) - (backward-list)) - (if (nth 1 p) - (progn (goto-char (1+ (nth 1 p))) - (skip-chars-forward " \t")) - (back-to-indentation)) + (progn + (skip-syntax-backward " ") + (when (= (char-before) ?\)) (backward-list)) + (back-to-indentation) hunk ./site-lisp/javascript.el 682 + (set (make-local-variable 'parse-sexp-ignore-comments) t) + hunk ./site-lisp/javascript.el 690 + ;; Make c-mark-function work + (setq c-nonsymbol-token-regexp "!=\\|%=\\|&[&=]\\|\\*[/=]\\|\\+[+=]\\|-[=-]\\|/[*/=]\\|<\\(?:<=\\|[<=]\\)\\|==\\|>\\(?:>\\(?:>=\\|[=>]\\)\\|[=>]\\)\\|\\^=\\||[=|]\\|[]!%&(-,./:-?[{-~^-]" + c-stmt-delim-chars "^;{}?:" + c-syntactic-ws-end "[ \n \f/]" + c-syntactic-eol "\\(\\s \\|/\\*\\([^*\n ]\\|\\*[^/\n ]\\)*\\*/\\)*\\(\\(/\\*\\([^*\n ]\\|\\*[^/\n ]\\)*\\|\\\\\\)?$\\|//\\)") + hunk ./site-lisp/moz.el 50 +(defvar moz-repl-host "localhost") + +(defvar moz-repl-port 4242) + hunk ./site-lisp/moz.el 111 - :syntax-table js-mode-syntax-table hunk ./site-lisp/moz.el 133 -(defun inferior-moz-switch-to-mozilla () +(defun inferior-moz-switch-to-mozilla (arg) hunk ./site-lisp/moz.el 135 - (interactive) + (interactive "P") + (when arg + (setq moz-repl-host (read-string "Host: " "localhost")) + (setq moz-repl-port (read-number "Port: " 4242))) hunk ./site-lisp/moz.el 156 - (apply 'make-comint "Moz" '("localhost" . 4242) nil nil)) + (apply 'make-comint "Moz" (cons moz-repl-host moz-repl-port) nil nil)) }