emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] org.el: Don't clear dynamic block if write function is undefined


From: Kyle Meyer
Subject: [PATCH] org.el: Don't clear dynamic block if write function is undefined
Date: Thu, 04 Feb 2021 01:15:42 -0500

Michael Powe writes:

> Hello,
>
> After logging some clock time, I used the normal key combination, C-u C-c
> C-x C-u to update my timesheet tables, and received this error message.
>
> org-update-dblock: Symbol’s function definition is void:
> org-dblock-write:CLOCKTABLE
[...]
> Well, after recovering from my horror at losing my timesheets for a day's
> work, I was able to track down the problem: the function is case sensitive.
> At some point, (apparently) I fat-fingered a key combo & upcased the mode
> line for two tables. After returning them to l-case, all worked as it
> should.
>
> I dunno - should the function be case insensitive?

I don't think so.  Other libraries and users can define their own
dynamic blocks, and I don't think anything documents that the
org-dblock-write:<name> function must be all lower case.  However, I do
think we could improve the situation by signaling an error if the
function is unknown _before_ clearing the block.

With the below patch, you would have seen

  user-error: Unknown dynamic block type: CLOCKTABLE

and the existing block would have been left as is.  What do you think?

-- >8 --
Subject: [PATCH] org.el: Don't clear dynamic block if write function is
 undefined

* lisp/org.el (org-prepare-dblock): Check whether the block's write
function is defined before clearing the existing contents.
(org-map-dblocks): Relay the message of the caught error to help the
caller figure out what went wrong.

The write function may be undefined because the user unintentionally
modified the dynamic block name or didn't load a library, and deleting
contents in this situation can be alarming.  Instead signal an error
that's hopefully enough for the user to figure out what went wrong.

Reported-by: Michael Powe <powem@ctpowe.net>
Ref: CAF7nVLVRVrmCgMnMhga9+mtuE0nav-eH4C17Bf4EiEryowt27w@mail.gmail.com
---
 lisp/org.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 5b1443c4e..c9f58c9a5 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9165,6 +9165,8 @@ (defun org-prepare-dblock ()
         (name (org-no-properties (match-string 1)))
         (params (append (list :name name)
                         (read (concat "(" (match-string 3) ")")))))
+    (unless (fboundp (intern (concat "org-dblock-write:" name)))
+      (user-error "Unknown dynamic block type: %s" name))
     (save-excursion
       (beginning-of-line 1)
       (skip-chars-forward " \t")
@@ -9189,9 +9191,11 @@ (defun org-map-dblocks (&optional command)
       (while (re-search-forward org-dblock-start-re nil t)
        (goto-char (match-beginning 0))
         (save-excursion
-          (condition-case nil
+          (condition-case err
               (funcall cmd)
-            (error (message "Error during update of dynamic block"))))
+            (error
+             (message "Error during update of dynamic block: %s"
+                      (error-message-string err)))))
        (unless (re-search-forward org-dblock-end-re nil t)
          (error "Dynamic block not terminated"))))))
 

base-commit: 369eb2739787b9b24399c803be31e4e793113dd1
-- 
2.30.0





reply via email to

[Prev in Thread] Current Thread [Next in Thread]