Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Script to Combine new_note() and new_templated_note() #270

Open
1 task done
thw26 opened this issue Jul 7, 2023 · 2 comments
Open
1 task done

A Script to Combine new_note() and new_templated_note() #270

thw26 opened this issue Jul 7, 2023 · 2 comments
Assignees

Comments

@thw26
Copy link
Contributor

thw26 commented Jul 7, 2023

Please confirm

  • I am running the latest version of this plugin

Tell us about what's bothering you...
While I understand having two different functions for creating a note, that means I need to memorize two keymaps! I created this function to give me a menu for creating a new note:

local Menu = require("nui.menu")
local event = require("nui.utils.autocmd").event
local telekasten = require("plugins.telekasten")

local menu = Menu({
  position = "50%",
  size = {
    width = 25,
    height = 5,
  },
  border = {
    style = "single",
    text = {
      top = "[ Create New Note ]",
      top_align = "center",
    },
  },
  win_options = {
    winhighlight = "Normal:Normal,FloatBorder:Normal",
  },
}, {
  lines = {
    Menu.item("New Blank Note", { id = 1 }),
    Menu.item("New Templated Note", { id = 2 }),
    Menu.item("Quit", { id = 3 }),
  },
  max_width = 20,
  keymap = {
    focus_next = { "j", "<Down>", "<Tab>" },
    focus_prev = { "k", "<Up>", "<S-Tab>" },
    close = { "<Esc>", "<C-c>" },
    submit = { "<CR>", "<Space>" },
  },
  on_close = function()
    print("Menu Closed.")
  end,
  on_submit = function(item)
    if item.id == 1 then
      vim.cmd([[Telekasten new_note]])
    elseif item.id == 2 then
      vim.cmd([[Telekasten new_templated_note]])
    else
      print("Menu Closed.")
    end
  end,
})

-- mount the component
menu:mount()

I saved it in ~/.config/nvim/lua/functions/createNewNote.lua and then mapped it to the following:

map("n", "<C-n>", "<cmd>luafile ~/.config/nvim/lua/functions/createNewNote.lua<CR>", { desc = "Create new note" })

Would you be interested in having this added to the wiki or somewhere else?

@thw26 thw26 changed the title Combine Create New Note and Create Templated Note A Script to Combine Create New Note and Create Templated Note Jul 7, 2023
@thw26 thw26 changed the title A Script to Combine Create New Note and Create Templated Note A Script to Combine new_note() and new_templated_note() Jul 7, 2023
@lambtho12
Copy link
Member

I am not sure I understand the purpose of that. If you are going to use a menu and require one more input before actually create the note, can't you just use new_templated_note in all cases and select the appropriate template when you just want to create a note?


In any case, once the code is a bit more refactored, I will completely rework the various function/pickers to simplify them and make them more versatile. Ideally, everything could be done by 3/4 pickers. We could then provide aliases to tailor the arguments of the picker functions automatically or just let the user specify their mappings as they want.

@thw26
Copy link
Contributor Author

thw26 commented Aug 2, 2023

I am not sure I understand the purpose of that. If you are going to use a menu and require one more input before actually create the note, can't you just use new_templated_note in all cases and select the appropriate template when you just want to create a note?

Yes, but then I need a template for a blank file. I see your point though; a blank template would accomplish the same thing and remove the need for an extra menu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants