Advertisement
Guest User

Untitled

a guest
Mar 7th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 5.37 KB | None | 0 0
  1. ;;; org-bullets.el --- Show bullets in org-mode as UTF-8 characters
  2. ;;; Version: 0.2.4
  3. ;; Package-Version: 0.2.4
  4. ;;; Author: sabof
  5. ;;; URL: https://github.com/sabof/org-bullets
  6.  
  7. ;; This file is NOT part of GNU Emacs.
  8. ;;
  9. ;; This program is free software; you can redistribute it and/or
  10. ;; modify it under the terms of the GNU General Public License as
  11. ;; published by the Free Software Foundation; either version 3, or (at
  12. ;; your option) any later version.
  13. ;;
  14. ;; This program is distributed in the hope that it will be useful, but
  15. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. ;; General Public License for more details.
  18. ;;
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with this program ; see the file COPYING.  If not, write to
  21. ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  22. ;; Boston, MA 02111-1307, USA.
  23.  
  24. ;;; Commentary:
  25.  
  26. ;; The project is hosted at https://github.com/sabof/org-bullets
  27. ;; The latest version, and all the relevant information can be found there.
  28.  
  29. ;;; Code:
  30.  
  31. (eval-when-compile (require 'cl))
  32.  
  33. (defgroup org-bullets nil
  34.   "Display bullets as UTF-8 characters"
  35.   :group 'org-appearance)
  36.  
  37. (defcustom org-bullets-bullet-list-expanded
  38.   '(;;; Large
  39.     "a"
  40.     "b"
  41.     "c"
  42.     "d"
  43.     )
  44.   "This variable contains the list of bullets.
  45. It can contain any number of symbols, which will be repeated."
  46.   :group 'org-bullets
  47.   :type '(repeat (string :tag "Bullet character")))
  48.  
  49. (defcustom org-bullets-bullet-list-collapsed
  50.   '(;;; Large
  51.     "A"
  52.     "B"
  53.     "C"
  54.     "D"
  55.     )
  56.   "This variable contains the list of bullets.
  57. It can contain any number of symbols, which will be repeated."
  58.   :group 'org-bullets
  59.   :type '(repeat (string :tag "Bullet character")))
  60.  
  61. (add-hook 'org-cycle-hook 'org-bullets-toggle-arrows)
  62.  
  63. (defun org-bullets-toggle-arrows (&optional arg)
  64.   (interactive)
  65.   ;; crappy: turning org-bullets-mode on and off again
  66.   (when org-bullets-mode
  67.     (org-bullets-mode 0)
  68.     (org-bullets-mode 1)))
  69.  
  70. (defcustom org-bullets-face-name nil
  71.   "This variable allows the org-mode bullets face to be
  72. overridden. If set to a name of a face, that face will be
  73. used. Otherwise the face of the heading level will be used."
  74.   :group 'org-bullets
  75.   :type 'symbol)
  76.  
  77. (defvar org-bullets-bullet-map
  78.   '(keymap
  79.     (mouse-1 . org-cycle)
  80.     (mouse-2
  81.      . (lambda (e)
  82.          (interactive "e")
  83.          (mouse-set-point e)
  84.          (org-cycle))))
  85.   "Mouse events for bullets.
  86. Should this be undesirable, one can remove them with
  87.  
  88. \(setcdr org-bullets-bullet-map nil\)")
  89.  
  90. (defun org-bullets-level-char (level next-block-hidden)
  91.   (if next-block-hidden
  92.       (string-to-char
  93.        (nth (mod (1- level)
  94.                  (length org-bullets-bullet-list-collapsed))
  95.             org-bullets-bullet-list-collapsed))
  96.     (string-to-char
  97.      (nth (mod (1- level)
  98.                (length org-bullets-bullet-list-expanded))
  99.           org-bullets-bullet-list-expanded))))
  100.  
  101. ;;;###autoload
  102. (define-minor-mode org-bullets-mode
  103.     "UTF8 Bullets for org-mode"
  104.   nil nil nil
  105.   (let* (( keyword
  106.            `(("^\\*+ "
  107.               (0 (let* (( level (- (match-end 0) (match-beginning 0) 1))
  108.                         ( is-inline-task
  109.                           (and (boundp 'org-inlinetask-min-level)
  110.                                (>= level org-inlinetask-min-level)))
  111.                         ( next-block-hidden (save-match-data
  112.                                                 (outline-end-of-heading) (outline-invisible-p))))
  113.                    (compose-region (- (match-end 0) 2)
  114.                                    (- (match-end 0) 1)
  115.                                    (org-bullets-level-char level next-block-hidden))
  116.                    (when is-inline-task
  117.                      (compose-region (- (match-end 0) 3)
  118.                                      (- (match-end 0) 2)
  119.                                      (org-bullets-level-char level next-block-hidden)))
  120.                    (when (facep org-bullets-face-name)
  121.                      (put-text-property (- (match-end 0)
  122.                                            (if is-inline-task 3 2))
  123.                                         (- (match-end 0) 1)
  124.                                         'face
  125.                                         org-bullets-face-name))
  126.                    (put-text-property (match-beginning 0)
  127.                                       (- (match-end 0) 2)
  128.                                       'face (list :foreground
  129.                                                   (face-attribute
  130.                                                    'default :background)))
  131.                    (put-text-property (match-beginning 0)
  132.                                       (match-end 0)
  133.                                       'keymap
  134.                                       org-bullets-bullet-map)
  135.                    nil))))))
  136.     (if org-bullets-mode
  137.         (progn
  138.           (font-lock-add-keywords nil keyword)
  139.           (font-lock-fontify-buffer))
  140.       (save-excursion
  141.         (goto-char (point-min))
  142.         (font-lock-remove-keywords nil keyword)
  143.         (while (re-search-forward "^\\*+ " nil t)
  144.           (decompose-region (match-beginning 0) (match-end 0)))
  145.         (font-lock-fontify-buffer))
  146.       )))
  147.  
  148. (provide 'org-bullets)
  149.  
  150. ;;; org-bullets.el ends here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement