首页 > IDE, 初级 > Emacs才是世界上最强的IDE - 用linum+智能显示行号

Emacs才是世界上最强的IDE - 用linum+智能显示行号

2010年4月2日 ahei 发表评论 阅读评论

稍微现代点的编辑器都有行号显示功能,行号显示是在buffer的左侧一栏显示当前buffer每行的行号,比较直观,但其实在以鼠标为中心的编辑器、IDE中,其实这个行号显示功能不大,但是在以纯键盘为中心的编辑器,如vi, Emacs中这个行号显示功能就非常方便了,它可以帮助你迅速定位到某行,知道了行号,直接通过M-x goto-line到达某行,非常方便。

但是Emacs比较“土”,Emacs23之前一直没有内置的行号显示功能,但是“土”归“土”,但是它很听话,你要怎样控制它就怎样控制它,所以诞生了一堆外置的行号显示插件,比如wb-line-number, setnu, setnu-plus, display-line-number, 虽然很多,但是都有一些小bug,不是很方便。Emacs23出来后,我欣喜的看到,它已经内置了行号显示功能,用的是linum-mode,既然是内置的,当然性能比较好,bug也比较少。它每次只显示当前buffer可视区域内的行号,而且用了一个小缓存的技巧,保证了性能,即使打开大文件也没问题。它的行号显示格式是通过linum-format来控制的,该值为’dynamic的话,就会动态控制行号的宽度,比如当前buffer最大行是3位数,那么行号的宽度就是3,这个format还可以设为固定的宽度,比如设置成”%4d”,那么始终显示成4个字符宽度。一般的编辑器用的都是那个’dynamic, 动态控制行号显示的宽度。

