├── .gitignore ├── AUTHORS ├── README.rst └── powerline.el /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.elc 3 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Jonathan Chu 2 | Justine Tunney 3 | Prakash Kailasa 4 | Okasu 5 | Hans Engel 6 | Yesudeep Mangalapilly 7 | Jason Filsinger 8 | @katspaugh 9 | Anatoly Smolyaninov 10 | Philippe Vaucher 11 | Igor Shymko 12 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | =============== 2 | Emacs Powerline 3 | =============== 4 | 5 | This is a fork of powerline.el from `http://www.emacswiki.org/emacs/powerline.el `_, which is ultimately inspired by `vim-powerline `_. 6 | 7 | Installation 8 | ------------ 9 | 10 | There are a number of ways to do this correctly. If you're comfortable with doing it your own way, please skip this section. If not, this is the recommended and tested way that I got it working. 11 | 12 | :: 13 | 14 | $ cd ~/.emacs.d/vendor 15 | $ git clone git://github.com/jonathanchu/emacs-powerline.git 16 | 17 | In your Emacs config: 18 | 19 | :: 20 | 21 | (add-to-list 'load-path "~/.emacs.d/vendor/emacs-powerline") 22 | (require 'powerline) 23 | 24 | *Note: Depending on what distribution of Emacs you're using, you might have to do:* 25 | 26 | :: 27 | 28 | (require 'cl) 29 | 30 | Customization 31 | ------------- 32 | 33 | You can choose between different arrow shapes: 34 | 35 | :: 36 | 37 | (setq powerline-arrow-shape 'arrow) ;; the default 38 | (setq powerline-arrow-shape 'curve) ;; give your mode-line curves 39 | (setq powerline-arrow-shape 'arrow14) ;; best for small fonts 40 | 41 | You can change the mode-line color using the standard method: 42 | 43 | :: 44 | 45 | (custom-set-faces 46 | '(mode-line ((t (:foreground "#030303" :background "#bdbdbd" :box nil)))) 47 | '(mode-line-inactive ((t (:foreground "#f9f9f9" :background "#666666" :box nil))))) 48 | 49 | Additionally, you can modify directly in `powerline.el`: 50 | 51 | :: 52 | 53 | (setq powerline-color1 "grey22") 54 | (setq powerline-color2 "grey40") 55 | 56 | Change the :foreground, :background, powerline-color1, powerline-color2 to whatever you wish. 57 | 58 | 59 | Screenshots 60 | ----------- 61 | 62 | .. image:: http://i.imgur.com/CECRc.png 63 | 64 | Comments/Feedback 65 | ----------------- 66 | 67 | Suggestions for any modifications, please feel free to fork and contribute! 68 | 69 | Please file bugs at `https://github.com/jonathanchu/emacs-powerline/issues `_. 70 | -------------------------------------------------------------------------------- /powerline.el: -------------------------------------------------------------------------------- 1 | ;;; powerline.el --- fancy statusline 2 | 3 | ;; Name: Emacs Powerline 4 | ;; Author: Unknown 5 | ;; Version: 1.0 6 | ;; Keywords: statusline 7 | 8 | ;;; Commentary: 9 | 10 | ;; This package simply provides a minor mode for fancifying the status line. 11 | 12 | ;; Modified by: Jonathan Chu 13 | 14 | ;;; Code: 15 | 16 | (require 'cl) 17 | 18 | (defvar powerline-color1) 19 | (defvar powerline-color2) 20 | 21 | (setq powerline-color1 "grey22") 22 | (setq powerline-color2 "grey40") 23 | 24 | (set-face-attribute 'mode-line nil 25 | :background "OliveDrab3" 26 | :box nil) 27 | (set-face-attribute 'mode-line-inactive nil 28 | :box nil) 29 | 30 | (defun get-arrow-dots 31 | (leftp width height) 32 | (let* ((halfheight (/ height 2))) 33 | (mapconcat 34 | (apply-partially 'format "\"%s\"") 35 | (mapcar 36 | (lambda (n) 37 | (let* ((nx (if (< n halfheight) n (- height n))) 38 | (dots (make-string nx ?.)) 39 | (spaces (make-string (- width nx) ? ))) 40 | (if leftp 41 | (concat dots spaces) 42 | (concat spaces dots)))) 43 | (arrow-number-sequence height)) 44 | ",\n"))) 45 | 46 | (defun arrow-number-sequence 47 | (height) 48 | (if (oddp height) 49 | (number-sequence 1 height) 50 | (let* ((halfheight (/ height 2))) 51 | (append 52 | (number-sequence 1 halfheight) 53 | (cons halfheight (number-sequence (1+ halfheight) (1- height))))))) 54 | 55 | (defun get-arrow-xpm 56 | (direction width height &optional color1 color2) 57 | "Create an XPM left arrow." 58 | (let* ((leftp (eq 'left direction)) 59 | (fg (if leftp color1 color2)) 60 | (bg (if leftp color2 color1))) 61 | (create-image 62 | (format "/* XPM */ 63 | static char * arrow_left[] = { 64 | \"%d %d 2 1\", 65 | \". c %s\", 66 | \" c %s\", 67 | %s};" 68 | width height 69 | (if fg fg "None") 70 | (if bg bg "None") 71 | (get-arrow-dots leftp width height)) 72 | 'xpm t :ascent 'center))) 73 | 74 | (defun mode-line-height () 75 | "The mode line height with its current font face." 76 | (- (elt (window-pixel-edges) 3) 77 | (elt (window-inside-pixel-edges) 3))) 78 | 79 | (defun proportional-arrow-xpm 80 | (direction color1 color2) 81 | (let* ((r 1.5) 82 | (m-height (mode-line-height)) 83 | (height (if (evenp m-height) m-height (+ 1 m-height))) 84 | (width (floor (/ height r)))) 85 | (get-arrow-xpm direction width height color1 color2))) 86 | 87 | (defun arrow-left-xpm 88 | (color1 color2) 89 | "Return an XPM left arrow string representing." 90 | (proportional-arrow-xpm 'left color1 color2)) 91 | 92 | (defun arrow-right-xpm 93 | (color1 color2) 94 | "Return an XPM right arrow string representing." 95 | (proportional-arrow-xpm 'right color1 color2)) 96 | 97 | (defun curve-right-xpm 98 | (color1 color2) 99 | "Return an XPM right curve string representing." 100 | (create-image 101 | (format "/* XPM */ 102 | static char * curve_right[] = { 103 | \"12 18 2 1\", 104 | \". c %s\", 105 | \" c %s\", 106 | \" .\", 107 | \" ...\", 108 | \" ...\", 109 | \" .....\", 110 | \" .....\", 111 | \" .....\", 112 | \" ......\", 113 | \" ......\", 114 | \" ......\", 115 | \" ......\", 116 | \" ......\", 117 | \" ......\", 118 | \" .....\", 119 | \" .....\", 120 | \" .....\", 121 | \" ...\", 122 | \" ...\", 123 | \" .\"};" 124 | (if color2 color2 "None") 125 | (if color1 color1 "None")) 126 | 'xpm t :ascent 'center)) 127 | 128 | (defun curve-left-xpm 129 | (color1 color2) 130 | "Return an XPM left curve string representing." 131 | (create-image 132 | (format "/* XPM */ 133 | static char * curve_left[] = { 134 | \"12 18 2 1\", 135 | \". c %s\", 136 | \" c %s\", 137 | \". \", 138 | \"... \", 139 | \"... \", 140 | \"..... \", 141 | \"..... \", 142 | \"..... \", 143 | \"...... \", 144 | \"...... \", 145 | \"...... \", 146 | \"...... \", 147 | \"...... \", 148 | \"...... \", 149 | \"..... \", 150 | \"..... \", 151 | \"..... \", 152 | \"... \", 153 | \"... \", 154 | \". \"};" 155 | (if color1 color1 "None") 156 | (if color2 color2 "None")) 157 | 'xpm t :ascent 'center)) 158 | 159 | (defun make-xpm 160 | (name color1 color2 data) 161 | "Return an XPM image for lol data" 162 | (create-image 163 | (concat 164 | (format "/* XPM */ 165 | static char * %s[] = { 166 | \"%i %i 2 1\", 167 | \". c %s\", 168 | \" c %s\", 169 | " 170 | (downcase (replace-regexp-in-string " " "_" name)) 171 | (length (car data)) 172 | (length data) 173 | (if color1 color1 "None") 174 | (if color2 color2 "None")) 175 | (let ((len (length data)) 176 | (idx 0)) 177 | (apply 'concat 178 | (mapcar #'(lambda (dl) 179 | (setq idx (+ idx 1)) 180 | (concat 181 | "\"" 182 | (concat 183 | (mapcar #'(lambda (d) 184 | (if (eq d 0) 185 | (string-to-char " ") 186 | (string-to-char "."))) 187 | dl)) 188 | (if (eq idx len) 189 | "\"};" 190 | "\",\n"))) 191 | data)))) 192 | 'xpm t :ascent 'center)) 193 | 194 | (defun half-xpm 195 | (color1 color2) 196 | (make-xpm "half" color1 color2 197 | (make-list 18 198 | (append (make-list 6 0) 199 | (make-list 6 1))))) 200 | 201 | (defun percent-xpm 202 | (pmax pmin we ws width color1 color2) 203 | (let* ((fs (if (eq pmin ws) 204 | 0 205 | (round (* 17 (/ (float ws) (float pmax)))))) 206 | (fe (if (eq pmax we) 207 | 17 208 | (round (* 17 (/ (float we) (float pmax)))))) 209 | (o nil) 210 | (i 0)) 211 | (while (< i 18) 212 | (setq o (cons 213 | (if (and (<= fs i) 214 | (<= i fe)) 215 | (append (list 0) (make-list width 1) (list 0)) 216 | (append (list 0) (make-list width 0) (list 0))) 217 | o)) 218 | (setq i (+ i 1))) 219 | (make-xpm "percent" color1 color2 (reverse o)))) 220 | 221 | 222 | ;; from memoize.el @ http://nullprogram.com/blog/2010/07/26/ 223 | (defun memoize (func) 224 | "Memoize the given function. If argument is a symbol then 225 | install the memoized function over the original function." 226 | (typecase func 227 | (symbol (fset func (memoize-wrap (symbol-function func))) func) 228 | (function (memoize-wrap func)))) 229 | 230 | (defun memoize-wrap (func) 231 | "Return the memoized version of the given function." 232 | (let ((table-sym (gensym)) 233 | (val-sym (gensym)) 234 | (args-sym (gensym))) 235 | (set table-sym (make-hash-table :test 'equal)) 236 | `(lambda (&rest ,args-sym) 237 | ,(concat (documentation func) "\n(memoized function)") 238 | (let ((,val-sym (gethash ,args-sym ,table-sym))) 239 | (if ,val-sym 240 | ,val-sym 241 | (puthash ,args-sym (apply ,func ,args-sym) ,table-sym)))))) 242 | 243 | (memoize 'arrow-left-xpm) 244 | (memoize 'arrow-right-xpm) 245 | (memoize 'curve-left-xpm) 246 | (memoize 'curve-right-xpm) 247 | (memoize 'half-xpm) 248 | (memoize 'percent-xpm) 249 | 250 | (defvar powerline-minor-modes nil) 251 | (defvar powerline-arrow-shape 'arrow) 252 | (defun powerline-make-face 253 | (bg &optional fg) 254 | (if bg 255 | (let ((cface (intern (concat "powerline-" 256 | bg 257 | "-" 258 | (if fg 259 | (format "%s" fg) 260 | "white"))))) 261 | (make-face cface)2 262 | (if fg 263 | (if (eq fg 0) 264 | (set-face-attribute cface nil 265 | :background bg 266 | :box nil) 267 | (set-face-attribute cface nil 268 | :foreground fg 269 | :background bg 270 | :box nil)) 271 | (set-face-attribute cface nil 272 | :foreground "white" 273 | :background bg 274 | :box nil)) 275 | cface) 276 | nil)) 277 | 278 | (defun powerline-make-left 279 | (string color1 &optional color2 localmap) 280 | (let ((plface (powerline-make-face color1)) 281 | (arrow (and color2 (not (string= color1 color2))))) 282 | (concat 283 | (if (or (not string) (string= string "")) 284 | "" 285 | (propertize " " 'face plface)) 286 | (if string 287 | (if localmap 288 | (propertize string 'face plface 'mouse-face plface 'local-map localmap) 289 | (propertize string 'face plface)) 290 | "") 291 | (if arrow 292 | (propertize " " 'face plface) 293 | "") 294 | (if arrow 295 | (propertize " " 'display 296 | (cond ((eq powerline-arrow-shape 'arrow) 297 | (arrow-left-xpm color1 color2)) 298 | ((eq powerline-arrow-shape 'curve) 299 | (curve-left-xpm color1 color2)) 300 | ((eq powerline-arrow-shape 'half) 301 | (half-xpm color2 color1)) 302 | (t 303 | (arrow-left-xpm color1 color2))) 304 | 'local-map (make-mode-line-mouse-map 305 | 'mouse-1 (lambda () (interactive) 306 | (setq powerline-arrow-shape 307 | (cond ((eq powerline-arrow-shape 'arrow) 'curve) 308 | ((eq powerline-arrow-shape 'curve) 'half) 309 | ((eq powerline-arrow-shape 'half) 'arrow) 310 | (t 'arrow))) 311 | (redraw-modeline)))) 312 | "")))) 313 | 314 | (defun powerline-make-right 315 | (string color2 &optional color1 localmap) 316 | (let ((plface (powerline-make-face color2)) 317 | (arrow (and color1 (not (string= color1 color2))))) 318 | (concat 319 | (if arrow 320 | (propertize " " 'display 321 | (cond ((eq powerline-arrow-shape 'arrow) 322 | (arrow-right-xpm color1 color2)) 323 | ((eq powerline-arrow-shape 'curve) 324 | (curve-right-xpm color1 color2)) 325 | ((eq powerline-arrow-shape 'half) 326 | (half-xpm color2 color1)) 327 | (t 328 | (arrow-right-xpm color1 color2))) 329 | 'local-map (make-mode-line-mouse-map 330 | 'mouse-1 (lambda () (interactive) 331 | (setq powerline-arrow-shape 332 | (cond ((eq powerline-arrow-shape 'arrow) 'curve) 333 | ((eq powerline-arrow-shape 'curve) 'half) 334 | ((eq powerline-arrow-shape 'half) 'arrow) 335 | (t 'arrow))) 336 | (redraw-modeline)))) 337 | "") 338 | (if arrow 339 | (propertize " " 'face plface) 340 | "") 341 | (if string 342 | (if localmap 343 | (propertize string 'face plface 'mouse-face plface 'local-map localmap) 344 | (propertize string 'face plface)) 345 | "") 346 | (if (or (not string) (string= string "")) 347 | "" 348 | (propertize " " 'face plface))))) 349 | 350 | ;; get-scroll-bar-mode is not available in emacs 23.2 351 | (if (not (functionp 'get-scroll-bar-mode)) 352 | (defun get-scroll-bar-mode () scroll-bar-mode)) 353 | 354 | (defun powerline-make-fill 355 | (color right-indent) 356 | ;; justify right by filling with spaces to right fringe, 20 should be calculated 357 | (let ((plface (powerline-make-face color))) 358 | (if (eq 'right (get-scroll-bar-mode)) 359 | (propertize " " 'display `((space :align-to (- right-fringe ,(+ 1 right-indent)))) 360 | 'face plface) 361 | (propertize " " 'display `((space :align-to (- right-fringe ,(+ 4 right-indent)))) 362 | 'face plface)))) 363 | 364 | (defun strip-text-properties(txt) 365 | (set-text-properties 0 (length txt) nil txt) 366 | txt) 367 | 368 | (defun powerline-items-length 369 | (powerline-items) 370 | (length 371 | (strip-text-properties 372 | (format-mode-line 373 | (list "%e" 374 | powerline-items ))))) 375 | 376 | (defun powerline-pull-right 377 | (powerline-items) 378 | (append 379 | (list (powerline-make-fill powerline-color2 (powerline-items-length powerline-items)) ) 380 | powerline-items 381 | )) 382 | 383 | (defun powerline-make-text 384 | (string color &optional fg localmap) 385 | (let ((plface (powerline-make-face color))) 386 | (if string 387 | (if localmap 388 | (propertize string 'face plface 'mouse-face plface 'local-map localmap) 389 | (propertize string 'face plface)) 390 | ""))) 391 | 392 | (defun powerline-make (side string color1 &optional color2 localmap) 393 | (cond ((and (eq side 'right) color2) (powerline-make-right string color1 color2 localmap)) 394 | ((and (eq side 'left) color2) (powerline-make-left string color1 color2 localmap)) 395 | ((eq side 'left) (powerline-make-left string color1 color1 localmap)) 396 | ((eq side 'right) (powerline-make-right string color1 color1 localmap)) 397 | (t (powerline-make-text string color1 localmap)))) 398 | 399 | (defmacro defpowerline (name string) 400 | `(defun ,(intern (concat "powerline-" (symbol-name name))) 401 | (side color1 &optional color2) 402 | (powerline-make side 403 | ,string 404 | color1 color2))) 405 | 406 | (defun powerline-mouse (click-group click-type string) 407 | (cond ((eq click-group 'minor) 408 | (cond ((eq click-type 'menu) 409 | `(lambda (event) 410 | (interactive "@e") 411 | (minor-mode-menu-from-indicator ,string))) 412 | ((eq click-type 'help) 413 | `(lambda (event) 414 | (interactive "@e") 415 | (describe-minor-mode-from-indicator ,string))) 416 | (t 417 | `(lambda (event) 418 | (interactive "@e") 419 | nil)))) 420 | (t 421 | `(lambda (event) 422 | (interactive "@e") 423 | nil)))) 424 | 425 | (defpowerline arrow "") 426 | (defpowerline buffer-id (propertize (car (propertized-buffer-identification "%12b")) 427 | 'face (powerline-make-face color1))) 428 | (defvar powerline-buffer-size-suffix t) 429 | (defpowerline buffer-size (propertize 430 | (if powerline-buffer-size-suffix 431 | "%I" 432 | "%i") 433 | 'local-map (make-mode-line-mouse-map 434 | 'mouse-1 (lambda () (interactive) 435 | (setq powerline-buffer-size-suffix 436 | (not powerline-buffer-size-suffix)) 437 | (redraw-modeline))))) 438 | (defpowerline lcl current-input-method-title) 439 | (defpowerline rmw "%*") 440 | (defpowerline major-mode (propertize (format-mode-line mode-name) 441 | '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" 442 | 'local-map (let ((map (make-sparse-keymap))) 443 | (define-key map [mode-line down-mouse-1] 444 | `(menu-item ,(purecopy "Menu Bar") ignore 445 | :filter (lambda (_) (mouse-menu-major-mode-map)))) 446 | (define-key map [mode-line mouse-2] 'describe-mode) 447 | (define-key map [mode-line down-mouse-3] mode-line-mode-menu) 448 | map))) 449 | (defpowerline minor-modes (let ((mms (split-string (format-mode-line minor-mode-alist)))) 450 | (apply 'concat 451 | (mapcar #'(lambda (mm) 452 | (propertize (if (string= (car mms) 453 | mm) 454 | mm 455 | (concat " " mm)) 456 | '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" 457 | 'local-map (let ((map (make-sparse-keymap))) 458 | (define-key map [mode-line down-mouse-1] (powerline-mouse 'minor 'menu mm)) 459 | (define-key map [mode-line mouse-2] (powerline-mouse 'minor 'help mm)) 460 | (define-key map [mode-line down-mouse-3] (powerline-mouse 'minor 'menu mm)) 461 | (define-key map [header-line down-mouse-3] (powerline-mouse 'minor 'menu mm)) 462 | map))) 463 | mms)))) 464 | (defpowerline row "%4l") 465 | (defpowerline column "%3c") 466 | (defpowerline percent "%6p") 467 | (defpowerline narrow (let (real-point-min real-point-max) 468 | (save-excursion 469 | (save-restriction 470 | (widen) 471 | (setq real-point-min (point-min) real-point-max (point-max)))) 472 | (when (or (/= real-point-min (point-min)) 473 | (/= real-point-max (point-max))) 474 | (propertize "Narrow" 475 | 'help-echo "mouse-1: Remove narrowing from the current buffer" 476 | 'local-map (make-mode-line-mouse-map 477 | 'mouse-1 'mode-line-widen))))) 478 | (defpowerline status "%s") 479 | (defpowerline emacsclient mode-line-client) 480 | (defpowerline vc vc-mode) 481 | 482 | (defpowerline percent-xpm (propertize " " 483 | 'display 484 | (let (pmax 485 | pmin 486 | (ws (window-start)) 487 | (we (window-end))) 488 | (save-restriction 489 | (widen) 490 | (setq pmax (point-max)) 491 | (setq pmin (point-min))) 492 | (percent-xpm pmax pmin we ws 15 color1 color2)))) 493 | 494 | (display-time-mode) 495 | (defpowerline display-time display-time-string) 496 | (setq display-time-format "%H:%M") 497 | 498 | (setq-default mode-line-format 499 | (list "%e" 500 | '(:eval (append 501 | (list 502 | (powerline-lcl 'left nil ) 503 | (powerline-rmw 'left nil ) 504 | (powerline-buffer-id 'left nil powerline-color1 ) 505 | (powerline-major-mode 'left powerline-color1 ) 506 | (powerline-minor-modes 'left powerline-color1 ) 507 | (powerline-narrow 'left powerline-color1 powerline-color2 ) 508 | (powerline-vc 'center powerline-color2 )) 509 | (powerline-pull-right (list 510 | (powerline-row 'right powerline-color1 powerline-color2 ) 511 | (powerline-make-text ":" powerline-color1 ) 512 | (powerline-column 'right powerline-color1 ) 513 | (powerline-percent 'right nil powerline-color1 ) 514 | (powerline-display-time 'right nil) 515 | (powerline-make-text " " nil ))) 516 | )))) 517 | 518 | (provide 'powerline) 519 | 520 | ;;; powerline.el ends here 521 | --------------------------------------------------------------------------------