Skip to content

Instantly share code, notes, and snippets.

@michiakig
Last active October 13, 2015 23:38
Show Gist options
  • Save michiakig/4274011 to your computer and use it in GitHub Desktop.
Save michiakig/4274011 to your computer and use it in GitHub Desktop.
;; package.el stuff
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
(defvar my-packages '(color-theme-solarized magit smex sml-mode))
(dolist (p my-packages)
(when (not (package-installed-p p))
(package-install p)))
;; basic stuff
(tool-bar-mode -1) ; hide toolbar
(scroll-bar-mode -1) ; hide scrollbar
(setq initial-buffer-choice t) ; open *scratch* on launch
(setq ring-bell-function 'ignore)
(load-theme 'solarized-dark t)
(setq-default indent-tabs-mode nil)
(setq backup-directory-alist `(("." . "~/.saves")))
;; mac os x specific stuff
(when (equal system-type 'darwin)
(setq mac-command-modifier 'meta)
(set-default-font "Menlo")
(let ((path-from-shell
(replace-regexp-in-string "[[:space:]\n]*$" ""
(shell-command-to-string "$SHELL -l -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
;; ido
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode 1)
(ido-mode t)
;; smex
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
;; emacsclient
(server-start)
(eval-when-compile (require 'cl))
(defun sml-smie-rules (kind token)
(let ((indent
(case kind
(:elem 0)
(:list-intro (member token '("fn")))
(:after
(cond
((member token '("d=" "of" "in" "local" "let" "sig" "struct")) 3)
;; ((equal token "=>") (if (smie-rule-hanging-p) 0 2))
;; ((member token '("(" "{" "[")) (if (not (smie-rule-hanging-p)) 2))
;; ((equal token "else") (if (smie-rule-hanging-p) 0)) ;; (:next "if" 0)
;; ((member token '("|" "d|" ";" ",")) (smie-rule-separator kind))
(t 0)))
(:before
(cond
((equal token "andalso") 0)
((equal token "then") 3)
((equal token "=>") (if (smie-rule-parent-p "fn") 3))
;; In case the language is extended to allow a | directly after of.
((and (equal token "|") (smie-rule-prev-p "of")) 1)
((member token '("|" "d|" ";" ",")) (smie-rule-separator kind))
;; Treat purely syntactic block-constructs as being part of their parent,
;; when the opening statement is hanging.
((member token '("let" "(" "[" "{"))
(if (smie-rule-hanging-p) (smie-rule-parent)))
;; Treat if ... else if ... as a single long syntactic construct.
;; Similarly, treat fn a => fn b => ... as a single construct.
((member token '("if" "fn"))
(and (not (smie-rule-bolp))
(smie-rule-prev-p (if (equal token "if") "else" "=>"))
(smie-rule-parent)))
((equal token "and")
;; FIXME: maybe "and" (c|sh)ould be handled as an smie-separator.
(cond
((smie-rule-parent-p "datatype") (if sml-rightalign-and 5 0))
((smie-rule-parent-p "fun" "val") 0)))
((equal token "d=") 0)
;; Indent an expression starting with "local" as if it were starting
;; with "fun".
((equal token "local") (smie-indent-keyword "fun"))
;; FIXME: type/val/fun/... are separators but "local" is not, even though
;; it appears in the same list. Try to fix up the problem by hand.
;; ((or (equal token "local")
;; (equal (cdr (assoc token smie-grammar))
;; (cdr (assoc "fun" smie-grammar))))
;; (let ((parent (save-excursion (smie-backward-sexp))))
;; (when (or (and (equal (nth 2 parent) "local")
;; (null (car parent)))
;; (progn
;; (setq parent (save-excursion (smie-backward-sexp "fun")))
;; (eq (car parent) (nth 1 (assoc "fun" smie-grammar)))))
;; (goto-char (nth 1 parent))
;; (cons 'column (smie-indent-virtual)))))
(t 0)
)))))
(message "sml-smie-rules %s %s %s" kind token indent)
indent))
(setq sml-mode-hook nil)
;; (add-hook 'sml-mode-hook (lambda ()
;; (defun sml-smie-rules (kind token)
;; (let ((indent (_sml-smie-rules kind token)))
;; (message "sml-smie-rules %s %s %s" kind token indent)
;; indent))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment