Giter Site home page Giter Site logo

Comments (6)

minad avatar minad commented on July 17, 2024

Thank you for the report! I am afraid it will be hard to support org-time-stamp-custom-formats since the org-modern text properties interfere with the usage of text properties to implement the custom time formats. While the motivation for such custom time formats is understandable I would probably avoid them since the implementation is quite problematic. It doesn't change the underlying time format, only the display is changed which has a bunch of consequences: https://orgmode.org/manual/Custom-time-format.html. However for me the ISO time stamp format used by Org internally also feels natural, so in my case the decision an easier one to make.

org-modern also uses text properties to style the timestamp, but we apply the text properties carefully one by one to the letters in order to avoid the negative consequences of org-display-custom-times. Unfortunately our method seems to lead to these left over diacritics. Maybe this could even happen without org-display-custom-times, e.g., if the weekday ends with a composed letter.

For now I disable the org-modern timestamp styling if org-display-custom-times is non-nil to avoid any negative impact of org-modern, see 89875c5. If you find a good solution to the problem, which would allow us to enable both org-modern-timestamp and org-display-custom-times at the same time, I would be happy to accept a PR.

from org-modern.

9viz avatar 9viz commented on July 17, 2024

Yes, I understand the negatives of the custom timestamp format but I digest it anyway since I cannot parse the ISO format mentally. If org-display-custom-times=nil, then there is no rendering issues BTW.

I took a quick look, stepped through edebug but I just cannot figure out what this form is supposed to achieve

  (put-text-property
       (1- (match-end 1))
       (match-end 1)
       'display (format "%c " (char-before (match-end 1))))

from org-modern.

9viz avatar 9viz commented on July 17, 2024

Looking at it more, I think we are left with no option but to put the display string property ourselves again. But the problem becomes: how are we supposed to know where the hour and the minutes are? The docstring of org-time-stamp-custom-formats says that they should be at the end... but I'm not sure if there is much we can do here. I would suggest to disable fontifying the time portion entirely when org-display-custom-times=t since then you at least get some fontification. WDYT?

from org-modern.

9viz avatar 9viz commented on July 17, 2024

I do have another idea to solve this problem, at the risk of not obeying what the user wants: if we go down the route of applying the display string property for the custom time stamp, we can always use the non-timed format and add the time bits when needed at the end. I would be personally fine with it, and if you think this is good enough:tm:, then I will see what I can do.

from org-modern.

minad avatar minad commented on July 17, 2024

Yes, we have to apply our own display property to the entire date. I think there are two possible solutions:

  • Either don't distinguish time and date, just format everything as a date box.
  • Introduce a org-modern-custom-timestamp-format variable (separate from org-time-stamp-custom-formats) which is a pair ("%Y-%m-%d" . "%H:%M"). The car is formatted as date, the cdr is formatted as timestamp.

Feel free to experiment and propose a PR. See https://github.com/minad/org-modern/#contributions if your contribution is above 15 lines of code.

from org-modern.

9viz avatar 9viz commented on July 17, 2024

I already sent a mail to [email protected] to get my copyright assignment for Emacs, and I am waiting for their reply. I believe I already exhausted those 15 LOC since I had a patch get merged in Emacs.

How does the following look? I have to admit that I really didn't put in the effort to write a clear docstring for the new defcustom.

diff --git a/org-modern.el b/org-modern.el
index 49e6a17..2ad910f 100644
--- a/org-modern.el
+++ b/org-modern.el
@@ -92,6 +92,12 @@ 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 '("%Y-%m-%d" . "%H:%M")
+  "Format of custom timestamps.
+It should be (DATE . TIME) where DATE is the format for date, and
+TIME is the format for time."
+  :type '(cons string string))
+
 (defcustom org-modern-table t
   "Prettify tables."
   :type 'boolean)
@@ -336,7 +342,16 @@ You can specify a font `:family'. The font families `Iosevka', `Hack' and
                       'org-modern-date-inactive))
          (time-face (if active
                         'org-modern-time-active
-                      'org-modern-time-inactive)))
+                      'org-modern-time-inactive))
+         (org-display-custom-times t)
+         (time (when org-display-custom-times
+                 (save-match-data
+                   (encode-time
+                    (org-fix-decoded-time
+                     (org-parse-time-string
+                      (buffer-substring (match-beginning 0) (match-end 0)))))))))
+    (when org-display-custom-times
+      (remove-text-properties (match-beginning 0) (match-end 0) '(display nil)))
     (put-text-property
      (match-beginning 0)
      (1+ (match-beginning 0))
@@ -350,16 +365,28 @@ You can specify a font `:family'. The font families `Iosevka', `Hack' and
      (match-beginning 0)
      (if (eq (match-beginning 2) (match-end 2)) (match-end 0) (match-end 1))
      'face date-face)
+    (when org-display-custom-times
+      (put-text-property
+       (match-beginning 1)
+       (match-end 1)
+       'display (format-time-string (car org-modern-custom-timestamp-format) time)))
     ;; hour:minute
     (unless (eq (match-beginning 2) (match-end 2))
       (put-text-property
        (1- (match-end 1))
        (match-end 1)
-       'display (format "%c " (char-before (match-end 1))))
+       'display (if org-display-custom-times
+                    " "
+                  (format "%c " (char-before (match-end 1)))))
       (put-text-property
        (match-beginning 2)
        (match-end 0)
-       'face time-face))))
+       'face time-face)
+      (when org-display-custom-times
+        (put-text-property
+         (match-beginning 2)
+         (match-end 2)
+         'display (format-time-string (concat " " (cdr org-modern-custom-timestamp-format)) time))))))
 
 (defun org-modern--star ()
   "Prettify headline stars."

from org-modern.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.