From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id sJZbA2oOk2KgQgEAbAwnHQ (envelope-from ) for ; Sun, 29 May 2022 08:10:50 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 2EJaA2oOk2JtrQAA9RJhRA (envelope-from ) for ; Sun, 29 May 2022 08:10:50 +0200 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 B28901E60 for ; Sun, 29 May 2022 08:10:49 +0200 (CEST) Received: from localhost ([::1]:39558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvC8W-0004qg-Pv for larch@yhetil.org; Sun, 29 May 2022 02:10:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvC5A-0004pw-A2 for emacs-orgmode@gnu.org; Sun, 29 May 2022 02:07:20 -0400 Received: from ciao.gmane.io ([116.202.254.214]:60284) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvC58-0007iU-Gt for emacs-orgmode@gnu.org; Sun, 29 May 2022 02:07:20 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1nvC54-00068x-7f for emacs-orgmode@gnu.org; Sun, 29 May 2022 08:07:14 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Max Nikulin Subject: Re: [PATCH v2] Re: Bug in 9.5.3 org--file-default-apps Date: Sun, 29 May 2022 13:07:06 +0700 Message-ID: References: <963d5f94-3fdf-a01b-bc91-edc99222cb34@gmail.com> <87czgeaxir.fsf@localhost> <6615610d-93ae-171f-b554-3f4cc79354cc@gmail.com> <87a6bhc1w6.fsf@localhost> <86692975-4d5f-6933-3227-c6b208f76862@gmail.com> <877d6lbsg5.fsf@localhost> <7c75b724-1ea2-5e3e-cbe6-e1895fd35bd3@gmail.com> <877d6j2htv.fsf@localhost> <87ilq14p6p.fsf@localhost> <87v8u0396t.fsf@localhost> <87ilpz3bi0.fsf@localhost> <87h75ip5r6.fsf@localhost> <87zgj46hwo.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Content-Language: en-US In-Reply-To: <87zgj46hwo.fsf@localhost> Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 28 X-Spam_score: 2.8 X-Spam_bar: ++ X-Spam_report: (2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NICE_REPLY_A=-0.001, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1653804649; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rFKlrR8QYwI/JAWphoXsBL680MWK/IYaeatpNbbpVdw=; b=altz6RyzBGyPTf3I39pqsEEeh0CpwOJB2237SZYOWTK9aW3PbZkCHVIMLqB3WK4eJs5pNH QjiJQ/DJUE8Jp/0o1cpsc3IkETfjG7oQfqaXQaSzB9FzR+b+bgS4bXWAOC2v95vCwXorhp 5P1wEG/1bRPdhWl1g3zTc6jKgHGkLDiAao2Ca/aap6qAJa3aXJQddAHsXF7kbegeibutFW SNnnf9Fm2ZtwBkRrVa9DjxJlUiznPbGDbxVvLu0rfkrCH39ajyqeK5MX6LvGJ8B9Ij9/UD /cmPSM3a7RIRU1SncMpZ9D379iz4SrxRvLAuiasVT2U1cTVDH0oNE7ver1gisQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1653804649; a=rsa-sha256; cv=none; b=BS9uUkzYU+NDLWxbd7u0PIJFtPJZ+E/xthbKSNvrPNGDtT+VzslKSBM3sUNgFXLcpucpg0 FQ0dBb3y/U6YurP5pTsAyCDIOKm8Ba1b+I3DNxKEzOtZgH5FZ2VwXcdukeV5YfzFIcHQrm zdIkj4AuNe79nyt7lxrQLqRnQY5Jswg36wBBNLYepQ4wFczpeYgEmhVOLzEf8uyKJBp3Nn 6aPEd73KQuXeN3KgG5NQkoWqqWHWNVAou38PJsB+a/PZysEwZnn29nMIqducQTKs+PnFgB sd4cVwGD259hIxrLkiVw8EN8LZP6s/k0Q1G1IexIgvMLat5wucWFwW3K6HuLeQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); 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" X-Migadu-Spam-Score: 2.66 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); 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" X-Migadu-Queue-Id: B28901E60 X-Spam-Score: 2.66 X-Migadu-Scanner: scn1.migadu.com X-TUID: 6UnhLygI+T/4 Ihor, Your patch may be an improvement, but it requires an additional fix, see below. However, in my opinion, it does not address original Craig's issue. The patch improves handling of *non-text* files requiring *external* viewers, while Craig complained that behavior for shell script is incorrect and his problem is tightly bound to erased `mailcap-mime-data'. I can not reproduce behavior he observed exactly, Org does not opens shell scripts by less, but it tries and silently (it is expected) fails. My results (emacs-27): 1. If there is no mailcap files at all, the script is opened in the same emacs session that is correct from my point of view. 2. If I add ~/.mailcap text/plain; less '%s'; needsterminal then I get silent failures Running less /etc/profile...done 3. With your patch and the following additional entry in ~/.mailcap (notice "text" instead of "application" and just "emacs") text/x-shellscript; emacs %s; test=test -n "$DISPLAY" new Emacs session is started. It is a problem but partially it is caused by incorrect mailcap configuration. Unlike "text/plain" that would be handled by view-mode unless `mailcap-mime-data' were erased in Emacs-27, "text/x-shellscript" is handled by less on my main system due to mailcap while I would expect same Emacs session. I read implementation of `org-open-file' once more and now I see that currently remote files can not be processed by mailcap code path even with custom `org-file-apps', so thank you for explanation. In some cases it may be handy to launch remote viewer from a host accessed through ssh, but let's leave it aside. > - (let* ((mime-type (mailcap-extension-to-mime (or ext ""))) > + (let* ((mime-type (if (executable-find "file") I would consider (and ... (not remp)) despite currently it is redundant. Just to mitigate consequences if other parts of this complicated function will be modified. On the other hand `start-process-shell-command' is not ready for remote files anyway, so major cleanup would be required. > + (shell-command-to-string > + (format "%s --brief --mime-type %s" > + (executable-find "file") > + (shell-quote-argument (convert-standard-filename file)))) It is not enough to cure my paranoia. However the following case is rather pathological mkdir 'Program Files' ln -s /usr/bin/file 'Program Files'/ PATH="$HOME/Program Files:$PATH" \ emacs -Q -L ~/src/org-mode/lisp/ ~/examples/org/open-script.org & Debugger entered--Lisp error: (wrong-type-argument stringp nil) string-match("/" nil 0) split-string(nil "/") mailcap-mime-info("/bin/bash: line 1: /home/ubuntu/Program: No such f...") (let* ((mime-type (if (executable-find "file") (shell-command-to-string (format "%s --brief --mime-type %s" (executable-find "file") (shell-quote-argument (convert-standard-filename file)))) (mailcap-extension-to-mime (or ext "")))) (command (mailcap-mime-info mime-type))) (if (stringp command) (setq cmd command) (setq cmd 'emacs))) > + (mailcap-extension-to-mime (or ext "")))) > Agree. Though it is not directly related. Maybe you can bump that thread > and mark is as a bug report to be listed on > https://updates.orgmode.org/? It is already tracked there as "org-open-file & org-file-apps multiple substitution bug" but my point was that great care is required otherwise a lot of issues may happen with shell command. Ihor Radchenko. Bug in 9.5.3 org--file-default-apps. Wed, 25 May 2022 14:18:10 +0800. https://list.orgmode.org/8735gy2l0d.fsf@localhost >> '>$ run-mailcap myscript' > > One comment. I do not personally have run-mailcap command on my system, > but searching for its docstring reveals > (http://www.linux-commands-examples.com/run-mailcap): > >>> If the mime-type is omitted, an attempt to determine the type is >>> made by trying to match the file’s extension with those in the >>> mime.types files. > > So, run-mailcap itself does not look inside the file and only checks the > extension. AFAIU. Correct me if I am wrong. It is a Debian extension. Local man page has the following statement (confirmed by code and strace): > If no mime-type is found, a last attempt will be done by running the > file command, if available.