emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Support showing stars as pretty bullets
@ 2018-04-01 20:59 Alex Branham
  2018-04-02 18:47 ` Nicolas Goaziou
  0 siblings, 1 reply; 13+ messages in thread
From: Alex Branham @ 2018-04-01 20:59 UTC (permalink / raw)
  To: Org Mode List

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

Hello,

I've written this patch that makes use of prettify-symbols-mode to show
the stars in org headings as nice UTF bullets. There's already
org-bullet-mode[1] but that seems to have been abandoned, plus it isn't
included in org mode itself.

The one bug right now is that it'll show an asterisk as a UTF bullet if
it's _anywhere_ on a heading line. Is there an easy way to check if a
character is a part of the beginning stars? If this is something you'd
be interested in adding to org-mode, I can fix this part before the
change gets applied.

I've checked it out with and without org-indent-mode and hiding leading
stars. Everything seems to work well for me.

I've already signed the FSF copyright assignment papers.

Please cc me on replies since I'm not subscribed to the devel list :-)

Thanks,
Alex

Footnotes:
[1]  https://github.com/sabof/org-bullets

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

From 8ab48ccd43446bbe447108153c2dbb742d81895b Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Sun, 1 Apr 2018 15:49:31 -0500
Subject: [PATCH] Add support for showing stars as UTF bullets

* lisp/org.el(org-mode): Add local variables
* lisp/org.el(org-pretty-compose-p): New function
* lisp/org.el(org-prettify-alist): New variable
* etc/ORG-NEWS: Document new feature.
---
 etc/ORG-NEWS |  3 +++
 lisp/org.el  | 15 +++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 0edd77115..bb57e9e82 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -228,6 +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.el b/lisp/org.el
index 5e5087a59..35cc33c00 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
@@ -9551,6 +9554,18 @@ The cdr of LINK must be either a link description or nil."
     (concat (format "%-45s" (substring desc 0 (min (length desc) 40)))
 	    "<" (car link) ">")))

+(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.
+MATCH is the string match.  See also
+`prettify-symbols-compose-predicate'."
+  (when (string= match "*")
+    (org-at-heading-p)))
+
 ;;;###autoload
 (defun org-insert-link-global ()
   "Insert a link like Org mode does.
--
2.16.3



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

From 8ab48ccd43446bbe447108153c2dbb742d81895b Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Sun, 1 Apr 2018 15:49:31 -0500
Subject: [PATCH] Add support for showing stars as UTF bullets

* lisp/org.el(org-mode): Add local variables
* lisp/org.el(org-pretty-compose-p): New function
* lisp/org.el(org-prettify-alist): New variable
* etc/ORG-NEWS: Document new feature.
---
 etc/ORG-NEWS |  3 +++
 lisp/org.el  | 15 +++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 0edd77115..bb57e9e82 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -228,6 +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.el b/lisp/org.el
index 5e5087a59..35cc33c00 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
@@ -9551,6 +9554,18 @@ The cdr of LINK must be either a link description or nil."
     (concat (format "%-45s" (substring desc 0 (min (length desc) 40)))
 	    "<" (car link) ">")))
 
