From 545f6e26ba4fa29fedbb38ccc26e6018774ae63e Mon Sep 17 00:00:00 2001 From: "Pedro A. Aranda" Date: Sat, 4 May 2024 09:09:43 +0200 Subject: [PATCH] org-table: add copy cell contents to kill ring --- etc/ORG-NEWS | 6 ++++++ lisp/org-table.el | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 99dd8839c..b4cacb2ce 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -1520,6 +1520,12 @@ optional argument =NEW-HEADING-CONTAINER= specifies where in the buffer it will be added. If not specified, new headings are created at level 1 at the end of the accessible part of the buffer, as before. +*** New interactive function ~org-table-copy-cell-as-kill~ + +This function copies the contents of a table cell to the kill-ring as +a string without properties. Prints the contents copied to the +kill-ring if called with an argument. + ** Miscellaneous *** =org-crypt.el= now applies initial visibility settings to decrypted entries diff --git a/lisp/org-table.el b/lisp/org-table.el index 0c2dc27ed..f02ea9243 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -6425,6 +6425,28 @@ This function is generated by a call to the macro `org-define-lookup-function'." (org-define-lookup-function last) (org-define-lookup-function all) +;;;###autoload +(defun org-table-copy-cell-as-kill (verbose) + "Copy the contents of the current cell to the kill buffer. +Print a message when verbose is not nil. + +hlines are not considered table cells" + (interactive "P") + ;; Check we are in a table cell that is not an hline + (unless (and (org-at-table-p) + (not (org-at-table-hline-p))) + (error "Not on a table cell")) + ;; if so, get the cell contents + (let ((content (org-table-get nil nil))) + (unless (and content + (length> content 0)) + (error "Empty cell")) + ;; This is a non-empty cell, extract the string + (let ((cell-val (substring-no-properties content))) + (when verbose + (message "Copied `%s'" cell-val)) + (kill-new cell-val)))) + (provide 'org-table) ;; Local variables: -- 2.34.1