From 4b4ddd7c39b4f8b8106d1d4f602ff27450378d83 Mon Sep 17 00:00:00 2001 From: "D. Williams" Date: Sun, 16 Aug 2020 13:18:02 +0200 Subject: [PATCH] =?UTF-8?q?Honor=20=E2=80=98org-inlinetask-show-first-star?= =?UTF-8?q?=E2=80=99.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- org-superstar.el | 134 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 108 insertions(+), 26 deletions(-) diff --git a/org-superstar.el b/org-superstar.el index 297b083..c65d861 100644 --- a/org-superstar.el +++ b/org-superstar.el @@ -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 @@ -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 @@ -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 @@ -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. @@ -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)) @@ -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) @@ -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. @@ -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 @@ -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 ()