但是这个动态显示宽度还不够智能,比如当前buffer最大行的行号是3位数,我显示前面几行行号的时候,比如从1到50,没必要也用3个字符宽度来显示,只需要用2位就可以了,所以我写了一个linum+,来弥补linum这个缺点,linum+主要是重新定义了下linum里面更新行号的函数linum-update-window,代码如下:

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
;;;###autoload
(defun linum+-generate-linum-format (format-type limit)
  "Generate line number format by FORMAT-TYPE, LIMIT is `window-end' of win."
  (cond ((stringp format-type) format-type)
        ((or (listp format-type) (vectorp format-type)
             (eq format-type 'dynamic) (eq format-type 'smart))
         (let* ((dynamic-width (or (vectorp format-type) (eq format-type 'smart)))
                (old-format
                 (if (eq format-type 'dynamic)
                     linum+-dynamic-format
                   (if (eq format-type 'smart)
                       linum+-smart-format
                     format-type)))
                (w (length
                    (number-to-string
                     (line-number-at-pos (if dynamic-width limit (point-max))))))
                (new-format
                 (if (listp old-format)
                     (car old-format)
                   (if (vectorp old-format)
                       (aref old-format 0)
                     old-format))))
           (format new-format w)))))
 
;;;###autoload
(defun linum-update-window (win)
  "Update line numbers for the portion visible in window WIN."
  (goto-char (window-start win))
  (let* ((line (line-number-at-pos))
         (limit (window-end win t))
         (fmt (linum+-generate-linum-format linum-format limit))
         (width 0))
    (run-hooks 'linum-before-numbering-hook)
    ;; Create an overlay (or reuse an existing one) for each
    ;; line visible in this window, if necessary.
    (while (and (not (eobp)) (<= (point) limit))
      (let* ((str (if fmt
                      (propertize (format fmt line) 'face 'linum)
                    (funcall linum-format line)))
             (visited (catch 'visited
                        (dolist (o (overlays-in (point) (point)))
                          (when (equal-including-properties
                                 (overlay-get o 'linum-str) str)
                            (unless (memq o linum-overlays)
                              (push o linum-overlays))
                            (setq linum-available (delq o linum-available))
                            (throw 'visited t))))))
        (setq width (max width (length str)))
        (unless visited
          (let ((ov (if (null linum-available)
                        (make-overlay (point) (point))
                      (move-overlay (pop linum-available) (point) (point)))))
            (push ov linum-overlays)
            (overlay-put ov 'before-string
                         (propertize " " 'display `((margin left-margin) ,str)))
            (overlay-put ov 'linum-str str))))
      (forward-line)
      (setq line (1+ line)))
    (set-window-margins win width)))

其实这个linum-update-window改的很简单,主要是根据当前最大行号来制定一个宽度。
linum+.el全文件在这里下载。
因为只有行号从n位数过度到n+1位数的时候,行号宽度才会发生改变,这种机会并不多,所以我这个linum+性能基本上和linum一样。

linum中, linum-format有可以有三种形式, string, ‘dynamic, 或者函数, 你使用了linum+以后,增加了三种形式, 分别是’smart, 含有一个字符串的list, 和含有一个字符串的vector, string和函数还和linum中的作用一样, ‘dynamic还是根据当前buffer最大行来控制最大的行号宽度, ’smart则是智能根据当前可使范围内最大行号来控制行号显示宽度的, 如果是list的话, 则是根据list中的字符串来和当前最大行号的宽度一起作为format函数的参数来生成当前行号的格式,然后再用这个格式来显示行号,比如当前buffer显示的行数是从1到50,那么最大的行号是50,其宽度是2,list的值为’(“%%%dd|”), 那么当前buffer每行行号的显示格式就是:

1
2
(format "%%%dd|" 2)
        =>"%2d|"

得到”%2d|”,然后当前buffer每行的行号显示格式就是”%2d|”了。
当linum-format为vector的时候, 处理过程基本和list的一样, 唯一的差别就是行号的格式的时候, “%d”是用当前buffer最大行号的宽度去替换的, 比如当前最大行号是125, 其宽度是3, 那么当前buffer每行行号的显示格式就是:

1
2
(format "%%%dd|" 3)
        =>"%2d|"

得到”%3d|”,然后当前buffer每行的行号显示格式就是”%2d|”了。
其实, linum+内部实现时, ‘dynamic和’(“%%%dd|”)作用一样, ’smart和["%%%dd|"]作用一样. 你不喜欢’smart后面的”|”的话, 把linum-format设置为["%%%dd"]就可以了.
如果你喜欢linum中的’dynamic, 根据buffer最大的行号生成固定的宽度, 而不喜欢linum+中’smart那样动态变化的宽度, 你仍然可以把linum-format配置成’dynamic, 或者配置成list, 比如’(“%%%dd”), 这样既可以享受固定的宽度, 又可以享受可配置的格式(linum中linum-format为’dynamic, 行号的格式你是控制不了的)

下面是linum+的截图:

用linum+智能显示行号

用linum+智能显示行号

分享家:Addthis中国
GD Star Rating
loading...
Emacs才是世界上最强的IDE - 用linum+智能显示行号, 8.9 out of 10 based on 7 ratings 标签:autoload, Emacs, face, IDE, linum+, linum-plus, org, screenshot, 截图, 插件, 行号, 鼠标

相关日志

分类: IDE, 初级
  1. 2016年4月7日00:24 | #1

    Mary J. Flaherty, Mary A. Flaherty, John J. Flaherty Jr., Joseph B. Flaherty, William M. Flaherty, Thomas P. Flaherty and Eileen B. Flaherty to Robert Hill and Megan Hill, 32 Ely Ave., $269,000. ray ban sunglasses The girls did a great job of doing that. y michael kors outlet online
    Watch whether Clinton is able to shift her focus from Sanders to the general election and GOP front-runner Donald Trump coach outlet You deglaze the pan with beer, of course, which mingles intimately with the fat and juices released by the burgers to create a delectable pan sauce.
    Oregon’s Royce Freeman remains in contention as college football’s best running back. michael kors online So to you, it might be worth $281,100. k michael kors bags
    All the numbers regarding marijuana use in the NFL — whether for pain relief, concussion prevention or recreation — are anecdotal. louis vuitton outlet Sotelo credited his parents, Anthony and Mindy, for showing him how to conduct himself through different life situations.
    c Tickets for the show are available online through the and by calling (413) 586-8686. coach outlet store “Political pollsters have greatly valued our superior telephone sampling approach. michael kors outlet
    Compassion and Choices is an organization for the right-to-die legislation and says their mission is to improve care and expand choice at the end of life coach handbags “The enigmatic Safin earned two major titles at the 2000 U. http://www.coachoutletssonline.us.org
    Cross streets only at designated crosswalks and corners. Students should not enter a crosswalk until checking to ensure all vehicles have come to a stop, even if the student has the right of way. michael kors outlet The Bible says, “Blessed is the one who trusts in the Lord” Psalm 40:4. s http://www.raybansunglassesbuy.co.uk
    Goodman Stadium is home to the Lehigh University football team louis vuitton outlet online The film, which opens Friday, is a blend of tones broadly funny, dramatically tender and populated by veteran performers like Tyne Daly, Stephen Root and Peter Gallagher.
    True Bowie fans and music aficionados may scoff at my ignorance, but his ability to stand as both a pillar of entertainment and as a cosmic wizard behind the curtain, perpetually rediscovered, now transcends Bowie’s own mortality. louis vuitton handbags Artillery shells struck Tuesday near the main street of a Syrian village controlled by the government.
    “If you’re looking for a relaxing break from the daily grind, look no further than Cas Haley’s new album ‘More Music, More Family. ray ban sunglasses Pac-12ATulane vs.
    While sports are a big part of the culture of San Benito County and its schools, I see no evidence that they are more important. coach factory outlet store “But with the hard work I put in, I felt I earned everything.
    i WASHINGTON (AP) Antti Raanta made 32 saves while subbing for the injured Henrik Lundqvist and Derek Stepan scored as the New York Rangers bounced back from a loss in Pittsburgh to beat the Washington Capitals 3-2 Friday night michael kors outlet After a health scare in November, he predicts being at 100 percent “in a few days.
    Offensive linemen who hit the market will notice that ’s contract is worth about $12 million a year, an enormous bump up from the previous high for a guard (’s $8 million average) and they won’t be settling for $8 million anymore. michael kors outlet online tumblr. n michael kors outlet store
    By the way, depending on how many chickens you have, you may be getting significant additional fertilizer from them. http://www.coachhandbags.net.co Remember that the county education system is getting more than 65 cents of every city property tax dollar – on of the highest percentages in the entire state.
    b Pintu’s Indian Palace ray ban sunglasses All set for first race since winning Robert B. c
    Playing partners were Gary Babbit, Ollie Booth and Bob Wigand. michael kors outlet online What about the loss of Andrew Andrews, you say? The Huskies have a better prospect at point guard, incoming freshman Markelle Fultz. michael kors outlet
    Lt. Kathy McNicholas, spokeswoman, said officers found a “man down” when they arrived, but declined to elaborate. ray ban sunglasses outlet For more information, visit Allergan s website at . a ray ban sunglasses outlet
    Serrano-Vitorino, 40, was deported in April 2004 because he was in the country illegally, but he re-entered at some unknown time, ICE said by email http://www.michaelkorshandbagsrack.us.com “This is Arivaca; we all have different ideas,” said Jim Chilton, a fifth-generation Arizona cattleman.
    Welter said Roseburg probably would have been host to Saturday’s semifinals, and possibly a Crater-Ashland final, but the school is undergoing significant renovation and the stadium is unavailable. michael kors bags Andrew Cuomo called Garrett a “visionary leader. w michael kors outlet online
    The Fairbanks Daily News-Miner reports that 24-year-old Nolan Youngmun, of Anchorage, had been charged with first and second degree sexual assault after the woman claimed he raped her on April, 5 2015. http://www.coachoutletsonlines.us.org “I’m not sleeping as well at night,” Thomas joked when he got word of Fowler’s exploits.

    [回复]

  2. 2016年4月7日10:38 | #2

    The Ducks were 3-3 after an October 10 loss at home to Washington State. The UO defense was abysmal and the offense struggling to gain traction with transfer quarterback Vernon Adams sidelined with a broken finger. [url=http://www.michaelkorsbags.me]michael kors bags[/url] The Clinton School event will also be livestreamed at http://clintonschool. g [url=http://www.michaelkorshandbags.us.org]http://www.michaelkorshandbags.us.org[/url]
    ” The suit, filed by attorneys Hunter Shkolnik and Adam Slater, claims that the defendants acted recklessly and with negligence. [url=http://www.louisvuitton-outlet.us.org]louis vuitton handbags[/url] True creativity doesn’t come from outside, from a formula.
    Anthony Mancinone to Nicola Difilippo and Emilio Mancuso, 685-689 James St., $65,000. [url=http://www.michaelkorsoutletbuy.us.com]http://www.michaelkorsoutletbuy.us.com[/url] The Vertical s Senior Writer Chris Mannix and Front Office Insider Bobby Marks dive deep into Cleveland s personnel woes, OKC s coaching puzzle and a necessary paradigm shift for Phil Jackson. q [url=http://www.coachoutletonlinebuy.us.com]coach outlet online[/url]
    Anyways, the 20 players chosen were (in order of their voterankings): Phil Ivey Daniel Negreanu Doyle Brunson Phil Hellmuth Chris Ferguson Allen Cunningham Johnny Chan Scotty Nguyen Barry Greenstein John Juanda Erik Seidel Jennifer Harman Huck Seed Dan Harringtonvideo-ad-asset-container, video-ad-asset-container-played max-height: 0px; overflow: hidden; -webkit-transition: max-height 1s; -moz-transition: max-height 1s; transition: max-height 1s;video-ad-asset-container. [url=http://www.louisvuittonhandbagsrack.us.com]louis vuitton handbags[/url] ” We show them a cartoon called S?dan f?r man alts? b?rn that brings everything down to a level that children can understand without censoring things unnecessarily.
    h The Tigers haven’t ruled out Mick Billmeyer as a potential replacement, but he’s considered a long shot and is likely to remain in his role as Detroit’s bullpen coach. [url=http://www.coachoutletssonline.us.org]coach outlet online[/url] They include raising the age of criminal responsibility from 16 to 18 and allowing judges to consider whether a person is truly dangerous when setting bail, something now done routinely in many states, but not in New York. [url=http://www.louisvuittonhandbagsbuy.co.uk]louis vuitton outlet online[/url]
    Immigration commanded considerable attention for good reason: Florida is home to nearly 1. [url=http://www.michaelkorsbag.us.org]michael kors bags[/url] Jan. http://www.michaelkorsbag.us.org
    Michael F. Archambault and Keffrey B. Skipton to Neil K. Bonsteel, 73 Bridge St., $189,000. [url=http://www.michaelkorsbags.me]michael kors bags[/url] Tickets: $10, AAC members $8. s [url=http://www.louisvuittonhandbags.us.org]www.louisvuittonhandbags.us.org[/url]
    Little Harper James has conquered more obstacles in her first four and a half months on this earth than many will face in a lifetime [url=http://www.louisvuittonhandbagsbuy.us.com]louis vuitton handbags[/url] Judge Garye Vasquez of the Arizona Court of Appeals Division II also won his retention vote.
    First, the Eagles got out of the Byron Maxwell mega-deal by sending him and linebacker Kiko Alonso to the Miami Dolphins. [url=http://www.coachhandbagsdeal.us.com]coach handbags[/url] Have we reached the point of no return?
    With respect to Content other than photos, graphics, audio or video you submit or make available for inclusion on publicly accessible areas of the Yahoo Services other than Yahoo Groups, the perpetual, irrevocable and fully sublicensable license to use, distribute, reproduce, modify, adapt, publish, translate, publicly perform and publicly display such Content (in whole or in part) and to incorporate such Content into other works in any format or medium now known or later developed. [url=http://www.michaelkorsbags.me]michael kors bags[/url] “The wind made it tough, but I was to stay strong physically and mentally.
    Fines also were assessed — a team fine of $250,000, with head coach Andy Reid fined $75,000 and general manager John Dorsey fined $25,000. [url=http://www.coachoutlet.cc]www.coachoutlet.cc[/url] No sanitizer at threecompartment sink.
    v “Obviously we wish it hadn’t happened, (and) we’d love to discuss with ICE why it happened,” he said [url=http://www.michaelkorshandbagsoutletup.us.com]michael kors outlet[/url] 6 percent from the field and making 11 of 22 three-pointers, both beating the Wildcats off the dribble and sinking shots over their defense.
    com/thumbor/TZprzVOwg_0CHckUAznxherdZyM=/cdn0. [url=http://www.louisvuittonhandbags.us.org]louis vuitton handbags[/url] Dirk Nowitzki, Ricky Rubio, and Kristaps Porzingis are all examples. b [url=http://www.coachhandbagsdeal.us.com]coach outlet online[/url]
    Agregó que el trabajo lo elaboran más de 30 compa?ías para obtener un mejor diagnóstico de la prueba del zika, ya que las pruebas actuales con frecuencia mezclan infecciones de dengue y zika. [url=http://www.raybansunglassesbuy.co.uk]ray ban sunglasses[/url] I was not aware of the social media animosity going on in some quarters.
    y “A Christmas Dance” (2012), 2 p.m. Dec. 7, Hallmark. [url=http://www.cheapchinajerseysnfl.us.org]nfl jerseys[/url] McIlroy shot a 65 for his share of second place after two rounds, and Danny Willett was alone in fourth at 7 under. e
    News World Report, as well as being named a “Top Workplace” by Philly. [url=http://www.michaelkorsbags.me]michael kors outlet online[/url] New York’s Eli Manning went 27 for 31 for 337 yards and four scores. [url=http://www.louisvuittonbagsbuy.us.com]www.louisvuittonbagsbuy.us.com[/url]
    Schweickhard E. Von Goeler and Adelheid Von Goeler to Virginia D. Golay and Ronald B. Golay, 9-11 Cole Road, $417,000. [url=http://www.michaelkorsbag.us.org]michael kors bags[/url] Who: Chilirhea s [url=http://www.michaelkorsoutletbuy.us.com]http://www.michaelkorsoutletbuy.us.com[/url]
    Danny Amendola, WR, Buffalo: When Julian Edelman went down, Amendola jumped to the top of the list of sexy waiver wire pick-ups. [url=http://www.cheapjordanshoes.us.org]cheap jordan shoes[/url] He bunted so well,” Kellner said.
    – Nick Budnick [url=http://www.raybansunglasses.name]ray ban sunglasses[/url] III59 AsiaPacific Growth Engine of Global SUV Market III59 Outlook. k [url=http://www.cheapmichaelkorsbags.us.com]michael kors outlet[/url]
    comwatch?v=fdI0zYOXz2s ” data-embed-type youtube” id ui-id-7″sd-embed [url=http://www.louisvuitton-outlet.us.org]louis vuitton outlet[/url] “”I am sorry, if you are running a $30 million a year sole enterprise you better make sure the basis for that commercial success, if nothing else, remains unassailable,” Pound added in the interview with the AP on the sidelines of the Tackling Doping in Sport conference at Twickenham Stadium.

    [回复]

评论分页
1 2 3 4 41085
  1. 2011年11月15日00:25 | #1
  2. 2011年11月20日00:04 | #2
:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!: