Skip to content
This repository
Browse code

Lib dir: moved classes into 'xiki' dir.

  • Loading branch information...
commit 06ea614d31557686a62de56e7604b86418d87c6a 1 parent 642d6df
trogdoro authored August 01, 2012

Showing 95 changed files with 862 additions and 163 deletions. Show diff stats Hide diff stats

  1. 17  bin/xiki
  2. 10  etc/command/xiki_command.rb
  3. 10  etc/command/xiki_process.rb
  4. 5  etc/www/web_server.rb
  5. 4  etc/xiki.org/xiki_bootstrap_source.notes
  6. 2  lib/menu.rb
  7. 40  lib/xiki.rb
  8. 0  lib/{ → xiki}/block.rb
  9. 4  lib/{ → xiki}/bookmarks.rb
  10. 0  lib/{ → xiki}/buffers.rb
  11. 4  lib/{ → xiki}/clipboard.rb
  12. 2  lib/{ → xiki}/code.rb
  13. 4  lib/{ → xiki}/code_tree.rb
  14. 4  lib/{ → xiki}/color.rb
  15. 0  lib/{ → xiki}/console.rb
  16. 0  lib/{ → xiki}/control_lock.rb
  17. 0  lib/{ → xiki}/control_tab.rb
  18. 2  lib/{ → xiki}/core_ext.rb
  19. 0  lib/{ → xiki}/cursor.rb
  20. 0  lib/{ → xiki}/deletes.rb
  21. 2  lib/{ → xiki}/diff_log.rb
  22. 2  lib/{ → xiki}/effects.rb
  23. 0  lib/{ → xiki}/environment.rb
  24. 8  lib/{ → xiki}/file_tree.rb
  25. 0  lib/{ → xiki}/files.rb
  26. 0  lib/{ → xiki}/hide.rb
  27. 0  lib/{ → xiki}/history.rb
  28. 0  lib/{ → xiki}/image.rb
  29. 0  lib/{ → xiki}/incrementer.rb
  30. 0  lib/{ → xiki}/insert.rb
  31. 0  lib/{ → xiki}/irc.rb
  32. 0  lib/{ → xiki}/key_bindings.rb
  33. 10  lib/{ → xiki}/keys.rb
  34. 10  lib/{ → xiki}/launcher.rb
  35. 0  lib/{ → xiki}/line.rb
  36. 0  lib/{ → xiki}/links.rb
  37. 0  lib/{ → xiki}/location.rb
  38. 0  lib/{ → xiki}/macros.rb
  39. 0  lib/{ → xiki}/man.rb
  40. 709  lib/xiki/menu.rb
  41. 2  lib/{ → xiki}/merb.rb
  42. 0  lib/{ → xiki}/message.rb
  43. 0  lib/{ → xiki}/meths.rb
  44. 0  lib/{ → xiki}/mode.rb
  45. 2  lib/{ → xiki}/move.rb
  46. 45  lib/{ → xiki}/notes.rb
  47. 0  lib/{ → xiki}/numbers.rb
  48. 0  lib/{ → xiki}/ol.rb
  49. 0  lib/{ → xiki}/ol_helper.rb
  50. 0  lib/{ → xiki}/overlay.rb
  51. 2  lib/{ → xiki}/pause_means_space.rb
  52. 0  lib/{ → xiki}/php.rb
  53. 0  lib/{ → xiki}/projects.rb
  54. 0  lib/{ → xiki}/relinquish_exception.rb
  55. 2  lib/{ → xiki}/remote.rb
  56. 2  lib/{ → xiki}/requirer.rb
  57. 0  lib/{ → xiki}/rest_tree.rb
  58. 0  lib/{ → xiki}/ruby.rb
  59. 0  lib/{ → xiki}/ruby_console.rb
  60. 10  lib/{ → xiki}/search.rb
  61. 0  lib/{ → xiki}/search_term.rb
  62. 0  lib/{ → xiki}/snippet.rb
  63. 0  lib/{ → xiki}/specs.rb
  64. 0  lib/{ → xiki}/styles.rb
  65. 0  lib/{ → xiki}/svn.rb
  66. 4  lib/{ → xiki}/text_util.rb
  67. 2  lib/{ → xiki}/tree.rb
  68. 0  lib/{ → xiki}/tree_cursor.rb
  69. 0  lib/{ → xiki}/trouble_shooting.rb
  70. 0  lib/{ → xiki}/url_tree.rb
  71. 0  lib/{ → xiki}/view.rb
  72. 0  lib/{ → xiki}/window.rb
  73. 6  menus/agenda.rb
  74. 4  menus/amazon.rb
  75. 4  menus/cassandra_db.rb
  76. 2  menus/deck.rb
  77. 8  menus/dir.rb
  78. 6  menus/headings.rb
  79. 5  menus/mac.rb
  80. 4  menus/maps.rb
  81. 2  menus/piano.rb
  82. 2  menus/rails.rb
  83. 2  menus/redmine.rb
  84. 2  spec/code_tree_spec.rb
  85. 8  spec/diff_log_spec.rb
  86. 4  spec/file_tree_spec.rb
  87. 4  spec/line_spec.rb
  88. 10  spec/menu_spec.rb
  89. 6  spec/ol_spec.rb
  90. 4  spec/remote_spec.rb
  91. 4  spec/search_spec.rb
  92. 2  spec/text_util_spec.rb
  93. 6  spec/tree_cursor_spec.rb
  94. 6  spec/tree_spec.rb
  95. 4  xiki.gemspec
17  bin/xiki
@@ -16,31 +16,18 @@
16 16
 require 'rubygems'
17 17
 
18 18
 # Generate with correct path (see below)
19  
-# xiki_dir = "/projects/xiki/"
20 19
 xiki_dir = File.expand_path "#{File.dirname(__FILE__)}/.."
21  
-# p "xiki_dir: #{xiki_dir.inspect}"
22 20
 
23  
-# $:.unshift xiki_dir #.sub(/\/$/, '')
24 21
 $:.unshift "#{xiki_dir}/lib" #.sub(/\/$/, '')
25 22
 
26  
-# require "#{xiki_dir}/ol"
27  
-require "ol"
28  
-# Ol.line
29  
-require "core_ext"
  23
