Skip to content

Commit

Permalink
Honor ‘org-inlinetask-show-first-star’.
Browse files Browse the repository at this point in the history
Added various functions and custom variables to accomodate new
feature.  This is the first step towards addressing issue #5.

Moved org-superstar-remove-leading-stars to a more appropriate
location.
  • Loading branch information
integral-dw committed Aug 16, 2020
1 parent 9ee9812 commit 4b4ddd7
Showing 1 changed file with 108 additions and 26 deletions.
134 changes: 108 additions & 26 deletions org-superstar.el
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,58 @@ variable for your changes to take effect."
(character :value ?◉
:format "Fallback character for terminal: %v\n")))))

(defun org-superstar--set-fbullet (symbol value)
"Set SYMBOL ‘org-superstar-first-inlinetask-bullet’ to VALUE.
If set to a character, also set ‘org-superstar-first-inlinetask-fallback’."
(set-default symbol value)
(when (characterp value)
(set-default 'org-superstar-first-inlinetask-fallback value)))

(defcustom org-superstar-first-inlinetask-bullet ?▶
"A special bullet used for the first star of an inline task.
Normally, this variable is a character replacing the default
star. If it’s a string, compose the replacement according to the
rules of ‘compose-region’ for the COMPONENTS argument.
This bullet is displayed using the dedicated face
‘org-superstar-first’.
This variable is only used for graphical displays.
‘org-superstar-first-inlinetask-fallback’ is used for terminal
displays instead.
You should call ‘org-superstar-restart’ after changing this
variable for your changes to take effect."
:group 'org-superstar
:type '(choice
(character :tag "Single character to display"
:format "\n%t: %v\n"
:value ?▶)
(string :tag "String of characters to compose replacement from"
:format "\n%t:\n%v"
:value "*"))
:set #'org-superstar--set-fbullet)

(defcustom org-superstar-first-inlinetask-fallback
(cond ((characterp org-superstar-first-inlinetask-bullet)
org-superstar-first-inlinetask-bullet)
(t ?*))
"A special bullet used for the first star of an inline task.
This variable is a character replacing the default star in
terminal displays instead of ‘org-superstar-first-inlinetask-bullet’.
If the leading bullet is set to a character before the package is
loaded, this variable’s default value is set to that character as
well. Setting the leading bullet to a character using the custom
interface also automatically sets this variable.
You should call ‘org-superstar-restart’ after changing this
variable for your changes to take effect."
:group 'org-superstar
:type '(character :tag "Single character to display"
:format "\n%t: %v\n"
:value ?*))

;;;###autoload
(put 'org-superstar-leading-bullet
'safe-local-variable
Expand Down Expand Up @@ -320,6 +372,26 @@ keyword)."
There is usually no need to use this variable directly; instead,
use the command ‘org-superstar-toggle-lightweight-lists’.")

(defcustom org-superstar-remove-leading-stars nil
"Non-nil means font-lock should hide leading star characters.
A more radical version of ‘org-hide-leading-stars’, where the
indentation caused by leading stars is completely removed. It
works similar to ‘org-hide-emphasis-markers’.
If Non-nil, this variable takes precedence over
‘org-hide-leading-stars’.
This variable only eliminates indentation caused directly by
leading stars, meaning additional indentation should be
preserved. For an example of this, see the minor-mode command
‘org-indent-mode’.
You should call ‘org-superstar-restart’ after changing this
variable for your changes to take effect."
:group 'org-superstar
:type 'boolean)


;;; Faces

Expand Down Expand Up @@ -347,25 +419,11 @@ unspecified inherits the org-level-X faces for header bullets."
"Face used to display prettified item bullets."
:group 'org-superstar)

(defcustom org-superstar-remove-leading-stars nil
"Non-nil means font-lock should hide leading star characters.
A more radical version of ‘org-hide-leading-stars’, where the
indentation caused by leading stars is completely removed. It
works similar to ‘org-hide-emphasis-markers’.
If Non-nil, this variable takes precedence over
‘org-hide-leading-stars’.
This variable only eliminates indentation caused directly by
leading stars, meaning additional indentation should be
preserved. For an example of this, see the minor-mode command
‘org-indent-mode’.
You should call ‘org-superstar-restart’ after changing this
variable for your changes to take effect."
:group 'org-superstar
:type 'boolean)
(defface org-superstar-first
'((default . (:inherit org-warning)))
"Face used to display the first bullet of an inline task.
This face is only used when ‘org-inlinetask-show-first-star’ is
non-nil.")


;;; Functions intended for users
Expand Down Expand Up @@ -483,8 +541,6 @@ N counts from zero. Headline bullets are specified in
(let ((bullet-entry
(elt org-superstar-headline-bullets-list n)))
(cond
;; Using characters for bullets is actually way more consistent
;; with the rest of the package, so why not just support it.
((characterp bullet-entry)
bullet-entry)
;; Strip bullets provided as strings down to their first char.
Expand Down Expand Up @@ -514,6 +570,12 @@ replaced by their corresponding entry in ‘org-superstar-item-bullet-alist’."
org-superstar-leading-bullet
org-superstar-leading-fallback))

(defun org-superstar--fbullet ()
"Return the correct first inline task star for the current display."
(if (org-superstar-graphic-p)
org-superstar-first-inlinetask-bullet
org-superstar-first-inlinetask-fallback))

(defun org-superstar--heading-level ()
"Return the heading level of the currently matched headline."
(- (match-end 0) (match-beginning 0) 1))
Expand Down Expand Up @@ -606,7 +668,9 @@ prettifying bullets in (for example) source blocks."
(defun org-superstar--prettify-other-lbullet ()
"Prettify the first leading bullet after the headline bullet.
This function serves as an extension of
‘org-superstar--prettify-leading-hbullets’.
‘org-superstar--prettify-leading-hbullets’, only providing the
correct face for the bullet, without doing any composing.
This function uses ‘org-superstar-headline-p’ to avoid
prettifying bullets in (for example) source blocks."
(cond ((org-superstar-headline-p)
Expand All @@ -617,8 +681,8 @@ prettifying bullets in (for example) source blocks."
(defun org-superstar--prettify-leading-hbullets ()
"Prettify the leading bullets of a header line.
Unless ‘org-hide-leading-stars’ is non-nil, each leading star is
visually replaced by ‘org-superstar-leading-bullet’ and inherits
face properties from ‘org-superstar-leading’.
rendered as ‘org-superstar-leading-bullet’ and inherits face
properties from ‘org-superstar-leading’.
If viewed from a terminal, ‘org-superstar-leading-fallback’ is
used instead of the regular leading bullet to avoid errors.
Expand All @@ -634,6 +698,23 @@ prettifying bullets in (for example) source blocks."
(org-superstar--lbullet)))
'org-superstar-leading)))

(defun org-superstar--prettify-first-bullet ()
"Prettify the first bullet of an inline task.
If ‘org-inlinetask-show-first-star’ is non-nil, the first star of
an inlinetask is rendered as ‘org-superstar-first-inlinetask-bullet’
and inherits face properties from ‘org-superstar-first’.
If viewed from a terminal, ‘org-superstar-first-inlinetask-fallback’
is used instead of the regular bullet to avoid errors.
This function uses ‘org-superstar-inlinetask-p’ to avoid
prettifying bullets in (for example) source blocks."
(when (org-superstar-inlinetask-p)
(let ((star-beg (match-beginning 3)))
(compose-region star-beg (1+ star-beg)
(org-superstar--fbullet))
'org-superstar-first)))

(defun org-superstar--make-invisible (subexp)
"Make part of the text matched by the last search invisible.
SUBEXP, a number, specifies which parenthesized expression in the
Expand Down Expand Up @@ -683,8 +764,9 @@ cleanup routines."
,@(when (featurep 'org-inlinetask)
'((2 (org-superstar--prettify-other-hbullet)
prepend)))
;; If requested, put another function here that formats the
;; first star of an inlinetask as a bullet.
,@(when (and (featurep 'org-inlinetask)
org-inlinetask-show-first-star)
'((3 (org-superstar--prettify-first-bullet))))
))))

(defun org-superstar--fontify-buffer ()
Expand Down

0 comments on commit 4b4ddd7

Please sign in to comment.