simplenote-vim / simplenote.vim

vim plugin to interact with the simplenote service
http://www.vim.org/scripts/script.php?script_id=3582
MIT License
368 stars 31 forks source link

"markdown" filetype gets overridden by "conf" filetype on Ubuntu 12.04 #59

Closed amontalenti closed 10 years ago

amontalenti commented 10 years ago

Even though I set

let g:SimplenoteFiletype = "markdown"

When I open notes that are Markdown-formatted and that start with a line like this:

# Some Title

Some text

My vim filetype will be set to conf. I wondered why this might be; it turns out it's because vim has some logic in the system filetype detection that if it sees a file with a leading "#" as its first char, it'll guess the "configuration" filetype. This is revealed with this:

:verbose set ft?
  filetype=conf
        Last set from /usr/share/vim/vim73/filetype.vim

The solution I came up with is slightly dramatic -- I changed the plugin to give the scratch buffers the name <simplenote-id>.md. This would cause my filetype.vim logic to kick in based on file extension, which would force the setting of filetype=markdown. There is probably a better way to fix this, but my vim-plugin-fu is a little weak so I am looking to you for some better ideas.

diff --git a/autoload/simplenote.vim b/autoload/simplenote.vim
index daf67f7..cd49bb0 100644
--- a/autoload/simplenote.vim
+++ b/autoload/simplenote.vim
@@ -175,11 +175,12 @@ class SimplenoteVimInterface(object):
     def get_current_note(self):
     """ returns the key of the currently edited note """
     key = vim.eval("expand('%:t')")
+    key = key.replace('.md', '')
     return key

     def set_current_note(self, key):
     """ sets the key of the currently edited note """
-        vim.command(""" silent exe "file %s" """ % key)
+        vim.command(""" silent exe "file %s.md" """ % key)

     def transform_to_scratchbuffer(self):
     """ transforms the current buffer into a scratchbuffer """

Cheers on a great plugin, BTW!

atomicules commented 10 years ago

Hi. Sorry for the delay in replying. I can't reproduce this on NetBSD (which is what I'm on currently). Which platform are you on?

Did you know that Simplenote.vim now respects the markdown flag in Simplenote? For example if you set as markdown in the web interface and then open via Simplenote.vim it will open with filetype=markdown. You could then unset this in vim (:set filetype=txt) and update via Simplenote.vim (:Simplenote -u) and the markdown flag will have been removed in the web interface.

We could think about using the presence of the g:SimplenoteFiletype = "markdown" setting to ensure the markdown flag is set in Simplenote for new notes created and notes updated via Simplenote.vim

amontalenti commented 10 years ago

I'm on Ubuntu 12.04 LTS (Linux).

When you say, "did you know Simplenote.vim now respects the markdown flag in Simplenote", now as of when? I just installed the plugin last week.

atomicules commented 10 years ago

Sorry (again) missed the second part of your comment. If you've installed it from here (i.e. via git) then it has been there from quite some time (since September/December 2013). If you've installed from Vimscripts then it won't have that functionality (that's stuck on the 0.7.0 release).

atomicules commented 10 years ago

Ok, so I think I've just been affected by this. Recently been setting Gvim up on Windows and it seems to suffer from this issue as well.

I don't think it is just because of Gvim though; I'm pretty sure I never saw this on Arch Linux with Gvim; On NetBSD I only use (terminal) vim.

I'll have a think about a better way of fixing this.

atomicules commented 10 years ago

Hi. I think this problem is to do with doautocmd BufReadPost which was introduced recently.

I've only investigated on opening new notes so far, but changing the order of these lines:

    if note.has_key("systemtags"):
        if ("markdown" in note["systemtags"]):
            vim.command("setlocal filetype=markdown")
    vim.command("setlocal nomodified")
    vim.command("doautocmd BufReadPost")

to this:

    vim.command("setlocal nomodified")
    vim.command("doautocmd BufReadPost")
    if note.has_key("systemtags"):
        if ("markdown" in note["systemtags"]):
            vim.command("setlocal filetype=markdown")

Seems to do the trick at least as far as the auto-detection of the markdown flag in simplenote. I'll carry on looking into this (for the use case of g:SimplenoteFiletype) and update here when done.

atomicules commented 10 years ago

That fixes it as far as I can tell from my testing, but please let me know if you are still having issues.

Thanks for reporting it as well and sorry for the delay in being able to reproduce it.