首页 > mode-line, 中级 > Emacs的状态栏 - mode-line

Emacs的状态栏 - mode-line

2009年11月17日 ahei 发表评论 阅读评论

Emacs中的mode-line是指每个buffer下面的那一行显示buffer相关信息的区域, 相当于一般windows程序中的状态栏, 而它的格式则是由mode-line-format来控制, 这个mode-line-format非常灵活, 可以任意定制.

mode-line-format可以为nil, 字符串, 符号, 列表, cons cell.

  • nil的话很显然就表示啥都不显示, 多出了空间, 但是毕竟buffer中的相关信息都显示不了, 还是不方便.
  • 字符串的话, 和c语言中printf格式类似, %结构含义如下:
    %b — 打印buffer名字
    %f — 打印buffer对应的文件名字
    %F — 打印frame名字
    %* — 根据buffer是否只读, 是否已修改显示%,*,或连字符(-)
    %+ — 根据buffer是否只读, 是否已修改显示*,%,或连字符(-)
    %& — 和%*类似, 不过忽略buffer的只读状态
    %表示buffer只读, *表示buffer已修改, 对于只读buffer, %*打印%, 而%+打印*.
    %s — 打印buffer对应的进程状态
    %l — 打印当前行号
    %c — 打印当前列号, 不过`column-number-mode’必须打开
    %i — 打印当前buffer大小
    %I — 和%i类似, 不过使用k,M,G等单位来显示buffer大小
    %p — 显示当前位置的百分比, 光标在buffer顶端时显示Top, 在低端时显示Bot, 如果一屏能显示完所有buffer中的内容, 则显示All
    %P — 正好与%p相反
    %n — 显示当前buffer是否为Narrow状态
    %t — 当前buffer对应的文件是文本文件还是二进制文件
    %z — 显示输入法, 终端和buffer的编码
    %Z — 与%z类似, 不过还包括显示文件是dos格式还是unix格式
    %e — 当内存占满后, 会显示错误消息
    %@ — 如果当前buffer对应的文件为远程机器上的文件, 则显示@, 否则显示连字符(-)
    $[ -- 对每一次递归编辑, 显示[, $]与此类似
    %% — 显示%
    %- — 显示能足够多的连字符(-)
    与printf中的格式类似, %后面跟的数字限制将要显示的数据的宽度.
  • 符号的话, 根据符号的值分为以下几种情况:
    1. 字符串, 直接把字符串显示在mode-line上, 即使字符串里面含有%结构, 而且这个字符串的文本属性
      将会被忽略, 除非它被标记为`risky-local-variable’.
    2. (eval :FORM), 对FORM进行求值后, 根据求值后的值的类型来进行递归处理, 这里的FORM是任意的elisp代码, 所以能非常灵活的控制mode-line.
    3. `(:propertize ELT PROPS…), 显示指定属性后的字符串, 这样可以以丰富的色彩把字符串显示在mode-line上
    4. 列表的car为符号, 如果这个car不为nil, 则这个列表的cdr被递归处理, 否则这个列表的cddr被递归处理.
    5. 列表的car为字符串或者列表, 那么这个列表的每一个元素被递归处理, 然后再把每一个元素处理后的结果连接起来.
    6. 列表的car为整数, 对列表的cdr进行递归处理, 如果列表的car为正, 则把处理后的结果连在后面, 否则根据长度进行截断.

我上面所说的基本上是翻译mode-line-format的docstring, 英文还可以的同志可以去看docstring, M-x describe-variable mode-line-format.

具备了上面的知识, 我们现在可以对mode-line做一些高级的控制了, 比如在mode-line上用彩色显示当前buffer行数, 这个功能很方便,一眼就能看到当前buffer行数,就像下面这样:

mode-line

mode-line


mode-line

mode-line


mode-line-format的%结构只提供了%p显示当前位置功能,还有%l和%c显示当前行号和列号的功能,就是没有显示当前buffer行数的功能。我配置后的mode-line, 当你选中一块区域后, 会高亮显示这个区域有多少个字符, 没有选中区域的时候, 则显示当前buffer的大小,下面是效果图:
mode line chars

mode line chars


另外用与控制frame标题的frame-title-format的结构与mode-line-format完全相同.

mode-line的配置文件在这里
下面是我的mode-line配置,用彩色显示当前buffer行数的主要是函数`get-lines-4-mode-line’.

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
;; -*- Emacs-Lisp -*-
 
