Compare commits

...

2 Commits

Author SHA1 Message Date
00af1c53b9 documentation: new notes 2026-02-18 17:24:20 +01:00
717f44425b functionality to add new notes 2026-02-18 17:08:24 +01:00
5 changed files with 131 additions and 11 deletions

View File

@@ -63,6 +63,9 @@ search for patterns within your notes.
With this, you may populate the location list with all links to the currently With this, you may populate the location list with all links to the currently
opened note. opened note.
- `:DenoteNew {title}`:
With this, a new note entry is generated with the supplied title.
#### Key mappings #### Key mappings
This package also defines the following interface for key mappings, which This package also defines the following interface for key mappings, which
automatically open the location window: automatically open the location window:
@@ -83,16 +86,13 @@ nnoremap [l :lprevious<CR>
``` ```
### Customization ### Customization
You can customize the behavior of this package using the following two global You can customize the behavior of this package using several global variables.
variables. The variable `g:denote_note_file_extensions` defaults to `['md', Customization is explained in the [help file](doc/denote.txt), also accessible
'org', 'txt']` and lists the file extensions in which `:DenoteGrep` will look through `:help denote-settings`.
for the given pattern. The other variable `g:denote_loc_title_columns` defaults
to `40` and specifies the number of columns used to display the titles of your
notes.
### Future features ### Future features
These features are planned: These features are planned:
- Note creation (and deletion?)
- Tag manipulation - Tag manipulation
- Title manipulation - Title manipulation
- Signature handling? - Signature handling?
- Note deletion?

View File

@@ -0,0 +1,59 @@
" Functions to create the front matter {{{1
" Helper function to put string in double quotes, and remove inside double
" quotes.
function s:escapeDQ(s)
return '"' .. substitute(a:s, '"', '', 'g') .. '"'
endfunction
" Create front matter (yaml)
function s:md_new_yaml(id, title, tags)
return [
\ '---',
\ 'title: ' .. s:escapeDQ(a:title),
\ 'date: ' .. strftime("%FT%T%z"),
\ 'tags: [' .. map(copy(a:tags), {_, t -> s:escapeDQ(t) })->join(', ') .. ']',
\ 'identifier: ' .. s:escapeDQ(a:id),
\ '---'
\ ]
endfunction
" Create front matter (toml)
function s:md_new_toml(id, title, tags)
return [
\ '+++',
\ 'title ' .. s:escapeDQ(a:title),
\ 'date ' .. strftime("%FT%T%z"),
\ 'tags [' .. map(copy(a:tags), {_, t -> s:escapeDQ(t) })->join(', ') .. ']',
\ 'identifier ' .. s:escapeDQ(a:id),
\ '+++'
\ ]
endfunction
" Create front matter (plain)
function s:plain_new(id, title, tags)
return [
\ 'title: ' .. a:title,
\ 'date: ' .. strftime("%F"),
\ 'tags: ' .. a:tags->join(' '),
\ 'identifier: ' .. a:id,
\ '---------------------------',
\ ]
endfunction
" Create front matter (org)
function s:org_new(id, title, tags)
return [
\ '#+title: ' .. a:title,
\ '#+date: [' .. strftime("%F %a %R") .. ']',
\ '#+filetags: :' .. map(copy(a:tags), {_, t -> substitute(t, ':', '', 'g') })->join(':') .. ':',
\ '#+identifier: ' .. a:id,
\ ]
endfunction
" Create front matter
function denote#frontmatter#new(ft, id, title, tags=[])
return a:ft == 'org' ? s:org_new(a:id, a:title, a:tags)
\ : a:ft == 'plain' ? s:plain_new(a:id, a:title, a:tags)
\ : g:denote_fm_md_type == 'toml' ? s:md_new_toml(a:id, a:title, a:tags)
\ : s:md_new_yaml(a:id, a:title, a:tags)
endfunction

View File

@@ -32,5 +32,14 @@ endfunction
" Return the note tags from the filename as a list. " Return the note tags from the filename as a list.
function denote#meta#noteTagsFromFile(filename) function denote#meta#noteTagsFromFile(filename)
return a:filename->matchstr("__\\zs.\\{-\\}\\ze\\(==\\|@@\\|--\\|\\..\\)")->split("_") return a:filename->matchstr("__\\zs.\\{-\\}\\ze\\(==\\|@@\\|--\\|\\..\\)")->split("_")
\ ?? [] endfunction
" Identifier creation
function denote#meta#identifier_generate()
if g:denote_identifier_fun
return execute "call " .. g:denote_identifier_fun .. "()"
endif
return exists("*strftime")
\ ? strftime("%Y%m%dT%H%M%S")
\ : rand()
endfunction endfunction

View File

@@ -1,4 +1,4 @@
*denote.txt* For Vim version 9.0. Last change: 2026 Feb 17 *denote.txt* For Vim version 9.0. Last change: 2026 Feb 18
This is the documentation for the denote plugin. This is the documentation for the denote plugin.
@@ -51,25 +51,47 @@ This command is a wrapper around |:lvimgrep| to search for a pattern in the
denote entries. The required argument is a pattern as required by |:vimgrep|, denote entries. The required argument is a pattern as required by |:vimgrep|,
i.e., /{pattern}/[g][j][f]. i.e., /{pattern}/[g][j][f].
*:DenoteNew*
This command takes as argument a note title, and generates a new denote entry
with the specified title. The entry file type is controlled by the setting
|g:denote_new_ft|.
*:DenoteBackReferences* *:DenoteBackReferences*
When called from an opened denote entry, this command populates the location When called from an opened denote entry, this command populates the location
list with all references to the current note. list with all references to the current note.
*denote-settings* *denote-settings*
Settings ~ Settings ~
*'g:denote_note_file_extension'* *g:denote_note_file_extension*
With this setting you may specify the file extensions of all denote entries With this setting you may specify the file extensions of all denote entries
within which |:DenoteGrep| will search for the provided pattern. If left within which |:DenoteGrep| will search for the provided pattern. If left
unspecified, it is set to the following default value: unspecified, it is set to the following default value:
> >
g:denote_note_file_extension = ['md', 'org', 'txt'] g:denote_note_file_extension = ['md', 'org', 'txt']
< <
*'g:denote_loc_title_columns'* *g:denote_loc_title_columns*
This integer specifies the number of columns used to display the titles of This integer specifies the number of columns used to display the titles of
denote entries. Per default, it is set to: denote entries. Per default, it is set to:
> >
g:denote_loc_title_columns = 60 g:denote_loc_title_columns = 60
< <
*g:denote_new_ft*
Newly created notes are of this file type. Possible values are 'md', 'org', or
'txt', with the following default:
>
g:denote_new_ft = 'md'
<
*g:denote_fm_md_type*
The front matter of 'md' notes is given as 'yaml' or as 'toml'. By default,
this package uses 'yaml':
>
g:denote_fm_md_type = 'yaml'
<
*g:denote_identifier_fun*
Denote allows the use of custom identifiers. This variable, if set, points to
a function that generates identifiers for newly created notes. The function is
supposed to return a unique string.
*denote-mappings* *denote-mappings*
Mappings ~ Mappings ~

View File

@@ -10,6 +10,22 @@ if !exists('g:denote_loc_title_columns')
let g:denote_loc_title_columns=40 let g:denote_loc_title_columns=40
endif endif
" Default filetype for newly created denote entries
if !exists('g:denote_new_ft')
let g:denote_new_ft='md'
endif
" Default front-matter type for markdown notes, may be one of 'yaml' or 'toml'
if !exists('g:denote_fm_md_type')
let g:denote_fm_md_type='yaml'
endif
" By using the following global variable, the user may specify a custom
" function for creating identifiers.
if !exists('g:denote_identifier_fun')
let g:denote_identifier_fun=''
endif
" Local functions {{{1 " Local functions {{{1
" Put all notes of the given tag to the location list. The tag argument is " Put all notes of the given tag to the location list. The tag argument is
" mandatory. " mandatory.
@@ -82,10 +98,24 @@ function s:tagList(ArgLead, cmdLine, CursorPos)
return uniq(sort(tags))->join("\n") return uniq(sort(tags))->join("\n")
endfunction endfunction
" This creates a new denote entry with the given title and of the given
" filetype. The title may be empty.
function s:DenoteNew(title, ft=g:denote_new_ft)
let identifier=denote#meta#identifier_generate()
let fn=identifier .. '--' .. a:title
\ ->tolower()
\ ->substitute('[^[:fname:]]\|/', '-', 'g')
\ ->substitute('-\+', '-', 'g')
\ ->trim('-') .. '.' .. a:ft
execute "edit " .. fn
call setline(1, denote#frontmatter#new(a:ft, identifier, a:title))
endfunction
" Public commands and key mappings {{{1 " Public commands and key mappings {{{1
command -nargs=* Denote :call <SID>DenoteNotes(<q-args>) command -nargs=* Denote :call <SID>DenoteNotes(<q-args>)
command -nargs=1 -complete=custom,<SID>tagList DenoteTag :call <SID>DenoteNotesByTag(<q-args>) command -nargs=1 -complete=custom,<SID>tagList DenoteTag :call <SID>DenoteNotesByTag(<q-args>)
command -nargs=+ DenoteGrep :call <SID>DenoteGrep(<q-args>) command -nargs=+ DenoteGrep :call <SID>DenoteGrep(<q-args>)
command -nargs=1 DenoteNew :call <SID>DenoteNew(<q-args>)
" Useful key mappings " Useful key mappings
nnoremap <silent> <Plug>DenoteList :Denote<CR>:lclose<CR>:lopen<CR>:resize 20<CR> nnoremap <silent> <Plug>DenoteList :Denote<CR>:lclose<CR>:lopen<CR>:resize 20<CR>