emacs stuff

This commit is contained in:
Sami Samhuri 2011-04-14 10:33:36 -07:00
parent 80a70e3bcc
commit 960852d084
2 changed files with 317 additions and 55 deletions

92
emacs
View file

@ -205,16 +205,17 @@
;; js-mode (espresso)
;; Espresso mode has sane indenting so we use that.
(setq js-indent-level 4)
(setq js-indent-level 2)
;; Customize JS2
(setq js2-basic-offset 4)
(setq js2-basic-offset 2)
(setq js2-cleanup-whitespace t)
(autoload 'js2-mode "js2-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(add-to-list 'auto-mode-alist '("Jakefile$" . js2-mode))
(add-hook 'js2-mode-hook (lambda () (slime-js-minor-mode 1)))
(global-set-key [f5] 'slime-js-reload)
;; Custom indentation function since JS2 indenting is terrible.
;; Uses js-mode's (espresso-mode) indentation semantics.
@ -277,6 +278,9 @@
;; coffee script
(require 'coffee-mode)
;; mustache
(require 'mustache-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; objective j
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -299,15 +303,18 @@
(add-hook 'objc-mode-hook 'my-objc-mode-hook)
;; css
(setq css-mode-hook (lambda () (setq indent-tabs-mode nil)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; mojo (webos)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'mojo)
;(require 'mojo)
;; enable Mojo for CSS, HTML, JS, and JSON files within a Mojo project
;; root. Did I forget anything?
(mojo-setup-mode-hooks 'css-mode-hook 'js2-mode-hook 'espresso-mode-hook 'html-mode-hook)
;(mojo-setup-mode-hooks 'css-mode-hook 'js2-mode-hook 'espresso-mode-hook 'html-mode-hook)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -374,7 +381,7 @@
(when (file-exists-p "~/.slime")
(add-to-list 'load-path "~/.slime")
(require 'slime)
(slime-setup)
(slime-setup '(slime-repl slime-js))
(add-hook 'lisp-mode-hook (lambda () (slime-mode t)))
(add-hook 'scheme-mode-hook (lambda () (slime-mode t)))
(add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t)))
@ -426,61 +433,38 @@
;; Select the enclosed parens/brackets/braces
(global-set-key "\M-B" 'select-enclosing-pair)
;; nice OS X keyboard behaviors that save my pinky too
(defun save-the-pinky-buffer () (interactive) (message "Save your pinky! Use s-b (Opt-b) instead."))
(defun save-the-pinky-open () (interactive) (message "Save your pinky! Use M-o (Cmd-o) instead."))
(defun save-the-pinky-save () (interactive) (message "Save your pinky! Use M-s (Cmd-s) instead."))
(defun save-the-pinky-undo () (interactive) (message "Save your pinky! Use M-z (Cmd-z) instead."))
(defun save-the-pinky-window () (interactive) (message "Save your pinky! Use M-` (Cmd-`) instead."))
(global-set-key "\C-_" 'save-the-pinky-undo)
(global-set-key "\C-x\C-f" 'save-the-pinky-open)
(global-set-key "\C-xo" 'save-the-pinky-window)
(global-set-key "\C-x\C-s" 'save-the-pinky-save)
(global-set-key "\C-x\C-b" 'save-the-pinky-buffer)
(when macosx-p
;; nice OS X keyboard behaviors that save my pinky too
(defun save-the-pinky-buffer () (interactive) (message "Save your pinky! Use s-b (Opt-b) instead."))
(defun save-the-pinky-open () (interactive) (message "Save your pinky! Use M-o (Cmd-o) instead."))
(defun save-the-pinky-save () (interactive) (message "Save your pinky! Use M-s (Cmd-s) instead."))
(defun save-the-pinky-undo () (interactive) (message "Save your pinky! Use M-z (Cmd-z) instead."))
(defun save-the-pinky-window () (interactive) (message "Save your pinky! Use M-` (Cmd-`) instead."))
(global-set-key "\C-_" 'save-the-pinky-undo)
(global-set-key "\C-x\C-f" 'save-the-pinky-open)
(global-set-key "\C-xo" 'save-the-pinky-window)
(global-set-key "\C-x\C-s" 'save-the-pinky-save)
(global-set-key "\C-x\C-b" 'save-the-pinky-buffer)
(global-set-key "\M-n" 'new-frame)
(global-set-key "\M-o" 'find-file)
(global-set-key "\M-s" 'save-buffer)
(global-set-key "\M-z" 'undo)
(global-set-key [(meta down)] 'end-of-buffer)
(global-set-key [(meta up)] 'beginning-of-buffer)
(global-set-key [(meta right)] 'end-of-line)
(global-set-key [(meta left)] 'beginning-of-line)
(global-set-key "\M-n" 'new-frame)
(global-set-key "\M-o" 'find-file)
(global-set-key "\M-s" 'save-buffer)
(global-set-key "\M-z" 'undo)
(global-set-key [(meta down)] 'end-of-buffer)
(global-set-key [(meta up)] 'beginning-of-buffer)
(global-set-key [(meta right)] 'end-of-line)
(global-set-key [(meta left)] 'beginning-of-line)
;; can't seem to un-hijack cmd-`, so make it do something useful
(global-set-key "\M-`" 'other-window-in-any-frame)
;; can't seem to un-hijack cmd-`, so make it do something useful
(global-set-key "\M-`" 'other-window-in-any-frame)
;; find files like textmate
(global-set-key "\M-F" 'textmate-find-regex-in-project)
;; run the ssa server
(global-set-key [(super s)] 'ssa-run-server)
;; find files like textmate
(global-set-key "\M-F" 'textmate-find-regex-in-project)
)
;; quickly jump to a project
(global-set-key [(super o)] 'open-project)
(defun ssa-start-server (buffer)
(process-send-string buffer "cd ~/Projects/ssa/SelfServeApps/Backend")
(comint-send-input)
(process-send-string buffer "node listener.js")
(comint-send-input))
(defun ssa-run-server (&optional args)
"Run the ssa backend in an inferior shell."
(interactive "P")
(let* ((arg (car args))
(running (get-buffer "*server*"))
(restart (and (numberp arg) (= arg 4))))
(when (not running)
(shell "*server*")
(sleep-for 0.5)
(ssa-start-server "*server*"))
(when running
(switch-to-buffer "*server*")
(when restart
(comint-interrupt-subjob)
(ssa-start-server "*server*")))))
(defvar *open-project-registry* (list))
(defun register-project (name root-file)

278
emacs.d/mustache-mode.el Normal file
View file

@ -0,0 +1,278 @@
;;; tpl-mode.el -- a major mode for editing Google CTemplate files.
;;; By Tony Gentilcore, July 2006
;;;
;;; Very minor, backwards compatible changes added for Mustache compatibility
;;; by Chris Wanstrath, October 2009
;;;
;;; TO USE:
;;; 1) Copy this file somewhere you in emacs load-path. To see what
;;; your load-path is, run inside emacs: C-h v load-path<RET>
;;; 2) Add the following two lines to your .emacs file:
;;; (setq auto-mode-alist (cons '("\\.tpl$" . tpl-mode) auto-mode-alist))
;;; (autoload 'tpl-mode "tpl-mode" "Major mode for editing CTemplate files." t)
;;; 3) Optionally (but recommended), add this third line as well:
;;; (add-hook 'tpl-mode-hook '(lambda () (font-lock-mode 1)))
;;; ---
;;;
;;; While the Mustache language can be used for any types of text,
;;; this mode is intended for using Mustache to write HTML.
;;;
;;; The indentation still has minor bugs due to the fact that
;;; templates do not require valid HTML.
;;;
;;; It would be nice to be able to highlight attributes of HTML tags,
;;; however this is difficult due to the presence of CTemplate symbols
;;; embedded within attributes.
(eval-when-compile
(require 'font-lock))
(defgroup tpl-mode nil
"Major mode for editing Google CTemplate and Mustache files"
:group 'languages)
(defvar tpl-mode-version "1.1"
"Version of `tpl-mode.el'.")
(defvar tpl-mode-abbrev-table nil
"Abbrev table for use in tpl-mode buffers.")
(define-abbrev-table 'tpl-mode-abbrev-table ())
(defcustom tpl-mode-hook nil
"*Hook that runs upon entering tpl-mode."
:type 'hook)
(defvar tpl-mode-map nil
"Keymap for tpl-mode major mode")
(if tpl-mode-map
nil
(setq tpl-mode-map (make-sparse-keymap)))
(define-key tpl-mode-map "\t" 'tpl-indent-command)
(define-key tpl-mode-map "\C-m" 'reindent-then-newline-and-indent)
(define-key tpl-mode-map "\C-ct" 'tpl-insert-tag)
(define-key tpl-mode-map "\C-cv" 'tpl-insert-variable)
(define-key tpl-mode-map "\C-cs" 'tpl-insert-section)
(defvar tpl-mode-syntax-table nil
"Syntax table in use in tpl-mode buffers.")
;; Syntax table.
(if tpl-mode-syntax-table
nil
(setq tpl-mode-syntax-table (make-syntax-table text-mode-syntax-table))
(modify-syntax-entry ?< "(> " tpl-mode-syntax-table)
(modify-syntax-entry ?> ")< " tpl-mode-syntax-table)
(modify-syntax-entry ?\" ". " tpl-mode-syntax-table)
(modify-syntax-entry ?\\ ". " tpl-mode-syntax-table)
(modify-syntax-entry ?' "w " tpl-mode-syntax-table))
(defvar tpl-basic-offset 2
"The basic indentation offset.")
;; Constant regular expressions to identify template elements.
(defconst tpl-mode-tpl-token "[a-zA-Z_][a-zA-Z0-9_:=\?!-]*?")
(defconst tpl-mode-section (concat "\\({{[#^/]\s*"
tpl-mode-tpl-token
"\s*}}\\)"))
(defconst tpl-mode-open-section (concat "\\({{#\s*"
tpl-mode-tpl-token
"\s*}}\\)"))
(defconst tpl-mode-close-section (concat "{{/\\(\s*"
tpl-mode-tpl-token
"\s*\\)}}"))
;; TODO(tonyg) Figure out a way to support multiline comments.
(defconst tpl-mode-comment "\\({{!.*?}}\\)")
(defconst tpl-mode-include (concat "\\({{[><]\s*"
tpl-mode-tpl-token
"\s*}}\\)"))
(defconst tpl-mode-variable (concat "\\({{\s*"
tpl-mode-tpl-token
"\s*}}\\)"))
(defconst tpl-mode-builtins
(concat
"\\({{\\<\s*"
(regexp-opt
'("BI_NEWLINE" "BI_SPACE")
t)
"\s*\\>}}\\)"))
(defconst tpl-mode-close-section-at-start (concat "^[ \t]*?"
tpl-mode-close-section))
;; Constant regular expressions to identify html tags.
;; Taken from HTML 4.01 / XHTML 1.0 Reference found at:
;; http://www.w3schools.com/tags/default.asp.
(defconst tpl-mode-html-constant "\\(&#?[a-z0-9]\\{2,5\\};\\)")
(defconst tpl-mode-pair-tag
(concat
"\\<"
(regexp-opt
'("a" "abbr" "acronym" "address" "applet" "area" "b" "bdo"
"big" "blockquote" "body" "button" "caption" "center" "cite"
"code" "col" "colgroup" "dd" "del" "dfn" "dif" "div" "dl"
"dt" "em" "fieldset" "font" "form" "frame" "frameset" "h1"
"h2" "h3" "h4" "h5" "h6" "head" "html" "i" "iframe" "ins"
"kbd" "label" "legend" "li" "link" "map" "menu" "noframes"
"noscript" "object" "ol" "optgroup" "option" "p" "pre" "q"
"s" "samp" "script" "select" "small" "span" "strike"
"strong" "style" "sub" "sup" "table" "tbody" "td" "textarea"
"tfoot" "th" "thead" "title" "tr" "tt" "u" "ul" "var")
t)
"\\>"))
(defconst tpl-mode-standalone-tag
(concat
"\\<"
(regexp-opt
'("base" "br" "hr" "img" "input" "meta" "param")
t)
"\\>"))
(defconst tpl-mode-open-tag (concat "<\\("
tpl-mode-pair-tag
"\\)"))
(defconst tpl-mode-close-tag (concat "</\\("
tpl-mode-pair-tag
"\\)>"))
(defconst tpl-mode-close-tag-at-start (concat "^[ \t]*?"
tpl-mode-close-tag))
(defconst tpl-mode-blank-line "^[ \t]*?$")
(defconst tpl-mode-dangling-open (concat "\\("
tpl-mode-open-section
"\\)\\|\\("
tpl-mode-open-tag
"\\)[^/]*$"))
(defun tpl-indent-command ()
"Command for indenting text. Just calls tpl-indent."
(interactive)
(tpl-indent))
(defun tpl-insert-tag (tag)
"Inserts an HTML tag."
(interactive "sTag: ")
(tpl-indent)
(insert (concat "<" tag ">"))
(insert "\n\n")
(insert (concat "</" tag ">"))
(tpl-indent)
(forward-line -1)
(tpl-indent))
(defun tpl-insert-variable (variable)
"Inserts a tpl variable."
(interactive "sVariable: ")
(insert (concat "{{" variable "}}")))
(defun tpl-insert-section (section)
"Inserts a tpl section."
(interactive "sSection: ")
(tpl-indent)
(insert (concat "{{#" section "}}\n"))
(insert "\n")
(insert (concat "{{/" section "}}"))
(tpl-indent)
(forward-line -1)
(tpl-indent))
;; Function to control indenting.
(defun tpl-indent ()
"Indent current line"
;; Set the point to beginning of line.
(beginning-of-line)
;; If we are at the beginning of the file, indent to 0.
(if (bobp)
(indent-line-to 0)
(let ((tag-stack 1) (close-tag "") (cur-indent 0) (old-pnt (point-marker))
(close-at-start) (open-token) (dangling-open))
(progn
;; Determine if this is a template line or an html line.
(if (looking-at "^[ \t]*?{{")
(setq close-at-start tpl-mode-close-section-at-start
open-token "{{#")
(setq close-at-start tpl-mode-close-tag-at-start
open-token "<"))
;; If there is a closing tag at the start of the line, search back
;; for its opener and indent to that level.
(if (looking-at close-at-start)
(progn
(save-excursion
(setq close-tag (match-string 1))
;; Keep searching for a match for the close tag until
;; the tag-stack is 0.
(while (and (not (bobp))
(> tag-stack 0)
(re-search-backward (concat open-token
"\\(/?\\)"
close-tag) nil t))
(if (string-equal (match-string 1) "/")
;; We found another close tag, so increment tag-stack.
(setq tag-stack (+ tag-stack 1))
;; We found an open tag, so decrement tag-stack.
(setq tag-stack (- tag-stack 1)))
(setq cur-indent (current-indentation))))
(if (> tag-stack 0)
(save-excursion
(forward-line -1)
(setq cur-indent (current-indentation)))))
;; This was not a closing tag, so we check if the previous line
;; was an opening tag.
(save-excursion
;; Keep moving back until we find a line that is not blank
(while (progn
(forward-line -1)
(and (not (bobp)) (looking-at tpl-mode-blank-line))))
(setq cur-indent (current-indentation))
(if (re-search-forward tpl-mode-dangling-open old-pnt t)
(setq cur-indent (+ cur-indent tpl-basic-offset)))))
;; Finally, we execute the actual indentation.
(if (> cur-indent 0)
(indent-line-to cur-indent)
(indent-line-to 0))))))
;; controls highlighting
(defconst tpl-mode-font-lock-keywords
(list
(list tpl-mode-section
'(1 font-lock-keyword-face))
(list tpl-mode-comment
'(1 font-lock-comment-face))
(list tpl-mode-include
'(1 font-lock-function-name-face))
(list tpl-mode-builtins
'(1 font-lock-variable-name-face))
(list tpl-mode-variable
'(1 font-lock-reference-face))
(list (concat "</?\\(" tpl-mode-pair-tag "\\)")
'(1 font-lock-function-name-face))
(list (concat "<\\(" tpl-mode-standalone-tag "\\)")
'(1 font-lock-function-name-face))
(list tpl-mode-html-constant
'(1 font-lock-variable-name-face))))
(put 'tpl-mode 'font-lock-defaults '(tpl-font-lock-keywords nil t))
(defun tpl-mode ()
"Major mode for editing Google CTemplate file."
(interactive)
(kill-all-local-variables)
(use-local-map tpl-mode-map)
(setq major-mode 'tpl-mode)
(setq mode-name "tpl-mode")
(setq local-abbrev-table tpl-mode-abbrev-table)
(setq indent-tabs-mode nil)
(set-syntax-table tpl-mode-syntax-table)
;; show trailing whitespace, but only when the user can fix it
(setq show-trailing-whitespace (not buffer-read-only))
(make-local-variable 'indent-line-function)
(setq indent-line-function 'tpl-indent)
(setq font-lock-defaults '(tpl-mode-font-lock-keywords))
(run-hooks 'tpl-mode-hook))
;; Automatically load tpl-mode for .mustache files.
(add-to-list 'auto-mode-alist '("\\.mustache$" . tpl-mode))
(add-hook 'tpl-mode-hook '(lambda () (font-lock-mode 1)))
(provide 'mustache-mode)