ruby_learner 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,264 @@
1
+ ;;; line-num.el --- Display line numbers in left-margin of buffer.
2
+ ;;
3
+ ;; Filename: line-num.el
4
+ ;; Description: Display line numbers in left-margin of buffer.
5
+ ;; Author: (Darryl Okahata) darrylo@hpsrdmo, Drew Adams
6
+ ;; Maintainer: Drew Adams (concat "drew.adams" "@" "oracle" ".com")
7
+ ;; Copyright (C) 1999-2015, Drew Adams, all rights reserved.
8
+ ;; Copyright (C) 1989, Hewlett-Packard, all rights reserved.
9
+ ;; Created: Wed Mar 31 16:18:24 1999
10
+ ;; Version: 0
11
+ ;; Package-Requires: ()
12
+ ;;; Last-Updated: Thu Jan 1 11:01:00 2015 (-0800)
13
+ ;; By: dradams
14
+ ;; Update #: 219
15
+ ;; URL: http://www.emacswiki.org/line-num.el
16
+ ;; Doc URL: http://emacswiki.org/LineNumbers
17
+ ;; Keywords: local
18
+ ;; Compatibility: GNU Emacs: 20.x, 21.x, 22.x, 23.x, 24.x, 25.x
19
+ ;;
20
+ ;; Features that might be required by this library:
21
+ ;;
22
+ ;; None
23
+ ;;
24
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25
+ ;;
26
+ ;;; Commentary:
27
+ ;;
28
+ ;; Display line numbers in left-margin of buffer.
29
+ ;;
30
+ ;; New functions defined here:
31
+ ;;
32
+ ;; `display-line-numbers', `toggle-line-numbers-display',
33
+ ;; `turn-on-line-numbers-display', `turn-off-line-numbers-display'.
34
+ ;;
35
+ ;; NOTE: `setnu.el' now provides similar, but generally better,
36
+ ;; functionality.
37
+ ;;
38
+ ;; Original author was Darryl Okahata darrylo@hpsrdmo: The copy on
39
+ ;; which the current (Adams) modifications were made was obtained from
40
+ ;; Rick Kunin (rickk@sperdk).
41
+ ;;
42
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43
+ ;;
44
+ ;;; Change Log:
45
+ ;;
46
+ ;; 2004/11/26 dadams
47
+ ;; Replaced decf with setq...1+.
48
+ ;; turn-off-line-numbers-display: Error if not displaying line #s.
49
+ ;; Removed calls to `fit-frame' (and require of fit-frame.el).
50
+ ;; 2000/11/01 dadams
51
+ ;; 1. Added: toggle-line-numbers-display, turn-on-line-numbers-display,
52
+ ;; turn-off-line-numbers-display.
53
+ ;; 2. Added global vars: displaying-line-numbers-p,
54
+ ;; display-line-numbers-format-string, display-line-numbers-first-line,
55
+ ;; display-line-numbers-count, display-line-numbers-buffer-name,
56
+ ;; display-line-numbers-modified-p.
57
+ ;; 1999/04/14 dadams
58
+ ;; Commented out assignment to unused free var: insert-end.
59
+ ;;
60
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
61
+ ;;
62
+ ;; This program is free software; you can redistribute it and/or modify
63
+ ;; it under the terms of the GNU General Public License as published by
64
+ ;; the Free Software Foundation; either version 2, or (at your option)
65
+ ;; any later version.
66
+
67
+ ;; This program is distributed in the hope that it will be useful,
68
+ ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
69
+ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70
+ ;; GNU General Public License for more details.
71
+
72
+ ;; You should have received a copy of the GNU General Public License
73
+ ;; along with this program; see the file COPYING. If not, write to
74
+ ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
75
+ ;; Floor, Boston, MA 02110-1301, USA.
76
+ ;;
77
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78
+ ;;
79
+ ;;; Code:
80
+
81
+ ;;>> Problem: Tabs at beginning of lines
82
+
83
+ ;;;;;;;;;;;;;
84
+
85
+
86
+ ;;;###autoload
87
+ (defun display-line-numbers ()
88
+ "Temporarily display line numbers in left margin of current buffer."
89
+ (interactive)
90
+ (or (eq (current-buffer) (window-buffer (selected-window)))
91
+ (error "Current buffer, %s, is not the selected window's buffer"
92
+ (buffer-name)))
93
+ (let ((buffer-read-only nil)
94
+ (modified (buffer-modified-p))
95
+ (name buffer-file-name)
96
+ (point (point-marker))
97
+ format-string
98
+ line-number
99
+ (count 0)
100
+ nlines
101
+ first-line)
102
+ (save-restriction
103
+ (widen)
104
+ (save-excursion
105
+ (setq first-line (window-start (selected-window)))
106
+ (goto-char first-line)
107
+ (setq line-number (1+ (count-lines (point-min) (point))))
108
+ (move-to-window-line -1)
109
+ (beginning-of-line)
110
+ (setq nlines (count-lines first-line (point)))
111
+ (let ((max (+ line-number nlines)))
112
+ (setq format-string (cond ((< max 100) "%2d ")
113
+ ((< max 1000) "%3d ")
114
+ ((< max 10000) "%4d ")
115
+ (t "%7d "))))))
116
+ (save-excursion
117
+ (unwind-protect
118
+ (progn
119
+ (goto-char first-line)
120
+ ;; defeat file locking... don't try this at home, kids!
121
+ (setq buffer-file-name nil)
122
+ (while (<= count nlines)
123
+ (insert-before-markers (format format-string line-number))
124
+ ;;;(setq insert-end (point)) THIS VAR IS FREE - AND UNUSED!
125
+ (setq line-number (1+ line-number))
126
+ (setq count (1+ count))
127
+ (forward-line 1))
128
+ (set-window-start (selected-window) first-line)
129
+ (goto-char point)
130
+ (set-buffer-modified-p modified)
131
+ (message "<<< Press SPACE to continue >>>")
132
+ (let ((char (read-char)))
133
+ (or (eql char ?\ )
134
+ (setq unread-command-events (list char))))
135
+ )
136
+ (goto-char first-line)
137
+ (let ((n (1+ (- (aref format-string 1) ?0))))
138
+ (while (> count 0)
139
+ (setq count (1- count))
140
+ (delete-char n)
141
+ (forward-line 1)))
142
+ (setq buffer-file-name name)
143
+ (set-buffer-modified-p modified)))))
144
+
145
+ ;;;-----------------------------------------------------------------
146
+
147
+ (defvar displaying-line-numbers-p nil)
148
+ (make-variable-buffer-local 'displaying-line-numbers-p)
149
+ (defvar display-line-numbers-format-string nil)
150
+ (make-variable-buffer-local 'display-line-numbers-format-string)
151
+ (defvar display-line-numbers-first-line nil)
152
+ (make-variable-buffer-local 'display-line-numbers-first-line)
153
+ (defvar display-line-numbers-count 0)
154
+ (make-variable-buffer-local 'display-line-numbers-count)
155
+ (defvar display-line-numbers-buffer-name nil)
156
+ (make-variable-buffer-local 'display-line-numbers-buffer-name)
157
+ (defvar display-line-numbers-modified-p nil)
158
+ (make-variable-buffer-local 'display-line-numbers-modified-p)
159
+
160
+ ;;;###autoload
161
+ (defun toggle-line-numbers-display (arg)
162
+ "Display/clear line numbers in left margin of current buffer.
163
+ With prefix ARG, just number lines in current window, not all lines in
164
+ buffer."
165
+ (interactive "P")
166
+ (if displaying-line-numbers-p
167
+ (turn-off-line-numbers-display)
168
+ (turn-on-line-numbers-display arg)))
169
+
170
+ ;;;###autoload
171
+ (defun turn-on-line-numbers-display (arg)
172
+ "Display line numbers in left margin of current buffer.
173
+ With prefix ARG, just number lines in current window, not all lines in
174
+ buffer."
175
+ (interactive "P")
176
+ (or (eq (current-buffer) (window-buffer (selected-window)))
177
+ (error "Current buffer, %s, is not the selected window's buffer"
178
+ (buffer-name)))
179
+ (let ((buffer-read-only nil)
180
+ (point (point-marker))
181
+ line-number
182
+ nlines)
183
+ (setq display-line-numbers-buffer-name buffer-file-name)
184
+ (setq display-line-numbers-modified-p (buffer-modified-p))
185
+ (save-restriction
186
+ (widen)
187
+ (save-excursion
188
+ (setq display-line-numbers-first-line
189
+ (if arg
190
+ (window-start (selected-window))
191
+ (point-min)))
192
+ (goto-char display-line-numbers-first-line)
193
+ (setq line-number (1+ (count-lines (point-min) (point))))
194
+ (if arg
195
+ (move-to-window-line -1)
196
+ (goto-char (point-max)))
197
+ (beginning-of-line)
198
+ (setq nlines (count-lines display-line-numbers-first-line (point)))
199
+ (let ((max (+ line-number nlines)))
200
+ (setq display-line-numbers-format-string (cond ((< max 100) "%2d ")
201
+ ((< max 1000) "%3d ")
202
+ ((< max 10000) "%4d ")
203
+ (t "%7d "))))))
204
+ (save-excursion
205
+ (condition-case nil
206
+ (progn
207
+ (goto-char display-line-numbers-first-line)
208
+ (setq buffer-file-name nil) ; To prevent saving with line numbers etc.
209
+ (setq displaying-line-numbers-p t)
210
+ (while (<= display-line-numbers-count nlines)
211
+ (insert-before-markers
212
+ (format display-line-numbers-format-string line-number))
213
+ (setq line-number (1+ line-number))
214
+ (setq display-line-numbers-count (1+ display-line-numbers-count))
215
+ (forward-line 1))
216
+ (when arg
217
+ (set-window-start (selected-window) display-line-numbers-first-line))
218
+ (goto-char point)
219
+ (set-buffer-modified-p display-line-numbers-modified-p))
220
+ (error
221
+ (progn
222
+ (goto-char display-line-numbers-first-line)
223
+ (let ((n (1+ (- (aref display-line-numbers-format-string 1) ?0))))
224
+ (while (> display-line-numbers-count 0)
225
+ (setq display-line-numbers-count (1- display-line-numbers-count))
226
+ (delete-char n)
227
+ (forward-line 1)))
228
+ (setq buffer-file-name display-line-numbers-buffer-name)
229
+ (set-buffer-modified-p display-line-numbers-modified-p)
230
+ (setq displaying-line-numbers-p nil))))))
231
+ (let ((curr-line (count-lines (window-start) (point))))
232
+ (when (> curr-line 0) (setq curr-line (1+ curr-line)))
233
+ (recenter curr-line)))
234
+
235
+ ;;;###autoload
236
+ (defun turn-off-line-numbers-display ()
237
+ "Clear displayed line numbers from left margin of current buffer."
238
+ (interactive)
239
+ (unless (eq (current-buffer) (window-buffer (selected-window)))
240
+ (error "Current buffer, `%s', is not the selected window's buffer"
241
+ (buffer-name)))
242
+ (unless displaying-line-numbers-p
243
+ (error "Not displaying line numbers in buffer `%s'" (buffer-name)))
244
+ (let ((buffer-read-only nil))
245
+ (save-excursion
246
+ (when (boundp 'display-line-numbers-buffer-name)
247
+ (setq buffer-file-name display-line-numbers-buffer-name))
248
+ (goto-char display-line-numbers-first-line)
249
+ (let ((n (1+ (- (aref display-line-numbers-format-string 1) ?0))))
250
+ (while (> display-line-numbers-count 0)
251
+ (setq display-line-numbers-count (1- display-line-numbers-count))
252
+ (delete-char n)
253
+ (forward-line 1)))
254
+ (when (boundp 'display-line-numbers-modified-p)
255
+ (set-buffer-modified-p display-line-numbers-modified-p))
256
+ (setq displaying-line-numbers-p nil))))
257
+
258
+
259
+ ;;;;;;;;;;;;;;;;;;;;;;;
260
+
261
+ (provide 'line-num)
262
+
263
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
264
+ ;;; line-num.el ends here
@@ -0,0 +1,366 @@
1
+ ;;; install-elisp.el --- Simple Emacs Lisp installer
2
+ ;; $Id: install-elisp.el,v 1.18 2009/01/25 17:47:20 rubikitch Exp $
3
+
4
+ ;; Copyright (C) 2007 rubikitch
5
+
6
+ ;; Author: rubikitch <rubikitch@ruby-lang.org>
7
+ ;; Keywords: lisp, convenience, maint
8
+ ;; URL: http://www.emacswiki.org/cgi-bin/wiki/download/install-elisp.el
9
+
10
+ ;; This file is free software; you can redistribute it and/or modify
11
+ ;; it under the terms of the GNU General Public License as published by
12
+ ;; the Free Software Foundation; either version 2, or (at your option)
13
+ ;; any later version.
14
+
15
+ ;; This file is distributed in the hope that it will be useful,
16
+ ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ ;; GNU General Public License for more details.
19
+
20
+ ;; You should have received a copy of the GNU General Public License
21
+ ;; along with GNU Emacs; see the file COPYING. If not, write to
22
+ ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23
+ ;; Boston, MA 02110-1301, USA.
24
+
25
+ ;;; Commentary:
26
+
27
+ ;; Automate Emacs Lisp installation.
28
+ ;; (1) download Emacs Lisp
29
+ ;; (!) confirm installation
30
+ ;; (2) save to your repository
31
+ ;; (3) byte compile
32
+ ;; (4) load
33
+ ;; (5) show Emacs Lisp
34
+
35
+ ;;; Commands:
36
+ ;;
37
+ ;; Below are complete command list:
38
+ ;;
39
+ ;; `install-elisp'
40
+ ;; Retrieve Emacs Lisp program from URL and save and byte-compile and load.
41
+ ;; `install-elisp-from-emacswiki'
42
+ ;; Install Emacs Lisp program from the EmacsWiki.
43
+ ;; `install-elisp-from-gist'
44
+ ;; Install Emacs Lisp program from gist.
45
+ ;; `dired-install-elisp-from-emacswiki'
46
+ ;; Upgrade the current Emacs Lisp program from the EmacsWiki.
47
+ ;; `install-elisp-confirmation-minor-mode'
48
+ ;; Emacs Lisp install confirmation.
49
+ ;;
50
+ ;;; Customizable Options:
51
+ ;;
52
+ ;; Below are customizable option list:
53
+ ;;
54
+ ;; `install-elisp-repository-directory'
55
+ ;; Directory to save Emacs Lisp programs downloaded by install-elisp.el.
56
+ ;; default = "~/.emacs.d/"
57
+ ;; `install-elisp-use-view-mode'
58
+ ;; If non-nil, turn on `view-mode' for installed Emacs Lisp program.
59
+ ;; default = t
60
+ ;; `install-elisp-use-url-retrieve'
61
+ ;; If nil, use external command-line HTTP client instead.
62
+ ;; default = (fboundp (quote url-retrieve-synchronously))
63
+ ;; `install-elisp-confirm-flag'
64
+ ;; If non-nil, do install confirmation.
65
+ ;; default = t
66
+ ;; `install-elisp-retrieval-program'
67
+ ;; URL retrieving program used when `install-elisp-use-url-retrieve' is nil.
68
+ ;; default = "wget -q -O- '%s'"
69
+
70
+ ;;; Installation:
71
+
72
+ ;; If you use Emacs21 and under, you must have wget or other
73
+ ;; command-line HTTP client.
74
+
75
+ ;; You need to add to .emacs:
76
+ ;; (require 'install-elisp)
77
+ ;; (setq install-elisp-repository-directory "~/.emacs.d/")
78
+
79
+ ;;; Usage:
80
+
81
+ ;; M-x install-elisp
82
+ ;; M-x install-elisp-from-emacswiki
83
+ ;; M-x install-elisp-from-gist
84
+ ;; M-x dired-install-elisp-from-emacswiki
85
+ ;;
86
+ ;; It is convenient to add to your Emacs Lisp programs:
87
+ ;; (install-elisp "http://your.site/hogehoge.el")
88
+ ;; because users have only to evaluate this sexp by C-x C-e.
89
+
90
+ ;; If you want to complete EmacsWiki pagename, eval:
91
+ ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/oddmuse.el")
92
+ ;; It is very convenient to access EmacsWiki with oddmuse.el.
93
+
94
+ ;;; Upgrade this program:
95
+
96
+ ;; Simply eval:
97
+ ;; (install-elisp-from-emacswiki "install-elisp.el")
98
+
99
+ ;;; Related project:
100
+
101
+ ;; Emacs Lisp Package Archive: http://tromey.com/elpa/
102
+ ;; auto-install.el is successor of this:
103
+ ;; http://www.emacswiki.org/cgi-bin/wiki/download/auto-install.el
104
+
105
+ ;;; Bug Report:
106
+ ;;
107
+ ;; If you have problem, send a bug report via M-x install-elisp-send-bug-report.
108
+ ;; The step is:
109
+ ;; 0) Setup mail in Emacs, the easiest way is:
110
+ ;; (setq user-mail-address "your@mail.address")
111
+ ;; (setq user-full-name "Your Full Name")
112
+ ;; (setq smtpmail-smtp-server "your.smtp.server.jp")
113
+ ;; (setq mail-user-agent 'message-user-agent)
114
+ ;; (setq message-send-mail-function 'message-smtpmail-send-it)
115
+ ;; 1) Be sure to use the LATEST version of install-elisp.el.
116
+ ;; 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
117
+ ;; 3) Use Lisp version instead of compiled one: (load "install-elisp.el")
118
+ ;; 4) Do it!
119
+ ;; 5) If you got an error, please do not close *Backtrace* buffer.
120
+ ;; 6) M-x install-elisp-send-bug-report and M-x insert-buffer *Backtrace*
121
+ ;; 7) Describe the bug using a precise recipe.
122
+ ;; 8) Type C-c C-c to send.
123
+ ;; # If you are a Japanese, please write in Japanese:-)
124
+
125
+ ;;; History:
126
+
127
+ ;; $Log: install-elisp.el,v $
128
+ ;; Revision 1.18 2009/01/25 17:47:20 rubikitch
129
+ ;; New command: `install-elisp-from-gist'
130
+ ;;
131
+ ;; Revision 1.17 2009/01/24 18:54:54 rubikitch
132
+ ;; Fixed unbound `find-function-source-path'.
133
+ ;;
134
+ ;; Revision 1.16 2009/01/21 10:19:57 rubikitch
135
+ ;; Restore `mode-line-format' when installation is done.
136
+ ;;
137
+ ;; Revision 1.15 2008/12/27 10:56:25 rubikitch
138
+ ;; Use font-lock.
139
+ ;;
140
+ ;; Revision 1.14 2008/12/27 10:45:11 rubikitch
141
+ ;; Make install-elisp find the package's directory,
142
+ ;; if found use package's directory, otherwise use `install-elisp-repository-directory'.
143
+ ;; patched by Andy Stewart (with slightly modified), thanks.
144
+ ;;
145
+ ;; Revision 1.13 2008/12/27 09:14:42 rubikitch
146
+ ;; "Get elisp from..." message
147
+ ;;
148
+ ;; Revision 1.12 2007/07/25 20:38:08 rubikitch
149
+ ;; use defgroup.
150
+ ;; install-elisp-retrieval-program: "wget -q -O- '%s'" by default.
151
+ ;;
152
+ ;; Revision 1.11 2007/07/25 19:43:22 rubikitch
153
+ ;; New variable: install-elisp-retrieval-program
154
+ ;;
155
+ ;; use `defcustom'.
156
+ ;;
157
+ ;; Revision 1.10 2007/07/25 19:27:43 rubikitch
158
+ ;; update Commentary and Usage
159
+ ;;
160
+ ;; Revision 1.9 2007/07/25 19:20:08 rubikitch
161
+ ;; install-elisp-confirmation-minor-mode: pretty mode-line-format
162
+ ;;
163
+ ;; Revision 1.8 2007/07/25 19:11:50 rubikitch
164
+ ;; EmacsWiki HTTP workaround
165
+ ;;
166
+ ;; Revision 1.7 2007/07/25 19:02:57 rubikitch
167
+ ;; Install confirmation for security.
168
+ ;;
169
+ ;; Revision 1.6 2007/07/25 17:58:39 rubikitch
170
+ ;; New command: dired-install-elisp-from-emacswiki
171
+ ;;
172
+ ;; Revision 1.5 2007/07/25 17:50:30 rubikitch
173
+ ;; `install-elisp-repository-directory': "~/.emacs.d/" by default.
174
+ ;;
175
+ ;; Revision 1.4 2007/07/25 17:47:21 rubikitch
176
+ ;; rename function: %install-elisp-from -> install-elisp-from
177
+ ;;
178
+ ;; Revision 1.3 2007/07/25 17:46:13 rubikitch
179
+ ;; use `url-retrieve-synchronously' if available
180
+ ;;
181
+ ;; Revision 1.2 2007/07/24 10:44:31 rubikitch
182
+ ;; Fixed a serious bug.
183
+ ;; New variable: install-elisp-use-view-mode
184
+ ;;
185
+ ;; Revision 1.1 2007/07/24 10:39:40 rubikitch
186
+ ;; Initial revision
187
+ ;;
188
+
189
+ ;;; Code:
190
+
191
+ (require 'find-func)
192
+
193
+ (defgroup install-elisp nil
194
+ "Simple Emacs Lisp installer."
195
+ :group 'hypermedia)
196
+
197
+ (defcustom install-elisp-repository-directory "~/.emacs.d/"
198
+ "Directory to save Emacs Lisp programs downloaded by install-elisp.el. "
199
+ :group 'install-elisp)
200
+
201
+ (defcustom install-elisp-use-view-mode t
202
+ "If non-nil, turn on `view-mode' for installed Emacs Lisp program."
203
+ :group 'install-elisp)
204
+
205
+ (defcustom install-elisp-use-url-retrieve (fboundp 'url-retrieve-synchronously)
206
+ "If nil, use external command-line HTTP client instead.
207
+ See also `install-elisp-retrieval-program'."
208
+ :group 'install-elisp)
209
+
210
+ (defcustom install-elisp-confirm-flag t
211
+ "If non-nil, do install confirmation.
212
+ You should set it non-nil for security reason."
213
+ :group 'install-elisp)
214
+
215
+ (defcustom install-elisp-retrieval-program "wget -q -O- '%s'"
216
+ "URL retrieving program used when `install-elisp-use-url-retrieve' is nil.
217
+ If you use curl, set it to \"curl --silent '%s'\"."
218
+ :group 'install-elisp)
219
+
220
+ (defvar install-elisp-filename nil)
221
+ (make-variable-buffer-local 'install-elisp-filename)
222
+
223
+ (defvar install-elisp-confirmation-minor-mode-map (make-sparse-keymap))
224
+
225
+ (defun %install-elisp-create-buffer (url)
226
+ (message "Get elisp from %s" url)
227
+ (cond (install-elisp-use-url-retrieve
228
+ (switch-to-buffer (url-retrieve-synchronously url))
229
+ (goto-char (point-min))
230
+ (re-search-forward "^$" nil 'move)
231
+ (delete-region (point-min) (1+ (point)))
232
+ (%install-elisp-emacswiki-http-workaround))
233
+ (t
234
+ (let ((buffer (generate-new-buffer " *install-elisp-tmp*")))
235
+ (shell-command (format install-elisp-retrieval-program url) buffer)
236
+ (switch-to-buffer buffer))))
237
+ (emacs-lisp-mode)
238
+ (setq font-lock-mode t)
239
+ (font-lock-fontify-buffer))
240
+
241
+ ;; I do not know why!!
242
+ (defun %install-elisp-emacswiki-http-workaround ()
243
+ (save-excursion
244
+ (let (buffer-read-only)
245
+ (goto-char (1- (point-max)))
246
+ (when (eq (char-before) ?\C-m)
247
+ (delete-backward-char 2)))))
248
+
249
+ (defun install-elisp-proceed ()
250
+ (interactive)
251
+ (write-file install-elisp-filename)
252
+ (byte-compile-file buffer-file-name t)
253
+ (install-elisp-confirmation-minor-mode -1))
254
+
255
+ ;;;###autoload
256
+ (defun install-elisp (url &optional filename)
257
+ "Retrieve Emacs Lisp program from URL and save and byte-compile and load.
258
+ If optional FILENAME is supplied, save URL as FILENAME, otherwise URL's basename."
259
+ (interactive "sInstall Emacs Lisp from URL: ")
260
+ (if (null install-elisp-repository-directory)
261
+ (with-output-to-temp-buffer "*Help*"
262
+ (princ "You must prepare to use install-elisp program!
263
+ Set `install-elisp-repository-directory' to your local Emacs Lisp repository directory in your ~/.emacs.
264
+
265
+ For example: (setq install-elisp-repository-directory \"~/emacs/lisp/\")"))
266
+ (%install-elisp-create-buffer url)
267
+ (and install-elisp-use-view-mode (view-mode 1))
268
+ (setq install-elisp-filename
269
+ (%install-elisp-get-filename (or filename (file-name-nondirectory url))))
270
+ (if (not install-elisp-confirm-flag)
271
+ (install-elisp-proceed)
272
+ (install-elisp-confirmation-minor-mode 1)
273
+ (message "Type C-c C-c to do installation!"))))
274
+
275
+ ;; (%install-elisp-find-library-name "vc.el")
276
+ ;; (%install-elisp-find-library-name "vc.elc")
277
+ (defun %install-elisp-find-library-name (library)
278
+ "Return the absolute file name of the Lisp source of LIBRARY."
279
+ ;; If the library is byte-compiled, try to find a source library by
280
+ ;; the same name.
281
+ (if (string-match "\\.el\\(c\\(\\..*\\)?\\)\\'" library)
282
+ (setq library (replace-match "" t t library)))
283
+ (locate-file library
284
+ (or find-function-source-path load-path)
285
+ (append (find-library-suffixes) load-file-rep-suffixes)))
286
+
287
+ ;; (%install-elisp-get-filename "vc.el")
288
+ ;; (%install-elisp-get-filename "vc.elc")
289
+ ;; (%install-elisp-get-filename "icicles.el")
290
+ ;; (%install-elisp-get-filename "hoge.el")
291
+ (defun %install-elisp-get-filename (filename)
292
+ (let ((lib-file (%install-elisp-find-library-name filename)))
293
+ (if (and lib-file (file-writable-p lib-file))
294
+ ;; use current directory,
295
+ ;; if file is not in `install-elisp-repository-directory'.
296
+ lib-file
297
+ ;; otherwise use `install-elisp-repository-directory'.
298
+ (expand-file-name filename install-elisp-repository-directory))))
299
+
300
+ (defun install-elisp-from (baseurl)
301
+ "Return higher-order function installing from BASEURL, which accepts an argument FILENAME."
302
+ `(lambda (filename)
303
+ (install-elisp (concat ,baseurl filename) filename)))
304
+
305
+ ;;;###autoload
306
+ (defun install-elisp-from-emacswiki (filename)
307
+ "Install Emacs Lisp program from the EmacsWiki."
308
+ (interactive (list (if (fboundp 'oddmuse-read-pagename)
309
+ (oddmuse-read-pagename "EmacsWiki")
310
+ (read-string "PageName: "))))
311
+ (funcall (install-elisp-from "http://www.emacswiki.org/cgi-bin/wiki/download/") filename))
312
+
313
+ ;;;###autoload
314
+ (defun install-elisp-from-gist (gistid &optional filename)
315
+ "Install Emacs Lisp program from gist."
316
+ (interactive "sInstall Emacs Lisp from gist ID: ")
317
+ (install-elisp (concat "http://gist.github.com/" (format "%s" gistid) ".txt")
318
+ (or filename
319
+ (format "gist-%s.el" gistid))))
320
+
321
+ ;;;###autoload
322
+ (defun dired-install-elisp-from-emacswiki (&optional filename)
323
+ "Upgrade the current Emacs Lisp program from the EmacsWiki."
324
+ (interactive (list (dired-get-filename t)))
325
+ (install-elisp-from-emacswiki filename))
326
+
327
+ (define-key install-elisp-confirmation-minor-mode-map "\C-c\C-c" 'install-elisp-proceed)
328
+
329
+ (define-minor-mode install-elisp-confirmation-minor-mode
330
+ "Emacs Lisp install confirmation."
331
+ nil "" install-elisp-confirmation-minor-mode-map
332
+ (if install-elisp-confirmation-minor-mode
333
+ (setq mode-line-format
334
+ (format "%s: Type C-c C-c to install!"
335
+ (file-name-nondirectory install-elisp-filename)))
336
+ (setq mode-line-format default-mode-line-format)))
337
+
338
+ ;;;; Bug report
339
+ (defvar install-elisp-maintainer-mail-address
340
+ (concat "rubiki" "tch@ru" "by-lang.org"))
341
+ (defvar install-elisp-bug-report-salutation
342
+ "Describe bug below, using a precise recipe.
343
+
344
+ When I executed M-x ...
345
+
346
+ How to send a bug report:
347
+ 1) Be sure to use the LATEST version of install-elisp.el.
348
+ 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
349
+ 3) Use Lisp version instead of compiled one: (load \"install-elisp.el\")
350
+ 4) If you got an error, please paste *Backtrace* buffer.
351
+ 5) Type C-c C-c to send.
352
+ # If you are a Japanese, please write in Japanese:-)")
353
+ (defun install-elisp-send-bug-report ()
354
+ (interactive)
355
+ (reporter-submit-bug-report
356
+ install-elisp-maintainer-mail-address
357
+ "install-elisp.el"
358
+ (apropos-internal "^install-elisp-" 'boundp)
359
+ nil nil
360
+ install-elisp-bug-report-salutation))
361
+
362
+ (provide 'install-elisp)
363
+
364
+ ;; How to save (DO NOT REMOVE!!)
365
+ ;; (emacswiki-post "install-elisp.el")
366
+ ;;; install-elisp.el ends here