From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id aHbHDlMiamfpGwEA62LTzQ:P1 (envelope-from ) for ; Tue, 24 Dec 2024 02:54:11 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id aHbHDlMiamfpGwEA62LTzQ (envelope-from ) for ; Tue, 24 Dec 2024 03:54:11 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MYwzfEKv; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1735008850; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=0rINs9CgSzMdC15Cr4HVYTYINbfemkYE/P6Gu6IjanU=; b=FVJFiWG0Yn36J7cdr3mZ5sUz8BWaqykjsZmti2fiQlIyKO8iZFDSbPJEVXpffZCnJmhmWC h7n/6unhDbnQL+mtvQaf96zQ6XwXB21cGZ7Ctmg8hOISsUzDN1BHrYyMe93p89/syYZrV/ OvWgTOmgeTSEEMWK9FHTMgQvWTAXYAlTcB3Qb3D6PRPs03MCAHR7M2+btv+NpHLyQCRPWH 7+Icp7b/MOwj+RoZr1J+NGJWJtPrjkfrycwmBQQAWe1lUnKNYRa0Hvc2TegWgMWaM0tRmn i2F/Nuez5Ev+HKvjmd4tYY5s11KgetSuYiUFhKVZetvOYByETkegEeW5x1z5OA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MYwzfEKv; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1735008850; a=rsa-sha256; cv=none; b=XExjsy2e1ftY51x7nELqMXgreBJb4hLBadZJ3fshrtO4Z6XvgiHyo76XclsICPlJexrExy +5dOq3Ji93cyLLbcLrn4T3H1lmBm02lvd3RpBQ7zUlX6KYs1p9z4fDc8fo7L3suy+MDXnL FKy/pV2mbJC8k2LnhMJ8Aig5kpZD4++hgAp1dRrJ4HbbIwwXD0xCDFYdypi2wzMn+PvK+j /djSYAaa8lWDtA5SaldXM/TaskB2armCjAkfHBJ1qCktzVdg+qivRKZGj5SskDXewcECuA kIZgoYo3k96mz+lbjSOqRIAoJpXiRd9OsWIl6zA07xg5GVX22DmqTI/FjsyhAw== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1588877F6 for ; Tue, 24 Dec 2024 03:54:09 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tPv2s-0007J7-BP; Mon, 23 Dec 2024 21:53:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tPv2r-0007Iw-AV for emacs-orgmode@gnu.org; Mon, 23 Dec 2024 21:53:17 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tPv2p-00028p-A8 for emacs-orgmode@gnu.org; Mon, 23 Dec 2024 21:53:17 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-21644e6140cso47873105ad.1 for ; Mon, 23 Dec 2024 18:53:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735008794; x=1735613594; darn=gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=0rINs9CgSzMdC15Cr4HVYTYINbfemkYE/P6Gu6IjanU=; b=MYwzfEKvcqVnnNj/banGROsAwgZsW4XpMUFWhJcAbX+AghSm/uIoYul9jpTNekhEnx yBVtQxufohMGGKCPqMCxpfqiO/liaMFks/jpkLli9pd3SeAm8SZ/4bYh433glbzlilbk x5MF73i+dHzCt4BKXLjq0gYqEv3drNfjOzENEQql5QXJgO9DNafsSPt8TAbJWnHrvssz f1BDxJ1Y+b21UEsGhmEw1gJNKj/QbUas6Sp1ghm5KKzKvU+q6jN332xHO1P+7nu25zuH C5vXAHse8WXYZ/EJbMDyxsadTuHQUl4BO7ptMMqSVROzVn4yZ/vp30FYRLojbwV6bKwd k4XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735008794; x=1735613594; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0rINs9CgSzMdC15Cr4HVYTYINbfemkYE/P6Gu6IjanU=; b=MK7OMwre2+x7lHYTkk2R4wDmkBCI+g4X1NsXdFiQ4HAea9DxOFALT2ePw37Wj0ycc5 UwNe+YmyMtynjsAwyY9k4kTE/rlrYnVXcKo22VyG9wFUPmhGH9LNkORuUSJtJAX0nO1b bjKQoQgeT7FxDvKyJWTkadExZTDF8THJGcPJ+VnCNXXWUW5JB2VSaqvbT7RgsQFp14NC 7ZitcVObqVrMH9yPUJ0w1uSTy63Pq84RHlGyvVJMaK1QZNomr5bGDZKL8Nw0EpwulAGx gt3chqY4d/rudDqJvKoykr1C2Ri0O28s2HzZJ5nh690TeVai256gOfUsWqDQBka17ANd rkMQ== X-Forwarded-Encrypted: i=1; AJvYcCWUjbW8+nbQ63NHatISMnwWwACG9jVu2bFHkSvAQbsqv6JhCGc9gK2HxhQqnbh3OR4mRkBcXGhd0yaxc643@gnu.org X-Gm-Message-State: AOJu0YwSjZDEkQXtVsLvYgLPaagOApRJJAEtCn573vHCmEW/SaKMOQKl 5ozIPDY1BJZPZX2/hZmkjsPASWHNt787+cnXsdv5x+t3Ae738E87 X-Gm-Gg: ASbGncuVwK2qOE9pfLeJhKYeSoCCsa/oYxKikXIbCKucl1gmlUBo7eP1qAUY8eM8SQn xzwz379tzFoujL7Bzf86ICPJAWZauINxestM1lsoTw7uAt5b49sQNUgfxA5j/8qVNOUdyhO65wZ OJ85qnFajTOV+D4VkTws15LZbKv7OiO4a72BGT2t1DBDh+z6JeMDGyNbJKj+q4YvExLHm5d4/ie qp9fTbPS3aUOYO6OY/u+qsTMesWZpvt/uwC1gG7vqVIcnvif2wE X-Google-Smtp-Source: AGHT+IGixlwkJJTJnTE5lnOeckDWgYZeSp6o8PsIujiC3nWB6QBMrINDU2ZN9qoVTkGjMFRjhK2Siw== X-Received: by 2002:a17:902:ce92:b0:215:a179:14ca with SMTP id d9443c01a7336-219e6e8c35amr200942385ad.2.1735008793662; Mon, 23 Dec 2024 18:53:13 -0800 (PST) Received: from localhost ([49.204.129.41]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f7312sm79962175ad.225.2024.12.23.18.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 18:53:12 -0800 (PST) From: Visuwesh To: Ihor Radchenko Cc: Rens Oliemans , org-mode-email Subject: Re: [PATCH] Add yank-media handler for LibreOffice Calc tables In-Reply-To: <875xnajn21.fsf@localhost> (Ihor Radchenko's message of "Mon, 23 Dec 2024 18:01:42 +0000") References: <87r08i3alo.fsf@gmail.com> <871q0ise9x.fsf@localhost> <87msj53o2o.fsf@gmail.com> <87msj5dx8l.fsf@localhost> <87ttdawssj.fsf@gmail.com> <871q0cy3h2.fsf@localhost> <87ed4cwnmr.fsf@gmail.com> <87ldykwnbi.fsf@localhost> <8734kswkez.fsf@gmail.com> <87bjzgwk4k.fsf@localhost> <87y12kv4vh.fsf@gmail.com> <875xpo1k1v.fsf@rensoliemans.nl> <87ttd8v0oo.fsf@gmail.com> <87o73dvnxx.fsf@rensoliemans.nl> <871q09vj59.fsf@gmail.com> <87bjxyqgo5.fsf@gmail.com> <875xnajn21.fsf@localhost> Date: Tue, 24 Dec 2024 08:23:09 +0530 Message-ID: <878qs5bxm2.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::644; envelope-from=visuweshm@gmail.com; helo=mail-pl1-x644.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 1588877F6 X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -4.20 X-Spam-Score: -4.20 X-TUID: KTCHKjiXyla2 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable [=E0=AE=A4=E0=AE=BF=E0=AE=99=E0=AF=8D=E0=AE=95=E0=AE=B3=E0=AF=8D =E0=AE=9F= =E0=AE=BF=E0=AE=9A=E0=AE=AE=E0=AF=8D=E0=AE=AA=E0=AE=B0=E0=AF=8D 23, 2024] I= hor Radchenko wrote: >> I have now done this in the attached patch. I use a temporary buffer to >> convert the table, and also decode it as per buffer-file-coding-system >> of the Org buffer as I could not tell whether LibreOffice always uses >> UTF-8 or not. I believe buffer-file-coding-system should be utf-8 on >> most systems so it should be a safe choice. > > utf-8 is not used everywhere. Quite far from that, AFAIK. > You can try 'undecided as coding system value (see 34.10.7 Explicit > Encoding and Decoding) Ah thank you, I missed it. Using it now. >> When yanking images from clipboard, Org saves the image on disk and >> @@ -21702,6 +21703,9 @@ of ~org-yank-dnd-method~. Image files >> pasted this way also respect >> the value of ~org-yank-image-save-method~ when the action to perform >> is =3Dattach=3D. >>=20=20 >> +Yanking tables copied from LibreOffice Calc documents are inserted as >> +Org tables. > > Looks like "yanking" is stray. I reworded it to Tables copied from LibreOffice Calc documents are yanked as Org tables. Updated patch attached below. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-yank-media-handler-for-LibreOffice-Calc-tables.patch >From 39aeafc4b748110562044e9488097bf0b8de3a64 Mon Sep 17 00:00:00 2001 From: Visuwesh Date: Mon, 14 Oct 2024 22:04:23 +0530 Subject: [PATCH] Add `yank-media' handler for LibreOffice Calc tables * lisp/org.el (org--libreoffice-table-handler): Add new `yank-media' handler for tables copied from LibreOffice Calc documents. (org-setup-yank-dnd-handlers): Register it. * doc/org-manual.org: (Drag and Drop & ~yank-media~): Update the manual to mention the new feature. * etc/ORG-NEWS: Announce the new feature. --- doc/org-manual.org | 6 +++++- etc/ORG-NEWS | 5 +++++ lisp/org.el | 27 ++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 451fd72cd..8a58b9966 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -21640,7 +21640,8 @@ value as ~org-attach-method~ (~cp~ by default).] #+cindex: pasting files, images from clipboard Starting from Emacs 29, Org mode supports ~yank-media~ command to yank -images from the clipboard and files from a file manager. +images from the clipboard, files from a file manager and tables copied +from LibreOffice Calc documents. #+vindex: org-yank-image-save-method When yanking images from clipboard, Org saves the image on disk and @@ -21658,6 +21659,9 @@ of ~org-yank-dnd-method~. Image files pasted this way also respect the value of ~org-yank-image-save-method~ when the action to perform is =attach=. +Tables copied from LibreOffice Calc documents are yanked as Org +tables. + ** Repeating commands :PROPERTIES: :DESCRIPTION: Repeating navigation commands diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 5d421172f..37ee9a52f 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -114,6 +114,11 @@ The keybindings in the repeat-maps can be changed by customizing See the new [[info:org#Repeating commands]["Repeating commands"]] section in Org mode manual. +*** Tables copied from LibreOffice Calc documents can be pasted as Org tables + +Tables copied into the clipboard from LibreOffice Calc documents can +now be pasted as an Org table using ~yank-media~. + ** New and changed options # Chanes deadling with changing default values of customizations, diff --git a/lisp/org.el b/lisp/org.el index 6177856c3..1c08e6300 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20860,7 +20860,9 @@ (defun org-setup-yank-dnd-handlers () ;; Looks like different DEs go for different handler names, ;; https://larsee.com/blog/2019/05/clipboard-files/. (yank-media-handler "x/special-\\(?:gnome\\|KDE\\|mate\\)-files" - #'org--copied-files-yank-media-handler)) + #'org--copied-files-yank-media-handler) + (yank-media-handler "application/x-libreoffice-tsvc" + #'org--libreoffice-table-handler)) (when (boundp 'x-dnd-direct-save-function) (setq-local x-dnd-direct-save-function #'org--dnd-xds-function))) @@ -20953,6 +20955,29 @@ (defun org--copied-files-yank-media-handler (_mimetype data) (org--dnd-local-file-handler f action sep) (message "File `%s' is not readable, skipping" f))))) +(defun org--libreoffice-table-handler (_mimetype data) + "Insert LibreOffice Calc table DATA as an Org table. +DATA is in the TSV format." + ;; Some LibreOffice versions have the null byte in the selection. + ;; It should be safe to remove it. + (when (string-search "\0" data) + (setq data (string-replace "\0" "" data))) + (let ((orig-buf (current-buffer))) + (with-temp-buffer + (decode-coding-string data 'undecided nil (current-buffer)) + (let ((tmp (current-buffer)) + (nlines (count-lines (point-min) (point-max)))) + (when (> nlines org-table-convert-region-max-lines) + (unless (yes-or-no-p + (format "Inserting large table with %d lines, more than `org-table-convert-region-max-lines'. Continue? " + nlines)) + (user-error "Table is larger than limit `org-table-convert-region-max-lines'"))) + ;; User has chosen to ignore the limit. + (let ((org-table-convert-region-max-lines most-positive-fixnum)) + (org-table-convert-region (point-min) (point-max))) + (with-current-buffer orig-buf + (insert-buffer-substring tmp)))))) + (defcustom org-yank-dnd-method 'ask "Action to perform on the dropped and the pasted files. When the value is the symbol, -- 2.45.2 --=-=-=--