emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Re: [FR]: thing-at-point 'org-table-cell
@ 2024-05-03 19:41 Pedro Andres Aranda Gutierrez
  2024-05-03 19:51 ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2024-05-03 19:41 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org List


Hi Ihor, of course this was just an example. The thing-at-point would make it easier to write a copy-as-kill-cell function.

Best,/PA

Enviado desde mi iPhone

> El 3 may 2024, a las 13:17, Ihor Radchenko <yantar92@posteo.net> escribió:
> 
> Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:
> 
>> It would be great to have a thing-at-point handler that returns a cell in
>> and org table. The most simple use case is to have a table in an org-file
>> with data that you need to transfer to an online Web page. Being able to
>> (copy-as-kill ...) a cell's contents could speed up the whole process...
> 
> May you please elaborate on how exactly `thing-at-point' will help copy-as-kill?
> 
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FR]: thing-at-point 'org-table-cell
  2024-05-03 19:41 [FR]: thing-at-point 'org-table-cell Pedro Andres Aranda Gutierrez
@ 2024-05-03 19:51 ` Ihor Radchenko
  2024-05-04  7:14   ` [PATCH] copy cell contents to kill-ring. WAS " Pedro Andres Aranda Gutierrez
  0 siblings, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2024-05-03 19:51 UTC (permalink / raw)
  To: Pedro Andres Aranda Gutierrez; +Cc: Org List

Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:

>>> It would be great to have a thing-at-point handler that returns a cell in
>>> and org table. The most simple use case is to have a table in an org-file
>>> with data that you need to transfer to an online Web page. Being able to
>>> (copy-as-kill ...) a cell's contents could speed up the whole process...
>> 
>> May you please elaborate on how exactly `thing-at-point' will help copy-as-kill?
> 
> Hi Ihor, of course this was just an example. The thing-at-point would make it easier to write a copy-as-kill-cell function.

Then, you can just use `org-element-context' and/or `org-element-at-point'.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] copy cell contents to kill-ring. WAS [FR]: thing-at-point 'org-table-cell
  2024-05-03 19:51 ` Ihor Radchenko
@ 2024-05-04  7:14   ` Pedro Andres Aranda Gutierrez
  2024-05-04 12:24     ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2024-05-04  7:14 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org List


[-- Attachment #1.1: Type: text/plain, Size: 1542 bytes --]

Hi,

I needed this function to copy contents from an org spreadsheet to a Web
page and I see it may be useful to others. Take a look and if you find it
useful, I'll add the changelog stuff.

Thanks for the guidance ;-)
Best, /PA

On Fri, 3 May 2024 at 21:50, Ihor Radchenko <yantar92@posteo.net> wrote:

> Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:
>
> >>> It would be great to have a thing-at-point handler that returns a cell
> in
> >>> and org table. The most simple use case is to have a table in an
> org-file
> >>> with data that you need to transfer to an online Web page. Being able
> to
> >>> (copy-as-kill ...) a cell's contents could speed up the whole
> process...
> >>
> >> May you please elaborate on how exactly `thing-at-point' will help
> copy-as-kill?
> > 
> > Hi Ihor, of course this was just an example. The thing-at-point would
> make it easier to write a copy-as-kill-cell function.
>
> Then, you can just use `org-element-context' and/or `org-element-at-point'.
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>
>


-- 
Fragen sind nicht da, um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet

[-- Attachment #1.2: Type: text/html, Size: 2515 bytes --]

[-- Attachment #2: 0001-org-table-add-copy-cell-contents-to-kill-ring.patch --]
[-- Type: text/x-patch, Size: 2163 bytes --]

From 545f6e26ba4fa29fedbb38ccc26e6018774ae63e Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <paaguti@gmail.com>
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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] copy cell contents to kill-ring. WAS [FR]: thing-at-point 'org-table-cell
  2024-05-04  7:14   ` [PATCH] copy cell contents to kill-ring. WAS " Pedro Andres Aranda Gutierrez
@ 2024-05-04 12:24     ` Ihor Radchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Ihor Radchenko @ 2024-05-04 12:24 UTC (permalink / raw)
  To: Pedro Andres Aranda Gutierrez; +Cc: Org List

Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:

> I needed this function to copy contents from an org spreadsheet to a Web
> page and I see it may be useful to others. Take a look and if you find it
> useful, I'll add the changelog stuff.
> ...
> +(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"

Org mode already has a command that copies cell contents -
`org-table-copy-region'. That command has a problem though - it uses a
kludge with dynamic variable instead of copying to the kill ring.

I think that we can modify `org-table-copy-region' to copy to the kill
ring, adding text properties with cell info as metadata. Then,
`org-table-paste-rectangle' can check for these text properties instead
of relying upon `org-table-clip'.

Would you be willing to work on such refactoring?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-04 12:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-03 19:41 [FR]: thing-at-point 'org-table-cell Pedro Andres Aranda Gutierrez
2024-05-03 19:51 ` Ihor Radchenko
2024-05-04  7:14   ` [PATCH] copy cell contents to kill-ring. WAS " Pedro Andres Aranda Gutierrez
2024-05-04 12:24     ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).