Skip to content

Commit

Permalink
Merge pull request joxa#64 from s1n4/joxa-mode
Browse files Browse the repository at this point in the history
Improve emacs joxa-mode
  • Loading branch information
ericbmerritt committed Feb 12, 2014
2 parents 711a8da + 90fcdb4 commit d535853
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 39 deletions.
8 changes: 8 additions & 0 deletions 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)
```
129 changes: 129 additions & 0 deletions 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)
39 changes: 0 additions & 39 deletions emacs/joxa.el

This file was deleted.

0 comments on commit d535853

Please sign in to comment.