Advertisement
Guest User

Untitled

a guest
Mar 16th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 6.44 KB | None | 0 0
  1. ;;; org-bullets.el --- Show bullets in org-mode as UTF-8 characters
  2. ;;; Version: 0.2.4
  3. ;;; Author: sabof
  4. ;;; URL: https://github.com/sabof/org-bullets
  5.  
  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.  
  23. ;;; Commentary:
  24.  
  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.
  27.  
  28. ;;; Code:
  29.  
  30. (eval-when-compile (require 'cl))
  31.  
  32. (defgroup org-bullets nil
  33.   "Display bullets as UTF-8 characters"
  34.   :group 'org-appearance)
  35.  
  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.     ;; ♥ ● ◇ ✚ ✜ ☯ ◆ ♠ ♣ ♦ ☢ ❀ ◆ ◖ ▶ ;; not in Terminus?
  44.     ;;; Small
  45.     ;; ► • ★ ▸
  46.     )
  47.   "This variable contains the list of bullets.
  48. It can contain any number of symbols, which will be repeated."
  49.   :group 'org-bullets
  50.   :type '(repeat (string :tag "Bullet character")))
  51. ;; ◈ ⚪⬭⧖▷⏵     ▶▷   ◾
  52. (defcustom org-bullets-bullet-expanded-list '("▼" ">" "-")
  53.   ""
  54.   :group 'org-bullets
  55.   :type '(repeat (string :tag "Bullet character")))
  56.  
  57. (defcustom org-bullets-face-name nil
  58.   "This variable allows the org-mode bullets face to be
  59. overridden. If set to a name of a face, that face will be
  60. used. Otherwise the face of the heading level will be used."
  61.   :group 'org-bullets
  62.   :type 'symbol)
  63.  
  64. (defcustom org-bullets-face-name-collapsed nil
  65.   "This variable allows the org-mode bullets face to be
  66. overridden. If set to a name of a face, that face will be
  67. used. Otherwise the face of the heading level will be used."
  68.   :group 'org-bullets
  69.   :type 'symbol)
  70.  
  71. (defface org-bullets-expanded-bullets-face
  72.   ;; You MUST modify the overlay face call in fastnav.el
  73.   '((t :foreground "#555555"))
  74.   "face for fastnap-zap-up-to-char..."
  75.   :group 'is-this-important)
  76. (defface org-bullets-collapsed-bullets-face
  77.   ;; You MUST modify the overlay face call in fastnav.el
  78.   '((t :foreground "#80C0F0"))
  79.   "face for fastnap-zap-up-to-char..."
  80.   :group 'is-this-important)
  81. (setq org-bullets-face-name           'org-bullets-expanded-bullets-face)
  82. (setq org-bullets-face-name-collapsed 'org-bullets-collapsed-bullets-face)
  83.  
  84. (defvar org-bullets-bullet-map
  85.   '(keymap
  86.     (mouse-1 . org-cycle)
  87.     (mouse-2
  88.      . (lambda (e)
  89.          (interactive "e")
  90.          (mouse-set-point e)
  91.          (org-cycle))))
  92.   "Mouse events for bullets.
  93. Should this be undesirable, one can remove them with
  94.  
  95. \(setcdr org-bullets-bullet-map nil\)")
  96.  
  97. ;; org-cycle-hook wants functions taking one arg
  98. (defun org-bullets-toggle-arrows (&optional arg)
  99.   (when org-bullets-mode
  100.     (font-lock-flush)
  101.     (font-lock-ensure)))
  102.  
  103. (add-hook 'org-cycle-hook 'org-bullets-toggle-arrows)
  104.  
  105. (defun org-bullets-level-char (level)
  106.   (string-to-char
  107.    (nth (mod (1- level)
  108.              (length org-bullets-bullet-list))
  109.         org-bullets-bullet-list)))
  110.  
  111. (defun org-bullets-level-char (level hidden)
  112.   (let* ((list (if hidden
  113.                    org-bullets-bullet-list
  114.                  org-bullets-bullet-expanded-list)))
  115.     (string-to-char (nth (mod (1- level) (length list)) list))))
  116.  
  117. ;;;###autoload
  118. (define-minor-mode org-bullets-mode
  119.     "UTF8 Bullets for org-mode"
  120.   nil nil nil
  121.   (let* (( keyword
  122.            `(("^\\*+ "
  123.               (0 (let* (( level (- (match-end 0) (match-beginning 0) 1))
  124.                         ( is-inline-task
  125.                           (and (boundp 'org-inlinetask-min-level)
  126.                                (>= level org-inlinetask-min-level)))
  127.                         ( block-hidden
  128.                           (save-match-data (outline-end-of-heading)
  129.                                            (outline-invisible-p))))
  130.                    (compose-region (- (match-end 0) 2)
  131.                                    (- (match-end 0) 1)
  132.                                    (org-bullets-level-char level block-hidden))
  133.                    (when is-inline-task
  134.                      (compose-region (- (match-end 0) 3)
  135.                                      (- (match-end 0) 2)
  136.                                      (org-bullets-level-char level block-hidden)))
  137.                    (when (facep org-bullets-face-name)
  138.                      (put-text-property (- (match-end 0)
  139.                                            (if is-inline-task 3 2))
  140.                                         (- (match-end 0) 1)
  141.                                         'face
  142.                                         (if block-hidden
  143.                                             org-bullets-face-name-collapsed
  144.                                             org-bullets-face-name)))
  145.                    (put-text-property (match-beginning 0)
  146.                                       (- (match-end 0) 2)
  147.                                       'face (list :foreground
  148.                                                   (face-attribute
  149.                                                    'default :background)))
  150.                    (put-text-property (match-beginning 0)
  151.                                       (match-end 0)
  152.                                       'keymap
  153.                                       org-bullets-bullet-map)
  154.                    nil))))))
  155.     (if org-bullets-mode
  156.         (progn
  157.           (font-lock-add-keywords nil keyword)
  158.           (font-lock-fontify-buffer))
  159.       (save-excursion
  160.         (goto-char (point-min))
  161.         (font-lock-remove-keywords nil keyword)
  162.         (while (re-search-forward "^\\*+ " nil t)
  163.           (decompose-region (match-beginning 0) (match-end 0)))
  164.         (font-lock-fontify-buffer))
  165.       )))
  166.  
  167. (provide 'org-bullets)
  168.  
  169. ;;; org-bullets.el ends here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement