al-font.el 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ;;; al-font.el --- Additional functionality for working with fonts
  2. ;; Copyright © 2014-2016 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  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. ;;; Code:
  16. (require 'cl-lib)
  17. ;;; Choosing the first available font
  18. ;; Idea from <http://www.emacswiki.org/emacs/SetFonts>.
  19. (defvar al/font-candidates
  20. '("Liberation Mono-12" "DejaVu Sans Mono-11" "Terminus-12")
  21. "List of font names used by `al/first-existing-font'.")
  22. (defun al/first-existing-font (&rest font-names)
  23. "Return the first existing font from FONT-NAMES.
  24. If FONT-NAMES is nil, use `al/font-candidates'."
  25. (cl-find-if (lambda (name)
  26. (find-font (font-spec :name name)))
  27. (or font-names al/font-candidates)))
  28. ;;; Setting different fonts for different characters
  29. ;; See (info "(emacs) Modifying Fontsets"),
  30. ;; <http://www.emacswiki.org/emacs/FontSets> and
  31. ;; <http://paste.lisp.org/display/133488> for more information.
  32. (defun al/set-fontset (&optional name frame add specs)
  33. "Modify fontset NAME.
  34. Each specification from SPECS list has the following form:
  35. (FONT . TARGETS)
  36. TARGETS is a list of characters TARGET. See `set-fontset-font'
  37. for details."
  38. (dolist (spec specs)
  39. (pcase spec
  40. (`(,font . ,targets)
  41. (dolist (target targets)
  42. (set-fontset-font name target font frame add))))))
  43. (provide 'al-font)
  44. ;;; al-font.el ends here