+require "xiki/ol"
  24
+require "xiki/core_ext"
30 25
 
31 26
 $:.unshift "#{xiki_dir}/etc/command"
32  
-# $:.unshift "#{xiki_dir}etc/command/stubs"
33 27
 
34 28
 require "xiki_command.rb"
35  
-# load "xiki_command.rb"
36 29
 
37 30
 result = XikiCommand.run
38 31
 puts result if result != ""
39 32
 
40 33
 exit 0
41  
-
42  
-# TODO: Start with template, and when installing, change:
43  
-  # - #!.. line to: result of: `which ruby`
44  
-  # - xiki_dir to: Xiki.dir
45  
-
46  
-
10  etc/command/xiki_command.rb
@@ -19,7 +19,7 @@ def self.pop_initial_request
19 19
   # Called by the 'xiki' shell command
20 20
   def self.run
21 21
 
22  
-    xiki_root = File.expand_path "#{File.dirname(__FILE__)}/../.."
  22
+    xiki_dir = File.expand_path "#{File.dirname(__FILE__)}/../.."
23 23
     argv = ARGV
24 24
 
25 25
     if argv.empty?
@@ -83,7 +83,7 @@ def self.run
83 83
         pid_orig = Process.pid
84 84
 
85 85
         @@initial_request = path
86  
-        xiki_process = "#{xiki_root}/etc/command/xiki_process.rb"
  86
+        xiki_process = "#{xiki_dir}/etc/command/xiki_process.rb"
87 87
         Daemons.run xiki_process, :ARGV=>['start'], :monitor=>false, :multiple=>false, :dir_mode=>:normal, :dir=>"/tmp/", :log_dir=>"/tmp/", :log_output=>true
88 88
 
89 89
         # Aparently this line never gets reached
@@ -94,7 +94,7 @@ def self.run
94 94
         process_succeeded = true
95 95
 
96 96
       rescue Exception=>e
97  
-        puts "- service couldn't start!"
  97
+        puts "- service couldn't start!:#{e.message}\n#{e.backtrace.join("\n")}\n\n"
98 98
       end
99 99
     end
100 100
 
@@ -169,8 +169,8 @@ def self.usage
169 169
 
170 170
   def self.ctrl action
171 171
     require 'daemons'
172  
-    xiki_root = File.expand_path "#{File.dirname(__FILE__)}/../.."
173  
-    xiki_process = "#{xiki_root}/etc/command/xiki_process.rb"
  172
+    xiki_dir = File.expand_path "#{File.dirname(__FILE__)}/../.."
  173
+    xiki_process = "#{xiki_dir}/etc/command/xiki_process.rb"
174 174
     Daemons.run xiki_process, :ARGV=>[action], :dir_mode=>:normal, :dir=>"/tmp/", :log_dir=>"/tmp/", :log_output=>true
175 175
     ""
176 176
   end
10  etc/command/xiki_process.rb
... ...
@@ -1,10 +1,6 @@
1  
-# Don't hard-code, generate with script? - or use __file path xiki env var!
2  
-require '/projects/xiki/lib/ol'
3  
-require 'core_ext'
4  
-
5  
-require 'menu'
6  
-
7  
-require 'launcher'
  1
+require 'xiki/core_ext'
  2
+require 'xiki/menu'
  3
+require 'xiki/launcher'
8 4
 
9 5
 Xiki.init
10 6
 
5  etc/www/web_server.rb
@@ -13,7 +13,7 @@ def self.htmlify txt, options={}
13 13
       xiki_dir = File.expand_path "#{File.dirname(__FILE__)}/../.."
14 14
 
15 15
       $:.unshift "#{xiki_dir}/lib"
16  
-      ["lib/core_ext", "lib/line", "lib/tree", "menus/bootstrap"].each{|o| require "#{xiki_dir}/#{o}"}
  16
+      ["xiki/ol", "xiki/core_ext", "xiki/line", "xiki/tree", "../../menus/bootstrap"].each{|o| require o}
17 17
 
18 18
       txt.slice! /.+\n/
19 19
       txt = txt.unindent
@@ -243,7 +243,6 @@ def self.usage
243 243
   end
244 244
 
245 245
   def self.index
246  
-
247 246
     no_keys = false
248 247
 
249 248
     if ENV['REQUEST_METHOD'] == "POST"
@@ -339,8 +338,6 @@ def self.menu *args
339 338
     txt = self.htmlify txt, :no_keys=>no_keys
340 339
     print txt
341 340
 
342  
-    # print "<pre>#{ENV.keys.map{|k| "#{k}: #{ENV[k]}"}.join("\n")}</pre>"
343  
-
344 341
   rescue Exception=>e
345 342
     puts "<pre>#{e.message}\n#{e.backtrace}</pre>"
346 343
   end
4  etc/xiki.org/xiki_bootstrap_source.notes
@@ -77,9 +77,7 @@ bootstrap/
77 77
           - p/
78 78
             Go to
79 79
             <a href="http://github.com/trogdoro/xiki">github.com/trogdoro/xiki</a>
80  
-            to check out the code and
81  
-            <a href="http://github.com/trogdoro/xiki/tree/master/INSTALL.txt">install</a>
82  
-            Xiki.
  80
+            to check out the code and install Xiki.
83 81
         - span4/
84 82
           - h1/
85 83
             - icon/043_group
2  lib/menu.rb
@@ -342,7 +342,7 @@ def self.[] path
342 342
   end
343 343
 
344 344
   def self.call root, rest=nil
345  
-    root = root.gsub /[ +]/, '_'
  345
+    root = root.gsub /[- +]/, '_'
346 346
     menus = Launcher.menus
347 347
     block = menus[0][root] || menus[1][root]
348 348
     return if block.nil?
40  lib/xiki.rb
... ...
@@ -1,11 +1,11 @@
1  
-XIKI_ROOT = File.expand_path "#{File.dirname(__FILE__)}/.."
2  
-Dir.chdir(XIKI_ROOT)
  1
+xiki_dir = File.expand_path "#{File.dirname(__FILE__)}/.."
  2
+Dir.chdir xiki_dir
3 3
 
4 4
 # Used by a lot of classes
5 5
 class Xiki
6 6
   @@dir = "#{Dir.pwd}/"   # Store current dir when xiki first launches
