Advertisement
Guest User

Emacs Powerline

a guest
Mar 10th, 2012
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 6.88 KB | None | 0 0
  1. (defvar powerline-color1)
  2. (defvar powerline-color2)
  3.  
  4. (setq powerline-color1 "grey22")
  5. (setq powerline-color2 "grey40")
  6.  
  7. (set-face-attribute 'mode-line nil
  8.                     :background "Turquoise"
  9.                     :box nil)
  10. (set-face-attribute 'mode-line-inactive nil
  11.                     :box nil)
  12.  
  13. (defun arrow-right-xpm (color1 color2)
  14.   "Return an XPM right arrow string representing."
  15.   (create-image
  16.    (format "/* XPM */
  17. static char * arrow_right[] = {
  18. \"12 18 2 1\",
  19. \". c %s\",
  20. \"  c %s\",
  21. \".           \",
  22. \"..          \",
  23. \"...         \",
  24. \"....        \",
  25. \".....       \",
  26. \"......      \",
  27. \".......     \",
  28. \"........    \",
  29. \".........   \",
  30. \".........   \",
  31. \"........    \",
  32. \".......     \",
  33. \"......      \",
  34. \".....       \",
  35. \"....        \",
  36. \"...         \",
  37. \"..          \",
  38. \".           \"};"
  39.            (if color1 color1 "None")
  40.            (if color2 color2 "None"))
  41.    'xpm t :ascent 'center))
  42.  
  43. (defun arrow-left-xpm (color1 color2)
  44.   "Return an XPM right arrow string representing."
  45.   (create-image
  46.    (format "/* XPM */
  47. static char * arrow_right[] = {
  48. \"12 18 2 1\",
  49. \". c %s\",
  50. \"  c %s\",
  51. \"           .\",
  52. \"          ..\",
  53. \"         ...\",
  54. \"        ....\",
  55. \"       .....\",
  56. \"      ......\",
  57. \"     .......\",
  58. \"    ........\",
  59. \"   .........\",
  60. \"   .........\",
  61. \"    ........\",
  62. \"     .......\",
  63. \"      ......\",
  64. \"       .....\",
  65. \"        ....\",
  66. \"         ...\",
  67. \"          ..\",
  68. \"           .\"};"
  69.            (if color2 color2 "None")
  70.            (if color1 color1 "None"))
  71.    'xpm t :ascent 'center))
  72.  
  73. (defvar powerline-minor-modes nil)
  74.  
  75. (defun powerline-make-face
  76.   (bg &optional fg)
  77.   (if bg
  78.       (let ((cface (intern (concat "powerline-" bg))))
  79.         (make-face cface)
  80.         (set-face-attribute cface nil
  81.                             :foreground (if fg fg "white")
  82.                             :background bg
  83.                             :box nil)
  84.         cface)
  85.     nil))
  86. (defun powerline-make-left
  87.   (string color1 &optional color2 localmap)
  88.   (let ((plface (powerline-make-face color1))
  89.         (arrow  (and color2 (not (string= color1 color2)))))
  90.     (concat
  91.      (propertize " " 'face plface)
  92.      (if localmap
  93.          (propertize string 'face plface 'mouse-face plface1 'local-map localmap)
  94.        (propertize string 'face plface))
  95.      (if arrow
  96.          (propertize " " 'face plface)
  97.        "")
  98.      (if arrow
  99.          (propertize " " 'display (arrow-right-xpm color1 color2))
  100.        ""))))
  101. (defun powerline-make-right
  102.   (string color2 &optional color1 localmap)
  103.   (let ((plface (powerline-make-face color2))
  104.         (arrow  (and color1 (not (string= color1 color2)))))
  105.     (concat
  106.      (if arrow
  107.        (propertize " " 'display (arrow-left-xpm color1 color2))
  108.        "")
  109.      (if arrow
  110.          (propertize " " 'face plface)
  111.        "")
  112.      (if localmap
  113.          (propertize string 'face plface 'mouse-face plface1 'local-map localmap)
  114.        (propertize string 'face plface))
  115.      (propertize " " 'face plface))))
  116. (defun powerline-make-fill
  117.   (color)
  118.   ;; justify right by filling with spaces to right fringe, 20 should be calculated
  119.   (let ((plface (powerline-make-face color)))
  120.     (propertize " " 'display '((space :align-to (- right-fringe 20)))
  121.                 'face plface)))
  122. (defun powerline-make-text
  123.   (string color &optional localmap)
  124.   (let ((plface (powerline-make-face color)))
  125.     (if localmap
  126.         (propertize string 'face plface 'mouse-face plface 'local-map localmap)
  127.       (propertize string 'face plface))))
  128. (defun powerline-make (side string color1 &optional color2 localmap)
  129.   (cond ((and (eq side 'right) color2) (powerline-make-right  string color1 color2 localmap))
  130.         ((and (eq side 'left) color2)  (powerline-make-left   string color1 color2 localmap))
  131.         ((eq side 'left)               (powerline-make-left   string color1 color1 localmap))
  132.         ((eq side 'right)              (powerline-make-right  string color1 color1 localmap))
  133.         (t                             (powerline-make-text   string color1 localmap))))
  134. (defun powerline-buffer-name
  135.   (side color1 &optional color2)
  136.   (powerline-make side
  137.                   "%b"
  138.                   color1 color2))
  139. (defun powerline-buffer-size
  140.   (side color1 &optional color2)
  141.   (powerline-make side
  142.                   "%I"
  143.                   color1 color2))
  144. (defun powerline-rmw
  145.   (side color1 &optional color2)
  146.   (powerline-make side
  147.                   "%*"
  148.                   color1 color2))
  149. (defun powerline-major-mode
  150.   (side color1 &optional color2)
  151.   (powerline-make side
  152.                   "%[%m%]"
  153.                   color1 color2))
  154. (defun powerline-minor-modes
  155.   (side color1 &optional color2)
  156.   (powerline-make side
  157.                   (substring (format-mode-line minor-mode-alist) 1)
  158.                   color1 color2))
  159. (defun powerline-percent
  160.   (side color1 &optional color2)
  161.   (powerline-make side
  162.                   "%6p"
  163.                   color1 color2))
  164. (defun powerline-row
  165.   (side color1 &optional color2)
  166.   (powerline-make side
  167.                   "%4l"
  168.                   color1 color2))
  169. (defun powerline-column
  170.   (side color1 &optional color2)
  171.   (powerline-make side
  172.                   "%3c"
  173.                   color1 color2))
  174. (defun powerline-narrow
  175.   (side color1 &optional color2)
  176.   (powerline-make side
  177.                   "%n"
  178.                   color1 color2))
  179. (defun powerline-emacsclient
  180.   (side color1 &optional color2)
  181.   (powerline-make side
  182.                   mode-line-client
  183.                   color1 color2))
  184. (defun powerline-vc
  185.   (side color1 &optional color2)
  186.   (if (buffer-file-name (current-buffer))
  187.       (powerline-make side
  188.                       (vc-mode-line (buffer-file-name (current-buffer)))
  189.                       color1 color2)
  190.     ""))
  191. (setq-default mode-line-format
  192.               (list '(:eval (powerline-rmw            'left   nil  ))
  193.                     '(:eval (powerline-buffer-size    'left   nil  ))
  194.                     '(:eval (powerline-buffer-name    'left   nil  powerline-color1  ))
  195.                     '(:eval (powerline-major-mode     'left        powerline-color1  ))
  196.                     '(:eval (powerline-minor-modes    'left        powerline-color1  powerline-color2  ))
  197.                     '(:eval (powerline-narrow         'center                        powerline-color2  ))
  198.                     '(:eval (powerline-vc             'center                        powerline-color2  ))
  199.                     '(:eval (powerline-make-fill                                     powerline-color2  ))
  200.                     '(:eval (powerline-percent        'right       powerline-color1  powerline-color2  ))
  201.                     '(:eval (powerline-row            'right  nil  powerline-color1))
  202.                     '(:eval (powerline-text ":" nil))
  203.                     '(:eval (powerline-column         'text   nil  ))))
  204.  
  205. (provide 'powerline)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement