GithubHelp home page GithubHelp logo

Comments (9)

is0n avatar is0n commented on July 4, 2024

Try using this:

require('fm-nvim').setup{
	on_close = {
		function()
			vim.cmd [[ checktime ]]
		end
	},
}

from fm-nvim.

piersolenski avatar piersolenski commented on July 4, 2024

Hmm, what exactly should this be doing - reloading the file? I added it but it doesn't seem to do anything...

I guess the exact behaviour I'm looking for is that of https://github.com/tpope/vim-eunuch when you :Delete or :Rename a file.

from fm-nvim.

is0n avatar is0n commented on July 4, 2024

:checkt[ime] Check if any buffers were changed outside of Vim.
This checks and warns you if you would end up with two
versions of a file.
If this is called from an autocommand, a ":global"
command or is not typed the actual check is postponed
until a moment the side effects (reloading the file)
would be harmless.
Each loaded buffer is checked for its associated file
being changed. If the file was changed Vim will take
action. If there are no changes in the buffer and
'autoread' is set, the buffer is reloaded. Otherwise,
you are offered the choice of reloading the file. If
the file was deleted you get an error message.
If the file previously didn't exist you get a warning
if it exists now.
Once a file has been checked the timestamp is reset,
you will not be warned again.
Syntax highlighting, marks, diff status,
'fileencoding', 'fileformat' and 'binary' options
are not changed. See |v:fcs_choice| to reload these
too (for example, if a code formatting tools has
changed the file).

:checktime essentially checks if any changes were made to the current buffer. Running this when Lf closes should in theory warn you about the file not existing but it doesn't seem to work for me either. 🤔

I'll see what I can do later today.

from fm-nvim.

is0n avatar is0n commented on July 4, 2024

Not sure if this is what you wanted but now you will be warned if a file does not exist.

require('fm-nvim').setup{
  on_close = {
    function()
      vim.fn.expand("%")
    end
  }
}

from fm-nvim.

piersolenski avatar piersolenski commented on July 4, 2024

The more I use this library, the more I reckon updating the buffer applies to most of its integrations too.

For example, take any one of the git integrations, reset a hunk, and return to the buffer. Ideally, you shouldn't see the old hunk, you should see the updated changes in the buffer. Currently, you need to close and reopen the buffer to do so.

In this scenario, your vim.cmd [[ checktime ]] does the job... would it be worth making that default behaviour?

I guess it won't work in regards to my original query around deleting or renaming a file, as the file is now different... so maybe that's almost a separate issue, maybe outside the scope of the plugin and would need some LF specific code.

from fm-nvim.

is0n avatar is0n commented on July 4, 2024

In this scenario, your vim.cmd [[ checktime ]] does the job... would it be worth making that default behaviour?

Seems like a great idea!

I guess it won't work in regards to my original query around deleting or renaming a file, as the file is now different... so maybe that's almost a separate issue, maybe outside the scope of the plugin and would need some LF specific code.

If you want to be notified when you're working with a deleted/renamed file, you can use the code from my last comment.

On the other hand, if you want to edit the newly renamed file after quitting from lf, you could create a command in your lfrc that renames the selected file (at it normally would) and writes the new file's path to some temp file. Then in the on_close option, check if the temp file exists and then read from it.

from fm-nvim.

piersolenski avatar piersolenski commented on July 4, 2024

I guess it would also need to close the buffer with the old file name too? The most simple plugin I can think of that already does this is Tim Pope's Eunuch with the rename function:

https://github.com/tpope/vim-eunuch/blob/master/plugin/eunuch.vim#L37

But yeah, this feels like two different issues now, one perhaps within the scope of fm-nvim and one a bit more outside of it!

from fm-nvim.

is0n avatar is0n commented on July 4, 2024

I think I get what you're getting at now. The following code should do the trick!

lfrc:

cmd mv ${{
  mv "$f" "$1"
  echo "$(readlink -f $1)" > /tmp/lf_renamed
}}

init.lua

local function Rename()
  local temp = "/tmp/lf_renamed"
  local file = io.open(temp, "r")
  if file ~= nil then
    vim.cmd("bdelete!")
    vim.cmd("edit " .. vim.fn.readfile(temp)[1])
    io.close(file)
    os.remove(temp)
  end
end

local function Delete()
  local file = vim.fn.expand("%:p")
  if io.open(file, "r") == nil then
    vim.cmd("bdelete!")
  end
end

require('fm-nvim').setup{
  on_close = {
    Rename,
    Delete
  }
}

from fm-nvim.

piersolenski avatar piersolenski commented on July 4, 2024

Ah this awesome! Thank you so much! Guess we can close this now 😀🎆

from fm-nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.