A while ago Eric raised two nice suggestions. (2) has just been
implemented as Bastien reminded me that I can now just push straight to
Org for org-plot.el without going through a patch-review process.

This patch resolves (1).

Eric S Fraga <e.fr...@ucl.ac.uk> writes:

> 1. it would be consistent and useful if "C-c C-c" executed
>    org-plot/gnuplot when on such a #+PLOT line.
>
> 2. why does point move to the next line when I do execute the command?
>    This is somewhat annoying when playing around with the settings.  It
>    would be nice to have point remain where it is.
>
> Thank you all!

--
Timothy

>From fccd5f2c66fe8342da2a8eb405240f5247958597 Mon Sep 17 00:00:00 2001
From: TEC <t...@tecosaur.com>
Date: Tue, 27 Apr 2021 00:05:37 +0800
Subject: [PATCH] org: Enable plotting with C-c C-c

* lisp/org.el (org-ctrl-c-ctrl-c): When at a table, check if the current
line starts with "#+plot", and if so call `org-plot/gnuplot'.
As I think 4-deep nested if statements are bad for readability, I
refactored the nested if statements to use `cond' while I was at it.
---
 lisp/org.el | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 3f9c9a284..950509bfd 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17693,24 +17693,28 @@ (defun org-ctrl-c-ctrl-c (&optional arg)
 	 ;; send the table if necessary.  If the table has
 	 ;; a `table.el' type, just give up.  At a table row or cell,
 	 ;; maybe recalculate line but always align table.
-	 (if (eq (org-element-property :type context) 'table.el)
-	     (message "%s" (substitute-command-keys "\\<org-mode-map>\
-Use `\\[org-edit-special]' to edit table.el tables"))
-	   (if (or (eq type 'table)
-		   ;; Check if point is at a TBLFM line.
-		   (and (eq type 'table-row)
-			(= (point) (org-element-property :end context))))
-	       (save-excursion
-		 (if (org-at-TBLFM-p)
-		     (progn (require 'org-table)
-			    (org-table-calc-current-TBLFM))
-		   (goto-char (org-element-property :contents-begin context))
-		   (org-call-with-arg 'org-table-recalculate (or arg t))
-		   (orgtbl-send-table 'maybe)))
-	     (org-table-maybe-eval-formula)
-	     (cond (arg (call-interactively #'org-table-recalculate))
-		   ((org-table-maybe-recalculate-line))
-		   (t (org-table-align))))))
+         (cond
+          ((string-match-p "#\\+plot" (thing-at-point 'line t))
+           (org-plot/gnuplot))
+          ((eq (org-element-property :type context) 'table.el)
+           (message "%s" (substitute-command-keys "\\<org-mode-map>\
+Use `\\[org-edit-special]' to edit table.el tables")))
+          ((or (eq type 'table)
+               ;; Check if point is at a TBLFM line.
+               (and (eq type 'table-row)
+                    (= (point) (org-element-property :end context))))
+           (save-excursion
+             (if (org-at-TBLFM-p)
+                 (progn (require 'org-table)
+                        (org-table-calc-current-TBLFM))
+               (goto-char (org-element-property :contents-begin context))
+               (org-call-with-arg 'org-table-recalculate (or arg t))
+               (orgtbl-send-table 'maybe))))
+          (t
+           (org-table-maybe-eval-formula)
+           (cond (arg (call-interactively #'org-table-recalculate))
+                 ((org-table-maybe-recalculate-line))
+                 (t (org-table-align))))))
 	((or `timestamp (and `planning (guard (org-at-timestamp-p 'lax))))
 	 (org-timestamp-change 0 'day))
 	((and `nil (guard (org-at-heading-p)))
-- 
2.31.1

Reply via email to