7 7
 
8  
-  # TODO Just use XIKI_ROOT from above?
  8
+  # TODO Just use XIKI_DIR from above?
9 9
 
10 10
   def self.dir
11 11
     @@dir
@@ -15,16 +15,18 @@ def self.dir
15 15
 
16 16
 $el.el4r_lisp_eval '(ignore-errors (kill-buffer "Issues Loading Xiki"))' if $el
17 17
 
  18
+# $LOAD_PATH << "#{xiki_dir}/lib"
  19
+
18 20
 # Require some of the core files
19  
-require 'trouble_shooting'
20 21
 require 'rubygems'
21  
-require 'ol'
22  
-require 'requirer'
23  
-require 'text_util'
24  
-Requirer.require_classes ['notes']
25  
-require 'launcher'
26  
-require 'mode'
27  
-require 'menu'
  22
+require 'xiki/trouble_shooting'
  23
+require 'xiki/ol'
  24
+require 'xiki/requirer'
  25
+require 'xiki/text_util'
  26
+Requirer.require_classes ['xiki/notes']
  27
+require 'xiki/launcher'
  28
+require 'xiki/mode'
  29
+require 'xiki/menu'
28 30
 
29 31
 # Launcher.add_class_launchers classes
30 32
 class Xiki
@@ -73,6 +75,7 @@ def self.menu
73 75
         - start/
74 76
         - stop/
75 77
         - restart/
  78
+        - log/
76 79
     - api/
77 80
       > Summary
78 81
       Here are some functions that will always be available to menu classes,
@@ -343,11 +346,10 @@ def self.on_open
343 346
   def self.init
344 347
     # Get rest of files to require
345 348
 
346  
-    classes = Dir["lib/*.rb"]
347  
-Ol << "classes: #{classes.inspect}"
  349
+    classes = Dir["lib/xiki/*.rb"]
348 350
     classes = classes.select{|i|
349  
-      i !~ /xiki.rb$/ &&   # Remove self
350  
-      i !~ /key_bindings.rb$/ &&   # Remove key_bindings
  351
+      i !~ /\/xiki.rb$/ &&   # Remove self
  352
+      i !~ /\/key_bindings.rb$/ &&   # Remove key_bindings
351 353
       i !~ /__/   # Remove __....rb files
352 354
     }
353 355
 
@@ -362,15 +364,13 @@ def self.init
362 364
 
363 365
     classes.map!{|i| i.sub(/\.rb$/, '')}.sort!
364 366
 
365  
-Ol << "classes: #{classes.inspect}"
366  
-
367 367
     # Require classes
368 368
     Requirer.require_classes classes
369 369
 
370 370
     # key_bindings has many dependencies, require it last
371  
-    Requirer.require_classes ['lib/key_bindings.rb']
  371
+    Requirer.require_classes ['lib/xiki/key_bindings.rb']
372 372
 
373  
-    Launcher.add_class_launchers classes.map{|o| o[/\/(.+)/, 1]}
  373
+    Launcher.add_class_launchers classes.map{|o| o[/.*\/(.+)/, 1]}
374 374
     Launcher.reload_menu_dirs
375 375
 
376 376
     Launcher.add "xiki"
@@ -395,6 +395,8 @@ def self.process action
395 395
       response = `xiki restart`
396 396
       response = "apparently it wasn't running" if response.blank?
397 397
       response.gsub /^/, '- '
  398
+    when "log"
  399
+      "@/tmp/xiki_process.rb.output"
398 400
     when "start"
399 401
       result = `xiki`
400 402
       "- started!"
0  lib/block.rb → lib/xiki/block.rb
File renamed without changes
4  lib/bookmarks.rb → lib/xiki/bookmarks.rb
... ...
@@ -1,5 +1,5 @@
1  
-require 'location'
2  
-require 'keys'
  1
+require 'xiki/location'
  2
+require 'xiki/keys'
3 3
 require 'yaml'
4 4
 
5 5
 class Bookmarks
0  lib/buffers.rb → lib/xiki/buffers.rb
File renamed without changes
4  lib/clipboard.rb → lib/xiki/clipboard.rb
... ...
@@ -1,5 +1,5 @@
1  
-require 'keys'
2  
-require 'file_tree'
  1
+require 'xiki/keys'
  2
+require 'xiki/file_tree'
3 3
 
4 4
 # Provides copy and paste functionality
5 5
 class Clipboard
2  lib/code.rb → lib/xiki/code.rb
... ...
@@ -1,4 +1,4 @@
1  
-require 'block'
  1
+require 'xiki/block'
2 2
 require 'stringio'
3 3
 gem 'ruby2ruby'
4 4
 require 'ruby2ruby'
4  lib/code_tree.rb → lib/xiki/code_tree.rb
... ...
@@ -1,5 +1,5 @@
1  
-require 'line'
2  
-require 'ol'
  1
+require 'xiki/line'
  2
+require 'xiki/ol'
3 3
 
4 4
 class CodeTree
5 5
 
4  lib/color.rb → lib/xiki/color.rb
... ...
@@ -1,5 +1,5 @@
1  
-require 'effects'
2  
-require 'styles'
  1
+require 'xiki/effects'
  2
+require 'xiki/styles'
3 3
 
4 4
 # Colors lines, and shows only colored lines
5 5
 class Color
0  lib/console.rb → lib/xiki/console.rb
File renamed without changes
0  lib/control_lock.rb → lib/xiki/control_lock.rb
File renamed without changes
0  lib/control_tab.rb → lib/xiki/control_tab.rb
File renamed without changes
2  lib/core_ext.rb → lib/xiki/core_ext.rb
... ...
@@ -1,4 +1,4 @@
1  
-require 'text_util'
  1
+require 'xiki/text_util'
2 2
 
3 3
 class Array
4 4
   def blank?
0  lib/cursor.rb → lib/xiki/cursor.rb
File renamed without changes
0  lib/deletes.rb → lib/xiki/deletes.rb
File renamed without changes
2  lib/diff_log.rb → lib/xiki/diff_log.rb
... ...
@@ -1,4 +1,4 @@
1  
-require 'hide'
  1
+require 'xiki/hide'
2 2
 
3 3
 # Will store a diff each time a file is saved.
