Emacs才是世界上最强大的IDE - 用Emaci阅读文件
相信有很多人平时要阅读大量文件, 而且阅读文件比编辑文件的时间要多的多, 在Emacs里编辑文件的时候, 阅读文件很不方便, 只能用C-v M-v上下滚屏. Emacs下有个view-mode专门是为阅读文件而准备的, 在view-mode里, u向上滚半屏, d向下滚半屏, SPC向下滚一屏, 阅读文件方便多了, 但是还不够, 为什么? 因为经常在阅读文件的时候, 你看到什么不对的地方需要修改, 而在view-mode下, 文件是只读的, 而且有时候, 你在编辑文件的时候, 也需要阅读文件, 那么这两种情况下, 你都要不停的切换view-mode, 非常的不方便, 而且在view-mode里面上下左右移动还得用C-n, C-p, C-f, C-b, 也是非常的不方便, 还有前进一个单词M-f, 后退一个单词M-b, 操作起来都还是很麻烦.
大家都知道vi, 它的快捷键是出名的短, 在vi的命令模式, 上下左右以字符前进是hjkl, 是vi最著名的地方了, 非常方便, 还有它的以单词前进和后退的快捷键w, b, e, 还有好多类似移动光标的命令, 都非常的方便. Emacs下有好多模拟vi的插件, vi-mode就是一个, 它是Emacs内置的, 它模拟了好多vi的特性, 简单的光标移动命令更是当然支持了. 用它来阅读文件的话, 也是不错的, 但是还是有两方面缺点, 一是在vi-mode下好多下, 好多Emacs本身的快捷键就用不了, 比如C-a, C-y等, 二是vi本身固有的缺点(个人观点), 那就是虽然那些快捷键比较短, 但是基本上要在命令模式下运行, 想想, 当你在编辑文件的时候, 想要上下左右移动光标, 然后继续编辑, 再来个上下半屏移动光标, 再来个编辑, 然后再搜索某个单词, 再来个编辑, 就得不停的在编辑模式和命令模式来回切换, 个人觉得非常的不方便, 所以用vi-mode来阅读文件也不是最理想的选择.
鉴于以上理由, 个人自己写了个minor mode, 结合Emacs的优点和部分vi的优点, 所以它的名字Emaci就是由EMACs和vI组成, Emacs占了四个字符, vi却只占了1个字符, 因为Emaci偏向于Emacs的功能更多.
安装好Emaci(只要(require ‘emaci))后, M-x emaci-mode (我把它绑定到了M-s上, 非常方便)进入emaci-mode. 由于大部分情况下打开一个文件浏览的情况比较多, 所以我写了一个函数emaci-exist-file, 这个函数的作用就是判断当前文件是否存在, 存在的话就自动打开emaci-mode, 我把这个函数加到了find-file-hook里面, 这样当你打开一个文件的时候就自动进入了emaci-mode, 打开新文件则不会进入emaci-mode.
进入emaci-mode后, 和vi类似, hjkl上下左右以字符单位移动光标, f, b前进和后退一个单词, I回到行首并且退出emaci-mode, A回到行尾并且退出emaci-mode. 和view-mode类似, u向上滚半屏, SPC向下滚半屏, w向上滚一屏, d向下滚一屏, <和>回到buffer头和buffer尾, 这个也和view-mode一样. g也是回到buffer头, J和K则是向下和向上移动7行, B执行eval-buffer, 1最大化当前window, 2把当前buffer垂直分成两半,3把当前buffer水平非常两半,q退出emaci-mode. 我的配置里,当安装了highlight-symbol后,n向前搜索当前光标处的下一个单词,p则向后搜索,非常方便。这样配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | (defun highlight-symbol-settings-for-emaci () "`highlight-symbol' settings for `emaci'." (eval-when-compile (require 'cl)) ;;;###autoload (defun emaci-n () "Command bind to key n." (interactive) (if (edebug-active) (edebug-next-mode) (if (equal major-mode 'gud-mode) (call-interactively 'gud-next) (call-interactively 'highlight-symbol-next)))) (define-key-list emaci-mode-map `(("p" highlight-symbol-prev)))) (eval-after-load "emaci" `(highlight-symbol-settings-for-emaci)) |
与vi和view-mode相比最大的差异的地方也是我觉得最方便的地方, 是在emaci-mode下也可以进行一些编辑工作, 比如你在浏览某个文件的时候, 发现某一行不需要, 直接用C-k删除即可, 然后再用C-y复制一下刚才拷贝的东西, 当然同样, 可以删除一个区域, 一个单词, 一个字符, 删除字符还可以用vi中的x命令. 这些编辑操作都不需要你退出emaci-mode, 编辑完之后, 用C-x C-s保存即可. 只有当你需要敲一堆文字的时候, 因为可能会涉及到jkhl等快捷键, 这时候才需要用q退出emaci-mode. 这时候你就想了, 那是不是每次编辑之前还要看一下当前是否开了emaci-mode, 那岂不是非常麻烦? 不用担心, 开启了emaci-mode后, mode-line上会显示一个非常显眼的”Emaci”样, 我特地用白底红字标示出来, 就像这样:
当然,这个颜色你也可以控制的,该颜色是由颜色变量emaci-mode-line-face来控制的。
而且, 我一般把M-s绑定到了emaci-mode-on, M-S绑定到emaci-mode-off上面, 这样, 你想编辑的时候按下M-S, 浏览的时候按下M-s, 即使不用看那个白底红字的”Emaci”字样, 也不会出错的. 这点view-mode就不行, 它和其他的minor mode一样, 都是默认的颜色, 我一般开启了好多minor mode, 这样, 你想编辑的时候, 还得盯着mode-line看半天当前是否打开了view-mode.
emaci还对常用的一些mode, 比如view-mode(所以你如果不喜欢在emaci-mode里面能修改文件, 只想只读的阅读文件的话, 可以考虑view-mode, 它的配置文件在这里), Man-mode, apropos, diff-mode, help-mode等定制了通用的hjkl等方便的快捷键, 这些是通过emaci-brief-key-defs变量来控制的, 这个变量是一个list, list的每一个元素是由两个元素构成的list, 第一个元素是快捷键, 快捷键的写法和kbd宏的参数一样, 第二个参数是该快捷键对应的命令, 这个变量默认值如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | (defcustom emaci-brief-key-defs `(("h" backward-char) ("l" forward-char) ("j" next-line) ("k" previous-line) ("J" roll-down) ("K" roll-up) ("b" backward-word) ("w" am-forward-word-or-to-word) ("o" other-window) ("G" end-of-buffer) ("a" move-beginning-of-line) ("e" move-end-of-line)) "Key pairs used bind in modes `emaci-maps-to-bind-brief-keys'. Each element of this variable is two-elements list, and first element is key like argument of `kbd', and second element is command." :type 'list :group 'emaci) |
而待绑定这些快捷键的keymap是由变量emaci-maps-to-bind-brief-keys控制的, 其默认值如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | (defcustom emaci-maps-to-bind-brief-keys `(view-mode-map Man-mode-map apropos-mode-map completion-list-mode-map log-view-mode-map compilation-mode-map diff-mode-map help-mode-map ,(if (>= emacs-major-version 21) 'grep-mode-map) color-theme-mode-map) "List used for `emaci-bind-modes-keys'. Element of this list either a list whose first element is load file, and second element is map, or a string which means load file, or a map." :group 'emaci) |
此变量是一个keymap的list, list中的元素是keymap或者是nil。
如果你修改了以上两个变量后, 执行一下M-x emaci-bind-brief-keys使你的修改生效.
Emaci的配置文件在这里,配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | ;; -*- Emacs-Lisp -*- ;; Time-stamp: <2010-04-19 10:15:52 Monday by ahei> (require 'util) (require 'emaci) (apply-define-key global-map `(("M-s" emaci-mode-on) ("M-S" emaci-mode-off))) (defun emaci-settings () "settings for `emaci'." (eal-define-keys 'emaci-mode-map `(("/" describe-symbol-at-point) ("'" switch-to-other-buffer) ("L" count-brf-lines) ("t" sb-toggle-keep-buffer) ("." find-symbol-at-point) ("," find-symbol-go-back) ("]" goto-paren))) (setq emaci-brief-key-defs (append emaci-brief-key-defs `(("]" goto-paren)))) (emaci-bind-brief-keys) ;;;###autoload (defun switch-major-mode-with-emaci () "Run `switch-major-mode' with `emaci-mode'." (interactive) (let ((emaci emaci-mode)) (call-interactively 'switch-major-mode) (emaci-mode (if emaci 1 -1)))) (eal-define-keys-commonly global-map `(("C-x q" switch-major-mode-with-emaci)))) (eval-after-load "emaci" `(emaci-settings)) (provide 'emaci-settings) |
听完我的介绍, 怎么样, 是不是你也一直期待这样的功能呢, 那赶快试试吧. 这里下载Emaci, Emaci还依赖ahei-misc, eval-after-load两个包,读者均可在DEA里面下载。

