Method: Tree.construct_path

Defined in:
lib/xiki/tree.rb

.construct_path(options = {}) ⇒ Object

Mapped to Enter when on a FileTree buffer. Opens file cursor is on in the tree. It assumes the path to a dir is on the current line.



740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
# File 'lib/xiki/tree.rb', line 740

def self.construct_path options={}
  begin
    path = []
    orig = $el.point

    # Do until we're at a root
    line = Line.value
    clean = self.clean_path line
    while(line =~ /^ / && (options[:all] || clean !~ /^@/))
      line =~ /^  ( *)(.*)/
      spaces, item = $1, $2
      item = clean unless options[:raw]   # Removes labels, ##..., **...
      if item != ""   # If item wasn't completely cleaned away
        path.unshift item  # Add item to list
      end
      $el.search_backward_regexp "^#{spaces}[^\t \n]"

      # If ignoring Ol lines, keep searching until not on one
      if options[:ignore_ol]
        while Line =~ /^[# ]*Ol\b/
          $el.search_backward_regexp "^#{spaces}[^\t \n]"
        end
      end

      line = Line.value
      clean = self.clean_path line
    end
    # Add root of tree
    root = Line.value.sub(/^ +/, '')
    root = self.clean_path(root) unless options[:raw]
    root.slice! /^@ ?/
    path.unshift root

    last = path.length - 1
    path = path.map_with_index{|o, i|
      next o if i == last   # Don't add slash to last
      o =~ /\/$/ ? o : "#{o}/"
    } if options[:slashes]

    $el.goto_char orig
    if options[:indented]
      indentify_path path
    elsif options[:list]
      path
    else
      path.join
    end
  rescue Exception=>e
    raise ".construct_path couldn't construct the path - is this a well-formed tree\?: #{e}"
  end
end