Looping over VISUAL parts

Asked by Michel Blanc

Hi,

First, thanks for UltiSnippets, it's just awesome and very easy to use. It will save me from MSD !

I'm trying to refine my RDoc snippet which is included below.
It uses VISUAL and captures the 'def' Ruby line.
However, it would be cool to have one '@param' entry for every argument found on the 'def' line. Is it possible ?

Thanks !

EDIT: I suppose Python interpolation is the way to go, I'll give it a try.

The current snippet :

snippet rdoc "Insert RDoc documentation for method"
  ##
  # ${1:Summary}
  #
  # ${2:Description}
  #
  # @example ${3:Example description}
  #
  # ${4:Example code}
  #
  # @param [${5:String}] ${6:varname} ${7:Variable description}
  #
  # @date `date`
  # @author `whoami`
  #
  ${VISUAL}${0}
  end
  # End of ${VISUAL/def (.*)\(.*/$1/}
  endsnippet

Question information

Language:
English Edit question
Status:
Answered
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Michel Blanc (7-mb) said :
#1

Replying to self.

I ended up with :

# Rdoc snippet with args filling
global !p
import re
def fill_args(text):
  a = re.match(".*\((.*)\).*", text)
  print (a.group(1))

  args = a.group(1).split(',')
  ret = ""
  for arg in args:
    ret += "# @param [type] " + arg + " desc\n"

  return ret
endglobal

snippet pdoc "Insert RDoc documentation for method"
##
# ${1:Summary}
#
# ${2:Description}
#
# @example ${3:Example description}
#
# ${4:Example code}
#
`!p snip.rv = fill_args(snip.v.text)`
#
# @date `date`
# @author `whoami`
#
${VISUAL}${0}
end
# End of ${VISUAL/def (.*)\(.*/$1/}
endsnippet

However, it would be cool to return placeholders, so the generated section could be tab-navigated and filled, something like :

# @param [${6}:Symbol] arg ${7:No description}
# @param [${8}:Symbol] arg ${9:No description}
# @param [${10}:Symbol] arg ${11:No description}

Is this possible ?

Thanks !

Revision history for this message
SirVer (sirver) said :
#2

No, sorry. This is the single most requested feature though :). But currently it is not possible and I have no real clue how to add this in, it is not trivial, that's for sure.

Can you help with this problem?

Provide an answer of your own, or ask Michel Blanc for more information if necessary.

To post a message you must log in.