1

I'm trying to develop a new yas-snippet for expanding a common c++ log function I use a lot. The first parameter to the LOG function can be guessed by searching for existing LOG calls in the buffer. For example, if the user types

LOG(QWERTY_ID, EVENT, DEBUG, "wooo!");
LOG<TAB>

I would like yas-snippet to expand to

LOG(QUERY_ID, UNKNOWN_EVENT, , "");

If the LOG function hasn't been used before then I would like to expand to:

LOG(<SUBSYSTEM_ID>, UNKNOWN_EVENT, , "");
    ^^^^^^^^^^^^^^

The SUBSYSTEM_ID part isn't working for me. This is what I have so far

LOG(${1:`(progn
(beginning-of-buffer)
(re-search-forward "LOG(\s*\\([A-Za-z_]+\\)\s*," (point-max) t)
(let ((m (match-string-no-properties 1)))
  (if m m ("<SUBSYSTEM_ID>"))))`}, ${2:UNKNOWN_EVENT}, ${3:$$(yas-choose-value '("DEBUG" "INFO" "WARN" "ERROR" "FATAL" "OFF"))}, ${4:""}$0);

It actually just expands to some text that it seems to have matched from within the snippet itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.