commit | author | age
|
76bbd0
|
1 |
;;; org-bullets.el --- Show bullets in org-mode as UTF-8 characters |
C |
2 |
|
|
3 |
;; Version: 0.2.4 |
|
4 |
;; Package-Version: 20180208.2343 |
|
5 |
;; Author: sabof |
|
6 |
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li> |
|
7 |
;; Homepage: https://github.com/emacsorphanage/org-bullets |
|
8 |
|
|
9 |
;; This file is NOT part of GNU Emacs. |
|
10 |
|
|
11 |
;; This file is free software; you can redistribute it and/or modify |
|
12 |
;; it under the terms of the GNU General Public License as published by |
|
13 |
;; the Free Software Foundation; either version 3, or (at your option) |
|
14 |
;; any later version. |
|
15 |
|
|
16 |
;; This file is distributed in the hope that it will be useful, |
|
17 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
;; GNU General Public License for more details. |
|
20 |
|
|
21 |
;; For a full copy of the GNU General Public License |
|
22 |
;; see <http://www.gnu.org/licenses/>. |
|
23 |
|
|
24 |
;;; Commentary: |
|
25 |
|
|
26 |
;; Show org-mode bullets as UTF-8 characters. |
|
27 |
|
|
28 |
;; Because the author is inactive, this package is currenlty being |
|
29 |
;; maintained at https://github.com/emacsorphanage/org-bullets. |
|
30 |
|
|
31 |
;;; Code: |
|
32 |
|
|
33 |
(defgroup org-bullets nil |
|
34 |
"Display bullets as UTF-8 characters." |
|
35 |
:group 'org-appearance) |
|
36 |
|
|
37 |
;; A nice collection of unicode bullets: |
|
38 |
;; http://nadeausoftware.com/articles/2007/11/latency_friendly_customized_bullets_using_unicode_characters |
|
39 |
(defcustom org-bullets-bullet-list |
|
40 |
'(;;; Large |
|
41 |
"◉" |
|
42 |
"○" |
|
43 |
"✸" |
|
44 |
"✿" |
|
45 |
;; ♥ ● ◇ ✚ ✜ ☯ ◆ ♠ ♣ ♦ ☢ ❀ ◆ ◖ ▶ |
|
46 |
;;; Small |
|
47 |
;; ► • ★ ▸ |
|
48 |
) |
|
49 |
"List of bullets used in Org headings. |
|
50 |
It can contain any number of symbols, which will be repeated." |
|
51 |
:group 'org-bullets |
|
52 |
:type '(repeat (string :tag "Bullet character"))) |
|
53 |
|
|
54 |
(defcustom org-bullets-face-name nil |
|
55 |
"Face used for bullets in Org mode headings. |
|
56 |
If set to the name of a face, that face is used. |
|
57 |
Otherwise the face of the heading level is used." |
|
58 |
:group 'org-bullets |
|
59 |
:type 'symbol) |
|
60 |
|
|
61 |
(defvar org-bullets-bullet-map (make-sparse-keymap)) |
|
62 |
|
|
63 |
(defun org-bullets-level-char (level) |
|
64 |
(string-to-char |
|
65 |
(nth (mod (1- level) |
|
66 |
(length org-bullets-bullet-list)) |
|
67 |
org-bullets-bullet-list))) |
|
68 |
|
|
69 |
(defvar org-bullets--keywords |
|
70 |
`(("^\\*+ " |
|
71 |
(0 (let* ((level (- (match-end 0) (match-beginning 0) 1)) |
|
72 |
(is-inline-task |
|
73 |
(and (boundp 'org-inlinetask-min-level) |
|
74 |
(>= level org-inlinetask-min-level)))) |
|
75 |
(compose-region (- (match-end 0) 2) |
|
76 |
(- (match-end 0) 1) |
|
77 |
(org-bullets-level-char level)) |
|
78 |
(when is-inline-task |
|
79 |
(compose-region (- (match-end 0) 3) |
|
80 |
(- (match-end 0) 2) |
|
81 |
(org-bullets-level-char level))) |
|
82 |
(when (facep org-bullets-face-name) |
|
83 |
(put-text-property (- (match-end 0) |
|
84 |
(if is-inline-task 3 2)) |
|
85 |
(- (match-end 0) 1) |
|
86 |
'face |
|
87 |
org-bullets-face-name)) |
|
88 |
(put-text-property (match-beginning 0) |
|
89 |
(- (match-end 0) 2) |
|
90 |
'face (list :foreground |
|
91 |
(face-attribute |
|
92 |
'default :background))) |
|
93 |
(put-text-property (match-beginning 0) |
|
94 |
(match-end 0) |
|
95 |
'keymap |
|
96 |
org-bullets-bullet-map) |
|
97 |
nil))))) |
|
98 |
|
|
99 |
;;;###autoload |
|
100 |
(define-minor-mode org-bullets-mode |
|
101 |
"Use UTF8 bullets in Org mode headings." |
|
102 |
nil nil nil |
|
103 |
(if org-bullets-mode |
|
104 |
(progn |
|
105 |
(font-lock-add-keywords nil org-bullets--keywords) |
|
106 |
(org-bullets--fontify-buffer)) |
|
107 |
(save-excursion |
|
108 |
(goto-char (point-min)) |
|
109 |
(font-lock-remove-keywords nil org-bullets--keywords) |
|
110 |
(while (re-search-forward "^\\*+ " nil t) |
|
111 |
(decompose-region (match-beginning 0) (match-end 0))) |
|
112 |
(org-bullets--fontify-buffer)))) |
|
113 |
|
|
114 |
(defun org-bullets--fontify-buffer () |
|
115 |
(when font-lock-mode |
|
116 |
(if (and (fboundp 'font-lock-flush) |
|
117 |
(fboundp 'font-lock-ensure)) |
|
118 |
(save-restriction |
|
119 |
(widen) |
|
120 |
(font-lock-flush) |
|
121 |
(font-lock-ensure)) |
|
122 |
(with-no-warnings |
|
123 |
(font-lock-fontify-buffer))))) |
|
124 |
|
|
125 |
(provide 'org-bullets) |
|
126 |
;; Local Variables: |
|
127 |
;; indent-tabs-mode: nil |
|
128 |
;; End: |
|
129 |
;;; org-bullets.el ends here |