Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-line embedded lisp-code #1182

Open
joergdw opened this issue Jan 8, 2024 · 7 comments
Open

Multi-line embedded lisp-code #1182

joergdw opened this issue Jan 8, 2024 · 7 comments

Comments

@joergdw
Copy link

joergdw commented Jan 8, 2024

Sometimes, embedded lisp-expressions can become quite large. (E.g. 12 lines by ordinary formatting.)

Could we add a way to make multiline-lisp-definitions. I am aware of the expand-env-section. However it looks as it would not be multiline-aware. Additionally I was not able to bring in a let* definition there. Is it supposed to support access to previous definitions within the same section (as in let*)?

@monnier
Copy link
Collaborator

monnier commented Jan 8, 2024 via email

@joergdw
Copy link
Author

joergdw commented Jan 10, 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.

@monnier
Copy link
Collaborator

monnier commented Jan 14, 2024 via email

@monnier
Copy link
Collaborator

monnier commented Feb 13, 2024 via email

@joergdw
Copy link
Author

joergdw commented Feb 21, 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.

@monnier
Copy link
Collaborator

monnier commented Feb 22, 2024 via email

@joergdw
Copy link
Author

joergdw commented Feb 26, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants