;; Execute Ruby Code (defun is-rails-project () (when (textmate-project-root) (file-exists-p (expand-file-name "config/environment.rb" (textmate-project-root))))) (defun run-rails-test-or-ruby-buffer () (interactive) (if (is-rails-project) (let* ((path (buffer-file-name)) (filename (file-name-nondirectory path)) (test-path (expand-file-name "test" (textmate-project-root))) (command (list ruby-compilation-executable "-I" test-path path))) (pop-to-buffer (ruby-compilation-do filename command))) (ruby-compilation-this-buffer))) ;; Auto-indent on Paste (dolist (command '(yank yank-pop)) (eval `(defadvice ,command (after indent-region activate) (and (not current-prefix-arg) (member major-mode '(emacs-lisp-mode lisp-mode clojure-mode scheme-mode haskell-mode ruby-mode rspec-mode python-mode c-mode c++-mode objc-mode latex-mode plain-tex-mode)) (let ((mark-even-if-inactive transient-mark-mode)) (indent-region (region-beginning) (region-end) nil)))))) ;; Duplicate Line (defun duplicate-line() (interactive) (move-beginning-of-line 1) (kill-line) (yank) (newline) (yank)) ;; Yank Pop Forwards (defun yank-pop-forwards (arg) (interactive "p") (yank-pop (- arg))) ;; Window Switching (defun other-window-reverse () "Switch to the previous window" (interactive) (other-window -1)) ;; Window Swapping (from https://gist.github.com/287633) (defun swap-with (dir) (interactive) (let ((other-window (windmove-find-other-window dir))) (when other-window (let* ((this-window (selected-window)) (this-buffer (window-buffer this-window)) (other-buffer (window-buffer other-window)) (this-start (window-start this-window)) (other-start (window-start other-window))) (set-window-buffer this-window other-buffer) (set-window-buffer other-window this-buffer) (set-window-start this-window other-start) (set-window-start other-window this-start))))) ;; Transparency (defun transparency-set-initial-value () "Set initial value of alpha parameter for the current frame" (interactive) (if (equal (frame-parameter nil 'alpha) nil) (set-frame-parameter nil 'alpha 100))) (defun transparency-set-value (numb) "Set level of transparency for the current frame" (interactive "nEnter transparency level in range 0-100: ") (if (> numb 100) (message "Error! The maximum value for transparency is 100!") (if (< numb 0) (message "Error! The minimum value for transparency is 0!") (set-frame-parameter nil 'alpha numb)))) (defun transparency-increase () "Increase level of transparency for the current frame" (interactive) (transparency-set-initial-value) (if (> (frame-parameter nil 'alpha) 0) (set-frame-parameter nil 'alpha (+ (frame-parameter nil 'alpha) -1)) (message "This is a minimum value of transparency!"))) (defun transparency-decrease () "Decrease level of transparency for the current frame" (interactive) (transparency-set-initial-value) (if (< (frame-parameter nil 'alpha) 100) (set-frame-parameter nil 'alpha (+ (frame-parameter nil 'alpha) +1)) (message "This is a minimum value of transparency!")))