joaotavora / yasnippet

A template system for Emacs
http://joaotavora.github.io/yasnippet/
2.76k stars 314 forks source link

[FR/Q] How do I comment a line of the snippet from being included in the snippet? #1195

Open NightMachinery opened 3 months ago

NightMachinery commented 3 months ago

I have this snippet:

# -*- mode: snippet -*-
# name: llm-c3o
# key: <l
# uuid: <l
# --
#+begin_src jupyter-python :kernel py_base :session claude_1 :async yes :exports both
res = openai_chat_complete(
    ##
    model="OR:anthropic/claude-3-opus:beta",
    # model="OR:anthropic/claude-3-sonnet:beta",
    # model="OR:anthropic/claude-3-haiku:beta",
    # model="OR:mistralai/mistral-large",
    # model="OR:perplexity/sonar-medium-online",
    # model="gpt-4-turbo",
    # model="gpt-4-0314",
    # model="gpt-4-0613",
    # model="claude-3-opus-20240229",
    ##
    messages=[
        # {"role": "system", "content": \"""Output your changes in the unified diff format.\"""},
        {"role": "user", "content": r\"""
        `%`$0
        \"""},
    ],
    temperature=0,
    max_tokens=4000,
    interactive=True,
)

print_chat_streaming(res, copy_mode=None) # "chat2"
bell_gpt()
#+end_src

I want to comment some of the model=... lines such that they remain in the snippet file, but are never expanded. (I.e., if we treat the above snippet template as code, I want to add some comments to it.)

dericbytes commented 2 months ago

I know a hack that works. Run elisp code that returns an empty string

# key: dm
# name: delete-me-1
# --
This
is`(progn "ignore me" "")`
a
test.

You can create your own function to make it look neater

# key: dm2
# name: delete-me-2
# --
This
is a `(yas-comment "really")`good
second example.

create elisp function (best to change function name to avoid naming conflict)

(defun yas-comment (msg)
  "Ignore MSG. Return an empty string"
    "") 

You will need to escape and unescape your quotes. You can do that by selecting the region and running a function. http://xahlee.info/emacs/emacs/elisp_escape_quotes.html