org-bullets.el 4.2 KB

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