4 4
 class DiffLog
2  lib/effects.rb → lib/xiki/effects.rb
... ...
@@ -1,4 +1,4 @@
1  
-require 'styles'
  1
+require 'xiki/styles'
2 2
 
3 3
 # Makes visual things happen
4 4
 class Effects
0  lib/environment.rb → lib/xiki/environment.rb
File renamed without changes
8  lib/file_tree.rb → lib/xiki/file_tree.rb
... ...
@@ -1,9 +1,9 @@
1  
-require 'styles'
2  
-require 'line'
3  
-require 'view'
  1
+require 'xiki/styles'
  2
+require 'xiki/line'
  3
+require 'xiki/view'
4 4
 require 'net/http'
5 5
 require 'uri'
6  
-require 'cursor'
  6
+require 'xiki/cursor'
7 7
 
8 8
 # Draws a tree from a dir structure and lets you incrementally search in the tree.
9 9
 # Usage (user):
0  lib/files.rb → lib/xiki/files.rb
File renamed without changes
0  lib/hide.rb → lib/xiki/hide.rb
File renamed without changes
0  lib/history.rb → lib/xiki/history.rb
File renamed without changes
0  lib/image.rb → lib/xiki/image.rb
File renamed without changes
0  lib/incrementer.rb → lib/xiki/incrementer.rb
File renamed without changes
0  lib/insert.rb → lib/xiki/insert.rb
File renamed without changes
0  lib/irc.rb → lib/xiki/irc.rb
File renamed without changes
0  lib/key_bindings.rb → lib/xiki/key_bindings.rb
File renamed without changes
10  lib/keys.rb → lib/xiki/keys.rb
... ...
@@ -1,7 +1,7 @@
1  
-require 'pause_means_space'
2  
-require 'line'
3  
-require 'text_util'
4  
-require 'launcher'
  1
+require 'xiki/pause_means_space'
  2
+require 'xiki/line'
  3
+require 'xiki/text_util'
  4
+require 'xiki/launcher'
5 5
 
6 6
 # Methods for defining keyboard shortcuts
7 7
 class Keys
@@ -461,7 +461,7 @@ def self.jump_to_code
461 461
     end
462 462
 
463 463
     file, line = Code.location_from_proc proc
464  
-    file = "#{XIKI_ROOT}/#{file}" unless file =~ /^\//
  464
+    file = "#{Xiki.dir}#{file}" unless file =~ /^\//
465 465
     Location.go(file)
466 466
     View.to_line line.to_i
467 467
     Effects.blink(:what=>:line)
10  lib/launcher.rb → lib/xiki/launcher.rb
... ...
@@ -1,5 +1,5 @@
1  
-require 'effects'
2  
-require 'requirer'
  1
+require 'xiki/effects'
  2
+require 'xiki/requirer'
3 3
 
4 4
 require 'xiki'
5 5
 
@@ -653,13 +653,14 @@ def self.init_default_launchers
653 653
     end
654 654
 
655 655
     Launcher.add /^[a-z]+\+[a-z+]+\/?$/ do |path|
656  
-      Tree << %`
  656
+      txt = %`
657 657
         | If you were told to "type #{path}", it is meant that you should
658  
-        | "type the acronym" while holding down control. This means Meaning
  658
+        | "type the acronym" while holding down control. This means
659 659
         | you should type:
660 660
         |
661 661
         |   #{Keys.human_readable(path)}
