2014-08-09 19:25:06 -04:00
|
|
|
;;;; Macros ;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
(defmacro λ (&rest body)
|
|
|
|
`(lambda () (interactive) ,@body))
|
|
|
|
|
|
|
|
;; vimmish keymapping shortcuts
|
|
|
|
(defmacro nmap (map &rest body)
|
|
|
|
`(evil-define-key 'normal ,map ,@body))
|
|
|
|
(defmacro vmap (map &rest body)
|
|
|
|
`(evil-define-key 'visual ,map ,@body))
|
|
|
|
(defmacro imap (map &rest body)
|
|
|
|
`(evil-define-key 'insert ,map ,@body))
|
|
|
|
(defmacro emap (map &rest body)
|
|
|
|
`(evil-define-key 'emacs ,map ,@body))
|
2014-08-21 03:33:30 -04:00
|
|
|
(defmacro nvmap (map &rest body)
|
2014-08-24 06:26:22 -04:00
|
|
|
`(progn (evil-define-key 'normal ,map ,@body)
|
|
|
|
(evil-define-key 'visual ,map ,@body)))
|
2014-08-09 19:25:06 -04:00
|
|
|
|
|
|
|
;; insert-mode key-chord mapping
|
|
|
|
(defmacro ichmap (key command)
|
|
|
|
`(key-chord-define evil-insert-state-map ,key ,command))
|
|
|
|
|
|
|
|
;;;; Commands ;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; File navigation defuns
|
|
|
|
(defun my/initfiles ()
|
2014-08-10 03:15:16 -04:00
|
|
|
"Do an ido-find in ~/.emacs.d"
|
2014-08-09 19:25:06 -04:00
|
|
|
(interactive)
|
|
|
|
(ido-find-file-in-dir my/dir))
|
|
|
|
|
|
|
|
(defun my/open-scratch ()
|
2014-08-10 03:15:16 -04:00
|
|
|
"Open a blank scratch buffer"
|
2014-08-09 19:25:06 -04:00
|
|
|
(interactive)
|
|
|
|
(switch-to-buffer (get-buffer-create "*scratch*"))
|
|
|
|
(text-mode))
|
|
|
|
|
|
|
|
(defun my/byte-recompile ()
|
2014-08-10 03:15:16 -04:00
|
|
|
"Byte compile init.el, ~/.emacs.d/init/* and ~/.emacs.d/elisp/*"
|
2014-08-09 19:25:06 -04:00
|
|
|
(interactive)
|
2014-08-13 00:32:27 -04:00
|
|
|
(byte-recompile-file (expand-file-name "init.el" my/dir) t)
|
|
|
|
(byte-recompile-directory my/init-dir 0 t)
|
|
|
|
(byte-recompile-directory my/elisp-dir 0 t))
|
2014-08-09 19:25:06 -04:00
|
|
|
|
|
|
|
(defun my/notes()
|
|
|
|
"Load up my notes folder in dropbox"
|
|
|
|
(interactive)
|
|
|
|
(ido-find-file-in-dir "~/Dropbox/notes"))
|
|
|
|
|
|
|
|
(defun my/kill-all-buffers ()
|
2014-08-10 03:15:16 -04:00
|
|
|
"Kill all buffers, even the one you're in"
|
2014-08-09 19:25:06 -04:00
|
|
|
(interactive)
|
2014-08-13 02:48:49 -04:00
|
|
|
(delete-other-windows)
|
2014-08-09 19:25:06 -04:00
|
|
|
(mapc 'kill-buffer (buffer-list))
|
|
|
|
(message "All buffers killed"))
|
|
|
|
|
|
|
|
(defun my/kill-other-buffers ()
|
2014-08-10 03:15:16 -04:00
|
|
|
"Kill all buffers but the one you're in"
|
2014-08-09 19:25:06 -04:00
|
|
|
(interactive)
|
2014-08-13 02:48:49 -04:00
|
|
|
(delete-other-windows)
|
2014-08-09 19:25:06 -04:00
|
|
|
(mapc 'kill-buffer (cdr (buffer-list (current-buffer))))
|
|
|
|
(message "All other buffers killed"))
|
|
|
|
|
2014-08-21 03:33:30 -04:00
|
|
|
(defun my/kill-dired-buffers ()
|
|
|
|
(interactive)
|
|
|
|
(mapc (lambda (buffer)
|
|
|
|
(when (eq 'dired-mode (buffer-local-value 'major-mode buffer))
|
|
|
|
(kill-buffer buffer)))
|
|
|
|
(buffer-list)))
|
2014-08-09 19:25:06 -04:00
|
|
|
|
2014-08-13 00:24:22 -04:00
|
|
|
(defun my/recentf-ido-find-file ()
|
|
|
|
"Find a recent file using ido."
|
|
|
|
(interactive)
|
|
|
|
(let ((file (ido-completing-read "Choose recent file: " recentf-list nil t)))
|
|
|
|
(when file
|
|
|
|
(find-file file))))
|
|
|
|
|
|
|
|
(defun my/ido-goto-symbol (&optional symbol-list)
|
|
|
|
"Refresh imenu and jump to a place in the buffer using Ido."
|
|
|
|
(interactive)
|
|
|
|
(unless (featurep 'imenu)
|
|
|
|
(require 'imenu nil t))
|
|
|
|
(cond
|
|
|
|
((not symbol-list)
|
|
|
|
(let ((ido-mode ido-mode)
|
|
|
|
(ido-enable-flex-matching
|
|
|
|
(if (boundp 'ido-enable-flex-matching)
|
|
|
|
ido-enable-flex-matching t))
|
|
|
|
name-and-pos symbol-names position)
|
|
|
|
(unless ido-mode
|
|
|
|
(ido-mode 1)
|
|
|
|
(setq ido-enable-flex-matching t))
|
|
|
|
(while (progn
|
|
|
|
(imenu--cleanup)
|
|
|
|
(setq imenu--index-alist nil)
|
|
|
|
(my/ido-goto-symbol (imenu--make-index-alist))
|
|
|
|
(setq selected-symbol
|
|
|
|
(ido-completing-read "Symbol? " symbol-names))
|
|
|
|
(string= (car imenu--rescan-item) selected-symbol)))
|
|
|
|
(unless (and (boundp 'mark-active) mark-active)
|
|
|
|
(push-mark nil t nil))
|
|
|
|
(setq position (cdr (assoc selected-symbol name-and-pos)))
|
|
|
|
(cond
|
|
|
|
((overlayp position)
|
|
|
|
(goto-char (overlay-start position)))
|
|
|
|
(t
|
|
|
|
(goto-char position)))))
|
|
|
|
((listp symbol-list)
|
|
|
|
(dolist (symbol symbol-list)
|
|
|
|
(let (name position)
|
|
|
|
(cond
|
|
|
|
((and (listp symbol) (imenu--subalist-p symbol))
|
|
|
|
(my/ido-goto-symbol symbol))
|
|
|
|
((listp symbol)
|
|
|
|
(setq name (car symbol))
|
|
|
|
(setq position (cdr symbol)))
|
|
|
|
((stringp symbol)
|
|
|
|
(setq name symbol)
|
|
|
|
(setq position
|
|
|
|
(get-text-property 1 'org-imenu-marker symbol))))
|
|
|
|
(unless (or (null position) (null name)
|
|
|
|
(string= (car imenu--rescan-item) name))
|
|
|
|
(add-to-list 'symbol-names name)
|
|
|
|
(add-to-list 'name-and-pos (cons name position))))))))
|
|
|
|
|
2014-08-21 03:33:30 -04:00
|
|
|
;;;; Hooks ;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
(defun my/enable-hard-wrap()
|
|
|
|
(auto-fill-mode 1)
|
|
|
|
(diminish 'auto-fill-function))
|
|
|
|
|
|
|
|
(defun my/enable-comment-hard-wrap ()
|
|
|
|
(set (make-local-variable 'comment-auto-fill-only-comments) t)
|
|
|
|
(auto-fill-mode 1)
|
|
|
|
(diminish 'auto-fill-function))
|
|
|
|
|
2014-08-09 19:25:06 -04:00
|
|
|
(defun my/ac-ruby-setup()
|
|
|
|
"Set up RSense and ac-sources"
|
|
|
|
(setq ac-sources (append '(ac-source-rsense ac-source-yasnippet) ac-sources)))
|
|
|
|
|
|
|
|
(defun my/ac-files-setup()
|
|
|
|
"Set up filepath completion sources"
|
|
|
|
(setq ac-sources (append '(ac-source-filename ac-source-files-in-current-dir) ac-sources)))
|
|
|
|
|
|
|
|
(defun my/setup-run-code(mode interpreter)
|
2014-08-10 03:15:16 -04:00
|
|
|
"Set up s-r to run code using a specified interpreter and print the
|
|
|
|
output in the echo area"
|
2014-08-21 03:33:30 -04:00
|
|
|
(nmap mode (kbd ",r")
|
|
|
|
`(lambda()
|
|
|
|
(interactive)
|
|
|
|
(if (file-exists-p (buffer-file-name))
|
|
|
|
(shell-command (concat ,interpreter " " (buffer-file-name)))
|
|
|
|
(shell-command-on-region (point-min) (point-max) ,interpreter))))
|
|
|
|
(vmap mode (kbd ",r")
|
2014-08-13 00:24:22 -04:00
|
|
|
`(lambda() (interactive) (shell-command-on-region (region-beginning) (region-end) ,interpreter))))
|
|
|
|
|
|
|
|
;;;; Tmux defuns ;;;;;;;;;;;;;;;;;
|
2014-08-21 03:33:30 -04:00
|
|
|
(defun my/tmux-run (command)
|
|
|
|
"Run command in tmux"
|
|
|
|
(interactive
|
|
|
|
(list
|
|
|
|
(read-shell-command "Tmux command: " nil nil
|
|
|
|
(let ((filename (cond (buffer-file-name)
|
|
|
|
((eq major-mode 'dired-mode)
|
|
|
|
(dired-get-filename nil t)))))
|
|
|
|
(and filename (file-relative-name filename))))))
|
|
|
|
|
|
|
|
(shell-command (concat "/usr/local/bin/tmux send-keys C-u " (shell-quote-argument command) " Enter"))
|
|
|
|
;; (call-process "/usr/local/bin/tmux" nil nil nil "C-u" "send-keys" command "C-m")
|
2014-08-13 00:24:22 -04:00
|
|
|
(message "Tmux: Command sent!"))
|
|
|
|
|
2014-08-21 03:33:30 -04:00
|
|
|
(defun my/tmux-paste (command)
|
|
|
|
(interactive "sSend to Tmux: ")
|
|
|
|
(shell-command (concat "/usr/local/bin/tmux send-keys " command))
|
|
|
|
(message "Tmux: Text pasted!"))
|
|
|
|
|
2014-08-13 00:24:22 -04:00
|
|
|
(defun my/tmux-chdir(dir)
|
2014-08-21 03:33:30 -04:00
|
|
|
"CD into a new directory in tmux"
|
2014-08-13 00:24:22 -04:00
|
|
|
(interactive "DDirectory: ")
|
2014-08-21 03:33:30 -04:00
|
|
|
(my/tmux-run (concat "cd " (shell-quote-argument dir)))
|
2014-08-13 00:24:22 -04:00
|
|
|
(message "Tmux: Directory changed!"))
|
2014-08-09 19:25:06 -04:00
|
|
|
|
|
|
|
;;;; Mac-specific Defuns ;;;;;;;;;
|
|
|
|
(when is-mac
|
|
|
|
;; Send current file to OSX apps
|
|
|
|
(defun open-file-with (path &optional appName)
|
2014-08-21 03:33:30 -04:00
|
|
|
(if (and appName
|
|
|
|
(stringp appName)
|
|
|
|
(not (string= "" appName)))
|
2014-08-09 19:25:06 -04:00
|
|
|
(setq appName (concat "-a " appName ".app")))
|
2014-08-21 03:33:30 -04:00
|
|
|
(shell-command (concat "open " appName " " (shell-quote-argument path))))
|
2014-08-09 19:25:06 -04:00
|
|
|
|
|
|
|
(defun open-with (appName)
|
2014-08-21 03:33:30 -04:00
|
|
|
(interactive "sApp name: ")
|
|
|
|
(open-file-with buffer-file-name appName))
|
2014-08-09 19:25:06 -04:00
|
|
|
|
|
|
|
(defun send-to-transmit () (interactive) (open-with "Transmit"))
|
|
|
|
(defun send-to-launchbar () (interactive) (open-with "LaunchBar"))
|
|
|
|
(defun send-dir-to-launchbar () (interactive) (open-file-with default-directory "LaunchBar"))
|
|
|
|
(defun send-dir-to-finder () (interactive) (open-file-with default-directory "Finder")))
|
|
|
|
|
|
|
|
;;
|
|
|
|
(provide 'my-defuns)
|