+(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.
+MATCH is the string match.  See also
+`prettify-symbols-compose-predicate'."
+  (when (string= match "*")
+    (org-at-heading-p)))
+
 ;;;###autoload
 (defun org-insert-link-global ()
   "Insert a link like Org mode does.
-- 
2.16.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: Support showing stars as pretty bullets
  2018-04-01 20:59 Support showing stars as pretty bullets Alex Branham
@ 2018-04-02 18:47 ` Nicolas Goaziou
  2018-04-03  0:41   ` Alex Branham
  0 siblings, 1 reply; 13+ messages in thread
From: Nicolas Goaziou @ 2018-04-02 18:47 UTC (permalink / raw)
  To: Alex Branham; +Cc: Org Mode List

Hello,

Alex Branham <alex.branham@gmail.com> writes:

> I've written this patch that makes use of prettify-symbols-mode to show
> the stars in org headings as nice UTF bullets. There's already
> org-bullet-mode[1] but that seems to have been abandoned, plus it isn't
> included in org mode itself.

Is it abandoned, or simply complete? Org lists haven't changed for
a while.

In any case, I don't think this belongs to "org.el" proper. 

It could go into some "org-art.el" library (along with Org bullet mode,
or something that would auto-number headlines) within the code base, or
simply in GNU ELPA.

WDYT?

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Support showing stars as pretty bullets
  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
  0 siblings, 2 replies; 13+ messages in thread
From: Alex Branham @ 2018-04-03  0:41 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode List


On Mon 02 Apr 2018 at 13:47, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:

> Hello,
>
> Alex Branham <alex.branham@gmail.com> writes:
>
>> I've written this patch that makes use of prettify-symbols-mode to show
>> the stars in org headings as nice UTF bullets. There's already
>> org-bullet-mode[1] but that seems to have been abandoned, plus it isn't
>> included in org mode itself.
>
> Is it abandoned, or simply complete? Org lists haven't changed for
> a while.

Seems abandoned. The author hasn't had any activity on github since May
2015. Several issues and PR's have accumulated. Mind you, it still works
well overall. Looking more into this, there's already been some
discussion about it: https://github.com/sabof/org-bullets/issues/18

> In any case, I don't think this belongs to "org.el" proper.

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.

> It could go into some "org-art.el" library (along with Org bullet mode,
> or something that would auto-number headlines) within the code base, or
> simply in GNU ELPA.

I'm fine putting it into org-XXX.el if you want. I didn't for now since
it's only a few lines of code.

Thanks for the comments!
Alex

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Support showing stars as pretty bullets
  2018-04-03  0:41   ` Alex Branham
@ 2018-04-03  1:11     ` William Denton
  2018-04-03  6:39     ` Nicolas Goaziou
  1 sibling, 0 replies; 13+ messages in thread
From: William Denton @ 2018-04-03  1:11 UTC (permalink / raw)
  To: Org Mode List

On 2 April 2018, Alex Branham wrote:

>> It could go into some "org-art.el" library (along with Org bullet mode,
>> or something that would auto-number headlines) within the code base, or
>> simply in GNU ELPA.
>
> I'm fine putting it into org-XXX.el if you want. I didn't for now since
> it's only a few lines of code.

Wherever it goes, it would be great if it's integrated into the code base.  It's 
a very nice visual improvement.

Bill
--
William Denton :: Toronto, Canada   ---   Listening to Art: https://listeningtoart.org/
https://www.miskatonic.org/         ---   GHG.EARTH: http://ghg.earth/
Caveat lector.                      ---   STAPLR: http://staplr.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Support showing stars as pretty bullets
  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
  1 sibling, 1 reply; 13+ messages in thread
From: Nicolas Goaziou @ 2018-04-03  6:39 UTC (permalink / raw)
  To: Alex Branham; +Cc: Org Mode List

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.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Support showing stars as pretty bullets
  2018-04-03  6:39     ` Nicolas Goaziou
@ 2018-04-03 14:30       ` Alex Branham
  2018-04-03 20:33         ` Nicolas Goaziou
  2018-04-06 20:22         ` Rasmus
  0 siblings, 2 replies; 13+ messages in thread
From: Alex Branham @ 2018-04-03 14:30 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode List

[-- 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


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: Support showing stars as pretty bullets
  2018-04-03 14:30       ` Alex Branham
@ 2018-04-03 20:33         ` Nicolas Goaziou
  2018-04-04 22:14           ` Alex Branham
  2018-04-06 20:22         ` Rasmus
  1 sibling, 1 reply; 13+ messages in thread
From: Nicolas Goaziou @ 2018-04-03 20:33 UTC (permalink / raw)
  To: Alex Branham; +Cc: Org Mode List


> 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.

I don't think it belongs to "org-entities.el" either. While it is true
there is some prettification done there, this is not the sole point of
the library. IOW, it is more than eye-candy; it affects, e.g., export.

I really think it should go into a new "org-art.el" file.

More comments follow.

> +;; 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.")

Should this be a defcustom?

Also, note that the name space must match library, so if it goes into
"org-art.el", it ought to be named, e.g., `org-art-prettify-alist'.

> +(defun org-pretty-compose-p (start end match)
> +  "Return t if the symbol should be prettified.

"Non-nil if symbol between START and END should be prettified.
MATCH is ..."

> +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)

Doesn't this mean that any bold object in headline is going to be
prettified?

Maybe something like this (untested):

  (and (org-match-line org-outline-regexp-bol)
       (< end (match-end 0)))

> +    ;; else rely on the default function

Nitpick:

  ";; Else rely on the default function."
  
> +  ;; Setup prettify mode

Ditto:

  ";; Setup prettify mode."

> +  (setq-local prettify-symbols-alist org-prettify-alist)
> +  (setq-local prettify-symbols-compose-predicate
> #'org-pretty-compose-p)

This should also go into "org-art.el", which is an optional library. We
don't want to activate anything related to it every time Org is loaded.

Can it be tested somehow?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Support showing stars as pretty bullets
  2018-04-03 20:33         ` Nicolas Goaziou
@ 2018-04-04 22:14           ` Alex Branham
  2018-04-05 12:50             ` Nicolas Goaziou
  0 siblings, 1 reply; 13+ messages in thread
From: Alex Branham @ 2018-04-04 22:14 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode List


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

>> 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.
>
> I don't think it belongs to "org-entities.el" either. While it is true
> there is some prettification done there, this is not the sole point of
> the library. IOW, it is more than eye-candy; it affects, e.g., export.
>
> I really think it should go into a new "org-art.el" file.

The issue I see with putting it into org-art.el is that users won't be
able to just call M-x prettify-symbols-mode in an org buffer. They'll
have to do something like

(require 'org-art)
(add-hook 'org-mode-hook #'org-art-prettify)

or something like that. It seems like more work for users than setting
two variables in org-mode. There's also no way for users who prefer M-x
customize to easily activate it (unless we add a defcustom to org.el...)
Or am I missing something?

Let me know, everything else below is relatively minor.

Thanks again!

> More comments follow.
>
>> +;; 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.")
>
> Should this be a defcustom?

prettify-symbols-alist isn't, so I don't think this should be either.

> Also, note that the name space must match library, so if it goes into
> "org-art.el", it ought to be named, e.g., `org-art-prettify-alist'.

Will do

>> +(defun org-pretty-compose-p (start end match)
>> +  "Return t if the symbol should be prettified.
>
> "Non-nil if symbol between START and END should be prettified.
> MATCH is ..."

Sure thing

>> +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)
>
> Doesn't this mean that any bold object in headline is going to be
> prettified?
>
> Maybe something like this (untested):
>
>   (and (org-match-line org-outline-regexp-bol)
>        (< end (match-end 0)))

Thanks, this fixes the bug I mentioned in my first email. Seems to work
well on my end, too!

>> +    ;; else rely on the default function
>
> Nitpick:
>
>   ";; Else rely on the default function."
>
>> +  ;; Setup prettify mode
>
> Ditto:
>
>   ";; Setup prettify mode."

Sure, I'll fix those

>> +  (setq-local prettify-symbols-alist org-prettify-alist)
>> +  (setq-local prettify-symbols-compose-predicate
>> #'org-pretty-compose-p)
>
> This should also go into "org-art.el", which is an optional library. We
> don't want to activate anything related to it every time Org is loaded.
>
> Can it be tested somehow?

I'll look into it

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Support showing stars as pretty bullets
  2018-04-04 22:14           ` Alex Branham
@ 2018-04-05 12:50             ` Nicolas Goaziou
  2018-04-10 16:00               ` Alex Branham
  0 siblings, 1 reply; 13+ messages in thread
From: Nicolas Goaziou @ 2018-04-05 12:50 UTC (permalink / raw)
  To: Alex Branham; +Cc: Org Mode List

Hello,

Alex Branham <alex.branham@gmail.com> writes:

> The issue I see with putting it into org-art.el is that users won't be
> able to just call M-x prettify-symbols-mode in an org buffer. They'll
> have to do something like
>
> (require 'org-art)
> (add-hook 'org-mode-hook #'org-art-prettify)

I don't think users should call M-x prettify-symbols-mode. Instead, they
could call `org-art-prettify-buffer', an autoloaded function, which
would properly initialize `prettify-symbols-mode' and so on. What
mechanism is behind prettification is not important.

BTW, we could have a defcustom listings all eye candy
`org-art-prettify-buffer' -- or simply `org-prettify-buffer' if the
library is called "org-prettify" -- could do (e.g., headlines,
bullets...).

> prettify-symbols-alist isn't, so I don't think this should be either.

Of course. But Org users may want to control what symbol is used.
Anyway, I don't have a strong opinion about it.

>>> +(defun org-pretty-compose-p (start end match)
>>> +  "Return t if the symbol should be prettified.
>>
>> "Non-nil if symbol between START and END should be prettified.
>> MATCH is ..."
>
> Sure thing

Actually, I was mistaken: this is a function, not a variable. So, it
should be more like:

  Return non-nil when symbol between START and END is to be prettified.

>> Can it be tested somehow?
>
> I'll look into it

Thank you.

Regards,

-- 
Nicolas Goaziou                                                0x80A93738

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Support showing stars as pretty bullets
  2018-04-03 14:30       ` Alex Branham
  2018-04-03 20:33         ` Nicolas Goaziou
@ 2018-04-06 20:22         ` Rasmus
  1 sibling, 0 replies; 13+ messages in thread
From: Rasmus @ 2018-04-06 20:22 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Thanks for looking at this.  I’ll definitely use this.

Alex Branham <alex.branham@gmail.com> writes:

> +  (setq-local prettify-symbols-alist org-prettify-alist)

Hmm, wouldn’t this "break" the "normal" usage of prettify-symbols-mode?

I guess it would be better to simply add symbols to prettify-symbols-alist
(I believe ESS does that).  Alternatively, perhaps org-prettify-alist
could be locally bound in org-pretty-compose-p.

Thanks,
Rasmus

-- 
Warning: Everything saved will be lost

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Support showing stars as pretty bullets
  2018-04-05 12:50             ` Nicolas Goaziou
@ 2018-04-10 16:00               ` Alex Branham
  2018-04-14 10:20                 ` Nicolas Goaziou
  0 siblings, 1 reply; 13+ messages in thread
From: Alex Branham @ 2018-04-10 16:00 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode List

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


On Thu 05 Apr 2018 at 07:50, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:

Hi, and sorry for the delayed response.

> I don't think users should call M-x prettify-symbols-mode. Instead, they
> could call `org-art-prettify-buffer', an autoloaded function, which
> would properly initialize `prettify-symbols-mode' and so on. What
> mechanism is behind prettification is not important.

But then users of global-prettify-symbols-mode don't see the pretty
symbols in org buffers without knowing about and activating
org-pretty-mode. Anyway, the attached patch moves it to org-pretty.el.

> BTW, we could have a defcustom listings all eye candy
> `org-art-prettify-buffer' -- or simply `org-prettify-buffer' if the
> library is called "org-prettify" -- could do (e.g., headlines,
> bullets...).
>
>> prettify-symbols-alist isn't, so I don't think this should be either.
>
> Of course. But Org users may want to control what symbol is used.
> Anyway, I don't have a strong opinion about it.

I've left it as a defvar since there's no way for us to know about what
people want prettified where. Hopefully the default
prettify-symbols-compose-p function does an OK job, but people will have
to modify that if they customize org-pretty-alist anyway.

>>> Can it be tested somehow?
>>
>> I'll look into it

Can you see if these tests work for you? They work on my end, but I'm
not sure where to put them. Should they go into a new file
testing/lisp/test-org-pretty.el?

(ert-deftest test-org-pretty-mode ()
  "Test `org-pretty-mode'."
  (should
   (equal t
	  (org-test-with-temp-text
	      "* Test"
	    (org-pretty-mode)
	    (org-pretty-compose-p 1 1 "*")
	    )))
  (should-not
   (equal t
	  (org-test-with-temp-text
	      "* Test *"
	    (org-pretty-mode)
	    (org-pretty-compose-p 8 8 "*")))))


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

From 3278c7dd9d426bf205542c78d51456a96196988b Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Tue, 10 Apr 2018 10:38:09 -0500
Subject: [PATCH] New minor mode org-pretty-mode

* lisp/org-pretty.el: New file
* etc/ORG-NEWS: Document new minor mode
---
 etc/ORG-NEWS       |  9 ++++++
 lisp/org-pretty.el | 71 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+)
 create mode 100644 lisp/org-pretty.el

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 0edd77115..0339a2df3 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -228,7 +228,16 @@ parameters.  See example bellow.
   select sysdate from dual;
   ,#+END_SRC
 #+END_SRC
+*** New minor mode ~org-pretty-mode~ supports showing prettier characters.
+By default, it replaces asterisks in headings with a utf8 bullet: •

+To enable, either call M-x org-pretty-mode or add
+
+#+BEGIN_SRC elisp
+  (add-hook 'org-mode-hook #'org-pretty-mode)
+#+END_SRC
+
+to your configuration file.
 ** New functions
 *** ~org-insert-structure-template~

diff --git a/lisp/org-pretty.el b/lisp/org-pretty.el
new file mode 100644
index 000000000..2f2aaa68d
--- /dev/null
+++ b/lisp/org-pretty.el
@@ -0,0 +1,71 @@
+;;; org-pretty.el --- Support for prettify-symbols-mode  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2018 Free Software Foundation, Inc.
+;;
+;; Author: J. Alexander Branham <alex.branham at gmail dot com>
+;; Maintainer: emacs-orgmode@gnu.org
+;;
+;; This file is part of GNU Emacs.
+;;
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+;;
+;;; Commentary:
+;;
+;; This file adds support for `prettify-symbols-mode' in Org buffers.
+;; To use, call M-x org-prettify-mode or put
+;;
+;; (add-hook 'org-mode-hook #'org-prettify-mode)
+;;
+;; in your configuration file.
+
+;;; Code:
+
+(require 'org)
+
+(defvar-local org-pretty-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 non-nil if the symbol between START and END is to be prettified.
+MATCH is the string match.  See also
+`prettify-symbols-compose-predicate'."
+  (if (string= match "*")
+      ;; Prettify asterisks in headings.
+      (and (org-match-line org-outline-regexp-bol)
+	   (< end (match-end 0)))
+    ;; Else rely on the default function.
+    (funcall #'prettify-symbols-default-compose-p start end match)))
+
+;;;###autoload
+(define-minor-mode org-pretty-mode
+  "Set up `prettify-symbols-mode' in org buffers."
+  :lighter nil
+  :keymap nil
+  (if org-pretty-mode
+      ;; Turn on.
+      (when (eq major-mode 'org-mode)
+	(setq-local prettify-symbols-alist org-pretty-alist)
+	(setq-local prettify-symbols-compose-predicate #'org-pretty-compose-p)
+	(prettify-symbols-mode))
+    ;; Turn off.
+    (when (eq major-mode 'org-mode)
+      (setq-local prettify-symbols-alist nil)
+      (setq-local prettify-symbols-compose-predicate #'prettify-symbols-default-compose-p)
+      (prettify-symbols-mode -1))))
+
+(provide 'org-pretty)
+
+;;; org-pretty.el ends here
--
2.17.0


[-- Attachment #2: 0001-New-minor-mode-org-pretty-mode.patch --]
[-- Type: text/x-patch, Size: 3867 bytes --]

From 3278c7dd9d426bf205542c78d51456a96196988b Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Tue, 10 Apr 2018 10:38:09 -0500
Subject: [PATCH] New minor mode org-pretty-mode

* lisp/org-pretty.el: New file
* etc/ORG-NEWS: Document new minor mode
---
 etc/ORG-NEWS       |  9 ++++++
 lisp/org-pretty.el | 71 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+)
 create mode 100644 lisp/org-pretty.el

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 0edd77115..0339a2df3 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -228,7 +228,16 @@ parameters.  See example bellow.
   select sysdate from dual;
   ,#+END_SRC
 #+END_SRC
+*** New minor mode ~org-pretty-mode~ supports showing prettier characters.
+By default, it replaces asterisks in headings with a utf8 bullet: •
 
+To enable, either call M-x org-pretty-mode or add
+
+#+BEGIN_SRC elisp
+  (add-hook 'org-mode-hook #'org-pretty-mode)
+#+END_SRC
+
+to your configuration file.
 ** New functions
 *** ~org-insert-structure-template~
 
diff --git a/lisp/org-pretty.el b/lisp/org-pretty.el
new file mode 100644
index 000000000..2f2aaa68d
--- /dev/null
+++ b/lisp/org-pretty.el
@@ -0,0 +1,71 @@
+;;; org-pretty.el --- Support for prettify-symbols-mode  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2018 Free Software Foundation, Inc.
+;;
+;; Author: J. Alexander Branham <alex.branham at gmail dot com>
+;; Maintainer: emacs-orgmode@gnu.org
+;;
+;; This file is part of GNU Emacs.
+;;
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+;;
+;;; Commentary:
+;;
+;; This file adds support for `prettify-symbols-mode' in Org buffers.
+;; To use, call M-x org-prettify-mode or put
+;;
+;; (add-hook 'org-mode-hook #'org-prettify-mode)
+;;
+;; in your configuration file.
+
+;;; Code:
+
+(require 'org)
+
+(defvar-local org-pretty-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 non-nil if the symbol between START and END is to be prettified.
+MATCH is the string match.  See also
+`prettify-symbols-compose-predicate'."
+  (if (string= match "*")
+      ;; Prettify asterisks in headings.
+      (and (org-match-line org-outline-regexp-bol)
+	   (< end (match-end 0)))
+    ;; Else rely on the default function.
+    (funcall #'prettify-symbols-default-compose-p start end match)))
+
+;;;###autoload
+(define-minor-mode org-pretty-mode
+  "Set up `prettify-symbols-mode' in org buffers."
+  :lighter nil
+  :keymap nil
+  (if org-pretty-mode
+      ;; Turn on.
+      (when (eq major-mode 'org-mode)
+	(setq-local prettify-symbols-alist org-pretty-alist)
+	(setq-local prettify-symbols-compose-predicate #'org-pretty-compose-p)
+	(prettify-symbols-mode))
+    ;; Turn off.
+    (when (eq major-mode 'org-mode)
+      (setq-local prettify-symbols-alist nil)
+      (setq-local prettify-symbols-compose-predicate #'prettify-symbols-default-compose-p)
+      (prettify-symbols-mode -1))))
+
+(provide 'org-pretty)
+
+;;; org-pretty.el ends here
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: Support showing stars as pretty bullets
  2018-04-10 16:00               ` Alex Branham
@ 2018-04-14 10:20                 ` Nicolas Goaziou
  2018-04-14 13:10                   ` Rasmus
  0 siblings, 1 reply; 13+ messages in thread
From: Nicolas Goaziou @ 2018-04-14 10:20 UTC (permalink / raw)
  To: Alex Branham; +Cc: Org Mode List

Hello,

Alex Branham <alex.branham@gmail.com> writes:

> But then users of global-prettify-symbols-mode don't see the pretty
> symbols in org buffers without knowing about and activating
> org-pretty-mode. Anyway, the attached patch moves it to org-pretty.el.

[...]

> I've left it as a defvar since there's no way for us to know about what
> people want prettified where. Hopefully the default
> prettify-symbols-compose-p function does an OK job, but people will have
> to modify that if they customize org-pretty-alist anyway.

I think there's a misunderstanding. To me, `prettify-symbols-mode' is
the plumbing. Org Pretty users should not have to care about it.
Likewise, when you use Org Bullets, you don't really care about how it
is done internally.

As such, we know what people want prettified if we provide the
appropriate defcustom.

BTW, the plumbing should be `compose-region', not
`prettify-symbols-mode'.

WDYT?

Regards,

-- 
Nicolas Goaziou                                                0x80A93738

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Support showing stars as pretty bullets
  2018-04-14 10:20                 ` Nicolas Goaziou
@ 2018-04-14 13:10                   ` Rasmus
  0 siblings, 0 replies; 13+ messages in thread
From: Rasmus @ 2018-04-14 13:10 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> Alex Branham <alex.branham@gmail.com> writes:
>
>> But then users of global-prettify-symbols-mode don't see the pretty
>> symbols in org buffers without knowing about and activating
>> org-pretty-mode. Anyway, the attached patch moves it to org-pretty.el.
>
> [...]
>
>> I've left it as a defvar since there's no way for us to know about what
>> people want prettified where. Hopefully the default
>> prettify-symbols-compose-p function does an OK job, but people will have
>> to modify that if they customize org-pretty-alist anyway.
>
> I think there's a misunderstanding. To me, `prettify-symbols-mode' is
> the plumbing. Org Pretty users should not have to care about it.
> Likewise, when you use Org Bullets, you don't really care about how it
> is done internally.
>
> As such, we know what people want prettified if we provide the
> appropriate defcustom.
>
> BTW, the plumbing should be `compose-region', not
> `prettify-symbols-mode'.

IMO ‘prettify-symbols-mode’ is not pluming.  It’s an Emacs-wide equivalent
of "org-pretty-entities" (or at least the result when that variable is
non-nil).

IMO, the goal would be to offload more stuff into prettify-symbols-mode.
Since this involves a "regexp" in a sense, compose-region might be better.

In any case, the particular patch overwrites ‘prettify-symbols-alist’,
meaning which symbols will be displayed will depend on whether users have
their own pretty symbols loaded before the variable is being overwritten.

Rasmus

-- 
In theory, practice and theory are the same. In practice they are not

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2018-04-14 13:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-01 20:59 Support showing stars as pretty bullets 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
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

Code repositories for project(s) associated with this public 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).