Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Rinari working in starter-kit.el
Browse files Browse the repository at this point in the history
- updated to newest version of rinari.el
- updated to newest version of inf-ruby.el (with tab completion)
- starter-kit-ruby.el is now loading Rinari, and sets the
  rinari-major-modes variable so that Rinari is not added to the
  find-file-hook
  • Loading branch information
eschulte committed Jan 28, 2009
1 parent 62c3f06 commit 6293b8d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 35 deletions.
42 changes: 37 additions & 5 deletions elpa-to-submit/inf-ruby.el
Expand Up @@ -7,7 +7,7 @@
;; Created: 8 April 1998
;; Keywords: languages ruby
;; Version: 2.0
;; Package-Requires: ((ruby-mode "1.0"))
;; Package-Requires: (("ruby-mode"))

;;; Commentary:
;;
Expand Down Expand Up @@ -50,14 +50,15 @@
(let ((map (copy-keymap comint-mode-map)))
(define-key map (kbd "C-c C-l") 'inf-ruby-load-file)
(define-key map (kbd "C-x C-e") 'ruby-send-last-sexp)
(define-key map (kbd "TAB") 'inf-ruby-complete-or-tab)
map)
"*Mode map for inf-ruby-mode")

(defvar inf-ruby-implementations
'(("ruby" . "irb --inf-ruby-mode")
("jruby" . "jruby -S irb")
("rubinius" . "rbx")
("yarv" . "irb1.9 --inf-ruby-mode")) ;; TODO: ironruby?
'(("ruby" . "irb --inf-ruby-mode -r irb/completion")
("jruby" . "jruby -S irb -r irb/completion")
("rubinius" . "rbx -r irb/completion")
("yarv" . "irb1.9 --inf-ruby-mode -r irb/completion")) ;; TODO: ironruby?
"An alist of ruby implementations to irb executable names.")

;; TODO: do we need these two defvars?
Expand Down Expand Up @@ -310,6 +311,37 @@ Then switch to the process buffer."
(comint-send-string (inf-ruby-proc) (concat "(load \""
file-name
"\"\)\n")))

(defun inf-ruby-completions (seed)
"Return a list of completions for the line of ruby code starting with SEED."
(let* ((proc (get-buffer-process inf-ruby-buffer))
(comint-filt (process-filter proc))
(kept "") completions)
(set-process-filter proc (lambda (proc string) (setf kept (concat kept string))))
(process-send-string proc (format "puts IRB::InputCompletor::CompletionProc.call('%s').compact\n" seed))
(while (not (string-match inf-ruby-prompt-pattern kept)) (accept-process-output proc))
(if (string-match "^[[:alpha:]]+?Error: " kept) (error kept))
(setf completions (butlast (split-string kept "[\r\n]") 2))
(set-process-filter proc comint-filt)
completions))