662 662
         `
  663
+      Tree.<< txt, :no_slash=>1
663 664
     end
664 665
 
665 666
     # Menu launchers
@@ -948,6 +949,7 @@ def self.invoke_menu_after clazz, txt, args
948 949
   end
949 950
 
950 951
   def self.add_class_launchers classes
  952
+
951 953
     classes.each do |clazz|
952 954
       next if clazz =~ /\//
953 955
 
0  lib/line.rb → lib/xiki/line.rb
File renamed without changes
0  lib/links.rb → lib/xiki/links.rb
File renamed without changes
0  lib/location.rb → lib/xiki/location.rb
File renamed without changes
0  lib/macros.rb → lib/xiki/macros.rb
File renamed without changes
0  lib/man.rb → lib/xiki/man.rb
File renamed without changes
709  lib/xiki/menu.rb
... ...
@@ -0,0 +1,709 @@
  1
+class Menu
  2
+
  3
+  def self.menu
  4
+    '
  5
+    - history/
  6
+      - @log/
  7
+      - @last/
  8
+    - @all/
  9
+    - .create/
  10
+      - here/
  11
+      - class/
  12
+    - .install/
  13
+      - gem/
  14
+    - .setup/
  15
+      - @~/menus/
  16
+      - .reload_menus/
  17
+    - .api/
  18
+      > Summary
  19
+      | How to use ruby code to define menus.
  20
+      |
  21
+      | You can create sophisticated menus backed by classes, or by using other
  22
+      | simple means:
  23
+      - .classes/
  24
+        - .simple class/
  25
+        - .menu with method/
  26
+        - .menu with two methods/
  27
+      - other/
  28
+        - With a string/
  29
+          |
  30
+          |   Menu.fish :menu=>"- salmon/\n- tuna/\n  - yellow fin/"
  31
+          |
  32
+          Try it out by typing 1 do_ruby (C-1 Ctrl-d Ctrl-r) while on it, then
  33
+          double-clicking on this menu to see what happens:
  34
+          |
  35
+          @fish/
  36
+          |
  37
+        - Delegating to an existing menu/
  38
+          |
  39
+          |   Menu.critters :menu=>"foo/animals"
  40
+          |
  41
+          @critters/
  42
+          |
  43
+        - Using a block/
  44
+          |
  45
+          |   Menu.foo do
  46
+          |     "hey/"
  47
+          |   end
  48
+          |
  49
+          The block can optionally take a |path| param to handle multiple levels
  50
+          of nesting.
  51
+          |
  52
+          |   Menu.foo do |path|
  53
+          |     "hey/#{path}"
  54
+          |   end
  55
+          |
  56
+        - Extract menu text from somewhere/
  57
+          | Tree.children just expects text that is in the form of a menu (lines with
  58
+          | 2-space indenting for nesting). So, the text can be pulled from
  59
+          | anywhere, such as a part of a larger file:
  60
+          |
  61
+          | Menu.lawn do |path|
  62
+          |   menu = Notes.read_block("/tmp/garage.notes", "> Lawn")
  63
+          |   Tree.children menu, Tree.rootless(path)
  64
+          | end
  65
+          |
  66
+      |
  67
+      | If you want to create a very simple menu you can do so without code,
  68
+      | by just putting the menu in a file such as ~/menu/foo.menu. See:
  69
+      |
  70
+      << docs/how_to_create/
  71
+    - .docs/
  72
+      - .How to use/
  73
+      - .How to create/
  74
+      - .keys/
  75
+        > Summary
  76
+        | Helpful keyboard shortcuts when using menus.
  77
+        |
  78
+        | - as+menu
  79
+        |   - Save changes to menu (or create new one)
  80
+        | - to+menu
  81
+        |   - Jump to file that implements menu
  82
+        |
  83
+    '
  84
+  end
  85
+
  86
+  def self.install *args
  87
+    Xiki.dont_search
  88
+    Tree.quote "
  89
+      > TODO
  90
+      - implement this.
  91
+
  92
+      - Should it look for installed gems with this name?
  93
+      - Should it just show commands to do a gem install?
  94
+        - How would it know whether it the gem has a xiki menu?
  95
+      "
  96
+  end
  97
+
  98
+  def self.create *args
  99
+    type = args[0]
  100
+
  101
+    return self.create_here if type == "here"
  102
+    return self.create_class if type == "class"
  103
+    return self.create_more(*args.drop(1)) if type == "more"
  104
+
  105
+    "- unknown option #{type} passed to .create!"
  106
+  end
  107
+
  108
+  def self.create_here
  109
+
  110
+    # TODO: Handle various use cases
  111
+      # "menu/create/here/" at left margin
  112
+      # "@menu/create/here/" nested
  113
+      # "menu/create/\n  here/" at left margin
  114
+      # "@menu/create/\n  here/" nested
  115
+
  116
+    trunk = Xiki.trunk
  117
+    if wrapper = trunk[-2]   # If @menu/create/here is nested
  118
+      menu = Tree.root wrapper
  119
+    else   # If put it under a fake menu
  120
+
  121
+      # What?  This is if it's not nested? - is this used?
  122
+
  123
+      # TODO: Go to left margin and remove menu...
  124
+
  125
+      Tree.to_root
  126
+
  127
+      Tree.kill_under
  128
+      menu = "foo"
  129
+      Line.sub! /([ +-]*).*/, "\\1#{menu}/"
  130
+      # Insert it wherever we are
  131
+    end
  132
+    Xiki.dont_search
  133
+
  134
+    name_text = menu == "foo" ?
  135
+      "and change '#{menu}' to something" :
  136
+      "to go under the '#{menu}' menu"
  137
+
  138
+    snake = TextUtil.snake_case menu
  139
+
  140
+    Tree << "
  141
+      | Supply a few items here. Then do as+menu (type Ctrl-a Ctrl-m) to create
  142
+      | the '#{menu}' menu. Or, just create '~/menus/#{snake}.menu' yourself.
  143
+      - example item/
  144
+        - another/
  145
+      - and another/
  146
+      "
  147
+
  148
+    nil
  149
+
  150
+  end
  151
+
  152
+  def self.create_class
  153
+    trunk = Xiki.trunk
  154
+    if wrapper = trunk[-2]
  155
+      # Just do in-line
  156
+      menu = TextUtil.snake_case Tree.root(wrapper)
  157
+    else
  158
+      menu = 'foo'
  159
+    end
  160
+
  161
+    Xiki.dont_search
  162
+
  163
+    Tree << %`
  164
+      | Update this sample class to your liking. Then do as+update (type
  165
+      | Ctrl-a, Ctrl-u) to create the '#{menu}' class file.
  166
+      - @~/menus/
  167
+        - #{menu}.rb
  168
+          | class #{TextUtil.camel_case(menu)}
  169
+          |   def self.menu *args
  170
+          |     "- Args Passed: \#{args.inspect}\\n- Customize me in) @ ~/menus/#{menu}.rb"
  171
+          |   end
  172
+          | end
  173
+      - more examples) @menu/api/classes/
  174
+      `
  175
+    nil
  176
+  end
  177
+
  178
+  def self.simple_class *args
  179
+    root = 'foo'
  180
+    trunk = Xiki.trunk
  181
+    root = TextUtil.snake_case(trunk[-2][/^[\w -]+/]) if trunk.length > 1   # If nested path (due to @), grab root of parent
  182
+
  183
+    %`
  184
+    - @~/menus/
  185
+      - #{root}.rb
  186
+        | class #{TextUtil.camel_case(root)}
  187
+        |   def self.menu *args
  188
+        |     "- args passed: \#{args.inspect}\n- Customize me in) @ ~/menus/#{menu}.rb"
  189
+        |   end
  190
+        | end
  191
+    `
  192
+  end
  193
+
  194
+  def self.menu_with_method *args
  195
+    root = 'foo'
  196
+    trunk = Xiki.trunk
  197
+    root = TextUtil.snake_case(trunk[-2][/^[\w -]+/]) if trunk.length > 1   # If nested path (due to @), grab root of parent
  198
+
  199
+    %`
  200
+    - @~/menus/
  201
+      - #{root}.rb
  202
+        | class #{TextUtil.camel_case(root)}
  203
+        |   def self.menu
  204
+        |     "
  205
+        |     - cake/
  206
+        |       - chocolate/
  207
+        |     - .pie/
  208
+        |     "
  209
+        |   end
  210
+        |
  211
+        |   def self.pie
  212
+        |     "- apple/"
  213
+        |   end
  214
+        | end
  215
+    `
  216
+  end
  217
+
  218
+  def self.menu_with_two_methods *args
  219
+    root = 'foo'
  220
+    trunk = Xiki.trunk
  221
+    root = TextUtil.snake_case(trunk[-2][/^[\w -]+/]) if trunk.length > 1   # If nested path (due to @), grab root of parent
  222
+
  223
+    %`
  224
+    - @~/menus/
  225
+      - #{root}.rb
  226
+        | class #{TextUtil.camel_case(root)}
  227
