From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id QOAADFXKSWfPEQAAqHPOHw:P1 (envelope-from ) for ; Fri, 29 Nov 2024 14:06:13 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id QOAADFXKSWfPEQAAqHPOHw (envelope-from ) for ; Fri, 29 Nov 2024 15:06:13 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UKvf4FwQ; dmarc=pass (policy=none) header.from=gmail.com; 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" 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 06DEB36B7 for ; Fri, 29 Nov 2024 15:06:11 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tH1cf-0004j1-9O; Fri, 29 Nov 2024 09:05:29 -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 1tH1cc-0004bd-PC for emacs-orgmode@gnu.org; Fri, 29 Nov 2024 09:05:26 -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 1tH1cZ-0000fN-7S for emacs-orgmode@gnu.org; Fri, 29 Nov 2024 09:05:26 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-2129fd7b1a5so16279795ad.1 for ; Fri, 29 Nov 2024 06:05:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732889119; x=1733493919; 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=MqZmjI1G8Tesg2ghjtIBLOvg/1CteZfPlsxsqI+hPY0=; b=UKvf4FwQPxFa8/mizWR6gYpcX1D+LTfuKUtyd1pql301Nd4z5vRpx/ZJLhVihA+X0p evUjxps9NBFihVyW8EEJwfc2i41lZ4ZOwhYDR55SLMyIezRr7rXENrM46dd1M6YUqWUR 92zLtoMbXS7N8qZoa3KV8T+1Znucb7Q2JMQK/IWM289k2NlWbkdFOJq7tWldUAmBaPKs 6DL8lbzICMRXoOOtk2DemS4inSrFwLgrPVvHgg1VmSax7bT9PhZ/VkxQNOKsGYKq77+m 15fM2wLWI3mcMn/E+8VzTKCc5CvAGQt9E1G4MZdTfEneLOrO2++5OJom13/jXDbq53gI ux7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732889119; x=1733493919; 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=MqZmjI1G8Tesg2ghjtIBLOvg/1CteZfPlsxsqI+hPY0=; b=jjkgiM4qEvD7dhaFuGX/1Y7VS718tHLuLTaAiO/f7gXC7lBnPrLJamAT2w58LwlkBJ Gzn2sagTFK1j/1pwoZiHyWLSv7JQFZohHHGWhJCHem57P7/ErzxmaBOCp4cBOs3pg7e5 SYnO/gDLLpIxdX7Inroo5uJMrs4mzGI2fsEvSU6VHFDu79pMpeW94qmzXUXXQbozO1eN 0GPvdV2kwcyIY8OvhtPEA/bl+gReul+MQjRx7uucaQfsBlTeRl+D5gOk+bIpNBN4XZiq XQLxwlhkZHSCRj6Sqc4UOUvaDiozPQI9tm5ztOGszLQA8JGBNbOb1io/D62Es7eQfK3w 1VqA== X-Forwarded-Encrypted: i=1; AJvYcCVZ7OJKyb7ldsWPjCUEpSLJgkS0C+Y3wApQLIUxNNwCdkAaxFUENrWMI4K/j7cWY/KL2pGiNdM10XWkvKf0@gnu.org X-Gm-Message-State: AOJu0YwwLxKxYWmB5DDEAtAwDgo75vPao0bA1KS8udRNR4IEWeVZDGhL YL/jBkzysojrMsgpY5oZJdAspOfuLI16yxxyf+WPghTYYw+xULfTeJs1ftE7 X-Gm-Gg: ASbGncuitCl6y7SFKK0wTxbqP/9b66pv/eGdJt4Fz7mUyGarlYqoMpe1d+TQ/6dUE99 vklo1vph5OklMfbizUsEXlip5yms86cTaKr46F2y9PkXiWAcQO2/3Hne2L7kGmGlOEc4RtiZSy/ O/jrDrYuYq+JGmlj5kx+BABINKURicxwJ4CJs3TNFgzNKB+gBT0eUVpX0xFGCxcn4G7vPQ+BC0U OJltTGIsqyjN2l7TQ//v20OKLwqckBVbmlVv+xOUTQP19s= X-Google-Smtp-Source: AGHT+IFk5BfMbVaYCu8ajXVsQhzbzCMdhy82M4L1xu8I1e/mFJRP4Hdd89vrE4EG4RpkKTFNC8SoUA== X-Received: by 2002:a17:902:c945:b0:20c:5bf8:bd6e with SMTP id d9443c01a7336-21501f68618mr146093415ad.48.1732889119290; Fri, 29 Nov 2024 06:05:19 -0800 (PST) Received: from localhost ([115.240.90.130]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-215219c5533sm30821205ad.256.2024.11.29.06.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 06:05:18 -0800 (PST) From: Visuwesh To: Rens Oliemans Cc: Ihor Radchenko , org-mode-email Subject: Re: [PATCH] Add yank-media handler for LibreOffice Calc tables In-Reply-To: <871q09vj59.fsf@gmail.com> (Visuwesh's message of "Mon, 21 Oct 2024 16:04:58 +0530") 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> Date: Fri, 29 Nov 2024 19:35:14 +0530 Message-ID: <87bjxyqgo5.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-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -2.37 X-Spam-Score: -2.37 X-Migadu-Queue-Id: 06DEB36B7 X-Migadu-Scanner: mx12.migadu.com X-TUID: NSTFqNmYlfuM --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sorry for the late reply. I was busy with uni. [=E0=AE=A4=E0=AE=BF=E0=AE=99=E0=AF=8D=E0=AE=95=E0=AE=B3=E0=AF=8D =E0=AE=85= =E0=AE=95=E0=AF=8D=E0=AE=9F=E0=AF=8B=E0=AE=AA=E0=AE=B0=E0=AF=8D 21, 2024] V= isuwesh wrote: > [=E0=AE=A4=E0=AE=BF=E0=AE=99=E0=AF=8D=E0=AE=95=E0=AE=B3=E0=AF=8D =E0=AE= =85=E0=AE=95=E0=AF=8D=E0=AE=9F=E0=AF=8B=E0=AE=AA=E0=AE=B0=E0=AF=8D 21, 2024= ] Rens Oliemans wrote: > >> Visuwesh writes: >> >>> If possible, could you please try LibreOffice 7.6.4? The version Ihor >>> has installed in his system. There is an AppImage available for you to >>> try. >> >> Yep, on 7.6.4 the problem occurs. >> >> $ ./LibreOffice-7.6.4.1.basic-x86_64.AppImage --version >> LibreOffice 7.6.4.1 e19e193f88cd6c0525a17fb7a176ed8e6a3e2aa1 >> >> Debugger entered--entering a function: >> * org--libreoffice-table-handler(application/x-libreoffice-tsvc #("f= \0o\0o\0\11\0b\0a\0r\0\11\0\n\0001\0\11\0002\0\11\0003\0\n\0" 0 30 (foreign= -selection STRING))) >> yank-media() >> >> , resulting in >> >> | f\0o\0o\0 | \0b\0a\0r\0 | \0 | >> | \01\0 | \02\0 | \03\0 | >> | \0 | | | >> >> To narrow it down a bit more: the problem exists in 7.6.5.2, and does no= t exist in the >> following release, 7.6.6.3. > > Thank you! So it is most likely not locale related---a major headache > saved. I will look into this soon (cannot promise anything this week > unfortunately). For reasons that escape me completely, I did not see null bytes in the selection in % ./LibreOffice-7.6.4.1.standard.help-x86_64.AppImage --version LibreOffice 7.6.4.1 e19e193f88cd6c0525a17fb7a176ed8e6a3e2aa1 But considering that the chances of having null bytes in documents are very low, I decided to bruteforce strip them. [=E0=AE=9A=E0=AE=A9=E0=AE=BF =E0=AE=85=E0=AE=95=E0=AF=8D=E0=AE=9F=E0=AF=8B= =E0=AE=AA=E0=AE=B0=E0=AF=8D 19, 2024] Visuwesh wrote: > [=E0=AE=9A=E0=AE=A9=E0=AE=BF =E0=AE=85=E0=AE=95=E0=AF=8D=E0=AE=9F=E0=AF= =8B=E0=AE=AA=E0=AE=B0=E0=AF=8D 19, 2024] Ihor Radchenko wrote: > >> Visuwesh writes: >> >>>> Also, do note that any text exceeding >>>> `org-table-convert-region-max-lines' will lead to >>>> `org-table-convert-region' throwing an error. >>> >>> Catching that and messaging the user should be sufficient? >> >> Maybe. Or we may catch and ask user to lift the restriction temporarily. >> Something like: >> >> Inserting large table with more than `org-table-convert-region-max-lines= ' . Continue? (yes/no) > > Ah, something like what Calc does. Yes, I will go with this approach. > Thanks for the suggestion. 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. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-yank-media-handler-for-LibreOffice-Calc-tables.patch >From f392dc1f3eb550c3d833683113c2d958f7f9b722 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 95846b475..e23e388a0 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -21684,7 +21684,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 @@ -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 =attach=. +Yanking tables copied from LibreOffice Calc documents are inserted as +Org tables. + ** Repeating commands :PROPERTIES: :DESCRIPTION: Repeating navigation commands diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 08857962b..9ad2da5d4 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -136,6 +136,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 def094a9a..f9c275ca7 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20354,7 +20354,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))) @@ -20447,6 +20449,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 buffer-file-coding-system 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 --=-=-=--