[DRE-commits] [ruby-org] 88/303: Makes comment support compatible with org-mode: Only lines beginning with a # are comments. And begin_block/end_block are not comments (they can have spaces in front).

Jérémy Bobbio lunar at alioth.debian.org
Fri Aug 9 17:33:33 UTC 2013


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository ruby-org.

commit 5e7014914ea76878f997f395649cf70e050ab6bf
Author: Rüdiger Sonderfeld <ruediger at c-plusplus.de>
Date:   Wed Jul 20 16:52:56 2011 +0200

    Makes comment support compatible with org-mode: Only lines beginning with a # are comments. And begin_block/end_block are not comments (they can have spaces in front).
---
 lib/org-ruby/line.rb   |    6 ++++--
 lib/org-ruby/parser.rb |   26 ++++++++++++--------------
 spec/line_spec.rb      |    4 +---
 3 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb
index fe18ad2..5f64ec6 100644
--- a/lib/org-ruby/line.rb
+++ b/lib/org-ruby/line.rb
@@ -36,7 +36,7 @@ module Orgmode
 
     # Tests if a line is a comment.
     def comment?
-      check_assignment_or_regexp(:comment, /^\s*#/)
+      check_assignment_or_regexp(:comment, /^#/) and not begin_block? and not end_block?
     end
 
     # Tests if a line contains metadata instead of actual content.
@@ -45,7 +45,7 @@ module Orgmode
     end
 
     def nonprinting?
-      comment? || metadata?
+      comment? || metadata? || begin_block? || end_block?
     end
 
     def blank?
@@ -165,6 +165,8 @@ module Orgmode
       return :ordered_list if ordered_list?
       return :unordered_list if unordered_list?
       return :metadata if metadata?
+      return :begin_block if begin_block?
+      return :end_block if end_block?
       return :comment if comment?
       return :table_separator if table_separator?
       return :table_row if table_row?
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index 719c91e..ee4b038 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -199,23 +199,21 @@ module Orgmode
         output_buffer.prepare(line)
 
         case line.paragraph_type
-        when :metadata, :table_separator, :blank
+        when :metadata, :table_separator, :blank, :comment
 
           output_buffer << line.line if output_buffer.preserve_whitespace?          
 
-        when :comment
-          
-          if line.begin_block?
-            output_buffer.push_mode(:blockquote) if line.block_type.casecmp("QUOTE") == 0
-            output_buffer.push_mode(:src) if line.block_type.casecmp("SRC") == 0
-            output_buffer.push_mode(:example) if line.block_type.casecmp("EXAMPLE") == 0
-          elsif line.end_block?
-            output_buffer.pop_mode(:blockquote) if line.block_type.casecmp("QUOTE")==0
-            output_buffer.pop_mode(:src) if line.block_type.casecmp("SRC")==0
-            output_buffer.pop_mode(:example) if line.block_type.casecmp("EXAMPLE")==0
-          else
-            output_buffer << line.line if output_buffer.preserve_whitespace?
-          end
+        when :begin_block
+
+          output_buffer.push_mode(:blockquote) if line.block_type.casecmp("QUOTE") == 0
+          output_buffer.push_mode(:src) if line.block_type.casecmp("SRC") == 0
+          output_buffer.push_mode(:example) if line.block_type.casecmp("EXAMPLE") == 0
+
+        when :end_block
+
+          output_buffer.pop_mode(:blockquote) if line.block_type.casecmp("QUOTE") == 0
+          output_buffer.pop_mode(:src) if line.block_type.casecmp("SRC") == 0
+          output_buffer.pop_mode(:example) if line.block_type.casecmp("EXAMPLE") == 0
 
         when :table_row, :table_header
 
diff --git a/spec/line_spec.rb b/spec/line_spec.rb
index 9faad61..c2babe1 100644
--- a/spec/line_spec.rb
+++ b/spec/line_spec.rb
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), %w[spec_helper])
 describe Orgmode::Line do
 
   it "should tell comments" do
-    comments = ["# hello", "#hello", "   #hello", "\t#hello\n"]
+    comments = ["# hello", "#hello" ]
     comments.each do |c|
       line = Orgmode::Line.new c
       line.comment?.should be_true
@@ -81,14 +81,12 @@ describe Orgmode::Line do
 
     begin_examples.each_key do |str|
       line = Orgmode::Line.new str
-      line.comment?.should be_true
       line.begin_block?.should be_true
       line.block_type.should eql(begin_examples[str])
     end
 
     end_examples.each_key do |str|
       line = Orgmode::Line.new str
-      line.comment?.should be_true
       line.end_block?.should be_true
       line.block_type.should eql(end_examples[str])
     end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-org.git



More information about the Pkg-ruby-extras-commits mailing list