+        |   def self.menu
  228
+        |     "
  229
+        |     - sammiches/
  230
+        |       - ham/
  231
+        |         - .buy/
  232
+        |       - tofu/
  233
+        |         - .buy/
  234
+        |     - .checkout/
  235
+        |       - cash/
  236
+        |       - credit/
  237
+        |     "
  238
+        |   end
  239
+        |   def self.buy category, item
  240
+        |     "- buying \#{item} \#{category}"
  241
+        |   end
  242
+        |   def self.checkout kind
  243
+        |     "- checking out as \#{kind}..."
  244
+        |   end
  245
+        | end
  246
+        |
  247
+    `
  248
+  end
  249
+
  250
+  def self.how_to_use *args
  251
+    %`
  252
+    > Summary
  253
+    | How to use Xiki menus.  Note this refers to the wiki-style menus, not the menu bar.
  254
+    |
  255
+    | All menus can be used the same way.  Just type something and double-click
  256
+    | on it (or type Ctrl-enter while the cursor is on the line).
  257
+    |
  258
+    - example/
  259
+      | 1: type "foo" on a line (the "@" isn't necessary when the line isn't indented)
  260
+      @ foo
  261
+      |
  262
+      | 2: double-click on it to drill in. You can try it on the line above. It will look like this:
  263
+      @ foo/
  264
+      |  - sammiches/
  265
+      |  - dranks/
  266
+      |
  267
+      | 3: double-click to drill in further. It will look like this:
  268
+      @ foo/
  269
+      |  - sammiches/
  270
+      |    - ham/
  271
+      |    - tofu/
  272
+      |  - dranks/
  273
+      |
  274
+    - using the mouse/
  275
+      | You can click on the "bullets" (the - and + at the beginnings of lines)
  276
+      | to expand and collapse.  You can also double-click to expand and
  277
+      | collapse.
  278
+      |
  279
+    - search to narrow down/
  280
+      | When you double-click a line the cursor turns blue and you can type
  281
+      | letters to search and narrow down the list.
  282
+      |
  283
+    - misc keys/
  284
+      | - Return: stops searching and launches (expands file or dir)
  285
+      | - Tab: like return but hides others
  286
+      | - ;: like return but collapses path
  287
+      |
  288
+      | - C-g: stops searching
  289
+      |
  290
+      | - Arrow keys: you can use them to go up and down and expand and collapse
  291
+      |
  292
+    `
  293
+  end
  294
+
  295
+  def self.how_to_create *args
  296
+    txt = %q`
  297
+      > Summary
  298
+      | How to make your own menus in Xiki.  Note this refers to wiki-style
  299
+      | menus (such as this one), not the menu bar.
  300
+      |
  301
+      - Creating .menu files/
  302
+        | You can make menus without code, by just put "whatever.menu" files in the
  303
+        | "menu/" dir in your home dir.
  304
+        |
  305
+        | For example you could create a "foo.menu" file with the contents
  306
+        | "- sammiches/..." etc:
  307
+        |
  308
+        - TODO: get these to expand out somehow! - maybe pass another arg to Tree.children below? - probably bad idea
  309
+        - ~/menus/
  310
+          - foo.menu
  311
+            | - sammiches/
  312
+            |   - ham/
  313
+            |   - tofu/
  314
+            | - dranks/
  315
+            |   - foty/
  316
+        |
  317
+      - Delegating/
  318
+        | This makes a foo/ menu that you can expand.  Even though these menus
  319
+        | don't run code themselves, they can delegate to other menus or run code,
  320
+        | like:
  321
+        |
  322
+        - ~/menus/
  323
+          - foo.menu
  324
+            | - @mymenu/
  325
+            | - @MyClass.my_method
  326
+        |
  327
