Class: Search
Constant Summary collapse
- SPECIAL_ORDER =
"X!='\"[]{}<>_-+*@#\\/!$X"
- @@case_options =
nil
- @@outline_goto_once =
nil
- @@log =
File.("~/.emacs.d/search_log.notes")
Class Method Summary collapse
-
.add_case_option(name, the_proc) ⇒ Object
Make another option show up for View.cases.
-
.append_log(dir, txt) ⇒ Object
, prefix=”.
- .backward(search, options = {}) ⇒ Object
- .bookmark ⇒ Object
- .cancel ⇒ Object
- .case_options ⇒ Object
- .copy(match) ⇒ Object
- .copy_and_comment ⇒ Object
- .cut ⇒ Object
- .deep_outline(txt, line) ⇒ Object
- .downcase ⇒ Object
- .enter(txt = nil) ⇒ Object
- .enter_insert_search ⇒ Object
- .enter_like_edits ⇒ Object
- .enter_search(bm = nil, input = nil) ⇒ Object
- .find_in_buffers(string, options = {}) ⇒ Object
- .fit_in_snippet(match) ⇒ Object
-
.forward(search, options = {}) ⇒ Object
! elvar.isearch_success end.
- .go_to_end ⇒ Object
- .grep ⇒ Object
-
.have_label ⇒ Object
Insert line at beginning of search.
-
.have_line ⇒ Object
Insert line at beginning of search.
-
.have_paragraph ⇒ Object
Insert line at beginning of search.
- .have_right ⇒ Object
- .hide ⇒ Object
- .highlight_found ⇒ Object
- .history(txt = nil) ⇒ Object
- .insert_at_search_start ⇒ Object
- .insert_at_spot ⇒ Object
- .insert_quote_at_search_start ⇒ Object
- .insert_tree_at_spot ⇒ Object
- .insert_var_at_search_start ⇒ Object
- .isearch(txt = nil, options = {}) ⇒ Object
- .isearch_as_camel ⇒ Object
- .isearch_as_snake ⇒ Object
- .isearch_clipboard ⇒ Object
- .isearch_copy_as(name) ⇒ Object
- .isearch_delete ⇒ Object
- .isearch_enter_and_next ⇒ Object
- .isearch_find_in_buffers(options = {}) ⇒ Object
- .isearch_google(options = {}) ⇒ Object
- .isearch_have_case ⇒ Object
- .isearch_have_output ⇒ Object
- .isearch_have_output_javascript ⇒ Object
- .isearch_have_within ⇒ Object
- .isearch_just_adjust ⇒ Object
- .isearch_just_case ⇒ Object
- .isearch_just_comment ⇒ Object
- .isearch_just_search ⇒ Object
- .isearch_just_surround_with_char(left = nil, right = nil) ⇒ Object
- .isearch_just_tag ⇒ Object
- .isearch_just_underscores ⇒ Object
- .isearch_just_wrap ⇒ Object
- .isearch_m ⇒ Object
- .isearch_move_line ⇒ Object
- .isearch_move_to(path, options = {}) ⇒ Object
- .isearch_next ⇒ Object
- .isearch_open ⇒ Object
- .isearch_or_copy(name) ⇒ Object
- .isearch_outline ⇒ Object
- .isearch_paths ⇒ Object
- .isearch_pause_or_resume ⇒ Object
-
.isearch_pull_in_sexp ⇒ Object
During isearch, pull next sexp into the search string.
-
.isearch_pull_in_words(n) ⇒ Object
During isearch, pull next n words.
- .isearch_query_replace(after = nil) ⇒ Object
- .isearch_restart(path, options = {}) ⇒ Object
- .isearch_select_inner ⇒ Object
- .isearch_stop_at_end ⇒ Object
- .isearch_surround_with_tag ⇒ Object
-
.isearch_to ⇒ Object
During isearch, open most recently edited file with the search string in its name.
- .jump_to_difflog ⇒ Object
- .just_bookmark ⇒ Object
- .just_edges ⇒ Object
- .just_edits ⇒ Object
- .just_increment(options = {}) ⇒ Object
- .just_macro ⇒ Object
- .just_marker ⇒ Object
- .just_menu ⇒ Object
-
.just_name ⇒ Object
Copy match as name (like Keys.as_name).
- .just_orange ⇒ Object
- .just_select ⇒ Object
- .kill_filter(options = {}) ⇒ Object
-
.kill_search(left, right) ⇒ Object
Incrementeal search between cursor and end of paragraph (kills unmatching lines).
- .last_search ⇒ Object
- .launched(bm = nil) ⇒ Object
- .left ⇒ Object
- .like_delete ⇒ Object
- .log ⇒ Object
- .match(left = nil, right = nil) ⇒ Object
- .menu ⇒ Object
- .move_to(path, match, options = {}) ⇒ Object
- .move_to_files(match) ⇒ Object
- .move_to_search_start(match) ⇒ Object
-
.open_file_and_method(match) ⇒ Object
Jumps to the file corresponding to a string.
- .outline ⇒ Object
- .outline_goto_once ⇒ Object
- .outline_goto_once=(txt) ⇒ Object
- .outline_search ⇒ Object
-
.query_replace(s1 = nil, s2 = nil) ⇒ Object
Do query replace depending on what they type.
-
.query_replace_nth(n1, n2) ⇒ Object
Query replaces from “1” clipboard to “2” clipboard, etc.
- .right ⇒ Object
-
.search_at_root(txt) ⇒ Object
Go to root of tree and do search.
- .search_in_bookmark(match) ⇒ Object
- .search_last_launched ⇒ Object
- .search_thesaurus ⇒ Object
- .searches ⇒ Object
-
.stop(options = {}) ⇒ Object
Clears the isearch, allowing for inserting, or whatever else.
- .subtract ⇒ Object
- .to(find) ⇒ Object
- .to_left ⇒ Object
- .to_start ⇒ Object
-
.tree_grep ⇒ Object
prefix=nil.
- .upcase ⇒ Object
- .was_reverse ⇒ Object
- .xiki ⇒ Object
- .zap ⇒ Object
-
.zap_hooks ⇒ Object
To set a hook Search.zap_hooks ‘m’ do …
Class Method Details
.add_case_option(name, the_proc) ⇒ Object
Make another option show up for View.cases
72 73 74 75 76 |
# File 'lib/xiki/search.rb', line 72 def self.add_case_option name, the_proc # Delete if there already @@case_options.delete_if{|i| i.first == name} @@case_options << [name, the_proc] end |
.append_log(dir, txt) ⇒ Object
, prefix=”
1385 1386 1387 1388 |
# File 'lib/xiki/search.rb', line 1385 def self.append_log dir, txt#, prefix='' txt = "- #{dir}\n #{txt}\n" File.open(@@log, "a") { |f| f << txt } rescue nil end |
.backward(search, options = {}) ⇒ Object
760 761 762 763 764 765 |
# File 'lib/xiki/search.rb', line 760 def self.backward search, ={} orig = View.cursor found = $el.re_search_backward search, nil, ([:go_anyway] ? 1 : true) View.cursor = orig if [:dont_move] found end |
.bookmark ⇒ Object
1390 1391 1392 1393 1394 1395 1396 1397 1398 |
# File 'lib/xiki/search.rb', line 1390 def self.bookmark match = self.stop if match.nil? # If nothing searched for yet, resume search Search.tree_grep else Search.search_in_bookmark match end end |
.cancel ⇒ Object
738 739 740 741 |
# File 'lib/xiki/search.rb', line 738 def self.cancel self.stop self.to_start # Go back to start end |
.case_options ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/xiki/search.rb', line 61 def self. return @@case_options if @@case_options @@case_options = [] # Set to empty if not set yet self.add_case_option 'upper', proc {|txt| txt.upcase} self.add_case_option 'lower', proc {|txt| txt.downcase} self.add_case_option 'camel', proc {|txt| TextUtil.camel_case(txt)} self.add_case_option 'snake', proc {|txt| TextUtil.snake_case(txt)} @@case_options end |
.copy(match) ⇒ Object
257 258 259 260 261 262 |
# File 'lib/xiki/search.rb', line 257 def self.copy match Clipboard[0] = match $el.set_register ?X, match $el.x_select_text match Clipboard.save_by_first_letter match # Store for retrieval with enter_yank end |
.copy_and_comment ⇒ Object
191 192 193 194 195 196 197 198 |
# File 'lib/xiki/search.rb', line 191 def self.copy_and_comment self.stop line = Line.value(1, :include_linebreak=>true).sub("\n", "") Code.comment Line.left, Line.right self.to_start # Go back to start $el.insert "#{line}" Line.to_beginning end |
.cut ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/xiki/search.rb', line 264 def self.cut match = self.stop # If nothing searched for, go to spot of last delete if match.nil? # If nothing searched for yet Location.to_spot('killed') else Clipboard.set(0, match) $el.set_register ?X, match View.delete self.left, self.right Location.as_spot('killed') end end |
.deep_outline(txt, line) ⇒ Object
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 |
# File 'lib/xiki/search.rb', line 1440 def self.deep_outline txt, line txt = txt.split "\n" target_i = line # Start with current line i, children, matched_above = target_i-1, false, 1 result = [txt[i]] target_indent = txt[i][/^ */].length / 2 # Go through each line above while (i -= 1) >= 0 # Grab lines with incrementally lower indent, but only if they have lines under! line = txt[i] next if line.empty? indent = line[/^ */].length / 2 if indent > target_indent # If lower, skip, remembering children children = true elsif indent == target_indent # If same, only grab if there were children if children matched_above += 1 result.unshift txt[i] end children = false else # Indented less next if indent == 0 && line =~ /^#? ?Ol\b/ # Skip if ^Ol... line matched_above += 1 result.unshift txt[i] children = false target_indent = indent end end i, candidate = target_i-1, nil target_indent = txt[i][/^ */].length / 2 # Go through each line below while (i += 1) < txt.length # Grab lins with incrementally lower indent, but only if they have lines under! line = txt[i] next if line.empty? indent = line[/^ */].length / 2 if indent > target_indent # If lower, add candidate if any if candidate result << candidate candidate = nil end elsif indent == target_indent # If same, only grab if there were children candidate = txt[i] else # Indented less next if indent == 0 && line =~ /^#? ?Ol\b/ # Skip if ^Ol... line target_indent = indent candidate = txt[i] end end [result.join("\n")+"\n", matched_above] end |
.downcase ⇒ Object
840 841 842 843 |
# File 'lib/xiki/search.rb', line 840 def self.downcase self.stop $el.downcase_region(self.left, self.right) end |
.enter(txt = nil) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/xiki/search.rb', line 174 def self.enter txt=nil match = self.stop txt ||= Clipboard[0] if match.nil? # If nothing searched for yet, do search_edits bm = Keys.input :timed=>true, :prompt=>"Enter a bookmark to search edits: " return Launcher.open("diff log/diffs/") if bm == "8" || bm == " " path = bm == "." ? View.file : "$#{bm}/" return Launcher.open("- #{path}\n @edits/") end View.delete(Search.left, Search.right) View.insert txt end |
.enter_insert_search ⇒ Object
1528 1529 1530 1531 1532 1533 1534 1535 |
# File 'lib/xiki/search.rb', line 1528 def self.enter_insert_search # If in file tree, do ## if FileTree.handles? Search.enter_search else Google.insert end end |
.enter_like_edits ⇒ Object
845 846 847 848 849 |
# File 'lib/xiki/search.rb', line 845 def self.enter_like_edits Notes.enter_junior View << "@edits/" Launcher.launch end |
.enter_search(bm = nil, input = nil) ⇒ Object
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 |
# File 'lib/xiki/search.rb', line 851 def self.enter_search bm=nil, input=nil # If line already has something, assume we'll add - ##foo/ to it if ! Line[/^ *$/] input = Keys.prefix_u ? Clipboard.get : Keys.input(:prompt=>"Text to search for: ") indent = Line.indent Line.to_right View.insert "\n#{indent} - ###{input}/" Launcher.launch return end bm ||= Keys.input(:timed=>true, :prompt=>"Enter bookmark in which to search: ") return unless bm input ||= Keys.prefix_u? ? # Do search Clipboard.get : Keys.input(:prompt=>"Text to search for: ") if bm == "." # Do tree in dir from bookmark if Line.blank? dir = $el.elvar.default_directory else dir = nil end else dir = Bookmarks.("$#{bm}") end View.insert("- #{dir}" || "") indent = Line.indent Line.to_right View.insert("\n#{indent} - ###{input}/") FileTree.launch end |
.find_in_buffers(string, options = {}) ⇒ Object
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/xiki/search.rb', line 530 def self.find_in_buffers string, ={} string.gsub!('"', '\\"') new_args = "\"#{string}\"" = {} [:buffer] = View.buffer_name if [:current_only] new_args << ", #{.inspect[1..-2]}" unless .empty? View. if [:in_bar] $el.switch_to_buffer "*tree find in buffers" Notes.mode $el.erase_buffer View.insert "+ Buffers.search #{new_args}/" $el.open_line 1 CodeTree.launch :no_search=>true if [:buffer] # Goto first match $el.goto_line 4 Line.to_words Tree.search(:recursive=>false, :left=>Line.left, :right=>View.bottom) else # Goto first match in 2nd file $el.goto_line 2 $el.re_search_forward "^ -", nil, true Line.next 2 Line.to_words end end |
.fit_in_snippet(match) ⇒ Object
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 |
# File 'lib/xiki/search.rb', line 1318 def self.fit_in_snippet match target_path = View.file View.layout_files :no_blink=>1 View.to_highest Move.to_junior # Go to first file path = Xiki.trunk.last # Grab from wiki tree # If doesn't fit in the tree, just return to delegate back return false if ! target_path || ! target_path.start_with?(path) cursor = Line.left 2 FileTree.enter_quote match View.cursor = cursor return true # If handled end |
.forward(search, options = {}) ⇒ Object
! elvar.isearch_success
end
749 750 751 752 753 754 755 756 757 758 |
# File 'lib/xiki/search.rb', line 749 def self.forward search, ={} View.to_highest if [:from_top] orig = View.cursor found = $el.re_search_forward search, nil, ([:go_anyway] ? 1 : true) View.cursor = orig if [:dont_move] View.cursor = self.left if [:beginning] && View.cursor != View.bottom found end |
.go_to_end ⇒ Object
278 279 280 281 282 283 284 285 286 287 |
# File 'lib/xiki/search.rb', line 278 def self.go_to_end match = self.stop if match.nil? # If nothing searched for yet Search.isearch_restart "$f", :restart=>true return end $el.goto_char self.right end |
.grep ⇒ Object
385 386 387 |
# File 'lib/xiki/search.rb', line 385 def self.grep cm_grep("./", read_from_minibuffer("Grep for pattern: ")) end |
.have_label ⇒ Object
Insert line at beginning of search
585 586 587 588 589 590 |
# File 'lib/xiki/search.rb', line 585 def self.have_label self.stop label = Line.label self.to_start # Go back to start $el.insert "- #{label}: " end |
.have_line ⇒ Object
Insert line at beginning of search
577 578 579 580 581 582 |
# File 'lib/xiki/search.rb', line 577 def self.have_line self.stop line = Line.value(1, :include_linebreak=>true).sub("\n", "") self.to_start # Go back to start $el.insert line end |
.have_paragraph ⇒ Object
Insert line at beginning of search
593 594 595 596 597 598 599 600 601 602 |
# File 'lib/xiki/search.rb', line 593 def self.have_paragraph self.stop paragraph = View.paragraph offset = View.cursor - View.paragraph(:bounds=>true)[0] self.to_start # Go back to start orig = Location.new $el.insert paragraph orig.go Move.forward offset end |
.have_right ⇒ Object
1549 1550 1551 1552 1553 1554 |
# File 'lib/xiki/search.rb', line 1549 def self.have_right match = self.stop View.to_upper View.to_highest View << "#{match}\n\n" end |
.hide ⇒ Object
569 570 571 572 573 574 |
# File 'lib/xiki/search.rb', line 569 def self.hide match = self.stop Hide.hide_unless /#{Regexp.quote(match)}/i $el.recenter -3 Hide.search end |
.highlight_found ⇒ Object
563 564 565 566 567 |
# File 'lib/xiki/search.rb', line 563 def self.highlight_found match = self.stop $el.highlight_regexp(Regexp.quote(match), :hi_yellow) end |
.history(txt = nil) ⇒ Object
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 |
# File 'lib/xiki/search.rb', line 1417 def self.history txt=nil # If nothing selected yet, show history if ! txt searches = self.searches.uniq return searches.map{|o| "| #{o}\n"}.join("") end # Option selected, so search for it txt.sub! /^\| /, '' # Go back to where we came from, if we're in special search buffer View.kill if View.buffer_name == "@search/history/" Search.isearch txt nil end |
.insert_at_search_start ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/xiki/search.rb', line 95 def self.insert_at_search_start was_reverse = self.was_reverse match = self.stop if match.nil? # If nothing searched for yet, search difflog loc = Keys.input(:chars=>1, :prompt=>"Enter one char to search for corresponding string: ") loc = loc.to_s txt = Clipboard.hash[loc.to_s] || Clipboard.hash_by_first_letter[loc.to_s] txt ||= self.searches.find{|o| o =~ /^#{loc}/i} return View.("Nothing to search for matching '#{loc}'.", :beep=>1) if txt.nil? self.isearch txt, :reverse=>was_reverse return end self.to_start # Go back to start $el.insert match end |
.insert_at_spot ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/xiki/search.rb', line 78 def self.insert_at_spot match = self.stop Hide.show Location.to_spot $el.insert match end |
.insert_quote_at_search_start ⇒ Object
147 148 149 150 151 |
# File 'lib/xiki/search.rb', line 147 def self.insert_quote_at_search_start match = self.stop self.to_start $el.insert "'#{match}'" end |
.insert_tree_at_spot ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/xiki/search.rb', line 87 def self.insert_tree_at_spot self.stop txt = FileTree.snippet # Grab symbol Hide.show Location.go :_0 $el.insert txt end |
.insert_var_at_search_start ⇒ Object
141 142 143 144 145 |
# File 'lib/xiki/search.rb', line 141 def self.insert_var_at_search_start match = self.stop self.to_start # Go back to start $el.insert "\#{#{match}}" end |
.isearch(txt = nil, options = {}) ⇒ Object
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 |
# File 'lib/xiki/search.rb', line 1165 def self.isearch txt=nil, ={} if [:from_bottom] View.to_bottom [:reverse] = true end txt ||= "" # Searchig for nil causes error $el.isearch_resume txt, ([:regex] ?true:nil), nil, (! [:reverse]), txt, true $el.isearch_update end |
.isearch_as_camel ⇒ Object
908 909 910 911 912 913 |
# File 'lib/xiki/search.rb', line 908 def self.isearch_as_camel self.stop term = self.match self.to_start View.insert TextUtil.camel_case(term) end |
.isearch_as_snake ⇒ Object
915 916 917 918 919 920 |
# File 'lib/xiki/search.rb', line 915 def self.isearch_as_snake self.stop term = self.match self.to_start View.insert TextUtil.snake_case(term) end |
.isearch_clipboard ⇒ Object
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 |
# File 'lib/xiki/search.rb', line 1254 def self.isearch_clipboard txt = Search.stop if txt.nil? # If nothing searched for yet Console.search_last_commands else self.copy txt Location.as_spot('clipboard') end end |
.isearch_copy_as(name) ⇒ Object
722 723 724 725 |
# File 'lib/xiki/search.rb', line 722 def self.isearch_copy_as name self.stop Clipboard.set(name, self.match) end |
.isearch_delete ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/xiki/search.rb', line 160 def self.isearch_delete match = self.stop # If nothing searched for, go to spot of last delete if match.nil? # If nothing searched for yet, search difflog DiffLog.open View.to_bottom Search.isearch nil, :reverse=>true else View.delete(Search.left, Search.right) Location.as_spot('killed') end end |
.isearch_enter_and_next ⇒ Object
1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 |
# File 'lib/xiki/search.rb', line 1289 def self.isearch_enter_and_next if self.match == "" # If nothing searched for yet, go to where last copy happened self.stop Location.to_spot('clipboard') Search.isearch Clipboard[0] return end match = self.stop View.delete(Search.left, Search.right) View.insert Clipboard[0] Search.isearch match end |
.isearch_find_in_buffers(options = {}) ⇒ Object
525 526 527 528 |
# File 'lib/xiki/search.rb', line 525 def self.isearch_find_in_buffers ={} match = self.stop self.find_in_buffers match, end |
.isearch_google(options = {}) ⇒ Object
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 |
# File 'lib/xiki/search.rb', line 784 def self.isearch_google ={} term = self.stop if term term.gsub!(' ', '+') term = "\"#{term}\"" if [:quote] term =~ /^https?:\/\// ? # If url, just browse $el.browse_url(term) : $el.browse_url("http://google.com/search?q=#{term}") return end Firefox.log Search.isearch nil, :from_bottom=>true end |
.isearch_have_case ⇒ Object
1071 1072 1073 1074 1075 1076 1077 |
# File 'lib/xiki/search.rb', line 1071 def self.isearch_have_case self.stop txt = self.match lam = Keys.input(:prompt=>'convert to which case?: ', :choices=>TextUtil.case_choices) self.to_start # Go back to start $el.insert lam[txt] end |
.isearch_have_output ⇒ Object
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 |
# File 'lib/xiki/search.rb', line 886 def self.isearch_have_output return self.isearch_have_output_javascript if View.extension == "js" match = self.stop self.to_start return View.insert("Ol.line") if match.nil? if Tree.construct_path(:all=>1, :slashes=>1) =~ /<script/ View.insert "console.log('#{match}: ' + #{match});" return end View.insert "Ol << \"#{match}: \#{#{match}.inspect}\"" end |
.isearch_have_output_javascript ⇒ Object
902 903 904 905 906 |
# File 'lib/xiki/search.rb', line 902 def self.isearch_have_output_javascript match = self.stop self.to_start View.insert "p(\"#{match}: \" + #{match});" end |
.isearch_have_within ⇒ Object
116 117 118 119 120 |
# File 'lib/xiki/search.rb', line 116 def self.isearch_have_within match = self.stop self.to_start # Go back to start $el.insert match[/^.(.*).$/, 1] end |
.isearch_just_adjust ⇒ Object
922 923 924 925 926 927 |
# File 'lib/xiki/search.rb', line 922 def self.isearch_just_adjust self.stop Move.forward $el.transpose_chars 1 self.to_start end |
.isearch_just_case ⇒ Object
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 |
# File 'lib/xiki/search.rb', line 1060 def self.isearch_just_case was_reverse = self.was_reverse txt = self.stop return Search.isearch(Clipboard[0], :reverse=>was_reverse) if txt.nil? choice = Keys.input(:prompt=>'convert to which case?: ', :choices=>TextUtil.case_choices) View.delete(Search.left, Search.right) View.insert choice[txt] end |
.isearch_just_comment ⇒ Object
200 201 202 203 204 |
# File 'lib/xiki/search.rb', line 200 def self.isearch_just_comment self.stop Code.comment Line.left, Line.right Line.to_beginning end |
.isearch_just_search ⇒ Object
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 |
# File 'lib/xiki/search.rb', line 1278 def self.isearch_just_search self.just_orange match = self.match Tree.to_parent # Go to parent Tree.to_parent if Line[/^ *- ##/] Tree.under "- \#\##{match}/", :escape=>'', :no_search=>1, :no_slash=>1 Launcher.launch end |
.isearch_just_surround_with_char(left = nil, right = nil) ⇒ Object
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 |
# File 'lib/xiki/search.rb', line 998 def self.isearch_just_surround_with_char left=nil, right=nil right ||= left term = self.stop if term == "" View.insert "()" Move.backward return end View.to(Search.left + term.length) View.insert right View.to(Search.left) View.insert left View.to Search.left end |
.isearch_just_tag ⇒ Object
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 |
# File 'lib/xiki/search.rb', line 948 def self.isearch_just_tag self.stop left, right = Search.left, Search.right tag = Keys.input :timed=>true, :prompt=>"Enter tag name: " left_tag = "<#{tag}>" right_tag = "</#{tag}>" if tag == 'di' left_tag = "<div id='#{Keys.input :prompt=>"Enter id: "}'>" right_tag = "</div>" elsif tag == 'dc' left_tag = "<div class='#{Keys.input :prompt=>"Enter id: "}'>" right_tag = "</div>" end View.to(right) View.insert right_tag View.to(left) View.insert left_tag View.to right + left_tag.length end |
.isearch_just_underscores ⇒ Object
1079 1080 1081 1082 1083 1084 |
# File 'lib/xiki/search.rb', line 1079 def self.isearch_just_underscores self.stop term = self.match View.delete(Search.left, Search.right) View.insert TextUtil.snake_case(term) end |
.isearch_just_wrap ⇒ Object
971 972 973 974 975 976 977 978 979 980 981 982 |
# File 'lib/xiki/search.rb', line 971 def self.isearch_just_wrap self.stop left, right = Search.left, Search.right wrap_with = Keys.input :timed=>true, :prompt=>"Enter string to wrap match with: " View.to(right) View.insert wrap_with View.to(left) View.insert wrap_with View.to right + wrap_with.length end |
.isearch_m ⇒ Object
1512 1513 1514 1515 1516 1517 1518 |
# File 'lib/xiki/search.rb', line 1512 def self.isearch_m match = self.stop return if match # If there was a match, just stop Launcher.open("- log/") if match.nil? end |
.isearch_move_line ⇒ Object
809 810 811 812 813 814 815 816 817 |
# File 'lib/xiki/search.rb', line 809 def self.isearch_move_line $el.isearch_done $el. line = $el.buffer_substring $el.point_at_bol, $el.point_at_eol + 1 View.delete $el.point_at_bol, $el.point_at_eol + 1 #self.to_start # Go back to start $el.exchange_point_and_mark $el.insert line end |
.isearch_move_to(path, options = {}) ⇒ Object
1303 1304 1305 1306 1307 |
# File 'lib/xiki/search.rb', line 1303 def self.isearch_move_to path, ={} match = self.stop match = Line.value if match.nil? # Use line if nothing searched for self.move_to path, match, end |
.isearch_next ⇒ Object
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 |
# File 'lib/xiki/search.rb', line 1237 def self.isearch_next was_reverse = self.was_reverse match = self.stop if match.nil? && Keys.before_last == "19" # If nothing searched for yet self.stop self.search_last_launched else self.stop $el.next_line end end |
.isearch_open ⇒ Object
779 780 781 782 |
# File 'lib/xiki/search.rb', line 779 def self.isearch_open self.stop View.open(self.match) end |
.isearch_or_copy(name) ⇒ Object
710 711 712 713 714 715 716 717 718 719 720 |
# File 'lib/xiki/search.rb', line 710 def self.isearch_or_copy name was_reverse = self.was_reverse match = self.stop if match.nil? # If nothing searched for yet self.isearch Clipboard[name].downcase, :reverse=>was_reverse else # Else, if nothing searched for self.stop Clipboard[name] = match end end |
.isearch_outline ⇒ Object
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 |
# File 'lib/xiki/search.rb', line 1188 def self.isearch_outline match = self.stop if match.nil? # If nothing searched for yet # Do isearch in Ol buffer Search.isearch_restart "$o", :restart=>true else if ! View.file # If buffer, not file buffer_name = $el.buffer_name txt = View.txt View.to_buffer "* outline of matches in #{buffer_name}" Notes.mode View.kill_all View.insert txt.grep(Regexp.new(match)).join return end # If file Search.outline_goto_once = Line.number dir = View.dir file_name = View.file_name View.to_buffer "*tree grep"; View.dir = dir View.clear; Notes.mode View.insert " - #{dir}/ - #{file_name} - ###{Regexp.quote(match)}/ ".unindent View.to_line 3 FileTree.launch # Search.isearch_find_in_buffers(:current_only=>true) end end |
.isearch_paths ⇒ Object
1228 1229 1230 1231 1232 1233 1234 1235 |
# File 'lib/xiki/search.rb', line 1228 def self.isearch_paths was_reverse = self.was_reverse match = self.stop return Line.previous if match.nil? && was_reverse # Odd case, user might do this if at end of file return Git.search_repository if match.nil? Search.move_to_search_start match end |
.isearch_pause_or_resume ⇒ Object
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 |
# File 'lib/xiki/search.rb', line 1265 def self.isearch_pause_or_resume match = self.stop if match.nil? # If nothing searched for yet, resume search Location.to_spot('paused') Search.isearch $xiki_paused_isearch_string else # If search in progress, stop it, remembering spot $xiki_paused_isearch_string = self.match.downcase Location.as_spot('paused') end end |
.isearch_pull_in_sexp ⇒ Object
During isearch, pull next sexp into the search string
615 616 617 618 619 620 621 622 623 624 625 626 627 |
# File 'lib/xiki/search.rb', line 615 def self.isearch_pull_in_sexp # If on the beginning of a grouping char, move back to catch the sexp $el.el4r_lisp_eval %q= (isearch-yank-internal (lambda () (if (and (> (point) 1) (string-match "[{<\\\\\"'(\\\\[]" (char-to-string (char-before (point)))) ) (backward-char)) (forward-sexp) (point)))= end |
.isearch_pull_in_words(n) ⇒ Object
During isearch, pull next n words
606 607 608 609 610 611 612 |
# File 'lib/xiki/search.rb', line 606 def self.isearch_pull_in_words n # If on the beginning of a grouping char, move back to catch the sexp $el.el4r_lisp_eval " (isearch-yank-internal (lambda () (forward-word #{n}) (point)))" end |
.isearch_query_replace(after = nil) ⇒ Object
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/xiki/search.rb', line 362 def self.isearch_query_replace after=nil match = self.stop# was_upper = match =~ /[A-Z]/ match.downcase! left, right = Search.left, Search.right before = $el.regexp_quote(match) # Always start with isearch match # If before not there or is :match, prompt for input if after.nil? || after == :match initial_input = after == :match ? before : '' after = Keys.input(:prompt=>"Change instances of '#{before}' to: ", :initial_input=>initial_input) @@query_from, @@query_to = before, after end View.delete left, right View.insert was_upper ? TextUtil.title_case(after) : after $el.query_replace_regexp before, after end |
.isearch_restart(path, options = {}) ⇒ Object
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 |
# File 'lib/xiki/search.rb', line 1126 def self.isearch_restart path, ={} self.stop term = Search.last_search if path == "$t" # If $t, open bar View.layout_todo # FileTree.open_in_bar; Effects.blink(:what=>:line) elsif path == "$f" View.layout_files elsif path == "$o" View.layout_output [:reverse] = true elsif path == "$d" View.open "$d" [:reverse] = true elsif path == :top # Will go to highest below elsif path == :right View.layout_right 1 elsif path == :next View.next elsif path == :previous View.previous else View.open Bookmarks[path] end View.wrap unless [:restart] # Don't change wrapping if starting search View.to_highest if [:reverse] View.to_bottom [:restart] ? $el.isearch_backward : self.isearch(term, :reverse=>true) return end [:restart] ? $el.isearch_forward : self.isearch(term) end |
.isearch_select_inner ⇒ Object
153 154 155 156 157 158 |
# File 'lib/xiki/search.rb', line 153 def self.isearch_select_inner self.stop $el.set_mark self.left + 1 $el.goto_char self.right - 1 Effects.blink :what=>:region end |
.isearch_stop_at_end ⇒ Object
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 |
# File 'lib/xiki/search.rb', line 1177 def self.isearch_stop_at_end # Kind of a hack - search for anything, so it won't error when we stop $el.isearch_resume "[^`]", true, nil, true, "", true self.stop self.to_start # Go back to start View. "" nil end |
.isearch_surround_with_tag ⇒ Object
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 |
# File 'lib/xiki/search.rb', line 1017 def self.isearch_surround_with_tag term = self.stop left = Search.left tag = Keys.input :timed=>1, :prompt=>"Enter tag to surround: " View.to(left + term.length) View.insert "</#{tag}>" View.to left View.insert "<#{tag}>" View.to left end |
.isearch_to ⇒ Object
During isearch, open most recently edited file with the search string in its name
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 |
# File 'lib/xiki/search.rb', line 630 def self.isearch_to match = self.stop if match.nil? # If nothing searched for yet Search.isearch_restart "$t", :restart=>true else dir = Keys.bookmark_as_path :prompt=>"Enter bookmark to look in (or space for recently edited): " return View.("Use space!", :beep=>1) if dir == :comma return self.open_file_and_method(match) if dir == :space # If key is comma, treat as last edited TextUtil.snake_case! match if match =~ /[a-z][A-Z]/ # If camel case, file is probably snake FileTree.grep_with_hashes dir, match, '**' # Open buffer and search end end |
.jump_to_difflog ⇒ Object
238 239 240 241 242 243 244 245 246 247 |
# File 'lib/xiki/search.rb', line 238 def self.jump_to_difflog match = self.stop self.to_start Location.as_spot DiffLog.open View.to_bottom Search.isearch match, :reverse=>true end |
.just_bookmark ⇒ Object
1520 1521 1522 1523 1524 1525 1526 |
# File 'lib/xiki/search.rb', line 1520 def self.just_bookmark match = self.stop path = Keys.bookmark_as_path :include_file=>1 # Get path (from bookmark) View.open path View.to_highest Search.isearch match end |
.just_edges ⇒ Object
990 991 992 993 994 995 996 |
# File 'lib/xiki/search.rb', line 990 def self.just_edges self.stop left, right = Search.left+1, Search.right-1 Effects.blink :left=>left, :right=>right View.delete(left, right) View.to(Search.left+1) end |
.just_edits ⇒ Object
249 250 251 252 253 254 255 |
# File 'lib/xiki/search.rb', line 249 def self.just_edits match = self.stop DiffLog.open View.file View.to_bottom Search.isearch match, :reverse=>true end |
.just_increment(options = {}) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/xiki/search.rb', line 206 def self.just_increment ={} match = self.stop View.delete(Search.left, Search.right) orig = View.cursor position = SPECIAL_ORDER.index match # If one of certain chars, use custom order result = if position # Change '[' to ']', etc increment_or_decrement = [:decrement] ? -1 : 1 SPECIAL_ORDER[position+increment_or_decrement].chr else if [:decrement] match =~ /[a-z]/i ? (match[0] - 1) : (match.to_i - 1).to_s else match.next end end View.insert(result) View.cursor = orig end |
.just_macro ⇒ Object
1039 1040 1041 1042 |
# File 'lib/xiki/search.rb', line 1039 def self.just_macro self.stop Macros.run end |
.just_marker ⇒ Object
557 558 559 560 561 |
# File 'lib/xiki/search.rb', line 557 def self.just_marker match = self.stop $el.highlight_regexp(Regexp.quote(match), :notes_label) end |
.just_menu ⇒ Object
1053 1054 1055 1056 1057 1058 |
# File 'lib/xiki/search.rb', line 1053 def self. match = self.stop View.open "$ml" View.to_bottom Search.isearch match, :reverse=>true end |
.just_name ⇒ Object
Copy match as name (like Keys.as_name)
1032 1033 1034 1035 1036 1037 |
# File 'lib/xiki/search.rb', line 1032 def self.just_name term = self.stop loc ||= Keys.input(:chars=>1, :prompt=>"Enter one char (variable name to store this as): ") || "0" Clipboard.copy loc, term Effects.blink :left=>left, :right=>right end |
.just_orange ⇒ Object
985 986 987 988 |
# File 'lib/xiki/search.rb', line 985 def self.just_orange self.stop Overlay.face(:notes_label, :left=>Search.left, :right=>Search.right) end |
.just_select ⇒ Object
941 942 943 944 945 946 |
# File 'lib/xiki/search.rb', line 941 def self.just_select self.stop View.set_mark(Search.right) View.to(Search.left) Effects.blink :what=>:region end |
.kill_filter(options = {}) ⇒ Object
727 728 729 730 731 732 733 734 735 736 |
# File 'lib/xiki/search.rb', line 727 def self.kill_filter ={} # TODO: Get options[:kill_matching]=>true to delete matching # - and map to Keys.do_kill_matching Line.start left = $el.point $el.re_search_forward "^$", nil, 1 right = $el.point $el.goto_char left Tree.search(:left=>left, :right=>right, :recursive=>true) end |
.kill_search(left, right) ⇒ Object
Incrementeal search between cursor and end of paragraph (kills unmatching lines)
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/xiki/search.rb', line 415 def self.kill_search(left, right) pattern = "" lines = $el.buffer_substring(left, right).split "\n" ch = $el.char_to_string read_char while ch =~ /[~#-'>a-zA-Z0-9!*\_'.~#-\/]/ if ch == "\t" pattern = "" else pattern = pattern + regexp_quote(ch) # Filter text and put back View.delete left, right # Replace out lines that don't match lines = lines.grep(/#{pattern}/i) # Put back into buffer $el.insert lines.join("\n") + "\n" right = $el.point # Go to first file $el.goto_char left end $el. "Delete lines not matching: %s", pattern ch = $el.char_to_string read_char end # Run whatever they typed last as a command (it was probably C-m or C-a, etc.) case ch when "\C-m" # If it was C-m # Do nothing else $el.command_execute ch end end |
.last_search ⇒ Object
1408 1409 1410 1411 1412 1413 1414 1415 |
# File 'lib/xiki/search.rb', line 1408 def self.last_search begin $el.nth 0, $el.elvar.search_ring.to_a rescue Exception=>e View.beep return "- weird stuff in search ring!" end end |
.launched(bm = nil) ⇒ Object
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/xiki/search.rb', line 491 def self.launched bm=nil txt = File.read @@log txt = txt.sub(/\A- /, '').split(/^- /).reverse.uniq if bm && bm == "#" txt = txt.select{|o| o =~ /^ - ##/} elsif bm && bm == ":" txt = txt.select{|o| o =~ /^ - [^#].*: /} elsif bm path = Bookmarks[bm] if File.file? path # File regex = /^#{Regexp.escape File.dirname path}\/\n - #{Regexp.escape File.basename path}/ else # Dir regex = /^#{Regexp.escape path}/ path = "#{path}/" if path !~ /\/$/ end txt = txt.select{|o| o =~ regex} end result = "- @#{txt.join("- @")}" result end |
.left ⇒ Object
517 518 519 |
# File 'lib/xiki/search.rb', line 517 def self.left $el.match_beginning 0 end |
.like_delete ⇒ Object
1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 |
# File 'lib/xiki/search.rb', line 1537 def self.like_delete match = self.stop line = View.line View.to_highest $el.delete_matching_lines match View.line = line end |
.log ⇒ Object
1381 1382 1383 |
# File 'lib/xiki/search.rb', line 1381 def self.log View.open @@log end |
.match(left = nil, right = nil) ⇒ Object
315 316 317 318 319 320 321 322 323 324 |
# File 'lib/xiki/search.rb', line 315 def self.match left=nil, right=nil left ||= self.left right ||= self.right return nil if left == 0# || self.nil? result = $el.buffer_substring(left, right) return nil if result == "" result end |
.menu ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/xiki/search.rb', line 15 def self. ' - .history/ - .log/ - .launched/ - docs/ | > Summary | You start a search by typing Control-s. Then type the search string. | Here are some interesting keys to type while searching, to do things | with the match. | | > What do we mean by "search_bookmark" etc.? | With all xiki keyboard shorcuts, you "type the acronym". | By the key shortcut "search_bookmark" we mean typing Control-s and then | Control-c. | | Of course, typing Control-s to search lets you type characters | to search for, so in some cases typing a search string in between makes | sense. So, search_clipboard actually means you would type Control-s then | some characters to search for then Control-c to copy to the clipboard. | | > Examples - examples/ | search_copy: Copy found to clipboard | search_bookmark: Search text of files in a dir | search_all: Show all previous searches | search_value: Insert found where search began | search_delete: Delete found | search_diffs (without searching): Search in diffs | search_todo: Search in $t bookmark | search_files: Search in $f bookmark | search_paths: Search history of menus - miscellaneous/ | search_search: Re-do the last search | search_word: Suck the next word in | search_yank: Suck the rest of the line in | search_usurp: Suck the next expression in | | For more details about Xiki keyboard shortcuts, see: - @keys/docs/ | - see/ <@ next/ ' end |
.move_to(path, match, options = {}) ⇒ Object
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 |
# File 'lib/xiki/search.rb', line 1339 def self.move_to path, match, ={} orig = Location.new = View. if path == "$t" # If $f, grab path also View.layout_todo :no_blink=>1 elsif path == "$f" # If $f, grab path also match = self.move_to_files match return orig.go if ! match # It handled it if it didn't return the match else View.open path end # Maybe extract to .insert_in_section ? View.to_highest line_occupied = ! Line.blank? Notes.to_block if [:append] View.insert match View.insert "\n" if line_occupied # Make room if line not blank # Add line after if before heading, unless match already had one View.insert "\n" if Line[/^>/] && match !~ /\n$/ # If there wasn't a linebreak at the end of the match line = View.line View.to_highest # Which case was this handling? Being in $f? Why leave cursor in $t when in $f? # return if path == "$t" && was_in_bar && orig.buffer != "todo.notes" orig.go if path == "$t" && orig.buffer == "todo.notes" Line.next line-1 View.column = orig.column end end |
.move_to_files(match) ⇒ Object
1310 1311 1312 1313 1314 1315 1316 |
# File 'lib/xiki/search.rb', line 1310 def self.move_to_files match match_with_path = FileTree.snippet :txt=>match match_with_path = ">\n- #{match_with_path}" result = self.fit_in_snippet match result ? nil : match_with_path end |
.move_to_search_start(match) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/xiki/search.rb', line 122 def self.move_to_search_start match was_reverse = self.was_reverse View.delete(Search.left, Search.right) deleted = View.cursor self.to_start # Go back to start Move.backward match.length if was_reverse # If reverse, move back width of thing deleted View.insert match # Save spot where it was deleted (must do after modification, for bookmark to work) View.cursor = deleted Move.forward(match.length) unless was_reverse Location.as_spot('killed') self.to_start # Go back to start Move.forward(match.length) unless was_reverse end |
.open_file_and_method(match) ⇒ Object
Jumps to the file corresponding to a string. The string has no path - the edited history (and visited history?) are used to find the file.
If the string is like “Foo.bar” it jumps to the method as well (“foo”).
> Examples Search.open_file_and_method “View” Search.open_file_and_method “View.path”
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 |
# File 'lib/xiki/search.rb', line 659 def self.open_file_and_method match match.sub!(/^[+-] /, '') match.sub!(/ .+/, '') if match =~ /(.+)[.#](.+)/ match, method = $1, $2 # split off, and open end # Convert to snake case, or nil if already in snake case snake = TextUtil.snake_case(match) snake = nil if snake == match match = "#{match}." snake = "#{snake}." # For each file edited found = (Files.edited_array + Files.history_array).find do |o| next if o =~ /.notes$/ # Ignore notes files next if o =~ /:/ # Ignore files with colons (tramp) name = o[/.*\/(.*)/, 1] # Strip off path # Check for match if name =~ /^#{Regexp.quote(match)}/i || (snake && name =~ /^#{Regexp.quote(snake)}/i) o else false end end if found # Open it if it matches View.open found if method # If method, go to it View.to_highest result = Search.forward "^ +def \\(self\\.\\)?#{method}[^_a-zA-Z0-9]", :beginning=>true return Code.suggest_creating_method View.file, method if !result # If not found, suggest creating Move.to_axis $el.recenter 0 dir, name = found.match(/(.+\/)(.+)/)[1..2] Search.append_log dir, "- #{name}\n | #{Line.value}" end else View. "'#{match}' not found (no recently edited file with that substring found)." end return end |
.outline ⇒ Object
819 820 821 822 823 824 825 |
# File 'lib/xiki/search.rb', line 819 def self.outline if Keys.prefix_u? History.open_current :outline => true, :prompt_for_bookmark => true else History.open_current :outline => true end end |
.outline_goto_once ⇒ Object
1437 |
# File 'lib/xiki/search.rb', line 1437 def self.outline_goto_once; @@outline_goto_once; end |
.outline_goto_once=(txt) ⇒ Object
1438 |
# File 'lib/xiki/search.rb', line 1438 def self.outline_goto_once= txt; @@outline_goto_once = txt; end |
.outline_search ⇒ Object
827 828 829 830 831 832 833 |
# File 'lib/xiki/search.rb', line 827 def self.outline_search if Keys.prefix_u? History.open_current :bar=>true, :all=>true else History.open_current :all=>true end end |
.query_replace(s1 = nil, s2 = nil) ⇒ Object
Do query replace depending on what they type
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/xiki/search.rb', line 331 def self.query_replace s1=nil, s2=nil if s1 && s2 # If manually passed in $el.query_replace_regexp($el.regexp_quote(s1 || ""), s2 || "") return end first = Keys.input(:timed=>true) # If they typed 'o', use clipboard 1 and clipboard 2 if first == "o" || first == "1" $el.query_replace_regexp($el.regexp_quote(Clipboard.get("1")), Clipboard.get("2")) # If they typed 't', use clipboard 2 and clipboard 1 elsif first == "t" || first == "2" $el.query_replace_regexp(Clipboard.get("2"), Clipboard.get("1")) # If 'q', prompt for both args elsif first == "q" $el.query_replace_regexp( Keys.input(:prompt=>"Replace: "), Keys.input(:prompt=>"With: ")) # If they typed 'c', use clipboard and prompt for 2nd arg elsif first == "c" $el.query_replace_regexp(Clipboard.get, Keys.input(:prompt=>"Replace with (pause when done): ", :timed=>true)) # If they typed 'c', use clipboard and prompt for 2nd arg elsif first == "l" $el.query_replace_regexp(@@query_from, @@query_to) # Otherwise, just get more input and use it else $el.query_replace_regexp(first, Keys.input(:timed=>true)) end nil end |
.query_replace_nth(n1, n2) ⇒ Object
Query replaces from “1” clipboard to “2” clipboard, etc.
Search.query_replace_nth “1”, “2”
1561 1562 1563 1564 1565 1566 1567 1568 1569 |
# File 'lib/xiki/search.rb', line 1561 def self.query_replace_nth n1, n2 if Keys.up? # If up+, grab line from last diff a, b = DiffLog.last_intraline_diff return Search.query_replace a, b end Search.query_replace Clipboard.get(n1), Clipboard.get(n2) end |
.right ⇒ Object
521 522 523 |
# File 'lib/xiki/search.rb', line 521 def self.right $el.match_end 0 end |
.search_at_root(txt) ⇒ Object
Go to root of tree and do search
930 931 932 933 934 935 936 937 938 939 |
# File 'lib/xiki/search.rb', line 930 def self.search_at_root txt Search.backward("^ *[+-] /") # If next line isn't ##... line (will be visually distinct) add linebreak unless Line.value(2) =~ /^ *[+-] ##/ Line.next View.insert "\n" Line.previous 2 end self.enter_search '.', txt end |
.search_in_bookmark(match) ⇒ Object
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/xiki/search.rb', line 446 def self.search_in_bookmark match bm = Keys.bookmark_as_path :include_file=>1 if bm == :slash # If space, go back to root and search # Make match be orange Overlay.face(:ls_search, :left=>self.left, :right=>self.right) self.search_at_root match return end View. if View. if bm == :space # If space, search in buffers self.find_in_buffers match return end match.gsub!(/([#()*+?^$\[\]|.])/, "\\\\\\1") match.gsub! "\\+", "." # Change + to . to help when searching for key shortcuts # Search in bookmark FileTree.grep_with_hashes bm, match end |
.search_last_launched ⇒ Object
485 486 487 488 489 |
# File 'lib/xiki/search.rb', line 485 def self.search_last_launched match = self.stop Launcher.open Launcher. end |
.search_thesaurus ⇒ Object
802 803 804 805 806 807 |
# File 'lib/xiki/search.rb', line 802 def self.search_thesaurus term = self.stop url = term.sub(/^\s+/, '').gsub('"', '%22').gsub(':', '%3A').gsub(' ', '%20') $el.browse_url "http://thesaurus.reference.com/browse/#{url}" end |
.searches ⇒ Object
1400 1401 1402 1403 1404 1405 1406 |
# File 'lib/xiki/search.rb', line 1400 def self.searches begin $el.elvar.search_ring.to_a rescue Exception=>e ["error getting searches, probably because of special char :("] end end |
.stop(options = {}) ⇒ Object
Clears the isearch, allowing for inserting, or whatever else
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/xiki/search.rb', line 290 def self.stop ={} left, right = self.left, self.right txt = self.match(left, right)# if options[:match] # Make it do special clear if nothing found (to avoid weird isearch error) if txt.nil? if $el.elvar.isearch_success # || Search.left == View.bottom # Done so isearch_done won't error $el.isearch_resume "[^`]", true, nil, true, "", true View. "" else txt = :not_found end end $el.elvar.isearch_mode = nil $el. $el.isearch_done txt == :not_found ? Search.last_search : txt end |
.subtract ⇒ Object
472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'lib/xiki/search.rb', line 472 def self.subtract match = self.match if match # If currently searching return $el.isearch_del_char end View. "Unused!", :beep=>1 self.stop self.search_last_launched end |
.to(find) ⇒ Object
767 768 769 770 771 772 773 774 775 776 777 |
# File 'lib/xiki/search.rb', line 767 def self.to find Move.forward if Search.forward(find) match = $el.buffer_substring self.left, self.right Move.backward(match.size) else $el.beep $el. "not found" Move.backward end end |
.to_left ⇒ Object
1044 1045 1046 1047 1048 1049 1050 1051 |
# File 'lib/xiki/search.rb', line 1044 def self.to_left match = self.stop if match.nil? # If nothing searched for yet return Launcher.open "- search/.history/", :bar_is_fine=>1 end Line.to_left end |
.to_start ⇒ Object
326 327 328 |
# File 'lib/xiki/search.rb', line 326 def self.to_start View.to($el.elvar.isearch_opoint) end |
.tree_grep ⇒ Object
prefix=nil
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/xiki/search.rb', line 389 def self.tree_grep # prefix=nil prefix = Keys.isearch_prefix path = Keys.bookmark_as_path :include_file=>1 # Get path (from bookmark) # If C-u, just jump to bookmark and search from the top if prefix == :u View.open path View.to_highest Search.isearch return end if path == :space # If space, search in buffers self.find_in_buffers Keys.input(:prompt=>"Search all open files for: ") return end input = Keys.input(:prompt=>"Text to search for: ") input.gsub! "#", "\\#" FileTree.grep_with_hashes path, input end |
.upcase ⇒ Object
835 836 837 838 |
# File 'lib/xiki/search.rb', line 835 def self.upcase self.stop $el.upcase_region(self.left, self.right) end |
.was_reverse ⇒ Object
1250 1251 1252 |
# File 'lib/xiki/search.rb', line 1250 def self.was_reverse ! $el.elvar.isearch_forward end |
.xiki ⇒ Object
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 |
# File 'lib/xiki/search.rb', line 1108 def self.xiki match = self.stop View.beep "- Don't know what to do when search+x with search match." if match char = Keys.input(:chars=>1, :prompt=>"Enter one char: ") if char == "m" Launcher.open("- #{Xiki.dir}\n - ##\\bdef /") elsif char == "k" Launcher.open("- $x/key_bindings.rb\n - ##\\bKeys\\./") elsif char == "l" Launcher.open("- $ttm\n - ##xiki|isearch/") else View.beep "Don't know what to do with that char." end end |
.zap ⇒ Object
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 |
# File 'lib/xiki/search.rb', line 1093 def self.zap match = self.stop if match.nil? # If nothing searched for yet char = Keys.input(:chars=>1, :prompt=>"Enter one char: ") block = self.zap_hooks[char] return View.beep "- search+zap+#{char}... doesn't seem to be defined!" if block.nil? return block.call end right = $el.point self.to_start # Go back to search start View.delete($el.point, right) end |
.zap_hooks ⇒ Object
To set a hook Search.zap_hooks ‘m’ do … end
1089 1090 1091 |
# File 'lib/xiki/search.rb', line 1089 def self.zap_hooks # key, &block @@zap_hooks#[key] = value end |