(defun inf-ruby-complete-or-tab (&optional command)
"Either complete the ruby code at point or call
`indent-for-tab-command' if no completion is available. Relies
on the irb/completion Module used by readline when running irb
through a terminal."
(interactive (list (let* ((curr (thing-at-point 'line))
(completions (inf-ruby-completions curr)))
(case (length completions)
(0 nil)
(1 (car completions))
(t (completing-read "possible completions: " completions nil 'confirm-only curr))))))
(if (not command)
(call-interactively 'indent-for-tab-command)
(move-beginning-of-line 1)
(kill-line 1)
(insert command)))

;;;###autoload
(eval-after-load 'ruby-mode
'(add-hook 'ruby-mode-hook 'inf-ruby-keys))
Expand Down
79 changes: 49 additions & 30 deletions elpa-to-submit/rinari.el
Expand Up @@ -83,7 +83,12 @@
(defvar rinari-minor-mode-hook nil
"*Hook for customising Rinari.")

(defadvice ruby-compilation-run (around rinari-compilation-run activate)
(defcustom rinari-rails-env nil
"Use this to force a value for RAILS_ENV when running rinari.
Leave this set to nil to not force any value for RAILS_ENV, and
leave this to the environment variables outside of Emacs.")

(defadvice ruby-compilation-do (around rinari-compilation-do activate)
"Set default directory to the root of the rails application
before running ruby processes."
(let ((default-directory (or (rinari-root) default-directory)))
Expand Down Expand Up @@ -112,7 +117,8 @@
"environment.rb" (expand-file-name "config" dir)))
dir
(let ((new-dir (expand-file-name (file-name-as-directory "..") dir)))
(unless (string-match "\\(^[[:alpha:]]:/$\\|^/$\\)" dir)
;; regexp to match windows roots, tramp roots, or regular posix roots
(unless (string-match "\\(^[[:alpha:]]:/$\\|^/[^\/]+:\\|^/$\\)" dir)
(rinari-root new-dir)))))

;;--------------------------------------------------------------------------------
Expand All @@ -124,7 +130,8 @@ output dumped to a compilation buffer allowing jumping between
errors and source code. With optional prefix argument allows
editing of the rake command arguments."
(interactive "P")
(ruby-compilation-rake task edit-cmd-args))
(ruby-compilation-rake task edit-cmd-args
(if rinari-rails-env (list (cons "RAILS_ENV" rinari-rails-env)))))

(defun rinari-script (&optional script)
"Tab completing selection of a script from the script/
Expand Down Expand Up @@ -170,11 +177,12 @@ history and links between errors and source code. With optional
prefix argument allows editing of the console command arguments."
(interactive "P")
(let* ((script ;; (concat (rinari-root) "script/console")
(expand-file-name "console" (file-name-as-directory
(expand-file-name "script" (rinari-root)))))
(concat (expand-file-name "console" (file-name-as-directory
(expand-file-name "script" (rinari-root))))
(if rinari-rails-env (concat " " rinari-rails-env))))
(command (if edit-cmd-args
(read-string "Run Ruby: " (concat script " "))
script)))
(read-string "Run Ruby: " (concat script " "))
script)))
(run-ruby command)
(save-excursion
(set-buffer "*ruby*")
Expand All @@ -187,7 +195,7 @@ prefix argument allows editing of the console command arguments."
from your conf/database.sql file."
(interactive)
(flet ((sql-name (env) (format "*%s-sql*" env)))
(let* ((environment (or (getenv "RAILS_ENV") "development"))
(let* ((environment (or rinari-rails-env (getenv "RAILS_ENV") "development"))
(sql-buffer (get-buffer (sql-name environment))))
(if sql-buffer
(pop-to-buffer sql-buffer)
Expand Down Expand Up @@ -221,13 +229,14 @@ allowing jumping between errors and source code. With optional
prefix argument allows editing of the server command arguments."
(interactive "P")
(let* ((default-directory (rinari-root))
(script (expand-file-name "server"
(file-name-as-directory
(expand-file-name "script" (rinari-root)))))
(script (concat (expand-file-name "server"
(file-name-as-directory
(expand-file-name "script" (rinari-root))))
(if rinari-rails-env (concat " -e " rinari-rails-env))))
(command (if edit-cmd-args
(read-string "Run Ruby: " (concat script " "))
script)))
(ruby-compilation-run command)))
(ruby-compilation-run command)) (rinari-launch))

(defun rinari-insert-erb-skeleton (no-equals)
"Insert an erb skeleton at point, with optional prefix argument
Expand Down Expand Up @@ -492,7 +501,7 @@ renders and redirects to find the final controller or view."
(public "p" ((t . "public/")) nil)
(stylesheet "y" ((t . "public/stylesheets/.*")) nil)
(javascript "j" ((t . "public/javascripts/.*")) nil)
(plugin "l" ((t . "vendor/plugins/")) nil)
(plugin "u" ((t . "vendor/plugins/")) nil)
(file-in-project "f" ((t . ".*")) nil)
(by-context
";"
Expand All @@ -506,19 +515,25 @@ renders and redirects to find the final controller or view."
(list (car cv) (cdr cv))))))
. "app/views/\\1/\\2.*")))))

(mapcar
(lambda (type)
(let ((name (first type))
(specs (third type))
(make (fourth type)))
(eval `(defjump
(quote ,(read (format "rinari-find-%S" name)))
(quote ,specs)
'rinari-root
,(format "Go to the most logical %S given the current location" name)
,(if make `(quote ,make))
'ruby-add-log-current-method))))
rinari-jump-schema)
(defun rinari-apply-jump-schema (schema)
"This function takes a of SCHEMA s.t. each element in the list
can be fed to `defjump'. This is used to define all of the
rinari-find-* functions, and can be used to customize their
behavior."
(mapcar
(lambda (type)
(let ((name (first type))
(specs (third type))
(make (fourth type)))
(eval `(defjump
(quote ,(read (format "rinari-find-%S" name)))
(quote ,specs)
'rinari-root
,(format "Go to the most logical %S given the current location" name)
,(if make `(quote ,make))
'ruby-add-log-current-method))))
schema))
(rinari-apply-jump-schema rinari-jump-schema)

;;--------------------------------------------------------------------
;; minor mode and keymaps
Expand Down Expand Up @@ -561,13 +576,17 @@ otherwise turn `rinari-minor-mode' off if it is on."
(and (file-exists-p r-tags-path) r-tags-path))
(run-hooks 'rinari-minor-mode-hook)
(rinari-minor-mode t))
(if rinari-minor-mode (rinari-minor-mode)))))
(if (and (fboundp rinari-minor-mode) rinari-nimor-mode) (rinari-minor-mode)))))

;;;###autoload
(dolist (hook '(ruby-mode-hook mumamo-after-change-major-mode-hook
dired-mode-hook))
(add-hook hook 'rinari-launch))
(defvar rinari-major-modes
(if (boundp 'rinari-major-modes)
rinari-major-modes
(list 'find-file-hook 'mumamo-after-change-major-mode-hook 'dired-mode-hook))
"Major Modes from which to launch Rinari.")

;;;###autoload
(dolist (hook rinari-major-modes) (add-hook hook 'rinari-launch))

(defadvice cd (after rinari-on-cd activate)
"Active/Deactive rinari-minor-node when changing into and out
Expand Down
6 changes: 6 additions & 0 deletions starter-kit-ruby.el
Expand Up @@ -88,6 +88,12 @@ exec-to-string command, but it works and seems fast"
(if (functionp 'whitespace-mode)
(add-hook 'haml-mode-hook 'whitespace-mode)))

;; Rinari (Minor Mode for Ruby On Rails)
(setq rinari-major-modes
(list 'mumamo-after-change-major-mode-hook 'dired-mode-hook 'ruby-mode-hook
'css-mode-hook 'yaml-mode-hook 'javascript-mode-hook))
(require 'rinari)

;; TODO: set up ri
;; TODO: electric

Expand Down

0 comments on commit 6293b8d

Please sign in to comment.