Mickey on Polymode

微信扫一扫,分享到朋友圈

Mickey on Polymode

If you’ve been paying attention to the Emacs scene, you may have heard about Polymode
, a package that lets you have two or more active major
modes associated with a buffer. The first question to occur to many is, “Why would I want that?”

Not to worry, the incomparable Mickey is here to explain it all
. There are, it turns out, legitimate use cases for multiple major modes in a single buffer. I’m an old-timey, backend sort of guy so I’ve been spared having to deal with those use cases but for those not so fortunate, Polymode can be a real win.

The basic idea is that you want to deal with two (or more) different languages in the same buffer—Mickey uses the example of Python and SQL. The indentation and font-locking are, of course, different for the two languages and you’d like Emacs to do the right thing automatically. That’s what Polymode does. It detects where one language leaves off and another starts and adjusts the operative major mode accordingly. A configuration that handles a given set of languages is called a “polymode.”

The bad news is that although there are, apparently, a few polymodes already written, by and large you’re going to have to write your own for most things. The good news is that writing a new polymode is pretty simple and generally takes just a few lines. Mickey’s post shows how it’s done by creating a Python/SQL polymode. Doubtlessly, more prebuilt polymodes will start to appear once the package starts getting traction.

If the need for this or the ideas behind it are unclear to you, take a look at Mickey’s post. As usual, he does an excellent job of explaining everything. As a bonus, if you’re not British, you may, like me, learn a new word: bijou
. How can you lose?

微信扫一扫,分享到朋友圈

Mickey on Polymode

WebGL month. Day 2: Shaders and points

上一篇

The Day “/Proc” Died

下一篇

你也可能喜欢

Mickey on Polymode

长按储存图像,分享给朋友