mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
fix #43 via template_handling option, #38 via new_note_location opt, #33 improvements (detecting dailies/weeklies in links)
This commit is contained in:
96
README.md
96
README.md
@@ -1,9 +1,18 @@
|
||||
<div align="center">
|
||||
|
||||
# .nvim
|
||||
|
||||
<!-- [](http://www.lua.org) -->
|
||||
<!-- [](https://neovim.io) -->
|
||||
[](http://www.lua.org)
|
||||
[](https://neovim.io)
|
||||
|
||||
</div>
|
||||
|
||||
A Neovim (lua) plugin for working with a text-based, markdown [zettelkasten](https://takesmartnotes.com/) / wiki and
|
||||
mixing it with a journal, based on [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim).
|
||||
|
||||
#### Highlights:
|
||||
#### Highlights
|
||||
|
||||
- Find notes by name, #tag, and daily, weekly notes by date
|
||||
- search within all notes
|
||||
@@ -20,7 +29,11 @@ mixing it with a journal, based on [telescope.nvim](https://github.com/nvim-tele
|
||||
- insert links to images
|
||||
- **image previews**, via extension _(Linux only)_
|
||||
|
||||
##### New features are being announced in the [discussions](https://github.com/renerocksai/telekasten.nvim/discussions)!
|
||||
<div align="center">
|
||||
|
||||
#### New features are being announced in the [discussions](https://github.com/renerocksai/telekasten.nvim/discussions)
|
||||
|
||||
</div>
|
||||
|
||||
---
|
||||
|
||||
@@ -54,7 +67,6 @@ This is the result of my first days of hacking neovim with lua (more features ha
|
||||
|
||||

|
||||
|
||||
|
||||
## Search-based navigation
|
||||
|
||||
Every navigation action, like following a link, is centered around a Telescope search: a Telescope search popup is
|
||||
@@ -63,6 +75,7 @@ linked note, you get a preview in Telescope and can decide if you actually want
|
||||
likely to show up more than one result, you can preview related notes immediately.
|
||||
|
||||
### The preview is a powerful feature
|
||||
|
||||
Leaving the opening of the note to Telescope, you can decide with one keypress whether you want to open the note in a
|
||||
split or in the current window - or if you've seen enough.
|
||||
|
||||
@@ -70,44 +83,42 @@ I find that pressing the enter key to confirm the search does not interrupt my f
|
||||
check the preview. I often get enough information from it alone so I don't actually have to "visit" every note in terms
|
||||
of being able to edit it.
|
||||
|
||||
|
||||
## Contents
|
||||
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
* [0. Install and setup](#0-install-and-setup)
|
||||
* [0.0 Prerequisites](#00-prerequisites)
|
||||
* [0.0.1 Telescope](#001-telescope)
|
||||
* [0.0.2 calendar-vim Plugin (optional)](#002-calendar-vim-plugin-optional)
|
||||
* [0.0.3 For pasting images: xclip (optional)](#003-for-pasting-images-xclip-optional)
|
||||
* [0.0.4 For image previews: telescope-media-files.nvim (optional)](#004-for-image-previews-telescope-media-filesnvim-optional)
|
||||
* [0.1 Install the plugin](#01-install-the-plugin)
|
||||
* [0.1.0 Other useful plugins](#010-other-useful-plugins)
|
||||
* [0.2 Configure telekasten.nvim](#02-configure-telekastennvim)
|
||||
* [0.3 Configure your own colors](#03-configure-your-own-colors)
|
||||
* [1. Get Help](#1-get-help)
|
||||
* [2. Use it](#2-use-it)
|
||||
* [2.0 Telekasten command](#20-telekasten-command)
|
||||
* [2.1 Telekasten command palette](#21-telekasten-command-palette)
|
||||
* [2.2 Telekasten lua functions](#22-telekasten-lua-functions)
|
||||
* [2.3 Link notation](#23-link-notation)
|
||||
* [2.4 Tag notation](#24-tag-notation)
|
||||
* [2.5 Note templates](#25-note-templates)
|
||||
* [2.5.1 Template files](#251-template-files)
|
||||
* [2.6 Using the calendar](#26-using-the-calendar)
|
||||
* [2.7 Using the telescope pickers](#27-using-the-telescope-pickers)
|
||||
* [3. Bind it](#3-bind-it)
|
||||
* [4. The hardcoded stuff](#4-the-hardcoded-stuff)
|
||||
- [0. Install and setup](#0-install-and-setup)
|
||||
- [0.0 Prerequisites](#00-prerequisites)
|
||||
- [0.0.1 Telescope](#001-telescope)
|
||||
- [0.0.2 calendar-vim Plugin (optional)](#002-calendar-vim-plugin-optional)
|
||||
- [0.0.3 For pasting images: xclip (optional)](#003-for-pasting-images-xclip-optional)
|
||||
- [0.0.4 For image previews: telescope-media-files.nvim (optional)](#004-for-image-previews-telescope-media-filesnvim-optional)
|
||||
- [0.1 Install the plugin](#01-install-the-plugin)
|
||||
- [0.1.0 Other useful plugins](#010-other-useful-plugins)
|
||||
- [0.2 Configure telekasten.nvim](#02-configure-telekastennvim)
|
||||
- [0.3 Configure your own colors](#03-configure-your-own-colors)
|
||||
- [1. Get Help](#1-get-help)
|
||||
- [2. Use it](#2-use-it)
|
||||
- [2.0 Telekasten command](#20-telekasten-command)
|
||||
- [2.1 Telekasten command palette](#21-telekasten-command-palette)
|
||||
- [2.2 Telekasten lua functions](#22-telekasten-lua-functions)
|
||||
- [2.3 Link notation](#23-link-notation)
|
||||
- [2.4 Tag notation](#24-tag-notation)
|
||||
- [2.5 Note templates](#25-note-templates)
|
||||
- [2.5.1 Template files](#251-template-files)
|
||||
- [2.6 Using the calendar](#26-using-the-calendar)
|
||||
- [2.7 Using the telescope pickers](#27-using-the-telescope-pickers)
|
||||
- [3. Bind it](#3-bind-it)
|
||||
- [4. The hardcoded stuff](#4-the-hardcoded-stuff)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## 0. Install and setup
|
||||
|
||||
|
||||
### 0.0 Prerequisites
|
||||
|
||||
#### 0.0.1 Telescope
|
||||
|
||||
Since this plugin uses [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim), you need to install it first.
|
||||
|
||||
[Neovim (v0.5.1)](https://github.com/neovim/neovim/releases/tag/v0.5.1) or the latest neovim nighly commit is required
|
||||
@@ -127,13 +138,14 @@ See below for installing and using it.
|
||||
---
|
||||
|
||||
#### 0.0.3 For pasting images: xclip (optional)
|
||||
|
||||
Telekasten.nvim supports pasting images from the clipboard. Currently, this is only implemented for systems that have
|
||||
the `xclip` utility installed.
|
||||
|
||||
On Ubuntu/Debian like systems:
|
||||
|
||||
```console
|
||||
$ sudo apt-get install xclip
|
||||
sudo apt-get install xclip
|
||||
```
|
||||
|
||||
---
|
||||
@@ -147,9 +159,9 @@ Telescope extension [telescope-media-files.nvim](https://github.com/nvim-telesco
|
||||
|
||||
This extension has its own list of prerequisites, of which I recommend (and use) the following:
|
||||
|
||||
* [Überzug](https://github.com/seebye/ueberzug) (required for image support)
|
||||
* [ffmpegthumbnailer](https://github.com/dirkvdb/ffmpegthumbnailer) (optional, for video preview support)
|
||||
* [pdftoppm](https://linux.die.net/man/1/pdftoppm) (optional, for pdf preview support)
|
||||
- [Überzug](https://github.com/seebye/ueberzug) (required for image support)
|
||||
- [ffmpegthumbnailer](https://github.com/dirkvdb/ffmpegthumbnailer) (optional, for video preview support)
|
||||
- [pdftoppm](https://linux.die.net/man/1/pdftoppm) (optional, for pdf preview support)
|
||||
|
||||
Here is a demo from the original authors of
|
||||
[telescope-media-files.nvim](https://github.com/nvim-telescope/telescope-media-files.nvim):
|
||||
@@ -159,6 +171,7 @@ Here is a demo from the original authors of
|
||||
---
|
||||
|
||||
### 0.1 Install the plugin
|
||||
|
||||
Install with your plugin manager of choice. Mine is [Vundle](https://github.com/VundleVim/Vundle.vim).
|
||||
|
||||
```vim
|
||||
@@ -182,6 +195,7 @@ Other plugins I find useful in my day-to-day zettelkasten work:
|
||||
- [telescope-media-files](https://github.com/nvim-telescope/telescope-media-files.nvim)
|
||||
|
||||
### 0.2 Configure telekasten.nvim
|
||||
|
||||
Somewhere in your vim config, put a snippet like this:
|
||||
|
||||
```lua
|
||||
@@ -262,6 +276,7 @@ require('telekasten').setup({
|
||||
})
|
||||
END
|
||||
```
|
||||
|
||||
| setting | description | example |
|
||||
| --- | --- | --- |
|
||||
| `home` | path to your zettelkasten folder (folder with markdown files) | ~/zettelkasten |
|
||||
@@ -303,7 +318,6 @@ END
|
||||
| | - `get_cursor`: floating popup window at cursor position ||
|
||||
| `subdirs_in_links` | include subdirs (if applicable) in generated (yanked, inserted) links| true |
|
||||
|
||||
|
||||
The calendar support has its own options, contained in `calendar_opts`:
|
||||
|
||||
| calendar setting | description | example |
|
||||
@@ -320,8 +334,8 @@ The calendar support has its own options, contained in `calendar_opts`:
|
||||
| | 'left-fit' : mark to the left of the day| |
|
||||
| | 'right' : mark to the right of the day| |
|
||||
|
||||
|
||||
### 0.3 Configure your own colors
|
||||
|
||||
Telekasten.nvim allows you to color your `[[links]]` and `#tags` by providing the following syntax groups:
|
||||
|
||||
- `tkLink` : the link title inside the brackets
|
||||
@@ -356,14 +370,16 @@ hi tkTagSep ctermfg=gray guifg=gray
|
||||
hi tkTag ctermfg=175 guifg=#d3869B
|
||||
```
|
||||
|
||||
|
||||
## 1. Get Help
|
||||
|
||||
Telekasten.nvim now comes with its own help file. So you can always:
|
||||
|
||||
```vim
|
||||
:h telekasten.nvim
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```vim
|
||||
:h telekasten.<TAB> " or whatever your completion key is there
|
||||
```
|
||||
@@ -450,8 +466,8 @@ This is what the popup looks like:
|
||||
|
||||

|
||||
|
||||
|
||||
### 2.2 Telekasten lua functions
|
||||
|
||||
The plugin defines the following functions:
|
||||
|
||||
- `new_note()` : prompts for title and creates new note by template, then shows it in Telescope
|
||||
@@ -603,7 +619,6 @@ is.
|
||||
**Note**: For proper highlighting, the `install_syntax` option is set to `true` by default. This automatically sets the
|
||||
syntax of filetype `markdown` to `telekasten`, and also registers this syntax with telescope previewers for `.md` files.
|
||||
|
||||
|
||||
### 2.5 Note templates
|
||||
|
||||
The functions `goto_today`, `goto_thisweek`, `find_daily_notes`, `find_weekly_notes`, and `follow_link` can create
|
||||
@@ -714,7 +729,6 @@ command in vim:
|
||||
:CalendarT
|
||||
```
|
||||
|
||||
|
||||
### 2.7 Using the telescope pickers
|
||||
|
||||
When you are prompted with a telescope picker to select a note or media file, the following mappings apply:
|
||||
@@ -728,9 +742,8 @@ When you are prompted with a telescope picker to select a note or media file, th
|
||||
- <kbd>RETURN / ENTER</kbd> : usually opens the selected note or performs the action defined by the called function
|
||||
- e.g. `insert_img_link()`'s action is to insert a link to the selected image.
|
||||
|
||||
|
||||
|
||||
## 3. Bind it
|
||||
|
||||
Usually, you would set up some key bindings, though:
|
||||
|
||||
```vim
|
||||
@@ -786,6 +799,7 @@ hi tkTag ctermfg=175 guifg=#d3869B
|
||||
## 4. The hardcoded stuff
|
||||
|
||||
Currently, the following things are hardcoded:
|
||||
|
||||
- the file naming format for daily note files: `YYYY-MM-DD.ext` (e.g. `2021-11-21.md`)
|
||||
- the file naming format for weekly note files: `YYYY-Www.ext` (e.g. `2021-W46.md`)
|
||||
- the file naming format for pasted images: `pasted_img_YYYYMMDDhhmmss.png` (e.g. `pasted_img_20211126041108.png`)
|
||||
|
||||
@@ -69,7 +69,7 @@ local rep = string.rep
|
||||
local len = string.len -- luacheck: ignore
|
||||
local sub = string.sub
|
||||
local gsub = string.gsub
|
||||
local gmatch = string.gmatch or string.gfind
|
||||
local gmatch = string.gmatch
|
||||
local find = string.find
|
||||
local ostime = os.time
|
||||
local osdate = os.date
|
||||
@@ -188,7 +188,7 @@ local function makedaynum(y, m, d)
|
||||
end
|
||||
-- date from day number, month is zero base
|
||||
local function breakdaynum(g)
|
||||
local g = g + 306
|
||||
g = g + 306
|
||||
local y = floor((10000 * g + 14780) / 3652425)
|
||||
local d = g - dayfromyear(y)
|
||||
if d < 0 then
|
||||
@@ -333,8 +333,8 @@ local function getequivyear(y)
|
||||
and yt[-6]
|
||||
and yt[-7]
|
||||
then
|
||||
getequivyear = function(y)
|
||||
return yt[(weekday(makedaynum(y, 0, 1)) + 1) * (isleapyear(y) and -1 or 1)]
|
||||
getequivyear = function(yy)
|
||||
return yt[(weekday(makedaynum(yy, 0, 1)) + 1) * (isleapyear(y) and -1 or 1)]
|
||||
end
|
||||
return getequivyear(y)
|
||||
end
|
||||
@@ -565,7 +565,8 @@ local function date_parse(str)
|
||||
elseif inlist(x, sl_timezone, 2, sw) then
|
||||
c = fix(sw[0]) -- ignore gmt and utc
|
||||
if c ~= 0 then
|
||||
setz(c, x)
|
||||
-- setz(c, x) -- wtf
|
||||
setz(c) -- better
|
||||
end
|
||||
elseif not inlist(x, sl_weekdays, 2, sw) then
|
||||
sw:back()
|
||||
@@ -668,7 +669,8 @@ local tmap = {
|
||||
}
|
||||
local function date_getdobj(v)
|
||||
local o, r = (tmap[type(v)] or fnil)(v)
|
||||
return (o and o:normalize() or error("invalid date time value")), r -- if r is true then o is a reference to a date obj
|
||||
return (o and o:normalize() or error("invalid date time value")), r
|
||||
-- if r is true then o is a reference to a date obj
|
||||
end
|
||||
--#end -- not DATE_OBJECT_AFX
|
||||
local function date_from(arg1, arg2, arg3, arg4, arg5, arg6, arg7)
|
||||
@@ -1038,7 +1040,7 @@ local tvspec = {
|
||||
return fmt("%s%.9f", x >= 10 and "" or "0", x)
|
||||
end,
|
||||
-- percent character %
|
||||
["%%"] = function(self)
|
||||
["%%"] = function(_)
|
||||
return "%"
|
||||
end,
|
||||
-- Group Spec --
|
||||
|
||||
@@ -68,6 +68,7 @@ M.date_from_doy = function(year, doy)
|
||||
return ret -- unreachable if input values are sane
|
||||
end
|
||||
|
||||
-- the algo on wikipedia seems wrong, so we opt for full-blown luadate
|
||||
M.isoweek_to_date = function(year, isoweek)
|
||||
local ret = date(year .. "-W" .. string.format("%02d", isoweek) .. "-1")
|
||||
return {
|
||||
|
||||
@@ -17,6 +17,7 @@ local filetype = require("plenary.filetype")
|
||||
local taglinks = require("taglinks.taglinks")
|
||||
local tagutils = require("taglinks.tagutils")
|
||||
local linkutils = require("taglinks.linkutils")
|
||||
local dateutils = require("taglinks.dateutils")
|
||||
local Path = require("plenary.path")
|
||||
|
||||
-- declare locals for the nvim api stuff to avoid more lsp warnings
|
||||
@@ -89,9 +90,9 @@ M.Cfg = {
|
||||
show_tags_theme = "ivy",
|
||||
|
||||
-- template_handling
|
||||
-- - prefer_home: use new_note template for all new notes created via new_note(),
|
||||
-- new_templated_note(), and follow_link() to non-existing note
|
||||
-- - smart: if day or week is detected in title, use daily / weekly
|
||||
-- What to do when creating a new note via `new_note()` or `follow_link()` to a non-existing note
|
||||
-- - prefer_new_note: use `new_note` template
|
||||
-- - smart: if day or week is detected in title, use daily / weekly templates (default)
|
||||
-- - always_ask: always ask before creating a note
|
||||
template_handling = "smart",
|
||||
|
||||
@@ -107,9 +108,15 @@ M.Cfg = {
|
||||
--
|
||||
-- Valid options:
|
||||
-- - smart: put daily-looking notes in daily, weekly-looking ones in weekly,
|
||||
-- - default: put all notes in home except for goto_today(), goto_thisweek()
|
||||
-- - same-as-current: put all new notes in the dir of the current note if
|
||||
-- all other ones in home, except for notes/with/subdirs/in/title.
|
||||
-- (default)
|
||||
--
|
||||
-- - prefer_home: put all notes in home except for goto_today(), goto_thisweek()
|
||||
-- except for notes/with/subdirs/in/title.
|
||||
--
|
||||
-- - same_as_current: put all new notes in the dir of the current note if
|
||||
-- present or else in home
|
||||
-- except for notes/with/subdirs/in/title.
|
||||
new_note_location = "smart",
|
||||
}
|
||||
|
||||
@@ -199,6 +206,7 @@ M.note_type_templates = {
|
||||
}
|
||||
|
||||
local function daysuffix(day)
|
||||
day = tostring(day)
|
||||
if (day == "1") or (day == "21") or (day == "31") then
|
||||
return "st"
|
||||
end
|
||||
@@ -393,6 +401,7 @@ local Pinfo = {
|
||||
is_daily = false,
|
||||
is_weekly = false,
|
||||
template = "",
|
||||
calendar_info = nil,
|
||||
}
|
||||
|
||||
function Pinfo:new(opts)
|
||||
@@ -434,10 +443,14 @@ function Pinfo:resolve_path(p, opts)
|
||||
end
|
||||
if vim.startswith(p, M.Cfg.dailies) then
|
||||
self.root_dir = M.Cfg.dailies
|
||||
-- TODO: parse "title" into calendarinfo like in resolve_link
|
||||
-- not really necessary as the file exists anyway and therefore we don't need to instantiate a template
|
||||
self.is_daily_or_weekly = true
|
||||
self.is_daily = true
|
||||
end
|
||||
if vim.startswith(p, M.Cfg.weeklies) then
|
||||
-- TODO: parse "title" into calendarinfo like in resolve_link
|
||||
-- not really necessary as the file exists anyway and therefore we don't need to instantiate a template
|
||||
self.root_dir = M.Cfg.weeklies
|
||||
self.is_daily_or_weekly = true
|
||||
self.is_weekly = true
|
||||
@@ -463,7 +476,7 @@ local function check_if_daily_or_weekly(title)
|
||||
|
||||
local is_daily = false
|
||||
local is_weekly = false
|
||||
local dateinfo = {}
|
||||
local dateinfo = calculate_dates() -- sane default
|
||||
|
||||
local start, _, year, month, day = title:find(daily_match)
|
||||
if start ~= nil then
|
||||
@@ -473,7 +486,7 @@ local function check_if_daily_or_weekly(title)
|
||||
dateinfo.year = tonumber(year)
|
||||
dateinfo.month = tonumber(month)
|
||||
dateinfo.day = tonumber(day)
|
||||
-- TODO: calculate_dates() here
|
||||
dateinfo = calculate_dates(dateinfo)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -483,8 +496,9 @@ local function check_if_daily_or_weekly(title)
|
||||
if start ~= nil then
|
||||
if tonumber(week) < 53 then
|
||||
is_weekly = true
|
||||
-- TODO: ISO8601 week -> date calculation
|
||||
dateinfo.year = tonumber(year)
|
||||
-- ISO8601 week -> date calculation
|
||||
dateinfo = dateutils.isoweek_to_date(tonumber(year), tonumber(week))
|
||||
dateinfo = calculate_dates(dateinfo)
|
||||
end
|
||||
end
|
||||
return is_daily, is_weekly, dateinfo
|
||||
@@ -508,8 +522,12 @@ function Pinfo:resolve_link(title, opts)
|
||||
self.is_daily = false
|
||||
self.is_weekly = false
|
||||
self.template = nil
|
||||
self.calendar_info = nil
|
||||
|
||||
if opts.weeklies and file_exists(opts.weeklies .. "/" .. self.filename) then
|
||||
-- TODO: parse "title" into calendarinfo like below
|
||||
-- not really necessary as the file exists anyway and therefore we don't need to instantiate a template
|
||||
-- if we still want calendar_info, just move the code for it out of `if self.fexists == false`.
|
||||
self.filepath = opts.weeklies .. "/" .. self.filename
|
||||
self.fexists = true
|
||||
self.root_dir = opts.weeklies
|
||||
@@ -517,6 +535,9 @@ function Pinfo:resolve_link(title, opts)
|
||||
self.is_weekly = true
|
||||
end
|
||||
if opts.dailies and file_exists(opts.dailies .. "/" .. self.filename) then
|
||||
-- TODO: parse "title" into calendarinfo like below
|
||||
-- not really necessary as the file exists anyway and therefore we don't need to instantiate a template
|
||||
-- if we still want calendar_info, just move the code for it out of `if self.fexists == false`.
|
||||
self.filepath = opts.dailies .. "/" .. self.filename
|
||||
self.fexists = true
|
||||
self.root_dir = opts.dailies
|
||||
@@ -546,24 +567,41 @@ function Pinfo:resolve_link(title, opts)
|
||||
|
||||
-- if we just cannot find the note, check if it's a daily or weekly one
|
||||
if self.fexists == false then
|
||||
-- TODO: if we're not smart, we also shouldn't need to try to set the calendar info..?
|
||||
-- I bet someone will want the info in there, so let's put it in if possible
|
||||
_, _, self.calendar_info = check_if_daily_or_weekly(self.title) -- will set today as default, so leave in!
|
||||
|
||||
if opts.new_note_location == "smart" then
|
||||
self.filepath = opts.home .. "/" .. self.filename -- default
|
||||
-- TODO: store the date_info somewhere
|
||||
self.is_daily, self.is_weekly, _ = check_if_daily_or_weekly(
|
||||
self.is_daily, self.is_weekly, self.calendar_info =
|
||||
check_if_daily_or_weekly(
|
||||
self.title
|
||||
)
|
||||
if self.is_daily == true then
|
||||
self.root_dir = opts.dailies
|
||||
self.filepath = opts.dailies .. "/" .. self.filename
|
||||
self.is_daily_or_weekly = true
|
||||
end
|
||||
if self.is_weekly == true then
|
||||
self.root_dir = opts.weeklies
|
||||
self.filepath = opts.weeklies .. "/" .. self.filename
|
||||
self.is_daily_or_weekly = true
|
||||
end
|
||||
elseif opts.new_note_location == "same_as_current" then
|
||||
local cwd = vim.fn.expand("%:p")
|
||||
if #cwd > 0 then
|
||||
self.root_dir = Path:new(cwd):parent():absolute()
|
||||
if Path:new(self.root_dir):exists() then
|
||||
-- check if potential subfolders in filename would end up in a non-existing directory
|
||||
self.filepath = self.root_dir .. "/" .. self.filename
|
||||
if not Path:new(self.filepath):parent():exists() then
|
||||
print("Path " .. self.filepath .. " is invalid!")
|
||||
-- self.filepath = opts.home .. "/" .. self.filename
|
||||
end
|
||||
else
|
||||
print("Path " .. self.root_dir .. " is invalid!")
|
||||
-- self.filepath = opts.home .. "/" .. self.filename
|
||||
end
|
||||
else
|
||||
self.filepath = opts.home .. "/" .. self.filename
|
||||
end
|
||||
@@ -571,6 +609,15 @@ function Pinfo:resolve_link(title, opts)
|
||||
-- default fn for creation
|
||||
self.filepath = opts.home .. "/" .. self.filename
|
||||
end
|
||||
|
||||
-- final round, there still can be a subdir mess-up
|
||||
if not Path:new(self.filepath):parent():exists() then
|
||||
print("Path " .. self.filepath .. " is invalid!")
|
||||
-- local fname_only = Path:new(self.filename):_split()
|
||||
-- fname_only = fname_only[#fname_only]
|
||||
-- self.filepath = opts.home .. "/" .. fname_only
|
||||
self.filepath = ""
|
||||
end
|
||||
end
|
||||
|
||||
-- now work out subdir relative to root
|
||||
@@ -582,7 +629,7 @@ function Pinfo:resolve_link(title, opts)
|
||||
|
||||
-- now suggest a template based on opts
|
||||
self.template = M.note_type_templates.normal
|
||||
if opts.template_handling == "prefer_home" then
|
||||
if opts.template_handling == "prefer_new_note" then
|
||||
self.template = M.note_type_templates.normal
|
||||
elseif opts.template_handling == "always_ask" then
|
||||
self.template = nil
|
||||
@@ -1507,7 +1554,12 @@ local function on_create_with_template(opts, title)
|
||||
-- local template = M.Cfg.templates .. "/" .. action_state.get_selected_entry().value
|
||||
local template = action_state.get_selected_entry().value
|
||||
-- TODO: pass in the calendar_info returned from the pinfo
|
||||
create_note_from_template(title, fname, template)
|
||||
create_note_from_template(
|
||||
title,
|
||||
fname,
|
||||
template,
|
||||
pinfo.calendar_info
|
||||
)
|
||||
-- open the new note
|
||||
vim.cmd("e " .. fname)
|
||||
picker_actions.post_open()
|
||||
@@ -1554,11 +1606,14 @@ local function on_create(opts, title)
|
||||
local pinfo = Pinfo:new({ title = title, opts })
|
||||
local fname = pinfo.filepath
|
||||
|
||||
print(vim.inspect(pinfo))
|
||||
|
||||
if pinfo.fexists ~= true then
|
||||
-- TODO: pass in the calendar_info returned in pinfo
|
||||
create_note_from_template(title, fname, pinfo.template)
|
||||
create_note_from_template(
|
||||
title,
|
||||
fname,
|
||||
pinfo.template,
|
||||
pinfo.calendar_info
|
||||
)
|
||||
opts.erase = true
|
||||
opts.erase_file = fname
|
||||
end
|
||||
@@ -1689,12 +1744,18 @@ local function FollowLink(opts)
|
||||
if opts.template_handling == "always_ask" then
|
||||
return on_create_with_template(opts, title)
|
||||
end
|
||||
-- TODO: if daily or weekly: derive date opts from filename!!!
|
||||
-- pass in the info contained in pinfo
|
||||
create_note_from_template(title, pinfo.filepath, pinfo.template)
|
||||
|
||||
if #pinfo.filepath > 0 then
|
||||
create_note_from_template(
|
||||
title,
|
||||
pinfo.filepath,
|
||||
pinfo.template,
|
||||
pinfo.calendar_info
|
||||
)
|
||||
opts.erase = true
|
||||
opts.erase_file = pinfo.filepath
|
||||
end
|
||||
end
|
||||
|
||||
find_files_sorted({
|
||||
prompt_title = "Follow link to note...",
|
||||
@@ -2241,7 +2302,7 @@ local function FindAllTags(opts)
|
||||
actions.select_default:replace(function()
|
||||
actions._close(prompt_bufnr, true)
|
||||
|
||||
-- TODO actions for insert tag, default action: search for tag
|
||||
-- actions for insert tag, default action: search for tag
|
||||
local selection = action_state.get_selected_entry().value.tag
|
||||
local follow_opts = {
|
||||
follow_tag = selection,
|
||||
|
||||
Reference in New Issue
Block a user