+      `
  328
+
  329
+    Tree.children(txt, args.join('/'))
  330
+  end
  331
+
  332
+  def self.reload_menus
  333
+    Launcher.reload_menu_dirs
  334
+    View.flash
  335
+    nil
  336
+  end
  337
+
  338
+  def self.[] path
  339
+    path, rest = path.split '/', 2
  340
+
  341
+    self.call path, rest
  342
+  end
  343
+
  344
+  def self.call root, rest=nil
  345
+    root = root.gsub /[ +]/, '_'
  346
+    menus = Launcher.menus
  347
+    block = menus[0][root] || menus[1][root]
  348
+    return if block.nil?
  349
+    Tree.output_and_search block, :line=>"#{root}/#{rest}", :just_return=>1
  350
+  end
  351
+
  352
+  def self.method_missing *args, &block
  353
+    Launcher.method_missing *args, &block
  354
+    "- defined!"
  355
+  end
  356
+
  357
+  def self.split path, options={}
  358
+    path = path.sub /\/$/, ''
  359
+    path = Tree.rootless path if options[:rootless]
  360
+
  361
+    return [] if path.empty?
  362
+
  363
+    groups = path.split '/|', -1
  364
+
  365
+    result = groups[0] =~ /^\|/ ?
  366
+      [groups[0]] :
  367
+      groups[0].split('/', -1)
  368
+
  369
+    result += groups[1..-1].map{|o| "|#{o}"}
  370
+  end
  371
+
  372
+  def self.to_menu
  373
+    # Take best guess, by looking through dirs for root
  374
+    trunk = Xiki.trunk
  375
+
  376
+    return View.<<("- You weren't on a menu\n  | To jump to a menu's implementation, put your cursor on it\n  | (or type it on a blank line) and then do as+menu (ctrl-a ctrl-m)\n  | Or, look in one of these dirs:\n  - ~/menus/\n  - $xiki/menus/") if trunk[-1].blank?
  377
+
  378
+    root = trunk[0][/^[\w _-]+/]
  379
+
  380
+    root = trunk[-1][/^[\w _-]+/] if ! Keys.prefix_u
  381
+
  382
+    root.gsub!(/[ -]/, '_') if root
  383
+
  384
+    root.downcase!
  385
+
  386
+    (["#{Xiki.dir}lib/"]+Launcher::MENU_DIRS).reverse.each do |dir|
  387
+      next unless File.directory? dir
  388
+      file = Dir["#{dir}/#{root}.*"]
  389
+      next unless file.any?
  390
+      return View.open file[0]
  391
+    end
  392
+
  393
+    #     message = "
  394
+    #       - No menu found:
  395
+    #         | No \"#{root}\" menu or class file found in these dirs:
  396
+    #         @ ~/menus/
  397
+    #         @ $x/menus/
  398
+    #         ".unindent
  399
+
  400
+    # Should be able to get it right from proc
  401
+
  402
+    proc = Launcher.menus[1][root]
  403
+
  404
+    return View.flash "- Menu 'root' doesn't exist!", :times=>4 if ! proc
  405
+
  406
+    location = proc.source_location # ["./firefox.rb", 739]
  407
+    location[0].sub! /^\.\//, Xiki.dir
  408
+    View.open location[0]
  409
+    View.line = location[1]
  410
+
  411
+  end
  412
+
  413
+  def self.external menu, options={}
  414
+
  415
+    View.message ""
  416
+
  417
+    View.wrap :off
  418
+
  419
+    # IF nothing passed, must want to do tiny search box
  420
+    if menu.empty?
  421
+      Launcher.open ""
  422
+      View.message ""
  423
+      View.prompt "Type anything", :timed=>1, :times=>2 #, :color=>:rainbow
  424
+
  425
+      Launcher.launch
  426
+    else
  427
+      Launcher.open menu, options
  428
+    end
  429
+  end
  430
+
  431
+  def self.as_menu
  432
+    orig = View.cursor
  433
+
  434
+    Tree.to_root
  435
+
  436
+    root, left = Line.value, View.cursor
  437
+    root = Line.without_label :line=>root
  438
+
  439
+    root = TextUtil.snake_case(root).sub(/^_+/, '')
  440
+
  441
+    if Line.value(2) =~ /^ +\| Supply a few items here/   # If sample text, remove
  442
+      Line.next
  443
+      while Line.=~(/^ +\| /)
  444
+        Line.delete
  445
+      end
  446
+      Line.previous
  447
+      orig = nil
  448
+    end
  449
+
  450
+    Tree.after_children
  451
+    right = View.cursor
  452
+    View.cursor = left
  453
+
  454
+    # Go until end of paragraph (simple for now)
  455
+    Effects.blink :left=>left, :right=>right
  456
+    txt = View.txt left, right
  457
+    txt.sub! /.+\n/, ''
  458
+    txt.gsub! /^  /, ''
  459
+    txt.unindent
  460
+
  461
+    return Tree << "| You must supply something to put under the '#{root}' menu.\n| First, add some lines here, such as these:\n- line/\n- another line/\n" if txt.empty?
  462
+
  463
+    path = File.expand_path "~/menus/#{root}.menu"
  464
+
  465
+    file_existed = File.exists? path
  466
+
  467
+    if file_existed
  468
+      treeb = File.read path
  469
+      txt = Tree.restore txt, treeb
  470
+
  471
+      DiffLog.save_diffs :patha=>path, :textb=>txt
  472
+    end
  473
+
  474
+    File.open(path, "w") { |f| f << txt }
  475
+
  476
+    View.cursor = orig if orig
  477
+
  478
+    require_menu path
  479
+
  480
+    View.flash "- #{file_existed ? 'Updated' : 'Created'} ~/menus/#{root}.menu", :times=>3
  481
+    nil
  482
+  end
  483
+
  484
+  @@loaded_already = {}
  485
+
  486
+  def self.load_if_changed file
  487
+    return :not_found if ! File.exists?(file)
  488
+    previous = @@loaded_already[file]
  489
+    recent = File.mtime(file)
  490
+
  491
+    if previous == nil
  492
+      #       require file
  493
+      load file
  494
+      @@loaded_already[file] = recent
  495
+      return
  496
+    end
  497
+
  498
+    return if recent <= previous
  499
+
  500
+    load file
  501
+    @@loaded_already[file] = recent
  502
+  end
  503
+
  504
+  def self.collapser_launcher
  505
+
  506
+    line = Line.value
  507
+    arrows = line[/<+/].length
  508
+    arrows -= 1 if arrows > 1   # Make "<<" go back just 1, etc.
  509
+
  510
+    #     line.sub! /(^ +)= /, "\\1< "   # Temporarily get "=" to work too
  511
+    line = Line.without_label :line=>line
  512
+
  513
+    skip = line.empty? && arrows - 1
  514
+
  515
+    Line.sub! /^(  +)<+ .+/, "\\1- "   # Delete after bullet to prepare for loop
  516
+
  517
+    arrows.times do |i|
  518
+
  519
+      # If no items left on current line, jump to parent and delete
  520
+      if Line =~ /^[ +-]+$/
  521
+        Tree.to_parent
  522
+        Tree.kill_under
  523
+        Move.to_end
  524
+      end
  525
+
  526
+      unless i == skip   # Remove last item, or after bullet if no items
  527
+        Line.sub!(/\/[^\/]+\/$/, '/') || Line.sub!(/^([ @+-]*).*/, "\\1")
  528
+      end
  529
+    end
  530
+
  531
+    if Line.indent.blank?
  532
+      line.sub! /^@ ?/, ''
  533
+      Line.sub! /^@ ?/, ''
  534
+    end
  535
+
  536
+    Line << line unless skip
  537
+    Launcher.launch
  538
+
  539
+  end
  540
+
  541
+  def self.root_collapser_launcher
  542
+
  543
+    View.cursor
  544
+
  545
+
  546
+    # Grab line
  547
+    line = Line.value
  548
+
  549
+    arrows = line[/<+/].length
  550
+
  551
+    line.sub!(/ *<+@ /, '')
  552
+
  553
+    # Go up to root, and kill under
  554
+    arrows.times { Tree.to_root }
  555
+    Tree.kill_under
  556
+
  557
+    # Insert line, and launch
  558
+    old = Line.delete :leave_linebreak
  559
+    old.sub! /^( *).+/, "\\1"
  560
+    old << "@" if old =~ /^ /   # If any indent, @ is needed
  561
+    View << "#{old}#{line}"
  562
+
  563
+    Launcher.launch
  564
+  end
  565
+
  566
+  def self.replacer_launcher
  567
+    Line.sub! /^( +)<+= /, "\\1+ "
  568
+
  569
+    # Run in place, grab output, then move higher and show output
  570
+
  571
+    orig = View.line
  572
+    Launcher.launch :no_search=>1
  573
+
  574
+    # If didn't move line, assume it had no output, and it's collapse things itself
  575
+    return if orig == View.line
  576
+
  577
+    # If it inserted something
  578
+
  579
+    output = Tree.siblings :everything=>1
  580
+
  581
+    # return
  582
+
  583
+    # Shouldn't this be looping like self.collapser_launcher ?
  584
+    Tree.to_parent
  585
+    Tree.to_parent
  586
+    Tree.kill_under :no_plus=>1
  587
+    Tree << output
  588
+
  589
+    # TODO: do search now, after insterted?
  590
+
  591
+  end
  592
+
  593
+  def self.menu_to_hash txt
  594
+    txt = File.read txt if txt =~ /\A\/.+\z/   # If 1 line and starts with slash, read file
  595
+
  596
+    txt.gsub(/^\| /, '').split("\n").inject({}) do |o, txt|
  597
+      txt = txt.split(/ : /)
  598
+      o[txt[0]] = txt[1]
  599
+      o
  600
+    end
  601
+
  602
+  end
  603
+
  604
+  #   def self.config txt, *args
  605
+
  606
+  #     # TODO: implement
  607
+  #       # Args look like sample invocation below
  608
+  #       # If not there, create it first, using supplied default
  609
+  #       # Insert quoted file contents to be edited
  610
+
  611
+  #     # Sample invocation
  612
+  #     #     Menu.config "
  613
+  #     #       - @ ~/xiki_config/browser.notes
  614
+  #     #         | - default browser:
  615
+  #     #         |   - Firefox
  616
+  #     #         | - others:
  617
+  #     #         |   - Safari
  618
+  #     #         |   - Chrome
  619
+  #     #       ", *args
  620
+
  621
+  #     "TODO"
  622
+  #   end
  623
+
  624
+  # Moves item to root of tree (replacing tree), then launches.
  625
+  def self.do_as_menu
  626
+    line = Line.value
  627
+
  628
+    # If on ^@... line and there's child on next line...
  629
+
  630
+    on_subtree = line =~ /^[ +-]*@/ && Tree.has_child?
  631
+
  632
+    txt = on_subtree ? Tree.subtree.unindent.sub(/^[ @+-]+/, '') : Tree.path.last
  633
+
  634
+    Keys.prefix_u ? Tree.to_root(:highest=>1) : Tree.to_root
  635
+    Tree.kill_under
  636
+
  637
+    Line.sub! /^([ @]*).+/, "\\1#{txt}"
  638
+
  639
+    return if on_subtree
  640
+
  641
+    # replace line with menu
  642
+
  643
+    Launcher.launch
  644
+  end
  645
+
  646
+
  647
+  # The following 3 methods are for the menu bar
  648
+  #   - a different use of the "Menu" class
  649
+  # TODO move them into menu_bar.rb ?
  650
+
  651
+  def self.add_menu *name
  652
+    menu_spaces = name.join(' ').downcase
  653
+    menu_dashes = name.join('-').downcase
  654
+    name = name[-1]
  655
+
  656
+    lisp = %Q<
  657
+      (define-key global-map
  658
+        [menu-bar #{menu_spaces}]
  659
+        (cons "#{name}" (make-sparse-keymap "#{menu_dashes}")))
  660
+    >
  661
+    $el.el4r_lisp_eval lisp
  662
+
  663
+    menu = $el.elvar.menu_bar_final_items.to_a
  664
+    $el.elvar.menu_bar_final_items = menu.push(name.downcase.to_sym)
  665
+  end
  666
+
  667
+  def self.add_item menu, name, function
  668
+
  669
+    menu_spaces = menu.join(' ').downcase
  670
+    lisp = "
  671
+      (define-key global-map
  672
+        [menu-bar #{menu_spaces} #{function}]
  673
+        '(\"#{name}\" . #{function}))
  674
+    "
  675
+    $el.el4r_lisp_eval lisp
  676
+  end
  677
+
  678
+  ROOT_MENU = 'Keys'
  679
+
  680
+  def self.init
  681
+
  682
+    return if ! $el
  683
+
  684
+    Mode.define(:menu, ".menu") do
  685
+      Notes.mode
  686
+    end
  687
+
  688
+    add_menu ROOT_MENU
  689
+
  690
+    menus = [
  691
+      [ROOT_MENU, 'To'],
  692
+      [ROOT_MENU, 'Open'],
  693
+      [ROOT_MENU, 'Layout'],
  694
+      [ROOT_MENU, 'As'],
  695
+      [ROOT_MENU, 'Enter'],
  696
+      [ROOT_MENU, 'Do'],
  697
+      [ROOT_MENU, 'Search']
  698
+    ]
  699
+    menus.reverse.each do |tuple|
  700
+      add_menu tuple[0], tuple[1]
  701
+    end
  702
+  end
  703
+
  704
+
  705
+end
  706
+
  707
+Menu.init   # Define mode
  708
+
  709
+
2  lib/merb.rb → lib/xiki/merb.rb
... ...
@@ -1,4 +1,4 @@
1  
-require "launcher"
  1
+require 'xiki/launcher'
2 2
 
3 3
 class Merb
4 4
 
0  lib/message.rb → lib/xiki/message.rb
File renamed without changes
0  lib/meths.rb → lib/xiki/meths.rb
File renamed without changes
0  lib/mode.rb → lib/xiki/mode.rb
File renamed without changes
2  lib/move.rb → lib/xiki/move.rb
... ...
@@ -1,4 +1,4 @@
1  
-require 'keys'
  1
+require 'xiki/keys'
2 2
 
3 3
 # Provides different ways of moving cursor.
4 4
 class Move
45  lib/notes.rb → lib/xiki/notes.rb
... ...
@@ -1,9 +1,9 @@
1  
-require 'styles'
2  
-require 'line'
3  
-require 'effects'
4  
-require 'view'
5  
-require 'keys'
6  
-require 'clipboard'
  1
+require 'xiki/styles'
  2
+require 'xiki/line'
  3
+require 'xiki/effects'
  4
+require 'xiki/view'
  5
+require 'xiki/keys'
  6
+require 'xiki/clipboard'
7 7