[DRE-commits] [ruby-org] 216/303: Slight code refactoring was done, which improves accumulating block contents.
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:34:00 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 3922887bc1db3b06cbb998380d7cefa39afbc989
Author: vonavi <ivvl82 at gmail.com>
Date: Fri Jan 4 22:23:44 2013 +0300
Slight code refactoring was done, which improves accumulating block contents.
---
lib/org-ruby/line.rb | 8 +++----
lib/org-ruby/output_buffer.rb | 51 ++++++++++++++++++++++-------------------
2 files changed, 31 insertions(+), 28 deletions(-)
diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb
index 2f7e469..272f6d7 100644
--- a/lib/org-ruby/line.rb
+++ b/lib/org-ruby/line.rb
@@ -262,13 +262,13 @@ module Orgmode
:table
when inline_example?
:inline_example
- when (begin_block? and block_type.casecmp("QUOTE") == 0)
+ when (block_type and block_type.casecmp("QUOTE") == 0)
:blockquote
- when (begin_block? and block_type.casecmp("CENTER") == 0)
+ when (block_type and block_type.casecmp("CENTER") == 0)
:center
- when (begin_block? and block_type.casecmp("EXAMPLE") == 0)
+ when (block_type and block_type.casecmp("EXAMPLE") == 0)
:example
- when (begin_block? and block_type.casecmp("SRC") == 0)
+ when (block_type and block_type.casecmp("SRC") == 0)
:src
end
end
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index 5978ac3..c8246c8 100644
--- a/lib/org-ruby/output_buffer.rb
+++ b/lib/org-ruby/output_buffer.rb
@@ -77,7 +77,7 @@ module Orgmode
@logger.debug "Looking at #{line.paragraph_type}(#{current_mode}) : #{line.to_s}"
# We try to get the lang from #+BEGIN_SRC blocks
@block_lang = line.block_lang if line.begin_block?
- if not should_accumulate_output?(line)
+ unless should_accumulate_output?(line)
flush!
maintain_mode_stack(line)
end
@@ -156,16 +156,15 @@ module Orgmode
return true if ((line.paragraph_type == :example_line) ^
(@output_type == :example_line))
# Boundary of begin...end block
- return true if (@output_type == :begin_block and
- not mode_is_code?(current_mode))
- return true if @output_type == :end_block
+ return true if (@output_type == :begin_block or
+ @output_type == :end_block)
end
def maintain_mode_stack(line)
- # Always close heading line
- pop_mode if mode_is_heading? current_mode
- # Always close paragraph mode
- pop_mode if current_mode == :paragraph
+ # Always close a heading line, paragraph and inline example
+ pop_mode if (mode_is_heading? current_mode or
+ current_mode == :paragraph or
+ current_mode == :inline_example)
if ((not line.paragraph_type == :blank) or
@output_type == :blank)
@@ -175,17 +174,14 @@ module Orgmode
pop_mode
end
while ((not @list_indent_stack.empty?) and
- @list_indent_stack.last == line.indent)
- if mode_is_block? current_mode
- # Special case: Only end-block line closes the block
- pop_mode if line.end_block?
- break
- elsif current_mode != line.major_mode # item can't close its major mode
- pop_mode
- else
- break
- end
+ @list_indent_stack.last == line.indent and
+ # item can't close its major mode
+ line.major_mode != current_mode and
+ # don't allow an arbitrary line to close block
+ (not mode_is_block? current_mode))
+ pop_mode
end
+
# Opens the major mode of line if it exists.
if line.major_mode
if (@list_indent_stack.empty? or
@@ -196,10 +192,14 @@ module Orgmode
# Open tag that precedes text immediately
if (@list_indent_stack.empty? or
@list_indent_stack.last <= line.indent)
- push_mode(line.paragraph_type, line.indent) unless line.begin_block?
+ push_mode(line.paragraph_type, line.indent) unless line.block_type
+ end
+
+ # Special case: Only end-block line closes the block
+ if mode_is_block? current_mode
+ pop_mode if (line.end_block? and
+ line.major_mode == current_mode)
end
- else # If blank line, close preceding paragraph or inline example
- pop_mode if current_mode == :paragraph or current_mode == :inline_example
end
end
@@ -211,11 +211,14 @@ module Orgmode
# output buffer.
def should_accumulate_output?(line)
# Special case: Assign mode if not yet done.
- return false if not current_mode
+ return false unless current_mode
# Special case: Handles accumulating block content
+ if mode_is_code? current_mode
+ return true unless (line.end_block? and
+ line.major_mode == current_mode)
+ end
return false if boundary_of_block?(line)
- return true if mode_is_code?(current_mode) and not line.end_block?
# Special case: Don't accumulate headings, comments and horizontal rules.
return false if (mode_is_heading?(@output_type) or
@@ -228,7 +231,7 @@ module Orgmode
if line.paragraph_type == :paragraph
# Paragraph gets accumulated only if its indent level is
# greater than the indent level of the previous mode.
- if (@mode_stack[-2] and not mode_is_block? @mode_stack[-2])
+ if @mode_stack[-2] and not mode_is_block? @mode_stack[-2]
return false if line.indent <= @list_indent_stack[-2]
end
# Special case: Multiple "paragraphs" get accumulated.
--
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