/font-awesome.el

https://github.com/krismolendyke/font-awesome.el · Lisp · 314 lines · 287 code · 14 blank · 13 comment · 2 complexity · 972d20157cfa4c633e8bcd74b5d84101 MD5 · raw file

  1. ;;; font-awesome.el --- A simple library for using FontAwesome icons.
  2. ;;; Commentary:
  3. ;;
  4. ;; FontAwesome is an icon font designed for use with the Twitter
  5. ;; Bootstrap front-end web framework but can be useful elsewhere like
  6. ;; a text editor, e.g., `org-mode'.
  7. ;;
  8. ;; `font-awesome' is a package which makes inserting FontAwesome icons
  9. ;; into Emacs easier. The OpenType font FontAwesome.otf is required
  10. ;; to be installed for the icons to be displayed properly. It can be
  11. ;; downloaded at http://fortawesome.github.io/Font-Awesome/
  12. ;;; Code:
  13. (defface font-awesome '((t :family "FontAwesome")) "The FontAwesome face.")
  14. (defconst font-awesome/icon-list
  15. '((#xf000 "glass")
  16. (#xf001 "music")
  17. (#xf002 "search")
  18. (#xf003 "envelope")
  19. (#xf004 "heart")
  20. (#xf005 "star")
  21. (#xf006 "star-empty")
  22. (#xf007 "user")
  23. (#xf008 "film")
  24. (#xf009 "th-large")
  25. (#xf00a "th")
  26. (#xf00b "th-list")
  27. (#xf00c "ok")
  28. (#xf00d "remove")
  29. (#xf00e "zoom-in")
  30. (#xf010 "zoom-out")
  31. (#xf011 "off")
  32. (#xf012 "signal")
  33. (#xf013 "cog")
  34. (#xf014 "trash")
  35. (#xf015 "home")
  36. (#xf016 "file")
  37. (#xf017 "time")
  38. (#xf018 "road")
  39. (#xf019 "download-alt")
  40. (#xf01a "download")
  41. (#xf01b "upload")
  42. (#xf01c "inbox")
  43. (#xf01d "play-circle")
  44. (#xf01e "repeat")
  45. (#xf021 "refresh")
  46. (#xf022 "list-alt")
  47. (#xf023 "lock")
  48. (#xf024 "flag")
  49. (#xf025 "headphones")
  50. (#xf026 "volume-off")
  51. (#xf027 "volume-down")
  52. (#xf028 "volume-up")
  53. (#xf029 "qrcode")
  54. (#xf02a "barcode")
  55. (#xf02b "tag")
  56. (#xf02c "tags")
  57. (#xf02d "book")
  58. (#xf02e "bookmark")
  59. (#xf02f "print")
  60. (#xf030 "camera")
  61. (#xf031 "font")
  62. (#xf032 "bold")
  63. (#xf033 "italic")
  64. (#xf034 "text-height")
  65. (#xf035 "text-width")
  66. (#xf036 "align-left")
  67. (#xf037 "align-center")
  68. (#xf038 "align-right")
  69. (#xf039 "align-justify")
  70. (#xf03a "list")
  71. (#xf03b "indent-left")
  72. (#xf03c "indent-right")
  73. (#xf03d "facetime-video")
  74. (#xf03e "picture")
  75. (#xf040 "pencil")
  76. (#xf041 "map-marker")
  77. (#xf042 "adjust")
  78. (#xf043 "tint")
  79. (#xf044 "edit")
  80. (#xf045 "share")
  81. (#xf046 "check")
  82. (#xf047 "move")
  83. (#xf048 "step-backward")
  84. (#xf049 "fast-backward")
  85. (#xf04a "backward")
  86. (#xf04b "play")
  87. (#xf04c "pause")
  88. (#xf04d "stop")
  89. (#xf04e "forward")
  90. (#xf050 "fast-forward")
  91. (#xf051 "step-forward")
  92. (#xf052 "eject")
  93. (#xf053 "chevron-left")
  94. (#xf054 "chevron-right")
  95. (#xf055 "plus-sign")
  96. (#xf056 "minus-sign")
  97. (#xf057 "remove-sign")
  98. (#xf058 "ok-sign")
  99. (#xf059 "question-sign")
  100. (#xf05a "info-sign")
  101. (#xf05b "screenshot")
  102. (#xf05c "remove-circle")
  103. (#xf05d "ok-circle")
  104. (#xf05e "ban-circle")
  105. (#xf060 "arrow-left")
  106. (#xf061 "arrow-right")
  107. (#xf062 "arrow-up")
  108. (#xf063 "arrow-down")
  109. (#xf064 "share-alt")
  110. (#xf065 "resize-full")
  111. (#xf066 "resize-small")
  112. (#xf067 "plus")
  113. (#xf068 "minus")
  114. (#xf069 "asterisk")
  115. (#xf06a "exclamation-sign")
  116. (#xf06b "gift")
  117. (#xf06c "leaf")
  118. (#xf06d "fire")
  119. (#xf06e "eye-open")
  120. (#xf070 "eye-close")
  121. (#xf071 "warning-sign")
  122. (#xf072 "plane")
  123. (#xf073 "calendar")
  124. (#xf074 "random")
  125. (#xf075 "comment")
  126. (#xf076 "magnet")
  127. (#xf077 "chevron-up")
  128. (#xf078 "chevron-down")
  129. (#xf079 "retweet")
  130. (#xf07a "shopping-cart")
  131. (#xf07b "folder-close")
  132. (#xf07c "folder-open")
  133. (#xf07d "resize-vertical")
  134. (#xf07e "resize-horizontal")
  135. (#xf080 "bar-chart")
  136. (#xf081 "twitter-sign")
  137. (#xf082 "facebook-sign")
  138. (#xf083 "camera-retro")
  139. (#xf084 "key")
  140. (#xf085 "cogs")
  141. (#xf086 "comments")
  142. (#xf087 "thumbs-up")
  143. (#xf088 "thumbs-down")
  144. (#xf089 "star-half")
  145. (#xf08a "heart-empty")
  146. (#xf08b "signout")
  147. (#xf08c "linkedin-sign")
  148. (#xf08d "pushpin")
  149. (#xf08e "external-link")
  150. (#xf090 "signin")
  151. (#xf091 "trophy")
  152. (#xf092 "github-sign")
  153. (#xf093 "upload-alt")
  154. (#xf094 "lemon")
  155. (#xf095 "phone")
  156. (#xf096 "check-empty")
  157. (#xf097 "bookmark-empty")
  158. (#xf098 "phone-sign")
  159. (#xf099 "twitter")
  160. (#xf09a "facebook")
  161. (#xf09b "github")
  162. (#xf09c "unlock")
  163. (#xf09d "credit-card")
  164. (#xf09e "rss")
  165. (#xf0a0 "hdd")
  166. (#xf0a1 "bullhorn")
  167. (#xf0a2 "bell")
  168. (#xf0a3 "certificate")
  169. (#xf0a4 "hand-right")
  170. (#xf0a5 "hand-left")
  171. (#xf0a6 "hand-up")
  172. (#xf0a7 "hand-down")
  173. (#xf0a8 "circle-arrow-left")
  174. (#xf0a9 "circle-arrow-right")
  175. (#xf0aa "circle-arrow-up")
  176. (#xf0ab "circle-arrow-down")
  177. (#xf0ac "globe")
  178. (#xf0ad "wrench")
  179. (#xf0ae "tasks")
  180. (#xf0b0 "filter")
  181. (#xf0b1 "briefcase")
  182. (#xf0b2 "fullscreen")
  183. (#xf0c0 "group")
  184. (#xf0c1 "link")
  185. (#xf0c2 "cloud")
  186. (#xf0c3 "beaker")
  187. (#xf0c4 "cut")
  188. (#xf0c5 "copy")
  189. (#xf0c6 "paper-clip")
  190. (#xf0c7 "save")
  191. (#xf0c8 "sign-blank")
  192. (#xf0c9 "reorder")
  193. (#xf0ca "list-ul")
  194. (#xf0cb "list-ol")
  195. (#xf0cc "strikethrough")
  196. (#xf0cd "underline")
  197. (#xf0ce "table")
  198. (#xf0d0 "magic")
  199. (#xf0d1 "truck")
  200. (#xf0d2 "pinterest")
  201. (#xf0d3 "pinterest-sign")
  202. (#xf0d4 "google-plus-sign")
  203. (#xf0d5 "google-plus")
  204. (#xf0d6 "money")
  205. (#xf0d7 "caret-down")
  206. (#xf0d8 "caret-up")
  207. (#xf0d9 "caret-left")
  208. (#xf0da "caret-right")
  209. (#xf0db "columns")
  210. (#xf0dc "sort")
  211. (#xf0dd "sort-down")
  212. (#xf0de "sort-up")
  213. (#xf0e0 "envelope-alt")
  214. (#xf0e1 "linkedin")
  215. (#xf0e2 "undo")
  216. (#xf0e3 "legal")
  217. (#xf0e4 "dashboard")
  218. (#xf0e5 "comment-alt")
  219. (#xf0e6 "comments-alt")
  220. (#xf0e7 "bolt")
  221. (#xf0e8 "sitemap")
  222. (#xf0e9 "umbrella")
  223. (#xf0ea "paste")
  224. (#xf0eb "lightbulb")
  225. (#xf0ec "exchange")
  226. (#xf0ed "cloud-download")
  227. (#xf0ee "cloud-upload")
  228. (#xf0f0 "user-md")
  229. (#xf0f1 "stethoscope")
  230. (#xf0f2 "suitcase")
  231. (#xf0f3 "bell-alt")
  232. (#xf0f4 "coffee")
  233. (#xf0f5 "food")
  234. (#xf0f6 "file-alt")
  235. (#xf0f7 "building")
  236. (#xf0f8 "hospital")
  237. (#xf0f9 "ambulance")
  238. (#xf0fa "medkit")
  239. (#xf0fb "fighter-jet")
  240. (#xf0fc "beer")
  241. (#xf0fd "h-sign")
  242. (#xf0fe "plus-sign-alt")
  243. (#xf100 "double-angle-left")
  244. (#xf101 "double-angle-right")
  245. (#xf102 "double-angle-up")
  246. (#xf103 "double-angle-down")
  247. (#xf104 "angle-left")
  248. (#xf105 "angle-right")
  249. (#xf106 "angle-up")
  250. (#xf107 "angle-down")
  251. (#xf108 "desktop")
  252. (#xf109 "laptop")
  253. (#xf10a "tablet")
  254. (#xf10b "mobile-phone")
  255. (#xf10c "circle-blank")
  256. (#xf10d "quote-left")
  257. (#xf10e "quote-right")
  258. (#xf110 "spinner")
  259. (#xf111 "circle")
  260. (#xf112 "reply"))
  261. "The list of available FontAwesome icons.
  262. This is used to create the hash table for fast icon lookups. The
  263. source for this list is
  264. http://fortawesome.github.io/Font-Awesome/design.html")
  265. (defconst font-awesome/icon-table
  266. (let ((table (make-hash-table :test 'equal)))
  267. (mapcar
  268. #'(lambda (icon-map)
  269. (let ((code (car icon-map))
  270. (name (cadr icon-map)))
  271. (puthash name code table)))
  272. font-awesome/icon-list)
  273. table)
  274. "The table of available FontAwesome icons.
  275. The mapping is icon name to hexadecimal icon code.")
  276. (defun font-awesome/get-icon (name)
  277. "Get the given icon as a string.
  278. If icon NAME cannot be found, return beer."
  279. (let ((icons (make-hash-table :test 'equal))
  280. (beer #xf0fc))
  281. (char-to-string
  282. (gethash name font-awesome/icon-table beer))))
  283. (defun font-awesome/propertize-icon (icon)
  284. "Propertize the given ICON."
  285. (propertize (font-awesome/get-icon icon) 'face 'font-awesome))
  286. (defun font-awesome/insert-icon (&optional icon)
  287. "Insert an ICON."
  288. (interactive)
  289. (insert (font-awesome/propertize-icon
  290. (or icon (completing-read "icon: " font-awesome/icon-table)))))
  291. (defun font-awesome/insert-all-icons ()
  292. "Insert all available FontAwesome icons."
  293. (interactive)
  294. (maphash
  295. (lambda (name icon)
  296. (insert
  297. (format "%s: %s\n" name (font-awesome/propertize-icon name))))
  298. font-awesome/icon-table))
  299. (provide 'font-awesome)
  300. ;;; font-awesome.el ends here