ml729 / org-habit-stats

Stats and visuals for Emacs org-mode habits
GNU General Public License v3.0
65 stars 4 forks source link

Error on `org-habit-stats-view-habit-at-point` after recent org-mode update #10

Open thomaslaich opened 4 months ago

thomaslaich commented 4 months ago

When invoking org-habit-stats-view-habit-at-point, I get the following error:

Debugger entered--Lisp error: (wrong-type-argument stringp [org-element-deferred org-element--headline-raw-value (3 69) nil])
  string-width([org-element-deferred org-element--headline-raw-value (3 69) nil])
  truncate-string-to-width([org-element-deferred org-element--headline-raw-value (3 69) nil] 25 nil nil t)
  org-habit-stats-create-habit-buffer((739044 1 nil nil (738849 738850 738851 738852 738853 738854 738855 738857 738858 738860 738861 738862 738863 738864 738865 738866 738867 738868 738868 738871 738872 738876 738878 738879 738880 738881 738882 738883 738885 738887 738897 738898 738899 738900 738901 738902 738906 738907 738908 738909 738920 738921 738926 738970 739017 739020 739026 739027 739030 739031 ...) ".+") [org-element-deferred org-element--headline-raw-value (3 69) nil] nil file)
  org-habit-stats-view-habit-at-point()
  funcall-interactively(org-habit-stats-view-habit-at-point)
  command-execute(org-habit-stats-view-habit-at-point)

it seems like org-mode made changes to the org-element-property function after 9.7 releases, so the following code does not work anymore:

(defun org-habit-stats-view-habit-at-point ()
  "Open an org-habit-stats buffer for the habit at point in a file."
  (interactive)
  (let ((habit-name (org-element-property :raw-value
                                          (save-excursion
                                            (when (not (eq (car (org-element-at-point)) 'headline))
                                              (outline-previous-heading))
                                            (org-element-at-point))))
        (habit-data (org-habit-stats-parse-todo (point)))
        (habit-description (org-entry-get (point) "DESCRIPTION")))
    (org-habit-stats-create-habit-buffer habit-data habit-name habit-description 'file)))

Without having spent a ton of time investigating it, it seems to be a similar underlying issue as this: https://github.com/alphapapa/org-ql/issues/364#issuecomment-1662791557

Here are the org-mode changes: https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/etc/ORG-NEWS#n40

I hope I'm not completely off in this analysis.

My systems (happens on both my machines):

MacOS

OS: MacOS Sonoma 14.5 Emacs: 29.3 (PGTK version) (also tried 30.0.50) org-version: 9.7.3

NixOS

OS: NixOS 24.11 (Vicuña) Emacs: 29.3 (PGTK version) (also tried 30.0.50) org-version: 9.7.3