;; Time-stamp: <2009-11-22 17:49:25 Sunday by ahei>
 
;; 在mode-line上用彩色显示当前buffer行数
(defun get-lines-4-mode-line ()
  (let ((lines (count-lines (point-min) (point-max))))
    (concat (propertize
             (format "%dL" lines)
             'mouse-face 'mode-line-highlight
             ;; 加上颜色
             'face 'mode-line-lines-face
             'help-echo (format "%d lines" lines)) " ")))
 
(size-indication-mode 1)
(setq-default mode-line-buffer-identification (propertized-buffer-identification "%b"))
 
(if is-after-emacs-23
    (setq-default
     mode-line-position
     `((:eval (get-lines-4-mode-line))
       (1 ,(propertize
            "%p"
            'local-map mode-line-column-line-number-mode-map
            'mouse-face 'mode-line-highlight
            'help-echo "Size indication mode\n\
mouse-1: Display Line and Column Mode Menu"))
       (size-indication-mode
        (" "
         (:eval
          (propertize
           (if (and transient-mark-mode mark-active)
               (format "%d chars" (abs (- (mark t) (point))))
             "%I")
           'face (and transient-mark-mode mark-active 'region)
           'local-map mode-line-column-line-number-mode-map
           'mouse-face 'mode-line-highlight
           'help-echo "Buffer position, mouse-1: Line/col menu"))))
       (line-number-mode
        ((column-number-mode
          (1 ,(propertize
               " (%l,%c)"
               'local-map mode-line-column-line-number-mode-map
               'mouse-face 'mode-line-highlight
               'help-echo "Line number and Column number\n\
mouse-1: Display Line and Column Mode Menu"))
          (1 ,(propertize
               " L%l"
               'local-map mode-line-column-line-number-mode-map
               'mouse-face 'mode-line-highlight
               'help-echo "Line Number\n\
mouse-1: Display Line and Column Mode Menu"))))
        ((column-number-mode
          (1 ,(propertize
               " C%c"
               'local-map mode-line-column-line-number-mode-map
               'mouse-face 'mode-line-highlight
               'help-echo "Column number\n\
mouse-1: Display Line and Column Mode Menu")))))))
  (let* ((help-echo "mouse-1: select (drag to resize), mouse-2 = C-x 1, mouse-3 = C-x 0"))
    (setq-default
     mode-line-position
     `((:eval (get-lines-4-mode-line))
       (1 ,(propertize "%p" 'help-echo help-echo))
       (size-indication-mode
        (1 ,(propertize " %I" 'help-echo help-echo)))
       (line-number-mode
        ((column-number-mode
          (1 ,(propertize " (%l,%c)" 'help-echo help-echo))
          (1 ,(propertize " L%l" 'help-echo help-echo))))
        ((column-number-mode
          (1 ,(propertize " C%c" 'help-echo help-echo)))))))))
 
(let* ((help-echo
        "mouse-1: Select (drag to resize)\n\
mouse-2: Make current window occupy the whole frame\n\
mouse-3: Remove current window from display")
       (recursive-edit-help-echo "Recursive edit, type C-M-c to get out")
       (standard-mode-line-modes
        (list
         " "
         (propertize "%[" 'help-echo recursive-edit-help-echo)
         (propertize "(" 'help-echo help-echo)
         `(:propertize ("" mode-name)
                       help-echo "Major mode\n\
mouse-1: Display major mode menu\n\
mouse-2: Show help for major mode\n\
mouse-3: Toggle minor modes"
                       mouse-face mode-line-highlight
                       local-map ,mode-line-major-mode-keymap)
         '("" mode-line-process)
         `(:propertize ("" minor-mode-alist)
                       mouse-face mode-line-highlight
                       help-echo "Minor mode\n\
mouse-1: Display minor mode menu\n\
mouse-2: Show help for minor mode\n\
mouse-3: Toggle minor modes"
                       local-map ,mode-line-minor-mode-keymap)
         (propertize "%n" 'help-echo "mouse-2: Remove narrowing from the current buffer"
                     'mouse-face 'mode-line-highlight
                     'local-map (make-mode-line-mouse-map
                                 'mouse-1 #'mode-line-widen))
         (propertize ")" 'help-echo help-echo)
         (propertize "%]" 'help-echo recursive-edit-help-echo))))
  (setq-default mode-line-modes standard-mode-line-modes)
  (setq-default mode-line-format
                `("%e%t"
                  mode-line-mule-info
                  mode-line-client
                  mode-line-modified
                  mode-line-remote
                  " "
                  mode-line-buffer-identification
                  ,(propertize " " 'help-echo help-echo)
                  mode-line-position
                  (vc-mode vc-mode)
                  mode-line-modes
                  (which-func-mode (" " which-func-format))
                  (working-mode-line-message (" " working-mode-line-message))
                  ,(propertize "-%-" 'help-echo help-echo))))
 
(setq mode-line-format-bak mode-line-format)
(setq mode-line t)
(defun toggle-mode-line ()
  "Toggle mode-line."
  (interactive)
  (if mode-line
      (setq-default mode-line-format nil)
    (setq-default mode-line-format mode-line-format-bak))
  (setq mode-line (not mode-line)))
 
;; 在标题栏显示登陆名称和文件名
(setq frame-title-format
      '((:eval
         (let ((login-name (getenv-internal "LOGNAME")))
           (if login-name (concat login-name "@") "")))
        (:eval (system-name))
        ":"
        (:eval (or (buffer-file-name) (buffer-name)))))
分享家:Addthis中国
GD Star Rating
loading...
Emacs的状态栏 - mode-line, 9.2 out of 10 based on 9 ratings 标签:ahei, buffer, DEA, Elisp, Emacs, face, highlight, IDE, keymap, lightbox, lisp, mode, mode-line, screenshot, se, top, windows, 光标, 定制, 截图, 状态栏, 翻译, 行号, 配置, 配置文件, 颜色

相关日志

分类: mode-line, 中级
  1. hello
    2012年8月8日14:57 | #1

    用了你的mode-line-settings以后,display-time就没有效果了,无法显示时间,我用的vimpulse也没有和的切换显示了,请问怎么解决?

    [回复]

  2. 2016年4月7日09:14 | #2

    There have been eight murders and more than 220 bombings and arson attacks at abortion facilities in the U.S. since 1977, according to the National Abortion Foundation. Two Planned Parenthood receptionists were killed in 1994 at clinics in Brookline, Massachusetts. ray ban sunglasses “I didn’t consider him a student guy who people threw towels at. y coach outlet store
    That starts with determining the kind of weeds you’re getting and where they’re coming from michael kors outlet online “I think trying to keep greenhouse gas concentrations on the more moderate end really does matter,” he said.
    No 48 louis vuitton handbags Under no circumstances will Yahoo be liable in any way for any Content, including, but not limited to, any errors or omissions in any Content, or any loss or damage of any kind incurred as a result of the use of any Content posted, emailed, transmitted or otherwise made available via the Yahoo Services. q louis vuitton outlet
    Talk of the presidential election was otherwise largely absent the ceremony, though Vice President Joe Biden (whose presence added even greater security to the Dolby Theatre) was met by a standing ovation before talking about sexual assault on college campuses before introducing best-song nominee Lady Gaga cheap louis vuitton bags Either way, watching the film with the Man of Bronze himself will be a treat!What does Doc-Con have to offer for pop culture fans not familiar with Doc Savage and his heroic legacy?The most praised feature of Doc Con is the comradery that we as fans naturally extend to all new attendees, but the common denominator is still the enjoyment we felt when reading the Doc Savage stories.
    l “We’ve always assumed that tomorrow or next year is going to look like today does,” says Gunn. “We’ve built structures and societies and cultures and farming communities in ways that depend on tomorrow being the same as today. We believe, and I personally believe, that it won’t be and so we need to prepare for that.” http://www.louisvuittonhandbagsbuy.co.uk It said she wasn’t a signatory on any bank account for Metro or Dwyer and wasn’t authorized to sign company checks except when Dwyer approved her use of Dwyer’s inked signature stamp. coach factory outlet
    This one is the finest certified survivor. coach outlet store online He continued to play solid defense at shortstop, recording a career-best . http://www.raybansunglassesbuy.co.uk
    Old Navy Outlet http://www.michaelkorshandbagstrade.us.com The 28th annual induction luncheon is set for 11:30 a. x coach factory outlet
    ALSO SEE: Tesla wins fight with GM in Indiana, but there’s more to come coach outlet You have to have a motivation.
    It’s a move DeRay McKesson, a leader of the Black Lives Matter movement who is running for mayor of Baltimore, says “is good for the city of Baltimore. louis vuitton outlet The race was decided in the primary election because no one else filed as a candidate for the position.
    Blues chairman Tom Stillman says he initially expected the Blues to host a Stadium Series game, but that changed when the NFL’s Rams left for Los Angeles. coach outlet store ” But, buoyed by more respectable picks in recent years and a three-year hosting stint by Tina Fey and Amy Poehler, the boozy Globes have been on the rise.
    If you encounter a problem that throws you for a loop, head online to see if you can find answers. michael kors outlet Critical violations: Employee went from handling dirty silverware to handling clean trays and did not wash hands between tasks.
    p On Tuesday, he’dmet with “political operatives” connected to Wagner who offered him judgeships or lucrative state work if he dropped his candidacy michael kors outlet Old Pueblo Trolley bought a 27,146-square-foot building at 250 E.
    Fans of suspense will have the chance to meet one of the great authors of the genre. coach outlet store online Children looking to land the role must be between 8-13 years old and measuring between 4 feet, 5 inches and 4 feet, 10 inches tall. x oakley sunglasses
    LOS ANGELES (AP) – Those who worked with former US President Ronald Reagan say Nancy Reagan was intelligent and loyal to her husband 锘?a href=http://www.michaelkors.us.org>michael kors outlet More than 150 restaurants, the bulk of them in the Valley but some in Tucson, too, offer a three-course dinner menu for $30-$40 per person.
    d Nothing was different about the lead up to the game, our preparation was consistent as always. It was as simple as just not coming out and playing fast. coach outlet store online A key feature is a table, built by my grandfather, originally used as a kitchen island in my grandparents’ old house. b
    They became very popular in the last quarter of the 20th century and can be found in many cities and towns as a street tree. coach outlet Authorities also confiscated 15 assault weapons, three handguns and more than 500 pounds of marijuana. louis vuitton bags
    To borrow from Orwell, the ISIS picture of the future is whipping the non-conforming women of Raqqa — forever. michael kors outlet online SportsHub will operate the games under the trade name “CDM Sports. y ray ban sunglasses outlet
    We sailed with champagne glasses in hand and strains of “The Love Boat” theme seeping into our ears. coach outlet Pat Welchert, with Picor, represented the landlord and Jesse Blum, with CBRE, represented the tenant.
    There is no evidence that the foods would be unsafe, but for some, it’s an ethical issue. michael kors handbags But if Mitt Romney’s words this week can be repeated, over and again, maybe enough voters will see the light. r coach outlet online
    But he says the FBI, in seeking access to a phone used by one of the San Bernardino attackers, is asking a judge to “give them something we don’t have” and to create an operating system that does not exist coach outlet online He would bar all Muslims from entering the country until further notice.

    [回复]

评论分页
1 2 35281
  1. 2014年2月10日05:59 | #1
  2. 2014年6月5日11:08 | #2
:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!: