Inserting snipet to selected lines of code


#1

Im comming from a tex program where i was able to define macros to insert in to a selected area of code. It then inserted that snipet in the top and closed it after the last selected line of code. Is that possible to configure with atom somehow?

a sample:

\begin{center}
  ##Selected##
\end{center}

and sometimes it also useful to get a tag to set the cursor to the next used point:

\begin{multicol}{##Cursor##}
  ##Selected##
\end{multicol}

how can i build my snipets like that?


#2

Looks like you’ll need a proper package for that (or at least some work in the init file).

I’ll give it a try when I have time. In the mean time, there are LaTeX autocomplete packages that are configurable in terms of content and cursor position. They don’t work with selected text, but they might suit your needs.


#3

i assume it wold be better to integrate it to the snippets package as the main task is to automate workflows. this seams as a extension of the same to me.


#4

Snippets are for when you type a “prefix” and expand it to the “body”. What you’re suggesting, if I understand right, is to apply a modification to some selected text.


#5

corect.
The workflow i would see as apropriate is this:
my code:

foo bar
  • select code with the mouse. like select only: “foo”
  • press a hotkey like {shift & cmd} + p. to get a box where i can type for searching the tag.
  • select the tag by enter
  • that inserts the snipet and expands the selected text.

ending up with:

\begin{multicol}{set the cursor here}
  foo
\end{multicol}
bar

#6

Possibly the closest package with capability:


#7

That package is actually very old, haven’t done much since. But considering the interest around it, I’ll go back to it ASAP!


#8

Wow, thanks!