From 603d4ef734d86cc37d679dd6e0299abe40c3c579 Mon Sep 17 00:00:00 2001 From: Sina Samavati Date: Mon, 10 Feb 2014 02:01:17 +0330 Subject: [PATCH 1/2] Improve emacs joxa-mode rename joxa.el to joxa-mode.el improve syntax highlighting and indentation --- emacs/joxa-mode.el | 129 +++++++++++++++++++++++++++++++++++++++++++++ emacs/joxa.el | 39 -------------- 2 files changed, 129 insertions(+), 39 deletions(-) create mode 100644 emacs/joxa-mode.el delete mode 100644 emacs/joxa.el diff --git a/emacs/joxa-mode.el b/emacs/joxa-mode.el new file mode 100644 index 0000000..89ebe08 --- /dev/null +++ b/emacs/joxa-mode.el @@ -0,0 +1,129 @@ +;; Joxa mode + +(defvar joxa-mode-hook nil) + +;; syntax table +(defvar joxa-mode-syntax-table + (let ((table (make-syntax-table))) + (modify-syntax-entry ?\[ "(]" table) + (modify-syntax-entry ?\] ")[" table) + (modify-syntax-entry ?\{ "(}" table) + (modify-syntax-entry ?\} "){" table) + (modify-syntax-entry ?` "' " table) + (modify-syntax-entry ?' "' " table) + table)) + +;; mode map +(defvar joxa-mode-map + (let ((map (make-sparse-keymap))) + (set-keymap-parent map lisp-mode-shared-map) map)) + +;; syntax highlighting +(defvar joxa-font-lock-keywords + (eval-when-compile + `( + ;; keywords + (,(concat "(" + (regexp-opt '("use" "fn" "do" "case" "when" + "try" "try*" "catch" "require" + "receive" "let" "let*") t) + "\\>") + (1 font-lock-keyword-face)) + + ;; namespace + (,(concat "(" (regexp-opt '("ns") t) "\\>" + ;; Any whitespace + "[ \r\n\t]*" + "\\(\\sw+\\)?") + (1 font-lock-keyword-face) + (2 font-lock-variable-name-face nil t)) + + ;; BIFs + (,(concat "(" + (regexp-opt '("$filename" "$namespace" + "$line-number" "$function-name" + "apply" "quote" "string" "list" + "tuple" "binary" "error") t) + "\\>") + (1 font-lock-builtin-face)) + + ;; functions + (,(concat "(" + (regexp-opt '("definline" "defn+" "defn") t) + "\\>" + ;; Any whitespace + "[ \r\n\t]*" + "\\(\\sw+\\)?") + + (1 font-lock-keyword-face) + (2 font-lock-function-name-face nil t)) + + ;; type/spec + (,(concat "(" + (regexp-opt '("deftype" "deftype+" "defspec") t) + "\\>" + ;; Any whitespace + "[ \r\n\t]*" + "\\(\\sw+\\)?") + (1 font-lock-keyword-face) + (2 font-lock-type-face nil t)) + + ;; macros + (,(concat "(" (regexp-opt '("defmacro" "defmacro+") t) "\\>" + ;; Any whitespace + "[ \r\n\t]*" + "\\(\\sw+\\)?") + (1 font-lock-keyword-face) + (2 font-lock-constant-face)) + + ;; variables + (,(concat "(" (regexp-opt '("define") t) "\\>" + ;; Any whitespace + "[ \r\n\t]*" + "\\(\\sw+\\)?") + (1 font-lock-keyword-face) + (2 font-lock-variable-name-face)) + + ;; atoms + ("\\:\\(\\sw\\|\\s_\\)+\\(\\>\\|\\_>\\)" 0 font-lock-constant-face) + + ))) + +(define-derived-mode joxa-mode lisp-mode "Joxa Editing Mode" "Major mode for editing Joxa files" + (interactive) + (setq major-mode 'joxa-mode) + (setq mode-name "Joxa") + (set-syntax-table joxa-mode-syntax-table) + (use-local-map joxa-mode-map) + (setq font-lock-defaults '(joxa-font-lock-keywords + nil nil (("+-*/.<>=!?$%_&~^:@" . "w")) nil + (font-lock-mark-block-function . mark-defun) + (font-lock-syntactic-face-function + . lisp-font-lock-syntactic-face-function))) + ;; enable show-paren-mode + (make-variable-buffer-local 'show-paren-mode) + (show-paren-mode t) + (run-hooks 'joxa-mode-hook)) + +(put 'ns 'lisp-indent-function 1) +(put 'definline 'lisp-indent-function 'defun) +(put 'defn 'lisp-indent-function 'defun) +(put 'defn+ 'lisp-indent-function 'defun) +(put 'fn 'lisp-indent-function 1) +(put 'defmacro 'lisp-indent-function 'defmacro) +(put 'defmacro+ 'lisp-indent-function 'defmacro) +(put 'define 'doc-string-elt 3) +(put 'deftype 'lisp-indent-function 'defun) +(put 'deftype+ 'lisp-indent-function 'defun) +(put 'defspec 'lisp-indent-function 'defun) +(put 'receive 'lisp-indent-function 0) +(put 'try* 'lisp-indent-function 0) +(put 'catch 'lisp-indent-function 1) +(put 'do 'lisp-indent-function 0) +(put 'use 'lisp-indent-function 0) +(put 'require 'lisp-indent-function 0) + +;;;###autoload +(add-to-list 'auto-mode-alist '("\\.jxa\\'" . joxa-mode)) + +(provide 'joxa-mode) diff --git a/emacs/joxa.el b/emacs/joxa.el deleted file mode 100644 index 8dd2d1b..0000000 --- a/emacs/joxa.el +++ /dev/null @@ -1,39 +0,0 @@ -;; This is an absolute, minimal, better-then-nothing mode for joxa. At -;; some point we will build something better. - -(define-derived-mode joxa-mode lisp-mode "Joxa Editing Mode" "Major mode for editing Joxa files" - - (font-lock-add-keywords 'joxa-mode - '(("module" . font-lock-keyword-face) - ("deftype" . font-lock-keyword-face) - ("defspec" . font-lock-keyword-face) - ("definline" . font-lock-keyword-face) - ("defmacro+" . font-lock-keyword-face) - ("defmacro" . font-lock-keyword-face) - ("defn+" . font-lock-keyword-face) - ("defn" . font-lock-keyword-face) - ("__try" . font-lock-keyword-face) - ("use" . font-lock-keyword-face) - ("ns" . font-lock-keyword-face) - ("fn" . font-lock-keyword-face))) - - (define-key joxa-mode-map "{" 'paredit-open-curly) - (define-key joxa-mode-map "}" 'paredit-close-curly) - - (modify-syntax-entry ?< "(>" ) - (modify-syntax-entry ?> ")<" ) - - (modify-syntax-entry ?[ "(]" ) - (modify-syntax-entry ?] ")[" ) - - (modify-syntax-entry ?\{ "(}") - (modify-syntax-entry ?\} "){")) - - -;; Uncomment this if you want parenface and paredit (which you should) -;; (add-hook 'joxa-mode-hook '(lambda () -;; (paredit-mode) -;; (require 'parenface) -;; (set-face-foreground 'paren-face "#073642"))) - - (add-to-list 'auto-mode-alist '("\\.jxa\\'" . joxa-mode)) \ No newline at end of file From 90fcdb49a4663ac42f214e010604613cd81dcb7a Mon Sep 17 00:00:00 2001 From: Sina Samavati Date: Mon, 10 Feb 2014 02:10:58 +0330 Subject: [PATCH 2/2] Add emacs joxa-mode installation instruction --- emacs/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 emacs/README.md diff --git a/emacs/README.md b/emacs/README.md new file mode 100644 index 0000000..55c921f --- /dev/null +++ b/emacs/README.md @@ -0,0 +1,8 @@ +## Installation + +Add the following to your .emacs + +```lisp +(add-to-list 'load-path "/path/to/joxa/emacs") +(require 'joxa-mode) +```