xiki 0.5.0a

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 (252) hide show
  1. data/Gemfile +11 -0
  2. data/LICENSE +22 -0
  3. data/README.markdown +83 -0
  4. data/Rakefile +8 -0
  5. data/bin/xiki +46 -0
  6. data/etc/command/xiki_command.rb +203 -0
  7. data/etc/command/xiki_process.rb +52 -0
  8. data/etc/command/xiki_wrapper +2 -0
  9. data/etc/js/menu1.js +55 -0
  10. data/etc/js/xiki.js +259 -0
  11. data/etc/logo.png +0 -0
  12. data/etc/presentations/bootstrap.deck +5 -0
  13. data/etc/presentations/databases.deck +41 -0
  14. data/etc/presentations/diffs.deck +23 -0
  15. data/etc/presentations/documentation.deck +14 -0
  16. data/etc/presentations/effects.deck +5 -0
  17. data/etc/presentations/face.deck +297 -0
  18. data/etc/presentations/files.deck +79 -0
  19. data/etc/presentations/icons.deck +22 -0
  20. data/etc/presentations/images.deck +24 -0
  21. data/etc/presentations/key_shortcuts.deck +16 -0
  22. data/etc/presentations/macros.deck +18 -0
  23. data/etc/presentations/menu_classes.deck +44 -0
  24. data/etc/presentations/menu_directories.deck +30 -0
  25. data/etc/presentations/notes.deck +19 -0
  26. data/etc/presentations/other_languages.deck +55 -0
  27. data/etc/presentations/other_wiki_syntaxes.deck +4 -0
  28. data/etc/presentations/piano.deck +5 -0
  29. data/etc/presentations/potential/diffs.deck +38 -0
  30. data/etc/presentations/potential/evolution.deck +18 -0
  31. data/etc/presentations/potential/intro.deck +711 -0
  32. data/etc/presentations/potential/intro1.deck +711 -0
  33. data/etc/presentations/potential/intro2.deck +97 -0
  34. data/etc/presentations/potential/make_mysql_menu.deck +36 -0
  35. data/etc/presentations/potential/ruby_development.deck +17 -0
  36. data/etc/presentations/potential/ui_prototyping.deck +50 -0
  37. data/etc/presentations/potential/web_dev.deck +4 -0
  38. data/etc/presentations/potential/web_development.deck +10 -0
  39. data/etc/presentations/potential/wiki.deck +45 -0
  40. data/etc/presentations/presentations.deck +24 -0
  41. data/etc/presentations/rails_development.deck +29 -0
  42. data/etc/presentations/search_key_shortcuts.deck +37 -0
  43. data/etc/presentations/simplest_possible_ui.deck +37 -0
  44. data/etc/presentations/svg.deck +5 -0
  45. data/etc/presentations/testing.deck +28 -0
  46. data/etc/presentations/the_end.deck +13 -0
  47. data/etc/presentations/type_something_and_double_click.deck +57 -0
  48. data/etc/presentations/type_the_acronym.deck +144 -0
  49. data/etc/presentations/web_browser.deck +56 -0
  50. data/etc/presentations/xiki_command.deck +20 -0
  51. data/etc/presentations/xiki_url.deck +14 -0
  52. data/etc/shark.icns +0 -0
  53. data/etc/shark_script.icns +0 -0
  54. data/etc/snippets/html.notes +7 -0
  55. data/etc/snippets/notes.notes +20 -0
  56. data/etc/snippets/rb.notes +38 -0
  57. data/etc/templates/menu_template.menu +2 -0
  58. data/etc/templates/menu_template.rb +8 -0
  59. data/etc/templates/template.rb +5 -0
  60. data/etc/themes/Dark_Metal.notes +28 -0
  61. data/etc/themes/Orange_Path.notes +15 -0
  62. data/etc/themes/Shiny_Blue.notes +27 -0
  63. data/etc/themes/Shiny_Green.notes +27 -0
  64. data/etc/wrappers/wrapper.js +17 -0
  65. data/etc/wrappers/wrapper.py +20 -0
  66. data/etc/wrappers/wrapper.rb +25 -0
  67. data/lib/block.rb +72 -0
  68. data/lib/bookmarks.rb +352 -0
  69. data/lib/buffers.rb +170 -0
  70. data/lib/clipboard.rb +333 -0
  71. data/lib/code.rb +860 -0
  72. data/lib/code_tree.rb +476 -0
  73. data/lib/color.rb +274 -0
  74. data/lib/console.rb +557 -0
  75. data/lib/control_lock.rb +9 -0
  76. data/lib/control_tab.rb +176 -0
  77. data/lib/core_ext.rb +31 -0
  78. data/lib/cursor.rb +111 -0
  79. data/lib/deletes.rb +65 -0
  80. data/lib/diff_log.rb +297 -0
  81. data/lib/effects.rb +145 -0
  82. data/lib/environment.rb +5 -0
  83. data/lib/file_tree.rb +1875 -0
  84. data/lib/files.rb +334 -0
  85. data/lib/hide.rb +259 -0
  86. data/lib/history.rb +286 -0
  87. data/lib/image.rb +51 -0
  88. data/lib/incrementer.rb +15 -0
  89. data/lib/insert.rb +7 -0
  90. data/lib/irc.rb +22 -0
  91. data/lib/key_bindings.rb +658 -0
  92. data/lib/keys.rb +754 -0
  93. data/lib/launcher.rb +1351 -0
  94. data/lib/line.rb +429 -0
  95. data/lib/links.rb +6 -0
  96. data/lib/location.rb +175 -0
  97. data/lib/macros.rb +48 -0
  98. data/lib/man.rb +19 -0
  99. data/lib/menu.rb +708 -0
  100. data/lib/merb.rb +259 -0
  101. data/lib/message.rb +5 -0
  102. data/lib/meths.rb +56 -0
  103. data/lib/mode.rb +34 -0
  104. data/lib/move.rb +248 -0
  105. data/lib/notes.rb +1000 -0
  106. data/lib/numbers.rb +45 -0
  107. data/lib/ol.rb +203 -0
  108. data/lib/ol_helper.rb +44 -0
  109. data/lib/overlay.rb +167 -0
  110. data/lib/pause_means_space.rb +68 -0
  111. data/lib/php.rb +22 -0
  112. data/lib/projects.rb +21 -0
  113. data/lib/relinquish_exception.rb +2 -0
  114. data/lib/remote.rb +206 -0
  115. data/lib/requirer.rb +46 -0
  116. data/lib/rest_tree.rb +108 -0
  117. data/lib/ruby.rb +57 -0
  118. data/lib/ruby_console.rb +165 -0
  119. data/lib/search.rb +1572 -0
  120. data/lib/search_term.rb +40 -0
  121. data/lib/snippet.rb +68 -0
  122. data/lib/specs.rb +229 -0
  123. data/lib/styles.rb +274 -0
  124. data/lib/svn.rb +682 -0
  125. data/lib/text_util.rb +110 -0
  126. data/lib/tree.rb +1871 -0
  127. data/lib/tree_cursor.rb +87 -0
  128. data/lib/trouble_shooting.rb +27 -0
  129. data/lib/url_tree.rb +11 -0
  130. data/lib/view.rb +1474 -0
  131. data/lib/window.rb +133 -0
  132. data/lib/xiki.rb +404 -0
  133. data/menus/accounts.rb +5 -0
  134. data/menus/address_book.rb +21 -0
  135. data/menus/agenda.rb +28 -0
  136. data/menus/all.rb +5 -0
  137. data/menus/amazon.rb +16 -0
  138. data/menus/app.rb +16 -0
  139. data/menus/applescript.rb +46 -0
  140. data/menus/as.rb +15 -0
  141. data/menus/bookmarklet.rb +63 -0
  142. data/menus/bootstrap.rb +568 -0
  143. data/menus/browse.rb +13 -0
  144. data/menus/browser.rb +78 -0
  145. data/menus/cassandra_db.rb +36 -0
  146. data/menus/chmod.rb +27 -0
  147. data/menus/classes.rb +5 -0
  148. data/menus/coffee_script.rb +35 -0
  149. data/menus/computer.rb +24 -0
  150. data/menus/contacts.rb +5 -0
  151. data/menus/cookies.rb +25 -0
  152. data/menus/couch.rb +184 -0
  153. data/menus/crop.rb +45 -0
  154. data/menus/css.rb +55 -0
  155. data/menus/current.rb +5 -0
  156. data/menus/db.rb +12 -0
  157. data/menus/deck.rb +219 -0
  158. data/menus/dictionary.rb +9 -0
  159. data/menus/dir.rb +8 -0
  160. data/menus/disk.rb +5 -0
  161. data/menus/do.rb +13 -0
  162. data/menus/docs.rb +58 -0
  163. data/menus/dotsies.rb +107 -0
  164. data/menus/edited.rb +18 -0
  165. data/menus/emacs.rb +17 -0
  166. data/menus/enter.rb +13 -0
  167. data/menus/eval.rb +17 -0
  168. data/menus/executable.rb +16 -0
  169. data/menus/filter.rb +46 -0
  170. data/menus/firefox.rb +607 -0
  171. data/menus/foo.rb +30 -0
  172. data/menus/french.rb +7 -0
  173. data/menus/git.rb +185 -0
  174. data/menus/gito.rb +785 -0
  175. data/menus/google.rb +35 -0
  176. data/menus/google_images.rb +11 -0
  177. data/menus/google_patents.rb +10 -0
  178. data/menus/gutenberg.rb +13 -0
  179. data/menus/head.rb +10 -0
  180. data/menus/headings.rb +39 -0
  181. data/menus/html.rb +61 -0
  182. data/menus/icon.rb +40 -0
  183. data/menus/images.menu +2 -0
  184. data/menus/img.rb +15 -0
  185. data/menus/info.rb +9 -0
  186. data/menus/ip.rb +10 -0
  187. data/menus/iterm.rb +36 -0
  188. data/menus/itunes.rb +78 -0
  189. data/menus/javascript.rb +74 -0
  190. data/menus/layout.rb +18 -0
  191. data/menus/local_storage.rb +67 -0
  192. data/menus/ls.rb +19 -0
  193. data/menus/mac.rb +87 -0
  194. data/menus/maps.rb +18 -0
  195. data/menus/matches.rb +18 -0
  196. data/menus/memcache.rb +117 -0
  197. data/menus/mkdir.rb +23 -0
  198. data/menus/mongo.rb +83 -0
  199. data/menus/mysql.rb +294 -0
  200. data/menus/node.rb +88 -0
  201. data/menus/open.rb +19 -0
  202. data/menus/outline.rb +24 -0
  203. data/menus/piano.rb +746 -0
  204. data/menus/postgres.rb +34 -0
  205. data/menus/pre.rb +5 -0
  206. data/menus/python.rb +39 -0
  207. data/menus/rails.rb +160 -0
  208. data/menus/rake.rb +12 -0
  209. data/menus/redmine.rb +168 -0
  210. data/menus/riak_tree.rb +204 -0
  211. data/menus/rss.rb +15 -0
  212. data/menus/safari.rb +11 -0
  213. data/menus/sass.rb +15 -0
  214. data/menus/say.rb +6 -0
  215. data/menus/scale.rb +49 -0
  216. data/menus/serve.rb +78 -0
  217. data/menus/shuffle.rb +24 -0
  218. data/menus/spanish.rb +7 -0
  219. data/menus/standalone.rb +57 -0
  220. data/menus/tail.rb +41 -0
  221. data/menus/technologies.rb +19 -0
  222. data/menus/themes.rb +32 -0
  223. data/menus/thesaurus.rb +13 -0
  224. data/menus/to.rb +24 -0
  225. data/menus/twitter.rb +57 -0
  226. data/menus/wikipedia.rb +34 -0
  227. data/menus/words.rb +11 -0
  228. data/spec/code_tree_spec.rb +59 -0
  229. data/spec/diff_log_spec.rb +40 -0
  230. data/spec/file_tree_spec.rb +102 -0
  231. data/spec/keys_spec.rb +24 -0
  232. data/spec/line_spec.rb +68 -0
  233. data/spec/menu_spec.rb +50 -0
  234. data/spec/ol_spec.rb +98 -0
  235. data/spec/remote_spec.rb +43 -0
  236. data/spec/search_spec.rb +162 -0
  237. data/spec/text_util_spec.rb +119 -0
  238. data/spec/tree_cursor_spec.rb +91 -0
  239. data/spec/tree_spec.rb +955 -0
  240. data/tests/console_test.rb +11 -0
  241. data/tests/couch_db_test.rb +12 -0
  242. data/tests/diff_log_test.rb +43 -0
  243. data/tests/el_mixin.rb +16 -0
  244. data/tests/git_test.rb +95 -0
  245. data/tests/keys_test.rb +19 -0
  246. data/tests/line_test.rb +38 -0
  247. data/tests/merb_test.rb +11 -0
  248. data/tests/redmine_test.rb +50 -0
  249. data/tests/remote_test.rb +31 -0
  250. data/tests/rest_tree_test.rb +70 -0
  251. data/xiki.gemspec +37 -0
  252. metadata +332 -0
