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).
This commit is contained in:
Alex Vear
2020-02-15 03:00:16 +00:00
parent d671e862e4
commit 6a29a2e961
4 changed files with 23 additions and 37 deletions

1
TODO
View File

@@ -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

View File

@@ -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~

View File

@@ -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

View File

@@ -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'