Chinaunix首页 | 论坛 | 博客
  • 博客访问: 385588
  • 博文数量: 39
  • 博客积分: 1771
  • 博客等级: 上尉
  • 技术积分: 1231
  • 用 户 组: 普通用户
  • 注册时间: 2005-05-01 14:21
文章分类

全部博文(39)

文章存档

2013年(1)

2012年(4)

2011年(16)

2010年(6)

2009年(12)

分类: LINUX

2012-02-28 20:29:48

原文链接:Tabify: Change spaces to TABs

The Emacs command M-x tabify will remove space characters and insert TABs, effectively making the file smaller. Tabify only works on a marked region, not on the whole buffer. (A "region" is the area or block of text between the "point" and the "mark" in Emacs.)

tabify uses the current  variable to calculate how many tabs to insert on the line. For example, if you have 5 spaces at the beginning of the line and the tab-width variable is set to '2', tabifywill change those 5 spaces to 2 TABs and one space. If the tab-width variable is set to '4', tabify will change those 5 spaces to one TAB and one space.

Note in particular that tabify will insert TABs throughout the entire line, not just in the spaces at the beginning of the line. If for some reason you only want TABs inserted at the beginning of a line, but no TABs inserted in the spaces after the line starts, use the Emacs command M-x shell-command-on-region, invoking the external GNU utility called "unexpand", which by default only converts spaces to TABs at the beginning of a line, but not within the line. The "unexpand" utility also supports a switch to alter the length of a TAB character.

Untabify: Change TABs to spaces

The Emacs command M-x untabify will change all the TABs in the current region to spaces. This means you must have marked the region first. A "region" is the area between the "point" (cursor) and the "mark", considered as a stream-block rather than a vertical or columnar block.

How many spaces are inserted for each TAB depends on the current  setting, so if the code doesn't seem to be lining up properly, change the tab-width setting to different values until you find one that looks the most nearly correct, and then invoke untabify to convert all the TABs in the marked region to space characters.

Incidentally, the external GNU utility "expand" also converts TABs to spaces, and it has switches to alter the tab-width value, plus a switch to convert TABs to spaces only at the beginning of the line, but not to touch TAB characters in the middle of a line. This is a very useful utility in some circumstances, such as in editing TAB-delimited data files.

阅读(1808) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~