a WordPress rating system
The Grizzlies led for most of the game despite playing without Zach Randolph, who missed his fourth straight game with soreness in his right knee. [url=http://www.michaelkorsoutletbuy.us.com]www.michaelkorsoutletbuy.us.com[/url] Underwood: Carrie Underwood: The Storyteller Tour arrives at North Little Rock’s Verizon Arena, 7 p. b [url=http://www.raybansunglassesebay.us.com]ray ban glasses[/url]
Please let me know if there is any action I can take to get my refund. [url=http://www.coachhandbagsdeal.us.com]coach outlet online[/url] The nuclear accord was a victory for Iran’s moderate president, Hassan Rouhani, over hard-liners who sharply opposed reining in the nuclear program.
US Bank, trustee, to Deluca Development Corp., 104 Belvidere St., $52,500. [url=http://www.coachoutletonlinebuy.us.com]coach outlet[/url] Is anything really being learned that is of measureable value to our City?? I fully agree with Mayor Velazquez that a detailed summary of each trip needs to be written and presented publicly to the City Council within a couple of weeks of returning from the trip. b [url=http://www.coachoutletstores.net.co]www.coachoutletstores.net.co[/url]
If you have dark hair, you’ve got to do areally good job or the white powder can leave not-so-attractiveresidue. [url=http://www.coachoutletstoreonline.me]coach outlet store online[/url] Like how new recruits are handed a list of items they need to do.
n DB: Rasul Hall, David Douglas, junior [url=http://www.michaelkorshandbags.us.org]michael kors handbags[/url] Yemen’s war has killed at least 6,200 civilians and injured tens of thousands of Yemenis, and 2. [url=http://www.michaelkorsoutletbuy.us.com]michael kors outlet store[/url]
The Inland Northwest Blood Center says right now they have enough for day to day operations but they’re still concerned. [url=http://www.louisvuittonhandbagsrack.us.com]louis vuitton handbags[/url] It was late on a Thursday night, Jan. http://www.coachoutletssonline.us.org
Anita R. Tranquilli to Nadia Grushetskiy, 61 Greenwich St., $77,000. [url=http://www.raybanoutlet.name]cheap ray bans[/url] Brianna Hanley, LR Central, 1:59. g [url=http://www.coachoutletstores.net.co]coach outlet[/url]
When traveling around Pennsylvania, I always love learning about thehistory of the state that most people never knew. [url=http://www.coachoutletstores.net.co]coach outlet store[/url] Now he paints in shades leaning toward the pastel.
That could easily add another five years or, perhaps, 10 years. [url=http://www.raybansunglasses.name]ray ban sunglasses[/url] We need to all be brothers.
Coachwhip snakes and gopher snakes are occasionally seen as well. [url=http://www.michaelkorsoutletbuy.us.com]michael kors outlet[/url] Sharapova, who said she has taken meldonium for 10 years for health issues, said she neglected to click on a link in a late December email to check the new list of banned substances.
Expand your mind. [url=http://www.michaelkorshandbags.us.org]michael kors handbags[/url] Busch finished fourth, falling a few laps shy of completing a weekend sweep after dominating the Xfinity Series race Saturday.
k One of the tournament’s most anticipated bouts could be the 149-pound final between Penn State’s top-ranked Zain Retherford, of Benton, and Iowa’s second-ranked Brandon Sorensen [url=http://www.cheapmichaelkorsbags.us.com]www.cheapmichaelkorsbags.us.com[/url] “Humane Borders volunteers said they have seen an increase in militia activity in remote areas in Southern Arizona in recent months and reported the incident to the Pima County Sheriff’s Department and the Border Patrol.
Claudio can always score when he is on the pitch, no matter who he is playing against, Werder sports director Thomas Eichin said. [url=http://www.louisvuittonhandbagsbuy.us.com]http://www.louisvuittonhandbagsbuy.us.com[/url] Yes, THAT Cuba. v [url=http://www.coachoutlet.cc]coach outlet online[/url]
The dress must be a solid piece of material from top to bottom (no cut-outs). [url=http://www.louisvuittonhandbagsrack.us.com]louis vuitton handbags[/url] As cool as the new worlds, amazing creatures and awesome action sequences were, the main topic of conversation on the trip back home was about the shocking revelation that Darth Vader was Luke’s father.
d His trips extended beyond Boston and included the Lowell mills and Springfield Armory. He during his trips. [url=http://www.coachoutletstores.net.co]coach outlet store[/url] Saturday at North Locust Avenue and West Spring Street. j
The lentils were perfectly cooked so that they were creamy and popped a little in your mouth. [url=http://www.michaelkorshandbagsoutletup.us.com]http://www.michaelkorshandbagsoutletup.us.com[/url] “That’s why it’s nice to see him coming healthy and hopefully, we can keep him that way. [url=http://www.raybansunglassesebay.us.com]ray ban sunglasses[/url]
Will Gov.-elect Edwards, as governors before him have done, strong-arm state House members into appointing his handpicked choice as Louisiana House Speaker, or will the Republican-controlled chamber flex its GOP muscle and just say no to the bid by New Orleans Democrat Walt Leger? House members, as they regularly do, claim they won’t be the governor’s lapdogs, but in the end they pretty much always go along with whatever the governor or governor-elect want. [url=http://www.michaelkorsoutletbuy.us.com]www.michaelkorsoutletbuy.us.com[/url] It will place more parking near downtown for trail users. g [url=http://www.raybansunglassesebay.us.com]http://www.raybansunglassesebay.us.com[/url]
The company is called Bowen McCauley Dance and tonight’s Working Woman is the founding artistic director [url=http://www.coachoutletstoreonline.me]coach online store[/url] Makley or Clark presented the firemen with $12 as a token of appreciation, and were remembered for their anxiety.
“We’re going to get him in the game in the first half and then see how it goes,” Stotts said. “He’s not going to come in and play 30 minutes. It’s important that he get on the court and get his sea legs and get a feel for being back on an NBA court.” [url=http://www.louisvuittonhandbags.us.org]louis vuitton handbags[/url] The local firm has been ranked #2306, with a threeyear growth rate of 168%. e [url=http://www.michaelkors.us.org]http://www.michaelkors.us.org[/url]
“Misogyny anyone?Strindberg made no secret of his disdain for women, and it becomes abundantly clear in his long and often astonishing preface to this play. [url=http://www.coachoutlet.cc]coach outlet[/url] In the U.
[回复]
Detectives say the 15-year-old told them he bought the gun from an acquaintance a few months after being struck by a bullet in August. An 18-year-old was arrested in that case. cheap jordan shoes One token of that is the appearance of auto executives on turf usually associated with the tech industry such as the CES electronics show in Las Vegas. p coach factory outlet
“It’s always a bit nerve-racking,” Trujillo, 14, later said. coach outlet You get fired, you go to the bench … and it’s not a good feeling.
Walter E. Hawley and Mary L. Hawley to Darla J. Samol, 10 Hayden Road, $65,000. michael kors outlet online Louis will be the eighth franchise to host the Winter Classic. a michael kors outlet
RELATED: LIST: Super Tuesday projected winners coach outlet How about a Go Fund Me account to raise funds for San Juan’s security?
u Yasui grew up in Hood River and moved to Portland after the start of World War II to fight against new restrictions on Japanese-Americans. http://www.michaelkorshandbagstrade.us.com The city of at least 3 million doesn’t even have a mayor because Ghani and Afghanistan’s chief executive, Abdullah Abdullah, have been unable to agree on how to fill thousands of vacant government positions. coach bags
“This challenge has made workforce development a top priority for CAEDC to work with our educators in the region to ensure alignment between education programs, skill certifications and degrees versus the skill sets needed by employers,” Bowser said coach outlet online Bands, marching groups, government entities, western groups, businesses, horses and riders and western vehicles are among the entry categories organizers are seeking, according to Ellen Bilbrey of the parade committee. http://www.coachoutlet.cc
According to Brown’s arrest documents, the senator was at the hotel Saturday with three women – the woman who described herself as his “side friend,” her friend, and the second woman’s daughter. The report did not reveal the ages of the other women. michael kors outlet online Large family? Tom and Suzy Diaz Joe Nieves, Cerina Vincent have seven kids. m ray ban sunglasses
“The Lady in the Van”At Midtown Cinema and Regal Harrisburg Stadium 14. cheap michael kors bags No coach in college basketball history has endured more court-stormings than Duke’s Mike Krzyzewski.
Musician James Friley, also known as Idiot Glee, has added Phoenix’s Lost Leaf to his US tour schedule. http://o.westboroughpolice.com Don’t be too quick to judge a book by its cover, though.
They are not job creators or government revenue generators, but does the county listen to the proven facts? Nope. cheap michael kors bags ESPNWest Virginia vs.
“We think that defeating Proposition 122 is important as it is another bad idea from an Arizona Legislature that has promoted many outlandish and unconstitutional measures to ignore, undermine, weaken, and defund implementation of important federal laws, including the Clean Air Act, the Clean Water Act and the Endangered Species Act,” said Sandy Bahr, director of the Sierra Club’s Grand Canyon Chapter. ray ban outlet Last year, I made the mistake of leaving on Sunday, before the final screenings and the last night of festivities, a mistake I do not intend to repeat.
i Q: I booked two single rooms on the National Geographic Sea Lion expedition to the Columbia and Snake rivers. louis vuitton bags “The restrictions will be in place until the end of the flu season, which typically lasts from December to March, Elliott said.
That’s been a successful approach for us,” Elway said. louis vuitton handbags YAHOO PRIVACY POLICY Registration Data and certain other information about you are subject to our applicable privacy policy. q louis vuitton handbags
But the B1G schedule-maker did them some huge favors and their non-con slate is not that impressive coach outlet online Doc Cons have been tried in other states and some of us Arizona organizers have attended the most famous being in La Plata, Missouri, where we visited the home of Lester Dent, the primary writer of most Doc Savage stories.
q Joseph F. Zuraw to Joseph F. Zuraw and Pearle E. Zuraw, 76 South Maple St., $100. cheap jordan shoes For more information, contact: d
While the California location will be the fourth Tint World? to open up on the West Coast, the Idaho and Mississippi locations will be the first Tint World? stores in their respective states ray ban sunglasses “”But so far, one-and-a-half years (later), they have nothing (to show for) on reconciliation,” he said, adding that in fact the opposite is true. louis vuitton outlet
Friday: Rain likely. Cloudy, with a high near 59. South-southwest wind around 14 mph, with gusts as high as 22 mph. coach factory outlet “We’re not dominant in one area,” Foley said. u http://www.michaelkorsbags.me
But the way Hanger sees it, it’s actually the other way around http://www.coachoutletsonlines.us.org Oregon took a 15-0 lead in an 85-78 victory on March 4, Oregon State scored nine of the first 10 points in a 78-76 overtime victory March 8, and Stanford scored the first nine points the Pac-12 tournament game.
Tickets for the show are priced between $37 and $33 and are available through the or by calling (860) 851-9780. coach outlet “Downton is also a really great example of where we are in media,” Kerger said, “because there are television events that people want to be a part of as they are happening. z michael kors outlet
Stir in garlic, oregano and pepper flakes and cook until fragrant, about 30 seconds. michael kors bags Some of the things families can do to support our younger generation is to be more generous and to start with modeling.
[回复]