From 37248610be60d3a8894d57051c88e64ebf024b4b Mon Sep 17 00:00:00 2001 From: Ignacy Moryc Date: Mon, 6 Dec 2010 20:53:48 +0100 Subject: [PATCH] Lots of changes --- bookmarks | 56 ++++---- imoryc/project-top.el | 65 ++++++++++ imoryc/rake-setup.el | 67 ++++++++++ imoryc/ruby-electric.el | 189 +++++++++++++++++++++++++++ imoryc/ruby-setup.el | 167 ++++++++++++++++++++++++ imoryc/rvm.el | 280 ++++++++++++++++++++++++++++++++++++++++ init.el | 69 +++++----- 7 files changed, 827 insertions(+), 66 deletions(-) create mode 100644 imoryc/project-top.el create mode 100644 imoryc/rake-setup.el create mode 100644 imoryc/ruby-electric.el create mode 100644 imoryc/ruby-setup.el create mode 100644 imoryc/rvm.el diff --git a/bookmarks b/bookmarks index 28dd6e2..3f72f25 100644 --- a/bookmarks +++ b/bookmarks @@ -2,29 +2,33 @@ ;;; This format is meant to be slightly human-readable; ;;; nevertheless, you probably don't want to edit it. ;;; -*- End Of Bookmark File Format Version Stamp -*- -(("customer_show_view" - (filename . "~/code/middleware/app/views/customers/show.html.haml") - (front-context-string . "\n%tbody\n %tr\n ") - (rear-context-string . "_to 'Calls', '#'") - (position . 49)) -("rc.lua " - (filename . "~/.config/awesome/rc.lua") - (front-context-string . "-- Standard awes") - (rear-context-string) - (position . 1)) -("org-remember-last-stored" - (filename . "~/Dropbox/org/notes.org") - (front-context-string . "** [2010-12-06 p") - (rear-context-string . "ories present]]\n") - (position . 72363)) -("zshr" - (filename . "~/.zshrc") - (front-context-string . "# Lines configur") - (rear-context-string) - (position . 1)) -("init" - (filename . "~/.emacs.d/init.el") - (front-context-string . "(setq dotfiles-d") - (rear-context-string) - (position . 1)) -) \ No newline at end of file +(("ruby-setup.el" + (filename . "~/.emacs.d/imoryc/ruby-setup.el") + (front-context-string . ";; Setup ruby\n\n(") + (rear-context-string) + (position . 1)) + ("customer_show_view" + (filename . "~/code/middleware/app/views/customers/show.html.haml") + (front-context-string . "\n%tbody\n %tr\n ") + (rear-context-string . "_to 'Calls', '#'") + (position . 49)) + ("rc.lua " + (filename . "~/.config/awesome/rc.lua") + (front-context-string . "-- Standard awes") + (rear-context-string) + (position . 1)) + ("org-remember-last-stored" + (filename . "~/Dropbox/org/notes.org") + (front-context-string . "** [2010-12-06 p") + (rear-context-string . "ories present]]\n") + (position . 72363)) + ("zshr" + (filename . "~/.zshrc") + (front-context-string . "# Lines configur") + (rear-context-string) + (position . 1)) + ("init" + (filename . "~/.emacs.d/init.el") + (front-context-string . "(setq dotfiles-d") + (rear-context-string) + (position . 1))) diff --git a/imoryc/project-top.el b/imoryc/project-top.el new file mode 100644 index 0000000..8bf1f42 --- /dev/null +++ b/imoryc/project-top.el @@ -0,0 +1,65 @@ +;; Find the top of a project + +(defconst project-top-default-top-files '(".git" "Rakefile" "rakelib" "lib" "config")) + +(defun project-top (&rest top-files) + "Return the file-name to the top of the project containing the current buffer." + (project-top-from + (project-top-starting-point) + (if (null top-files) + project-top-default-top-files + (project-top-from (project-top-starting-point) top-files)))) + +(defun project-top-find-file (&rest args) + "Return the path to the file given a relative path from the project top. +Usage: (project-top-find-file config/database.yml) + (project-top-find-file config/database.yml starting-file) + (project-top-file-file config/database.yml starting-file top-files)" + (let ((file-path (apply 'project-top-path-to args))) + (if (and file-path (file-exists-p file-path)) + (find-file file-path) + (message (concat "Can't find file " (car args)))))) + +(defun project-top-path-to (file-from-top &rest args) + "Return the path to the file given a relative path from the project top. +Usage: (project-path-to config/database.yml) + (project-path-to config/database.yml starting-file) + (project-path-to config/database.yml starting-file top-files)" + (let* ((from-path (project-top-arg args (project-top-starting-point))) + (top-files (project-top-arg (cdr args) project-top-default-top-files)) + (path (project-top-from from-path top-files))) + (if path (concat (file-name-as-directory path) file-from-top)))) + +(defun project-top-from (path top-files) + "Return the path to the top of the project containing path. +Returns nil if no project top found. Use the list of possible +top-files to determine the top of the project." + (cond ((null path) nil) + ((project-top-at-top-p path top-files) path) + (t (project-top-from (project-top-parent path) top-files)))) + +(defun project-top-at-top-p (path top-files) + "Is the path at the top level of a project?" + (cond ((null top-files) nil) + ((project-top-contains-p path (car top-files)) t) + (t (project-top-at-top-p path (cdr top-files))))) + +(defun project-top-parent (path) + "Return the parent directory of path. The parent of / is nil." + (cond ((string-equal "/" path) nil) + (t (file-name-directory (directory-file-name path))) ) ) + +(defun project-top-contains-p (dir file) + (file-exists-p (concat (file-name-as-directory dir) file))) + +(defun project-top-arg (opt default-value) + "Return the car of opt if it is not null, otherwise return the default value." + (if (null opt) default-value (car opt))) + +(defun project-top-starting-point () + (let ((cur (buffer-file-name (current-buffer)))) + (if cur + cur + (directory-file-name (substring (pwd) 10))))) + +(provide 'project-top) diff --git a/imoryc/rake-setup.el b/imoryc/rake-setup.el new file mode 100644 index 0000000..3626bbb --- /dev/null +++ b/imoryc/rake-setup.el @@ -0,0 +1,67 @@ +;;; ================================================================== +;;; Author: Jim Weirich +;;; File: ini-rake +;;; Purpose: Rake / Emacs Integration +;;; ================================================================== + +;;; Name of the buffer used to capture rake output. +(defconst jw-rake-buffer-name "*rake*") + +;;; Name of the buffer used to capture rake tasks. +(defconst jw-rake-task-buffer-name "*rake-tasks*") + +;;; Name of the rake command. +(defconst jw-run-rake-command "rake") + +;;; Name of the rake process. +(defconst jw-rake-process-name "*rake-process*") + +(defun jw-rake-tasks () + (if (get-buffer jw-rake-task-buffer-name) + (kill-buffer jw-rake-task-buffer-name)) + (call-process "rake" nil jw-rake-task-buffer-name nil "-T")) + +(defun jw-rake-parse-task-names () + (save-current-buffer + (set-buffer jw-rake-task-buffer-name) + (goto-char (point-min)) + (let ((result nil) (n 0)) + (while (re-search-forward "^rake \\([a-zA-Z0-9_:]+\\)" nil t) + (setq n (+ n 1)) + (setq result (cons (list (buffer-substring (match-beginning 1) (match-end 1)) n) + result)) ) + result))) + +(defun jw-rake-read-task () + "Fill the rake task buffer with the rake commands available at the moment." + (interactive) + (jw-rake-tasks) + (completing-read "Rake Task: " (jw-rake-parse-task-names))) + +(defun jw-rake-process-filter (proc string) + "Process the output from the rake process. +Just insert into the rake output buffer, removing any carriage +returns along the way." + (with-current-buffer (process-buffer proc) + (let ((moving (= (point) (process-mark proc)))) + (save-excursion + (goto-char (process-mark proc)) + (insert (replace-regexp-in-string " +" "" string)) + (set-marker (process-mark proc) (point))) + (if moving (goto-char (process-mark proc)))))) + +(defun jw-start-rake-process (task) + "Start the rake process using *cmd* and any optional *args*. +The process is run asynchronously and the output is placed in the +buffer identified by jw-rake-buffer-name." + (let* ((process + (start-process jw-rake-process-name + jw-rake-buffer-name jw-run-rake-command task))) + (set-process-filter process 'jw-rake-process-filter) )) + +(defun rake () + (interactive) + (if (get-buffer jw-rake-buffer-name) (kill-buffer jw-rake-buffer-name)) + (jw-start-rake-process (jw-rake-read-task)) + (pop-to-buffer jw-rake-buffer-name)) diff --git a/imoryc/ruby-electric.el b/imoryc/ruby-electric.el new file mode 100644 index 0000000..8d7cdbf --- /dev/null +++ b/imoryc/ruby-electric.el @@ -0,0 +1,189 @@ +;; -*-Emacs-Lisp-*- +;; +;; ruby-electric.el --- electric commands editing for ruby files +;; +;; Copyright (C) 2005 by Dee Zsombor . +;; Released under same license terms as Ruby. +;; +;; Due credit: this work was inspired by a code snippet posted by +;; Frederick Ros at http://rubygarden.org/ruby?EmacsExtensions. +;; +;; Following improvements where added: +;; +;; - handling of strings of type 'here document' +;; - more keywords, with special handling for 'do' +;; - packaged into a minor mode +;; +;; Usage: +;; +;; 0) copy ruby-electric.el into directory where emacs can find it. +;; +;; 1) modify your startup file (.emacs or whatever) by adding +;; following line: +;; +;; (require 'ruby-electric) +;; +;; 2) toggle Ruby Electric Mode on/off with ruby-electric-mode. +;; +;; Changelog: +;; +;; 2005/Jan/14: inserts matching pair delimiters like {, [, (, ', ", +;; ' and | . +;; +;; 2005/Jan/14: added basic Custom support for configuring keywords +;; with electric closing. +;; +;; 2005/Jan/18: more Custom support for configuring characters for +;; which matching expansion should occur. +;; +;; 2005/Jan/18: no longer uses 'looking-back' or regexp character +;; classes like [:space:] since they are not implemented on XEmacs. + + + +(require 'ruby-mode) + +(defconst ruby-electric-expandable-do-re + "do\\s-$") + +(defconst ruby-electric-expandable-bar + "\\s-\\(do\\|{\\)\\s-+|") + +(defvar ruby-electric-matching-delimeter-alist + '((?\[ . ?\]) + (?\( . ?\)) + (?\' . ?\') + (?\` . ?\`) + (?\" . ?\"))) + +(defcustom ruby-electric-simple-keywords-re + "\\(def\\|if\\|class\\|module\\|unless\\|case\\|while\\|do\\|until\\|for\\|begin\\)" + "*Regular expresion matching keywords for which closing 'end' +is to be inserted." + :type 'regexp :group 'ruby-electric) + +(defcustom ruby-electric-expand-delimiters-list '(all) + "*List of contexts where matching delimiter should be +inserted. The word 'all' will do all insertions." + :type '(set :extra-offset 8 + (const :tag "Everything" all ) + (const :tag "Curly brace" ?\{ ) + (const :tag "Square brace" ?\[ ) + (const :tag "Round brace" ?\( ) + (const :tag "Quote" ?\' ) + (const :tag "Double quote" ?\" ) + (const :tag "Back quote" ?\` ) + (const :tag "Veritcal bar" ?\| )) + :group 'ruby-electric) + +(defcustom ruby-electric-newline-before-closing-bracket nil + "*Controls whether a newline should be inserted before the +closing bracket or not." + :type 'boolean :group 'ruby-electric) + +(define-minor-mode ruby-electric-mode + "Toggle Ruby Electric mode. +With no argument, this command toggles the mode. Non-null prefix +argument turns on the mode. Null prefix argument turns off the +mode. + +When Ruby Electric mode is enabled, an indented 'end' is +heuristicaly inserted whenever typing a word like 'module', +'class', 'def', 'if', 'unless', 'case', 'until', 'for', 'begin', +'do'. Simple, double and back quotes as well as braces are paired +auto-magically. Expansion does not occur inside comments and +strings. Note that you must have Font Lock enabled." + ;; initial value. + nil + ;;indicator for the mode line. + " REl" + ;;keymap + ruby-mode-map + (ruby-electric-setup-keymap)) + +(defun ruby-electric-setup-keymap() + (define-key ruby-mode-map " " 'ruby-electric-space) + (define-key ruby-mode-map "{" 'ruby-electric-curlies) + (define-key ruby-mode-map "(" 'ruby-electric-matching-char) + (define-key ruby-mode-map "[" 'ruby-electric-matching-char) + (define-key ruby-mode-map "\"" 'ruby-electric-matching-char) + (define-key ruby-mode-map "\'" 'ruby-electric-matching-char) + (define-key ruby-mode-map "|" 'ruby-electric-bar)) + +(defun ruby-electric-space (arg) + (interactive "P") + (self-insert-command (prefix-numeric-value arg)) + (if (ruby-electric-space-can-be-expanded-p) + (save-excursion + (ruby-indent-line t) + (newline) + (ruby-insert-end)))) + +(defun ruby-electric-code-at-point-p() + (and ruby-electric-mode + (let* ((properties (text-properties-at (point)))) + (and (null (memq 'font-lock-string-face properties)) + (null (memq 'font-lock-comment-face properties)))))) + +(defun ruby-electric-string-at-point-p() + (and ruby-electric-mode + (consp (memq 'font-lock-string-face (text-properties-at (point)))))) + +(defun ruby-electric-is-last-command-char-expandable-punct-p() + (or (memq 'all ruby-electric-expand-delimiters-list) + (memq last-command-char ruby-electric-expand-delimiters-list))) + +(defun ruby-electric-space-can-be-expanded-p() + (if (ruby-electric-code-at-point-p) + (let* ((ruby-electric-keywords-re + (concat ruby-electric-simple-keywords-re "\\s-$")) + (ruby-electric-single-keyword-in-line-re + (concat "\\s-*" ruby-electric-keywords-re))) + (save-excursion + (backward-word) + (or (looking-at ruby-electric-expandable-do-re) + (and (looking-at ruby-electric-keywords-re) + (not (string= "do" (match-string 1))) + (progn + (beginning-of-line) + (looking-at ruby-electric-single-keyword-in-line-re)))))))) + + +(defun ruby-electric-curlies(arg) + (interactive "P") + (self-insert-command (prefix-numeric-value arg)) + (if (ruby-electric-is-last-command-char-expandable-punct-p) + (cond ((ruby-electric-code-at-point-p) + (insert " ") + (save-excursion + (if ruby-electric-newline-before-closing-bracket + (newline)) + (insert "}"))) + ((ruby-electric-string-at-point-p) + (save-excursion + (backward-char 1) + (when (char-equal ?\# (preceding-char)) + (forward-char 1) + (insert "}"))))))) + +(defun ruby-electric-matching-char(arg) + (interactive "P") + (self-insert-command (prefix-numeric-value arg)) + (and (ruby-electric-is-last-command-char-expandable-punct-p) + (ruby-electric-code-at-point-p) + (save-excursion + (insert (cdr (assoc last-command-char + ruby-electric-matching-delimeter-alist)))))) + +(defun ruby-electric-bar(arg) + (interactive "P") + (self-insert-command (prefix-numeric-value arg)) + (and (ruby-electric-is-last-command-char-expandable-punct-p) + (ruby-electric-code-at-point-p) + (and (save-excursion (re-search-backward ruby-electric-expandable-bar nil t)) + (= (point) (match-end 0))) ;looking-back is missing on XEmacs + (save-excursion + (insert "|")))) + + +(provide 'ruby-electric) diff --git a/imoryc/ruby-setup.el b/imoryc/ruby-setup.el new file mode 100644 index 0000000..aff4614 --- /dev/null +++ b/imoryc/ruby-setup.el @@ -0,0 +1,167 @@ +;; Setup ruby + +(add-to-list 'load-path (concat dotfiles-dir "/ruby-debug-extra-0.10.1")) +(add-to-list 'load-path (concat dotfiles-dir "/ruby-debug-extra-0.10.1/emacs")) +(require 'rdebug) + +;;; Setup rails +(add-to-list 'load-path (concat dotfiles-dir "/emacs-rails-reloaded")) +(add-to-list 'load-path (concat dotfiles-dir "/inf-ruby-2.1")) +(require 'rails-autoload) +(add-to-list 'load-path (concat dotfiles-dir "/rhtml")) +(require 'rhtml-mode) + +(require 'ruby-electric) +;; ruby-electric uses this function, but for some reason my ruby-mode +;; version doesn't define it. +(defun ruby-insert-end () + (interactive) + (insert "end") + (ruby-indent-line t) + (end-of-line)) + +(ruby-electric-mode t) + +(defun rel () + "Toggle Ruby electric mode (shortcut)" + (interactive) + (ruby-electric-mode)) + + +(defun ruby-interpolate () + "In a double quoted string, interpolate." + (interactive) + (insert "#") + (let ((properties (text-properties-at (point)))) + (when (and + (memq 'font-lock-string-face properties) + (save-excursion + (ruby-forward-string "\"" (line-end-position) t))) + (insert "{}") + (backward-char 1)))) +(define-key ruby-mode-map (kbd "#") 'ruby-interpolate) + +(eval-after-load 'ruby-mode + '(progn + (ignore-errors (require 'ruby-compilation)) + (setq ruby-use-encoding-map nil) + (add-hook 'ruby-mode-hook 'inf-ruby-keys) + (define-key ruby-mode-map (kbd "RET") 'reindent-then-newline-and-indent) + (define-key ruby-mode-map (kbd "C-c l") "lambda"))) + +(global-set-key (kbd "C-h r") 'ri) + +;; Rake files are ruby, too, as are gemspecs, rackup files, etc. +(add-to-list 'auto-mode-alist '("\\.rake$" . ruby-mode)) +(add-to-list 'auto-mode-alist '("\\.gemspec$" . ruby-mode)) +(add-to-list 'auto-mode-alist '("\\.ru$" . ruby-mode)) +(add-to-list 'auto-mode-alist '("Rakefile$" . ruby-mode)) +(add-to-list 'auto-mode-alist '("Gemfile$" . ruby-mode)) +(add-to-list 'auto-mode-alist '("Capfile$" . ruby-mode)) +(add-to-list 'auto-mode-alist '("Vagrantfile$" . ruby-mode)) + +;; Clear the compilation buffer between test runs. +(eval-after-load 'ruby-compilation + '(progn + (defadvice ruby-do-run-w/compilation (before kill-buffer (name cmdlist)) + (let ((comp-buffer-name (format "*%s*" name))) + (when (get-buffer comp-buffer-name) + (with-current-buffer comp-buffer-name + (delete-region (point-min) (point-max)))))) + (ad-activate 'ruby-do-run-w/compilation))) + +(add-hook 'ruby-mode-hook 'run-coding-hook) + +(load-library "compile") + +;;; For some reason, the gnu regex is capturing leading white space. +(setq compilation-error-regexp-alist + (remq 'gnu compilation-error-regexp-alist)) + +;; Ruby test unit patterns. +(add-to-list 'compilation-error-regexp-alist + '("\\([^ \t:\\[]+\\):\\([0-9]+\\):in" 1 2)) +(add-to-list 'compilation-error-regexp-alist + '("test[a-zA-Z0-9_]*([A-Z][a-zA-Z0-9_]*) \\[\\(.*\\):\\([0-9]+\\)\\]:" 1 2)) + + +(defface erb-face + `((t (:background "grey10"))) + "Default inherited face for ERB tag body" + :group 'rhtml-faces) + +(defface erb-delim-face + `((t (:background "grey15"))) + "Default inherited face for ERB tag delimeters" + :group 'rhtml-faces) + +(defface erb-out-delim-face + `((t (:inherit erb-delim-face :weight bold :foreground "yellow"))) + "Basic face for Ruby embedded into HTML" + :group 'rhtml-faces) + +(defface erb-exec-delim-face + `((t (:inherit erb-delim-face :weight bold :foreground "yellow"))) + "Basic face for Ruby embedded into HTML" + :group 'rhtml-faces) + +(require 'project-top) + +(defun schema () + "Open the schema file in this Rails project." + (interactive) + (project-top-find-file "db/schema.rb")) + +(defun routes () + "Open the routes file in this Rails project." + (interactive) + (project-top-find-file "config/routes.rb")) + +(defun gud-rubydb-find-file (f) + (save-excursion + (let ((buf (find-file-noselect f))) + (set-buffer buf) +;; (gud-make-debug-menu) + buf))) + +(defvar rubydb-command-name ''rvm--emacs-ruby-binary + "File name for executing ruby.") + +;;;###autoload + + (defun rubydb (command-line) + "Run rubydb on program FILE in buffer *gud-FILE*. +The directory containing FILE becomes the initial working directory +and source-file directory for your debugger." + (interactive + (list (read-from-minibuffer "Run rubydb (like this): " + (if (consp gud-rubydb-history) + (car gud-rubydb-history) + (concat rubydb-command-name " ")) + nil nil + '(gud-rubydb-history . 1)))) + + (if (not (fboundp 'gud-overload-functions)) + (gud-common-init command-line 'gud-rubydb-massage-args + 'gud-rubydb-marker-filter 'gud-rubydb-find-file) + (gud-overload-functions '((gud-massage-args . gud-rubydb-massage-args) + (gud-marker-filter . gud-rubydb-marker-filter) + (gud-find-file . gud-rubydb-find-file))) + (gud-common-init command-line rubydb-command-name)) + + (gud-def gud-break "b %l" "\C-b" "Set breakpoint at current line.") +; (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line") + (gud-def gud-step "s" "\C-s" "Step one source line with display.") + (gud-def gud-next "n" "\C-n" "Step one line (skip functions).") + (gud-def gud-cont "c" "\C-r" "Continue with display.") + (gud-def gud-finish "finish" "\C-f" "Finish executing current function.") + (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).") + (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).") + (gud-def gud-print "p %e" "\C-p" "Evaluate ruby expression at point.") + + (setq comint-prompt-regexp "^(rdb:-) ") + (if (boundp 'comint-last-output-start) + (set-marker comint-last-output-start (point))) + (set (make-local-variable 'paragraph-start) comint-prompt-regexp) + (run-hooks 'rubydb-mode-hook) + ) diff --git a/imoryc/rvm.el b/imoryc/rvm.el new file mode 100644 index 0000000..64b8bc7 --- /dev/null +++ b/imoryc/rvm.el @@ -0,0 +1,280 @@ +;;; rvm.el --- Emacs integration for rvm + +;; Copyright (C) 2010 Yves Senn + +;; Author: Yves Senn +;; URL: http://www.emacswiki.org/emacs/RvmEl +;; Version: 1.1 +;; Created: 5 April 2010 +;; Keywords: ruby rvm +;; EmacsWiki: RvmEl + +;; This file is NOT part of GNU Emacs. + +;;; License: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; M-x rvm-use-default prepares the current Emacs session to use +;; the default ruby configured with rvm. + +;; M-x rvm-use allows you to switch the current session to the ruby +;; implementation of your choice. You can also change the active gemset. + +;;; Compiler support: + +(eval-when-compile (require 'cl)) +(defvar eshell-path-env) +(defvar persp-mode) +(defvar perspectives-hash) +(declare-function persp-switch "perspective" (name)) + +;;; Code: + +(defcustom rvm-executable + (or (executable-find "rvm") "~/.rvm/bin/rvm") + "Location of RVM executable." + :group 'rvm + :type 'file) + +(defcustom rvm-configuration-file-name + ".rvmrc" + "RVM configuration file name" + :group 'rvm + :type 'string) + +(defcustom rvm-interactive-completion-function + (if ido-mode 'ido-completing-read 'completing-read) + "The function which is used by rvm.el to interactivly complete user input" + :group 'rvm + :type 'function) + +(defcustom rvm-interactive-find-file-function + (if ido-mode 'ido-find-file 'find-file) + "The function which is used by rvm.el to interactivly open files" + :group 'rvm + :type 'function) + +(defvar rvm--gemset-default "global" + "the default gemset per ruby interpreter") + +(defvar rvm--gemset-separator "@" + "character that separates the ruby version from the gemset.") + +(defvar rvm--current-ruby-binary-path nil + "reflects the path to the current 'ruby' executable. +This path gets added to the PATH variable and the exec-path list.") + +(defvar rvm--current-gem-binary-path nil + "reflects the path to the current 'rubygems' executables. +This path gets added to the PATH variable and the exec-path list.") + +(defvar rvm--list-ruby-regexp "\s*\\(=>\\)?\s*\\(.+?\\)\s*\\[\\(.+\\)\\]\s*$" + "regular expression to parse the ruby version from the 'rvm list' output") + +;;;###autoload +(defun rvm-use-default () + "use the rvm-default ruby as the current ruby version" + (interactive) + (rvm-use (rvm--ruby-default) rvm--gemset-default)) + +;;;###autoload +(defun rvm-activate-corresponding-ruby () + "activate the corresponding ruby version for the file in the current buffer. +This function searches for an .rvmrc file and actiavtes the configured ruby. +If no .rvmrc file is found, the default ruby is used insted." + (interactive) + (let* ((rvmrc-path (rvm--rvmrc-locate)) + (rvmrc-info (if rvmrc-path (rvm--rvmrc-read-version rvmrc-path) nil))) + (if rvmrc-info (rvm-use (first rvmrc-info) (second rvmrc-info)) + (rvm-use-default)))) + +;;;###autoload +(defun rvm-use (new-ruby new-gemset) + "switch the current ruby version to any ruby, which is installed with rvm" + (interactive + (let* ((picked-ruby (rvm--completing-read "Ruby Version: " + (rvm/list))) + (picked-gemset (rvm--completing-read "Gemset: " + (rvm/gemset-list picked-ruby)))) + (list picked-ruby picked-gemset))) + (let* ((new-ruby-with-gemset (concat new-ruby rvm--gemset-separator new-gemset)) + (ruby-info (rvm/info new-ruby-with-gemset)) + (new-ruby-binary (cdr (assoc "ruby" ruby-info))) + (new-ruby-gemhome (cdr (assoc "GEM_HOME" ruby-info))) + (new-ruby-gempath (cdr (assoc "GEM_PATH" ruby-info)))) + (rvm--set-ruby (file-name-directory new-ruby-binary)) + (rvm--set-gemhome new-ruby-gemhome new-ruby-gempath new-gemset)) + (message (concat "Ruby: " new-ruby " Gemset: " new-gemset))) + +;;;###autoload +(defun rvm-open-gem (gemhome) + (interactive (list (rvm--emacs-gemhome))) + (let* ((gems-dir (concat gemhome "/gems/")) + (gem-name (rvm--completing-read "Gem: " + (directory-files gems-dir nil "^[^.]"))) + (gem-dir (concat gems-dir gem-name))) + (when (and (featurep 'perspective) persp-mode) + (let ((initialize (not (gethash gem-name perspectives-hash)))) + (persp-switch gem-name))) + (rvm--find-file gem-dir))) + +;;;; TODO: take buffer switching into account +(defun rvm-autodetect-ruby () + (interactive) + (add-hook 'ruby-mode-hook 'rvm-activate-corresponding-ruby) + (message "rvm.el is now autodetecting the ruby version")) + +(defun rvm-autodetect-ruby-stop () + (interactive) + (remove-hook 'ruby-mode-hook 'rvm-activate-corresponding-ruby) + (message "stopped rvm.el from autodetecting ruby versions")) + +(defun rvm/list (&optional default-ruby) + (let ((rubies (rvm--call-process "list" (when default-ruby "default"))) + (start 0) + (parsed-rubies '()) + (current-ruby '())) + (while (string-match rvm--list-ruby-regexp rubies start) + (let ((ruby-version (match-string 2 rubies)) + (ruby-platform (match-string 3 rubies)) + (ruby-current-version (match-string 1 rubies))) + (add-to-list 'current-ruby ruby-current-version) + (if ruby-current-version (add-to-list 'parsed-rubies ruby-version) + (add-to-list 'parsed-rubies ruby-version t)) + (setq start (match-end 0)))) + parsed-rubies)) + +(defun rvm/gemset-list (ruby-version) + (let* ((gemset-result (rvm--call-process ruby-version "gemset" "list")) + (gemset-lines (split-string gemset-result "\n")) + (parsed-gemsets (list))) + (loop for i from 2 to (length gemset-lines) do + (let ((gemset (nth i gemset-lines))) + (when (and (> (length gemset) 0) + (not (string-match "info:" gemset))) + (add-to-list 'parsed-gemsets gemset t)))) + parsed-gemsets)) + +(defun rvm/info (&optional ruby-version) + (let ((info (rvm--call-process "info" ruby-version)) + (start 0) + (parsed-info '())) + (when (not info) (error "The ruby version: %s is not installed" ruby-version)) + (while (string-match "\s+\\(.+\\):\s+\"\\(.+\\)\"" info start) + (let ((info-key (match-string 1 info)) + (info-value (match-string 2 info))) + (add-to-list 'parsed-info (cons info-key info-value)) + (setq start (match-end 0)))) + parsed-info)) + +(defun rvm--completing-read (prompt options) + (funcall rvm-interactive-completion-function prompt options)) + +(defun rvm--find-file (directory) + (let ((default-directory directory)) + (call-interactively rvm-interactive-find-file-function))) + +(defun rvm--emacs-ruby-binary () + rvm--current-ruby-binary-path) + +(defun rvm--emacs-gemhome () + (getenv "GEM_HOME")) + +(defun rvm--emacs-gempath () + (getenv "GEM_PATH")) + +(defun rvm--change-path (current-binary-var new-binaries) + (let ((current-binaries-for-path + (mapconcat 'identity (eval current-binary-var) ":")) + (new-binaries-for-path (mapconcat 'identity new-binaries ":"))) + (if (and (eval current-binary-var) + (not (string= (first (eval current-binary-var)) "/bin"))) + (progn + (setenv "PATH" (replace-regexp-in-string + (regexp-quote current-binaries-for-path) + new-binaries-for-path + (getenv "PATH"))) + (dolist (binary (eval current-binary-var)) + (setq exec-path (remove binary exec-path)))) + (setenv "PATH" (concat new-binaries-for-path ":" (getenv "PATH")))) + (dolist (binary new-binaries) + (add-to-list 'exec-path binary)) + (setq eshell-path-env (getenv "PATH")) + (set current-binary-var new-binaries))) + +(defun rvm--set-ruby (ruby-binary) + (rvm--change-path 'rvm--current-ruby-binary-path (list ruby-binary))) + +(defun rvm--rvmrc-locate (&optional path) + "searches the directory tree for an .rvmrc configuration file" + (when (null path) (setq path default-directory)) + (cond + ((equal (expand-file-name path) (expand-file-name "~")) nil) + ((equal (expand-file-name path) "/") nil) + ((member rvm-configuration-file-name (directory-files path)) + (concat (expand-file-name path) "/.rvmrc")) + (t (rvm--rvmrc-locate (concat (file-name-as-directory path) ".."))))) + +(defun rvm--rvmrc-read-version (path-to-rvmrc) + (with-temp-buffer + (insert-file-contents path-to-rvmrc) + (rvm--rvmrc-parse-version (buffer-substring-no-properties (point-min) (point-max))))) + +(defun rvm--rvmrc-parse-version (rvmrc-line) + (when (string-match + (concat "rvm\\(\s+use\\)?\s+\\([^" rvm--gemset-separator "]+\\)\\(" rvm--gemset-separator "\\(.*\\)\\)?") + rvmrc-line) + (list (match-string 2 rvmrc-line) (or + (match-string 4 rvmrc-line) + rvm--gemset-default)))) + +(defun rvm--gem-binary-path-from-gem-path (gempath) + (let ((gem-paths (split-string gempath ":"))) + (mapcar (lambda (path) (concat path "/bin")) gem-paths))) + +(defun rvm--set-gemhome (gemhome gempath gemset) + (if (and gemhome gempath gemset) + (progn + (setenv "GEM_HOME" gemhome) + (setenv "GEM_PATH" gempath) + (setenv "BUNDLE_PATH" gemhome) + (rvm--change-path 'rvm--current-gem-binary-path (rvm--gem-binary-path-from-gem-path gempath))) + ;; TODO: make system gems work + (setenv "GEM_HOME" "") + (setenv "GEM_PATH" "") + (setenv "BUNDLE_PATH" ""))) + +(defun rvm--ruby-default () + (car (rvm/list t))) + +(defun rvm--default-gemset-p (gemset) + (string= gemset rvm--gemset-default)) + +(defun rvm--call-process (&rest args) + (with-temp-buffer + (let* ((success (apply 'call-process rvm-executable nil t nil + (delete nil args))) + (output (buffer-substring-no-properties + (point-min) (point-max)))) + (if (= 0 success) + output + (message output))))) + +(provide 'rvm) +;;; rvm.el ends here diff --git a/init.el b/init.el index 7f00973..8e87f9a 100644 --- a/init.el +++ b/init.el @@ -1,13 +1,17 @@ (setq dotfiles-dir "~/.emacs.d") (setq imoryc-dir (concat dotfiles-dir "/imoryc")) +(add-to-list 'load-path imoryc-dir) (setq inhibit-startup-message t) -(load-file (concat dotfiles-dir "/haskell-mode/haskell-site-file.el")) +;; (load-file (concat dotfiles-dir "/haskell-mode/haskell-site-file.el")) (load-file (concat dotfiles-dir "/emacs-rails-reloaded/vendor/anything.el")) +(load-file (concat imoryc-dir "/ruby-setup.el")) +(load-file (concat imoryc-dir "/rake-setup.el")) +(load-file (concat imoryc-dir "/project-top.el")) -(add-to-list 'load-path imoryc-dir) +(require 'rvm) (require 'anything) (require 'git) (require 'proel) @@ -19,16 +23,11 @@ '(proel-anything-projects proel-anything-current-project-files)) - -(add-to-list 'load-path (concat dotfiles-dir "/ruby-debug-extra-0.10.1")) -(add-to-list 'load-path (concat dotfiles-dir "/ruby-debug-extra-0.10.1/emacs")) -(require 'rdebug) - (add-to-list 'load-path (concat dotfiles-dir "/feature-mode")) (require 'feature-mode) (add-to-list 'auto-mode-alist '("\.feature$" . feature-mode)) -(setq-default fill-column 80) +(setq-default fill-column 100) (setq ditaa-cmd "java -jar /home/ignacy/bin/ditaa0_9.jar") (defun djcb-ditaa-generate () @@ -36,14 +35,12 @@ (shell-command (concat ditaa-cmd " " buffer-file-name))) - (scroll-bar-mode -1) (setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands (transient-mark-mode 1) ;; No region when it is not highlighted (setq cua-keep-region-after-copy t) ;; Standard Windows behaviour (delete-selection-mode t) -;;(set-scroll-bar-mode 'right) (setq visible-bell t) (show-paren-mode 1) (fset 'yes-or-no-p 'y-or-n-p) @@ -65,6 +62,15 @@ (global-set-key [(meta a)] 'anything) (setq x-select-enable-clipboard t) +(global-set-key [(control v)] 'clipboard-yank) +(global-set-key (kbd "C-x C-x") 'clipboard-kill-region) + +(defvar compile-command "rake ") ; set the default make command +(make-variable-buffer-local 'compile-command) +; make the compile command buffer local +; (this allows each buffer to have its +; own custom compile command) + (setq-default indent-tabs-mode nil) (setq indent-tabs-mode nil) (setq tab-width 2) @@ -98,13 +104,9 @@ (abort-recursive-edit))) (add-hook 'mouse-leave-buffer-hook 'stop-using-minibuffer) - - - ;; IBUFFER Settings (defalias 'list-buffers 'ibuffer) (setq ibuffer-show-empty-filter-groups nil) -;;(setq ibuffer-shrink-to-minimum-size t) (setq ibuffer-always-show-last-buffer nil) (setq ibuffer-sorting-mode 'recency) (setq ibuffer-formats '((mark modified read-only " " @@ -130,6 +132,7 @@ (add-hook 'ibuffer-mode-hook (lambda () (ibuffer-switch-to-saved-filter-groups "default"))) + (defadvice ibuffer-update-title-and-summary (after remove-column-titles) (save-excursion (set-buffer "*Ibuffer*") @@ -146,7 +149,8 @@ (global-unset-key [?\C-x ?\C-z]) (global-set-key [f1] 'menu-bar-mode) (global-set-key (kbd "C-z") 'undo) -;; (global-hl-line-mode 1) + +(global-hl-line-mode 1) ;;BOOKMARKS (define-key global-map [f9] 'bookmark-jump) (define-key global-map [f10] 'bookmark-set) @@ -181,22 +185,21 @@ (global-set-key (kbd "C-c d") 'duplicate-line) +(defun copy-line() + (interactive) + (move-beginning-of-line 1) + (kill-line) + (yank) + (next-line 1) +) +(global-set-key (kbd "C-c C-d") 'copy-line) + ;; install wmctrl (sudo apt-get install wmctrl) (defun switch-full-screen () "Switch emacs to full screen mode" (interactive) (shell-command "wmctrl -r :ACTIVE: -btoggle,fullscreen")) - - -;;; Setup rails -(add-to-list 'load-path (concat dotfiles-dir "/emacs-rails-reloaded")) -(add-to-list 'load-path (concat dotfiles-dir "/inf-ruby-2.1")) -(require 'rails-autoload) -(add-to-list 'load-path (concat dotfiles-dir "/rhtml")) -(require 'rhtml-mode) - - ;;yassnippet (add-to-list 'load-path (concat dotfiles-dir "/yasnippet-0.6.1c")) (require 'yasnippet) ;; not yasnippet-bundle @@ -266,7 +269,7 @@ (add-to-list 'load-path (concat dotfiles-dir "/color-theme-6.6.0")) -(load-file (concat imoryc-dir "/colors/color-theme-im.el")) +;;(load-file (concat imoryc-dir "/colors/color-theme-im.el")) (require 'color-theme) (eval-after-load "color-theme" '(progn @@ -298,19 +301,6 @@ (global-set-key (kbd "") 'use-emacs-keys) (global-set-key (kbd "") 'use-emacs-keys) -(defun ruby-interpolate () - "In a double quoted string, interpolate." - (interactive) - (insert "#") - (let ((properties (text-properties-at (point)))) - (when (and - (memq 'font-lock-string-face properties) - (save-excursion - (ruby-forward-string "\"" (line-end-position) t))) - (insert "{}") - (backward-char 1)))) - -(define-key ruby-mode-map (kbd "#") 'ruby-interpolate) (setq confirm-nonexistent-file-or-buffer nil) (setq kill-buffer-query-functions (remq 'process-kill-buffer-query-function @@ -319,7 +309,6 @@ (setq ibuffer-expert t) (setq ibuffer-show-empty-filter-groups nil) - (defun use-emacs-keys () (interactive) "Remind me to use emacs move keys not arrows!!"