emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Alex Branham <alex.branham@gmail.com>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: Org Mode List <emacs-orgmode@gnu.org>
Subject: Re: Support showing stars as pretty bullets
Date: Tue, 03 Apr 2018 09:30:27 -0500	[thread overview]
Message-ID: <87k1tofjlo.fsf@gmail.com> (raw)
In-Reply-To: <87woxoztd5.fsf@nicolasgoaziou.fr>

[-- Attachment #1: Type: text/plain, Size: 3801 bytes --]


On Tue 03 Apr 2018 at 01:39, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:

> Hello,
>
> Alex Branham <alex.branham@gmail.com> writes:
>
>> Why not, if you don't mind me asking? Other major modes (python, elisp,
>> and latex off the top of my head) setup prettify-symbols themselves.
>
> Because "org.el" file is already 23 kloc long, and I'm trying to put it
> on a diet.

Fair enough. How about the attached patch instead? It only sets up the
two local variables in org.el and puts the rest in org-entities.el since
that file is also concerned with replacing characters with "prettier"
versions of themselves.

Alex

------------------------------------------------------------

From fda030b62e4cf28e25fd3264472b01f498749d5a Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Tue, 3 Apr 2018 09:25:33 -0500
Subject: [PATCH] Add support for showing stars as UTF bullets

* lisp/org.el(org-mode): Add local variables
* lisp/org-entities.el(org-pretty-compose-p): New function
* lisp/org-entities.el(org-prettify-alist): New variable
* etc/ORG-NEWS: Document new feature.
---
 etc/ORG-NEWS         |  4 +++-
 lisp/org-entities.el | 17 +++++++++++++++++
 lisp/org.el          |  3 +++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 0edd77115..267ab336a 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -228,7 +228,9 @@ parameters.  See example bellow.
   select sysdate from dual;
   ,#+END_SRC
 #+END_SRC
-
+*** Add support for showing header stars as UTF-8 bullets
+This relies on ~prettify-symbols-mode~. To activate, either add this to
+~org-mode-hook~ or enable it globally with ~global-prettify-symbols-mode~.
 ** New functions
 *** ~org-insert-structure-template~

diff --git a/lisp/org-entities.el b/lisp/org-entities.el
index e291b521f..f4bdf9de8 100644
--- a/lisp/org-entities.el
+++ b/lisp/org-entities.el
@@ -29,6 +29,7 @@

 (declare-function org-toggle-pretty-entities "org"       ())
 (declare-function org-table-align            "org-table" ())
+(declare-function prettify-symbols-default-compose-p "prog-mode" (start end match))

 (defgroup org-entities nil
   "Options concerning entities in Org mode."
@@ -589,6 +590,22 @@ This first checks the user list, then the built-in list."
       (org-toggle-pretty-entities)))
   (select-window (get-buffer-window "*Org Entity Help*")))

