[TxMt] ^Q and the Mail bundle

Eric Peden eric at ericpeden.com
Sat Jul 8 06:18:00 UTC 2006


On Mon, Jul 03, 2006 at 12:23:43PM -0500, Charilaos Skiadas wrote:
>On Jul 3, 2006, at 12:16 PM, Grahame Bowland wrote:
>>I may be missing something entirely obvious, but when I have a
>>document's language set to Mail and hit ^Q  I seem to get the
>>behaviour from Text->Reformat Paragraph, rather than Mail->Reformat
>>Quoted Text. Can anyone give me a hint as to what I'm missing, or is
>>this a bug?
>>
>According to its scope, it is only supposed to work in quoted text.  
>What text are you trying it at?

I find it extremely useful to be able to reformat non-quoted mail
paragraphs as well as quoted portions of text. Here's my hacked Mail
language grammar, which also includes a new firstLineMatch so that the
correct language is picked when composing from mutt, as well as scope
assignments for headers:

✂------✂------✂------✂------✂------✂------✂------✂------✂------✂------
{	scopeName = 'text.plain.mail';
	firstLineMatch = '^(From |[-A-Za-z0-9_]+:\s+)\w+';
	fileTypes = ( 'mail' );
	patterns = (
		{	name = 'meta.header.mail';
			begin = '^(?=From |[-A-Za-z0-9_]+:\s+)';
			end = '^(?=\s*)$';
			patterns = ( { include = '#header'; } );
		},
		{	name = 'markup.quote.mail';
			match = '^(> ?)(> ?)(>(?: ?.*)?$\n?)';
			captures = 
			{	1 = { name = 'markup.quote.mail.single'; };
				2 = { name = 'markup.quote.mail.double'; };
				3 = { name = 'markup.quote.mail.many'; };
			};
		},
		{	name = 'markup.quote.mail';
			match = '^(> ?)(>(?: ?.*)?$\n?)';
			captures = 
			{	1 = { name = 'markup.quote.mail.single'; };
				2 = { name = 'markup.quote.mail.double'; };
			};
		},
		{	name = 'markup.quote.mail.single';
			match = '^>(?: ?.*)?$\n?';
		},
		{	name = 'meta.separator.signature.mail';
			match = '^-- $\n';
		},
		{	name = 'meta.paragraph.mail';
			begin = '^(?=\S)';
			end = '^(?:\s*$|(?=\s*>))';
		},
		{	include = 'text.plain'; },
	);
	repository = { header = { patterns = (
				{	match = '^(Subject:\s+)(.*)$';
					captures = 
					{	1 = { name = 'entity.name.header'; };
						2 = { name = 'string.other.header.subject'; };
					};
				},
				{	name = 'entity.name.header';
					match = '^([-A-Za-z0-9_]+:\s+)';
				},
				{	name = 'string.other.header.value';
					match = '.+[\n$]';
				},
			);
		};
	};
}
✂------✂------✂------✂------✂------✂------✂------✂------✂------✂------

With the modified grammar in place, you can set the scope for
the Reformat Paragraph command to "text.plain.mail markup.quote,
text.plain.mail meta.paragraph". Now you can press ⌃Q anywhere
in a paragraph to rewrap that paragraph. It will even work on
partially-wrapped paragraphs (such as when you wrap and then go back
later to add text in the middle of the paragraph).

Mail bundle maintainer(s), whoever you are, please feel free to
appropriate any or all of these modifications.

-- 
eric



More information about the textmate mailing list