E545 Added optional sub-captions to diary index. by edlanglois · Pull Request #498 · vimwiki/vimwiki · GitHub
[go: up one dir, main page]

Skip to content

Conversation

edlanglois
Copy link
Contributor
@edlanglois edlanglois commented May 23, 2018

Added the option 'diary_caption_level'.
At -1 (the default) the diary index is the same as before.

At level 1, the diary page links have no caption but have a sub-list of
captions linking to the individual top-level headers within the diary
page.

Example:

=== April ===
  * [[2018-04-30]]
    - [[2018-04-30#My Section|My Section]]
  * [[2018-04-27]]
    - [[2018-04-27#Some Section|Some Section]]
    - [[2018-04-27#Another Section|Another Section]]

At level 2, the main caption is the first top-level header and
sub-captions link to 2nd-level headers.

Example:

=== April ===
  * [[2018-04-30|My Section]]
    - [[2018-04-30#My Subsection|My Subsection]]
  * [[2018-04-27|Some Section]]
    - [[2018-04-27#Part 1|Part 1]]
    - [[2018-04-27#Part 2|Part 2]]

Inspired by: #154 (comment)
Also related: #30

@EinfachToll
Copy link
Member

The suggested behavior looks a bit muddled to me. When I set this option to 2 but then I have multiple level-1 headers in the diary page, only the first one is taken for the caption and each level-2 header is added as subitem in the diary index, even the ones which are under other level-1 headers.
How about the following behavior for the various values of the new option:

  • -1: no special captions and list items at all
  • 0: the behavior as it is now, that is, the first header is taken as caption
  • 1: if there is exactly one level-1 header, it is taken as the caption, else, they are added as subitems.
  • 2: if there is exactly one level-1 header, it is taken as the caption and the level-2 headers are added as subitems. If there are more level-1 headers, they are added as subitems and the level-2 headers as sub-sub-items
  • 3 and so on up to level-3 headers
  • 4 etc.

@edlanglois
Copy link
Contributor Author

Sounds good, I was aiming for consistency in the caption level as you vary the number of headers in the diary page but I agree that the current behaviour with multiple level-1 headers when set to 2 isn't great. I'm happy with either approach so I'll update it to work as you suggest.

@edlanglois edlanglois force-pushed the pr/diary-captions branch 4 times, most recently from 8bb6ee7 to fe599b3 Compare July 12, 2018 22:06
@edlanglois
Copy link
Contributor Author

I've updated the pull request to match the behaviour you requested. The commit message has a description of the behaviour:

Added the option 'diary_caption_level', which controls the presence of
captions in the diary index linking to headers within the diary pages.

Possible values:
-1: No headers are read from the diary page.
0: The first header from the diary page is used as the caption.
There are no sub-captions.
1: Captions are created for headers of level 1 in the diary page.
2: Captions are created for headers up to level 2 in the diary page.
etc.

When the value is >= 1, the primary caption of each diary page is set to
first header read from that page if it is the unique lowest-level
header.

I didn't document this but there was also the question of what to do about skipped header levels. The caption indentation depth is shifted over so that the smallest indentation depth is one deeper than the main page link. So you won't end up with all of the sub-captions indented 3 deep if all headers in the diary page are at 3rd level instead of 1st. Other than that shift, indentation depth is preserved relative to header level.

@hq6
Copy link
Contributor
hq6 commented Mar 19, 2019

I am a new maintainer and I'm interested in getting this merged.

@edlanglois , if you are still interested in this PR, please resolve the conflicts and test against the tip of dev.

@hq6 hq6 self-assigned this Mar 19, 2019
Added the option 'diary_caption_level', which controls the presence of
captions in the diary index linking to headers within the diary pages.

Possible values:
-1:  No headers are read from the diary page.
 0:  The first header from the diary page is used as the caption.
       There are no sub-captions.
 1:  Captions are created for headers of level 1 in the diary page.
 2:  Captions are created for headers up to level 2 in the diary page.
 etc.

When the value is >= 1, the primary caption of each diary page is set to
the first header read from that page if it is the unique lowest-level
header.
@edlanglois
Copy link
Contributor Author

Rebased on dev and tested it, everything still works for me.

I cleaned up the change a bit as well:

  • fixed endfo => endfor (somehow that worked in the first place?)
  • removed redundant "l:" variable scopes
  • removed an unused optional argument to get_first_header
  • added missing "the" to the documentation

@hq6
F440 Copy link
Contributor
hq6 commented Mar 20, 2019

@edlanglois, I am not super familiar with the diary feature, so it's possible that I am misusing this, but I was not able to reproduce the intended behavior of this patch. Here's what I tried.

  1. Put the following text in the file /home/hq6/vimwiki/diary/2019-03-20.wiki.
= First Level Header =
This is the diary entry.

= First Level Header 2 =
This is the diary entry.

== Second Level header ==
How about something here
  1. Open /home/hq6/vimwiki/diary/diary.wiki and run let g:diary_subcaption_level = 2.

  2. Run VimwikiDiaryGenerateLinks.

Output:


= Diary =

== 2019 ==

=== March ===
    * [[2019-03-20|First Level Header]]

I expected to see links to all three headers appear in the index page. Am I using it incorrectly?

@edlanglois
Copy link
Contributor Author
edlanglois commented Mar 20, 2019

The default setting (diary_caption_level=0) preserves the existing behaviour before this change and just takes the first header. Setting diary_caption_level > 0 will show all headers up to that level (e.g. =1 will show the two top level headers only, 2-6 will show all three).

With diary_caption_level=1:

= Diary =

== 2019 ==

=== March ===
  * [[2019-03-20]]
    - [[2019-03-20#First Level Header|First Level Header]]
    - [[2019-03-20#First Level Header 2|First Level Header 2]]

@hq6
Copy link
Contributor
hq6 commented Mar 20, 2019

@edlanglois , I ran let g:diary_subcaption_level = 2 without any difference.

@edlanglois
Copy link
Contributor Author
edlanglois commented Mar 20, 2019

Oh, the setting is now diary_caption_level not diary_subcaption_level (I'll edit my original message in this PR).

Also, I set all vimwiki options using the vimwiki_list variable, does let g:<name> work for other options?:

let g:vimwiki_list = [{
	\ 'path': '~/some/path/to/vimwiki/',
	\ 'diary_caption_level': 1,
	\}]

@edlanglois
Copy link
Contributor Author
edlanglois commented Mar 20, 2019

It's been awhile so I had forgotten how the vimwiki options work. Looks like vimwiki_list is for wiki-local options and g:vimwiki_<name> for global options. I don't have a strong preference where the caption level option goes but other comparable diary options (diary_header, diary_sort) are also wiki-local.

@hq6
Copy link
Contributor
hq6 commented Mar 20, 2019

I have manually merged this PR as 8f5d383.

@hq6 hq6 closed this Mar 20, 2019
@jessebett
Copy link
jessebett commented Jul 8, 2019

This does not appear to work with Markdown syntax vimwiki. I have set 'diary_caption_level':2 but if I have an entry with

## Test

some stuff

## Test 2

other stuff

And then :VimwikiDiaryGenerateLinks the above behaviour does not happen, I only get the usual entry with [Test](path/to/entry)

Here's my config:

let g:vimwiki_list = [{'path': '~/vimwiki', 'template_path': '~/vimwiki/templates/',
          \ 'template_default': 'default', 'syntax': 'markdown', 'ext': '.md',
          \ 'path_html': '~/vimwiki/site_html/', 'custom_wiki2html': 'vimwiki_markdown',
          \ 'html_filename_parameterization': 1,
          \ 'diary_caption_level':2,
          \ 'template_ext': '.tpl'}]
let g:vimwiki_global_ext = 0
let g:vimwiki_markdown_link_ext = 1

@edlanglois
Copy link
Contributor Author
edlanglois commented Jul 8, 2019

(We determined that the issue was from using the master release branch)

For anyone else who comes across this:
This feature has not been included in the master branch yet. I recommend checking out the dev branch if you want diary subcaptions but expect vimwiki to be less stable and possibly missing some other content from the master branch.

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

Successfully merging this pull request may close these issues.

4 participants
0