Next: Skeletons as Abbrev Expansions, Previous: Using Skeletons, Up: Autotyping [Contents][Index]
Often you will find yourself with some code that for whatever reason suddenly becomes conditional. Or you have written a bit of text and want to put it in the middle of a form letter. Skeletons provide a means for accomplishing this, and can even, in the case of programming languages, reindent the wrapped code for you.
Skeleton commands take an optional numeric prefix argument (see Arguments in The GNU Emacs Manual). This is interpreted in two different ways depending on whether the prefix is positive, i.e., forwards oriented, or negative, i.e., backwards oriented.
A positive prefix means to wrap the skeleton around that many following words. This is accomplished by putting the words there where the point is normally left after that skeleton is inserted (see Using Skeletons). The point (see Point in The GNU Emacs Manual) is left at the next interesting spot in the skeleton instead.
A negative prefix means to do something similar with that many previously marked interregions (see Mark in The GNU Emacs Manual). In the simplest case, if you type M-- just before issuing the skeleton command, that will wrap the skeleton around the current region, just like a positive argument would have wrapped it around a number of words.
Smaller negative arguments will wrap that many interregions into successive interesting spots within the skeleton, again leaving the point at the next one. We speak about interregions rather than regions here, because we treat them in the order they appear in the buffer, which coincides with successive regions only if they were marked in order.
That is, if you marked in alphabetical order the points A B C [] (where [] represents the point) and call a skeleton command with M-- 3, you will wrap the text from A to B into the first interesting spot of the skeleton, the text from B to C into the next one, the text from C to the point into the third one, and leave the point in the fourth one. If there are less marks in the buffer, or if the skeleton defines less interesting points, the surplus is ignored.
If, on the other hand, you marked in alphabetical order the points [] A C B, and call a skeleton command with M-- 3, you will wrap the text from point to A, then the text from A to C and finally the text from C to B. This is done because the regions overlap and Emacs would be helplessly lost if it tried to follow the order in which you marked these points.
Next: Skeletons as Abbrev Expansions, Previous: Using Skeletons, Up: Autotyping [Contents][Index]