org-bullets.el 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 symbols, which will be repeated."
  43. :group 'org-bullets
  44. :type '(repeat (string :tag "Bullet character")))
  45. (defcustom org-bullets-face-name nil
  46. "This variable allows the org-mode bullets face to be
  47. overridden. If set to a name of a face, that face will be
  48. used. Otherwise the face of the heading level will be used."
  49. :group 'org-bullets
  50. :type 'symbol)
  51. (defvar org-bullets-bullet-map
  52. '(keymap
  53. (mouse-1 . org-cycle)
  54. (mouse-2
  55. . (lambda (e)
  56. (interactive "e")
  57. (mouse-set-point e)
  58. (org-cycle))))
  59. "Mouse events for bullets.
  60. Should this be undesirable, one can remove them with
  61. \(setcdr org-bullets-bullet-map nil\)")
  62. (defun org-bullets-level-char (level)
  63. (string-to-char
  64. (nth (mod (1- level)
  65. (length org-bullets-bullet-list))
  66. org-bullets-bullet-list)))
  67. ;;;###autoload
  68. (define-minor-mode org-bullets-mode
  69. "UTF8 Bullets for org-mode"
  70. nil nil nil
  71. (let* (( keyword
  72. `(("^\\*+ "
  73. (0 (let (( level (- (match-end 0) (match-beginning 0) 1)))
  74. (compose-region (- (match-end 0) 2)
  75. (- (match-end 0) 1)
  76. (org-bullets-level-char level))
  77. (when (facep org-bullets-face-name)
  78. (put-text-property (- (match-end 0) 2)
  79. (- (match-end 0) 1)
  80. 'face
  81. org-bullets-face-name))
  82. (put-text-property (match-beginning 0)
  83. (- (match-end 0) 2)
  84. 'face (list :foreground
  85. (face-attribute
  86. 'default :background)))
  87. (put-text-property (match-beginning 0)
  88. (match-end 0)
  89. 'keymap
  90. org-bullets-bullet-map)
  91. nil))))))
  92. (if org-bullets-mode
  93. (progn (font-lock-add-keywords nil keyword)
  94. (font-lock-fontify-buffer))
  95. (save-excursion
  96. (goto-char (point-min))
  97. (font-lock-remove-keywords nil keyword)
  98. (while (re-search-forward "^\\*+ " nil t)
  99. (decompose-region (match-beginning 0) (match-end 0)))
  100. (font-lock-fontify-buffer))
  101. )))
  102. (provide 'org-bullets)
  103. ;;; org-bullets.el ends here