Coder Social home page Coder Social logo

Multi-line embedded lisp-code about yasnippet HOT 7 OPEN

joergdw avatar joergdw commented on June 11, 2024
Multi-line embedded lisp-code

from yasnippet.

Comments (7)

monnier avatar monnier commented on June 11, 2024 1

from yasnippet.

monnier avatar monnier commented on June 11, 2024

from yasnippet.

joergdw avatar joergdw commented on June 11, 2024

That branch looks quite aged, hmmm 🤔. I would be surprised if I were the only one asking about multiline-capability. Self-contained snippets (for easy sharing, which is an important thing from my point of view) otherwise tend to have a unnecessarily poor readability. At least if they do some (non-trivial?) work for the user.

from yasnippet.

monnier avatar monnier commented on June 11, 2024

from yasnippet.

joergdw avatar joergdw commented on June 11, 2024

Embedded where? Inside the snippet (i.e. in a ${...}) or in the header?
Inside the snippet (in a ${…}).

It should be fairly easy to allow headers to span multiple lines. I'm not completely sure what format we could/should use. One natural option would be to do like RFC822, i.e. consider that a subsequent line that's more indented than the header to be part of the same header, so you could write: # name: my-snip # expand-env: ((a 1) (b 2) # (c 3) (d 4) (e 5)) # group: my-group # -- ... but that would break for those who like to align their colons, since something like: # name: my-snip # expand-env: ((a 1) (b 2) # (c 3) (d 4) (e 5)) # group: my-group # -- ... would treat the group: as being part of the expand-env header.

Three ideas:

  • We anyway start with the snippet only after a line containing # --, when we have a large one. That means, we can do line-breaks before and don't need to start the next line with a # in which case (but only before # --) lines starting without # are treated as belonging to the same header as the last one.
  • Lines starting with #^ (or any other suitable additional symbol) belong to the header before. This looks at least to me, simple. (Inspiration from Rust, where you add a ! to the comment-prefix to indicate that it belongs to the super-elemenet instead of the subsequent element.)
  • If the line is further indented than the one above and starts with $#[[:space:]]+ followed by a known header, then it belongs to the element before. This does not require additional syntax but perhaps may be a bit more complicated to implement.

from yasnippet.

monnier avatar monnier commented on June 11, 2024

from yasnippet.

joergdw avatar joergdw commented on June 11, 2024

The subsequent snippet lets you create an org-mode code-block and offers proposals for all modes that registered in a suitable list in emacs. Btw: org-mode should work and set the correct editing mode for all proposals by yasnippet.

# -*- mode: snippet -*-
# name: code-block
# key: #src
# --
#+CAPTION: ${1:Caption}
#+NAME: ${2:anchor}
#+BEGIN_SRC ${3:sh$(yas-choose-value (let* ((empty-choice (list "")) (source-ids-from-org-mode (seq-map 'symbol-name (seq-map 'car (progn (require 'ox-man) org-man-source-highlight-langs)))) (source-ids-from-alists (seq-filter (lambda (elt) (not (eq 'cons (type-of elt)))) (seq-map (lambda (sym) (replace-regexp-in-string "\\\\(-ts\\\\)?-mode" "" (symbol-name sym))) (seq-filter (lambda (elt) (not (eq 'cons (type-of elt)))) (seq-map 'cdr (append auto-mode-alist interpreter-mode-alist magic-mode-alist))))))) (cl-sort (delete-dups (append empty-choice source-ids-from-org-mode source-ids-from-alists)) 'string-lessp)))}
  `yas-selected-text`$0
#+END_SRC

Actually my snippet does more, for other options after BEGIN_SRC, but this is by far the largest thing among them.

from yasnippet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.