+;; prettify-mode
+(defvar-local org-prettify-alist '(("*" . ?•))
+  "An alist of symbols to prettify, see `prettify-symbols-alist'.
+Whether the symbol actually gets prettified is controlled by
+`org-pretty-compose-p', which see.")
+
+(defun org-pretty-compose-p (start end match)
+  "Return t if the symbol should be prettified.
+START and END are the start and end points, MATCH is the string
+match.  See also `prettify-symbols-compose-predicate'."
+  (if (string= match "*")
+      ;; prettify asterisks in headings
+      (org-at-heading-p)
+    ;; else rely on the default function
+    (funcall #'prettify-symbols-default-compose-p start end match)))
+

 (provide 'org-entities)

diff --git a/lisp/org.el b/lisp/org.el
index 5e5087a59..6bf7fef2d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5487,6 +5487,9 @@ The following commands are available:
      (when org-startup-truncated (setq truncate-lines t))
      (when org-startup-indented (require 'org-indent) (org-indent-mode 1))
      (org-refresh-effort-properties)))
+  ;; Setup prettify mode
+  (setq-local prettify-symbols-alist org-prettify-alist)
+  (setq-local prettify-symbols-compose-predicate #'org-pretty-compose-p)
   ;; Try to set `org-hide' face correctly.
   (let ((foreground (org-find-invisible-foreground)))
     (when foreground
--
2.16.3




[-- Attachment #2: 0001-Add-support-for-showing-stars-as-UTF-bullets.patch --]
[-- Type: text/x-patch, Size: 3098 bytes --]

From fda030b62e4cf28e25fd3264472b01f498749d5a Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Tue, 3 Apr 2018 09:25:33 -0500
Subject: [PATCH] Add support for showing stars as UTF bullets

* lisp/org.el(org-mode): Add local variables
* lisp/org-entities.el(org-pretty-compose-p): New function
* lisp/org-entities.el(org-prettify-alist): New variable
* etc/ORG-NEWS: Document new feature.
---
 etc/ORG-NEWS         |  4 +++-
 lisp/org-entities.el | 17 +++++++++++++++++
 lisp/org.el          |  3 +++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 0edd77115..267ab336a 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -228,7 +228,9 @@ parameters.  See example bellow.
   select sysdate from dual;
   ,#+END_SRC
 #+END_SRC
-
+*** Add support for showing header stars as UTF-8 bullets
+This relies on ~prettify-symbols-mode~. To activate, either add this to
+~org-mode-hook~ or enable it globally with ~global-prettify-symbols-mode~.
 ** New functions
 *** ~org-insert-structure-template~
 
diff --git a/lisp/org-entities.el b/lisp/org-entities.el
index e291b521f..f4bdf9de8 100644
--- a/lisp/org-entities.el
+++ b/lisp/org-entities.el
@@ -29,6 +29,7 @@
 
 (declare-function org-toggle-pretty-entities "org"       ())
 (declare-function org-table-align            "org-table" ())
+(declare-function prettify-symbols-default-compose-p "prog-mode" (start end match))
 
 (defgroup org-entities nil
   "Options concerning entities in Org mode."
@@ -589,6 +590,22 @@ This first checks the user list, then the built-in list."
       (org-toggle-pretty-entities)))
   (select-window (get-buffer-window "*Org Entity Help*")))
 
+;; prettify-mode
+(defvar-local org-prettify-alist '(("*" . ?•))
+  "An alist of symbols to prettify, see `prettify-symbols-alist'.
+Whether the symbol actually gets prettified is controlled by
+`org-pretty-compose-p', which see.")
+
+(defun org-pretty-compose-p (start end match)
+  "Return t if the symbol should be prettified.
+START and END are the start and end points, MATCH is the string
+match.  See also `prettify-symbols-compose-predicate'."
+  (if (string= match "*")
+      ;; prettify asterisks in headings
+      (org-at-heading-p)
+    ;; else rely on the default function
+    (funcall #'prettify-symbols-default-compose-p start end match)))
+
 
 (provide 'org-entities)
 
diff --git a/lisp/org.el b/lisp/org.el
index 5e5087a59..6bf7fef2d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5487,6 +5487,9 @@ The following commands are available:
      (when org-startup-truncated (setq truncate-lines t))
      (when org-startup-indented (require 'org-indent) (org-indent-mode 1))
      (org-refresh-effort-properties)))
+  ;; Setup prettify mode
+  (setq-local prettify-symbols-alist org-prettify-alist)
+  (setq-local prettify-symbols-compose-predicate #'org-pretty-compose-p)
   ;; Try to set `org-hide' face correctly.
   (let ((foreground (org-find-invisible-foreground)))
     (when foreground
-- 
2.16.3


  reply	other threads:[~2018-04-03 14:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-01 20:59 Alex Branham
2018-04-02 18:47 ` Nicolas Goaziou
2018-04-03  0:41   ` Alex Branham
2018-04-03  1:11     ` William Denton
2018-04-03  6:39     ` Nicolas Goaziou
2018-04-03 14:30       ` Alex Branham [this message]
2018-04-03 20:33         ` Nicolas Goaziou
2018-04-04 22:14           ` Alex Branham
2018-04-05 12:50             ` Nicolas Goaziou
2018-04-10 16:00               ` Alex Branham
2018-04-14 10:20                 ` Nicolas Goaziou
2018-04-14 13:10                   ` Rasmus
2018-04-06 20:22         ` Rasmus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k1tofjlo.fsf@gmail.com \
    --to=alex.branham@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    --subject='Re: Support showing stars as pretty bullets' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).