org-bullets.el 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ;;; org-bullets.el --- Show bullets in org-mode as UTF-8 characters
  2. ;;; Version: 0.1
  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. "Use different background for even and odd lines."
  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. (defun org-bullets-level-char (level)
  52. (nth (mod (1- level)
  53. (length org-bullets-bullet-list))
  54. org-bullets-bullet-list))
  55. (defun org-bullets-ptp (iter &rest args)
  56. (apply 'put-text-property
  57. (+ iter (match-beginning 0))
  58. (+ iter (match-beginning 0) 1)
  59. args))
  60. ;;;###autoload
  61. (define-minor-mode org-bullets-mode
  62. "UTF8 Bullets for org-mode"
  63. nil nil nil
  64. (let* (( keyword
  65. `(("^\\*+ "
  66. (0 (let (( offset 0)
  67. ( level
  68. (- (match-end 0)
  69. (match-beginning 0) 1)))
  70. (dotimes (iter level)
  71. (if (= (1- level) iter)
  72. (progn
  73. (compose-region
  74. (+ iter (match-beginning 0))
  75. (+ iter (match-beginning 0) 1)
  76. (org-bullets-level-char level))
  77. (when (facep org-bullets-face-name)
  78. (org-bullets-ptp
  79. iter 'face org-bullets-face-name)))
  80. (org-bullets-ptp
  81. iter 'face (list :foreground
  82. (face-attribute
  83. 'default :background))))
  84. (put-text-property
  85. (match-beginning 0)
  86. (match-end 0)
  87. 'keymap
  88. '(keymap
  89. (mouse-1 . org-cycle)
  90. (mouse-2
  91. . (lambda (e)
  92. (interactive "e")
  93. (mouse-set-point e)
  94. (org-cycle))))))
  95. nil))))))
  96. (if org-bullets-mode
  97. (progn (font-lock-add-keywords nil keyword)
  98. (font-lock-fontify-buffer))
  99. (save-excursion
  100. (goto-char (point-min))
  101. (font-lock-remove-keywords nil keyword)
  102. (while (re-search-forward "^\\*+ " nil t)
  103. (decompose-region (match-beginning 0) (match-end 0)))
  104. (font-lock-fontify-buffer))
  105. )))
  106. (provide 'org-bullets)
  107. ;;; org-bullets.el ends here