Kungsgeten / yankpad

Paste snippets from an org-mode file
MIT License
216 stars 18 forks source link

unexpected indentation #13

Closed AnthonyDiGirolamo closed 8 years ago

AnthonyDiGirolamo commented 8 years ago

Thanks for the great package! I've been avoiding yasnippet because of the one snippet per file restriction. This fixes that perfectly.

I'm running into an issue with incorrect indentation when inserting snippets without yasnippets enabled. I'm not sure if it's my indentation settings or yankpad. Given the following yankpad.org

* ruby-mode
** if: if..end
   if $1
     unless run_code
       $0
     end
   end

And the test file:

def new_method_yasnippet_disabled
  if
end

def new_method_yasnippet_enabled
  if
end

When I run yankpad-expand with the cursor after each if I get the following with and without yas-minor-mode enabled respectively:

def new_method_yasnippet_enabled
  if 
    unless run_code

    end
  end

end

def new_method_yasnippet_disabled
  if $1
  unless run_code
    $0
  end
end

end

$1 and $0 not being there when yasnippet is disabled is expected. But the indentation for the next four lines after the initial if is off. They are all unindented one more level than expected. I can of course leave yasnippet installed to fix this but thought you may want to know anyway.

Kungsgeten commented 8 years ago

Thank you, very interesting! I'll look into it. Its strange that the indentation changed depending on if we're using Yasnippet or not.

Kungsgeten commented 8 years ago

I've done some debugging to figure out the differences. It seems like YASnippet uses a function called yas--indent after inserting the snippet text into the buffer, while Yankpad (without yas-minor-mode does not). If you mark the text inserted with yas-minor-mode disabled, and press tab, you will see that the result is the same as if you had yas-minor-mode enabled. It is also interesting if you try the same example but with fundamental-mode instead of ruby-mode.

I'll have to look more into the indentation mechanics of YASnippet and Emacs, in order to see how this should be handled in Yankpad.

Kungsgeten commented 8 years ago

I've pushed an update which should fix the issue. By default the snippets are indented (so your example should work), but you can disable that by adding a tag indent_nil to the snippet.