From 6a29a2e9617acb25ebf324a807345ee8a86bd8b1 Mon Sep 17 00:00:00 2001 From: Alex Vear Date: Sat, 15 Feb 2020 03:00:16 +0000 Subject: [PATCH] Better Org mode hyperlink syntax highlighting and disabled link conceal Org mode hyperlinks are now fully syntax highlighted (similar to Markdown links). The `org_conceal_links` option has been removed in favour of using built-in Vim options to enable concealing (with a short section in the `doc/org.txt` file on how to do this). This was done because concealed text makes navigating "hard-wrapped" documents difficult (especially when the concealed text is as long as most URLs). --- TODO | 1 - doc/org.txt | 46 +++++++++++++++++----------------------------- ftplugin/org.vim | 6 ------ syntax/org.vim | 7 ++++++- 4 files changed, 23 insertions(+), 37 deletions(-) diff --git a/TODO b/TODO index f759d27..5ab5d5b 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ MAYBE: - - Better link syntax highlighting (more similar to links in vim-markdown) - Syntax highlight checkboxes and checkbox cookies - Different syntax group for heading delimiters diff --git a/doc/org.txt b/doc/org.txt index 3d10864..e4e0991 100644 --- a/doc/org.txt +++ b/doc/org.txt @@ -123,6 +123,23 @@ Or if you want folding enabled and all folds opened by default, use < For more information on folding in Vim, refer to |fold.txt|. +------------------------------------------------------------------------------ + *org-conceal-links* + +You can tell Vim to conceal links by using the built-in 'conceallevel' and +'concealcursor' options. + +For example, you can make Vim collapse an Org mode link to look like it would +within Emacs or a Web browser (i.e. only showing the link title). +> + [[https://www.vim.org][Vim website]] --> Vim website +< +This is achieved with this |autocmd|: +> + autocmd FileType org setlocal conceallevel=2 concealcursor=nc +< +Note: long concealed text can act weird when "hard-wraping" text in Vim. + ------------------------------------------------------------------------------ *'b:org_state_keywords'* *'g:org_state_keywords'* Value: list of strings~ @@ -138,35 +155,6 @@ Note: state keywords are case sensitive. State keywords can be set on specific buffers by using |'b:org_state_keywords'| rather than |'g:org_state_keywords'|. ------------------------------------------------------------------------------- - *'b:org_conceal_links'* *'g:org_conceal_links'* -Value: numeric~ -Default: 1~ - -This option changes how Org mode links are rendered. If this option is -enabled, most of the link syntax will be collapsed to look as it would within -Emacs or a web browser; only showing the (underlined) link text. -> - [[https://www.vim.org][Vim website]] --> Vim website -< -When in insert mode with the cursor on that line, Vim will show the full link -syntax. This feature is enabled by default, however the way Vim treats -concealed text can be annoying, so it can be disabled. - -To disable for all Org mode files, place the following line in your vimrc: -> - let g:org_conceal_links = 0 -< -To disable for a specific file use this instead: -> - let b:org_conceal_links = 0 -< -If you would like to modify how links are concealed, you can disable this -option, and manually set the |conceallevel| and |concealcursor| options from -an |autocmd| like so. -> - autocmd FileType org setlocal conceallevel=2 concealcursor=nc -< ------------------------------------------------------------------------------ *'b:org_clean_folds'* *'g:org_clean_folds'* Value: numeric~ diff --git a/ftplugin/org.vim b/ftplugin/org.vim index 3140224..d2f974f 100644 --- a/ftplugin/org.vim +++ b/ftplugin/org.vim @@ -22,9 +22,3 @@ if org#option('org_clean_folds', 0) setlocal foldtext=org#fold_text() setlocal fillchars-=fold:- endif - -" Conceal Org mode link syntax -if org#option('org_conceal_links', 1) - setlocal conceallevel=2 - setlocal concealcursor=nc -endif diff --git a/syntax/org.vim b/syntax/org.vim index a189816..85268d1 100644 --- a/syntax/org.vim +++ b/syntax/org.vim @@ -103,8 +103,13 @@ highlight def link orgTimestampInactive Comment syntax match orgHyperlink /\[\{2}\([^][]\{-1,}\]\[\)\?[^][]\{-1,}\]\{2}/ containedin=ALL contains=orgHyperLeft,orgHyperRight,orgHyperURL syntax match orgHyperLeft /\[\{2}/ contained conceal syntax match orgHyperRight /\]\{2}/ contained conceal -syntax match orgHyperURL /[^][]\{-1,}\]\[/ contained conceal +syntax match orgHyperURL /[^][]\{-1,}\]\[/ contains=orgHyperCentre contained conceal +syntax match orgHyperCentre /\]\[/ contained conceal highlight def link orgHyperlink Underlined +highlight def link orgHyperURL String +highlight def link orgHyperCentre Comment +highlight def link orgHyperLeft Comment +highlight def link orgHyperRight Comment let b:current_syntax = 'org'