├── .gitignore ├── .gitmodules ├── .travis.yml ├── Makefile ├── README.md ├── config ├── align.el ├── appearance.el ├── auto-complete.el ├── basic-bindings.el ├── basic.el ├── clojure.el ├── cmd.el ├── coffee.el ├── colorize-compilation.el ├── colors.el ├── css.el ├── dash.el ├── debug.el ├── erc.el ├── eshell.el ├── expand-region.el ├── fiplr.el ├── flycheck.el ├── font.el ├── git.el ├── golang.el ├── helm.el ├── ido.el ├── idomenu.el ├── indent.el ├── jade-mode.el ├── js2-refactor.el ├── js2.el ├── json.el ├── linum.el ├── lisp.el ├── markdown.el ├── node.el ├── npm.el ├── optimize.el ├── paredit.el ├── powerline.el ├── shell.el ├── slim.el ├── smart-forward.el ├── smex.el ├── solarized.el ├── string.el ├── undo-tree.el ├── web.el ├── yasnippet.el ├── zencoding.el └── zsh.el ├── custom.example.el ├── init.el ├── libs ├── color-theme │ ├── color-theme-gruber-darker.el │ └── color-theme.el ├── dircolors │ └── dircolors.el ├── golang │ └── go-mode.el ├── js-comint │ └── js-comint.el ├── json │ └── json.el ├── let-alist │ └── let-alist.el ├── paredit │ └── paredit.el ├── rainbow │ ├── rainbow-delimiters.el │ └── rainbow-parens.el ├── rename-file.el ├── smooth-scrolling │ └── smooth-scrolling.el └── undo-tree │ └── undo-tree.el ├── profiles ├── clojure.el ├── coffee.el ├── default.el ├── golang.el └── js.el └── snippets ├── go-mode ├── &s ├── << ├── as ├── aserr ├── asf ├── asn ├── ast ├── c ├── c.JSON ├── cstring ├── e ├── err ├── errif ├── f ├── ferr ├── for ├── func ├── i ├── iferr ├── ifunc ├── imp ├── init ├── j ├── jf ├── json ├── m ├── main ├── map ├── merr ├── meth ├── n ├── p ├── pkg ├── range ├── sort ├── st ├── struct ├── test └── xml └── js2-mode ├── act.yasnippet ├── after.yasnippet ├── afterEach.yasnippet ├── assert.yasnippet ├── before.yasnippet ├── beforeEach.yasnippet ├── build.yasnippet ├── cb.yasnippet ├── com.yasnippet ├── deps.yasnippet ├── describe.yasnippet ├── devdeps.yasnippet ├── e.yasnippet ├── err-one-liner.yasnippet ├── err-throw.yasnippet ├── err.snippet ├── error.snippet ├── exp.yasnippet ├── expect-error.yasnippet ├── expect.yasnippet ├── exports-obj.yasnippet ├── exports.yasnippet ├── f.yasnippet ├── fn.yasnippet ├── for.yasnippet ├── id.yasnippet ├── if.yasnippet ├── invoc.yasnippet ├── it.yasnippet ├── log.yasnippet ├── m.yasnippet ├── method.yasnippet ├── mod-debug.yasnippet ├── mod-exp.yasnippet ├── mod.yasnippet ├── new-err.yasnippet ├── next.yasnippet ├── prop.yasnippet ├── proto.yasnippet ├── r.yasnippet ├── rq.yasnippet ├── rt.yasnippet ├── select-all.yasnippet ├── select.yasnippet ├── should.yasnippet ├── slice.yasnippet ├── super.yasnippet ├── switch.yasnippet ├── task.yasnippet ├── test.yasnippet ├── throw.yasnippet ├── try.yasnippet ├── v.snippet ├── var-rq.yasnippet ├── var.yasnippet ├── wh.yasnippet └── while.yasnippet /.gitignore: -------------------------------------------------------------------------------- 1 | tmp 2 | libs/js2-mode-compiled 3 | libs/magit 4 | custom.el 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libs/auto-complete"] 2 | path = libs/auto-complete 3 | url = https://github.com/azer/auto-complete.git 4 | [submodule "libs/coffee-mode"] 5 | path = libs/coffee-mode 6 | url = https://github.com/azer/coffee-mode.git 7 | [submodule "libs/dash"] 8 | path = libs/dash 9 | url = https://github.com/magnars/dash.el.git 10 | [submodule "libs/expand-region"] 11 | path = libs/expand-region 12 | url = https://github.com/magnars/expand-region.el.git 13 | [submodule "libs/jade-mode"] 14 | path = libs/jade-mode 15 | url = https://github.com/brianc/jade-mode.git 16 | [submodule "libs/js2-mode"] 17 | path = libs/js2-mode 18 | url = https://github.com/mooz/js2-mode.git 19 | [submodule "libs/js2-refactor"] 20 | path = libs/js2-refactor 21 | url = https://github.com/magnars/js2-refactor.el.git 22 | [submodule "libs/markdown-mode"] 23 | path = libs/markdown-mode 24 | url = git://jblevins.org/git/markdown-mode.git 25 | [submodule "libs/mark-multiple"] 26 | path = libs/mark-multiple 27 | url = https://github.com/magnars/mark-multiple.el.git 28 | [submodule "libs/multiple-cursors"] 29 | path = libs/multiple-cursors 30 | url = https://github.com/magnars/multiple-cursors.el.git 31 | [submodule "libs/powerline"] 32 | path = libs/powerline 33 | url = https://github.com/milkypostman/powerline.git 34 | [submodule "libs/smart-forward"] 35 | path = libs/smart-forward 36 | url = https://github.com/magnars/smart-forward.el.git 37 | [submodule "libs/smex"] 38 | path = libs/smex 39 | url = https://github.com/nonsequitur/smex.git 40 | [submodule "libs/zencoding"] 41 | path = libs/zencoding 42 | url = https://github.com/rooney/zencoding.git 43 | [submodule "libs/yasnippet"] 44 | path = libs/yasnippet 45 | url = https://github.com/joaotavora/yasnippet.git 46 | [submodule "libs/popup"] 47 | path = libs/popup 48 | url = https://github.com/auto-complete/popup-el.git 49 | [submodule "libs/npm"] 50 | path = libs/npm 51 | url = https://github.com/azer/npm.el.git 52 | [submodule "libs/relative-line-numbers"] 53 | path = libs/relative-line-numbers 54 | url = https://github.com/azer/linum-relativenumber.git 55 | [submodule "libs/clojure-mode"] 56 | path = libs/clojure-mode 57 | url = https://github.com/clojure-emacs/clojure-mode.git 58 | [submodule "libs/gocode"] 59 | path = libs/gocode 60 | url = https://github.com/nsf/gocode.git 61 | [submodule "libs/go-errcheck"] 62 | path = libs/go-errcheck 63 | url = https://github.com/dominikh/go-errcheck.el.git 64 | [submodule "libs/slim"] 65 | path = libs/slim 66 | url = https://github.com/slim-template/emacs-slim.git 67 | [submodule "libs/fiplr"] 68 | path = libs/fiplr 69 | url = https://github.com/grizzl/fiplr.git 70 | [submodule "libs/grizzl"] 71 | path = libs/grizzl 72 | url = https://github.com/grizzl/grizzl.git 73 | [submodule "libs/web-mode"] 74 | path = libs/web-mode 75 | url = https://github.com/fxbois/web-mode.git 76 | [submodule "libs/flycheck"] 77 | path = libs/flycheck 78 | url = https://github.com/flycheck/flycheck.git 79 | [submodule "libs/magit"] 80 | path = libs/magit 81 | url = git://github.com/magit/magit.git 82 | [submodule "libs/solarized"] 83 | path = libs/solarized 84 | url = https://github.com/sellout/emacs-color-theme-solarized.git 85 | [submodule "libs/solarized-theme"] 86 | path = libs/solarized-theme 87 | url = https://github.com/sellout/emacs-color-theme-solarized.git 88 | [submodule "libs/go-mode"] 89 | path = libs/go-mode 90 | url = https://github.com/dominikh/go-mode.el.git 91 | [submodule "libs/helm"] 92 | path = libs/helm 93 | url = https://github.com/emacs-helm/helm.git 94 | [submodule "libs/async"] 95 | path = libs/async 96 | url = https://github.com/jwiegley/emacs-async.git 97 | [submodule "libs/s"] 98 | path = libs/s 99 | url = https://github.com/magnars/s.el.git 100 | [submodule "libs/git-grep"] 101 | path = libs/git-grep 102 | url = https://github.com/yasuyk/helm-git-grep.git 103 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: emacs-lisp 2 | script: make install 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CHECK=\033[32m✔\033[39m 2 | DONE="${CHECK} DONE." 3 | 4 | all: install 5 | 6 | install: init-submodules install-js2mode install-go-tools install-helm 7 | @mkdir libs/color-theme/themes 8 | @echo $(DONE) 9 | 10 | install-js2mode: 11 | @echo "Installing js2-mode" 12 | @mkdir -p libs/js2-mode-compiled 13 | @cd libs/js2-mode && make && mv *.elc ../js2-mode-compiled/. 14 | @cp libs/js2-mode/js2-old-indent.el libs/js2-mode-compiled/. 15 | 16 | install-magit: 17 | @echo "Installing magit" 18 | @cd libs/magit && make 19 | 20 | install-helm: 21 | @cd libs/helm && make 22 | 23 | install-go-tools: 24 | @go get github.com/rogpeppe/godef 25 | @go get -u github.com/nsf/gocode 26 | 27 | init-submodules: 28 | @echo "Initializing submodules" 29 | @git submodule init && git submodule update && git submodule status 30 | 31 | override: 32 | ln -s ~/emacs/init.el ~/.emacs 33 | 34 | new-submodule: 35 | @echo "Creating new submodule '${name}' from ${git}" 36 | @git submodule add --force ${git} libs/${name} 37 | @echo $(DONE) 38 | 39 | update: update-repo init-submodules update-submodules 40 | 41 | update-repo: 42 | git pull origin master 43 | @echo $(DONE) 44 | 45 | update-submodules: 46 | @echo "Updating submodules" 47 | @git submodule foreach "(git checkout master; git pull)&" 48 | @echo $(DONE) 49 | 50 | clean: clean-js2mode 51 | 52 | clean-js2mode: 53 | @rm -rf libs/js2-mode-compiled 54 | 55 | .PHONY: clean 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Azer's Emacs Setup 2 | 3 | Ready-to-use Emacs setup for JavaScript and Go programming. 4 | 5 | ![](https://cldup.com/IqyLyhaTVM.gif) 6 | 7 | ## Install 8 | 9 | ```bash 10 | $ cd ~ 11 | $ git clone https://github.com/azer/emacs 12 | $ cd emacs 13 | $ make 14 | ``` 15 | 16 | Backup your existing configuration: 17 | 18 | ```bash 19 | $ mkdir ~/emacsbak && mv ~/.emacs* ~/emacsbak/. 20 | ``` 21 | 22 | And enable this emacs distro: 23 | 24 | ``` 25 | $ ln -s ~/emacs/init.el ~/.emacs 26 | ``` 27 | 28 | To check for updates; 29 | 30 | ```bash 31 | $ make update 32 | ``` 33 | 34 | ## What's included? 35 | 36 | * [npm.el](http://github.com/azer/npm.el) 37 | * [js2-mode](https://github.com/mooz/js2-mode) 38 | * [go-mode](https://github.com/dominikh/go-mode.el) 39 | * [gocode](https://github.com/nsf/gocode) 40 | * [errcheck](https://github.com/kisielk/errcheck) 41 | * [auto-complete](https://github.com/auto-complete/auto-complete) 42 | * [yasnippet](https://github.com/capitaomorte/yasnippet) 43 | * [zencoding](https://github.com/rooney/zencoding.git) 44 | * [js2-refactor](https://github.com/magnars/js2-refactor.el) 45 | * [js-comint](http://js-comint-el.sourceforge.net/) 46 | * [expand-region](https://github.com/magnars/expand-region.el) 47 | * [smart-forward](https://github.com/magnars/smart-forward.el) 48 | * powerline 49 | * jade-mode 50 | * zsh 51 | * smex 52 | * undo-tree 53 | * markdown-mode 54 | 55 | ## Usage 56 | 57 | ### Arrow Buttons 58 | 59 | * **Left:** Undo 60 | * **Right:** Redo 61 | * **Up:** Jump to up 62 | * **Down:** Jump to down 63 | 64 | ### NPM 65 | 66 | * **M-n n:** Create a new NodeJS Project 67 | * **M-n d:** Install and save new dependency 68 | * **M-n e:** Install and save new development dependency 69 | * **M-n s:** Search NPM 70 | * **M-n i:** Run `npm install` on current directory 71 | * **M-n p:** Publish the library on NPM 72 | * **M-n t:** Run the test command 73 | * **M-n v:** Make a new NPM version 74 | * **M-n b:** Release new patch version 75 | * **M-n m:** Release new minor version 76 | * **M-n a:** Release new major version 77 | 78 | ### Go 79 | 80 | * **C-c C-d:** Describe the code 81 | * **C-c C-j:** Jump to the definition of the code 82 | * **C-c C-a:** Add new import 83 | * **C-c C-r:** Remove unused imports 84 | * **C-c i:** Go to imports 85 | * **C-c m:** Run error check 86 | * **C-M a:** Go to the beginning of the function 87 | * **C-M e:** Go to the end of the function 88 | * **C-c d:** Godoc at point 89 | 90 | ### Git 91 | 92 | * **M-g s:** git status 93 | * **M-g l:** git log 94 | * **M-g f:** git pull 95 | * **M-g p:** git push 96 | 97 | ### Others 98 | 99 | ```bash 100 | * M-i ido-goto-symbol 101 | * C-c C-m Start Refactoring. More info: https://github.com/magnars/js2-refactor.el 102 | * m-g n run-js 103 | * m-g m js-send-region 104 | * m-s s er/expand-region 105 | * C-j zencoding-expand-yas 106 | * up jump to up 107 | * down jump to down 108 | * left undo 109 | * right redo 110 | * m-r replace-regexp 111 | * m-g g go to line 112 | * m-down go to forward line 113 | * m-up go to previous line 114 | * C-x \ align= 115 | * m-c run-last-command 116 | * m-g c run-new-command 117 | * m-z zsh 118 | ``` 119 | 120 | ## Snippets 121 | 122 | * [JavaScript snippets](https://github.com/azer/yasnippet/blob/master/snippets/js2-mode) 123 | * [Go Snippets](https://github.com/azer/yasnippet/tree/master/snippets/go-mode) 124 | 125 | ## Troubleshooting 126 | 127 | * js2-mode not working? Recompile js2-mode: `make install-js2mode` 128 | 129 | ## Notes 130 | 131 | * If you have `magit` installed on your system, enable related config from profiles/default.el 132 | * If you have `emacs-w3m` installed on your system, enable related config from profiles/default.el 133 | -------------------------------------------------------------------------------- /config/align.el: -------------------------------------------------------------------------------- 1 | (defun align= (begin end) 2 | "Align region to equal signs" 3 | (interactive "r") 4 | (align-regexp begin end "\\(\\s-*\\)[=|:]" 1 1)) 5 | 6 | (global-set-key (kbd "\C-x\\") 'align=) 7 | -------------------------------------------------------------------------------- /config/appearance.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "dircolors") 2 | (require 'dircolors) 3 | 4 | (add-lib-path "smooth-scrolling") 5 | (require 'smooth-scrolling) 6 | 7 | (menu-bar-mode -1) 8 | 9 | (if window-system 10 | ((tool-bar-mode -1) 11 | (menu-bar-mode -1) 12 | (scroll-bar-mode -1))) 13 | 14 | ;;highlight current line 15 | (global-hl-line-mode 1) 16 | 17 | ;;(set-face-background 'hl-line "#111") 18 | 19 | ;;set cursor colour 20 | ;;(set-cursor-color "yellow") 21 | -------------------------------------------------------------------------------- /config/auto-complete.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "auto-complete") 2 | (add-lib-path "popup") 3 | 4 | (require 'auto-complete) 5 | (require 'auto-complete-config) 6 | 7 | (ac-config-default) 8 | (ac-flyspell-workaround) 9 | (add-to-list 'ac-dictionary-directories (concat +emacs-lib-dir+ "/auto-complete/dict")) 10 | 11 | (setq ac-comphist-file (concat +emacs-tmp-dir+ "/ac-comphist.dat")) 12 | 13 | (global-auto-complete-mode t) 14 | (setq ac-auto-show-menu t) 15 | (setq ac-dwim t) 16 | (setq ac-use-menu-map t) 17 | (setq ac-quick-help-delay 1) 18 | (setq ac-quick-help-height 60) 19 | (setq ac-ignore-case nil) 20 | 21 | (set-default 'ac-sources 22 | '(ac-source-dictionary 23 | ac-source-words-in-buffer 24 | ac-source-words-in-same-mode-buffers 25 | ac-source-words-in-all-buffer)) 26 | 27 | (dolist (mode '(magit-log-edit-mode log-edit-mode org-mode text-mode haml-mode 28 | sass-mode yaml-mode csv-mode espresso-mode haskell-mode 29 | html-mode nxml-mode sh-mode smarty-mode clojure-mode 30 | lisp-mode javascript-mode js2-mode js2-jsx-mode textile-mode markdown-mode tuareg-mode)) 31 | (add-to-list 'ac-modes mode)) 32 | 33 | ;;Key triggers 34 | (ac-set-trigger-key "TAB") 35 | (define-key ac-completing-map (kbd "C-M-n") 'ac-next) 36 | (define-key ac-completing-map (kbd "C-M-p") 'ac-previous) 37 | (define-key ac-completing-map "\t" 'ac-complete) 38 | (define-key ac-completing-map "\r" nil) 39 | -------------------------------------------------------------------------------- /config/basic-bindings.el: -------------------------------------------------------------------------------- 1 | ;;(global-set-key (kbd "RET") 'newline-and-indent) 2 | 3 | (global-set-key (kbd "M-r") 'replace-regexp) 4 | (global-set-key (kbd "M-g u") 'undo) 5 | (global-set-key (kbd "M-g r") 'redo) 6 | 7 | (global-set-key "\C-w" 'backward-kill-word) 8 | (global-set-key "\C-x\C-k" 'kill-region) 9 | (global-set-key "\C-c\C-k" 'kill-region) 10 | 11 | (global-set-key [left] 'undo) 12 | (global-set-key [right] 'redo) 13 | 14 | (define-key input-decode-map "\e\eOA" [(meta up)]) 15 | (define-key input-decode-map "\e\eOB" [(meta down)]) 16 | (global-set-key [(meta up)] 'scroll-down-command) 17 | (global-set-key [(meta down)] 'scroll-up-command) 18 | 19 | ;;(global-set-key [(meta up)] 'previous-line) 20 | ;;(global-set-key [(meta down)] 'next-line) 21 | 22 | (global-set-key (kbd "C-c r") 'rename-this-buffer-and-file) 23 | 24 | ;;(global-set-key [up] nil) 25 | ;;(global-set-key [down] nil) 26 | ;;(global-set-key [left] nil) 27 | ;;(global-set-key [right] nil) 28 | 29 | (defun rename-this-buffer-and-file () 30 | "Renames current buffer and file it is visiting." 31 | (interactive) 32 | (let ((name (buffer-name)) 33 | (filename (buffer-file-name))) 34 | (if (not (and filename (file-exists-p filename))) 35 | (error "Buffer '%s' is not visiting a file!" name) 36 | (let ((new-name (read-file-name "New name: " filename))) 37 | (cond ((get-buffer new-name) 38 | (error "A buffer named '%s' already exists!" new-name)) 39 | (t 40 | (rename-file filename new-name 1) 41 | (rename-buffer new-name) 42 | (set-visited-file-name new-name) 43 | (set-buffer-modified-p nil) 44 | (message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name)))))))) 45 | -------------------------------------------------------------------------------- /config/basic.el: -------------------------------------------------------------------------------- 1 | (defalias 'yes-or-no-p 'y-or-n-p) 2 | 3 | (setq make-backup-files nil) 4 | (setq backup-inhibited t) 5 | (setq auto-save-default nil) 6 | (setq confirm-kill-emacs nil) 7 | 8 | (setq temporary-file-directory "/tmp/") 9 | (setq auto-save-file-name-transforms 10 | `((".*" ,temporary-file-directory t))) 11 | 12 | (setq create-lockfiles nil) 13 | 14 | (set-default 'truncate-lines t) 15 | 16 | (setq visible-bell t 17 | column-number-mode t 18 | echo-keystrokes 0.1 19 | font-lock-maximum-decoration t 20 | inhibit-startup-message t 21 | transient-mark-mode t 22 | color-theme-is-global t 23 | shift-select-mode nil 24 | mouse-yank-at-point t 25 | ;;require-final-newline t 26 | truncate-partial-width-windows nil 27 | delete-by-moving-to-trash nil 28 | uniquify-buffer-name-style 'forward 29 | ediff-window-setup-function 'ediff-setup-windows-plain 30 | xterm-mouse-mode t) 31 | 32 | (setq locale-coding-system 'utf-8) 33 | (set-terminal-coding-system 'utf-8) 34 | (set-keyboard-coding-system 'utf-8) 35 | (set-selection-coding-system 'utf-8) 36 | (prefer-coding-system 'utf-8) 37 | (ansi-color-for-comint-mode-on) 38 | 39 | (auto-compression-mode t) 40 | 41 | (random t) ;; Seed the random-number generator 42 | 43 | (setq diff-switches "-u") 44 | 45 | ;; make emacs use the clipboard 46 | (setq x-select-enable-clipboard t) 47 | 48 | (setq confirm-nonexistent-file-or-buffer nil) 49 | 50 | ;;remove all trailing whitespace and trailing blank lines before saving the file 51 | (add-hook 'before-save-hook 'delete-trailing-whitespace) 52 | ;;(add-hook 'before-save-hook 'delete-trailing-blank-lines) 53 | (setq-default show-trailing-whitespace t) 54 | 55 | ;; set uniquify separator 56 | (require 'uniquify) 57 | (setq 58 | uniquify-buffer-name-style 'post-forward 59 | uniquify-separator ":") 60 | 61 | (defun delete-trailing-blank-lines () 62 | "Deletes all blank lines at the end of the file." 63 | (interactive) 64 | (save-excursion 65 | (save-restriction 66 | (widen) 67 | (goto-char (point-max)) 68 | (delete-blank-lines)))) 69 | -------------------------------------------------------------------------------- /config/clojure.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "clojure-mode") 2 | (require 'clojure-mode) 3 | (require 'rainbow-parens) 4 | (require 'rainbow-delimiters) 5 | 6 | (add-hook 'clojure-mode-hook 'rainbow-delimiters-mode) 7 | (add-hook 'clojure-mode-hook 'rainbow-paren-mode) 8 | 9 | (eval-after-load 'clojure-mode 10 | '(font-lock-add-keywords 11 | 'clojure-mode `(("(\\(fn\\)[\[[:space:]]" 12 | (0 (progn (compose-region (match-beginning 1) 13 | (match-end 1) "λ") 14 | nil)))))) 15 | 16 | (eval-after-load 'clojure-mode 17 | '(font-lock-add-keywords 18 | 'clojure-mode `(("\\(#\\)(" 19 | (0 (progn (compose-region (match-beginning 1) 20 | (match-end 1) "ƒ") 21 | nil)))))) 22 | 23 | (eval-after-load 'clojure-mode 24 | '(font-lock-add-keywords 25 | 'clojure-mode `(("\\(#\\){" 26 | (0 (progn (compose-region (match-beginning 1) 27 | (match-end 1) "∈") 28 | nil)))))) 29 | 30 | (eval-after-load 'find-file-in-project 31 | '(add-to-list 'ffip-patterns "*.clj")) 32 | 33 | 34 | ;;command to align let statements 35 | ;;To use: M-x align-cljlet 36 | ;;(add-lib-path "align-cljlet") 37 | ;;(require 'align-cljlet) 38 | -------------------------------------------------------------------------------- /config/cmd.el: -------------------------------------------------------------------------------- 1 | (setq cmd "make") 2 | 3 | (defun run-last-command () 4 | "Run given command on working directory" 5 | (interactive) 6 | (message (concat "Running " cmd)) 7 | (compile cmd)) 8 | 9 | (defun run-new-command () 10 | "Set the command to run" 11 | (interactive) 12 | (setq cmd (read-from-minibuffer "Set the command to run: " cmd)) 13 | (run-last-command)) 14 | 15 | (global-set-key (kbd "M-g c") 'run-new-command) 16 | (global-set-key (kbd "M-c") 'run-last-command) 17 | -------------------------------------------------------------------------------- /config/coffee.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "coffee-mode") 2 | (require 'coffee-mode) 3 | 4 | (add-to-list 'auto-mode-alist '("\\.coffee$" . coffee-mode)) 5 | (add-to-list 'auto-mode-alist '("Cakefile" . coffee-mode)) 6 | (add-to-list 'auto-mode-alist '("Devfile" . coffee-mode)) 7 | 8 | (add-to-list 'ac-modes 'coffee-mode) 9 | 10 | (setq coffee-tab-width 2) 11 | 12 | (add-hook 'coffee-mode-hook 13 | (lambda () 14 | (setq imenu-generic-expression coffee-imenu-generic-expression))) 15 | -------------------------------------------------------------------------------- /config/colorize-compilation.el: -------------------------------------------------------------------------------- 1 | (require 'ansi-color) 2 | 3 | ;;(setq compilation-ask-about-save nil) 4 | 5 | (defun colorize-compilation-buffer () 6 | (toggle-read-only) 7 | (ansi-color-apply-on-region (point-min) (point-max)) 8 | (toggle-read-only)) 9 | 10 | (add-hook 'compilation-filter-hook 'colorize-compilation-buffer) 11 | -------------------------------------------------------------------------------- /config/colors.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "color-theme") 2 | 3 | (require 'color-theme) 4 | (color-theme-initialize) 5 | 6 | (require 'color-theme-gruber-darker) 7 | (color-theme-gruber-darker) 8 | -------------------------------------------------------------------------------- /config/css.el: -------------------------------------------------------------------------------- 1 | (setq css-indent-offset 2) 2 | -------------------------------------------------------------------------------- /config/dash.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "dash") 2 | (require 'dash) 3 | -------------------------------------------------------------------------------- /config/debug.el: -------------------------------------------------------------------------------- 1 | (setq debug-on-error t) 2 | (setq max-specpdl-size 5) 3 | -------------------------------------------------------------------------------- /config/erc.el: -------------------------------------------------------------------------------- 1 | (setq erc-truncate-buffer-on-save t) 2 | (defvar erc-insert-post-hook) 3 | (add-hook 'erc-insert-post-hook 4 | 'erc-truncate-buffer) 5 | 6 | (setq erc-max-buffer-size 20000) 7 | ;;(erc-hide-timestamps) 8 | 9 | (setq erc-hide-list '("JOIN" "NICK" "PART" "QUIT")) 10 | 11 | (add-hook 'erc-mode-hook (lambda () 12 | (setq show-trailing-whitespace nil) 13 | (linum-mode 0))) 14 | -------------------------------------------------------------------------------- /config/eshell.el: -------------------------------------------------------------------------------- 1 | (defvar eshell-path-env (getenv "PATH")) 2 | -------------------------------------------------------------------------------- /config/expand-region.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "expand-region") 2 | (require 'expand-region) 3 | 4 | (global-set-key (kbd "M-s s") 'er/expand-region) 5 | -------------------------------------------------------------------------------- /config/fiplr.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "grizzl") 2 | (require 'grizzl) 3 | 4 | (add-lib-path "fiplr") 5 | (require 'fiplr) 6 | (global-set-key (kbd "C-x f") 'fiplr-find-file) 7 | 8 | (setq fiplr-ignored-globs 9 | '((directories 10 | ;; Version control 11 | (".git" 12 | ".svn" 13 | ".hg" 14 | ".bzr" 15 | ;; NPM 16 | "node_modules" 17 | ;; Bower 18 | "bower_components" 19 | ;; Maven 20 | "target" 21 | ;; Python 22 | "__pycache__" 23 | ;; others 24 | "tmp" 25 | "vendor" 26 | )) 27 | (files 28 | ;; Emacs 29 | (".#*" 30 | ;; Vim 31 | "*~" 32 | ;; Objects 33 | "*.so" 34 | "*.o" 35 | "*.obj" 36 | ;; Media 37 | "*.jpg" 38 | "*.png" 39 | "*.gif" 40 | "*.pdf" 41 | ;; Archives 42 | "*.gz" 43 | "*.zip")))) 44 | -------------------------------------------------------------------------------- /config/flycheck.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "let-alist") 2 | (require 'let-alist) 3 | 4 | (add-lib-path "flycheck") 5 | (require 'flycheck) 6 | -------------------------------------------------------------------------------- /config/font.el: -------------------------------------------------------------------------------- 1 | (set-default-font "Inconsolata-12") 2 | (setq-default line-spacing 5) 3 | -------------------------------------------------------------------------------- /config/git.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "magit/lisp") 2 | (add-lib-path "git-grep") 3 | (require 'magit) 4 | (require 'helm-git-grep) 5 | 6 | (global-set-key (kbd "M-g s") 'magit-status) 7 | (global-set-key (kbd "M-g l") 'magit-log) 8 | (global-set-key (kbd "M-g f") 'magit-pull-current) 9 | (global-set-key (kbd "M-g p") 'magit-push-quickly) 10 | (global-set-key (kbd "M-g r") 'helm-git-grep) 11 | 12 | (with-eval-after-load 'info 13 | (info-initialize) 14 | (add-to-list 'Info-directory-list 15 | (concat +emacs-lib-dir+ "/magit/Documentation"))) 16 | -------------------------------------------------------------------------------- /config/golang.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "go-mode") 2 | (add-lib-path "go-errcheck") 3 | (add-lib-path "gocode/emacs") 4 | 5 | (require 'go-mode) 6 | (require 'go-autocomplete) 7 | (require 'auto-complete-config) 8 | (require 'go-errcheck) 9 | 10 | (add-hook 'before-save-hook 'gofmt-before-save) 11 | ;;(add-hook 'before-save-hook 'go-remove-unused-imports) 12 | 13 | (add-hook 14 | 'go-mode-hook (lambda () (setq indent-tabs-mode t))) 15 | 16 | (add-hook 'go-mode-hook (lambda () 17 | (local-set-key (kbd "C-c C-r") 'go-remove-unused-imports))) 18 | 19 | (add-hook 'go-mode-hook (lambda () 20 | (local-set-key (kbd "C-c i") 'go-goto-imports))) 21 | 22 | (add-hook 'go-mode-hook (lambda () 23 | (local-set-key (kbd "C-c m") 'go-errcheck))) 24 | 25 | (add-hook 'go-mode-hook (lambda () 26 | (local-set-key (kbd "C-c C-r") 'go-remove-unused-imports))) 27 | 28 | (add-hook 'go-mode-hook (lambda () 29 | (local-set-key (kbd "C-c d") 'godoc-at-point))) 30 | 31 | (defun auto-complete-for-go () 32 | (auto-complete-mode 1)) 33 | 34 | (add-hook 'go-mode-hook 'auto-complete-for-go) 35 | 36 | (defun set-go-path () 37 | "Set GOPATH and GOBIN" 38 | (interactive) 39 | (let (gopath) 40 | (setq gopath (read-from-minibuffer "GOPATH: " (file-name-directory (or load-file-name buffer-file-name)))) 41 | (message (concat "Setting GOPATH to " gopath)) 42 | (setenv "GOPATH" gopath) 43 | (setenv "GOBIN" (concat gopath "/bin")) 44 | ) 45 | ) 46 | 47 | (add-hook 'go-mode-hook (lambda () 48 | (local-set-key (kbd "C-c p") 'set-go-path))) 49 | -------------------------------------------------------------------------------- /config/helm.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "async") 2 | (add-lib-path "helm") 3 | 4 | (require 'helm-config) 5 | (require 'helm) 6 | (helm-autoresize-mode 1) 7 | -------------------------------------------------------------------------------- /config/ido.el: -------------------------------------------------------------------------------- 1 | (ido-mode t) 2 | (setq ido-enable-prefix nil 3 | ido-enable-flex-matching t 4 | ido-create-new-buffer 'always 5 | ido-use-filename-at-point 'guess 6 | ido-max-prospects 10) 7 | -------------------------------------------------------------------------------- /config/idomenu.el: -------------------------------------------------------------------------------- 1 | (defun ido-goto-symbol (&optional symbol-list) 2 | "Refresh imenu and jump to a place in the buffer using Ido." 3 | (interactive) 4 | (unless (featurep 'imenu) 5 | (require 'imenu nil t)) 6 | (cond 7 | ((not symbol-list) 8 | (let ((ido-mode ido-mode) 9 | (ido-enable-flex-matching 10 | (if (boundp 'ido-enable-flex-matching) 11 | ido-enable-flex-matching t)) 12 | name-and-pos symbol-names position) 13 | (unless ido-mode 14 | (ido-mode 1) 15 | (setq ido-enable-flex-matching t)) 16 | (while (progn 17 | (imenu--cleanup) 18 | (setq imenu--index-alist nil) 19 | (ido-goto-symbol (imenu--make-index-alist)) 20 | (setq selected-symbol 21 | (ido-completing-read "Symbol? " symbol-names)) 22 | (string= (car imenu--rescan-item) selected-symbol))) 23 | (unless (and (boundp 'mark-active) mark-active) 24 | (push-mark nil t nil)) 25 | (setq position (cdr (assoc selected-symbol name-and-pos))) 26 | (cond 27 | ((overlayp position) 28 | (goto-char (overlay-start position))) 29 | (t 30 | (goto-char position))))) 31 | ((listp symbol-list) 32 | (dolist (symbol symbol-list) 33 | (let (name position) 34 | (cond 35 | ((and (listp symbol) (imenu--subalist-p symbol)) 36 | (ido-goto-symbol symbol)) 37 | ((listp symbol) 38 | (setq name (car symbol)) 39 | (setq position (cdr symbol))) 40 | ((stringp symbol) 41 | (setq name symbol) 42 | (setq position 43 | (get-text-property 1 'org-imenu-marker symbol)))) 44 | (unless (or (null position) (null name) 45 | (string= (car imenu--rescan-item) name)) 46 | (add-to-list 'symbol-names name) 47 | (add-to-list 'name-and-pos (cons name position)))))))) 48 | 49 | (global-set-key (kbd "M-i") 'ido-goto-symbol) 50 | -------------------------------------------------------------------------------- /config/indent.el: -------------------------------------------------------------------------------- 1 | (setq-default indent-tabs-mode nil) 2 | (setq-default tab-width 2) 3 | (setq indent-line-function 'insert-tab) 4 | -------------------------------------------------------------------------------- /config/jade-mode.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "jade-mode") 2 | (require 'sws-mode) 3 | (require 'jade-mode) 4 | (require 'stylus-mode) 5 | (add-to-list 'auto-mode-alist '("\\.styl$" . stylus-mode)) 6 | (add-to-list 'auto-mode-alist '("\\.jade$" . jade-mode)) 7 | 8 | (add-to-list 'ac-modes 'stylus-mode) 9 | -------------------------------------------------------------------------------- /config/js2-refactor.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "multiple-cursors") 2 | (require 'multiple-cursors) 3 | 4 | (add-lib-path "js2-refactor") 5 | (require 'js2-refactor) 6 | -------------------------------------------------------------------------------- /config/js2.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "js2-mode-compiled") 2 | 3 | (autoload 'js2-mode "js2-mode" nil t) 4 | (autoload 'js2-jsx-mode "js2-mode" nil t) 5 | (add-to-list 'auto-mode-alist '("\\.js$" . js2-jsx-mode)) 6 | ;;(add-to-list 'auto-mode-alist '("\\.jsx$" . js2-mode)) 7 | (add-to-list 'auto-mode-alist '("\\.json$" . js2-mode)) 8 | 9 | (custom-set-variables '(js2-strict-inconsistent-return-warning nil)) 10 | (custom-set-variables '(js2-strict-missing-semi-warning nil)) 11 | 12 | (setq js-indent-level 2) 13 | (setq js2-indent-level 2) 14 | (setq js2-basic-offset 2) 15 | 16 | ;;(add-hook 'js2-mode-hook '(lambda () 17 | ;; (local-set-key (kbd "RET") 'newline-and-indent))) 18 | -------------------------------------------------------------------------------- /config/json.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "json") 2 | (require 'json) 3 | -------------------------------------------------------------------------------- /config/linum.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "relative-line-numbers") 2 | (require 'relative-linum) 3 | 4 | (global-linum-mode) 5 | 6 | (defun linum-forward (n) 7 | (interactive "n Jump to forward line: ") 8 | (forward-line n)) 9 | 10 | (defun linum-previous (n) 11 | (interactive "n Jump to previous line: ") 12 | (previous-line n)) 13 | 14 | (global-set-key [up] 'linum-previous) 15 | (global-set-key [down] 'linum-forward) 16 | 17 | (global-set-key (kbd "M-n l") 'global-linum-mode) 18 | -------------------------------------------------------------------------------- /config/lisp.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "rainbow") 2 | 3 | (require 'rainbow-parens) 4 | (require 'rainbow-delimiters) 5 | 6 | (show-paren-mode 1) 7 | (define-key lisp-mode-shared-map (kbd "RET") 'reindent-then-newline-and-indent) 8 | 9 | (defun turn-on-paredit () 10 | (paredit-mode t)) 11 | 12 | (dolist (x '(scheme emacs-lisp lisp clojure)) 13 | (add-hook 14 | (intern (concat (symbol-name x) "-mode-hook")) 'turn-on-paredit) 15 | (add-hook 16 | (intern (concat (symbol-name x) "-mode-hook")) 'rainbow-paren-mode)) 17 | -------------------------------------------------------------------------------- /config/markdown.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "markdown-mode") 2 | 3 | (autoload 'markdown-mode "markdown-mode.el" 4 | "Major mode for editing Markdown files" t) 5 | (setq auto-mode-alist 6 | (cons '("\\.md" . markdown-mode) auto-mode-alist)) 7 | -------------------------------------------------------------------------------- /config/node.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "js-comint") 2 | 3 | (require 'js-comint) 4 | 5 | (setq inferior-js-program-command "node") 6 | (setq inferior-js-mode-hook 7 | (lambda () 8 | ;; We like nice colors 9 | (ansi-color-for-comint-mode-on) 10 | ;; Deal with some prompt nonsense 11 | (add-to-list 'comint-preoutput-filter-functions 12 | (lambda (output) 13 | (replace-regexp-in-string ".*1G\.\.\..*5G" "..." 14 | (replace-regexp-in-string ".*1G.*3G" " > " output)))))) 15 | 16 | (global-set-key (kbd "M-g n") 'run-js) 17 | (global-set-key (kbd "M-g m") 'js-send-region) 18 | -------------------------------------------------------------------------------- /config/npm.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "npm") 2 | (require 'npm) 3 | 4 | (global-set-key (kbd "M-n i") 'npm-install) 5 | (global-set-key (kbd "M-n n") 'npm-new) 6 | (global-set-key (kbd "M-n d") 'npm-new-dependency) 7 | (global-set-key (kbd "M-n e") 'npm-new-dev-dependency) 8 | (global-set-key (kbd "M-n p") 'npm-publish) 9 | (global-set-key (kbd "M-n b") 'npm-patch) 10 | (global-set-key (kbd "M-n m") 'npm-minor) 11 | (global-set-key (kbd "M-n a") 'npm-major) 12 | (global-set-key (kbd "M-n t") 'npm-test) 13 | (global-set-key (kbd "M-n s") 'npm-search) 14 | (global-set-key (kbd "M-n v") 'npm-version) 15 | -------------------------------------------------------------------------------- /config/optimize.el: -------------------------------------------------------------------------------- 1 | (setq jit-lock-defer-time 0.05) 2 | -------------------------------------------------------------------------------- /config/paredit.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "paredit") 2 | 3 | 4 | (eval-after-load 'paredit 5 | ;; need a binding that works in the terminal 6 | '(define-key paredit-mode-map (kbd "M-)") 'paredit-forward-slurp-sexp)) 7 | 8 | (require 'paredit) 9 | -------------------------------------------------------------------------------- /config/powerline.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "powerline") 2 | (require 'powerline) 3 | (powerline-default-theme) 4 | 5 | (setq-default mode-line-format 6 | '("%e" 7 | (:eval 8 | (let* ((active (eq (frame-selected-window) (selected-window))) 9 | (face1 (if active 'powerline-active1 'powerline-inactive1)) 10 | (face2 (if active 'powerline-active2 'powerline-inactive2)) 11 | (lhs (list 12 | (powerline-raw "%*" nil 'l) 13 | (powerline-buffer-size nil 'l) 14 | (powerline-buffer-id nil 'l) 15 | 16 | (powerline-raw " ") 17 | (powerline-arrow-right nil face1) 18 | 19 | (powerline-major-mode face1 'l) 20 | (powerline-minor-modes face1 'l) 21 | (powerline-raw mode-line-process face1 'l) 22 | 23 | (powerline-narrow face1 'l) 24 | 25 | (powerline-arrow-right face1 face2) 26 | 27 | (powerline-vc face2) 28 | )) 29 | (rhs (list 30 | (powerline-raw global-mode-string face2 'r) 31 | 32 | (powerline-arrow-left face2 face1) 33 | 34 | (powerline-raw "%4l" face1 'r) 35 | (powerline-raw ":" face1) 36 | (powerline-raw "%3c" face1 'r) 37 | 38 | (powerline-arrow-left face1 nil) 39 | (powerline-raw " ") 40 | 41 | (powerline-raw "%6p" nil 'r) 42 | 43 | (powerline-hud face2 face1)))) 44 | (concat 45 | (powerline-render lhs) 46 | (powerline-fill face2 (powerline-width rhs)) 47 | (powerline-render rhs)))))) 48 | -------------------------------------------------------------------------------- /config/shell.el: -------------------------------------------------------------------------------- 1 | (require 'ansi-color) 2 | 3 | (defun colorize-compilation-buffer () 4 | (toggle-read-only) 5 | (ansi-color-apply-on-region (point-min) (point-max)) 6 | (toggle-read-only)) 7 | 8 | (add-hook 'compilation-filter-hook 'colorize-compilation-buffer) 9 | (add-hook 'shell-mode-hook 'colorize-compilation-buffer) 10 | -------------------------------------------------------------------------------- /config/slim.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "slim") 2 | (require 'slim-mode) 3 | -------------------------------------------------------------------------------- /config/smart-forward.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "smart-forward") 2 | (require 'smart-forward) 3 | 4 | (define-key input-decode-map "\e\eOA" [(meta up)]) 5 | (define-key input-decode-map "\e\eOB" [(meta down)]) 6 | 7 | 8 | ;;(global-set-key [(meta up)] 'smart-up) 9 | ;;(global-set-key [(meta down)] 'smart-down) 10 | -------------------------------------------------------------------------------- /config/smex.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "smex") 2 | (require 'smex) 3 | (smex-initialize) 4 | (global-set-key (kbd "M-x") 'smex) 5 | (global-set-key (kbd "M-X") 'smex-major-mode-commands) 6 | ;; This is your old M-x. 7 | (global-set-key (kbd "C-c C-c M-x") 'execute-extended-command) 8 | -------------------------------------------------------------------------------- /config/solarized.el: -------------------------------------------------------------------------------- 1 | (add-to-list 'custom-theme-load-path (concat +emacs-lib-dir+ "/solarized-theme")) 2 | ;;(load-theme "solarized-dark") 3 | (set-frame-parameter nil 'background-mode 'dark) 4 | (customize-set-variable 'frame-background-mode 'dark) 5 | (load-theme 'solarized t) 6 | -------------------------------------------------------------------------------- /config/string.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "s") 2 | (require 's) 3 | -------------------------------------------------------------------------------- /config/undo-tree.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "undo-tree") 2 | (require 'undo-tree) 3 | (global-undo-tree-mode) 4 | -------------------------------------------------------------------------------- /config/web.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "web-mode") 2 | 3 | (require 'web-mode) 4 | (add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode)) 5 | (add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode)) 6 | (add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode)) 7 | (add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode)) 8 | (add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode)) 9 | (add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode)) 10 | (add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode)) 11 | (add-to-list 'auto-mode-alist '("\\.jsx$" . web-mode)) 12 | 13 | (setq web-mode-markup-indent-offset 2) 14 | (setq web-mode-css-indent-offset 2) 15 | (setq web-mode-code-indent-offset 2) 16 | 17 | (set-face-attribute 'web-mode-html-tag-bracket-face nil :foreground "Grey22") 18 | 19 | (defadvice web-mode-highlight-part (around tweak-jsx activate) 20 | (if (equal web-mode-content-type "jsx") 21 | (let ((web-mode-enable-part-face nil)) 22 | ad-do-it) 23 | ad-do-it)) 24 | 25 | (flycheck-define-checker jsxhint-checker 26 | "A JSX syntax and style checker based on JSXHint." 27 | 28 | :command ("jsxhint" source) 29 | :error-patterns 30 | ((error line-start (1+ nonl) ": line " line ", col " column ", " (message) line-end)) 31 | :modes (web-mode)) 32 | 33 | (add-hook 'web-mode-hook 34 | (lambda () 35 | (when (equal web-mode-content-type "jsx") 36 | ;; enable flycheck 37 | (flycheck-select-checker 'jsxhint-checker) 38 | (flycheck-mode)))) 39 | -------------------------------------------------------------------------------- /config/yasnippet.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "yasnippet") 2 | (require 'yasnippet) 3 | 4 | ;;(defconst +snippets-dir+ (concat +emacs-lib-dir+ "/yasnippet/snippets")) 5 | 6 | ;;(yas/load-directory +snippets-dir+) 7 | ;;(setq yas/snippet-dirs '(+snippets-dir+)) 8 | 9 | 10 | (setq yas-snippet-dirs '(+emacs-snippets-dir+)) 11 | 12 | (yas/global-mode 1) 13 | (setq yas/trigger-key "M-SPC") 14 | (global-set-key (kbd "M-SPC") 'yas/expand) 15 | 16 | ;;(define-key yas-minor-mode-map [(tab)] nil) 17 | ;;(define-key yas-minor-mode-map (kbd "TAB") nil) 18 | ;;(define-key yas-minor-mode-map (kbd "") nil) 19 | ;;(define-key ac-completing-map "\t" nil) 20 | ;;(define-key yas-minor-mode-map (kbd "SPC") 'yas-next-field-or-maybe-expand) 21 | 22 | (eval-after-load 'yasnippet 23 | '(progn 24 | (define-key yas-keymap (kbd "TAB") nil) 25 | (define-key yas-keymap (kbd "") nil) 26 | (define-key yas-keymap [(tab)] nil) 27 | (define-key yas-keymap [right] 'yas-next-field-or-maybe-expand))) 28 | 29 | (eval-after-load 'js2-mode 30 | '(progn 31 | (define-key js2-mode-map (kbd "TAB") (lambda() 32 | (interactive) 33 | (let ((yas/fallback-behavior 'return-nil)) 34 | (unless (yas/expand) 35 | (indent-for-tab-command) 36 | (if (looking-back "^\s*") 37 | (back-to-indentation)))))))) 38 | -------------------------------------------------------------------------------- /config/zencoding.el: -------------------------------------------------------------------------------- 1 | (add-lib-path "zencoding") 2 | 3 | (require 'zencoding-mode) 4 | (add-hook 'sgml-mode-hook 'zencoding-mode) 5 | 6 | (global-set-key (kbd "\C-j") 'zencoding-expand-yas) 7 | -------------------------------------------------------------------------------- /config/zsh.el: -------------------------------------------------------------------------------- 1 | (defun zsh () 2 | "Start a terminal and rename buffer." 3 | (interactive) 4 | (term "/bin/zsh")) 5 | 6 | (global-set-key (kbd "M-z") 'zsh) 7 | 8 | (add-hook 'term-mode-hook (lambda () 9 | (setq show-trailing-whitespace nil) 10 | (linum-mode 0))) 11 | -------------------------------------------------------------------------------- /custom.example.el: -------------------------------------------------------------------------------- 1 | ;; copy paste this file to ./custom.el 2 | 3 | (setq npm-vars-author "Azer Koculu ") 4 | (setq npm-vars-git-user "azer") 5 | (setq npm-vars-deps "mocha * dev") 6 | -------------------------------------------------------------------------------- /init.el: -------------------------------------------------------------------------------- 1 | (package-initialize) 2 | (defconst +home-dir+ "~") 3 | (defconst +emacs-dir+ (concat +home-dir+ "/emacs")) 4 | (defconst +emacs-profiles-dir+ (concat +emacs-dir+ "/profiles")) 5 | (defconst +emacs-lib-dir+ (concat +emacs-dir+ "/libs")) 6 | (defconst +emacs-conf-dir+ (concat +emacs-dir+ "/config")) 7 | (defconst +emacs-tmp-dir+ (concat +emacs-dir+ "/tmp")) 8 | (defconst +emacs-snippets-dir+ (concat +emacs-dir+ "/snippets")) 9 | 10 | ;; new projects will be created under this directory 11 | (defconst +dev-dir+ (concat +home-dir+ "/dev")) 12 | 13 | (defun add-load-path (p) 14 | (add-to-list 'load-path (concat +emacs-dir+ "/" p))) 15 | 16 | (defun add-lib-path (p) 17 | (add-to-list 'load-path (concat +emacs-lib-dir+ "/" p))) 18 | 19 | (defun load-conf-file (f) 20 | (load-file (concat +emacs-conf-dir+ "/" f ".el"))) 21 | 22 | (defun load-lib-file (f) 23 | (load-file (concat +emacs-lib-dir+ "/" f))) 24 | 25 | (defun load-profile (p) 26 | (load-file (concat +emacs-profiles-dir+ "/" p ".el"))) 27 | 28 | (defun load-customizations () 29 | (let ((filename (concat +emacs-dir+ "/custom.el"))) 30 | (if (file-readable-p filename) 31 | (load-file filename)))) 32 | 33 | (add-load-path "") 34 | (add-load-path "lib") 35 | 36 | (load-profile "default") 37 | (load-profile "js") 38 | ;;(load-profile "coffee") 39 | (load-profile "golang") 40 | ;;(load-profile "clojure") 41 | 42 | (load-customizations) 43 | 44 | ;;(add-to-list 'command-switch-alist '("clojure" . (lambda (n) (load-profile "clojure")))) 45 | ;;(add-to-list 'command-switch-alist '("ruby" . (lambda (n) (load-profile "ruby")))) 46 | ;;(add-to-list 'command-switch-alist '("android" . (lambda (n) (load-profile "android")))) 47 | (custom-set-variables 48 | ;; custom-set-variables was added by Custom. 49 | ;; If you edit it by hand, you could mess it up, so be careful. 50 | ;; Your init file should contain only one such instance. 51 | ;; If there is more than one, they won't work right. 52 | '(custom-safe-themes 53 | (quote 54 | ("8aebf25556399b58091e533e455dd50a6a9cba958cc4ebb0aab175863c25b9a4" "a8245b7cc985a0610d71f9852e9f2767ad1b852c2bdea6f4aadc12cce9c4d6d0" default))) 55 | '(js2-strict-inconsistent-return-warning nil)) 56 | (custom-set-faces 57 | ;; custom-set-faces was added by Custom. 58 | ;; If you edit it by hand, you could mess it up, so be careful. 59 | ;; Your init file should contain only one such instance. 60 | ;; If there is more than one, they won't work right. 61 | ) 62 | -------------------------------------------------------------------------------- /libs/color-theme/color-theme-gruber-darker.el: -------------------------------------------------------------------------------- 1 | ;; color-theme-gruber-dark.el 2 | ;; Revision 1 3 | ;; 4 | :;; Copyright (C) 2009-2010 Jason R. Blevins 5 | ;; 6 | ;; Permission is hereby granted, free of charge, to any person 7 | ;; obtaining a copy of this software and associated documentation 8 | ;; files (the "Software"), to deal in the Software without 9 | ;; restriction, including without limitation the rights to use, 10 | ;; copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | ;; copies of the Software, and to permit persons to whom the 12 | ;; Software is furnished to do so, subject to the following 13 | ;; conditions: 14 | ;; 15 | ;; The above copyright notice and this permission notice shall be 16 | ;; included in all copies or substantial portions of the Software. 17 | ;; 18 | ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | ;; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | ;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | ;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | ;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | ;; OTHER DEALINGS IN THE SOFTWARE. 26 | 27 | (require 'color-theme) 28 | 29 | (defun color-theme-gruber-darker () 30 | "Gruber Darker color theme for Emacs by Jason Blevins. 31 | A darker variant of the Gruber Dark theme for BBEdit 32 | by John Gruber." 33 | (interactive) 34 | (color-theme-install 35 | '(color-theme-gruber-darker 36 | ((foreground-color . "#e4e4ef") 37 | (background-color . "#000000") 38 | (background-mode . dark) 39 | (cursor-color . "#ffdd33") 40 | (mouse-color . "#ffdd33")) 41 | 42 | ;; Standard font lock faces 43 | (default ((t (nil)))) 44 | (font-lock-comment-face ((t (:foreground "#cc8c3c")))) 45 | (font-lock-comment-delimiter-face ((t (:foreground "#cc8c3c")))) 46 | (font-lock-doc-face ((t (:foreground "#73c936")))) 47 | (font-lock-doc-string-face ((t (:foreground "#73c936")))) 48 | (font-lock-string-face ((t (:foreground "#73c936")))) 49 | (font-lock-keyword-face ((t (:foreground "#ffdd33")))) 50 | (font-lock-builtin-face ((t (:foreground "#ffdd33")))) 51 | ;;(font-lock-function-name-face ((t (:foreground "#96a6c8" :weight bold)))) 52 | (font-lock-function-name-face ((t (:foreground "#ff6644" :weight normal)))) 53 | (font-lock-variable-name-face ((t (:foreground "#f4f4ff")))) 54 | (font-lock-preprocessor-face ((t (:foreground "#95a99f")))) 55 | (font-lock-constant-face ((t (:foreground "#95a99f")))) 56 | (font-lock-type-face ((t (:foreground "#95a99f")))) 57 | (font-lock-warning-face ((t (:foreground "#f43841")))) 58 | (font-lock-reference-face ((t (:foreground "#95a99f")))) 59 | (trailing-whitespace ((t (:foreground "#000" :background "#f43841")))) 60 | (link ((t (:foreground "#96A6C8" :underline t)))) 61 | 62 | ;; Search 63 | (isearch ((t (:foreground "#000" :background "#f5f5f5")))) 64 | (isearch-lazy-highlight-face ((t (:foreground "#f4f4ff" :background "#5f627f")))) 65 | (isearch-fail ((t (:foreground "#000" :background "#f43841")))) 66 | 67 | ;; User interface 68 | (fringe ((t (:background "#111" :foreground "#444")))) 69 | (border ((t (:background "#111" :foreground "#444")))) 70 | (mode-line ((t (:background "#453d41" :foreground "#fff")))) 71 | (mode-line-buffer-id ((t (:background "#453d41" :foreground "#fff")))) 72 | (mode-line-inactive ((t (:background "#453d41" :foreground "#999")))) 73 | (minibuffer-prompt ((t (:foreground "#96A6C8")))) 74 | (region ((t (:background "#222" :foreground "#ff0066")))) 75 | (secondary-selection ((t (:background "#484951" :foreground "#F4F4FF")))) 76 | (tooltip ((t (:background "#52494e" :foreground "#fff")))) 77 | 78 | ;; Parenthesis matching 79 | (show-paren-match-face ((t (:background "#52494e" :foreground "#f4f4ff")))) 80 | (show-paren-mismatch-face ((t (:foreground "#f4f4ff" :background "#c73c3f")))) 81 | ;; Line highlighting 82 | (highlight ((t (:background "#282828" :foreground nil)))) 83 | (highlight-current-line-face ((t (:background "#111" :foreground nil)))) 84 | 85 | ;; Calendar 86 | (holiday-face ((t (:foreground "#f43841")))) 87 | 88 | ;; Info 89 | (info-xref ((t (:foreground "#96a6c8")))) 90 | (info-visited ((t (:foreground "#9e95c7")))) 91 | 92 | ;; AUCTeX 93 | (font-latex-sectioning-5-face ((t (:foreground "#96a6c8" :bold t)))) 94 | (font-latex-bold-face ((t (:foreground "#95a99f" :bold t)))) 95 | (font-latex-italic-face ((t (:foreground "#95a99f" :italic t)))) 96 | (font-latex-math-face ((t (:foreground "#73c936")))) 97 | (font-latex-string-face ((t (:foreground "#73c936")))) 98 | (font-latex-warning-face ((t (:foreground "#f43841")))) 99 | (font-latex-slide-title-face ((t (:foreground "#96a6c8")))) 100 | ))) 101 | 102 | (provide 'color-theme-gruber-darker) 103 | -------------------------------------------------------------------------------- /libs/dircolors/dircolors.el: -------------------------------------------------------------------------------- 1 | ;;; dircolors.el -- provide the same facility of ls --color inside emacs 2 | 3 | ;; Copyright (C) 2000 Padioleau yoann 4 | 5 | ;; This file is free software; you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation; either version 2, or (at your option) 8 | ;; any later version. 9 | 10 | ;; This file is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with GNU Emacs; see the file COPYING. If not, write to 17 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | ;; Boston, MA 02111-1307, USA. 19 | 20 | ;; Emacs Lisp Archive Entry 21 | ;; Filename: dircolors.el 22 | ;; Author: Padioleau Yoann 23 | ;; Version: 1.0 24 | 25 | ;;; Goal 26 | ; try to colorize the buffers of emacs as ls --color do in a terminal 27 | ; so if you try C-x b TAB or C-x C-f, you will see directory in blue 28 | ; c source file in yellow, object file in gray, .... 29 | ; it helps a lot to find the file you want to open 30 | 31 | ;;; Usage 32 | ; Add the following lines to ~/.emacs or an equivalent 33 | ; (require 'dircolors) 34 | ; you can customize this module by : 35 | ; - changing the colors of some faces for example with 36 | ; (set-face-foreground 'dircolors-face-asm "blue") 37 | ; - adding some faces/extension for example with 38 | ; (make-face 'myface-modula) 39 | ; (set-face-foreground 'myface-modula "yellow") 40 | ; (setq dircolors-extension (cons '(("mod" "md3") myface-modula) dircolors-extension) 41 | ; - make dircolors working for other emacs buffer 42 | ; (add-hook 'completion-list-mode-hook 'dircolors) 43 | 44 | 45 | 46 | ;;; Code 47 | 48 | ;; generic functions not included in emacs 49 | (defun join-string(xs &optional sep) 50 | (cond ((null xs) "") 51 | ((null (cdr xs)) (car xs)) 52 | (t (concat (car xs) (or sep " ") (join-string (cdr xs) sep))))) 53 | 54 | (defun map-apply(func xs) 55 | (mapcar #'(lambda (l)(apply func l)) xs)) 56 | 57 | (defmacro lam(args &rest body) `(lambda ,args ,@body)) 58 | 59 | ;; here start the real code 60 | (map-apply (lam (face color) 61 | (make-face face) (set-face-foreground face color)) 62 | '( 63 | (dircolors-face-dir "SkyBlue" ) 64 | (dircolors-face-doc "MediumTurquoise") 65 | (dircolors-face-html "Plum" ) 66 | (dircolors-face-package "IndianRed" ) 67 | (dircolors-face-tar "OrangeRed" ) 68 | (dircolors-face-dos "LimeGreen" ) 69 | (dircolors-face-sound "LightBlue" ) 70 | (dircolors-face-img "Salmon" ) 71 | (dircolors-face-ps "BlueViolet" ) 72 | (dircolors-face-backup "Magenta" ) 73 | (dircolors-face-make "Khaki" ) 74 | (dircolors-face-paddb "Orange" ) 75 | (dircolors-face-lang "Yellow" ) 76 | (dircolors-face-emacs "GreenYellow" ) 77 | (dircolors-face-lang-interface "Goldenrod" ) 78 | (dircolors-face-yacc "Coral" ) 79 | (dircolors-face-objet "DimGray" ) 80 | (dircolors-face-asm "Tan" ) 81 | (dircolors-face-compress "Sienna" ) 82 | )) 83 | 84 | (defvar dircolors-extension 85 | '((("txt" "doc" "tex" "texi" "man" 86 | (r "README") (r "readme") 87 | ) dircolors-face-doc) 88 | (("htm" "html" "html\\.gz" "htm\\.gz") 89 | dircolors-face-html) 90 | (("rpm" "deb" ) dircolors-face-package) 91 | (("tar" "tgz" "tar.gz" "tar.bz2" "zip" ) dircolors-face-tar) 92 | (("cmd" "exe" "com" "bat") dircolors-face-dos) 93 | (("mp3" "s3m" "mod" "au" "wav") dircolors-face-sound) 94 | (("jpg" "gif" "bmp" "xbm" "tif" 95 | "xpm" "jpeg" 96 | ) dircolors-face-img) 97 | (("ps" "pdf" "ps\\.gz" ) dircolors-face-ps) 98 | (("bak" "BAK" (r "\\.save")) dircolors-face-backup) 99 | (((r "akefile")) dircolors-face-make) 100 | (("db") dircolors-face-paddb) 101 | (("ml" 102 | "hs" "lhs" 103 | "scm" "sc" 104 | "p" "pas" 105 | "c" "cpp" "c\\+\\+" "cc" 106 | "pm" "pl" "m" 107 | "bet" 108 | ) dircolors-face-lang) 109 | (( "el" "emacs") dircolors-face-emacs) 110 | (("mli" 111 | "h" "hpp" "hh" 112 | ) dircolors-face-lang-interface) 113 | (("ly" "mly" "mll" 114 | "l" "y" 115 | "l\\+\\+" "y\\+\\+" 116 | "ll" "yy") dircolors-face-yacc) 117 | (("class" "o" ) dircolors-face-objet) 118 | (("asm" "s" "S" ) dircolors-face-asm) 119 | ; last because can conflict 120 | (("gz" ) dircolors-face-compress) 121 | ) 122 | "the syntax is (extension_list face), where extension can be either of the 123 | simple form string in which case it is interpreted as an extension 124 | for example \"txt\" will colorise all string that ends with .txt 125 | or can be of the form (r regexp)" 126 | ) 127 | 128 | 129 | 130 | (setq dircolors-font-lock-keywords 131 | (append 132 | '( 133 | ("\\w*/" . 'dircolors-face-dir); why this ` and 'tricks ?? 134 | ) 135 | (map-apply 136 | (lam (lext face) 137 | (cons (join-string 138 | (mapcar 139 | (lam (e) (if (stringp e) 140 | ; (concat "\\w\\(\\w\\|[_-]\\)*+\\." e "\\>") 141 | (concat "\\w*\\." e "\\>") 142 | (concat "\\w*" (cadr e) "\\w*\\>") ;regexp '(r "reg") 143 | )) lext) 144 | "\\|" 145 | ) (list 'quote face))) dircolors-extension))) 146 | 147 | (defun dircolors() 148 | (interactive) 149 | (make-local-variable 'font-lock-defaults) 150 | (make-local-variable 'lazy-lock-minimum-size) 151 | ; quite fast with this 152 | (setq lazy-lock-minimum-size 10) ;dont know why, but put this in global and all is slow 153 | (setq font-lock-defaults 154 | '(dircolors-font-lock-keywords 155 | t ; KEYWORDS-ONLY, dont want fontification of comment/strings ? 156 | nil ; CASE-FOLD 157 | ; SYNTAX-ALIST, say that _ is a word constituent 158 | ((?_ . "w") (?- . "w") (?+ . "w") (?. . "w")) 159 | )) 160 | (font-lock-mode 1)) 161 | 162 | ; if no font-lock-mode : but pb with read-only buffer, and with speed (lazy-mode is fast) 163 | ; (mapcar (lambda (x) 164 | ; (goto-char (point-min)) 165 | ; (while (re-search-forward (car x) (point-max) t) 166 | ; (progn 167 | ; (remove-text-properties (match-beginning 0) (match-end 0) '(face nil)) 168 | ; (add-text-properties (match-beginning 0) (match-end 0) 169 | ; (list 'face (car (cdr x)))) 170 | ; ) 171 | ; ) 172 | ; ) 173 | ; dircolors-font-lock-keywords) 174 | ; ) 175 | 176 | 177 | (add-hook 'completion-list-mode-hook 'dircolors) 178 | (add-hook 'buffer-menu-mode-hook 'dircolors) 179 | 180 | (provide 'dircolors) -------------------------------------------------------------------------------- /libs/golang/go-mode.el: -------------------------------------------------------------------------------- 1 | ;;; go-mode.el --- Major mode for the Go programming language 2 | 3 | ;; Copyright 2013 The Go Authors. All rights reserved. 4 | ;; Use of this source code is governed by a BSD-style 5 | ;; license that can be found in the LICENSE file. 6 | 7 | (require 'cl) 8 | (require 'ffap) 9 | (require 'url) 10 | 11 | ;; XEmacs compatibility guidelines 12 | ;; - Minimum required version of XEmacs: 21.5.32 13 | ;; - Feature that cannot be backported: POSIX character classes in 14 | ;; regular expressions 15 | ;; - Functions that could be backported but won't because 21.5.32 16 | ;; covers them: plenty. 17 | ;; - Features that are still partly broken: 18 | ;; - godef will not work correctly if multibyte characters are 19 | ;; being used 20 | ;; - Fontification will not handle unicode correctly 21 | ;; 22 | ;; - Do not use \_< and \_> regexp delimiters directly; use 23 | ;; go--regexp-enclose-in-symbol 24 | ;; 25 | ;; - The character `_` must not be a symbol constituent but a 26 | ;; character constituent 27 | ;; 28 | ;; - Do not use process-lines 29 | ;; 30 | ;; - Use go--old-completion-list-style when using a plain list as the 31 | ;; collection for completing-read 32 | ;; 33 | ;; - Use go--kill-whole-line instead of kill-whole-line (called 34 | ;; kill-entire-line in XEmacs) 35 | ;; 36 | ;; - Use go--position-bytes instead of position-bytes 37 | (defmacro go--xemacs-p () 38 | `(featurep 'xemacs)) 39 | 40 | (defalias 'go--kill-whole-line 41 | (if (fboundp 'kill-whole-line) 42 | 'kill-whole-line 43 | 'kill-entire-line)) 44 | 45 | ;; XEmacs unfortunately does not offer position-bytes. We can fall 46 | ;; back to just using (point), but it will be incorrect as soon as 47 | ;; multibyte characters are being used. 48 | (if (fboundp 'position-bytes) 49 | (defalias 'go--position-bytes 'position-bytes) 50 | (defun go--position-bytes (point) point)) 51 | 52 | (defun go--old-completion-list-style (list) 53 | (mapcar (lambda (x) (cons x nil)) list)) 54 | 55 | ;; GNU Emacs 24 has prog-mode, older GNU Emacs and XEmacs do not. 56 | ;; Ideally we'd use defalias instead, but that breaks in XEmacs. 57 | ;; 58 | ;; TODO: If XEmacs decides to add prog-mode, change this to use 59 | ;; defalias to alias prog-mode or fundamental-mode to go--prog-mode 60 | ;; and use that in define-derived-mode. 61 | (if (not (fboundp 'prog-mode)) 62 | (define-derived-mode prog-mode fundamental-mode "" "")) 63 | 64 | (defun go--regexp-enclose-in-symbol (s) 65 | ;; XEmacs does not support \_<, GNU Emacs does. In GNU Emacs we make 66 | ;; extensive use of \_< to support unicode in identifiers. Until we 67 | ;; come up with a better solution for XEmacs, this solution will 68 | ;; break fontification in XEmacs for identifiers such as "typeµ". 69 | ;; XEmacs will consider "type" a keyword, GNU Emacs won't. 70 | 71 | (if (go--xemacs-p) 72 | (concat "\\<" s "\\>") 73 | (concat "\\_<" s "\\_>"))) 74 | 75 | (defconst go-dangling-operators-regexp "[^-]-\\|[^+]\\+\\|[/*&><.=|^]") 76 | (defconst go-identifier-regexp "[[:word:][:multibyte:]]+") 77 | (defconst go-label-regexp go-identifier-regexp) 78 | (defconst go-type-regexp "[[:word:][:multibyte:]*]+") 79 | (defconst go-func-regexp (concat (go--regexp-enclose-in-symbol "func") "\\s *\\(" go-identifier-regexp "\\)")) 80 | (defconst go-func-meth-regexp (concat (go--regexp-enclose-in-symbol "func") "\\s *\\(?:(\\s *" go-identifier-regexp "\\s +" go-type-regexp "\\s *)\\s *\\)?\\(" go-identifier-regexp "\\)(")) 81 | (defconst go-builtins 82 | '("append" "cap" "close" "complex" "copy" 83 | "delete" "imag" "len" "make" "new" 84 | "panic" "print" "println" "real" "recover") 85 | "All built-in functions in the Go language. Used for font locking.") 86 | 87 | (defconst go-mode-keywords 88 | '("break" "default" "func" "interface" "select" 89 | "case" "defer" "go" "map" "struct" 90 | "chan" "else" "goto" "package" "switch" 91 | "const" "fallthrough" "if" "range" "type" 92 | "continue" "for" "import" "return" "var") 93 | "All keywords in the Go language. Used for font locking.") 94 | 95 | (defconst go-constants '("nil" "true" "false" "iota")) 96 | (defconst go-type-name-regexp (concat "\\(?:[*(]\\)*\\(?:" go-identifier-regexp "\\.\\)?\\(" go-identifier-regexp "\\)")) 97 | 98 | (defvar go-dangling-cache) 99 | (defvar go-godoc-history nil) 100 | 101 | (defgroup go nil 102 | "Major mode for editing Go code" 103 | :group 'languages) 104 | 105 | (defcustom go-fontify-function-calls t 106 | "Fontify function and method calls if this is non-nil." 107 | :type 'boolean 108 | :group 'go) 109 | 110 | (defvar go-mode-syntax-table 111 | (let ((st (make-syntax-table))) 112 | (modify-syntax-entry ?+ "." st) 113 | (modify-syntax-entry ?- "." st) 114 | (modify-syntax-entry ?% "." st) 115 | (modify-syntax-entry ?& "." st) 116 | (modify-syntax-entry ?| "." st) 117 | (modify-syntax-entry ?^ "." st) 118 | (modify-syntax-entry ?! "." st) 119 | (modify-syntax-entry ?= "." st) 120 | (modify-syntax-entry ?< "." st) 121 | (modify-syntax-entry ?> "." st) 122 | (modify-syntax-entry ?/ (if (go--xemacs-p) ". 1456" ". 124b") st) 123 | (modify-syntax-entry ?* ". 23" st) 124 | (modify-syntax-entry ?\n "> b" st) 125 | (modify-syntax-entry ?\" "\"" st) 126 | (modify-syntax-entry ?\' "\"" st) 127 | (modify-syntax-entry ?` "\"" st) 128 | (modify-syntax-entry ?\\ "\\" st) 129 | ;; It would be nicer to have _ as a symbol constituent, but that 130 | ;; would trip up XEmacs, which does not support the \_< anchor 131 | (modify-syntax-entry ?_ "w" st) 132 | 133 | st) 134 | "Syntax table for Go mode.") 135 | 136 | (defun go--build-font-lock-keywords () 137 | ;; we cannot use 'symbols in regexp-opt because emacs <24 doesn't 138 | ;; understand that 139 | (append 140 | `((,(go--regexp-enclose-in-symbol (regexp-opt go-mode-keywords t)) . font-lock-keyword-face) 141 | (,(go--regexp-enclose-in-symbol (regexp-opt go-builtins t)) . font-lock-builtin-face) 142 | (,(go--regexp-enclose-in-symbol (regexp-opt go-constants t)) . font-lock-constant-face) 143 | (,go-func-regexp 1 font-lock-function-name-face)) ;; function (not method) name 144 | 145 | (if go-fontify-function-calls 146 | `((,(concat "\\(" go-identifier-regexp "\\)[[:space:]]*(") 1 font-lock-function-name-face) ;; function call/method name 147 | (,(concat "(\\(" go-identifier-regexp "\\))[[:space:]]*(") 1 font-lock-function-name-face)) ;; bracketed function call 148 | `((,go-func-meth-regexp 1 font-lock-function-name-face))) ;; method name 149 | 150 | `( 151 | (,(concat (go--regexp-enclose-in-symbol "type") "[[:space:]]*\\([^[:space:]]+\\)") 1 font-lock-type-face) ;; types 152 | (,(concat (go--regexp-enclose-in-symbol "type") "[[:space:]]*" go-identifier-regexp "[[:space:]]*" go-type-name-regexp) 1 font-lock-type-face) ;; types 153 | (,(concat "[^[:word:][:multibyte:]]\\[\\([[:digit:]]+\\|\\.\\.\\.\\)?\\]" go-type-name-regexp) 2 font-lock-type-face) ;; Arrays/slices 154 | (,(concat "\\(" go-identifier-regexp "\\)" "{") 1 font-lock-type-face) 155 | (,(concat (go--regexp-enclose-in-symbol "map") "\\[[^]]+\\]" go-type-name-regexp) 1 font-lock-type-face) ;; map value type 156 | (,(concat (go--regexp-enclose-in-symbol "map") "\\[" go-type-name-regexp) 1 font-lock-type-face) ;; map key type 157 | (,(concat (go--regexp-enclose-in-symbol "chan") "[[:space:]]*\\(?:<-\\)?" go-type-name-regexp) 1 font-lock-type-face) ;; channel type 158 | (,(concat (go--regexp-enclose-in-symbol "\\(?:new\\|make\\)") "\\(?:[[:space:]]\\|)\\)*(" go-type-name-regexp) 1 font-lock-type-face) ;; new/make type 159 | ;; TODO do we actually need this one or isn't it just a function call? 160 | (,(concat "\\.\\s *(" go-type-name-regexp) 1 font-lock-type-face) ;; Type conversion 161 | (,(concat (go--regexp-enclose-in-symbol "func") "[[:space:]]+(" go-identifier-regexp "[[:space:]]+" go-type-name-regexp ")") 1 font-lock-type-face) ;; Method receiver 162 | ;; Like the original go-mode this also marks compound literal 163 | ;; fields. There, it was marked as to fix, but I grew quite 164 | ;; accustomed to it, so it'll stay for now. 165 | (,(concat "^[[:space:]]*\\(" go-label-regexp "\\)[[:space:]]*:\\(\\S.\\|$\\)") 1 font-lock-constant-face) ;; Labels and compound literal fields 166 | (,(concat (go--regexp-enclose-in-symbol "\\(goto\\|break\\|continue\\)") "[[:space:]]*\\(" go-label-regexp "\\)") 2 font-lock-constant-face)))) ;; labels in goto/break/continue 167 | 168 | (defvar go-mode-map 169 | (let ((m (make-sparse-keymap))) 170 | (define-key m "}" 'go-mode-insert-and-indent) 171 | (define-key m ")" 'go-mode-insert-and-indent) 172 | (define-key m "," 'go-mode-insert-and-indent) 173 | (define-key m ":" 'go-mode-insert-and-indent) 174 | (define-key m "=" 'go-mode-insert-and-indent) 175 | (define-key m (kbd "C-c C-a") 'go-import-add) 176 | (define-key m (kbd "C-c C-j") 'godef-jump) 177 | (define-key m (kbd "C-c C-d") 'godef-describe) 178 | m) 179 | "Keymap used by Go mode to implement electric keys.") 180 | 181 | (defun go-mode-insert-and-indent (key) 182 | "Invoke the global binding of KEY, then reindent the line." 183 | 184 | (interactive (list (this-command-keys))) 185 | (call-interactively (lookup-key (current-global-map) key)) 186 | (indent-according-to-mode)) 187 | 188 | (defmacro go-paren-level () 189 | `(car (syntax-ppss))) 190 | 191 | (defmacro go-in-string-or-comment-p () 192 | `(nth 8 (syntax-ppss))) 193 | 194 | (defmacro go-in-string-p () 195 | `(nth 3 (syntax-ppss))) 196 | 197 | (defmacro go-in-comment-p () 198 | `(nth 4 (syntax-ppss))) 199 | 200 | (defmacro go-goto-beginning-of-string-or-comment () 201 | `(goto-char (nth 8 (syntax-ppss)))) 202 | 203 | (defun go--backward-irrelevant (&optional stop-at-string) 204 | "Skips backwards over any characters that are irrelevant for 205 | indentation and related tasks. 206 | 207 | It skips over whitespace, comments, cases and labels and, if 208 | STOP-AT-STRING is not true, over strings." 209 | 210 | (let (pos (start-pos (point))) 211 | (skip-chars-backward "\n\s\t") 212 | (if (and (save-excursion (beginning-of-line) (go-in-string-p)) (looking-back "`") (not stop-at-string)) 213 | (backward-char)) 214 | (if (and (go-in-string-p) (not stop-at-string)) 215 | (go-goto-beginning-of-string-or-comment)) 216 | (if (looking-back "\\*/") 217 | (backward-char)) 218 | (if (go-in-comment-p) 219 | (go-goto-beginning-of-string-or-comment)) 220 | (setq pos (point)) 221 | (beginning-of-line) 222 | (if (or (looking-at (concat "^" go-label-regexp ":")) (looking-at "^[[:space:]]*\\(case .+\\|default\\):")) 223 | (end-of-line 0) 224 | (goto-char pos)) 225 | (if (/= start-pos (point)) 226 | (go--backward-irrelevant stop-at-string)) 227 | (/= start-pos (point)))) 228 | 229 | (defun go--buffer-narrowed-p () 230 | "Return non-nil if the current buffer is narrowed." 231 | (/= (buffer-size) 232 | (- (point-max) 233 | (point-min)))) 234 | 235 | (defun go-previous-line-has-dangling-op-p () 236 | "Returns non-nil if the current line is a continuation line." 237 | (let* ((cur-line (line-number-at-pos)) 238 | (val (gethash cur-line go-dangling-cache 'nope))) 239 | (if (or (go--buffer-narrowed-p) (equal val 'nope)) 240 | (save-excursion 241 | (beginning-of-line) 242 | (go--backward-irrelevant t) 243 | (setq val (looking-back go-dangling-operators-regexp)) 244 | (if (not (go--buffer-narrowed-p)) 245 | (puthash cur-line val go-dangling-cache)))) 246 | val)) 247 | 248 | (defun go--at-function-definition () 249 | "Return non-nil if point is on the opening curly brace of a 250 | function definition. 251 | 252 | We do this by first calling (beginning-of-defun), which will take 253 | us to the start of *some* function. We then look for the opening 254 | curly brace of that function and compare its position against the 255 | curly brace we are checking. If they match, we return non-nil." 256 | (if (= (char-after) ?\{) 257 | (save-excursion 258 | (let ((old-point (point)) 259 | start-nesting) 260 | (beginning-of-defun) 261 | (when (looking-at "func ") 262 | (setq start-nesting (go-paren-level)) 263 | (skip-chars-forward "^{") 264 | (while (> (go-paren-level) start-nesting) 265 | (forward-char) 266 | (skip-chars-forward "^{") 0) 267 | (if (and (= (go-paren-level) start-nesting) (= old-point (point))) 268 | t)))))) 269 | 270 | (defun go-goto-opening-parenthesis (&optional char) 271 | (let ((start-nesting (go-paren-level))) 272 | (while (and (not (bobp)) 273 | (>= (go-paren-level) start-nesting)) 274 | (if (zerop (skip-chars-backward 275 | (if char 276 | (case char (?\] "^[") (?\} "^{") (?\) "^(")) 277 | "^[{("))) 278 | (if (go-in-string-or-comment-p) 279 | (go-goto-beginning-of-string-or-comment) 280 | (backward-char)))))) 281 | 282 | (defun go--indentation-for-opening-parenthesis () 283 | "Return the semantic indentation for the current opening parenthesis. 284 | 285 | If point is on an opening curly brace and said curly brace 286 | belongs to a function declaration, the indentation of the func 287 | keyword will be returned. Otherwise the indentation of the 288 | current line will be returned." 289 | (save-excursion 290 | (if (go--at-function-definition) 291 | (progn 292 | (beginning-of-defun) 293 | (current-indentation)) 294 | (current-indentation)))) 295 | 296 | (defun go-indentation-at-point () 297 | (save-excursion 298 | (let (start-nesting (outindent 0)) 299 | (back-to-indentation) 300 | (setq start-nesting (go-paren-level)) 301 | 302 | (cond 303 | ((go-in-string-p) 304 | (current-indentation)) 305 | ((looking-at "[])}]") 306 | (go-goto-opening-parenthesis (char-after)) 307 | (if (go-previous-line-has-dangling-op-p) 308 | (- (current-indentation) tab-width) 309 | (go--indentation-for-opening-parenthesis))) 310 | ((progn (go--backward-irrelevant t) (looking-back go-dangling-operators-regexp)) 311 | ;; only one nesting for all dangling operators in one operation 312 | (if (go-previous-line-has-dangling-op-p) 313 | (current-indentation) 314 | (+ (current-indentation) tab-width))) 315 | ((zerop (go-paren-level)) 316 | 0) 317 | ((progn (go-goto-opening-parenthesis) (< (go-paren-level) start-nesting)) 318 | (if (go-previous-line-has-dangling-op-p) 319 | (current-indentation) 320 | (+ (go--indentation-for-opening-parenthesis) tab-width))) 321 | (t 322 | (current-indentation)))))) 323 | 324 | (defun go-mode-indent-line () 325 | (interactive) 326 | (let (indent 327 | shift-amt 328 | end 329 | (pos (- (point-max) (point))) 330 | (point (point)) 331 | (beg (line-beginning-position))) 332 | (back-to-indentation) 333 | (if (go-in-string-or-comment-p) 334 | (goto-char point) 335 | (setq indent (go-indentation-at-point)) 336 | (if (looking-at (concat go-label-regexp ":\\([[:space:]]*/.+\\)?$\\|case .+:\\|default:")) 337 | (decf indent tab-width)) 338 | (setq shift-amt (- indent (current-column))) 339 | (if (zerop shift-amt) 340 | nil 341 | (delete-region beg (point)) 342 | (indent-to indent)) 343 | ;; If initial point was within line's indentation, 344 | ;; position after the indentation. Else stay at same point in text. 345 | (if (> (- (point-max) pos) (point)) 346 | (goto-char (- (point-max) pos)))))) 347 | 348 | (defun go-beginning-of-defun (&optional count) 349 | (unless count (setq count 1)) 350 | (let ((first t) failure) 351 | (dotimes (i (abs count)) 352 | (while (and (not failure) 353 | (or first (go-in-string-or-comment-p))) 354 | (if (>= count 0) 355 | (progn 356 | (go--backward-irrelevant) 357 | (if (not (re-search-backward go-func-meth-regexp nil t)) 358 | (setq failure t))) 359 | (if (looking-at go-func-meth-regexp) 360 | (forward-char)) 361 | (if (not (re-search-forward go-func-meth-regexp nil t)) 362 | (setq failure t))) 363 | (setq first nil))) 364 | (if (< count 0) 365 | (beginning-of-line)) 366 | (not failure))) 367 | 368 | (defun go-end-of-defun () 369 | (let (orig-level) 370 | ;; It can happen that we're not placed before a function by emacs 371 | (if (not (looking-at "func")) 372 | (go-beginning-of-defun -1)) 373 | (skip-chars-forward "^{") 374 | (forward-char) 375 | (setq orig-level (go-paren-level)) 376 | (while (>= (go-paren-level) orig-level) 377 | (skip-chars-forward "^}") 378 | (forward-char)))) 379 | 380 | ;;;###autoload 381 | (define-derived-mode go-mode prog-mode "Go" 382 | "Major mode for editing Go source text. 383 | 384 | This mode provides (not just) basic editing capabilities for 385 | working with Go code. It offers almost complete syntax 386 | highlighting, indentation that is almost identical to gofmt and 387 | proper parsing of the buffer content to allow features such as 388 | navigation by function, manipulation of comments or detection of 389 | strings. 390 | 391 | In addition to these core features, it offers various features to 392 | help with writing Go code. You can directly run buffer content 393 | through gofmt, read godoc documentation from within Emacs, modify 394 | and clean up the list of package imports or interact with the 395 | Playground (uploading and downloading pastes). 396 | 397 | The following extra functions are defined: 398 | 399 | - `gofmt' 400 | - `godoc' 401 | - `go-import-add' 402 | - `go-remove-unused-imports' 403 | - `go-goto-imports' 404 | - `go-play-buffer' and `go-play-region' 405 | - `go-download-play' 406 | - `godef-describe' and `godef-jump' 407 | 408 | If you want to automatically run `gofmt' before saving a file, 409 | add the following hook to your emacs configuration: 410 | 411 | \(add-hook 'before-save-hook 'gofmt-before-save) 412 | 413 | If you want to use `godef-jump' instead of etags (or similar), 414 | consider binding godef-jump to `M-.', which is the default key 415 | for `find-tag': 416 | 417 | \(add-hook 'go-mode-hook (lambda () 418 | (local-set-key (kbd \"M-.\") 'godef-jump))) 419 | 420 | Please note that godef is an external dependency. You can install 421 | it with 422 | 423 | go get code.google.com/p/rog-go/exp/cmd/godef 424 | 425 | 426 | If you're looking for even more integration with Go, namely 427 | on-the-fly syntax checking, auto-completion and snippets, it is 428 | recommended that you look at goflymake 429 | \(https://github.com/dougm/goflymake), gocode 430 | \(https://github.com/nsf/gocode) and yasnippet-go 431 | \(https://github.com/dominikh/yasnippet-go)" 432 | 433 | ;; Font lock 434 | (set (make-local-variable 'font-lock-defaults) 435 | '(go--build-font-lock-keywords)) 436 | 437 | ;; Indentation 438 | (set (make-local-variable 'indent-line-function) 'go-mode-indent-line) 439 | 440 | ;; Comments 441 | (set (make-local-variable 'comment-start) "// ") 442 | (set (make-local-variable 'comment-end) "") 443 | (set (make-local-variable 'comment-use-syntax) t) 444 | (set (make-local-variable 'comment-start-skip) "\\(//+\\|/\\*+\\)\\s *") 445 | 446 | (set (make-local-variable 'beginning-of-defun-function) 'go-beginning-of-defun) 447 | (set (make-local-variable 'end-of-defun-function) 'go-end-of-defun) 448 | 449 | (set (make-local-variable 'parse-sexp-lookup-properties) t) 450 | (if (boundp 'syntax-propertize-function) 451 | (set (make-local-variable 'syntax-propertize-function) 'go-propertize-syntax)) 452 | 453 | (set (make-local-variable 'go-dangling-cache) (make-hash-table :test 'eql)) 454 | (add-hook 'before-change-functions (lambda (x y) (setq go-dangling-cache (make-hash-table :test 'eql))) t t) 455 | 456 | 457 | (setq imenu-generic-expression 458 | '(("type" "^type *\\([^ \t\n\r\f]*\\)" 1) 459 | ("func" "^func *\\(.*\\) {" 1))) 460 | (imenu-add-to-menubar "Index") 461 | 462 | ;; Go style 463 | (setq indent-tabs-mode t) 464 | 465 | ;; Handle unit test failure output in compilation-mode 466 | ;; 467 | ;; Note the final t argument to add-to-list for append, ie put these at the 468 | ;; *ends* of compilation-error-regexp-alist[-alist]. We want go-test to be 469 | ;; handled first, otherwise other elements will match that don't work, and 470 | ;; those alists are traversed in *reverse* order: 471 | ;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2001-12/msg00674.html 472 | (when (and (boundp 'compilation-error-regexp-alist) 473 | (boundp 'compilation-error-regexp-alist-alist)) 474 | (add-to-list 'compilation-error-regexp-alist 'go-test t) 475 | (add-to-list 'compilation-error-regexp-alist-alist 476 | '(go-test . ("^\t+\\([^()\t\n]+\\):\\([0-9]+\\):? .*$" 1 2)) t))) 477 | 478 | ;;;###autoload 479 | (add-to-list 'auto-mode-alist (cons "\\.go\\'" 'go-mode)) 480 | 481 | (defun go--apply-rcs-patch (patch-buffer) 482 | "Apply an RCS-formatted diff from PATCH-BUFFER to the current 483 | buffer." 484 | (let ((target-buffer (current-buffer)) 485 | ;; Relative offset between buffer line numbers and line numbers 486 | ;; in patch. 487 | ;; 488 | ;; Line numbers in the patch are based on the source file, so 489 | ;; we have to keep an offset when making changes to the 490 | ;; buffer. 491 | ;; 492 | ;; Appending lines decrements the offset (possibly making it 493 | ;; negative), deleting lines increments it. This order 494 | ;; simplifies the forward-line invocations. 495 | (line-offset 0)) 496 | (save-excursion 497 | (with-current-buffer patch-buffer 498 | (goto-char (point-min)) 499 | (while (not (eobp)) 500 | (unless (looking-at "^\\([ad]\\)\\([0-9]+\\) \\([0-9]+\\)") 501 | (error "invalid rcs patch or internal error in go--apply-rcs-patch")) 502 | (forward-line) 503 | (let ((action (match-string 1)) 504 | (from (string-to-number (match-string 2))) 505 | (len (string-to-number (match-string 3)))) 506 | (cond 507 | ((equal action "a") 508 | (let ((start (point))) 509 | (forward-line len) 510 | (let ((text (buffer-substring start (point)))) 511 | (with-current-buffer target-buffer 512 | (decf line-offset len) 513 | (goto-char (point-min)) 514 | (forward-line (- from len line-offset)) 515 | (insert text))))) 516 | ((equal action "d") 517 | (with-current-buffer target-buffer 518 | (goto-char (point-min)) 519 | (forward-line (- from line-offset 1)) 520 | (incf line-offset len) 521 | (go--kill-whole-line len))) 522 | (t 523 | (error "invalid rcs patch or internal error in go--apply-rcs-patch"))))))))) 524 | 525 | (defun gofmt () 526 | "Formats the current buffer according to the gofmt tool." 527 | 528 | (interactive) 529 | (let ((tmpfile (make-temp-file "gofmt" nil ".go")) 530 | (patchbuf (get-buffer-create "*Gofmt patch*")) 531 | (errbuf (get-buffer-create "*Gofmt Errors*")) 532 | (coding-system-for-read 'utf-8) 533 | (coding-system-for-write 'utf-8)) 534 | 535 | (with-current-buffer errbuf 536 | (setq buffer-read-only nil) 537 | (erase-buffer)) 538 | (with-current-buffer patchbuf 539 | (erase-buffer)) 540 | 541 | (write-region nil nil tmpfile) 542 | 543 | ;; We're using errbuf for the mixed stdout and stderr output. This 544 | ;; is not an issue because gofmt -w does not produce any stdout 545 | ;; output in case of success. 546 | (if (zerop (call-process "gofmt" nil errbuf nil "-w" tmpfile)) 547 | (if (zerop (call-process-region (point-min) (point-max) "diff" nil patchbuf nil "-n" "-" tmpfile)) 548 | (progn 549 | (kill-buffer errbuf) 550 | (message "Buffer is already gofmted")) 551 | (go--apply-rcs-patch patchbuf) 552 | (kill-buffer errbuf) 553 | (message "Applied gofmt")) 554 | (message "Could not apply gofmt. Check errors for details") 555 | (gofmt--process-errors (buffer-file-name) tmpfile errbuf)) 556 | 557 | (kill-buffer patchbuf) 558 | (delete-file tmpfile))) 559 | 560 | 561 | (defun gofmt--process-errors (filename tmpfile errbuf) 562 | ;; Convert the gofmt stderr to something understood by the compilation mode. 563 | (with-current-buffer errbuf 564 | (goto-char (point-min)) 565 | (insert "gofmt errors:\n") 566 | (while (search-forward-regexp (concat "^\\(" (regexp-quote tmpfile) "\\):") nil t) 567 | (replace-match (file-name-nondirectory filename) t t nil 1)) 568 | (compilation-mode) 569 | (display-buffer errbuf))) 570 | 571 | ;;;###autoload 572 | (defun gofmt-before-save () 573 | "Add this to .emacs to run gofmt on the current buffer when saving: 574 | (add-hook 'before-save-hook 'gofmt-before-save). 575 | 576 | Note that this will cause go-mode to get loaded the first time 577 | you save any file, kind of defeating the point of autoloading." 578 | 579 | (interactive) 580 | (when (eq major-mode 'go-mode) (gofmt))) 581 | 582 | (defun godoc--read-query () 583 | "Read a godoc query from the minibuffer." 584 | ;; Compute the default query as the symbol under the cursor. 585 | ;; TODO: This does the wrong thing for e.g. multipart.NewReader (it only grabs 586 | ;; half) but I see no way to disambiguate that from e.g. foobar.SomeMethod. 587 | (let* ((bounds (bounds-of-thing-at-point 'symbol)) 588 | (symbol (if bounds 589 | (buffer-substring-no-properties (car bounds) 590 | (cdr bounds))))) 591 | (completing-read (if symbol 592 | (format "godoc (default %s): " symbol) 593 | "godoc: ") 594 | (go--old-completion-list-style (go-packages)) nil nil nil 'go-godoc-history symbol))) 595 | 596 | (defun godoc--get-buffer (query) 597 | "Get an empty buffer for a godoc query." 598 | (let* ((buffer-name (concat "*godoc " query "*")) 599 | (buffer (get-buffer buffer-name))) 600 | ;; Kill the existing buffer if it already exists. 601 | (when buffer (kill-buffer buffer)) 602 | (get-buffer-create buffer-name))) 603 | 604 | (defun godoc--buffer-sentinel (proc event) 605 | "Sentinel function run when godoc command completes." 606 | (with-current-buffer (process-buffer proc) 607 | (cond ((string= event "finished\n") ;; Successful exit. 608 | (goto-char (point-min)) 609 | (view-mode 1) 610 | (display-buffer (current-buffer) t)) 611 | ((/= (process-exit-status proc) 0) ;; Error exit. 612 | (let ((output (buffer-string))) 613 | (kill-buffer (current-buffer)) 614 | (message (concat "godoc: " output))))))) 615 | 616 | ;;;###autoload 617 | (defun godoc (query) 618 | "Show go documentation for a query, much like M-x man." 619 | (interactive (list (godoc--read-query))) 620 | (unless (string= query "") 621 | (set-process-sentinel 622 | (start-process-shell-command "godoc" (godoc--get-buffer query) 623 | (concat "godoc " query)) 624 | 'godoc--buffer-sentinel) 625 | nil)) 626 | 627 | (defun go-goto-imports () 628 | "Move point to the block of imports. 629 | 630 | If using 631 | 632 | import ( 633 | \"foo\" 634 | \"bar\" 635 | ) 636 | 637 | it will move point directly behind the last import. 638 | 639 | If using 640 | 641 | import \"foo\" 642 | import \"bar\" 643 | 644 | it will move point to the next line after the last import. 645 | 646 | If no imports can be found, point will be moved after the package 647 | declaration." 648 | (interactive) 649 | ;; FIXME if there's a block-commented import before the real 650 | ;; imports, we'll jump to that one. 651 | 652 | ;; Generally, this function isn't very forgiving. it'll bark on 653 | ;; extra whitespace. It works well for clean code. 654 | (let ((old-point (point))) 655 | (goto-char (point-min)) 656 | (cond 657 | ((re-search-forward "^import ([^)]+)" nil t) 658 | (backward-char 2) 659 | 'block) 660 | ((re-search-forward "\\(^import \\([^\"]+ \\)?\"[^\"]+\"\n?\\)+" nil t) 661 | 'single) 662 | ((re-search-forward "^[[:space:]\n]*package .+?\n" nil t) 663 | (message "No imports found, moving point after package declaration") 664 | 'none) 665 | (t 666 | (goto-char old-point) 667 | (message "No imports or package declaration found. Is this really a Go file?") 668 | 'fail)))) 669 | 670 | (defun go-play-buffer () 671 | "Like `go-play-region', but acts on the entire buffer." 672 | (interactive) 673 | (go-play-region (point-min) (point-max))) 674 | 675 | (defun go-play-region (start end) 676 | "Send the region to the Playground and stores the resulting 677 | link in the kill ring." 678 | (interactive "r") 679 | (let* ((url-request-method "POST") 680 | (url-request-extra-headers 681 | '(("Content-Type" . "application/x-www-form-urlencoded"))) 682 | (url-request-data (buffer-substring-no-properties start end)) 683 | (content-buf (url-retrieve 684 | "http://play.golang.org/share" 685 | (lambda (arg) 686 | (cond 687 | ((equal :error (car arg)) 688 | (signal 'go-play-error (cdr arg))) 689 | (t 690 | (re-search-forward "\n\n") 691 | (kill-new (format "http://play.golang.org/p/%s" (buffer-substring (point) (point-max)))) 692 | (message "http://play.golang.org/p/%s" (buffer-substring (point) (point-max))))))))))) 693 | 694 | ;;;###autoload 695 | (defun go-download-play (url) 696 | "Downloads a paste from the playground and inserts it in a Go 697 | buffer. Tries to look for a URL at point." 698 | (interactive (list (read-from-minibuffer "Playground URL: " (ffap-url-p (ffap-string-at-point 'url))))) 699 | (with-current-buffer 700 | (let ((url-request-method "GET") url-request-data url-request-extra-headers) 701 | (url-retrieve-synchronously (concat url ".go"))) 702 | (let ((buffer (generate-new-buffer (concat (car (last (split-string url "/"))) ".go")))) 703 | (goto-char (point-min)) 704 | (re-search-forward "\n\n") 705 | (copy-to-buffer buffer (point) (point-max)) 706 | (kill-buffer) 707 | (with-current-buffer buffer 708 | (go-mode) 709 | (switch-to-buffer buffer))))) 710 | 711 | (defun go-propertize-syntax (start end) 712 | (save-excursion 713 | (goto-char start) 714 | (while (search-forward "\\" end t) 715 | (put-text-property (1- (point)) (point) 'syntax-table (if (= (char-after) ?`) '(1) '(9)))))) 716 | 717 | ;; ;; Commented until we actually make use of this function 718 | ;; (defun go--common-prefix (sequences) 719 | ;; ;; mismatch and reduce are cl 720 | ;; (assert sequences) 721 | ;; (flet ((common-prefix (s1 s2) 722 | ;; (let ((diff-pos (mismatch s1 s2))) 723 | ;; (if diff-pos (subseq s1 0 diff-pos) s1)))) 724 | ;; (reduce #'common-prefix sequences))) 725 | 726 | (defun go-import-add (arg import) 727 | "Add a new import to the list of imports. 728 | 729 | When called with a prefix argument asks for an alternative name 730 | to import the package as. 731 | 732 | If no list exists yet, one will be created if possible. 733 | 734 | If an identical import has been commented, it will be 735 | uncommented, otherwise a new import will be added." 736 | 737 | ;; - If there's a matching `// import "foo"`, uncomment it 738 | ;; - If we're in an import() block and there's a matching `"foo"`, uncomment it 739 | ;; - Otherwise add a new import, with the appropriate syntax 740 | (interactive 741 | (list 742 | current-prefix-arg 743 | (replace-regexp-in-string "^[\"']\\|[\"']$" "" (completing-read "Package: " (go--old-completion-list-style (go-packages)))))) 744 | (save-excursion 745 | (let (as line import-start) 746 | (if arg 747 | (setq as (read-from-minibuffer "Import as: "))) 748 | (if as 749 | (setq line (format "%s \"%s\"" as import)) 750 | (setq line (format "\"%s\"" import))) 751 | 752 | (goto-char (point-min)) 753 | (if (re-search-forward (concat "^[[:space:]]*//[[:space:]]*import " line "$") nil t) 754 | (uncomment-region (line-beginning-position) (line-end-position)) 755 | (case (go-goto-imports) 756 | ('fail (message "Could not find a place to add import.")) 757 | ('block 758 | (save-excursion 759 | (re-search-backward "^import (") 760 | (setq import-start (point))) 761 | (if (re-search-backward (concat "^[[:space:]]*//[[:space:]]*" line "$") import-start t) 762 | (uncomment-region (line-beginning-position) (line-end-position)) 763 | (insert "\n\t" line))) 764 | ('single (insert "import " line "\n")) 765 | ('none (insert "\nimport (\n\t" line "\n)\n"))))))) 766 | 767 | (defun go-root-and-paths () 768 | (let* ((output (split-string (shell-command-to-string "go env GOROOT GOPATH") "\n")) 769 | (root (car output)) 770 | (paths (split-string (cadr output) ":"))) 771 | (append (list root) paths))) 772 | 773 | (defun go--string-prefix-p (s1 s2 &optional ignore-case) 774 | "Return non-nil if S1 is a prefix of S2. 775 | If IGNORE-CASE is non-nil, the comparison is case-insensitive." 776 | (eq t (compare-strings s1 nil nil 777 | s2 0 (length s1) ignore-case))) 778 | 779 | (defun go--directory-dirs (dir) 780 | "Recursively return all subdirectories in DIR." 781 | (if (file-directory-p dir) 782 | (let ((dir (directory-file-name dir)) 783 | (dirs '()) 784 | (files (directory-files dir nil nil t))) 785 | (dolist (file files) 786 | (unless (member file '("." "..")) 787 | (let ((file (concat dir "/" file))) 788 | (if (file-directory-p file) 789 | (setq dirs (append (cons file 790 | (go--directory-dirs file)) 791 | dirs)))))) 792 | dirs) 793 | '())) 794 | 795 | 796 | (defun go-packages () 797 | (sort 798 | (delete-dups 799 | (mapcan 800 | (lambda (topdir) 801 | (let ((pkgdir (concat topdir "/pkg/"))) 802 | (mapcan (lambda (dir) 803 | (mapcar (lambda (file) 804 | (let ((sub (substring file (length pkgdir) -2))) 805 | (unless (or (go--string-prefix-p "obj/" sub) (go--string-prefix-p "tool/" sub)) 806 | (mapconcat 'identity (cdr (split-string sub "/")) "/")))) 807 | (if (file-directory-p dir) 808 | (directory-files dir t "\\.a$")))) 809 | (if (file-directory-p pkgdir) 810 | (go--directory-dirs pkgdir))))) 811 | (go-root-and-paths))) 812 | 'string<)) 813 | 814 | (defun go-unused-imports-lines () 815 | ;; FIXME Technically, -o /dev/null fails in quite some cases (on 816 | ;; Windows, when compiling from within GOPATH). Practically, 817 | ;; however, it has the same end result: There won't be a 818 | ;; compiled binary/archive, and we'll get our import errors when 819 | ;; there are any. 820 | (reverse (remove nil 821 | (mapcar 822 | (lambda (line) 823 | (if (string-match "^\\(.+\\):\\([[:digit:]]+\\): imported and not used: \".+\"$" line) 824 | (if (string= (file-truename (match-string 1 line)) (file-truename buffer-file-name)) 825 | (string-to-number (match-string 2 line))))) 826 | (split-string (shell-command-to-string 827 | (if (string-match "_test\.go$" buffer-file-truename) 828 | "go test -c" 829 | "go build -o /dev/null")) "\n"))))) 830 | 831 | (defun go-remove-unused-imports (arg) 832 | "Removes all unused imports. If ARG is non-nil, unused imports 833 | will be commented, otherwise they will be removed completely." 834 | (interactive "P") 835 | (save-excursion 836 | (let ((cur-buffer (current-buffer)) flymake-state lines) 837 | (when (boundp 'flymake-mode) 838 | (setq flymake-state flymake-mode) 839 | (flymake-mode-off)) 840 | (save-some-buffers nil (lambda () (equal cur-buffer (current-buffer)))) 841 | (if (buffer-modified-p) 842 | (message "Cannot operate on unsaved buffer") 843 | (setq lines (go-unused-imports-lines)) 844 | (dolist (import lines) 845 | (goto-char (point-min)) 846 | (forward-line (1- import)) 847 | (beginning-of-line) 848 | (if arg 849 | (comment-region (line-beginning-position) (line-end-position)) 850 | (go--kill-whole-line))) 851 | (message "Removed %d imports" (length lines))) 852 | (if flymake-state (flymake-mode-on))))) 853 | 854 | (defun godef--find-file-line-column (specifier) 855 | "Given a file name in the format of `filename:line:column', 856 | visit FILENAME and go to line LINE and column COLUMN." 857 | (let* ((components (split-string specifier ":")) 858 | (line (string-to-number (nth 1 components))) 859 | (column (string-to-number (nth 2 components)))) 860 | (with-current-buffer (find-file (car components)) 861 | (goto-char (point-min)) 862 | (forward-line (1- line)) 863 | (beginning-of-line) 864 | (forward-char (1- column)) 865 | (if (buffer-modified-p) 866 | (message "Buffer is modified, file position might not have been correct"))))) 867 | 868 | (defun godef--call (point) 869 | "Call godef, acquiring definition position and expression 870 | description at POINT." 871 | (if (go--xemacs-p) 872 | (message "godef does not reliably work in XEmacs, expect bad results")) 873 | (if (not buffer-file-name) 874 | (message "Cannot use godef on a buffer without a file name") 875 | (let ((outbuf (get-buffer-create "*godef*"))) 876 | (with-current-buffer outbuf 877 | (erase-buffer)) 878 | (call-process-region (point-min) (point-max) "godef" nil outbuf nil "-i" "-t" "-f" (file-truename buffer-file-name) "-o" (number-to-string (go--position-bytes (point)))) 879 | (with-current-buffer outbuf 880 | (split-string (buffer-substring-no-properties (point-min) (point-max)) "\n"))))) 881 | 882 | (defun godef-describe (point) 883 | "Describe the expression at POINT." 884 | (interactive "d") 885 | (condition-case nil 886 | (let ((description (nth 1 (godef--call point)))) 887 | (if (string= "" description) 888 | (message "No description found for expression at point") 889 | (message "%s" description))) 890 | (file-error (message "Could not run godef binary")))) 891 | 892 | (defun godef-jump (point) 893 | "Jump to the definition of the expression at POINT." 894 | (interactive "d") 895 | (condition-case nil 896 | (let ((file (car (godef--call point)))) 897 | (cond 898 | ((string= "-" file) 899 | (message "godef: expression is not defined anywhere")) 900 | ((string= "godef: no identifier found" file) 901 | (message "%s" file)) 902 | ((go--string-prefix-p "godef: no declaration found for " file) 903 | (message "%s" file)) 904 | (t 905 | (push-mark) 906 | (godef--find-file-line-column file)))) 907 | (file-error (message "Could not run godef binary")))) 908 | 909 | (provide 'go-mode) 910 | -------------------------------------------------------------------------------- /libs/js-comint/js-comint.el: -------------------------------------------------------------------------------- 1 | ;;; js-comint.el --- Run javascript in an inferior process window. 2 | 3 | ;;; Copyright (C) 2008 Paul Huff 4 | 5 | ;;; Author: Paul Huff 6 | ;;; Maintainer: Paul Huff 7 | ;;; Created: 26 May 2008 8 | ;;; Version: 0.0.1 9 | ;;; Package-Requires: () 10 | ;;; Keywords: javascript, inferior-mode, convenience 11 | 12 | 13 | ;; js-comint.el is free software; you can redistribute it and/or 14 | ;; modify it under the terms of the GNU General Public License as 15 | ;; published by the Free Software Foundation; either version 2, or 16 | ;; {at your option} any later version. 17 | 18 | ;; js-comint.el is distributed in the hope that it will be useful, but 19 | ;; WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | ;; General Public License for more details. 22 | 23 | ;; You should have received a copy of the GNU General Public License 24 | ;; along with GNU Emacs; see the file COPYING, or type `C-h C-c'. If 25 | ;; not, write to the Free Software Foundation at this address: 26 | 27 | ;; Free Software Foundation 28 | ;; 51 Franklin Street, Fifth Floor 29 | ;; Boston, MA 02110-1301 30 | ;; USA 31 | 32 | ;;; Commentary: 33 | ;;; js-comint.el let's you run an inferior javascript process in emacs, 34 | ;;; and defines a few functions for sending javascript input to it quickly. 35 | 36 | ;; Usage: 37 | ;; Put js-comint.el in your load path 38 | ;; Add (require 'js-comint) to your .emacs 39 | ;; Set inferior-js-program-command to the execution command for running your javascript REPL 40 | ;; (setq inferior-js-program-command "/path/to/executable ") 41 | ;; Do: M-x run-js 42 | ;; Away you go. 43 | 44 | ;; I've added the following couple of lines to my .emacs to take advantage of 45 | ;; cool keybindings for sending things to the javascript interpreter inside 46 | ;; of Steve Yegge's most excellent js2-mode. 47 | 48 | ;; (add-hook 'js2-mode-hook '(lambda () 49 | ;; (local-set-key "\C-x\C-e" 'js-send-last-sexp) 50 | ;; (local-set-key "\C-\M-x" 'js-send-last-sexp-and-go) 51 | ;; (local-set-key "\C-cb" 'js-send-buffer) 52 | ;; (local-set-key "\C-c\C-b" 'js-send-buffer-and-go) 53 | ;; (local-set-key "\C-cl" 'js-load-file-and-go) 54 | ;; )) 55 | 56 | ;; This is version 0.0.1, so I've only tested it on my own version of emacs which is currently: 57 | ;; GNU Emacs 22.0.90.1 (i386-apple-darwin8.8.1, Carbon Version 1.6.0) of 2006-10-28 58 | ;; Not sure if it'll work anywhere else, but it doesn't require anything apple-ish, just emacs-ish. 59 | 60 | ;; Additionally, I've only tested this with rhino. I'm sure it'll probably work with spidermonkey, 61 | ;; though if it barfs let me know, and I'll update it. 62 | 63 | ;; I'm a newbie elisper, so please let me know if I'm a. doing things the wrong way, b. 64 | ;; making things work they way they shouldn't in the elisp world. 65 | 66 | ;;; History: 67 | ;; 68 | 69 | ;;; Code: 70 | 71 | (require 'comint) 72 | 73 | (provide 'js-comint) 74 | 75 | (defcustom inferior-js-program-command "/usr/bin/java org.mozilla.javascript.tools.shell.Main" "Path to the javascript interpreter") 76 | 77 | (defgroup inferior-js nil 78 | "Run a javascript process in a buffer." 79 | :group 'inferior-js) 80 | 81 | (defcustom inferior-js-mode-hook nil 82 | "*Hook for customizing inferior-js mode." 83 | :type 'hook 84 | :group 'inferior-js) 85 | 86 | ;;;###autoload 87 | (defun run-js (cmd &optional dont-switch-p) 88 | "Run an inferior Javascript process, input and output via buffer `*js*'. 89 | If there is a process already running in `*js*', switch to that buffer. 90 | With argument, allows you to edit the command line (default is value 91 | of `inferior-js-program-command'). 92 | Runs the hook `inferior-js-mode-hook' \(after the `comint-mode-hook' 93 | is run). 94 | \(Type \\[describe-mode] in the process buffer for a list of commands.)" 95 | 96 | (interactive (list (if current-prefix-arg 97 | (read-string "Run js: " inferior-js-program-command) 98 | inferior-js-program-command))) 99 | (if (not (comint-check-proc "*js*")) 100 | (save-excursion (let ((cmdlist (split-string cmd))) 101 | (set-buffer (apply 'make-comint "js" (car cmdlist) 102 | nil (cdr cmdlist))) 103 | (inferior-js-mode)))) 104 | (setq inferior-js-program-command cmd) 105 | (setq inferior-js-buffer "*js*") 106 | (if (not dont-switch-p) 107 | (pop-to-buffer "*js*"))) 108 | 109 | ;;;###autoload 110 | (defun js-send-region (start end) 111 | "Send the current region to the inferior Javascript process." 112 | (interactive "r") 113 | (run-js inferior-js-program-command t) 114 | (comint-send-region inferior-js-buffer start end) 115 | (comint-send-string inferior-js-buffer "\n")) 116 | 117 | ;;;###autoload 118 | (defun js-send-region-and-go (start end) 119 | "Send the current region to the inferior Javascript process." 120 | (interactive "r") 121 | (run-js inferior-js-program-command t) 122 | (comint-send-region inferior-js-buffer start end) 123 | (comint-send-string inferior-js-buffer "\n") 124 | (switch-to-js inferior-js-buffer)) 125 | 126 | ;;;###autoload 127 | (defun js-send-last-sexp-and-go () 128 | "Send the previous sexp to the inferior Js process." 129 | (interactive) 130 | (js-send-region-and-go (save-excursion (backward-sexp) (point)) (point))) 131 | 132 | ;;;###autoload 133 | (defun js-send-last-sexp () 134 | "Send the previous sexp to the inferior Javascript process." 135 | (interactive) 136 | (js-send-region (save-excursion (backward-sexp) (point)) (point))) 137 | 138 | ;;;###autoload 139 | (defun js-send-buffer () 140 | "Send the buffer to the inferior Javascript process." 141 | (interactive) 142 | (js-send-region (point-min) (point-max))) 143 | 144 | 145 | ;;;###autoload 146 | (defun js-send-buffer-and-go () 147 | "Send the buffer to the inferior Javascript process." 148 | (interactive) 149 | (js-send-region-and-go (point-min) (point-max))) 150 | 151 | ;;;###autoload 152 | (defun js-load-file (filename) 153 | "Load a file in the javascript interpreter." 154 | (interactive "f") 155 | (let ((filename (expand-file-name filename))) 156 | (run-js inferior-js-program-command t) 157 | (comint-send-string inferior-js-buffer (concat "load(\"" filename "\")\n")))) 158 | 159 | ;;;###autoload 160 | (defun js-load-file-and-go (filename) 161 | "Load a file in the javascript interpreter." 162 | (interactive "f") 163 | (let ((filename (expand-file-name filename))) 164 | (run-js inferior-js-program-command t) 165 | (comint-send-string inferior-js-buffer (concat "load(\"" filename "\")\n")) 166 | (switch-to-js inferior-js-buffer))) 167 | 168 | ;;;###autoload 169 | (defun switch-to-js (eob-p) 170 | "Switch to the javascript process buffer. 171 | With argument, position cursor at end of buffer." 172 | (interactive "P") 173 | (if (or (and inferior-js-buffer (get-buffer inferior-js-buffer)) 174 | (js-interactively-start-process)) 175 | (pop-to-buffer inferior-js-buffer) 176 | (error "No current process buffer. See variable `inferior-js-buffer'")) 177 | (when eob-p 178 | (push-mark) 179 | (goto-char (point-max)))) 180 | 181 | (defvar inferior-js-buffer) 182 | 183 | (defvar inferior-js-mode-map 184 | (let ((m (make-sparse-keymap))) 185 | (define-key m "\C-x\C-e" 'js-send-last-sexp) 186 | (define-key m "\C-cl" 'js-load-file) 187 | m)) 188 | 189 | ;;;###autoload 190 | (define-derived-mode inferior-js-mode comint-mode "Inferior Javascript" 191 | "Major mode for interacting with an inferior javascript process. 192 | 193 | The following commands are available: 194 | \\{inferior-js-mode-map} 195 | 196 | A javascript process can be fired up with M-x run-js. 197 | 198 | Customization: Entry to this mode runs the hooks on comint-mode-hook and 199 | inferior-js-mode-hook (in that order). 200 | 201 | You can send text to the inferior Javascript process from othber buffers containing 202 | Javascript source. 203 | switch-to-js switches the current buffer to the Javascript process buffer. 204 | js-send-region sends the current region to the Javascript process. 205 | 206 | 207 | " 208 | (use-local-map inferior-js-mode-map) 209 | ) -------------------------------------------------------------------------------- /libs/json/json.el: -------------------------------------------------------------------------------- 1 | ;;; json.el --- JavaScript Object Notation parser / generator 2 | 3 | ;; Copyright (C) 2006-2013 Free Software Foundation, Inc. 4 | 5 | ;; Author: Edward O'Connor 6 | ;; Version: 1.4 7 | ;; Keywords: convenience 8 | 9 | ;; This file is part of GNU Emacs. 10 | 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation, either version 3 of the License, or 14 | ;; (at your option) any later version. 15 | 16 | ;; GNU Emacs is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with GNU Emacs. If not, see . 23 | 24 | ;;; Commentary: 25 | 26 | ;; This is a library for parsing and generating JSON (JavaScript Object 27 | ;; Notation). 28 | 29 | ;; Learn all about JSON here: . 30 | 31 | ;; The user-serviceable entry points for the parser are the functions 32 | ;; `json-read' and `json-read-from-string'. The encoder has a single 33 | ;; entry point, `json-encode'. 34 | 35 | ;; Since there are several natural representations of key-value pair 36 | ;; mappings in elisp (alist, plist, hash-table), `json-read' allows you 37 | ;; to specify which you'd prefer (see `json-object-type' and 38 | ;; `json-array-type'). 39 | 40 | ;; Similarly, since `false' and `null' are distinct in JSON, you can 41 | ;; distinguish them by binding `json-false' and `json-null' as desired. 42 | 43 | ;;; History: 44 | 45 | ;; 2006-03-11 - Initial version. 46 | ;; 2006-03-13 - Added JSON generation in addition to parsing. Various 47 | ;; other cleanups, bugfixes, and improvements. 48 | ;; 2006-12-29 - XEmacs support, from Aidan Kehoe . 49 | ;; 2008-02-21 - Installed in GNU Emacs. 50 | ;; 2011-10-17 - Patch `json-alist-p' and `json-plist-p' to avoid recursion -tzz 51 | ;; 2012-10-25 - Added pretty-printed reformatting -Ryan Crum (ryan@ryancrum.org) 52 | 53 | ;;; Code: 54 | 55 | 56 | ;; Compatibility code 57 | 58 | (defalias 'json-encode-char0 'encode-char) 59 | (defalias 'json-decode-char0 'decode-char) 60 | 61 | 62 | ;; Parameters 63 | 64 | (defvar json-object-type 'alist 65 | "Type to convert JSON objects to. 66 | Must be one of `alist', `plist', or `hash-table'. Consider let-binding 67 | this around your call to `json-read' instead of `setq'ing it.") 68 | 69 | (defvar json-array-type 'vector 70 | "Type to convert JSON arrays to. 71 | Must be one of `vector' or `list'. Consider let-binding this around 72 | your call to `json-read' instead of `setq'ing it.") 73 | 74 | (defvar json-key-type nil 75 | "Type to convert JSON keys to. 76 | Must be one of `string', `symbol', `keyword', or nil. 77 | 78 | If nil, `json-read' will guess the type based on the value of 79 | `json-object-type': 80 | 81 | If `json-object-type' is: nil will be interpreted as: 82 | `hash-table' `string' 83 | `alist' `symbol' 84 | `plist' `keyword' 85 | 86 | Note that values other than `string' might behave strangely for 87 | Sufficiently Weird keys. Consider let-binding this around your call to 88 | `json-read' instead of `setq'ing it.") 89 | 90 | (defvar json-false :json-false 91 | "Value to use when reading JSON `false'. 92 | If this has the same value as `json-null', you might not be able to tell 93 | the difference between `false' and `null'. Consider let-binding this 94 | around your call to `json-read' instead of `setq'ing it.") 95 | 96 | (defvar json-null nil 97 | "Value to use when reading JSON `null'. 98 | If this has the same value as `json-false', you might not be able to 99 | tell the difference between `false' and `null'. Consider let-binding 100 | this around your call to `json-read' instead of `setq'ing it.") 101 | 102 | (defvar json-encoding-separator "," 103 | "Value to use as an element separator when encoding.") 104 | 105 | (defvar json-encoding-default-indentation " " 106 | "The default indentation level for encoding. 107 | Used only when `json-encoding-pretty-print' is non-nil.") 108 | 109 | (defvar json--encoding-current-indentation "\n" 110 | "Internally used to keep track of the current indentation level of encoding. 111 | Used only when `json-encoding-pretty-print' is non-nil.") 112 | 113 | (defvar json-encoding-pretty-print t 114 | "If non-nil, then the output of `json-encode' will be pretty-printed.") 115 | 116 | (defvar json-encoding-lisp-style-closings nil 117 | "If non-nil, ] and } closings will be formatted lisp-style, 118 | without indentation.") 119 | 120 | 121 | 122 | ;;; Utilities 123 | 124 | (defun json-join (strings separator) 125 | "Join STRINGS with SEPARATOR." 126 | (mapconcat 'identity strings separator)) 127 | 128 | (defun json-alist-p (list) 129 | "Non-null if and only if LIST is an alist." 130 | (while (consp list) 131 | (setq list (if (consp (car list)) 132 | (cdr list) 133 | 'not-alist))) 134 | (null list)) 135 | 136 | (defun json-plist-p (list) 137 | "Non-null if and only if LIST is a plist." 138 | (while (consp list) 139 | (setq list (if (and (keywordp (car list)) 140 | (consp (cdr list))) 141 | (cddr list) 142 | 'not-plist))) 143 | (null list)) 144 | 145 | (defmacro json--with-indentation (body) 146 | `(let ((json--encoding-current-indentation 147 | (if json-encoding-pretty-print 148 | (concat json--encoding-current-indentation 149 | json-encoding-default-indentation) 150 | ""))) 151 | ,body)) 152 | 153 | ;; Reader utilities 154 | 155 | (defsubst json-advance (&optional n) 156 | "Skip past the following N characters." 157 | (forward-char n)) 158 | 159 | (defsubst json-peek () 160 | "Return the character at point." 161 | (let ((char (char-after (point)))) 162 | (or char :json-eof))) 163 | 164 | (defsubst json-pop () 165 | "Advance past the character at point, returning it." 166 | (let ((char (json-peek))) 167 | (if (eq char :json-eof) 168 | (signal 'end-of-file nil) 169 | (json-advance) 170 | char))) 171 | 172 | (defun json-skip-whitespace () 173 | "Skip past the whitespace at point." 174 | (skip-chars-forward "\t\r\n\f\b ")) 175 | 176 | 177 | 178 | ;; Error conditions 179 | 180 | (put 'json-error 'error-message "Unknown JSON error") 181 | (put 'json-error 'error-conditions '(json-error error)) 182 | 183 | (put 'json-readtable-error 'error-message "JSON readtable error") 184 | (put 'json-readtable-error 'error-conditions 185 | '(json-readtable-error json-error error)) 186 | 187 | (put 'json-unknown-keyword 'error-message "Unrecognized keyword") 188 | (put 'json-unknown-keyword 'error-conditions 189 | '(json-unknown-keyword json-error error)) 190 | 191 | (put 'json-number-format 'error-message "Invalid number format") 192 | (put 'json-number-format 'error-conditions 193 | '(json-number-format json-error error)) 194 | 195 | (put 'json-string-escape 'error-message "Bad Unicode escape") 196 | (put 'json-string-escape 'error-conditions 197 | '(json-string-escape json-error error)) 198 | 199 | (put 'json-string-format 'error-message "Bad string format") 200 | (put 'json-string-format 'error-conditions 201 | '(json-string-format json-error error)) 202 | 203 | (put 'json-key-format 'error-message "Bad JSON object key") 204 | (put 'json-key-format 'error-conditions 205 | '(json-key-format json-error error)) 206 | 207 | (put 'json-object-format 'error-message "Bad JSON object") 208 | (put 'json-object-format 'error-conditions 209 | '(json-object-format json-error error)) 210 | 211 | 212 | 213 | ;;; Keywords 214 | 215 | (defvar json-keywords '("true" "false" "null") 216 | "List of JSON keywords.") 217 | 218 | ;; Keyword parsing 219 | 220 | (defun json-read-keyword (keyword) 221 | "Read a JSON keyword at point. 222 | KEYWORD is the keyword expected." 223 | (unless (member keyword json-keywords) 224 | (signal 'json-unknown-keyword (list keyword))) 225 | (mapc (lambda (char) 226 | (unless (char-equal char (json-peek)) 227 | (signal 'json-unknown-keyword 228 | (list (save-excursion 229 | (backward-word 1) 230 | (thing-at-point 'word))))) 231 | (json-advance)) 232 | keyword) 233 | (unless (looking-at "\\(\\s-\\|[],}]\\|$\\)") 234 | (signal 'json-unknown-keyword 235 | (list (save-excursion 236 | (backward-word 1) 237 | (thing-at-point 'word))))) 238 | (cond ((string-equal keyword "true") t) 239 | ((string-equal keyword "false") json-false) 240 | ((string-equal keyword "null") json-null))) 241 | 242 | ;; Keyword encoding 243 | 244 | (defun json-encode-keyword (keyword) 245 | "Encode KEYWORD as a JSON value." 246 | (cond ((eq keyword t) "true") 247 | ((eq keyword json-false) "false") 248 | ((eq keyword json-null) "null"))) 249 | 250 | ;;; Numbers 251 | 252 | ;; Number parsing 253 | 254 | (defun json-read-number (&optional sign) 255 | "Read the JSON number following point. 256 | The optional SIGN argument is for internal use. 257 | 258 | N.B.: Only numbers which can fit in Emacs Lisp's native number 259 | representation will be parsed correctly." 260 | ;; If SIGN is non-nil, the number is explicitly signed. 261 | (let ((number-regexp 262 | "\\([0-9]+\\)?\\(\\.[0-9]+\\)?\\([Ee][+-]?[0-9]+\\)?")) 263 | (cond ((and (null sign) (char-equal (json-peek) ?-)) 264 | (json-advance) 265 | (- (json-read-number t))) 266 | ((and (null sign) (char-equal (json-peek) ?+)) 267 | (json-advance) 268 | (json-read-number t)) 269 | ((and (looking-at number-regexp) 270 | (or (match-beginning 1) 271 | (match-beginning 2))) 272 | (goto-char (match-end 0)) 273 | (string-to-number (match-string 0))) 274 | (t (signal 'json-number-format (list (point))))))) 275 | 276 | ;; Number encoding 277 | 278 | (defun json-encode-number (number) 279 | "Return a JSON representation of NUMBER." 280 | (format "%s" number)) 281 | 282 | ;;; Strings 283 | 284 | (defvar json-special-chars 285 | '((?\" . ?\") 286 | (?\\ . ?\\) 287 | (?/ . ?/) 288 | (?b . ?\b) 289 | (?f . ?\f) 290 | (?n . ?\n) 291 | (?r . ?\r) 292 | (?t . ?\t)) 293 | "Characters which are escaped in JSON, with their elisp counterparts.") 294 | 295 | ;; String parsing 296 | 297 | (defun json-read-escaped-char () 298 | "Read the JSON string escaped character at point." 299 | ;; Skip over the '\' 300 | (json-advance) 301 | (let* ((char (json-pop)) 302 | (special (assq char json-special-chars))) 303 | (cond 304 | (special (cdr special)) 305 | ((not (eq char ?u)) char) 306 | ((looking-at "[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]") 307 | (let ((hex (match-string 0))) 308 | (json-advance 4) 309 | (json-decode-char0 'ucs (string-to-number hex 16)))) 310 | (t 311 | (signal 'json-string-escape (list (point))))))) 312 | 313 | (defun json-read-string () 314 | "Read the JSON string at point." 315 | (unless (char-equal (json-peek) ?\") 316 | (signal 'json-string-format (list "doesn't start with '\"'!"))) 317 | ;; Skip over the '"' 318 | (json-advance) 319 | (let ((characters '()) 320 | (char (json-peek))) 321 | (while (not (char-equal char ?\")) 322 | (push (if (char-equal char ?\\) 323 | (json-read-escaped-char) 324 | (json-pop)) 325 | characters) 326 | (setq char (json-peek))) 327 | ;; Skip over the '"' 328 | (json-advance) 329 | (if characters 330 | (apply 'string (nreverse characters)) 331 | ""))) 332 | 333 | ;; String encoding 334 | 335 | (defun json-encode-char (char) 336 | "Encode CHAR as a JSON string." 337 | (setq char (json-encode-char0 char 'ucs)) 338 | (let ((control-char (car (rassoc char json-special-chars)))) 339 | (cond 340 | ;; Special JSON character (\n, \r, etc.). 341 | (control-char 342 | (format "\\%c" control-char)) 343 | ;; ASCIIish printable character. 344 | ((and (> char 31) (< char 127)) 345 | (format "%c" char)) 346 | ;; Fallback: UCS code point in \uNNNN form. 347 | (t 348 | (format "\\u%04x" char))))) 349 | 350 | (defun json-encode-string (string) 351 | "Return a JSON representation of STRING." 352 | (format "\"%s\"" (mapconcat 'json-encode-char string ""))) 353 | 354 | (defun json-encode-key (object) 355 | "Return a JSON representation of OBJECT. 356 | If the resulting JSON object isn't a valid JSON object key, 357 | this signals `json-key-format'." 358 | (let ((encoded (json-encode object))) 359 | (unless (stringp (json-read-from-string encoded)) 360 | (signal 'json-key-format (list object))) 361 | encoded)) 362 | 363 | ;;; JSON Objects 364 | 365 | (defun json-new-object () 366 | "Create a new Elisp object corresponding to a JSON object. 367 | Please see the documentation of `json-object-type'." 368 | (cond ((eq json-object-type 'hash-table) 369 | (make-hash-table :test 'equal)) 370 | (t 371 | (list)))) 372 | 373 | (defun json-add-to-object (object key value) 374 | "Add a new KEY -> VALUE association to OBJECT. 375 | Returns the updated object, which you should save, e.g.: 376 | (setq obj (json-add-to-object obj \"foo\" \"bar\")) 377 | Please see the documentation of `json-object-type' and `json-key-type'." 378 | (let ((json-key-type 379 | (if (eq json-key-type nil) 380 | (cdr (assq json-object-type '((hash-table . string) 381 | (alist . symbol) 382 | (plist . keyword)))) 383 | json-key-type))) 384 | (setq key 385 | (cond ((eq json-key-type 'string) 386 | key) 387 | ((eq json-key-type 'symbol) 388 | (intern key)) 389 | ((eq json-key-type 'keyword) 390 | (intern (concat ":" key))))) 391 | (cond ((eq json-object-type 'hash-table) 392 | (puthash key value object) 393 | object) 394 | ((eq json-object-type 'alist) 395 | (cons (cons key value) object)) 396 | ((eq json-object-type 'plist) 397 | (cons key (cons value object)))))) 398 | 399 | ;; JSON object parsing 400 | 401 | (defun json-read-object () 402 | "Read the JSON object at point." 403 | ;; Skip over the "{" 404 | (json-advance) 405 | (json-skip-whitespace) 406 | ;; read key/value pairs until "}" 407 | (let ((elements (json-new-object)) 408 | key value) 409 | (while (not (char-equal (json-peek) ?})) 410 | (json-skip-whitespace) 411 | (setq key (json-read-string)) 412 | (json-skip-whitespace) 413 | (if (char-equal (json-peek) ?:) 414 | (json-advance) 415 | (signal 'json-object-format (list ":" (json-peek)))) 416 | (setq value (json-read)) 417 | (setq elements (json-add-to-object elements key value)) 418 | (json-skip-whitespace) 419 | (unless (char-equal (json-peek) ?}) 420 | (if (char-equal (json-peek) ?,) 421 | (json-advance) 422 | (signal 'json-object-format (list "," (json-peek)))))) 423 | ;; Skip over the "}" 424 | (json-advance) 425 | elements)) 426 | 427 | ;; Hash table encoding 428 | 429 | (defun json-encode-hash-table (hash-table) 430 | "Return a JSON representation of HASH-TABLE." 431 | (format "{%s%s}" 432 | (json-join 433 | (let (r) 434 | (json--with-indentation 435 | (maphash 436 | (lambda (k v) 437 | (push (format 438 | (if json-encoding-pretty-print 439 | "%s%s: %s" 440 | "%s%s:%s") 441 | json--encoding-current-indentation 442 | (json-encode-key k) 443 | (json-encode v)) 444 | r)) 445 | hash-table)) 446 | r) 447 | json-encoding-separator) 448 | (if (or (not json-encoding-pretty-print) 449 | json-encoding-lisp-style-closings) 450 | "" 451 | json--encoding-current-indentation))) 452 | 453 | ;; List encoding (including alists and plists) 454 | 455 | (defun json-encode-alist (alist) 456 | "Return a JSON representation of ALIST." 457 | (format "{%s%s}" 458 | (json-join 459 | (json--with-indentation 460 | (mapcar (lambda (cons) 461 | (format (if json-encoding-pretty-print 462 | "%s%s: %s" 463 | "%s%s:%s") 464 | json--encoding-current-indentation 465 | (json-encode-key (car cons)) 466 | (json-encode (cdr cons)))) 467 | alist)) 468 | json-encoding-separator) 469 | (if (or (not json-encoding-pretty-print) 470 | json-encoding-lisp-style-closings) 471 | "" 472 | json--encoding-current-indentation))) 473 | 474 | (defun json-encode-plist (plist) 475 | "Return a JSON representation of PLIST." 476 | (let (result) 477 | (json--with-indentation 478 | (while plist 479 | (push (concat 480 | json--encoding-current-indentation 481 | (json-encode-key (car plist)) 482 | (if json-encoding-pretty-print 483 | ": " 484 | ":") 485 | (json-encode (cadr plist))) 486 | result) 487 | (setq plist (cddr plist)))) 488 | (concat "{" 489 | (json-join (nreverse result) json-encoding-separator) 490 | (if (and json-encoding-pretty-print 491 | (not json-encoding-lisp-style-closings)) 492 | json--encoding-current-indentation 493 | "") 494 | "}"))) 495 | 496 | (defun json-encode-list (list) 497 | "Return a JSON representation of LIST. 498 | Tries to DWIM: simple lists become JSON arrays, while alists and plists 499 | become JSON objects." 500 | (cond ((null list) "null") 501 | ((json-alist-p list) (json-encode-alist list)) 502 | ((json-plist-p list) (json-encode-plist list)) 503 | ((listp list) (json-encode-array list)) 504 | (t 505 | (signal 'json-error (list list))))) 506 | 507 | ;;; Arrays 508 | 509 | ;; Array parsing 510 | 511 | (defun json-read-array () 512 | "Read the JSON array at point." 513 | ;; Skip over the "[" 514 | (json-advance) 515 | (json-skip-whitespace) 516 | ;; read values until "]" 517 | (let (elements) 518 | (while (not (char-equal (json-peek) ?\])) 519 | (push (json-read) elements) 520 | (json-skip-whitespace) 521 | (unless (char-equal (json-peek) ?\]) 522 | (if (char-equal (json-peek) ?,) 523 | (json-advance) 524 | (signal 'json-error (list 'bleah))))) 525 | ;; Skip over the "]" 526 | (json-advance) 527 | (apply json-array-type (nreverse elements)))) 528 | 529 | ;; Array encoding 530 | 531 | (defun json-encode-array (array) 532 | "Return a JSON representation of ARRAY." 533 | (if (and json-encoding-pretty-print 534 | (> (length array) 0)) 535 | (concat 536 | (json--with-indentation 537 | (concat (format "[%s" json--encoding-current-indentation) 538 | (json-join (mapcar 'json-encode array) 539 | (format "%s%s" 540 | json-encoding-separator 541 | json--encoding-current-indentation)))) 542 | (format "%s]" 543 | (if json-encoding-lisp-style-closings 544 | "" 545 | json--encoding-current-indentation))) 546 | (concat "[" 547 | (mapconcat 'json-encode array json-encoding-separator) 548 | "]"))) 549 | 550 | 551 | 552 | ;;; JSON reader. 553 | 554 | (defvar json-readtable 555 | (let ((table 556 | '((?t json-read-keyword "true") 557 | (?f json-read-keyword "false") 558 | (?n json-read-keyword "null") 559 | (?{ json-read-object) 560 | (?\[ json-read-array) 561 | (?\" json-read-string)))) 562 | (mapc (lambda (char) 563 | (push (list char 'json-read-number) table)) 564 | '(?- ?+ ?. ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)) 565 | table) 566 | "Readtable for JSON reader.") 567 | 568 | (defun json-read () 569 | "Parse and return the JSON object following point. 570 | Advances point just past JSON object." 571 | (json-skip-whitespace) 572 | (let ((char (json-peek))) 573 | (if (not (eq char :json-eof)) 574 | (let ((record (cdr (assq char json-readtable)))) 575 | (if (functionp (car record)) 576 | (apply (car record) (cdr record)) 577 | (signal 'json-readtable-error record))) 578 | (signal 'end-of-file nil)))) 579 | 580 | ;; Syntactic sugar for the reader 581 | 582 | (defun json-read-from-string (string) 583 | "Read the JSON object contained in STRING and return it." 584 | (with-temp-buffer 585 | (insert string) 586 | (goto-char (point-min)) 587 | (json-read))) 588 | 589 | (defun json-read-file (file) 590 | "Read the first JSON object contained in FILE and return it." 591 | (with-temp-buffer 592 | (insert-file-contents file) 593 | (goto-char (point-min)) 594 | (json-read))) 595 | 596 | 597 | 598 | ;;; JSON encoder 599 | 600 | (defun json-encode (object) 601 | "Return a JSON representation of OBJECT as a string." 602 | (cond ((memq object (list t json-null json-false)) 603 | (json-encode-keyword object)) 604 | ((stringp object) (json-encode-string object)) 605 | ((keywordp object) (json-encode-string 606 | (substring (symbol-name object) 1))) 607 | ((symbolp object) (json-encode-string 608 | (symbol-name object))) 609 | ((numberp object) (json-encode-number object)) 610 | ((arrayp object) (json-encode-array object)) 611 | ((hash-table-p object) (json-encode-hash-table object)) 612 | ((listp object) (json-encode-list object)) 613 | (t (signal 'json-error (list object))))) 614 | 615 | ;; Pretty printing 616 | 617 | (defun json-pretty-print-buffer () 618 | "Pretty-print current buffer." 619 | (interactive) 620 | (json-pretty-print (point-min) (point-max))) 621 | 622 | (defun json-pretty-print (begin end) 623 | "Pretty-print selected region." 624 | (interactive "r") 625 | (atomic-change-group 626 | (let ((json-encoding-pretty-print t) 627 | (txt (delete-and-extract-region begin end))) 628 | (insert (json-encode (json-read-from-string txt)))))) 629 | 630 | (provide 'json) 631 | 632 | ;;; json.el ends here 633 | -------------------------------------------------------------------------------- /libs/let-alist/let-alist.el: -------------------------------------------------------------------------------- 1 | ;;; let-alist.el --- Easily let-bind values of an assoc-list by their names 2 | 3 | ;; Copyright (C) 2014 Free Software Foundation, Inc. 4 | 5 | ;; Author: Artur Malabarba 6 | ;; Maintainer: Artur Malabarba 7 | ;; Version: 1.0 8 | ;; Keywords: extensions lisp 9 | ;; Prefix: let-alist 10 | ;; Separator: - 11 | 12 | ;; This file is part of GNU Emacs. 13 | 14 | ;; GNU Emacs is free software: you can redistribute it and/or modify 15 | ;; it under the terms of the GNU General Public License as published by 16 | ;; the Free Software Foundation, either version 3 of the License, or 17 | ;; (at your option) any later version. 18 | 19 | ;; GNU Emacs is distributed in the hope that it will be useful, 20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | ;; GNU General Public License for more details. 23 | 24 | ;; You should have received a copy of the GNU General Public License 25 | ;; along with GNU Emacs. If not, see . 26 | 27 | ;;; Commentary: 28 | 29 | ;; This package offers a single macro, `let-alist'. This macro takes a 30 | ;; first argument (whose value must be an alist) and a body. 31 | ;; 32 | ;; The macro expands to a let form containing body, where each dotted 33 | ;; symbol inside body is let-bound to their cdrs in the alist. Dotted 34 | ;; symbol is any symbol starting with a `.'. Only those present in 35 | ;; the body are let-bound and this search is done at compile time. 36 | ;; 37 | ;; For instance, the following code 38 | ;; 39 | ;; (let-alist alist 40 | ;; (if (and .title .body) 41 | ;; .body 42 | ;; .site)) 43 | ;; 44 | ;; expands to 45 | ;; 46 | ;; (let ((.title (cdr (assq 'title alist))) 47 | ;; (.body (cdr (assq 'body alist))) 48 | ;; (.site (cdr (assq 'site alist)))) 49 | ;; (if (and .title .body) 50 | ;; .body 51 | ;; .site)) 52 | ;; 53 | ;; Note that only one level is supported. If you nest `let-alist' 54 | ;; invocations, the inner one can't access the variables of the outer 55 | ;; one. 56 | 57 | ;;; Code: 58 | 59 | 60 | (defun let-alist--deep-dot-search (data) 61 | "Return alist of symbols inside DATA that start with a `.'. 62 | Perform a deep search and return an alist where each car is the 63 | symbol, and each cdr is the same symbol without the `.'." 64 | (cond 65 | ((symbolp data) 66 | (let ((name (symbol-name data))) 67 | (when (string-match "\\`\\." name) 68 | ;; Return the cons cell inside a list, so it can be appended 69 | ;; with other results in the clause below. 70 | (list (cons data (intern (replace-match "" nil nil name))))))) 71 | ((not (listp data)) nil) 72 | (t (apply #'append 73 | (remove nil (mapcar #'let-alist--deep-dot-search data)))))) 74 | 75 | ;;;###autoload 76 | (defmacro let-alist (alist &rest body) 77 | "Let-bind dotted symbols to their cdrs in ALIST and execute BODY. 78 | Dotted symbol is any symbol starting with a `.'. Only those present 79 | in BODY are let-bound and this search is done at compile time. 80 | 81 | For instance, the following code 82 | 83 | (let-alist alist 84 | (if (and .title .body) 85 | .body 86 | .site)) 87 | 88 | expands to 89 | 90 | (let ((.title (cdr (assq 'title alist))) 91 | (.body (cdr (assq 'body alist))) 92 | (.site (cdr (assq 'site alist)))) 93 | (if (and .title .body) 94 | .body 95 | .site))" 96 | (declare (indent 1) (debug t)) 97 | `(let ,(mapcar (lambda (x) `(,(car x) (cdr (assq ',(cdr x) ,alist)))) 98 | (delete-dups (let-alist--deep-dot-search body))) 99 | ,@body)) 100 | 101 | ;;;; ChangeLog: 102 | 103 | ;; 2014-12-11 Artur Malabarba 104 | ;; 105 | ;; let-alist: New package 106 | ;; 107 | 108 | 109 | (provide 'let-alist) 110 | 111 | ;;; let-alist.el ends here 112 | -------------------------------------------------------------------------------- /libs/rainbow/rainbow-delimiters.el: -------------------------------------------------------------------------------- 1 | ;;; rainbow-delimiters.el --- Colorize nested delimiters: () [] {} 2 | 3 | ;; Copyright (C) 2010 Jeremy Rayman 4 | ;; Copyright (C) 2009 Mark Triggs 5 | 6 | ;; Author: Mark Triggs , additions by 7 | ;; Jeremy Rayman, and help from Alex Osborne 8 | 9 | ;; This program is free software; you can redistribute it and/or modify 10 | ;; it under the terms of the GNU General Public License as published by 11 | ;; the Free Software Foundation, either version 3 of the License, or 12 | ;; (at your option) any later version. 13 | 14 | ;; This program is distributed in the hope that it will be useful, 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | ;; GNU General Public License for more details. 18 | 19 | ;; You should have received a copy of the GNU General Public License 20 | ;; along with this program. If not, see . 21 | 22 | ;;; Installation: 23 | 24 | ;; Place rainbow-delimiters.el on your emacs load-path. 25 | 26 | ;; (require 'rainbow-delimiters) 27 | ;; M-x rainbow-delimiters-mode 28 | 29 | ;; NOTE: The colors in this file were picked on a wide-gamut display, 30 | ;; meaning they will look terrible on a standard-gamut display. You 31 | ;; will want to change the colors to subtler ones of your liking. 32 | ;; Change the variable `*rainbow-delimiters-faces*' 33 | 34 | ;;; Commentary: 35 | 36 | ;; This is a "rainbow parentheses" mode which includes support for 37 | ;; parens "()", brackets "[]", and braces "{}". It conveys nesting 38 | ;; depth by using a new color from *rainbow-delimiters-faces* for each 39 | ;; for each nested level. It correctly colorizes statements of the 40 | ;; same depth - if two statements are the same level, they will be the 41 | ;; same color. The user can change the variable 42 | ;; `*rainbow-delimiter-faces*' to set their own color choices. 43 | ;; Emacs customize dialog support is forthcoming. 44 | 45 | ;; Each set of delimiters "()[]{}" is colored independently from one 46 | ;; another. This means that color chosen is based on the nesting depth 47 | ;; _solely of that type of delimiter_. Parens, brackets, and braces 48 | ;; all maintain their colors depth, meaning even a bracket nested 49 | ;; within several levels of parentheses will start with the topmost 50 | ;; (lightest) color, and each nested bracket will then move to the 51 | ;; next color. 52 | 53 | ;; Thanks to Mark Triggs and Alex Osborne, who did the heavy lifting 54 | ;; in this code. They made proper use of overlays and the mode 55 | ;; colorizes the buffer fast in most scenarios. This is a fork of 56 | ;; their work to add several new features. The original 57 | ;; rainbow-parens.el written by these authors is available at: 58 | ;; http://dishevelled.net/elisp/rainbow-parens.el 59 | 60 | ;; Bug reports about this code should be sent to Jeremy Rayman 61 | ;; . Please do not send bug reports to 62 | ;; the maintainers of rainbow-parens.el unless the bug is present in 63 | ;; their original version. Thank you. 64 | 65 | ;;; TODO: 66 | ;; - Add customize-interface for changing delimiter colors 67 | ;; - Use a separate *rainbow-______-face* for each type 68 | ;; of delimiter to allow independent color choices for each one 69 | ;; - Improve performance on very delimiter-heavy code (performance is 70 | ;; already good for most files including most lisp files) 71 | ;; - Add <> support with a toggle to colorize nested tags (XML, HTML) 72 | ;; vs colorizing nested angle brackets like we do with the other 73 | ;; types of delimiter. 74 | 75 | ;;; Code: 76 | 77 | (require 'paredit) 78 | (require 'cl) 79 | 80 | ;;; TODO: Customize interface: 81 | ;; (defgroup rainbow-delimiters nil 82 | ;; "Color each nested set of delimiters differently to visually communicate nesting level.") ; should rainbow-delimiters belong to a :group? 83 | 84 | (defun rainbow-delimiters-face-from-colour (colour) 85 | (let ((face (make-face (intern (concat "rainbow-delimiters-" colour "-face"))))) 86 | (set-face-foreground face colour) 87 | face)) 88 | 89 | (defvar *rainbow-delimiters-faces* 90 | `[,(rainbow-delimiters-face-from-colour "dark gray") 91 | ,(rainbow-delimiters-face-from-colour "green") 92 | ,(rainbow-delimiters-face-from-colour "gold") 93 | ,(rainbow-delimiters-face-from-colour "turquoise") 94 | ,(rainbow-delimiters-face-from-colour "orange") 95 | ,(rainbow-delimiters-face-from-colour "slate blue") 96 | ,(rainbow-delimiters-face-from-colour "yellow") 97 | ,(rainbow-delimiters-face-from-colour "light blue") 98 | ,(rainbow-delimiters-face-from-colour "#7f7f7f") 99 | ,(rainbow-delimiters-face-from-colour "light gray") 100 | ]) 101 | 102 | 103 | (defun rainbow-delimiters-this-paren-nesting () 104 | (let ((point (point)) 105 | (depth 0)) 106 | (while (ignore-errors 107 | (setq point (scan-lists point -1 1))) 108 | (when (= (char-after point) 40) 109 | (setq depth (1+ depth)))) 110 | depth)) 111 | 112 | (defun rainbow-delimiters-this-bracket-nesting () 113 | (let ((point (point)) 114 | (depth 0)) 115 | (while (ignore-errors 116 | (setq point (scan-lists point -1 1))) 117 | (when (= (char-after point) 91) 118 | (setq depth (1+ depth)))) 119 | depth)) 120 | 121 | (defun rainbow-delimiters-this-brace-nesting () 122 | (let ((point (point)) 123 | (depth 0)) 124 | (while (ignore-errors 125 | (setq point (scan-lists point -1 1))) 126 | (when (= (char-after point) 123) 127 | (setq depth (1+ depth)))) 128 | depth)) 129 | 130 | 131 | (defun rainbow-delimiters-face-for-depth (n) 132 | (aref *rainbow-delimiters-faces* 133 | (mod n (length *rainbow-delimiters-faces*)))) 134 | 135 | 136 | (defun rainbow-delimiters-apply (point face) 137 | (let* ((os (overlays-at point)) 138 | (o (or (some (lambda (o) 139 | (and (eq (overlay-get o 'type) 'rainbow-delimiter) 140 | o)) 141 | os) 142 | (make-overlay point (1+ point) nil t nil)))) 143 | (overlay-put o 'type 'rainbow-delimiter) 144 | (overlay-put o 'face face) 145 | (overlay-put o 'evaporate t))) 146 | 147 | 148 | 149 | (defun rainbow-delimiters-boring-delimiter-p () 150 | (or (paredit-in-string-p) 151 | (paredit-in-comment-p))) 152 | 153 | 154 | (defun rainbow-delimiters-skip-boring (bound) 155 | (while (and (< (point) bound) 156 | (rainbow-delimiters-boring-delimiter-p)) 157 | (forward-char 1))) 158 | 159 | 160 | (defun rainbow-delimiters-fontify (beg end) 161 | (save-excursion 162 | (goto-char beg) 163 | (rainbow-delimiters-skip-boring end) 164 | (let* ((paren-depth (rainbow-delimiters-this-paren-nesting)) 165 | (bracket-depth (rainbow-delimiters-this-bracket-nesting)) 166 | (brace-depth (rainbow-delimiters-this-brace-nesting))) 167 | (while (< (point) end) 168 | (rainbow-delimiters-skip-boring end) 169 | (cond ((= (char-after (point)) 91) ; [ 170 | (rainbow-delimiters-apply (point) 171 | (rainbow-delimiters-face-for-depth bracket-depth)) 172 | (setq bracket-depth (1+ bracket-depth))) 173 | ((= (char-after (point)) 93) ; ] 174 | (setq bracket-depth (1- bracket-depth)) 175 | (rainbow-delimiters-apply (point) 176 | (rainbow-delimiters-face-for-depth bracket-depth))) 177 | ((= (char-after (point)) 123) ; { 178 | (rainbow-delimiters-apply (point) 179 | (rainbow-delimiters-face-for-depth brace-depth)) 180 | (setq brace-depth (1+ brace-depth))) 181 | ((= (char-after (point)) 125) ; } 182 | (setq brace-depth (1- brace-depth)) 183 | (rainbow-delimiters-apply (point) 184 | (rainbow-delimiters-face-for-depth brace-depth))) 185 | ; < 60 186 | ; > 62 187 | ) 188 | (forward-char 1))))) 189 | 190 | 191 | (defun rainbow-delimiters-unfontify (beg end) 192 | (mapc #'(lambda (o) 193 | (when (eq (overlay-get o 'type) 'rainbow-delimiter) 194 | (delete-overlay o))) 195 | (overlays-in beg end))) 196 | 197 | 198 | (define-minor-mode rainbow-delimiters-mode 199 | "Color each nested set of delimiters differently to visually communicate nesting level. Supports (), [], {}." 200 | 201 | nil " R" nil 202 | (cond ((not rainbow-delimiters-mode) 203 | (jit-lock-unregister 'rainbow-delimiters-fontify) 204 | (rainbow-delimiters-unfontify (point-min) (point-max))) 205 | (t (jit-lock-register 'rainbow-delimiters-fontify)))) 206 | 207 | 208 | (provide 'rainbow-delimiters) 209 | 210 | ;;; Other possible delimiter colors to use: (wide-gamut) 211 | ;; ,(rainbow-delimiters-face-from-colour "#7f7f7f") 212 | ;; ,(rainbow-delimiters-face-from-colour "#7f7f91") 213 | ;; ,(rainbow-delimiters-face-from-colour "#7f7fa1") 214 | ;; ,(rainbow-delimiters-face-from-colour "#95aabc") 215 | ;; ,(rainbow-delimiters-face-from-colour "#9d9d9d") 216 | ;; ,(rainbow-delimiters-face-from-colour "#9d9d9d") 217 | ;; ,(rainbow-delimiters-face-from-colour "#8d929b") 218 | ;; ,(rainbow-delimiters-face-from-colour "#7f8f9d") 219 | ;; ,(rainbow-delimiters-face-from-colour "#73818c") 220 | ;; ,(rainbow-delimiters-face-from-colour "#91b3d0") 221 | ;; ,(rainbow-delimiters-face-from-colour "#91b3d0") 222 | ;; ,(rainbow-delimiters-face-from-colour "#91b3d0") 223 | ;; ,(rainbow-delimiters-face-from-colour "#7ea7c9") 224 | ;; ,(rainbow-delimiters-face-from-colour "#6b9ac2") 225 | ;; ,(rainbow-delimiters-face-from-colour "gray100") 226 | ;; ,(rainbow-delimiters-face-from-colour "gray85") 227 | ;; ,(rainbow-delimiters-face-from-colour "gray70") 228 | ;; ,(rainbow-delimiters-face-from-colour "#6093be") 229 | ;; ,(rainbow-delimiters-face-from-colour "#588dba") 230 | 231 | ;;; rainbow-delimiters.el ends here 232 | -------------------------------------------------------------------------------- /libs/rainbow/rainbow-parens.el: -------------------------------------------------------------------------------- 1 | ;;; rainbow-parens.el --- Argh! My eyes! 2 | 3 | ;; Copyright (C) 2009 Mark Triggs 4 | 5 | ;; Author: Mark Triggs with thanks to help 6 | ;; from Alex Osborne 7 | ;; Keywords: pain, horror 8 | 9 | ;; This program is free software; you can redistribute it and/or modify 10 | ;; it under the terms of the GNU General Public License as published by 11 | ;; the Free Software Foundation, either version 3 of the License, or 12 | ;; (at your option) any later version. 13 | 14 | ;; This program is distributed in the hope that it will be useful, 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | ;; GNU General Public License for more details. 18 | 19 | ;; You should have received a copy of the GNU General Public License 20 | ;; along with this program. If not, see . 21 | 22 | ;;; Commentary: 23 | 24 | ;; The horror! M-x rainbow-paren-mode to start it. 25 | 26 | 27 | ;;; Code: 28 | 29 | ;; Too lazy to define my own functions for figuring out whether I'm in a string 30 | ;; or comment... 31 | (require 'paredit) 32 | (require 'cl) 33 | 34 | 35 | (defun rainbow-paren-face-from-colour (colour) 36 | (let ((face (make-face (intern (concat "rainbow-paren-" colour "-face"))))) 37 | (set-face-foreground face colour) 38 | face)) 39 | 40 | 41 | (defvar *rainbow-paren-faces* 42 | `[,(rainbow-paren-face-from-colour "dark red") 43 | ,(rainbow-paren-face-from-colour "dark green") 44 | ,(rainbow-paren-face-from-colour "deep pink") 45 | ,(rainbow-paren-face-from-colour "yellow") 46 | ,(rainbow-paren-face-from-colour "green") 47 | ,(rainbow-paren-face-from-colour "light blue") 48 | ,(rainbow-paren-face-from-colour "orange") 49 | ,(rainbow-paren-face-from-colour "slate blue") 50 | ,(rainbow-paren-face-from-colour "light gray") 51 | ,(rainbow-paren-face-from-colour "gold") 52 | ,(rainbow-paren-face-from-colour "turquoise")]) 53 | 54 | 55 | (defun rainbow-paren-this-paren-nesting () 56 | (let ((point (point)) 57 | (depth 0)) 58 | (while (ignore-errors 59 | (setq point (scan-lists point -1 1))) 60 | (when (= (char-after point) 40) 61 | (setq depth (1+ depth)))) 62 | depth)) 63 | 64 | 65 | (defun rainbow-paren-face-for-depth (n) 66 | (aref *rainbow-paren-faces* 67 | (mod n (length *rainbow-paren-faces*)))) 68 | 69 | 70 | (defun rainbow-paren-apply (point face) 71 | (let* ((os (overlays-at point)) 72 | (o (or (some (lambda (o) 73 | (and (eq (overlay-get o 'type) 'rainbow-paren) 74 | o)) 75 | os) 76 | (make-overlay point (1+ point) nil t nil)))) 77 | (overlay-put o 'type 'rainbow-paren) 78 | (overlay-put o 'face face) 79 | (overlay-put o 'evaporate t))) 80 | 81 | 82 | 83 | (defun rainbow-paren-boring-paren-p () 84 | (or (paredit-in-string-p) 85 | (paredit-in-comment-p))) 86 | 87 | 88 | (defun rainbow-paren-skip-boring (bound) 89 | (while (and (< (point) bound) 90 | (rainbow-paren-boring-paren-p)) 91 | (forward-char 1))) 92 | 93 | 94 | (defun rainbow-paren-fontify (beg end) 95 | (save-excursion 96 | (goto-char beg) 97 | (rainbow-paren-skip-boring end) 98 | (let* ((depth (rainbow-paren-this-paren-nesting))) 99 | (while (< (point) end) 100 | (rainbow-paren-skip-boring end) 101 | (cond ((= (char-after (point)) 40) 102 | (rainbow-paren-apply (point) 103 | (rainbow-paren-face-for-depth depth)) 104 | (setq depth (1+ depth))) 105 | ((= (char-after (point)) 41) 106 | (setq depth (1- depth)) 107 | (rainbow-paren-apply (point) 108 | (rainbow-paren-face-for-depth depth)))) 109 | (forward-char 1))))) 110 | 111 | 112 | (defun rainbow-paren-unfontify (beg end) 113 | (mapc #'(lambda (o) 114 | (when (eq (overlay-get o 'type) 'rainbow-paren) 115 | (delete-overlay o))) 116 | (overlays-in beg end))) 117 | 118 | 119 | (define-minor-mode rainbow-paren-mode 120 | "Angry fruit salad parens" 121 | nil " R" nil 122 | (cond ((not rainbow-paren-mode) 123 | (jit-lock-unregister 'rainbow-paren-fontify) 124 | (rainbow-paren-unfontify (point-min) (point-max))) 125 | (t (jit-lock-register 'rainbow-paren-fontify)))) 126 | 127 | 128 | 129 | (provide 'rainbow-parens) 130 | ;;; rainbow-parens.el ends here 131 | -------------------------------------------------------------------------------- /libs/rename-file.el: -------------------------------------------------------------------------------- 1 | (defun rename-this-buffer-and-file () 2 | "Renames current buffer and file it is visiting." 3 | (interactive) 4 | (let ((name (buffer-name)) 5 | (filename (buffer-file-name))) 6 | (if (not (and filename (file-exists-p filename))) 7 | (error "Buffer '%s' is not visiting a file!" name) 8 | (let ((new-name (read-file-name "New name: " filename))) 9 | (cond ((get-buffer new-name) 10 | (error "A buffer named '%s' already exists!" new-name)) 11 | (t 12 | (rename-file filename new-name 1) 13 | (rename-buffer new-name) 14 | (set-visited-file-name new-name) 15 | (set-buffer-modified-p nil) 16 | (message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name)))))))) 17 | -------------------------------------------------------------------------------- /libs/smooth-scrolling/smooth-scrolling.el: -------------------------------------------------------------------------------- 1 | ;; smooth-scrolling.el 2 | ;; $Id: smooth-scrolling.el,v 1.10 2009-12-19 01:45:28 adam Exp $ 3 | ;; Adam Spiers 4 | ;; 5 | ;; Make emacs scroll smoothly, keeping the point away from the top and 6 | ;; bottom of the current buffer's window in order to keep lines of 7 | ;; context around the point visible as much as possible, whilst 8 | ;; avoiding sudden scroll jumps which are visually confusing. 9 | ;; 10 | ;; This is a nice alternative to all the native scroll-* custom 11 | ;; variables, which unfortunately cannot provide this functionality 12 | ;; perfectly. `scroll-margin' comes closest, but has some bugs 13 | ;; (e.g. with handling of mouse clicks). See 14 | ;; 15 | ;; http://www.emacswiki.org/cgi-bin/wiki/SmoothScrolling 16 | ;; 17 | ;; for the gory details. 18 | ;; 19 | ;;;_* Installation 20 | ;; 21 | ;; Put somewhere on your `load-path' and include 22 | ;; 23 | ;; (require 'smooth-scrolling) 24 | ;; 25 | ;; in your .emacs initialization file. 26 | ;; 27 | ;;;_* Notes 28 | ;; 29 | ;; This only affects the behaviour of the `next-line' and 30 | ;; `previous-line' functions, usually bound to the cursor keys and 31 | ;; C-n/C-p, and repeated isearches (`isearch-repeat'). Other methods 32 | ;; of moving the point will behave as normal according to the standard 33 | ;; custom variables. 34 | ;; 35 | ;; Prefix arguments to `next-line' and `previous-line' are honoured. 36 | ;; The minimum number of lines are scrolled in order to keep the 37 | ;; point outside the margin. 38 | ;; 39 | ;; There is one case where moving the point in this fashion may cause 40 | ;; a jump: if the point is placed inside one of the margins by another 41 | ;; method (e.g. left mouse click, or M-x goto-line) and then moved in 42 | ;; the normal way, the advice code will scroll the minimum number of 43 | ;; lines in order to keep the point outside the margin. This jump may 44 | ;; cause some slight confusion at first, but hopefully it is justified 45 | ;; by the benefit of automatically ensuring `smooth-scroll-margin' 46 | ;; lines of context are visible around the point as often as possible. 47 | ;; 48 | ;;;_* TODO 49 | ;; 50 | ;; - Maybe add option to avoid scroll jumps when point is within 51 | ;; margin. 52 | ;; 53 | ;;;_* Acknowledgements 54 | ;; 55 | ;; Thanks to Mark Hulme-Jones and consolers on #emacs for helping 56 | ;; debug issues with line-wrapping. 57 | ;; 58 | ;;;_* License 59 | ;; 60 | ;; Released under the GNU General Public License v2 or later, with 61 | ;; all rights assigned to the Free Software Foundation. 62 | ;; 63 | 64 | ;;;_* Code follows 65 | ;;;_ + disable `scroll-margin' 66 | (setq scroll-margin 0) 67 | ;;;_ + defcustoms 68 | (defcustom smooth-scroll-margin 10 69 | "Number of lines of visible margin at the top and bottom of a window. 70 | If the point is within these margins, then scrolling will occur 71 | smoothly for `previous-line' at the top of the window, and for 72 | `next-line' at the bottom. 73 | 74 | This is very similar in its goal to `scroll-margin'. However, it 75 | is implemented by activating `smooth-scroll-down' and 76 | `smooth-scroll-up' advise via `defadvice' for `previous-line' and 77 | `next-line' respectively. As a result it avoids problems 78 | afflicting `scroll-margin', such as a sudden jump and unexpected 79 | highlighting of a region when the mouse is clicked in the margin. 80 | 81 | Scrolling only occurs when the point is closer to the window 82 | boundary it is heading for (top or bottom) than the middle of the 83 | window. This is to intelligently handle the case where the 84 | margins cover the whole buffer (e.g. `smooth-scroll-margin' set 85 | to 5 and `window-height' returning 10 or less). 86 | 87 | See also `smooth-scroll-strict-margins'." 88 | :type 'integer 89 | :group 'windows) 90 | 91 | (defcustom smooth-scroll-strict-margins t 92 | "If true, the advice code supporting `smooth-scroll-margin' 93 | will use `count-screen-lines' to determine the number of 94 | *visible* lines between the point and the window top/bottom, 95 | rather than `count-lines' which obtains the number of actual 96 | newlines. This is because there might be extra newlines hidden 97 | by a mode such as folding-mode, outline-mode, org-mode etc., or 98 | fewer due to very long lines being displayed wrapped when 99 | `truncate-lines' is nil. 100 | 101 | However, using `count-screen-lines' can supposedly cause 102 | performance issues in buffers with extremely long lines. Setting 103 | `cache-long-line-scans' may be able to address this; 104 | alternatively you can set this variable to nil so that the advice 105 | code uses `count-lines', and put up with the fact that sometimes 106 | the point will be allowed to stray into the margin." 107 | :type 'boolean 108 | :group 'windows) 109 | ;;;_ + helper functions 110 | (defun smooth-scroll-lines-from-window-top () 111 | "Work out, using the function indicated by 112 | `smooth-scroll-strict-margins', what the current screen line is, 113 | relative to the top of the window. Counting starts with 1 referring 114 | to the top line in the window." 115 | (interactive) 116 | (cond ((= (window-start) (point)) 117 | ;; In this case, count-screen-lines would return 0, so we override. 118 | 1) 119 | (smooth-scroll-strict-margins 120 | (count-screen-lines (window-start) (point) 'count-final-newline)) 121 | (t 122 | (count-lines (window-start) (point))))) 123 | 124 | (defun smooth-scroll-lines-from-window-bottom () 125 | "Work out, using the function indicated by 126 | `smooth-scroll-strict-margins', how many screen lines there are 127 | between the point and the bottom of the window. Counting starts 128 | with 1 referring to the bottom line in the window." 129 | (interactive) 130 | (if smooth-scroll-strict-margins 131 | (count-screen-lines (point) (window-end)) 132 | (count-lines (point) (window-end)))) 133 | ;;;_ + after advice 134 | 135 | (defun smooth-scroll-down () 136 | "Scroll down smoothly if cursor is within `smooth-scroll-margin' 137 | lines of the top of the window." 138 | (and 139 | ;; Only scroll down if there is buffer above the start of the window. 140 | (> (line-number-at-pos (window-start)) 1) 141 | (let ((lines-from-window-top 142 | (smooth-scroll-lines-from-window-top))) 143 | (and 144 | ;; Only scroll down if we're within the top margin 145 | (<= lines-from-window-top smooth-scroll-margin) 146 | ;; Only scroll down if we're in the top half of the window 147 | (<= lines-from-window-top 148 | ;; N.B. `window-height' includes modeline, so if it returned 21, 149 | ;; that would mean exactly 10 lines in the top half and 10 in 150 | ;; the bottom. 22 (or any even number) means there's one in the 151 | ;; middle. In both cases the following expression will 152 | ;; yield 10: 153 | (/ (1- (window-height)) 2)) 154 | (save-excursion 155 | (scroll-down 156 | (1+ (- smooth-scroll-margin lines-from-window-top)))))))) 157 | 158 | (defun smooth-scroll-up () 159 | "Scroll up smoothly if cursor is within `smooth-scroll-margin' 160 | lines of the bottom of the window." 161 | (and 162 | ;; Only scroll up if there is buffer below the end of the window. 163 | (< (window-end) (buffer-end 1)) 164 | (let ((lines-from-window-bottom 165 | (smooth-scroll-lines-from-window-bottom))) 166 | (and 167 | ;; Only scroll up if we're within the bottom margin 168 | (<= lines-from-window-bottom smooth-scroll-margin) 169 | ;; Only scroll up if we're in the bottom half of the window. 170 | (<= lines-from-window-bottom 171 | ;; See above notes on `window-height'. 172 | (/ (1- (window-height)) 2)) 173 | (save-excursion 174 | (scroll-up 175 | (1+ (- smooth-scroll-margin lines-from-window-bottom)))))))) 176 | 177 | (defadvice previous-line (after smooth-scroll-down 178 | (&optional arg try-vscroll) 179 | activate) 180 | (smooth-scroll-down)) 181 | (defadvice next-line (after smooth-scroll-up 182 | (&optional arg try-vscroll) 183 | activate) 184 | (smooth-scroll-up)) 185 | 186 | (defadvice isearch-repeat (after isearch-smooth-scroll 187 | (direction) 188 | activate) 189 | (if (eq direction 'forward) 190 | (smooth-scroll-up) 191 | (smooth-scroll-down))) 192 | 193 | ;;;_ + provide 194 | (provide 'smooth-scrolling) 195 | 196 | ;;;_* Local emacs variables 197 | 198 | ;;Local variables: 199 | ;;allout-layout: (0 : -1 0) 200 | ;;mode: allout 201 | ;;End: 202 | -------------------------------------------------------------------------------- /profiles/clojure.el: -------------------------------------------------------------------------------- 1 | (load-conf-file "clojure") 2 | -------------------------------------------------------------------------------- /profiles/coffee.el: -------------------------------------------------------------------------------- 1 | (load-conf-file "coffee") 2 | -------------------------------------------------------------------------------- /profiles/default.el: -------------------------------------------------------------------------------- 1 | (load-conf-file "string") 2 | (load-conf-file "solarized") 3 | (load-conf-file "align") 4 | (load-conf-file "auto-complete") 5 | (load-conf-file "appearance") 6 | (load-conf-file "basic") 7 | (load-conf-file "basic-bindings") 8 | (load-conf-file "linum") 9 | (load-conf-file "colorize-compilation") 10 | ;;(load-conf-file "colors") 11 | (load-conf-file "optimize") 12 | (load-conf-file "cmd") 13 | (load-conf-file "helm") 14 | (load-conf-file "dash") 15 | (load-conf-file "eshell") 16 | (load-conf-file "erc") 17 | (load-conf-file "expand-region") 18 | (load-conf-file "font") 19 | ;;(load-conf-file "git") 20 | (load-conf-file "ido") 21 | (load-conf-file "idomenu") 22 | (load-conf-file "indent") 23 | (load-conf-file "jade-mode") 24 | (load-conf-file "json") 25 | 26 | (load-conf-file "paredit") 27 | (load-conf-file "lisp") 28 | 29 | (load-conf-file "markdown") 30 | (load-conf-file "npm") 31 | (load-conf-file "css") 32 | ;;(load-conf-file "powerline") 33 | (load-conf-file "smex") 34 | (load-conf-file "smart-forward") 35 | (load-conf-file "undo-tree") 36 | (load-conf-file "yasnippet") 37 | (load-conf-file "zsh") 38 | (load-conf-file "zencoding") 39 | (load-conf-file "slim") 40 | (load-conf-file "fiplr") 41 | 42 | (load-conf-file "flycheck") 43 | (load-conf-file "web") 44 | -------------------------------------------------------------------------------- /profiles/golang.el: -------------------------------------------------------------------------------- 1 | (load-conf-file "golang") 2 | -------------------------------------------------------------------------------- /profiles/js.el: -------------------------------------------------------------------------------- 1 | (load-conf-file "js2") 2 | ;;(load-conf-file "js2-refactor") 3 | (load-conf-file "node") 4 | -------------------------------------------------------------------------------- /snippets/go-mode/&s: -------------------------------------------------------------------------------- 1 | &struct{ 2 | $1 3 | }{$0} 4 | -------------------------------------------------------------------------------- /snippets/go-mode/<<: -------------------------------------------------------------------------------- 1 | $1 = append(${1:theSlice}, ${2:theValue}) 2 | -------------------------------------------------------------------------------- /snippets/go-mode/as: -------------------------------------------------------------------------------- 1 | assert.${1:Equal}(t, $0) 2 | -------------------------------------------------------------------------------- /snippets/go-mode/aserr: -------------------------------------------------------------------------------- 1 | assert.Nil(t, ${0:err}) 2 | -------------------------------------------------------------------------------- /snippets/go-mode/asf: -------------------------------------------------------------------------------- 1 | assert.False(t, $0) 2 | -------------------------------------------------------------------------------- /snippets/go-mode/asn: -------------------------------------------------------------------------------- 1 | assert.Nil(t, $0) 2 | -------------------------------------------------------------------------------- /snippets/go-mode/ast: -------------------------------------------------------------------------------- 1 | assert.True(t, $0) 2 | -------------------------------------------------------------------------------- /snippets/go-mode/c: -------------------------------------------------------------------------------- 1 | func $1(c *echo.Context) error { 2 | $0 3 | return nil 4 | } 5 | -------------------------------------------------------------------------------- /snippets/go-mode/c.JSON: -------------------------------------------------------------------------------- 1 | c.JSON(http.$1, $0) 2 | -------------------------------------------------------------------------------- /snippets/go-mode/cstring: -------------------------------------------------------------------------------- 1 | #name : CString 2 | # expand-env: ((yas/indent-line 'fixed)) 3 | # -- 4 | c${1:$(capitalize yas/text)} := C.CString($1) 5 | defer C.free(unsafe.Pointer(c${1:$(capitalize yas/text)})) 6 | 7 | -------------------------------------------------------------------------------- /snippets/go-mode/e: -------------------------------------------------------------------------------- 1 | if err != nil { 2 | return ${0:err} 3 | } 4 | -------------------------------------------------------------------------------- /snippets/go-mode/err: -------------------------------------------------------------------------------- 1 | if err != nil { 2 | $0 3 | } -------------------------------------------------------------------------------- /snippets/go-mode/errif: -------------------------------------------------------------------------------- 1 | if $1 { 2 | return $2errors.New("$3") 3 | } 4 | -------------------------------------------------------------------------------- /snippets/go-mode/f: -------------------------------------------------------------------------------- 1 | func $1($2) $3 { 2 | $0 3 | } 4 | -------------------------------------------------------------------------------- /snippets/go-mode/ferr: -------------------------------------------------------------------------------- 1 | func $1($2) error { 2 | $0 3 | return nil 4 | } 5 | -------------------------------------------------------------------------------- /snippets/go-mode/for: -------------------------------------------------------------------------------- 1 | #name : for (...; ...; ...) { ... } 2 | # -- 3 | for $1 { 4 | $0 5 | } 6 | -------------------------------------------------------------------------------- /snippets/go-mode/func: -------------------------------------------------------------------------------- 1 | func ${1:name}(${2:arguments}) (${3:results}) { 2 | $0 3 | } -------------------------------------------------------------------------------- /snippets/go-mode/i: -------------------------------------------------------------------------------- 1 | import ( 2 | "$1" 3 | ) 4 | -------------------------------------------------------------------------------- /snippets/go-mode/iferr: -------------------------------------------------------------------------------- 1 | if err := $1; err != nil { 2 | ${0:return err} 3 | } 4 | -------------------------------------------------------------------------------- /snippets/go-mode/ifunc: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: ifunc 3 | # -- 4 | func ($1) $2 { 5 | $0 6 | } -------------------------------------------------------------------------------- /snippets/go-mode/imp: -------------------------------------------------------------------------------- 1 | import ( 2 | "$1" 3 | ) -------------------------------------------------------------------------------- /snippets/go-mode/init: -------------------------------------------------------------------------------- 1 | func init() { 2 | $0 3 | } 4 | -------------------------------------------------------------------------------- /snippets/go-mode/j: -------------------------------------------------------------------------------- 1 | \`json:"$0"\` 2 | -------------------------------------------------------------------------------- /snippets/go-mode/jf: -------------------------------------------------------------------------------- 1 | $1 $2 \`json:"${1:$(s-snake-case yas-text)}"\` 2 | -------------------------------------------------------------------------------- /snippets/go-mode/json: -------------------------------------------------------------------------------- 1 | \`json:"$1"\` -------------------------------------------------------------------------------- /snippets/go-mode/m: -------------------------------------------------------------------------------- 1 | func (${1:$(s-lower-camel-case yas-text)} *$1) $2($3) $4 { 2 | $0 3 | } 4 | -------------------------------------------------------------------------------- /snippets/go-mode/main: -------------------------------------------------------------------------------- 1 | #name: func main 2 | # -- 3 | func main() { 4 | $0 5 | } -------------------------------------------------------------------------------- /snippets/go-mode/map: -------------------------------------------------------------------------------- 1 | map[${1:keytype}]${2:valuetype} -------------------------------------------------------------------------------- /snippets/go-mode/merr: -------------------------------------------------------------------------------- 1 | func ($1 *${1:$(capitalize yas-text)}) $2($3) error { 2 | $0 3 | } 4 | -------------------------------------------------------------------------------- /snippets/go-mode/meth: -------------------------------------------------------------------------------- 1 | func (${1:target}) ${2:name}(${3:arguments}) (${4:results}) { 2 | $0 3 | } -------------------------------------------------------------------------------- /snippets/go-mode/n: -------------------------------------------------------------------------------- 1 | ${1:$(s-lower-camel-case yas-text)} *$1 2 | -------------------------------------------------------------------------------- /snippets/go-mode/p: -------------------------------------------------------------------------------- 1 | package ${1:`(car (last (split-string (file-name-directory buffer-file-name) "/") 2))`} 2 | -------------------------------------------------------------------------------- /snippets/go-mode/pkg: -------------------------------------------------------------------------------- 1 | package ${1:`(car (last (split-string (file-name-directory buffer-file-name) "/") 2))`} 2 | -------------------------------------------------------------------------------- /snippets/go-mode/range: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: range 3 | # -- 4 | for ${1:_}, ${2:$(substring yas-text 0 1)} := range ${2:list} { 5 | $0 6 | } -------------------------------------------------------------------------------- /snippets/go-mode/sort: -------------------------------------------------------------------------------- 1 | func (${1:$(s-lower-camel-case yas-text)} $1) Len() int { 2 | return len(${1:$(s-lower-camel-case yas-text)}) 3 | } 4 | 5 | func (${1:$(s-lower-camel-case yas-text)} $1) Swap(i, j int) { 6 | ${1:$(s-lower-camel-case yas-text)}[i], ${1:$(s-lower-camel-case yas-text)}[j] = ${1:$(s-lower-camel-case yas-text)}[j], ${1:$(s-lower-camel-case yas-text)}[i] 7 | } 8 | 9 | func (${1:$(s-lower-camel-case yas-text)} $1) Less(i, j int) bool { 10 | return ${1:$(s-lower-camel-case yas-text)}[i].$2 < ${1:$(s-lower-camel-case yas-text)}[j].$2 11 | } 12 | -------------------------------------------------------------------------------- /snippets/go-mode/st: -------------------------------------------------------------------------------- 1 | #name : struct 2 | # -- 3 | type $1 struct { 4 | $0 5 | } 6 | -------------------------------------------------------------------------------- /snippets/go-mode/struct: -------------------------------------------------------------------------------- 1 | #name : struct 2 | # -- 3 | type $1 struct { 4 | $0 5 | } -------------------------------------------------------------------------------- /snippets/go-mode/test: -------------------------------------------------------------------------------- 1 | func Test$1(t *testing.T) { 2 | $0 3 | } -------------------------------------------------------------------------------- /snippets/go-mode/xml: -------------------------------------------------------------------------------- 1 | \`xml:"$1"\` -------------------------------------------------------------------------------- /snippets/js2-mode/act.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: action 3 | # key: act 4 | # -- 5 | 6 | const $1 = '$1'; 7 | 8 | export default function ${1:$(s-lower-camel-case yas-text)} () { 9 | return { 10 | type: $1, 11 | $0 12 | } 13 | } -------------------------------------------------------------------------------- /snippets/js2-mode/after.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: after 3 | # key: after 4 | # -- 5 | after(function(${3:done}){ 6 | $0 7 | }); 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/afterEach.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: afterEach 3 | # key: afterEach 4 | # -- 5 | afterEach(function(${3:done}){ 6 | $0 7 | }); 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/assert.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: assert 3 | # key: assert 4 | # -- 5 | assert.${1:equal}($0); 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/before.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: before 3 | # key: before 4 | # -- 5 | before(function(${3:done}){ 6 | $0 7 | }); 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/beforeEach.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: beforeEach 3 | # key: beforeEach 4 | # -- 5 | beforeEach(function(${3:done}){ 6 | $0 7 | }); 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/build.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: build 3 | # key: build 4 | # -- 5 | build("${1:name}", $2function (b) { 6 | $0 7 | }); 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/cb.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: $1($2, function(){ ... 3 | # key: cb 4 | # -- 5 | $1($2, function(error, ${3:value}){ 6 | 7 | if(error) return callback(error); 8 | 9 | $0 10 | }); 11 | -------------------------------------------------------------------------------- /snippets/js2-mode/com.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: com 3 | # key: com 4 | # -- 5 | 6 | /** 7 | * $0 8 | * @param {${1:String}} $2 9 | * @return {${3:String}} 10 | */ 11 | -------------------------------------------------------------------------------- /snippets/js2-mode/deps.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: dependencies: {} 3 | # key: deps 4 | # -- 5 | "dependencies": { 6 | "$2": "${3:0.x}"$0 7 | }, 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/describe.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: desc 3 | # key: desc 4 | # -- 5 | describe('$1', function(){ 6 | $2 7 | }); 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/devdeps.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: devDependencies: {} 3 | # key: deps 4 | # -- 5 | "devDependencies": { 6 | "$2": "${3:0.x}"$0 7 | }, 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/e.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: module.exports = 3 | # key: e 4 | # -- 5 | module.exports = $1; 6 | $0 7 | -------------------------------------------------------------------------------- /snippets/js2-mode/err-one-liner.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: if(error) return callback(error); 3 | # key: err 4 | # -- 5 | if(error) return callback(error);$0 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/err-throw.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: if(error) throw (error); 3 | # key: err 4 | # -- 5 | if(error) throw error;$0 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/err.snippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: if(error){ callback(error); return; } 3 | # key: err 4 | # -- 5 | if(${1:error}){ 6 | callback($1); 7 | return; 8 | } 9 | $0 10 | -------------------------------------------------------------------------------- /snippets/js2-mode/error.snippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: error 3 | # key: error 4 | # -- 5 | if(${1:error}){ 6 | callback($1); 7 | return; 8 | } 9 | $2 10 | -------------------------------------------------------------------------------- /snippets/js2-mode/exp.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: exports.$1 = $0 3 | # key: exp 4 | # -- 5 | exports.$1 = $0 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/expect-error.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: expect(error).to.not.exist 3 | # key: error 4 | # -- 5 | expect(error).to.not.exist; 6 | $0 7 | -------------------------------------------------------------------------------- /snippets/js2-mode/expect.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: expect 3 | # key: expect 4 | # -- 5 | expect($1).to.${2:equal}$3; 6 | $0 -------------------------------------------------------------------------------- /snippets/js2-mode/exports-obj.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: module.exports = {} 3 | # key: exp 4 | # -- 5 | module.exports = { 6 | $1: $1$0 7 | }; 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/exports.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: module.exports = $0 3 | # key: exp 4 | # -- 5 | module.exports = $0 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/f.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: function () {} 3 | # key: f 4 | # -- 5 | function ($1) { 6 | $0 7 | } 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/fn.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: function name () {} 3 | # key: fn 4 | # -- 5 | function $1 ($2) { 6 | $0 7 | } 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/for.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: for 3 | # key: for 4 | # -- 5 | var ${1:i} = ${2:-1}, len = $3.length; 6 | 7 | for(; ++$1 < len;){ 8 | $4 9 | } 10 | -------------------------------------------------------------------------------- /snippets/js2-mode/id.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: id 3 | # key: id 4 | # -- 5 | document.getElementById('$0'); 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/if.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: if 3 | # key: if 4 | # -- 5 | if (${1}) { 6 | $0 7 | } 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/invoc.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: invoc 3 | # key: invoc 4 | # -- 5 | (function($1){ 6 | $0 7 | })($2); 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/it.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: it 3 | # key: it 4 | # -- 5 | it('$1', function(${3:done}){ 6 | $0 7 | }); 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/log.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: log 3 | # key: log 4 | # -- 5 | console.${1:log}( $0 ); 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/m.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: m 3 | # key: m 4 | # -- 5 | 6 | $1($2) { 7 | $0 8 | } -------------------------------------------------------------------------------- /snippets/js2-mode/method.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: method 3 | # key: method 4 | # -- 5 | $1.prototype.$2 = function($3){ 6 | ${0} 7 | }; 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/mod-debug.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: module-with-debug 3 | # key: new 4 | # -- 5 | var debug = require("${1:debug}")("$2")$3 6 | 7 | module.exports = ${4:$2}; 8 | 9 | $5 10 | -------------------------------------------------------------------------------- /snippets/js2-mode/mod-exp.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: module.exports.$1 = $0 3 | # key: exp 4 | # -- 5 | module.exports.$1 = $0 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/mod.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: module 3 | # key: new 4 | # -- 5 | var $1 = require("${2:$1}")$3 6 | 7 | module.exports = { 8 | $4: $4$5 9 | }; -------------------------------------------------------------------------------- /snippets/js2-mode/new-err.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: new Error(..); 3 | # key: err 4 | # -- 5 | new Error($1); 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/next.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: process.nextTick 3 | # key: next 4 | # -- 5 | process.nextTick(function(){ 6 | $0 7 | }); 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/prop.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: prop 3 | # key: prop 4 | # -- 5 | 6 | var $1 = (function(){ 7 | 8 | var value = undefined; 9 | 10 | return function $1(newValue){ 11 | 12 | if( $1.arguments.length > 0 ){ 13 | value = newValue; 14 | } 15 | 16 | return value; 17 | }; 18 | 19 | })(); 20 | -------------------------------------------------------------------------------- /snippets/js2-mode/proto.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: proto 3 | # key: proto 4 | # -- 5 | $1.prototype.$2 = $0 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/r.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: require 3 | # key: r 4 | # -- 5 | var $1 = require("${2:$1}"); 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/rq.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: require("$1") 3 | # key: rq 4 | # -- 5 | $1 = require("${2:$1}")$0 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/rt.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: rt 3 | # key: rt 4 | # -- 5 | return$0; 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/select-all.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: querySelectorAll 3 | # key: sel 4 | # -- 5 | ${1:document}.querySelectorAll('$0') 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/select.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: querySelector 3 | # key: sel 4 | # -- 5 | ${1:document}.querySelector('$0') 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/should.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: .should.be.equal 3 | # key: should 4 | # -- 5 | $1.should.be.${2:equal}$0 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/slice.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: slice 3 | # key: slice 4 | # -- 5 | Array.prototype.slice.${1:call}($0); 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/super.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: super 3 | # key: super 4 | # -- 5 | $1.prototype.${2:constructor}.${3:call}($0); 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/switch.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: switch 3 | # key: switch 4 | # -- 5 | switch($1){ 6 | $0 7 | }; 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/task.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: task 3 | # key: task 4 | # -- 5 | task("${1:name}", $2function (t) { 6 | $0 7 | }); 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/test.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: test 3 | # key: test 4 | # -- 5 | test('$1', function (t) { 6 | $2 7 | }); 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/throw.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: throw new Error($1); 3 | # key: err 4 | # -- 5 | throw new Error("$1"); 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/try.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: try 3 | # key: try 4 | # -- 5 | try { 6 | $1 7 | } catch(error) { 8 | $0 9 | } 10 | -------------------------------------------------------------------------------- /snippets/js2-mode/v.snippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: var 3 | # key: v 4 | # -- 5 | var $1 = $2; 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/var-rq.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: var $1 = require("...") 3 | # key: rq 4 | # -- 5 | var $1 = require("${2:$1}")$0 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/var.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: var 3 | # key: var 4 | # -- 5 | var $1 = $0 6 | -------------------------------------------------------------------------------- /snippets/js2-mode/wh.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: wh 3 | # key: wh 4 | # -- 5 | while($1){ 6 | $0 7 | } 8 | -------------------------------------------------------------------------------- /snippets/js2-mode/while.yasnippet: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: while 3 | # key: while 4 | # -- 5 | 6 | var i = $1.length; 7 | 8 | while( i -- ){ 9 | $0 10 | } --------------------------------------------------------------------------------