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

Commit

Permalink
merged eschulte's rinari stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Feb 11, 2009
2 parents a4bd054 + 6293b8d commit e3dd93a
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
loaddefs.el*
backups/*
auto-save-list
custom.el
*elc
places
url/cookies
Expand Down
42 changes: 37 additions & 5 deletions elpa-to-submit/inf-ruby.el
Original file line number Diff line number Diff line change
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
14 changes: 8 additions & 6 deletions elpa-to-submit/inflections.el
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
;;; inflections.el ---
;;; inflections.el --- convert english words between singular and plural

;; Copyright (C) 2006 Dmitry Galinsky <dima dot exe at gmail dot com>

;; Authors: Dmitry Galinsky <dima dot exe at gmail dot com>,
;; Howard Yeh <hayeah at gmail dot com>

;; Authors: Dmitry Galinsky, Howard Yeh
;; URL: http://emacs-rails.rubyforge.org/svn/trunk/inflections.el
;; Version: 1.0
;; Created: 2007-11-02
;; Keywords: ruby rails languages oop
;; $URL: http://emacs-rails.rubyforge.org/svn/trunk/inflections.el $
;; $Id: inflections.el 216 2007-11-02 20:48:22Z dimaexe $

;; This file is NOT part of GNU Emacs.

;;; License

Expand Down Expand Up @@ -145,3 +146,4 @@
str)))

(provide 'inflections)
;;; inflections.el ends here
45 changes: 26 additions & 19 deletions elpa-to-submit/jump.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
;; Version: 2.0
;; Created: 2008-08-21
;; Keywords: project, convenience, navigation
;; Package-Requires: ((findr "0.7")
;; (inflections "1.0"))

;; This file is NOT part of GNU Emacs.

Expand Down Expand Up @@ -78,9 +80,9 @@

(defun jump-find-file-in-dir (dir)
"if `ido-mode' is turned on use ido speedups finding the file"
(if ido-mode
(if (or (equal ido-mode 'file) (equal ido-mode 'both))
(ido-find-file-in-dir dir)
(let ((default-dir dir)) (find-file))))
(let ((default-directory dir)) (call-interactively 'find-file))))

(defun jump-method ()
"Return the method defined at the current position in current
Expand Down Expand Up @@ -118,7 +120,7 @@ from all matches."
(interactive "Mfile: ")
(let ((file-cons (cons (file-name-nondirectory file) file))
file-alist)
(if (string-match "/$" file) ;; TODO: ensure that the directory exists
(if (and (equal (file-name-directory file) file) (file-exists-p file))
(jump-find-file-in-dir (expand-file-name file root)) ;; open directory
(if (file-exists-p file)
(find-file file) ;; open file
Expand Down Expand Up @@ -146,8 +148,8 @@ line inside of method."
(or (string-equal (jump-method) method)
(and (> (forward-line 1) 0)
(goto-char (point-min)))))))
(unless (equal results 1) t)))

(when (and (commandp 'recenter-top-bottom) (not (equal results 1))) (recenter-top-bottom))))
(defun jump-to-path (path)
"Jump to the location specified by PATH (regexp allowed in
path). If path ends in / then just look in that directory"
Expand All @@ -156,11 +158,11 @@ path). If path ends in / then just look in that directory"
(when (string-match "^\\(.*\\)#\\(.*\\)$" path)
(setf method (match-string 2 path))
(setf file (match-string 1 path)))
(if (jump-to-file file) ;; returns t as long as a file was found
(when method (jump-to-method method) t))))
(when (jump-to-file file) ;; returns t as long as a file was found
(when method (jump-to-method method))
t)))

(defun jump-insert-matches (spec matches)
(message (format "%S" (cons spec matches)))
(if matches
(let ((count 1) (new-spec spec) (spec nil))
(while (not (equal spec new-spec))
Expand Down Expand Up @@ -204,21 +206,22 @@ path). If path ends in / then just look in that directory"
(defun jump-to (spec &optional matches make)
"Jump to a spot defined by SPEC. If optional argument MATCHES
replace all '\\n' portions of SPEC with the nth (1 indexed)
element of MATCHES. If optiona argument MAKE, then create the
element of MATCHES. If optional argument MAKE, then create the
target file if it doesn't exist, if MAKE is a function then use
MAKE to create the target file."
(if (functionp spec) (eval (list spec matches)) ;; custom function in spec
(let ((path (jump-insert-matches spec matches)))
(unless (or (jump-to-path path)
(and matches (jump-to-all-inflections spec matches)))
(when make (message (format "making %s" path))
(if (not (or (jump-to-path path)
(and matches (jump-to-all-inflections spec matches))))
(when make (message (format "making %s" path))
(let ((path (if (or (string-match "^\\(.*?\\)\\.\\*" path)
(string-match "^\\(.*/\\)$" path))
(read-from-minibuffer "create " (match-string 1 path))
path)))
(when (functionp make) (eval (list make path)))
(find-file (concat root (if (string-match "^\\(.*\\)#" path)
(match-string 1 path) path)))))))))
(match-string 1 path) path)))))
t))))

(defun jump-from (spec)
"Match SPEC to the current location returning a list of any matches"
Expand Down Expand Up @@ -281,12 +284,16 @@ find the current method which defaults to `which-function'."
(car spec)) (cdr spec))
spec))
specs))
until (setf matches (jump-from (car spec)))
finally (cond
((equal t matches)
(jump-to (cdr spec) nil (if create (quote ,make))))
((consp matches)
(jump-to (cdr spec) matches (if create (quote ,make))))))))))
;; don't stop until both the front and the back match
;;
;; the back should match if the user is presented with a list
;; of files, or a single file is jumped to
until (and (setf matches (jump-from (car spec)))
(cond
((equal t matches)
(jump-to (cdr spec) nil (if create (quote ,make))))
((consp matches)
(jump-to (cdr spec) matches (if create (quote ,make)))))))))))

(provide 'jump)
;;; jump.el ends here
79 changes: 49 additions & 30 deletions elpa-to-submit/rinari.el
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ exec-to-string command, but it works and seems fast"
'flymake-display-err-menu-for-current-line)
(flymake-mode t))))))

;; 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 e3dd93a

Please sign in to comment.