• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/ruby-104/ruby/misc/

Lines Matching defs:ruby

3 ;;;  $Id: inf-ruby.el 38107 2012-12-01 08:13:04Z nobu $
6 ;;; Inferior Ruby Mode - ruby process in a buffer.
11 ;;; (0) check ruby-program-name variable that can run your environment.
13 ;;; (1) modify .emacs to use ruby-mode
16 ;;; (autoload 'ruby-mode "ruby-mode"
17 ;;; "Mode for editing ruby source files" t)
19 ;;; (append '(("\\.rb$" . ruby-mode)) auto-mode-alist))
20 ;;; (setq interpreter-mode-alist (append '(("ruby" . ruby-mode))
23 ;;; (2) set to load inf-ruby and set inf-ruby key definition in ruby-mode.
25 ;;; (autoload 'run-ruby "inf-ruby"
27 ;;; (autoload 'inf-ruby-keys "inf-ruby"
28 ;;; "Set local key defs for inf-ruby in ruby-mode")
29 ;;; (add-hook 'ruby-mode-hook
31 ;;; (inf-ruby-keys)
47 ;;; [ruby-list:39937]
50 ;;; * misc/inf-ruby.el (inferior-ruby-error-regexp-alist): regexp
51 ;;; alist for error message from ruby.
53 ;;; * misc/inf-ruby.el (inferior-ruby-mode): fixed for Emacs.
55 ;;; * misc/inf-ruby.el (ruby-send-region): compilation-parse-errors
60 ;;; * misc/inf-ruby.el (inf-ruby-keys): ruby-send-definition
61 ;;; conflicted with ruby-insert-end.
63 ;;; * misc/inf-ruby.el (inferior-ruby-mode): compilation-minor-mode.
65 ;;; * misc/inf-ruby.el (ruby-send-region): send as here document to
66 ;;; adjust source file/line. [ruby-talk:47113], [ruby-dev:17965]
68 ;;; * misc/inf-ruby.el (ruby-send-terminator): added to make unique
88 ;;; ruby 1.3 cycle
100 ;;; inferior-ruby-first-prompt-pattern
101 ;;; inferior-ruby-prompt-pattern
105 ;;; remove M-C-x in inferior-ruby-mode
114 (require 'ruby-mode)
119 ;(defvar ruby-program-name "rbc --noreadline"
120 ; "*Program invoked by the run-ruby command")
122 ;(defvar inferior-ruby-first-prompt-pattern "^rbc0> *"
123 ; "first prompt regex pattern of ruby interpreter.")
125 ;(defvar inferior-ruby-prompt-pattern "^\\(rbc.[>*\"'] *\\)+"
126 ; "prompt regex pattern of ruby interpreter.")
129 (defvar ruby-program-name "irb --inf-ruby-mode"
130 "*Program invoked by the run-ruby command")
132 (defvar inferior-ruby-first-prompt-pattern "^irb(.*)[0-9:]+0> *"
133 "first prompt regex pattern of ruby interpreter.")
135 (defvar inferior-ruby-prompt-pattern "^\\(irb(.*)[0-9:]+[>*\"'] *\\)+"
136 "prompt regex pattern of ruby interpreter.")
141 (defvar inferior-ruby-mode-hook nil
142 "*Hook for customising inferior-ruby mode.")
143 (defvar inferior-ruby-mode-map nil
144 "*Mode map for inferior-ruby-mode")
146 (defconst inferior-ruby-error-regexp-alist
150 (cond ((not inferior-ruby-mode-map)
151 (setq inferior-ruby-mode-map
153 ; (define-key inferior-ruby-mode-map "\M-\C-x" ;gnu convention
154 ; 'ruby-send-definition)
155 ; (define-key inferior-ruby-mode-map "\C-x\C-e" 'ruby-send-last-sexp)
156 (define-key inferior-ruby-mode-map "\C-c\C-l" 'ruby-load-file)
159 (defun inf-ruby-keys ()
160 "Set local key defs for inf-ruby in ruby-mode"
161 (define-key ruby-mode-map "\M-\C-x" 'ruby-send-definition)
162 ; (define-key ruby-mode-map "\C-x\C-e" 'ruby-send-last-sexp)
163 (define-key ruby-mode-map "\C-c\C-b" 'ruby-send-block)
164 (define-key ruby-mode-map "\C-c\M-b" 'ruby-send-block-and-go)
165 (define-key ruby-mode-map "\C-c\C-x" 'ruby-send-definition)
166 (define-key ruby-mode-map "\C-c\M-x" 'ruby-send-definition-and-go)
167 (define-key ruby-mode-map "\C-c\C-r" 'ruby-send-region)
168 (define-key ruby-mode-map "\C-c\M-r" 'ruby-send-region-and-go)
169 (define-key ruby-mode-map "\C-c\C-z" 'switch-to-ruby)
170 (define-key ruby-mode-map "\C-c\C-l" 'ruby-load-file)
171 (define-key ruby-mode-map "\C-c\C-s" 'run-ruby)
174 (defvar ruby-buffer nil "current ruby (actually irb) process buffer.")
176 (defun inferior-ruby-mode ()
177 "Major mode for interacting with an inferior ruby (irb) process.
180 \\{inferior-ruby-mode-map}
182 A ruby process can be fired up with M-x run-ruby.
185 inferior-ruby-mode-hook (in that order).
187 You can send text to the inferior ruby process from other buffers containing
189 switch-to-ruby switches the current buffer to the ruby process buffer.
190 ruby-send-definition sends the current definition to the ruby process.
191 ruby-send-region sends the current region to the ruby process.
193 ruby-send-definition-and-go, ruby-send-region-and-go,
194 switch to the ruby process buffer after sending their text.
196 documentation for variable ruby-buffer.
204 Tab indents for ruby; with argument, shifts rest
212 ;; Customise in inferior-ruby-mode-hook
214 (setq comint-prompt-regexp inferior-ruby-prompt-pattern)
216 (ruby-mode-variables)
217 (setq major-mode 'inferior-ruby-mode)
220 (use-local-map inferior-ruby-mode-map)
221 (setq comint-input-filter (function ruby-input-filter))
222 (setq comint-get-old-input (function ruby-get-old-input))
224 (setq compilation-error-regexp-alist inferior-ruby-error-regexp-alist)
226 (run-hooks 'inferior-ruby-mode-hook))
228 (defvar inferior-ruby-filter-regexp "\\`\\s *\\S ?\\S ?\\s *\\'"
232 (defun ruby-input-filter (str)
233 "Don't save anything matching inferior-ruby-filter-regexp"
234 (not (string-match inferior-ruby-filter-regexp str)))
246 (defun ruby-get-old-input ()
250 (re-search-backward inferior-ruby-first-prompt-pattern)
252 inferior-ruby-prompt-pattern)
255 (defun ruby-args-to-list (string)
260 (ruby-args-to-list (substring string (+ 1 where)
265 (ruby-args-to-list (substring string pos
268 (defun run-ruby (cmd)
269 "Run an inferior Ruby process, input and output via buffer *ruby*.
270 If there is a process already running in `*ruby*', switch to that buffer.
272 of `ruby-program-name'). Runs the hooks `inferior-ruby-mode-hook'
277 (read-string "Run Ruby: " ruby-program-name)
278 ruby-program-name)))
279 (if (not (comint-check-proc "*ruby*"))
280 (let ((cmdlist (ruby-args-to-list cmd)))
281 (set-buffer (apply 'make-comint "ruby" (car cmdlist)
283 (inferior-ruby-mode)))
284 (setq ruby-program-name cmd)
285 (setq ruby-buffer "*ruby*")
286 (pop-to-buffer "*ruby*"))
288 (defconst ruby-send-terminator "--inf-ruby-%x-%d-%d-%d--"
290 Must not contain ruby meta characters.")
292 (defconst ruby-eval-separator "")
294 (defun ruby-send-region (start end)
305 (setq term (apply 'format ruby-send-terminator (random) (current-time)))
309 (let ((m (process-mark (ruby-proc))))
312 (insert ruby-eval-separator "\n")
314 (comint-send-string (ruby-proc) (format "eval <<'%s', nil, %S, %d\n" term file line))
315 (comint-send-region (ruby-proc) start end)
316 (comint-send-string (ruby-proc) (concat "\n" term "\n"))))
318 (defun ruby-send-definition ()
322 (ruby-end-of-defun)
324 (ruby-beginning-of-defun)
325 (ruby-send-region (point) end))))
327 ;(defun ruby-send-last-sexp ()
330 ; (ruby-send-region (save-excursion (backward-sexp) (point)) (point)))
332 (defun ruby-send-block ()
336 (ruby-end-of-block)
339 (ruby-beginning-of-block)
340 (ruby-send-region (point) end))))
342 (defun switch-to-ruby (eob-p)
343 "Switch to the ruby process buffer.
346 (if (get-buffer ruby-buffer)
347 (pop-to-buffer ruby-buffer)
348 (error "No current process buffer. See variable ruby-buffer."))
353 (defun ruby-send-region-and-go (start end)
357 (ruby-send-region start end)
358 (switch-to-ruby t))
360 (defun ruby-send-definition-and-go ()
364 (ruby-send-definition)
365 (switch-to-ruby t))
367 (defun ruby-send-block-and-go ()
371 (ruby-send-block)
372 (switch-to-ruby t))
374 (defvar ruby-source-modes '(ruby-mode)
377 considered a ruby source file by ruby-load-file.
380 (defvar ruby-prev-l/c-dir/file nil
382 Caches the last pair used in the last ruby-load-file command.
386 (defun ruby-load-file (file-name)
388 (interactive (comint-get-source "Load Ruby file: " ruby-prev-l/c-dir/file
389 ruby-source-modes t)) ; T because LOAD
392 (setq ruby-prev-l/c-dir/file (cons (file-name-directory file-name)
394 (comint-send-string (ruby-proc) (concat "(load \""
398 (defun ruby-proc ()
399 "Returns the current ruby process. See variable ruby-buffer."
400 (let ((proc (get-buffer-process (if (eq major-mode 'inferior-ruby-mode)
402 ruby-buffer))))
404 (error "No current process. See variable ruby-buffer"))))
408 (defvar inf-ruby-load-hook nil
409 "This hook is run when inf-ruby is loaded in.
412 (run-hooks 'inf-ruby-load-hook)
414 (provide 'inf-ruby)
416 ;;; inf-ruby.el ends here