org-bullets.el 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. ;;; org-bullets.el --- Show bullets in org-mode as UTF-8 characters
  2. ;; Version: 0.2.2
  3. ;; Author: sabof
  4. ;; URL: https://github.com/sabof/org-bullets
  5. ;; This file is NOT part of GNU Emacs.
  6. ;;
  7. ;; This program is free software; you can redistribute it and/or
  8. ;; modify it under the terms of the GNU General Public License as
  9. ;; published by the Free Software Foundation; either version 3, or (at
  10. ;; your option) any later version.
  11. ;;
  12. ;; This program is distributed in the hope that it will be useful, but
  13. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. ;; General Public License for more details.
  16. ;;
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with this program ; see the file COPYING. If not, write to
  19. ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. ;; Boston, MA 02111-1307, USA.
  21. ;;; Commentary:
  22. ;; The project is hosted at https://github.com/sabof/org-bullets
  23. ;; The latest version, and all the relevant information can be found there.
  24. ;;; Code:
  25. (eval-when-compile (require 'cl))
  26. (defgroup org-bullets nil
  27. "Display bullets as UTF-8 characters."
  28. :group 'org-appearance)
  29. ;; A nice collection of unicode bullets:
  30. ;; http://nadeausoftware.com/articles/2007/11/latency_friendly_customized_bullets_using_unicode_characters
  31. (defcustom org-bullets-bullet-list
  32. '(;;; Large
  33. "◉"
  34. "○"
  35. "✸"
  36. "✿"
  37. ;; ♥ ● ◇ ✚ ✜ ☯ ◆ ♠ ♣ ♦ ☢ ❀ ◆ ◖ ▶
  38. ;;; Small
  39. ;; ► • ★ ▸
  40. )
  41. "This variable contains the list of bullets.
  42. It can contain any number of one-character strings.
  43. For levels beyond the size of the list, the stars will be
  44. displayed using the first items again."
  45. :group 'org-bullets
  46. :type '(repeat (string :tag "Bullet character")))
  47. (defcustom org-bullets-face-name nil
  48. "Allows to override `org-mode' bullets face.
  49. If set to a name of a face, that face will be used.
  50. Otherwise the face of the heading level will be used."
  51. :group 'org-bullets
  52. :type 'symbol)
  53. (defvar org-bullets-bullet-map
  54. '(keymap
  55. (mouse-1 . org-cycle)
  56. (mouse-2 . (lambda (e)
  57. (interactive "e")
  58. (mouse-set-point e)
  59. (org-cycle))))
  60. "Mouse events for bullets.
  61. If this is undesirable, one can remove them with
  62. \(setcdr org-bullets-bullet-map nil\)")
  63. (defun org-bullets-level-char (level)
  64. "Return a character corresponding to LEVEL."
  65. (string-to-char
  66. (nth (mod (1- level)
  67. (length org-bullets-bullet-list))
  68. org-bullets-bullet-list)))
  69. ;;;###autoload
  70. (define-minor-mode org-bullets-mode
  71. "UTF-8 bullets for `org-mode'."
  72. nil nil nil
  73. (let* ((keyword
  74. `((,org-outline-regexp-bol
  75. (0 (let (( level (- (match-end 0) (match-beginning 0) 1)))
  76. (compose-region (- (match-end 0) 2)
  77. (- (match-end 0) 1)
  78. (org-bullets-level-char level))
  79. (when (facep org-bullets-face-name)
  80. (put-text-property (- (match-end 0) 2)
  81. (- (match-end 0) 1)
  82. 'face
  83. org-bullets-face-name))
  84. (put-text-property (match-beginning 0)
  85. (- (match-end 0) 2)
  86. 'face (list :foreground
  87. (face-attribute
  88. 'default :background)))
  89. (put-text-property (match-beginning 0)
  90. (match-end 0)
  91. 'keymap
  92. org-bullets-bullet-map)
  93. nil))))))
  94. (if org-bullets-mode
  95. (progn (font-lock-add-keywords nil keyword)
  96. (font-lock-fontify-buffer))
  97. (save-excursion
  98. (goto-char (point-min))
  99. (font-lock-remove-keywords nil keyword)
  100. (while (re-search-forward org-outline-regexp-bol nil t)
  101. (decompose-region (match-beginning 0) (match-end 0)))
  102. (font-lock-fontify-buffer)))))
  103. (provide 'org-bullets)
  104. ;; Local Variables:
  105. ;; coding: utf-8-emacs
  106. ;; End:
  107. ;;; org-bullets.el ends here