contrib/lisp/org-contacts.el (org-contacts-complete-name): Prevent an error when...
[org-mode.git] / contrib / lisp / org-bullets.el
bloba248e88f4f5ac86b4902160f65cd66cbb6b1b2b1
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
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.
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.
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.
23 ;;; Commentary:
25 ;; The project is hosted at https://github.com/sabof/org-bullets
26 ;; The latest version, and all the relevant information can be found there.
28 ;;; Code:
30 (eval-when-compile (require 'cl))
32 (defgroup org-bullets nil
33 "Display bullets as UTF-8 characters"
34 :group 'org-appearance)
36 ;; A nice collection of unicode bullets:
37 ;; http://nadeausoftware.com/articles/2007/11/latency_friendly_customized_bullets_using_unicode_characters
38 (defcustom org-bullets-bullet-list
39 '(;;; Large
40 "◉"
41 "○"
42 "✸"
43 "✿"
44 ;; ♥ ● ◇ ✚ ✜ ☯ ◆ ♠ ♣ ♦ ☢ ❀ ◆ ◖ ▶
45 ;;; Small
46 ;; ► • ★ ▸
48 "This variable contains the list of bullets.
49 It can contain any number of symbols, which will be repeated."
50 :group 'org-bullets
51 :type '(repeat (string :tag "Bullet character")))
53 (defcustom org-bullets-face-name nil
54 "This variable allows the org-mode bullets face to be
55 overridden. If set to a name of a face, that face will be
56 used. Otherwise the face of the heading level will be used."
57 :group 'org-bullets
58 :type 'symbol)
60 (defvar org-bullets-bullet-map
61 '(keymap
62 (mouse-1 . org-cycle)
63 (mouse-2
64 . (lambda (e)
65 (interactive "e")
66 (mouse-set-point e)
67 (org-cycle))))
68 "Mouse events for bullets.
69 Should this be undesirable, one can remove them with
71 \(setcdr org-bullets-bullet-map nil\)")
73 (defun org-bullets-level-char (level)
74 (string-to-char
75 (nth (mod (1- level)
76 (length org-bullets-bullet-list))
77 org-bullets-bullet-list)))
79 ;;;###autoload
80 (define-minor-mode org-bullets-mode
81 "UTF8 Bullets for org-mode"
82 nil nil nil
83 (let* (( keyword
84 `(("^\\*+ "
85 (0 (let (( level (- (match-end 0) (match-beginning 0) 1)))
86 (compose-region (- (match-end 0) 2)
87 (- (match-end 0) 1)
88 (org-bullets-level-char level))
89 (when (facep org-bullets-face-name)
90 (put-text-property (- (match-end 0) 2)
91 (- (match-end 0) 1)
92 'face
93 org-bullets-face-name))
94 (put-text-property (match-beginning 0)
95 (- (match-end 0) 2)
96 'face (list :foreground
97 (face-attribute
98 'default :background)))
99 (put-text-property (match-beginning 0)
100 (match-end 0)
101 'keymap
102 org-bullets-bullet-map)
103 nil))))))
104 (if org-bullets-mode
105 (progn (font-lock-add-keywords nil keyword)
106 (font-lock-fontify-buffer))
107 (save-excursion
108 (goto-char (point-min))
109 (font-lock-remove-keywords nil keyword)
110 (while (re-search-forward "^\\*+ " nil t)
111 (decompose-region (match-beginning 0) (match-end 0)))
112 (font-lock-fontify-buffer))
115 (provide 'org-bullets)
117 ;;; org-bullets.el ends here