branch: externals/org-modern commit 98b52c2849efabfc5f3f3a3493d34f9c2a954e32 Author: viz <37809414+v...@users.noreply.github.com> Commit: GitHub <nore...@github.com>
Add org-modern-custom-timestamp-format (#30) * Add org-modern-custom-timestamp-format This option is the equivalent of org-mode's org-time-stamp-custom-formats. See #29. * Split org-modern--timestamp into two functions * org-modern--timestamp-custom: Prefer add-text-properties * Fix fallouts from merge Restore the org-modern-timestamp behaviour before the merge Co-authored-by: Visuwesh <visuwe...@gmail.com> --- org-modern.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/org-modern.el b/org-modern.el index 27be2d1790..4a8df614e8 100644 --- a/org-modern.el +++ b/org-modern.el @@ -93,6 +93,17 @@ Set to nil to disable styling the headlines." Set to nil to disable styling the time stamps." :type 'boolean) +(defcustom org-modern-custom-timestamp-format nil + "Format of custom timestamps, or nil for none. +If non-nil, it should be (DATE . TIME) where DATE is the format +for date, and TIME is the format for time. DATE and TIME must be +surrounded with space. For the syntax, refer to +`format-time-string'." + :type '(choice + (const :tag "Do not use custom timestamp format" nil) + (const :tag " YYYY-MM-DD HH:MM " '(" %Y-%m-%d " . " %H:%M ")) + (cons :tag "Custom date and time format" string string))) + (defcustom org-modern-table t "Prettify tables." :type 'boolean) @@ -333,7 +344,7 @@ You can specify a font `:family'. The font families `Iosevka', `Hack' and 'org-modern-done 'org-modern-todo))))) -(defun org-modern--timestamp () +(defun org-modern--timestamp-default () "Prettify timestamps." (let* ((active (eq (char-after (match-beginning 0)) ?<)) (date-face (if active @@ -342,6 +353,7 @@ You can specify a font `:family'. The font families `Iosevka', `Hack' and (time-face (if active 'org-modern-time-active 'org-modern-time-inactive))) + (remove-text-properties (match-beginning 0) (match-end 0) '(display nil)) (put-text-property (match-beginning 0) (1+ (match-beginning 0)) @@ -366,6 +378,35 @@ You can specify a font `:family'. The font families `Iosevka', `Hack' and (match-end 0) 'face time-face)))) +(defun org-modern--timestamp-custom () + "Prettify timestamps per `org-modern-custom-timestamp-format'." + (let* ((active (eq (char-after (match-beginning 0)) ?<)) + (date-face (if active + 'org-modern-date-active + 'org-modern-date-inactive)) + (time-face (if active + 'org-modern-time-active + 'org-modern-time-inactive)) + (time (save-match-data + (encode-time + (org-fix-decoded-time + (org-parse-time-string + (buffer-substring (match-beginning 0) (match-end 0)))))))) + (remove-list-of-text-properties (match-beginning 0) (match-end 0) '(display)) + ;; year-month-day + (add-text-properties + (match-beginning 0) + (if (eq (match-beginning 2) (match-end 2)) (match-end 0) (match-end 1)) + `( face ,date-face + display ,(format-time-string (car org-modern-custom-timestamp-format) time))) + ;; hour:minute + (unless (eq (match-beginning 2) (match-end 2)) + (add-text-properties + (match-beginning 2) + (match-end 0) + `( face ,time-face + display ,(format-time-string (cdr org-modern-custom-timestamp-format) time)))))) + (defun org-modern--star () "Prettify headline stars." (let ((level (- (match-end 1) (match-beginning 1)))) @@ -517,9 +558,11 @@ You can specify a font `:family'. The font families `Iosevka', `Hack' and (when org-modern-tag `((,(concat "^\\*+.*?\\( \\)\\(:\\(?:" org-tag-re ":\\)+\\)[ \t]*$") (0 (org-modern--tag))))) - (when (and org-modern-timestamp (not org-display-custom-times)) - '(("\\(?:<\\|\\[\\)\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\(?: [[:word:]]+\\)?\\(?: [.+-]+[0-9ymwdh/]+\\)*\\)\\(\\(?: [0-9:-]+\\)?\\(?: [.+-]+[0-9ymwdh/]+\\)*\\)\\(?:>\\|\\]\\)" - (0 (org-modern--timestamp))) + (when org-modern-timestamp + `(("\\(?:<\\|\\[\\)\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\(?: [[:word:]]+\\)?\\(?: [.+-]+[0-9ymwdh/]+\\)*\\)\\(\\(?: [0-9:-]+\\)?\\(?: [.+-]+[0-9ymwdh/]+\\)*\\)\\(?:>\\|\\]\\)" + (0 ,(if org-modern-custom-timestamp-format + '(org-modern--timestamp-custom) + '(org-modern--timestamp-default)))) ("<[^>]+>\\(-\\)\\(-\\)<[^>]+>\\|\\[[^]]+\\]\\(?1:-\\)\\(?2:-\\)\\[[^]]+\\]" (1 '(face org-modern-label display #(" " 1 2 (face (:strike-through t) cursor t))) t) (2 '(face org-modern-label display #(" " 0 1 (face (:strike-through t)))) t))))