Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ Inline directives occur in the body of comment blocks. Most take one argument
enclosed in parenthesis.

- `@function(name)` generates a link to a function defined in the plugin.
The equivalent spelling `@function(name())` is also accepted.
- `@command(name)` generates a link to a command defined in the plugin.
- `@flag(name)` generates a link to a flag defined in the plugin.
- `@setting(name)` generates a link to a setting defined in the plugin.
Expand Down
22 changes: 22 additions & 0 deletions tests/test_function_link_parentheses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import unittest

from vimdoc import module
from vimdoc import output


class TestFunctionLinkParentheses(unittest.TestCase):

def setUp(self):
self.writer = output.Helpfile(
module.Module('example', module.VimPlugin('example')), '.')

def test_function_call_spelling_matches_plain_name(self):
self.assertEqual('See |foo#Bar()| and |foo#Bar()|.', self.writer.Expand(
'See @function(foo#Bar()) and @function(foo#Bar).', None))

def test_relative_function_name_with_parentheses(self):
self.assertEqual('|example#Bar()|', self.writer.Expand(
'@function(#Bar())', 'example#'))

def test_unknown_directive_keeps_its_parentheses(self):
self.assertEqual('@unknown(Foo())', self.writer.Expand('@unknown(Foo())', None))
2 changes: 2 additions & 0 deletions vimdoc/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ def ExpandInline(self, inline, element, namespace):
if inline == 'section':
return self.Link(self.Slug(element))
elif inline == 'function':
if element.endswith('()'):
element = element[:-2]
# If a user says @function(#Foo) then that points to in#this#file#Foo.
if element.startswith('#'):
element = (namespace or '') + element[1:]
Expand Down
2 changes: 1 addition & 1 deletion vimdoc/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def _DelimitedRegex(pattern):
\s*\)
)?
""", re.VERBOSE)
inline_directive = re.compile(r'@([a-zA-Z_][a-zA-Z0-9_]*)(?:\(([^\s)]+)\))?')
inline_directive = re.compile(r'@([a-zA-Z_][a-zA-Z0-9_]*)(?:\(((?:[^\s()]|\(\))+)\))?')

name_hole = re.compile(r'<>')
arg_hole = re.compile(r'{\]')
Expand Down
Loading