al-color.el 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ;;; al-color.el --- Additional functionality for working with color themes, faces, ...
  2. ;; Copyright © 2013-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. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. ;;; Managing themes
  15. ;;;###autoload
  16. (defun al/load-theme (theme)
  17. "Similar to `load-theme' except it unloads the current themes at first."
  18. (interactive
  19. (list (intern (completing-read
  20. "Load custom theme: "
  21. (mapcar #'symbol-name (custom-available-themes))))))
  22. (mapc #'disable-theme custom-enabled-themes)
  23. (load-theme theme t)
  24. (message "Current theme: '%S'." theme))
  25. ;; Idea from <https://gist.github.com/joehakimrahme/6305195>.
  26. ;;;###autoload
  27. (defun al/load-random-theme ()
  28. "Load any random theme from the available ones."
  29. (interactive)
  30. (let ((themes (custom-available-themes)))
  31. (al/load-theme (nth (random (length themes))
  32. themes))))
  33. ;;; Working with faces
  34. (defun al/get-face (&optional pos)
  35. "Return name of the face at point POS.
  36. If POS is nil, use current point position."
  37. (or pos
  38. (setq pos (point)))
  39. (or (get-char-property pos 'read-face-name)
  40. (get-char-property pos 'face)))
  41. ;;;###autoload
  42. (defun al/face-to-kill-ring ()
  43. "Put a name of the current face into kill ring."
  44. (interactive)
  45. (let ((face (al/get-face)))
  46. (if (null face)
  47. (message "No face at point.")
  48. (setq face (symbol-name face))
  49. (kill-new face)
  50. (message "%s" face))))
  51. (provide 'al-color)
  52. ;;; al-color.el ends here