@@ -0,0 +1,27 @@
1
+ Styles.mode_line(
2
+ :bg=>'44aa44',
3
+ :border=>['55aa55', -5, 'released-button'],
4
+ :face=>'Lucida Grande',
5
+ :size=>'3',
6
+ :bold=>false,
7
+ :fg=>'fff'
8
+ )
9
+ Styles.mode_line_inactive(
10
+ :bg=>'bbb',
11
+ :border=>['bbbbbb', -1],
12
+ :face=>'Lucida Grande',
13
+ :bold=>false,
14
+ :fg=>'000'
15
+ )
16
+ Styles.mode_line_dir(
17
+ :fg=>"222222",
18
+ :size=>"0",
19
+ :face=>"arial",
20
+ :bold=>false
21
+ )
22
+ Styles.mode_line_file(
23
+ :fg=>"fff",
24
+ :size=>"0",
25
+ :face=>"arial",
26
+ :bold=>false
27
+ )
@@ -0,0 +1,17 @@
1
+ // Sample js file this can invoke
2
+ /*
3
+ @/projects/xiki_wrappers/
4
+ - pie.js
5
+ | exports.menu = function () {
6
+ | return "hey/\nyou/\nthere/\n";
7
+ | };
8
+ */
9
+
10
+ // Gets shelled out to by xiki to delegate call to a .js file.
11
+ // Just gets the args passed in and requires and invokes.
12
+ var file = process.argv[2]
13
+ var path = process.argv[3]
14
+
15
+ var clazz = require(file);
16
+ var output = clazz.menu();
17
+ console.log(output);
@@ -0,0 +1,20 @@
1
+ # Gets shelled out to by xiki to delegate call to a .py file.
2
+ # Just gets the args passed in and requires and invokes.
3
+ import sys, re
4
+
5
+ file = sys.argv[1]
6
+ path = sys.argv[2]
7
+
8
+ clazz = re.sub(".+/", "", file)
9
+ clazz = re.sub("\.py$", "", clazz)
10
+ clazz = clazz.capitalize()
11
+ execfile(file)
12
+
13
+ method = ".menu"
14
+
15
+ import re
16
+
17
+ if re.search("^\.", path):
18
+ method = path.replace(r'/', '')
19
+
20
+ print(eval(clazz+"()"+method+"()"))
@@ -0,0 +1,25 @@
1
+ # Gets shelled out to by xiki to delegate call to a no-dependency .rb file.
2
+ # Just gets the args passed in and requires and invokes.
3
+
4
+ # TODO Don't hard-code path
5
+ require "/projects/xiki/lib/ol.rb"
6
+
7
+ file = ARGV.shift
8
+ path = ARGV.shift
9
+
10
+ load file
11
+
12
+ clazz = file[/\w+/].gsub(/_([a-z]+)/) {"#{$1.capitalize}"}.sub(/(.)/) {$1.upcase}.gsub("_", "")
13
+ clazz = eval clazz
14
+
15
+ method = "menu"
16
+ method = path[/^\.(.+?)\/?$/, 1] if path =~ /^\./
17
+ method = method.to_sym
18
+
19
+ if clazz.respond_to? method
20
+ puts clazz.send method
21
+ else
22
+ cmethods = clazz.methods - Class.methods
23
+ puts cmethods.sort.map{|o| "+ .#{o}/"}
24
+ end
25
+
@@ -0,0 +1,72 @@
1
+ class Block
2
+
3
+ # def self.value
4
+ # res = []
5
+ # with(:save_excursion) do
6
+ # found = re_search_backward "^ *$", nil, 1
7
+ # if found
8
+ # end_of_line
9
+ # forward_char
10
+ # end
11
+ # res << point
12
+ # re_search_forward "^ *$", nil, 1
13
+ # beginning_of_line
14
+ # res << point
15
+ # end
16
+ # res
17
+ # end
18
+
19
+ def self.do_as_wrap
20
+
21
+ if Keys.prefix_u?
22
+ # Grab paragraph and remove linebreaks
23
+
24
+ orig = Location.new
25
+ txt = View.paragraph :delete => true, :start_here => true
26
+ txt.gsub! "\n", " "
27
+ txt.sub!(/ $/, "\n")
28
+ View.insert txt
29
+ orig.go
30
+
31
+ Line.to_left
32
+ View.insert "> "
33
+ $el.fill_paragraph nil
34
+ txt = View.paragraph(:delete => true)
35
+ View.insert txt.gsub(/^ /, '> ')
36
+ return
37
+ end
38
+
39
+ $el.fill_paragraph nil
40
+ end
41
+
42
+ def self.do_as_something
43
+
44
+ prefix = Keys.prefix
45
+ txt, left, right = View.txt_per_prefix prefix
46
+
47
+ result = yield txt
48
+
49
+ # Insert result at end of block
50
+ orig = Location.new
51
+ View.cursor = right
52
+ Line.to_left
53
+
54
+ if prefix.nil?
55
+ View.insert(">>\n"+result.strip+"\n") unless result.blank?
56
+ else
57
+ View.insert(result.strip.gsub(/^/, ' ')+"\n") unless result.blank?
58
+ end
59
+
60
+ orig.go
61
+ end
62
+
63
+ def self.>> txt
64
+ orig = Location.new
65
+ ignore, left, right = View.block_positions "^>"
66
+ View.cursor = right
67
+
68
+ View.insert(">>\n#{txt.strip}\n") unless txt.blank?
69
+ orig.go
70
+ end
71
+
72
+ end
@@ -0,0 +1,352 @@
1
+ require 'location'
2
+ require 'keys'
3
+ require 'yaml'
4
+
5
+ class Bookmarks
6
+
7
+ def self.menu
8
+ %`
9
+ - .list/
10
+ - .tree/
11
+ - .api/
12
+ | > Summary
13
+ | Some of the common ways to use the Bookmarks class programatically.
14
+ |
15
+ | > Get path for a bookmark
16
+ @p Bookmarks["$t"]
17
+ |
18
+ | > Expand bookmark in a path
19
+ @p Bookmarks["$tm/hi.txt"]
20
+ |
21
+ > Where Emacs stores bookmarks
22
+ @ ~/.emacs.bmk
23
+ |
24
+ - .elisp/
25
+ | > Save unsaved bookmarks to ~/.emacs.bmk
26
+ | (bookmark-save)
27
+ |
28
+ | > Delete a bookmark
29
+ | (bookmark-delete "foo")
30
+ - docs/
31
+ > Summary
32
+ | Xiki uses standard emacs bookmarks, while adding several keyboard shortcuts
33
+ | and the ability to bookmark buffers in addition to just files.
34
+ |
35
+ > Keys
36
+ | All of these prompt for a bookmark name:
37
+ |
38
+ | as+bookmark: bookmark the current file
39
+ | open+bookmark: jumps to bookmark file
40
+ | open+point: jumps to bookmark file and cursor position
41
+ |
42
+ > See Also
43
+ @files/docs/
44
+ `
45
+ end
46
+
47
+ def self.save arg=nil
48
+ in_a_file_tree = FileTree.handles? rescue nil
49
+
50
+ # If we're in a file tree, use file in tree (unless C-u over-rides it)
51
+ if ! Keys.prefix_u? && in_a_file_tree && ! Line[/^ *\|/]
52
+ path = Tree.construct_path
53
+ keys = Keys.input(:timed=>true, :prompt=>"Name of bookmark for #{path.sub(/.+\/(.)/, "\\1")}: ") || "0"
54
+ $el.with(:save_window_excursion) do
55
+ $el.find_file path
56
+ self.set keys
57
+ end
58
+ View.flash "- bookmarked as: $#{keys}", :times=>3
59
+ return
60
+ end
61
+
62
+ # If arg is a symbol, use it as the prefix
63
+ prefix = ""
64
+ if arg && arg.type == Symbol
65
+ prefix = arg.to_s
66
+ elsif arg && arg.type == String
67
+ self.set(arg.sub(/^\$/, ""))
68
+ return
69
+ end
70
+ # Use input from user or "default"
71
+ keys = Keys.input(:timed=>true, :prompt=>"Name of bookmark for #{View.file_name}: ") || "0"
72
+ self.set "#{prefix}#{keys}"
73
+
74
+ # Append to bookmark file
75
+ log_path = "/temp/bookmark_log.notes"
76
+ if File.exists?(log_path)
77
+ File.open(log_path, "a") { |f| f << "| $#{prefix}#{keys}\n#{View.file}\n\n" }
78
+ end
79
+ end
80
+
81
+ def self.[]= bookmark, path
82
+ $el.with(:save_window_excursion) do
83
+ View.open path
84
+ Bookmarks.set bookmark
85
+ end
86
+ end
87
+
88
+ # Like bookmark-set, but accepts buffers
89
+ def self.set name
90
+ # Just create normal bookmark if file
91
+ return $el.bookmark_set(name) if View.file || $el.elvar.dired_directory
92
+
93
+ # Must be buffer
94
+
95
+ $el.bookmark_delete name # Delete real bookmark
96
+
97
+ # Load bookmarks.yml
98
+ bookmarks_yml = File.expand_path("~/bookmarks.yml")
99
+ if File.exists?(bookmarks_yml)
100
+ bookmarks = YAML::load IO.read(bookmarks_yml)
101
+ end
102
+ bookmarks = [] unless bookmarks
103
+
104
+ # Delete if there
105
+ already_here = bookmarks.find {|bm| bm[0] == name}
106
+ bookmarks.delete(already_here) if already_here
107
+
108
+ # Add to end
109
+ bookmarks << [name, View.name]
110
+
111
+ # Save file
112
+ File.open(bookmarks_yml, "w") { |f| f << bookmarks.to_yaml }
113
+
114
+ end
115
+
116
+ # Like bookmark-jump, but accepts buffers
117
+ def self.jump name
118
+
119
+ # If normal bookmark found, use it
120
+ return $el.bookmark_jump(name) if $el.bookmark_get_filename(name)
121
+
122
+ buffer = self.buffer_bookmark name
123
+
124
+ if buffer == :buffer_not_open
125
+ return $el.message "Buffer '#{buffer}' not currently open."
126
+ end
127
+ return nil if buffer.nil?
128
+
129
+ View.to_buffer buffer
130
+ return true
131
+ end
132
+
133
+ def self.buffer_bookmark name
134
+ # Load bookmarks.yml
135
+ bookmarks_yml = File.expand_path("~/bookmarks.yml")
136
+ return nil unless File.exists?(bookmarks_yml)
137
+ bookmarks = YAML::load IO.read(bookmarks_yml)
138
+ bookmarks = [] unless bookmarks
139
+
140
+ # Get buffer name
141
+ found = bookmarks.find {|bm| bm[0] == name}
142
+ return nil unless found
143
+
144
+ unless View.buffer_open?(found[1])
145
+ return :buffer_not_open
146
+ end
147
+ # Do nothing if already open
148
+
149
+ found[1]
150
+ end
151
+
152
+
153
+
154
+ # If string passed, go to file+point of bookmark.
155
+ # If nothing passed, go to file of user-prompted text
156
+ # If no args passed, get bookmark from user and jump there
157
+ def self.go bookmark=nil, options={}
158
+ #el4r_lisp_eval "(require 'bookmark)(bookmark-maybe-load-default-file)"
159
+ # If arg is a symbol, use it as the prefix
160
+ prefix_to_bm = ""
161
+ if bookmark && bookmark.type == Symbol
162
+ prefix_to_bm = bookmark.to_s
163
+ elsif bookmark && bookmark.type == String
164
+ keys = bookmark
165
+ # return self.jump(bookmark.sub(/^\$/, ""))
166
+ end
167
+
168
+ # Use input from user or "default"
169
+ keys ||= Keys.input(:timed => true, :prompt => "Enter bookmark to jump to: ") || "0"
170
+
171
+ # Open file or jump to if already open
172
+ path = $el.bookmark_get_filename( "#{prefix_to_bm}#{keys}" )
173
+
174
+ if path.nil? # If not found, try buffer in bookmarks.yml
175
+
176
+ return true if self.jump( "#{prefix_to_bm}#{keys}" )
177
+ View.beep
178
+ $el.message("Bookmark not found!")
179
+ return :not_found
180
+ end
181
+
182
+ prefix = Keys.prefix
183
+ if prefix==9 # If 9, open in bar
184
+ View.bar
185
+ self.jump "#{prefix_to_bm}#{keys}"
186
+ else
187
+ Location.go path, :stay_in_bar => true
188
+ end
189
+
190
+ if options[:point] or prefix == :u # Go to actual point
191
+ return self.jump("#{prefix_to_bm}#{keys}")
192
+ end
193
+ end
194
+
195
+ def self.keys
196
+ # TODO: put newest keys here
197
+ end
198
+
199
+ # Expand $foo paths in strings. Expects strings to bee bookmark names,
200
+ # and replaces with corresponding paths.
201
+ def self.[] path
202
+ self.expand(path)
203
+ end
204
+
205
+ def self.expand path, options={}
206
+ if options[:just_bookmark] # If only a bookmark, just expand it
207
+ return $el.bookmark_get_filename(path)
208
+ end
209
+
210
+ # If $xxx found
211
+ if path =~ /^\$([._a-zA-Z0-9-]+)([\\\/]?)(.*)/
212
+ bm, slash, rest = $1, $2, $3
213
+
214
+ bm_orig = bm
215
+ # Expand bookmark
216
+ if ["x", "xiki"].member? bm
217
+ bm = Xiki.dir
218
+ else
219
+ bm = $el.bookmark_get_filename(bm)
220
+ end
221
+
222
+ if bm.nil?
223
+ bm =
224
+ if bm_orig == "t"
225
+ "#{File.expand_path("~")}/todo.notes"
226
+ elsif bm_orig == "f"
227
+ "#{File.expand_path("~")}/files.notes"
228
+ end
229
+ end
230
+ return path if bm.nil?
231
+
232
+ # If a slash, cut off filename if there is one (only dir is wanted)
233
+ if options[:file_ok] # Put slash back if there was one
234
+ bm << "/" if bm !~ /\/$/ && slash.any?
235
+ elsif slash.any?
236
+ bm.sub! /[^\\\/]+$/, ""
237
+ end
238
+
239
+ path = "#{bm}#{rest}"
240
+
241
+ # Expand ~/ if it has it
242
+
243
+ path = View.expand_path(path) if path =~ /^~/
244
+
245
+ path
246
+
247
+ elsif path =~ /^~\// # If home dir, expand
248
+ # Expand ~/ if it has it
249
+ View.expand_path(path)
250
+
251
+ elsif options[:absolute] || path =~ /^\.+(\/|$)/ # If relative path, expand
252
+ View.expand_path(path)
253
+ else
254
+ path
255
+ end
256
+ end
257
+
258
+ # Insert $bookmark into to path if it contains a bookmarked path
259
+ def self.collapse path
260
+ if ! @bookmarks_cache
261
+ @bookmarks_cache = []
262
+ # TODO: pull this list out and make configurable
263
+ %w[a tr p n x 18].each do |name|
264
+
265
+ bmpath = $el.bookmark_get_filename(name)
266
+ next unless bmpath
267
+ bmpath.sub!(/[^\/]+$/, "")
268
+
269
+ @bookmarks_cache << [name, bmpath]
270
+ end
271
+ end
272
+
273
+ @bookmarks_cache.each do |name, bmpath|
274
+ next unless path =~ /^#{bmpath}/
275
+ return path.sub(bmpath, "$#{name}/")
276
+ end
277
+ return path
278
+ end
279
+
280
+ # Remove file from the end (if not dir)
281
+ def self.dir_only path
282
+ path.sub(/\/[^\/]+\.[^\/]+$/, '')
283
+ end
284
+
285
+ # Prompt user for bookmark name, and return bookmark
286
+ def self.input options={}
287
+ self.expand(
288
+ Keys.input(options.merge(:timed => true)),
289
+ :just_bookmark => true
290
+ )
291
+ end
292
+
293
+ # Read a file
294
+ def self.read name
295
+ File.read(self.expand(name))
296
+ end
297
+
298
+ def self.list path=nil
299
+
300
+ result = ""
301
+ if ! path # Print all bookmarks
302
+ all = $el.elvar.bookmark_alist.collect { |bm|
303
+ item = bm.to_a
304
+ [item[0], item[1].to_a[0][1]]
305
+ }
306
+ all.each do |l|
307
+ n, p = l
308
+ result << "- #{n}) @#{p.sub(/\/$/,'')}\n"
309
+ # puts "- #{n.ljust(7)} #{p.sub(/\/$/,'')}"
310
+ #puts "- #{n}: #{p}"
311
+ end
312
+ return result
313
+ end
314
+
315
+ # Open single path
316
+ View.open path[/ ([~\/].+)/, 1]
317
+ nil
318
+ end
319
+
320
+ def self.tree
321
+ # paths = elvar.bookmark_alist.collect {|bm|
322
+ # bm.to_a[1].to_a[0][1]
323
+ # }.select{|path| path =~ /^\/.+\w$/}
324
+
325
+ paths = $el.elvar.bookmark_alist.collect {|bm|
326
+ ary = bm.to_a
327
+ key = ary[0]
328
+ path = ary[1].to_a[0][1]
329
+ [key, path]
330
+ }
331
+ paths = paths.select{|a| a[1] =~ /^\/.+\w$/} # Remove bm's to dirs
332
+ paths.collect! {|bm|
333
+ path = bm[1]
334
+ path.sub! /(.+\/)/, "\\1#{bm[0]}: "
335
+ path
336
+ }
337
+
338
+ Tree.paths_to_tree(paths)
339
+ end
340
+
341
+ def self.open_quick
342
+ bookmark = Keys.input :timed=>1, :prompt=>"Enter a quick bookmark to jump to:"
343
+ Bookmarks.go("q#{bookmark}")
344
+ end
345
+
346
+ end
347
+
348
+ if $el
349
+ $el.el4r_lisp_eval("(require 'bookmark)")
350
+ $el.bookmark_maybe_load_default_file
351
+ end
352
+