Browse Source

contrib/lisp/org-bullets.el: Code clean-up, use `org-outline-regexp-bol'

* contrib/lisp/org-bullets.el (org-bullets)
(org-bullets-bullet-list, org-bullets-mode): Fix docstrings.  Use
`org-outline-regexp-bol' instead of a hardcoded regexp.
Bastien Guerry 12 năm trước cách đây
mục cha
commit
3f6b24d718
1 tập tin đã thay đổi với 49 bổ sung43 xóa
  1. 49 43
      contrib/lisp/org-bullets.el

+ 49 - 43
contrib/lisp/org-bullets.el

@@ -1,7 +1,7 @@
 ;;; org-bullets.el --- Show bullets in org-mode as UTF-8 characters
-;;; Version: 0.2.2
-;;; Author: sabof
-;;; URL: https://github.com/sabof/org-bullets
+;; Version: 0.2.2
+;; Author: sabof
+;; URL: https://github.com/sabof/org-bullets
 
 ;; This file is NOT part of GNU Emacs.
 ;;
@@ -30,7 +30,7 @@
 (eval-when-compile (require 'cl))
 
 (defgroup org-bullets nil
-  "Display bullets as UTF-8 characters"
+  "Display bullets as UTF-8 characters."
   :group 'org-appearance)
 
 ;; A nice collection of unicode bullets:
@@ -46,31 +46,33 @@
     ;; ► • ★ ▸
     )
   "This variable contains the list of bullets.
-It can contain any number of symbols, which will be repeated."
+It can contain any number of one-character strings.
+For levels beyond the size of the list, the stars will be
+displayed using the first items again."
   :group 'org-bullets
   :type '(repeat (string :tag "Bullet character")))
 
 (defcustom org-bullets-face-name nil
-  "This variable allows the org-mode bullets face to be
- overridden. If set to a name of a face, that face will be
- used. Otherwise the face of the heading level will be used."
+  "Allows to override `org-mode' bullets face.
+If set to a name of a face, that face will be used.
+Otherwise the face of the heading level will be used."
   :group 'org-bullets
   :type 'symbol)
 
 (defvar org-bullets-bullet-map
   '(keymap
     (mouse-1 . org-cycle)
-    (mouse-2
-     . (lambda (e)
-         (interactive "e")
-         (mouse-set-point e)
-         (org-cycle))))
+    (mouse-2 . (lambda (e)
+		 (interactive "e")
+		 (mouse-set-point e)
+		 (org-cycle))))
   "Mouse events for bullets.
-Should this be undesirable, one can remove them with
+If this is undesirable, one can remove them with
 
 \(setcdr org-bullets-bullet-map nil\)")
 
 (defun org-bullets-level-char (level)
+  "Return a character corresponding to LEVEL."
   (string-to-char
    (nth (mod (1- level)
              (length org-bullets-bullet-list))
@@ -78,40 +80,44 @@ Should this be undesirable, one can remove them with
 
 ;;;###autoload
 (define-minor-mode org-bullets-mode
-    "UTF8 Bullets for org-mode"
+  "UTF-8 bullets for `org-mode'."
   nil nil nil
-  (let* (( keyword
-           `(("^\\*+ "
-              (0 (let (( level (- (match-end 0) (match-beginning 0) 1)))
-                   (compose-region (- (match-end 0) 2)
-                                   (- (match-end 0) 1)
-                                   (org-bullets-level-char level))
-                   (when (facep org-bullets-face-name)
-                     (put-text-property (- (match-end 0) 2)
-                                        (- (match-end 0) 1)
-                                        'face
-                                        org-bullets-face-name))
-                   (put-text-property (match-beginning 0)
-                                      (- (match-end 0) 2)
-                                      'face (list :foreground
-                                                  (face-attribute
-                                                   'default :background)))
-                   (put-text-property (match-beginning 0)
-                                      (match-end 0)
-                                      'keymap
-                                      org-bullets-bullet-map)
-                   nil))))))
+  (require 'org-mode)
+  (let* ((keyword
+	  `((org-outline-regexp-bol
+	     (0 (let (( level (- (match-end 0) (match-beginning 0) 1)))
+		  (compose-region (- (match-end 0) 2)
+				  (- (match-end 0) 1)
+				  (org-bullets-level-char level))
+		  (when (facep org-bullets-face-name)
+		    (put-text-property (- (match-end 0) 2)
+				       (- (match-end 0) 1)
+				       'face
+				       org-bullets-face-name))
+		  (put-text-property (match-beginning 0)
+				     (- (match-end 0) 2)
+				     'face (list :foreground
+						 (face-attribute
+						  'default :background)))
+		  (put-text-property (match-beginning 0)
+				     (match-end 0)
+				     'keymap
+				     org-bullets-bullet-map)
+		  nil))))))
     (if org-bullets-mode
         (progn (font-lock-add-keywords nil keyword)
                (font-lock-fontify-buffer))
-        (save-excursion
-          (goto-char (point-min))
-          (font-lock-remove-keywords nil keyword)
-          (while (re-search-forward "^\\*+ " nil t)
-            (decompose-region (match-beginning 0) (match-end 0)))
-          (font-lock-fontify-buffer))
-        )))
+      (save-excursion
+	(goto-char (point-min))
+	(font-lock-remove-keywords nil keyword)
+	(while (re-search-forward org-outline-regexp-bol nil t)
+	  (decompose-region (match-beginning 0) (match-end 0)))
+	(font-lock-fontify-buffer)))))
 
 (provide 'org-bullets)
 
+;; Local Variables:
+;; coding: utf-8-emacs
+;; End:
+
 ;;; org-bullets.el ends here