From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.devel Subject: Re: `M-x yank-media' Date: Tue, 23 Nov 2021 23:42:19 +0000 Message-ID: References: <877ddlt2pp.fsf@gnus.org> <837ddk9tc8.fsf@gnu.org> <878ry0kt2h.fsf@gnus.org> <83r1bs85jr.fsf@gnu.org> <87sfw8jdl1.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="kLa0xVg8LfvyXBu7" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11804"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , emacs-devel@gnu.org To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Nov 24 00:44:02 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpfSD-0002rC-So for ged-emacs-devel@m.gmane-mx.org; Wed, 24 Nov 2021 00:44:02 +0100 Original-Received: from localhost ([::1]:49900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mpfSC-0001Du-5f for ged-emacs-devel@m.gmane-mx.org; Tue, 23 Nov 2021 18:44:00 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:42812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpfR6-0000Wv-7r for emacs-devel@gnu.org; Tue, 23 Nov 2021 18:42:53 -0500 Original-Received: from [2a01:4f8:fff0:65::8:228] (port=44385 helo=outbound.soverin.net) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpfQp-0001Hs-AV; Tue, 23 Nov 2021 18:42:50 -0500 Original-Received: from smtp.soverin.net (unknown [10.10.3.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 2677C66; Tue, 23 Nov 2021 23:42:23 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [159.69.232.138]) by soverin.net DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1637710942; bh=V8+iJiZWnTogtI65wh/Vosh8WSum195132fCUfTdEEg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SEUX9Xs+eDytQ6m7rlo7NiGrJBH8XR5kkh6xxJs4cpqkozw4d7s6qBPqNc1o5yNih bgHdeDFolgmvCZ68JJkzySdM7+2WJPakuZVsS5vP46anxW62l8np+8xB5qp2XnqAOK cJtr0AhnJRQdsMmT30AqySNCj/0hC35EPTfdDzx0SsK1G0p3ICHLErHLZwDVx6fDQk Ph6dFjGh6iXgRtp1iRSfcdItbOE4WR1NL5vw2MmxiVIe0sjVOj+evd9hjGFOtfCSMR lWEQSt5tNNx/yQDipnGjoQjaXtqkGyeJgQ2AJKDCG8OTchtgPRaVRdFKHuQg1MwInk MyVL1XXxIJXjQ== Original-Received: from alan by faroe.holly.idiocy.org with local (Exim 4.95-RC2) (envelope-from ) id 1mpfQZ-000coQ-Ow; Tue, 23 Nov 2021 23:42:19 +0000 Mail-Followup-To: Alan Third , Lars Ingebrigtsen , Eli Zaretskii , emacs-devel@gnu.org Content-Disposition: inline In-Reply-To: <87sfw8jdl1.fsf@gnus.org> X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:4f8:fff0:65::8:228 (failed) Received-SPF: pass client-ip=2a01:4f8:fff0:65::8:228; envelope-from=alan@idiocy.org; helo=outbound.soverin.net X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:279974 Archived-At: --kLa0xVg8LfvyXBu7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, Nov 07, 2021 at 02:32:42PM +0100, Lars Ingebrigtsen wrote: > Eli Zaretskii writes: > > > What does this require from the clipboard to work? What are the > > assumptions? > > It's basically this on GNU/Linux: > > (gui-get-selection 'CLIPBOARD 'TARGETS) > => > [TIMESTAMP TARGETS MULTIPLE SAVE_TARGETS text/html text/_moz_htmlinfo text/_moz_htmlcontext image/png image/jpeg image/bmp image/x-bmp image/x-MS-bmp image/x-icon image/x-ico image/x-win-bitmap image/vnd\.microsoft\.icon application/ico image/ico image/icon text/ico image/tiff] > > This lists the available media types. > > I've just had a quick peek at what happens in Macos, and it's very > different there. > > (gui-get-selection 'CLIPBOARD 'TARGETS) > => "http" > > So gui-get-selection (or rather, ns-get-selection) has to grow support > for this? I think the attached should sort this. It doesn't seem to do much on GNUstep, I suspect GNUstep itself doesn't support copying of much more than plain text. -- Alan Third --kLa0xVg8LfvyXBu7 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Enable-yank-media-on-NS.patch" >From 2606ecbed8df134370aed4c40215cf6928cb3215 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Tue, 23 Nov 2021 20:56:44 +0000 Subject: [PATCH] Enable yank-media on NS * src/nsselect.m (ns_get_foreign_selection): Handle non-plain text clipboard entries. (ns_string_from_pasteboard): Remove EOL conversion. (syms_of_nsselect): Define QTARGETS. --- src/nsselect.m | 80 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/src/nsselect.m b/src/nsselect.m index 5ab3ef77fe..e999835014 100644 --- a/src/nsselect.m +++ b/src/nsselect.m @@ -215,9 +215,74 @@ Updated by Christian Limpach (chris@nice.ch) static Lisp_Object ns_get_foreign_selection (Lisp_Object symbol, Lisp_Object target) { + NSDictionary *typeLookup; id pb; pb = ns_symbol_to_pb (symbol); - return pb != nil ? ns_string_from_pasteboard (pb) : Qnil; + + /* Dictionary for looking up NS types from MIME types, and vice versa. */ + typeLookup + = [NSDictionary + dictionaryWithObjectsAndKeys: + @"text/plain", NSPasteboardTypeURL, +#if NS_USE_NSPasteboardTypeFileURL + @"text/plain", NSPasteboardTypeFileURL, +#else + @"text/plain", NSFilenamesPboardType, +#endif + @"text/html", NSPasteboardTypeHTML, + @"text/plain", NSPasteboardTypeMultipleTextSelection, + @"application/pdf", NSPasteboardTypePDF, + @"image/png", NSPasteboardTypePNG, + @"application/rtf", NSPasteboardTypeRTF, + @"application/rtfd", NSPasteboardTypeRTFD, + @"STRING", NSPasteboardTypeString, + @"text/plain", NSPasteboardTypeTabularText, + @"image/tiff", NSPasteboardTypeTIFF, + nil]; + + if (EQ (target, QTARGETS)) + { + NSMutableArray *types = [NSMutableArray arrayWithCapacity:3]; + + NSString *type; + NSEnumerator *e = [[pb types] objectEnumerator]; + while (type = [e nextObject]) + { + NSString *val = [typeLookup valueForKey:type]; + if (val && ! [types containsObject:val]) + [types addObject:val]; + } + + Lisp_Object v = Fmake_vector (make_fixnum ([types count]+1), Qnil); + ASET (v, 0, QTARGETS); + + for (int i = 0 ; i < [types count] ; i++) + ASET (v, i+1, intern ([[types objectAtIndex:i] UTF8String])); + + return v; + } + else + { + NSData *d; + NSArray *availableTypes; + NSString *result, *t; + + if (!NILP (target)) + availableTypes + = [typeLookup allKeysForObject: + [NSString stringWithLispString:SYMBOL_NAME (target)]]; + else + availableTypes = @[NSPasteboardTypeString]; + + t = [pb availableTypeFromArray:availableTypes]; + + result = [pb stringForType:t]; + if (result) + return [result lispString]; + + d = [pb dataForType:t]; + return make_string ([d bytes], [d length]); + } } @@ -234,8 +299,6 @@ Updated by Christian Limpach (chris@nice.ch) ns_string_from_pasteboard (id pb) { NSString *type, *str; - const char *utfStr; - int length; type = [pb availableTypeFromArray: ns_return_types]; if (type == nil) @@ -260,6 +323,14 @@ Updated by Christian Limpach (chris@nice.ch) } } + /* FIXME: Is the below EOL conversion even needed? I've removed it + for now so we can see if it causes problems. */ + return [str lispString]; + +#if 0 + const char *utfStr; + int length; + /* assume UTF8 */ NS_DURING { @@ -294,6 +365,7 @@ Updated by Christian Limpach (chris@nice.ch) NS_ENDHANDLER return make_string (utfStr, length); +#endif } @@ -491,6 +563,8 @@ Updated by Christian Limpach (chris@nice.ch) DEFSYM (QTEXT, "TEXT"); DEFSYM (QFILE_NAME, "FILE_NAME"); + DEFSYM (QTARGETS, "TARGETS"); + defsubr (&Sns_disown_selection_internal); defsubr (&Sns_get_selection); defsubr (&Sns_own_selection_internal); -- 2.33.0 --kLa0xVg8LfvyXBu7--