ruby_learner 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +58 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +65 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/new_terminal +25 -0
  13. data/bin/setup +8 -0
  14. data/docs/happy_ruby/RussOlsen_EloquentRuby_c1.pdf +0 -0
  15. data/docs/happy_ruby/RussOlsen_EloquentRuby_c5.pdf +0 -0
  16. data/docs/happy_ruby/TanoshiiRuby_v3_c23.pdf +0 -0
  17. data/docs/happy_ruby/TanoshiiRuby_v5_c1.pdf +0 -0
  18. data/docs/happy_ruby/TanoshiiRuby_v5_c2-3.pdf +0 -0
  19. data/docs/happy_ruby/c2.ipynb +479 -0
  20. data/docs/happy_ruby/c3_4.ipynb +237 -0
  21. data/docs/seminar/8-1.org +18 -0
  22. data/exe/ruby_learner +5 -0
  23. data/lib/ruby_learner/h.rb +14 -0
  24. data/lib/ruby_learner/methods.rb +131 -0
  25. data/lib/ruby_learner/random_h.rb +16 -0
  26. data/lib/ruby_learner/ruby_learner.rb +43 -0
  27. data/lib/ruby_learner/sequential_h.rb +15 -0
  28. data/lib/ruby_learner/typing_practice.rb +21 -0
  29. data/lib/ruby_learner/version.rb +3 -0
  30. data/questions/random_check/.rspec +1 -0
  31. data/questions/random_check/random_h.rb +16 -0
  32. data/questions/random_check/section_1/.rspec +1 -0
  33. data/questions/random_check/section_1/lib/answer.rb +15 -0
  34. data/questions/random_check/section_1/lib/sentence.org +9 -0
  35. data/questions/random_check/section_1/lib/workplace.rb +5 -0
  36. data/questions/random_check/section_1/spec/spec_helper.rb +100 -0
  37. data/questions/random_check/section_1/spec/workplace_spec.rb +10 -0
  38. data/questions/random_check/section_2/.rspec +1 -0
  39. data/questions/random_check/section_2/lib/answer.rb +17 -0
  40. data/questions/random_check/section_2/lib/sentence.org +12 -0
  41. data/questions/random_check/section_2/lib/workplace.rb +5 -0
  42. data/questions/random_check/section_2/spec/.rspec +1 -0
  43. data/questions/random_check/section_2/spec/spec_helper.rb +100 -0
  44. data/questions/random_check/section_2/spec/workplace_spec.rb +11 -0
  45. data/questions/sequential_check/section_1/part_1/lib/answer.rb +9 -0
  46. data/questions/sequential_check/section_1/part_1/lib/sentence.org +9 -0
  47. data/questions/sequential_check/section_1/part_1/lib/workplace.rb +5 -0
  48. data/questions/sequential_check/section_1/part_1/spec/spec_helper.rb +100 -0
  49. data/questions/sequential_check/section_1/part_1/spec/workplace_spec.rb +10 -0
  50. data/questions/sequential_check/section_1/part_2/lib/answer.rb +16 -0
  51. data/questions/sequential_check/section_1/part_2/lib/sentence.org +12 -0
  52. data/questions/sequential_check/section_1/part_2/lib/workplace.rb +5 -0
  53. data/questions/sequential_check/section_1/part_2/spec/.rspec +1 -0
  54. data/questions/sequential_check/section_1/part_2/spec/spec_helper.rb +100 -0
  55. data/questions/sequential_check/section_1/part_2/spec/workplace_spec.rb +11 -0
  56. data/ruby_learner.gemspec +41 -0
  57. data/takahashi/docs/README.org +139 -0
  58. data/takahashi/docs/drill.html +875 -0
  59. data/takahashi/docs/drill.html~ +877 -0
  60. data/takahashi/docs/drill.org +446 -0
  61. data/takahashi/docs/ruby_for_beginner.html +2642 -0
  62. data/takahashi/docs/ruby_for_beginner.org +1430 -0
  63. data/takahashi/sample_prog/answer/10_1.rb +5 -0
  64. data/takahashi/sample_prog/answer/11_1.rb +5 -0
  65. data/takahashi/sample_prog/answer/11_2.rb +4 -0
  66. data/takahashi/sample_prog/answer/1_1.rb +1 -0
  67. data/takahashi/sample_prog/answer/1_2.rb +1 -0
  68. data/takahashi/sample_prog/answer/1_3.rb +1 -0
  69. data/takahashi/sample_prog/answer/2_1.rb +5 -0
  70. data/takahashi/sample_prog/answer/2_2.rb +12 -0
  71. data/takahashi/sample_prog/answer/3_1.rb +10 -0
  72. data/takahashi/sample_prog/answer/4_1.rb +7 -0
  73. data/takahashi/sample_prog/answer/5_1.rb +6 -0
  74. data/takahashi/sample_prog/answer/5_2.rb +3 -0
  75. data/takahashi/sample_prog/answer/6_1.rb +3 -0
  76. data/takahashi/sample_prog/answer/6_2.rb +5 -0
  77. data/takahashi/sample_prog/answer/6_3.rb +5 -0
  78. data/takahashi/sample_prog/answer/6_4.rb +7 -0
  79. data/takahashi/sample_prog/answer/7_1.rb +3 -0
  80. data/takahashi/sample_prog/answer/7_2.rb +8 -0
  81. data/takahashi/sample_prog/answer/9_1.rb +3 -0
  82. data/takahashi/sample_prog/answer/9_2.rb +5 -0
  83. data/takahashi/sample_prog/answer/9_3.rb +10 -0
  84. data/takahashi/sample_prog/answer/hello.rb +3 -0
  85. data/workshop/.rspec +1 -0
  86. data/workshop/emacs.d/ac-comphist.dat +50 -0
  87. data/workshop/emacs.d/cp5022x.el +156 -0
  88. data/workshop/emacs.d/elpa/archives/gnu/archive-contents +1240 -0
  89. data/workshop/emacs.d/elpa/archives/melpa/archive-contents +2 -0
  90. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/auto-complete-autoloads.el +65 -0
  91. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/auto-complete-config.el +551 -0
  92. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/auto-complete-config.elc +0 -0
  93. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/auto-complete-pkg.el +6 -0
  94. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/auto-complete.el +2164 -0
  95. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/auto-complete.elc +0 -0
  96. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/ada-mode +72 -0
  97. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/c++-mode +99 -0
  98. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/c-mode +55 -0
  99. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/caml-mode +231 -0
  100. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/clojure-mode +580 -0
  101. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/clojurescript-mode +475 -0
  102. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/coq-mode +278 -0
  103. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/css-mode +874 -0
  104. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/erlang-mode +216 -0
  105. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/ess-julia-mode +37 -0
  106. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/go-mode +25 -0
  107. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/haskell-mode +679 -0
  108. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/java-mode +53 -0
  109. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/js-mode +148 -0
  110. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/julia-mode +37 -0
  111. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/lua-mode +21 -0
  112. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/nim-mode +70 -0
  113. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/objc-mode +161 -0
  114. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/octave-mode +46 -0
  115. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/php-mode +6144 -0
  116. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/python-mode +379 -0
  117. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/qml-mode +183 -0
  118. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/ruby-mode +181 -0
  119. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/scala-mode +1347 -0
  120. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/scheme-mode +216 -0
  121. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/sclang-mode +1481 -0
  122. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/sh-mode +182 -0
  123. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/swift-mode +87 -0
  124. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/tcl-mode +172 -0
  125. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/ts-mode +797 -0
  126. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/tuareg-mode +231 -0
  127. data/workshop/emacs.d/elpa/auto-complete-20170124.1845/dict/verilog-mode +313 -0
  128. data/workshop/emacs.d/elpa/better-defaults-20170613.2104/better-defaults-autoloads.el +16 -0
  129. data/workshop/emacs.d/elpa/better-defaults-20170613.2104/better-defaults-pkg.el +2 -0
  130. data/workshop/emacs.d/elpa/better-defaults-20170613.2104/better-defaults.el +90 -0
  131. data/workshop/emacs.d/elpa/better-defaults-20170613.2104/better-defaults.elc +0 -0
  132. data/workshop/emacs.d/elpa/haml-mode-20170923.2153/haml-mode-autoloads.el +26 -0
  133. data/workshop/emacs.d/elpa/haml-mode-20170923.2153/haml-mode-pkg.el +2 -0
  134. data/workshop/emacs.d/elpa/haml-mode-20170923.2153/haml-mode.el +877 -0
  135. data/workshop/emacs.d/elpa/haml-mode-20170923.2153/haml-mode.elc +0 -0
  136. data/workshop/emacs.d/elpa/haml-mode-readme.txt +8 -0
  137. data/workshop/emacs.d/elpa/material-theme-20171123.1040/material-light-theme.el +918 -0
  138. data/workshop/emacs.d/elpa/material-theme-20171123.1040/material-light-theme.elc +0 -0
  139. data/workshop/emacs.d/elpa/material-theme-20171123.1040/material-theme-autoloads.el +32 -0
  140. data/workshop/emacs.d/elpa/material-theme-20171123.1040/material-theme-pkg.el +8 -0
  141. data/workshop/emacs.d/elpa/material-theme-20171123.1040/material-theme.el +912 -0
  142. data/workshop/emacs.d/elpa/material-theme-20171123.1040/material-theme.elc +0 -0
  143. data/workshop/emacs.d/elpa/ox-bibtex-chinese-readme.txt +21 -0
  144. data/workshop/emacs.d/elpa/popup-20160709.729/popup-autoloads.el +15 -0
  145. data/workshop/emacs.d/elpa/popup-20160709.729/popup-pkg.el +2 -0
  146. data/workshop/emacs.d/elpa/popup-20160709.729/popup.el +1432 -0
  147. data/workshop/emacs.d/elpa/popup-20160709.729/popup.elc +0 -0
  148. data/workshop/emacs.d/elpa/yaml-mode-20180212.1556/yaml-mode-autoloads.el +33 -0
  149. data/workshop/emacs.d/elpa/yaml-mode-20180212.1556/yaml-mode-pkg.el +2 -0
  150. data/workshop/emacs.d/elpa/yaml-mode-20180212.1556/yaml-mode.el +470 -0
  151. data/workshop/emacs.d/elpa/yaml-mode-20180212.1556/yaml-mode.elc +0 -0
  152. data/workshop/emacs.d/elpa/yaml-mode-readme.txt +25 -0
  153. data/workshop/emacs.d/haml-mode-master/.gitignore +1 -0
  154. data/workshop/emacs.d/haml-mode-master/.mailmap +2 -0
  155. data/workshop/emacs.d/haml-mode-master/MIT-LICENSE +20 -0
  156. data/workshop/emacs.d/haml-mode-master/README.md +47 -0
  157. data/workshop/emacs.d/haml-mode-master/haml-mode.el +887 -0
  158. data/workshop/emacs.d/iceberg_theme.el +202 -0
  159. data/workshop/emacs.d/init-open-recentf.el +133 -0
  160. data/workshop/emacs.d/init.el +229 -0
  161. data/workshop/emacs.d/inits/line-num.el +264 -0
  162. data/workshop/emacs.d/install-elisp.el +366 -0
  163. data/workshop/emacs.d/markdown-mode/markdown-mode.el +5978 -0
  164. data/workshop/emacs.d/notes +12 -0
  165. data/workshop/emacs.d/processing-mode/processing-mode.el +275 -0
  166. data/workshop/emacs.d/recentf +31 -0
  167. data/workshop/emacs.d/ruby-mode/inf-ruby.el +416 -0
  168. data/workshop/emacs.d/ruby-mode/rdoc-mode.el +130 -0
  169. data/workshop/emacs.d/ruby-mode/ruby-electric.el +205 -0
  170. data/workshop/emacs.d/ruby-mode/ruby-mode.el +1496 -0
  171. data/workshop/emacs.d/ruby-mode/ruby-style.el +78 -0
  172. data/workshop/emacs.d/ruby-mode/rubydb2x.el +104 -0
  173. data/workshop/emacs.d/ruby-mode/rubydb3x.el +115 -0
  174. data/workshop/emacs.d/ruby_learner_init.el +244 -0
  175. data/workshop/emacs.d/themes/dracula-theme.el +431 -0
  176. data/workshop/emacs.d/themes/iceberg-theme.el +205 -0
  177. data/workshop/emacs.d/themes/my-misterioso-theme.el +109 -0
  178. data/workshop/emacs.d/themes/my-wombat-theme.el +121 -0
  179. data/workshop/emacs.d/wiki-mode/wiki.el +976 -0
  180. data/workshop/emacs_help.org +34 -0
  181. data/workshop/lib/answer.rb +1 -0
  182. data/workshop/lib/sentence.org +1 -0
  183. data/workshop/lib/workplace.rb +1 -0
  184. data/workshop/restore/empty.rb +0 -0
  185. data/workshop/spec/spec_helper.rb +100 -0
  186. data/workshop/spec/workplace_spec.rb +1 -0
  187. data/workshop/training_data.txt +3 -0
  188. metadata +343 -0
