Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

635 lines
28 KiB

пре 4 година
  1. ;;; powerline-separators.el --- Separators for Powerline
  2. ;; Copyright (C) 2012-2013 Donald Ephraim Curtis
  3. ;; Copyright (C) 2013 Jason Milkins
  4. ;; Copyright (C) 2012 Nicolas Rougier
  5. ;; This file is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation; either version 3, or (at your option)
  8. ;; any later version.
  9. ;; This file is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;; Separators for Powerline.
  18. ;; Included separators: alternate, arrow, arrow-fade, bar, box, brace, butt,
  19. ;; chamfer, contour, curve, rounded, roundstub, slant, wave, zigzag, and nil.
  20. ;;
  21. ;;; Code:
  22. (require 'cl-lib)
  23. (require 'color)
  24. (defvar powerline-image-apple-rgb
  25. (and (eq (window-system) 'ns)
  26. ns-use-srgb-colorspace
  27. (< 11
  28. (string-to-number
  29. (and (string-match "darwin\\([0-9]+\\)" system-configuration)
  30. (match-string-no-properties 1 system-configuration)))))
  31. "Boolean variable to determine whether to use Apple RGB colorspace to render images.
  32. t on macOS 10.7+ and `ns-use-srgb-colorspace' is t, nil otherwise.
  33. This variable is automatically set, there's no need to modify it.")
  34. (defun pl/interpolate (color1 color2)
  35. "Interpolate between COLOR1 and COLOR2.
  36. COLOR1 and COLOR2 must be supplied as hex strings with a leading #."
  37. (let* ((c1 (color-name-to-rgb color1))
  38. (c2 (color-name-to-rgb color2))
  39. (red (/ (+ (nth 0 c1) (nth 0 c2)) 2))
  40. (green (/ (+ (nth 1 c1) (nth 1 c2)) 2))
  41. (blue (/ (+ (nth 2 c1) (nth 2 c2)) 2)))
  42. (color-rgb-to-hex red green blue)))
  43. (defun pl/color-xyz-to-apple-rgb (X Y Z)
  44. "Convert CIE X Y Z colors to Apple RGB color space."
  45. (let ((r (+ (* 3.2404542 X) (* -1.5371385 Y) (* -0.4985314 Z)))
  46. (g (+ (* -0.9692660 X) (* 1.8760108 Y) (* 0.0415560 Z)))
  47. (b (+ (* 0.0556434 X) (* -0.2040259 Y) (* 1.0572252 Z))))
  48. (list (expt r (/ 1.8)) (expt g (/ 1.8)) (expt b (/ 1.8)))))
  49. (defun pl/color-srgb-to-apple-rgb (red green blue)
  50. "Convert RED GREEN BLUE colors from sRGB color space to Apple RGB.
  51. RED, GREEN and BLUE should be between 0.0 and 1.0, inclusive."
  52. (apply 'pl/color-xyz-to-apple-rgb (color-srgb-to-xyz red green blue)))
  53. (defun pl/hex-color (color)
  54. "Get the hexadecimal value of COLOR."
  55. (when color
  56. (let ((srgb-color (color-name-to-rgb color)))
  57. (if powerline-image-apple-rgb
  58. (apply 'color-rgb-to-hex (apply 'pl/color-srgb-to-apple-rgb srgb-color))
  59. (apply 'color-rgb-to-hex srgb-color)))))
  60. (defun pl/pattern (lst)
  61. "Turn LST into an infinite pattern."
  62. (when lst
  63. (let ((pattern (cl-copy-list lst)))
  64. (setcdr (last pattern) pattern))))
  65. (defun pl/pattern-to-string (pattern)
  66. "Convert a PATTERN into a string that can be used in an XPM."
  67. (concat "\"" (mapconcat 'number-to-string pattern "") "\","))
  68. (defun pl/reverse-pattern (pattern)
  69. "Reverse each line in PATTERN."
  70. (mapcar 'reverse pattern))
  71. (defun pl/row-pattern (fill total &optional fade)
  72. "Make a list that has FILL 0s out of TOTAL 1s with FADE 2s to the right of the fill."
  73. (unless fade
  74. (setq fade 0))
  75. (let ((fill (min fill total))
  76. (fade (min fade (max (- total fill) 0))))
  77. (append (make-list fill 0)
  78. (make-list fade 2)
  79. (make-list (- total fill fade) 1))))
  80. (defun pl/pattern-bindings-body (patterns height-exp pattern-height-sym
  81. second-pattern-height-sym)
  82. "Create let-var bindings and a function body from PATTERNS.
  83. The `car' and `cdr' parts of the result can be passed to the
  84. function `pl/wrap-defun' as its `let-vars' and `body' arguments,
  85. respectively. HEIGHT-EXP is an expression calculating the image
  86. height and it should contain a free variable `height'.
  87. PATTERN-HEIGHT-SYM and SECOND-PATTERN-HEIGHT-SYM are symbols used
  88. for let-var binding variables."
  89. (let* ((pattern (pl/pattern (mapcar 'pl/pattern-to-string (car patterns))))
  90. (header (mapcar 'pl/pattern-to-string (nth 1 patterns)))
  91. (footer (mapcar 'pl/pattern-to-string (nth 2 patterns)))
  92. (second-pattern (pl/pattern (mapcar 'pl/pattern-to-string (nth 3 patterns))))
  93. (center (mapcar 'pl/pattern-to-string (nth 4 patterns)))
  94. (reserve (+ (length header) (length footer) (length center))))
  95. (when pattern
  96. (cons `((,pattern-height-sym (max (- ,height-exp ,reserve) 0))
  97. (,second-pattern-height-sym (/ ,pattern-height-sym 2))
  98. (,pattern-height-sym ,(if second-pattern `(ceiling ,pattern-height-sym 2) `,pattern-height-sym)))
  99. (list (when header `(mapconcat 'identity ',header ""))
  100. `(mapconcat 'identity
  101. (cl-subseq ',pattern 0 ,pattern-height-sym) "")
  102. (when center `(mapconcat 'identity ',center ""))
  103. (when second-pattern
  104. `(mapconcat 'identity
  105. (cl-subseq ',second-pattern
  106. 0 ,second-pattern-height-sym) ""))
  107. (when footer `(mapconcat 'identity ',footer "")))))))
  108. (defun pl/pattern-defun (name dir width &rest patterns)
  109. "Create a powerline function of NAME in DIR with WIDTH for PATTERNS.
  110. PATTERNS is of the form (PATTERN HEADER FOOTER SECOND-PATTERN CENTER
  111. PATTERN-2X HEADER-2X FOOTER-2X SECOND-PATTERN-2X CENTER-2X).
  112. PATTERN is required, all other components are optional.
  113. The first 5 components are for the standard resolution image.
  114. The remaining ones are for the high resolution image where both
  115. width and height are doubled. If PATTERN-2X is nil or not given,
  116. then the remaining components are ignored and the standard
  117. resolution image with magnification and interpolation will be
  118. used in high resolution environments
  119. All generated functions generate the form:
  120. HEADER
  121. PATTERN ...
  122. CENTER
  123. SECOND-PATTERN ...
  124. FOOTER
  125. PATTERN and SECOND-PATTERN repeat infinitely to fill the space needed to generate a full height XPM.
  126. PATTERN, HEADER, FOOTER, SECOND-PATTERN, CENTER are of the form ((COLOR ...) (COLOR ...) ...).
  127. COLOR can be one of 0, 1, or 2, where 0 is the source color, 1 is the
  128. destination color, and 2 is the interpolated color between 0 and 1."
  129. (when (eq dir 'right)
  130. (setq patterns (mapcar 'pl/reverse-pattern patterns)))
  131. (let ((bindings-body (pl/pattern-bindings-body patterns
  132. 'height
  133. 'pattern-height
  134. 'second-pattern-height))
  135. (bindings-body-2x (pl/pattern-bindings-body (nthcdr 5 patterns)
  136. '(* height 2)
  137. 'pattern-height-2x
  138. 'second-pattern-height-2x)))
  139. (pl/wrap-defun name dir width
  140. (append (car bindings-body) (car bindings-body-2x))
  141. (cdr bindings-body) (cdr bindings-body-2x))))
  142. (defun pl/background-color (face)
  143. (face-attribute face
  144. (if (face-attribute face :inverse-video nil 'default)
  145. :foreground
  146. :background)
  147. nil
  148. 'default))
  149. (defun pl/wrap-defun (name dir width let-vars body &optional body-2x)
  150. "Generate a powerline function of NAME in DIR with WIDTH using LET-VARS and BODY."
  151. (let* ((src-face (if (eq dir 'left) 'face1 'face2))
  152. (dst-face (if (eq dir 'left) 'face2 'face1)))
  153. `(defun ,(intern (format "powerline-%s-%s" name (symbol-name dir)))
  154. (face1 face2 &optional height)
  155. (when window-system
  156. (unless height (setq height (pl/separator-height)))
  157. (let* ,(append `((color1 (when ,src-face
  158. (pl/hex-color (pl/background-color ,src-face))))
  159. (color2 (when ,dst-face
  160. (pl/hex-color (pl/background-color ,dst-face))))
  161. (colori (when (and color1 color2) (pl/interpolate color1 color2)))
  162. (color1 (or color1 "None"))
  163. (color2 (or color2 "None"))
  164. (colori (or colori "None")))
  165. let-vars)
  166. (apply 'create-image
  167. ,(append `(concat (format "/* XPM */ static char * %s_%s[] = { \"%s %s 3 1\", \"0 c %s\", \"1 c %s\", \"2 c %s\","
  168. ,(replace-regexp-in-string "-" "_" name)
  169. (symbol-name ',dir)
  170. ,width
  171. height
  172. color1
  173. color2
  174. colori))
  175. body
  176. '("};"))
  177. 'xpm t
  178. :ascent 'center
  179. :face (when (and face1 face2)
  180. ,dst-face)
  181. ,(and body-2x
  182. `(and (featurep 'mac)
  183. (list :data-2x
  184. ,(append `(concat (format "/* XPM */ static char * %s_%s_2x[] = { \"%s %s 3 1\", \"0 c %s\", \"1 c %s\", \"2 c %s\","
  185. ,(replace-regexp-in-string "-" "_" name)
  186. (symbol-name ',dir)
  187. (* ,width 2)
  188. (* height 2)
  189. color1
  190. color2
  191. colori))
  192. body-2x
  193. '("};")))))))))))
  194. (defmacro pl/alternate (dir)
  195. "Generate an alternating pattern XPM function for DIR."
  196. (pl/pattern-defun "alternate" dir 4
  197. '((2 2 1 1)
  198. (0 0 2 2))
  199. nil nil nil nil
  200. ;; 2x
  201. '((2 2 2 2 1 1 1 1)
  202. (2 2 2 2 1 1 1 1)
  203. (0 0 0 0 2 2 2 2)
  204. (0 0 0 0 2 2 2 2))))
  205. (defmacro pl/arrow (dir)
  206. "Generate an arrow XPM function for DIR."
  207. (let ((row-modifier (if (eq dir 'left) 'identity 'reverse)))
  208. (pl/wrap-defun "arrow" dir 'middle-width
  209. '((width (1- (/ height 2)))
  210. (middle-width (1- (ceiling height 2))))
  211. `((cl-loop for i from 0 to width
  212. concat (pl/pattern-to-string (,row-modifier (pl/row-pattern i middle-width))))
  213. (when (cl-oddp height)
  214. (pl/pattern-to-string (make-list middle-width 0)))
  215. (cl-loop for i from width downto 0
  216. concat (pl/pattern-to-string (,row-modifier (pl/row-pattern i middle-width)))))
  217. `((when (cl-evenp height)
  218. (pl/pattern-to-string (make-list (* middle-width 2) 1)))
  219. (cl-loop for i from 0 to (* middle-width 2)
  220. concat (pl/pattern-to-string (,row-modifier (pl/row-pattern i (* middle-width 2)))))
  221. (cl-loop for i from (* middle-width 2) downto 0
  222. concat (pl/pattern-to-string (,row-modifier (pl/row-pattern i (* middle-width 2)))))
  223. (when (cl-evenp height)
  224. (pl/pattern-to-string (make-list (* middle-width 2) 1)))))))
  225. (defmacro pl/arrow-fade (dir)
  226. "Generate an arrow-fade XPM function for DIR."
  227. (let* ((row-modifier (if (eq dir 'left) 'identity 'reverse)))
  228. (pl/wrap-defun "arrow-fade" dir 'middle-width
  229. '((width (1- (/ height 2)))
  230. (middle-width (1+ (ceiling height 2))))
  231. `((cl-loop for i from 0 to width
  232. concat (pl/pattern-to-string (,row-modifier (pl/row-pattern i middle-width 2))))
  233. (when (cl-oddp height)
  234. (pl/pattern-to-string (,row-modifier (pl/row-pattern (1+ width) middle-width 2))))
  235. (cl-loop for i from width downto 0
  236. concat (pl/pattern-to-string (,row-modifier (pl/row-pattern i middle-width 2)))))
  237. `((when (cl-evenp height)
  238. (pl/pattern-to-string (,row-modifier (pl/row-pattern 0 (* middle-width 2) (* 2 2)))))
  239. (cl-loop for i from 0 to (* (- middle-width 2) 2)
  240. concat (pl/pattern-to-string (,row-modifier (pl/row-pattern i (* middle-width 2) (* 2 2)))))
  241. (cl-loop for i from (* (- middle-width 2) 2) downto 0
  242. concat (pl/pattern-to-string (,row-modifier (pl/row-pattern i (* middle-width 2) (* 2 2)))))
  243. (when (cl-evenp height)
  244. (pl/pattern-to-string (,row-modifier (pl/row-pattern 0 (* middle-width 2) (* 2 2)))))))))
  245. (defmacro pl/bar (dir)
  246. "Generate a bar XPM function for DIR."
  247. (pl/pattern-defun "bar" dir 2
  248. '((2 2))))
  249. (defmacro pl/box (dir)
  250. "Generate a box XPM function for DIR."
  251. (pl/pattern-defun "box" dir 2
  252. '((0 0)
  253. (0 0)
  254. (1 1)
  255. (1 1))
  256. nil nil nil nil
  257. ;; 2x
  258. '((0 0 0 0)
  259. (0 0 0 0)
  260. (0 0 0 0)
  261. (0 0 0 0)
  262. (1 1 1 1)
  263. (1 1 1 1)
  264. (1 1 1 1)
  265. (1 1 1 1))))
  266. (defmacro pl/brace (dir)
  267. "Generate a brace XPM function for DIR."
  268. (pl/pattern-defun "brace" dir 4
  269. '((0 1 1 1))
  270. '((1 1 1 1)
  271. (2 1 1 1))
  272. '((2 1 1 1)
  273. (1 1 1 1))
  274. '((0 1 1 1))
  275. '((0 2 1 1)
  276. (0 2 1 1)
  277. (0 0 2 1)
  278. (0 0 0 0)
  279. (0 0 2 1)
  280. (0 2 1 1)
  281. (0 2 1 1))
  282. ;; 2x
  283. '((0 0 1 1 1 1 1 1))
  284. '((1 1 1 1 1 1 1 1)
  285. (1 1 1 1 1 1 1 1)
  286. (2 1 1 1 1 1 1 1)
  287. (0 2 1 1 1 1 1 1))
  288. '((0 2 1 1 1 1 1 1)
  289. (2 1 1 1 1 1 1 1)
  290. (1 1 1 1 1 1 1 1)
  291. (1 1 1 1 1 1 1 1))
  292. '((0 0 1 1 1 1 1 1))
  293. '((0 0 2 1 1 1 1 1)
  294. (0 0 0 1 1 1 1 1)
  295. (0 0 0 2 1 1 1 1)
  296. (0 0 0 0 1 1 1 1)
  297. (0 0 0 0 2 1 1 1)
  298. (0 0 0 0 0 2 1 1)
  299. (0 0 0 0 0 0 0 2)
  300. (0 0 0 0 0 0 0 2)
  301. (0 0 0 0 0 2 1 1)
  302. (0 0 0 0 2 1 1 1)
  303. (0 0 0 0 1 1 1 1)
  304. (0 0 0 2 1 1 1 1)
  305. (0 0 0 1 1 1 1 1)
  306. (0 0 2 1 1 1 1 1))))
  307. (defmacro pl/butt (dir)
  308. "Generate a butt XPM function for DIR."
  309. (pl/pattern-defun "butt" dir 3
  310. '((0 0 0))
  311. '((1 1 1)
  312. (0 1 1)
  313. (0 0 1))
  314. '((0 0 1)
  315. (0 1 1)
  316. (1 1 1))
  317. nil nil
  318. ;; 2x
  319. '((0 0 0 0 0 0))
  320. '((1 1 1 1 1 1)
  321. (0 1 1 1 1 1)
  322. (0 0 1 1 1 1)
  323. (0 0 0 1 1 1)
  324. (0 0 0 0 1 1)
  325. (0 0 0 0 0 1))
  326. '((0 0 0 0 0 1)
  327. (0 0 0 0 1 1)
  328. (0 0 0 1 1 1)
  329. (0 0 1 1 1 1)
  330. (0 1 1 1 1 1)
  331. (1 1 1 1 1 1))))
  332. (defmacro pl/chamfer (dir)
  333. "Generate a chamfer XPM function for DIR."
  334. (pl/pattern-defun "chamfer" dir 3
  335. '((0 0 0))
  336. '((1 1 1)
  337. (0 1 1)
  338. (0 0 1))
  339. nil nil nil
  340. ;; 2x
  341. '((0 0 0 0 0 0))
  342. '((1 1 1 1 1 1)
  343. (0 1 1 1 1 1)
  344. (0 0 1 1 1 1)
  345. (0 0 0 1 1 1)
  346. (0 0 0 0 1 1)
  347. (0 0 0 0 0 1))))
  348. (defmacro pl/contour (dir)
  349. "Generate a contour XPM function for DIR."
  350. (pl/pattern-defun "contour" dir 10
  351. '((0 0 0 0 0 1 1 1 1 1))
  352. '((1 1 1 1 1 1 1 1 1 1)
  353. (0 2 1 1 1 1 1 1 1 1)
  354. (0 0 2 1 1 1 1 1 1 1)
  355. (0 0 0 2 1 1 1 1 1 1)
  356. (0 0 0 0 1 1 1 1 1 1)
  357. (0 0 0 0 2 1 1 1 1 1))
  358. '((0 0 0 0 0 2 1 1 1 1)
  359. (0 0 0 0 0 0 1 1 1 1)
  360. (0 0 0 0 0 0 2 1 1 1)
  361. (0 0 0 0 0 0 0 2 1 1)
  362. (0 0 0 0 0 0 0 0 0 0))
  363. nil nil
  364. ;; 2x
  365. '((0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1))
  366. '((1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  367. (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  368. (0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  369. (0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  370. (0 0 0 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  371. (0 0 0 0 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  372. (0 0 0 0 0 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1)
  373. (0 0 0 0 0 0 0 2 1 1 1 1 1 1 1 1 1 1 1 1)
  374. (0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1)
  375. (0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1)
  376. (0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1)
  377. (0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1))
  378. '((0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1)
  379. (0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1)
  380. (0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1)
  381. (0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1)
  382. (0 0 0 0 0 0 0 0 0 0 0 0 2 1 1 1 1 1 1 1)
  383. (0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 1 1 1 1 1)
  384. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1)
  385. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1)
  386. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
  387. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))))
  388. (defmacro pl/curve (dir)
  389. "Generate a curve XPM function for DIR."
  390. (pl/pattern-defun "curve" dir 4
  391. '((0 0 0 0))
  392. '((1 1 1 1)
  393. (2 1 1 1)
  394. (0 0 1 1)
  395. (0 0 2 1)
  396. (0 0 0 1)
  397. (0 0 0 2))
  398. '((0 0 0 2)
  399. (0 0 0 1)
  400. (0 0 2 1)
  401. (0 0 1 1)
  402. (2 1 1 1)
  403. (1 1 1 1))
  404. nil nil
  405. ;; 2x
  406. '((0 0 0 0 0 0 0 0))
  407. '((1 1 1 1 1 1 1 1)
  408. (1 1 1 1 1 1 1 1)
  409. (1 1 1 1 1 1 1 1)
  410. (0 0 1 1 1 1 1 1)
  411. (0 0 0 2 1 1 1 1)
  412. (0 0 0 0 2 1 1 1)
  413. (0 0 0 0 0 2 1 1)
  414. (0 0 0 0 0 0 1 1)
  415. (0 0 0 0 0 0 1 1)
  416. (0 0 0 0 0 0 0 1)
  417. (0 0 0 0 0 0 0 1)
  418. (0 0 0 0 0 0 0 1))
  419. '((0 0 0 0 0 0 0 1)
  420. (0 0 0 0 0 0 0 1)
  421. (0 0 0 0 0 0 0 1)
  422. (0 0 0 0 0 0 1 1)
  423. (0 0 0 0 0 0 1 1)
  424. (0 0 0 0 0 2 1 1)
  425. (0 0 0 0 2 1 1 1)
  426. (0 0 0 2 1 1 1 1)
  427. (0 0 1 1 1 1 1 1)
  428. (1 1 1 1 1 1 1 1)
  429. (1 1 1 1 1 1 1 1)
  430. (1 1 1 1 1 1 1 1))))
  431. (defmacro pl/rounded (dir)
  432. "Generate a rounded XPM function for DIR."
  433. (pl/pattern-defun "rounded" dir 6
  434. '((0 0 0 0 0 0))
  435. '((2 1 1 1 1 1)
  436. (0 0 2 1 1 1)
  437. (0 0 0 0 1 1)
  438. (0 0 0 0 2 1)
  439. (0 0 0 0 0 1)
  440. (0 0 0 0 0 2))
  441. nil nil nil
  442. ;; 2x
  443. '((0 0 0 0 0 0 0 0 0 0 0 0))
  444. '((1 1 1 1 1 1 1 1 1 1 1 1)
  445. (0 0 2 1 1 1 1 1 1 1 1 1)
  446. (0 0 0 0 1 1 1 1 1 1 1 1)
  447. (0 0 0 0 0 0 1 1 1 1 1 1)
  448. (0 0 0 0 0 0 0 2 1 1 1 1)
  449. (0 0 0 0 0 0 0 0 1 1 1 1)
  450. (0 0 0 0 0 0 0 0 0 1 1 1)
  451. (0 0 0 0 0 0 0 0 0 0 1 1)
  452. (0 0 0 0 0 0 0 0 0 0 1 1)
  453. (0 0 0 0 0 0 0 0 0 0 2 1)
  454. (0 0 0 0 0 0 0 0 0 0 0 1)
  455. (0 0 0 0 0 0 0 0 0 0 0 1))))
  456. (defmacro pl/roundstub (dir)
  457. "Generate a roundstub XPM function for DIR."
  458. (pl/pattern-defun "roundstub" dir 3
  459. '((0 0 0))
  460. '((1 1 1)
  461. (0 0 1)
  462. (0 0 2))
  463. '((0 0 2)
  464. (0 0 1)
  465. (1 1 1))
  466. nil nil
  467. ;; 2x
  468. '((0 0 0 0 0 0))
  469. '((1 1 1 1 1 1)
  470. (2 1 1 1 1 1)
  471. (0 0 0 2 1 1)
  472. (0 0 0 0 1 1)
  473. (0 0 0 0 0 1)
  474. (0 0 0 0 0 1))
  475. '((0 0 0 0 0 1)
  476. (0 0 0 0 0 1)
  477. (0 0 0 0 1 1)
  478. (0 0 0 2 1 1)
  479. (2 1 1 1 1 1)
  480. (1 1 1 1 1 1))))
  481. (defmacro pl/slant (dir)
  482. "Generate a slant XPM function for DIR."
  483. (let* ((row-modifier (if (eq dir 'left) 'identity 'reverse)))
  484. (pl/wrap-defun "slant" dir 'width
  485. '((width (1- (ceiling height 2))))
  486. `((cl-loop for i from 0 to (1- height)
  487. concat (pl/pattern-to-string (,row-modifier (pl/row-pattern (/ i 2) width)))))
  488. `((cl-loop for i from 0 to (1- (* height 2))
  489. concat (pl/pattern-to-string (,row-modifier (pl/row-pattern (/ i 2) (* width 2)))))))))
  490. (defmacro pl/wave (dir)
  491. "Generate a wave XPM function for DIR."
  492. (pl/pattern-defun "wave" dir 11
  493. '((0 0 0 0 0 0 1 1 1 1 1))
  494. '((2 1 1 1 1 1 1 1 1 1 1)
  495. (0 0 1 1 1 1 1 1 1 1 1)
  496. (0 0 0 1 1 1 1 1 1 1 1)
  497. (0 0 0 2 1 1 1 1 1 1 1)
  498. (0 0 0 0 1 1 1 1 1 1 1)
  499. (0 0 0 0 2 1 1 1 1 1 1)
  500. (0 0 0 0 0 1 1 1 1 1 1)
  501. (0 0 0 0 0 1 1 1 1 1 1)
  502. (0 0 0 0 0 2 1 1 1 1 1))
  503. '((0 0 0 0 0 0 2 1 1 1 1)
  504. (0 0 0 0 0 0 0 1 1 1 1)
  505. (0 0 0 0 0 0 0 1 1 1 1)
  506. (0 0 0 0 0 0 0 2 1 1 1)
  507. (0 0 0 0 0 0 0 0 1 1 1)
  508. (0 0 0 0 0 0 0 0 2 1 1)
  509. (0 0 0 0 0 0 0 0 0 0 2))
  510. nil nil
  511. ;; 2x
  512. '((0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1))
  513. '((1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  514. (0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  515. (0 0 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  516. (0 0 0 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  517. (0 0 0 0 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  518. (0 0 0 0 0 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  519. (0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  520. (0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  521. (0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  522. (0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
  523. (0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1)
  524. (0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1)
  525. (0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1)
  526. (0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1)
  527. (0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1)
  528. (0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1)
  529. (0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1)
  530. (0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1))
  531. '((0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1)
  532. (0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1)
  533. (0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1)
  534. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1)
  535. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1)
  536. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1)
  537. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1)
  538. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1)
  539. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1)
  540. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1)
  541. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 1 1 1 1)
  542. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 1 1 1)
  543. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1)
  544. (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))))
  545. (defmacro pl/zigzag (dir)
  546. "Generate a zigzag pattern XPM function for DIR."
  547. (pl/pattern-defun "zigzag" dir 3
  548. '((1 1 1)
  549. (0 1 1)
  550. (0 0 1)
  551. (0 0 0)
  552. (0 0 1)
  553. (0 1 1))
  554. nil nil nil nil
  555. ;; 2x
  556. '((1 1 1 1 1 1)
  557. (0 1 1 1 1 1)
  558. (0 0 1 1 1 1)
  559. (0 0 0 1 1 1)
  560. (0 0 0 0 1 1)
  561. (0 0 0 0 0 1)
  562. (0 0 0 0 0 0)
  563. (0 0 0 0 0 1)
  564. (0 0 0 0 1 1)
  565. (0 0 0 1 1 1)
  566. (0 0 1 1 1 1)
  567. (0 1 1 1 1 1))))
  568. (defmacro pl/nil (dir)
  569. "Generate a XPM function that returns nil for DIR."
  570. `(defun ,(intern (format "powerline-nil-%s" (symbol-name dir)))
  571. (face1 face2 &optional height)
  572. nil))
  573. (defmacro pl/utf-8 (dir)
  574. "Generate function that returns raw utf-8 symbols."
  575. (let ((dir-name (symbol-name dir))
  576. (src-face (if (eq dir 'left) 'face1 'face2))
  577. (dst-face (if (eq dir 'left) 'face2 'face1)))
  578. `(defun ,(intern (format "powerline-utf-8-%s" dir-name))
  579. (face1 face2 &optional height)
  580. (powerline-raw
  581. (char-to-string ,(intern (format "powerline-utf-8-separator-%s"
  582. dir-name)))
  583. (list :foreground (pl/background-color ,src-face)
  584. :background (pl/background-color ,dst-face)
  585. :inverse-video nil)))))
  586. (provide 'powerline-separators)
  587. ;;; powerline-separators.el ends here