Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # -*- coding: ascii-8bit -*-
- #
- # Converts Taskpaper files to Emacs org-mode files.
- #
- # Author: Anupam Sengupta, 2010
- #
- # Distributed under the BSD license (<a href="http://www.opensource.org/licenses/bsd-license.php">http://www.opensource.org/licenses/bsd-license.php</a>)
- #
- # Usage: From the command line, enter the command:
- #
- # ./tpaper2org.rb <taskpaperfilename>
- #
- # The output is on STDOUT, which can be redirected to an Org-mode file.
- # Whether the generated org-mode file should use odd-level prefix stars
- # See <a href="http://orgmode.org/manual/Clean-view.html">http://orgmode.org/manual/Clean-view.html</a> for details.
- ORG_USES_ODD_LEVELS = false
- LINE_PATTERN = /^(\t*) # Leading tabs
- - # Followed by a dash (the taskpaper task identifier)
- (.*?) # The task description
- ((@\w+\s*)*) # The tags, if any
- $/x
- all_tags = Hash.new(0)
- Shiftlvl = ORG_USES_ODD_LEVELS ? 2 : 1 # Determine the number of stars to use in Org-mode entries
- while (line = gets());
- line.chomp!
- md = LINE_PATTERN.match(line) # Match and extract each line
- if md then # ................ A Task line
- tags = md[3].split(/ +/).reject {|tag| "@done" == tag } # get the tags, except @done tags
- tags = ['', tags, ''].flatten unless tags.empty?
- puts '*' * (1 + Shiftlvl * (md[1].length + 1)) + (line =~ /@done/ ? " DONE" : " TODO") + md[2] + tags.join(':')
- tags.each { |tag| all_tags[tag] += 1} if tags # Keep a list of all tags
- elsif line =~/:$/ # ................ A project line
- print "* "
- puts line.chomp(":")
- else # ................ Any other line
- puts line
- end
- end
- # Lets do a summary of the tags used.
- puts <<END
- # The tags used till now.
- #+TAGS:#{all_tags.keys.sort.join(' ')}
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement