Giter VIP home page Giter VIP logo

Comments (3)

latipun7 avatar latipun7 commented on July 21, 2024 3

These callbacks are for showing notify window when loading session via telescope as suggested in #24, also clearing all buffers before loading session.

Callbacks Example
    telescope = {
      before_source = function()
        local status_ok, _ = pcall(require, "bufdelete")
        if status_ok then
          vim.api.nvim_input("<Esc><Cmd>bufdo Bdelete<CR>")
        else
          vim.api.nvim_input("<Esc><Cmd>%bd<CR>")
        end
      end,
      after_source = function(session)
        vim.defer_fn(function()
          local status_ok, notify = pcall(require, "notify")
          if status_ok then
            notify(
              "Loaded session " .. session.name,
              vim.log.levels.INFO,
              { title = title }
            )
          else
            print("Loaded session " .. session.name)
          end
        end, 0)
      end,
    },

from persisted.nvim.

okuuva avatar okuuva commented on July 21, 2024 2

These callbacks are for showing notify window when loading session via telescope as suggested in #24, also clearing all buffers before loading session.

Just wanted to point out that you could use just plain vim.notify() instead of pcalling notify in the after_source function. I think that notify users are gonna override the defaut notify-function as the notify readme suggest setting vim.notify = require("notify").

Here's the one I use for both regular and telescope after_source leveraging the aforementioned trick:

Allpurpose `after_source` example
local after_source = function(session)
  local message = "Autoloaded session"
  if session then
    message = "Loaded session " .. session.name
  end

  vim.defer_fn(function()
    vim.notify(message, vim.log.levels.INFO, { title = "Session manager" })
  end, 0)
end

from persisted.nvim.

iujakchu avatar iujakchu commented on July 21, 2024 2

jump between sessions smoothly using telescope and do not autosave when dirpath starts with /tmp:

callback snippet #40
should_autosave = function()                                                 
    local path = vim.fn.expand "%:p"                                         
    if vim.bo.filetype == "alpha" or string.find(path, "/tmp") == 1 then     
        return false                                                         
    else                                                                     
        return true                                                          
    end                                                                      
end,                                                                         
                                                                    
telescope = {                          
    -- jump between session smoothly                                         
    after_source = function(param)                                           
        vim.api.nvim_command "%bd"                                           
        local path = param.dir_path                                                                                                    
        if string.find(path, "/") ~= 1 then                                  
            vim.api.nvim_command("cd " .. vim.fn.expand "~" .. "/" .. path)  
            vim.api.nvim_command("tcd " .. vim.fn.expand "~" .. "/" .. path) 
        else                                                                 
            vim.api.nvim_command("cd " .. path)                              
            vim.api.nvim_command("tcd " .. path)                             
        end                                                                  
    end,                                                                     
},                                                                           

from persisted.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.