@@ -0,0 +1,416 @@
1
+ ;;; -*-Emacs-Lisp-*-
2
+ ;;;
3
+ ;;; $Id: inf-ruby.el 30505 2011-01-10 04:51:20Z nobu $
4
+ ;;; $Author: nobu $
5
+ ;;;
6
+ ;;; Inferior Ruby Mode - ruby process in a buffer.
7
+ ;;; adapted from cmuscheme.el
8
+ ;;;
9
+ ;;; Usage:
10
+ ;;;
11
+ ;;; (0) check ruby-program-name variable that can run your environment.
12
+ ;;;
13
+ ;;; (1) modify .emacs to use ruby-mode
14
+ ;;; for example :
15
+ ;;;
16
+ ;;; (autoload 'ruby-mode "ruby-mode"
17
+ ;;; "Mode for editing ruby source files" t)
18
+ ;;; (setq auto-mode-alist
19
+ ;;; (append '(("\\.rb$" . ruby-mode)) auto-mode-alist))
20
+ ;;; (setq interpreter-mode-alist (append '(("ruby" . ruby-mode))
21
+ ;;; interpreter-mode-alist))
22
+ ;;;
23
+ ;;; (2) set to load inf-ruby and set inf-ruby key definition in ruby-mode.
24
+ ;;;
25
+ ;;; (autoload 'run-ruby "inf-ruby"
26
+ ;;; "Run an inferior Ruby process")
27
+ ;;; (autoload 'inf-ruby-keys "inf-ruby"
28
+ ;;; "Set local key defs for inf-ruby in ruby-mode")
29
+ ;;; (add-hook 'ruby-mode-hook
30
+ ;;; '(lambda ()
31
+ ;;; (inf-ruby-keys)
32
+ ;;; ))
33
+ ;;;
34
+ ;;; HISTORY
35
+ ;;; senda - 8 Apr 1998: Created.
36
+ ;;; $Log$
37
+ ;;; Revision 1.7 2004/07/27 08:11:36 matz
38
+ ;;; * eval.c (rb_eval): copy on write for argument local variable
39
+ ;;; assignment.
40
+ ;;;
41
+ ;;; * eval.c (assign): ditto.
42
+ ;;;
43
+ ;;; * eval.c (rb_call0): update ruby_frame->argv with the default
44
+ ;;; value used for the optional arguments.
45
+ ;;;
46
+ ;;; * object.c (Init_Object): "===" calls rb_obj_equal() directly.
47
+ ;;; [ruby-list:39937]
48
+ ;;;
49
+ ;;; Revision 1.6 2002/09/07 14:35:46 nobu
50
+ ;;; * misc/inf-ruby.el (inferior-ruby-error-regexp-alist): regexp
51
+ ;;; alist for error message from ruby.
52
+ ;;;
53
+ ;;; * misc/inf-ruby.el (inferior-ruby-mode): fixed for Emacs.
54
+ ;;;
55
+ ;;; * misc/inf-ruby.el (ruby-send-region): compilation-parse-errors
56
+ ;;; doesn't parse first line, so insert separators before each
57
+ ;;; evaluations.
58
+ ;;;
59
+ ;;; Revision 1.5 2002/08/19 10:05:47 nobu
60
+ ;;; * misc/inf-ruby.el (inf-ruby-keys): ruby-send-definition
61
+ ;;; conflicted with ruby-insert-end.
62
+ ;;;
63
+ ;;; * misc/inf-ruby.el (inferior-ruby-mode): compilation-minor-mode.
64
+ ;;;
65
+ ;;; * misc/inf-ruby.el (ruby-send-region): send as here document to
66
+ ;;; adjust source file/line. [ruby-talk:47113], [ruby-dev:17965]
67
+ ;;;
68
+ ;;; * misc/inf-ruby.el (ruby-send-terminator): added to make unique
69
+ ;;; terminator.
70
+ ;;;
71
+ ;;; Revision 1.4 2002/01/29 07:16:09 matz
72
+ ;;; * file.c (rb_stat_rdev_major): added. [new]
73
+ ;;;
74
+ ;;; * file.c (rb_stat_rdev_minor): added. [new]
75
+ ;;;
76
+ ;;; * file.c (rb_stat_inspect): print mode in octal.
77
+ ;;;
78
+ ;;; Revision 1.3 1999/12/01 09:24:18 matz
79
+ ;;; 19991201
80
+ ;;;
81
+ ;;; Revision 1.2 1999/08/13 05:45:18 matz
82
+ ;;; 1.4.0
83
+ ;;;
84
+ ;;; Revision 1.1.1.1.2.1 1999/07/15 07:59:59 matz
85
+ ;;; 990715
86
+ ;;;
87
+ ;;; Revision 1.1.1.1 1999/01/20 04:59:36 matz
88
+ ;;; ruby 1.3 cycle
89
+ ;;;
90
+ ;;; Revision 1.1.2.1 1998/12/16 07:30:36 matz
91
+ ;;; first public release of 1.1d (pre1.2) series
92
+ ;;;
93
+ ;;; Revision 1.4 1998/05/20 02:45:58 senda
94
+ ;;; default program to irb
95
+ ;;;
96
+ ;;; Revision 1.3 1998/04/10 04:11:30 senda
97
+ ;;; modification by Matsumoto san (1.1b9_09)
98
+ ;;; remove-in-string defined
99
+ ;;; global variable :
100
+ ;;; inferior-ruby-first-prompt-pattern
101
+ ;;; inferior-ruby-prompt-pattern
102
+ ;;; defined
103
+ ;;;
104
+ ;;; Revision 1.2 1998/04/09 07:53:42 senda
105
+ ;;; remove M-C-x in inferior-ruby-mode
106
+ ;;;
107
+ ;;; Revision 1.1 1998/04/09 07:28:36 senda
108
+ ;;; Initial revision
109
+ ;;;
110
+ ;;;
111
+
112
+ (require 'comint)
113
+ (require 'compile)
114
+ (require 'ruby-mode)
115
+
116
+ ;;
117
+ ;; you may change these variables
118
+ ;;
119
+ ;(defvar ruby-program-name "rbc --noreadline"
120
+ ; "*Program invoked by the run-ruby command")
121
+ ;
122
+ ;(defvar inferior-ruby-first-prompt-pattern "^rbc0> *"
123
+ ; "first prompt regex pattern of ruby interpreter.")
124
+ ;
125
+ ;(defvar inferior-ruby-prompt-pattern "^\\(rbc.[>*\"'] *\\)+"
126
+ ; "prompt regex pattern of ruby interpreter.")
127
+
128
+ ;;;; for irb
129
+ (defvar ruby-program-name "irb --inf-ruby-mode"
130
+ "*Program invoked by the run-ruby command")
131
+
132
+ (defvar inferior-ruby-first-prompt-pattern "^irb(.*)[0-9:]+0> *"
133
+ "first prompt regex pattern of ruby interpreter.")
134
+
135
+ (defvar inferior-ruby-prompt-pattern "^\\(irb(.*)[0-9:]+[>*\"'] *\\)+"
136
+ "prompt regex pattern of ruby interpreter.")
137
+
138
+ ;;
139
+ ;; mode variables
140
+ ;;
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")
145
+
146
+ (defconst inferior-ruby-error-regexp-alist
147
+ '(("SyntaxError: compile error\n^\\([^\(].*\\):\\([1-9][0-9]*\\):" 1 2)
148
+ ("^\tfrom \\([^\(].*\\):\\([1-9][0-9]*\\)\\(:in `.*'\\)?$" 1 2)))
149
+
150
+ (cond ((not inferior-ruby-mode-map)
151
+ (setq inferior-ruby-mode-map
152
+ (copy-keymap comint-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)
157
+ ))
158
+
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)
172
+ )
173
+
174
+ (defvar ruby-buffer nil "current ruby (actually irb) process buffer.")
175
+
176
+ (defun inferior-ruby-mode ()
177
+ "Major mode for interacting with an inferior ruby (irb) process.
178
+
179
+ The following commands are available:
180
+ \\{inferior-ruby-mode-map}
181
+
182
+ A ruby process can be fired up with M-x run-ruby.
183
+
184
+ Customisation: Entry to this mode runs the hooks on comint-mode-hook and
185
+ inferior-ruby-mode-hook (in that order).
186
+
187
+ You can send text to the inferior ruby process from other buffers containing
188
+ Ruby source.
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.
192
+
193
+ ruby-send-definition-and-go, ruby-send-region-and-go,
194
+ switch to the ruby process buffer after sending their text.
195
+ For information on running multiple processes in multiple buffers, see
196
+ documentation for variable ruby-buffer.
197
+
198
+ Commands:
199
+ Return after the end of the process' output sends the text from the
200
+ end of process to point.
201
+ Return before the end of the process' output copies the sexp ending at point
202
+ to the end of the process' output, and sends it.
203
+ Delete converts tabs to spaces as it moves back.
204
+ Tab indents for ruby; with argument, shifts rest
205
+ of expression rigidly with the current line.
206
+ C-M-q does Tab on each line starting within following expression.
207
+ Paragraphs are separated only by blank lines. # start comments.
208
+ If you accidentally suspend your process, use \\[comint-continue-subjob]
209
+ to continue it."
210
+ (interactive)
211
+ (comint-mode)
212
+ ;; Customise in inferior-ruby-mode-hook
213
+ ;(setq comint-prompt-regexp "^[^>\n]*>+ *")
214
+ (setq comint-prompt-regexp inferior-ruby-prompt-pattern)
215
+ ;;(scheme-mode-variables)
216
+ (ruby-mode-variables)
217
+ (setq major-mode 'inferior-ruby-mode)
218
+ (setq mode-name "Inferior Ruby")
219
+ (setq mode-line-process '(":%s"))
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))
223
+ (compilation-shell-minor-mode t)
224
+ (make-local-variable 'compilation-error-regexp-alist)
225
+ (setq compilation-error-regexp-alist inferior-ruby-error-regexp-alist)
226
+ (run-hooks 'inferior-ruby-mode-hook))
227
+
228
+ (defvar inferior-ruby-filter-regexp "\\`\\s *\\S ?\\S ?\\s *\\'"
229
+ "*Input matching this regexp are not saved on the history list.
230
+ Defaults to a regexp ignoring all inputs of 0, 1, or 2 letters.")
231
+
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)))
235
+
236
+ ;; adapted from replace-in-string in XEmacs (subr.el)
237
+ (defun remove-in-string (str regexp)
238
+ "Remove all matches in STR for REGEXP and returns the new string."
239
+ (let ((rtn-str "") (start 0) match prev-start)
240
+ (while (setq match (string-match regexp str start))
241
+ (setq prev-start start
242
+ start (match-end 0)
243
+ rtn-str (concat rtn-str (substring str prev-start match))))
244
+ (concat rtn-str (substring str start))))
245
+
246
+ (defun ruby-get-old-input ()
247
+ "Snarf the sexp ending at point"
248
+ (save-excursion
249
+ (let ((end (point)))
250
+ (re-search-backward inferior-ruby-first-prompt-pattern)
251
+ (remove-in-string (buffer-substring (point) end)
252
+ inferior-ruby-prompt-pattern)
253
+ )))
254
+
255
+ (defun ruby-args-to-list (string)
256
+ (let ((where (string-match "[ \t]" string)))
257
+ (cond ((null where) (list string))
258
+ ((not (= where 0))
259
+ (cons (substring string 0 where)
260
+ (ruby-args-to-list (substring string (+ 1 where)
261
+ (length string)))))
262
+ (t (let ((pos (string-match "[^ \t]" string)))
263
+ (if (null pos)
264
+ nil
265
+ (ruby-args-to-list (substring string pos
266
+ (length string)))))))))
267
+
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.
271
+ With argument, allows you to edit the command line (default is value
272
+ of `ruby-program-name'). Runs the hooks `inferior-ruby-mode-hook'
273
+ \(after the `comint-mode-hook' is run).
274
+ \(Type \\[describe-mode] in the process buffer for a list of commands.)"
275
+
276
+ (interactive (list (if current-prefix-arg
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)
282
+ nil (cdr cmdlist)))
283
+ (inferior-ruby-mode)))
284
+ (setq ruby-program-name cmd)
285
+ (setq ruby-buffer "*ruby*")
286
+ (pop-to-buffer "*ruby*"))
287
+
288
+ (defconst ruby-send-terminator "--inf-ruby-%x-%d-%d-%d--"
289
+ "Template for irb here document terminator.
290
+ Must not contain ruby meta characters.")
291
+
292
+ (defconst ruby-eval-separator "")
293
+
294
+ (defun ruby-send-region (start end)
295
+ "Send the current region to the inferior Ruby process."
296
+ (interactive "r")
297
+ (let (term (file (buffer-file-name)) line)
298
+ (save-excursion
299
+ (save-restriction
300
+ (widen)
301
+ (goto-char start)
302
+ (setq line (+ start (forward-line (- start)) 1))
303
+ (goto-char start)
304
+ (while (progn
305
+ (setq term (apply 'format ruby-send-terminator (random) (current-time)))
306
+ (re-search-forward (concat "^" (regexp-quote term) "$") end t)))))
307
+ ;; compilation-parse-errors parses from second line.
308
+ (save-excursion
309
+ (let ((m (process-mark (ruby-proc))))
310
+ (set-buffer (marker-buffer m))
311
+ (goto-char m)
312
+ (insert ruby-eval-separator "\n")
313
+ (set-marker m (point))))
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"))))
317
+
318
+ (defun ruby-send-definition ()
319
+ "Send the current definition to the inferior Ruby process."
320
+ (interactive)
321
+ (save-excursion
322
+ (ruby-end-of-defun)
323
+ (let ((end (point)))
324
+ (ruby-beginning-of-defun)
325
+ (ruby-send-region (point) end))))
326
+
327
+ ;(defun ruby-send-last-sexp ()
328
+ ; "Send the previous sexp to the inferior Ruby process."
329
+ ; (interactive)
330
+ ; (ruby-send-region (save-excursion (backward-sexp) (point)) (point)))
331
+
332
+ (defun ruby-send-block ()
333
+ "Send the current block to the inferior Ruby process."
334
+ (interactive)
335
+ (save-excursion
336
+ (ruby-end-of-block)
337
+ (end-of-line)
338
+ (let ((end (point)))
339
+ (ruby-beginning-of-block)
340
+ (ruby-send-region (point) end))))
341
+
342
+ (defun switch-to-ruby (eob-p)
343
+ "Switch to the ruby process buffer.
344
+ With argument, positions cursor at end of buffer."
345
+ (interactive "P")
346
+ (if (get-buffer ruby-buffer)
347
+ (pop-to-buffer ruby-buffer)
348
+ (error "No current process buffer. See variable ruby-buffer."))
349
+ (cond (eob-p
350
+ (push-mark)
351
+ (goto-char (point-max)))))
352
+
353
+ (defun ruby-send-region-and-go (start end)
354
+ "Send the current region to the inferior Ruby process.
355
+ Then switch to the process buffer."
356
+ (interactive "r")
357
+ (ruby-send-region start end)
358
+ (switch-to-ruby t))
359
+
360
+ (defun ruby-send-definition-and-go ()
361
+ "Send the current definition to the inferior Ruby.
362
+ Then switch to the process buffer."
363
+ (interactive)
364
+ (ruby-send-definition)
365
+ (switch-to-ruby t))
366
+
367
+ (defun ruby-send-block-and-go ()
368
+ "Send the current block to the inferior Ruby.
369
+ Then switch to the process buffer."
370
+ (interactive)
371
+ (ruby-send-block)
372
+ (switch-to-ruby t))
373
+
374
+ (defvar ruby-source-modes '(ruby-mode)
375
+ "*Used to determine if a buffer contains Ruby source code.
376
+ If it's loaded into a buffer that is in one of these major modes, it's
377
+ considered a ruby source file by ruby-load-file.
378
+ Used by these commands to determine defaults.")
379
+
380
+ (defvar ruby-prev-l/c-dir/file nil
381
+ "Caches the last (directory . file) pair.
382
+ Caches the last pair used in the last ruby-load-file command.
383
+ Used for determining the default in the
384
+ next one.")
385
+
386
+ (defun ruby-load-file (file-name)
387
+ "Load a Ruby file into the inferior Ruby process."
388
+ (interactive (comint-get-source "Load Ruby file: " ruby-prev-l/c-dir/file
389
+ ruby-source-modes t)) ; T because LOAD
390
+ ; needs an exact name
391
+ (comint-check-source file-name) ; Check to see if buffer needs saved.
392
+ (setq ruby-prev-l/c-dir/file (cons (file-name-directory file-name)
393
+ (file-name-nondirectory file-name)))
394
+ (comint-send-string (ruby-proc) (concat "(load \""
395
+ file-name
396
+ "\"\)\n")))
397
+
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)
401
+ (current-buffer)
402
+ ruby-buffer))))
403
+ (or proc
404
+ (error "No current process. See variable ruby-buffer"))))
405
+
406
+ ;;; Do the user's customisation...
407
+
408
+ (defvar inf-ruby-load-hook nil
409
+ "This hook is run when inf-ruby is loaded in.
410
+ This is a good place to put keybindings.")
411
+
412
+ (run-hooks 'inf-ruby-load-hook)
413
+
414
+ (provide 'inf-ruby)
415
+
416
+ ;;; inf-ruby.el ends here
@@ -0,0 +1,130 @@
1
+ ;;
2
+ ;; rdoc-mode.el
3
+ ;; Major mode for RDoc editing
4
+ ;;
5
+
6
+ ;; Created: Fri Sep 18 09:04:49 JST 2009
7
+
8
+ ;; License: Ruby's
9
+
10
+ (require 'derived)
11
+ (define-derived-mode rdoc-mode text-mode "RDoc"
12
+ "Major mode for RD editing.
13
+ \\{rdoc-mode-map}"
14
+ (make-local-variable 'paragraph-separate)
15
+ (setq paragraph-separate "^\\(=+\\|\\*+\\)[ \t\v\f]*\\|^\\s *$")
16
+ (make-local-variable 'paragraph-start)
17
+ (setq paragraph-start paragraph-separate)
18
+ (make-local-variable 'require-final-newline)
19
+ (setq require-final-newline t)
20
+ (make-local-variable 'font-lock-defaults)
21
+ (setq font-lock-defaults '((rdoc-font-lock-keywords) t nil))
22
+ (make-local-variable 'font-lock-keywords)
23
+ (setq font-lock-keywords rdoc-font-lock-keywords)
24
+ (make-local-variable 'outline-regexp)
25
+ (setq outline-regexp "^\\(=+\\)[ \t\v\f]*")
26
+ (outline-minor-mode t)
27
+ (setq show-trailing-whitespace t)
28
+ (rdoc-setup-keys)
29
+ (setq indent-tabs-mode nil)
30
+ (run-hooks 'rdoc-mode-hook)
31
+ )
32
+
33
+ (defun rdoc-fill-paragraph (&rest args)
34
+ "Fills paragraph, except for cited region"
35
+ (interactive (progn
36
+ (barf-if-buffer-read-only)
37
+ (list (if current-prefix-arg 'full))))
38
+ (save-excursion
39
+ (beginning-of-line)
40
+ (unless (looking-at "^ +")
41
+ (apply 'fill-paragraph args))))
42
+
43
+ (defun rdoc-setup-keys ()
44
+ (interactive)
45
+ (define-key rdoc-mode-map "\M-q" 'rdoc-fill-paragraph)
46
+ )
47
+
48
+ (defvar rdoc-heading1-face 'font-lock-keywordoc-face)
49
+ (defvar rdoc-heading2-face 'font-lock-type-face)
50
+ (defvar rdoc-heading3-face 'font-lock-variable-name-face)
51
+ (defvar rdoc-heading4-face 'font-lock-comment-face)
52
+ (defvar rdoc-bold-face 'font-lock-function-name-face)
53
+ (defvar rdoc-emphasis-face 'font-lock-function-name-face)
54
+ (defvar rdoc-code-face 'font-lock-keyword-face)
55
+ (defvar rdoc-description-face 'font-lock-constant-face)
56
+
57
+ (defvar rdoc-font-lock-keywords
58
+ (list
59
+ (list "^=([^=\r\n].*)?$"
60
+ 0 rdoc-heading1-face)
61
+ (list "^==([^=\r\n].*)?$"
62
+ 0 rdoc-heading2-face)
63
+ (list "^===([^=\r\n].*)?$"
64
+ 0 rdoc-heading3-face)
65
+ (list "^====+.*$"
66
+ 0 rdoc-heading4-face)
67
+ (list "\\(^\\|[ \t\v\f]\\)\\(\\*\\(\\sw\\|[-_:]\\)+\\*\\)\\($\\|[ \t\v\f]\\)"
68
+ 2 rdoc-bold-face) ; *bold*
69
+ (list "\\(^\\|[ \t\v\f]\\)\\(_\\(\\sw\\|[-_:]\\)+_\\)\\($\\|[ \t\v\f]\\)"
70
+ 2 rdoc-emphasis-face) ; _emphasis_
71
+ (list "\\(^\\|[ \t\v\f]\\)\\(\\+\\(\\sw\\|[-_:]\\)+\\+\\)\\($\\|[ \t\v\f]\\)"
72
+ 2 rdoc-code-face) ; +code+
73
+ (list "<em>[^<>]*</em>" 0 rdoc-emphasis-face)
74
+ (list "<i>[^<>]*</i>" 0 rdoc-emphasis-face)
75
+ (list "<b>[^<>]*</b>" 0 rdoc-bold-face)
76
+ (list "<tt>[^<>]*</tt>" 0 rdoc-code-face)
77
+ (list "<code>[^<>]*</code>" 0 rdoc-code-face)
78
+ (list "^\\([-*]\\|[0-9]+\\.\\|[A-Za-z]\\.\\)\\s "
79
+ 1 rdoc-description-face) ; bullet | numbered | alphabetically numbered
80
+ (list "^\\[[^\]]*\\]\\|\\S .*::\\)\\([ \t\v\f]\\|$\\)"
81
+ 1 rdoc-description-face) ; labeled | node
82
+ ;(list "^[ \t\v\f]+\\(.*\\)" 1 rdoc-verbatim-face)
83
+ ))
84
+
85
+ (defun rdoc-imenu-create-index ()
86
+ (let ((root '(nil . nil))
87
+ cur-alist
88
+ (cur-level 0)
89
+ (pattern (concat outline-regexp "\\(.*?\\)[ \t\v\f]*$"))
90
+ (empty-heading "-")
91
+ (self-heading ".")
92
+ pos level heading alist)
93
+ (save-excursion
94
+ (goto-char (point-min))
95
+ (while (re-search-forward pattern (point-max) t)
96
+ (setq heading (match-string-no-properties 2)
97
+ level (min 6 (length (match-string-no-properties 1)))
98
+ pos (match-beginning 1))
99
+ (if (= (length heading) 0)
100
+ (setq heading empty-heading))
101
+ (setq alist (list (cons heading pos)))
102
+ (cond
103
+ ((= cur-level level) ; new sibling
104
+ (setcdr cur-alist alist)
105
+ (setq cur-alist alist))
106
+ ((< cur-level level) ; first child
107
+ (dotimes (i (- level cur-level 1))
108
+ (setq alist (list (cons empty-heading alist))))
109
+ (if cur-alist
110
+ (let* ((parent (car cur-alist))
111
+ (self-pos (cdr parent)))
112
+ (setcdr parent (cons (cons self-heading self-pos) alist)))
113
+ (setcdr root alist)) ; primogenitor
114
+ (setq cur-alist alist
115
+ cur-level level))
116
+ (t ; new sibling of an ancestor
117
+ (let ((sibling-alist (last (cdr root))))
118
+ (dotimes (i (1- level))
119
+ (setq sibling-alist (last (cdar sibling-alist))))
120
+ (setcdr sibling-alist alist)
121
+ (setq cur-alist alist
122
+ cur-level level))))))
123
+ (cdr root)))
124
+
125
+ (defun rdoc-set-imenu-create-index-function ()
126
+ (setq imenu-create-index-function 'rdoc-imenu-create-index))
127
+
128
+ (add-hook 'rdoc-mode-hook 'rdoc-set-imenu-create-index-function)
129
+
130
+ (provide 'rdoc-mode)