From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#63911: Dired Open With Date: Thu, 23 Nov 2023 19:54:12 +0200 Organization: LINKOV.NET Message-ID: <86pm00xsmz.fsf@mail.linkov.net> References: <86bkhuney2.fsf@mail.linkov.net> <868rca9map.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25066"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) To: 63911@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 23 19:05:19 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1r6E4k-0006IW-Mv for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 23 Nov 2023 19:05:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r6E4U-00059Q-IZ; Thu, 23 Nov 2023 13:05:02 -0500 Original-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 1r6E4S-000596-SK for bug-gnu-emacs@gnu.org; Thu, 23 Nov 2023 13:05:00 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r6E4R-0005tv-IH for bug-gnu-emacs@gnu.org; Thu, 23 Nov 2023 13:04:59 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r6E4U-0001i5-Bt for bug-gnu-emacs@gnu.org; Thu, 23 Nov 2023 13:05:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 23 Nov 2023 18:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63911 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 63911-submit@debbugs.gnu.org id=B63911.17007626696508 (code B ref 63911); Thu, 23 Nov 2023 18:05:02 +0000 Original-Received: (at 63911) by debbugs.gnu.org; 23 Nov 2023 18:04:29 +0000 Original-Received: from localhost ([127.0.0.1]:35071 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r6E3x-0001gp-7s for submit@debbugs.gnu.org; Thu, 23 Nov 2023 13:04:29 -0500 Original-Received: from relay8-d.mail.gandi.net ([2001:4b98:dc4:8::228]:53965) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r6E3t-0001gK-PA for 63911@debbugs.gnu.org; Thu, 23 Nov 2023 13:04:26 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id AB3A61BF204 for <63911@debbugs.gnu.org>; Thu, 23 Nov 2023 18:04:14 +0000 (UTC) In-Reply-To: (Stefan Kangas's message of "Sat, 2 Sep 2023 00:33:29 +0200") X-GND-Sasl: juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:274823 Archived-At: --=-=-= Content-Type: text/plain >> After using this for a while I noticed that most of the time >> mailcap suggestions are useless - they don't contain the same >> items as in the context menus of a File Manager. For example, >> clicking the right mouse button on a ScreamTracker .stm file >> opens a menu with Rhythmbox, and clicking on a ScreamTracker3 >> .s3m file opens a menu where the first item is Celluloid >> and the second is Rhythmbox. >> >> So I implemented support for xdg commands that now displays exactly >> the same menus in Emacs as in the File Manager, and with the same order. > > Agreed, it's better to use the xdg commands for this. Here is a new patch that uses a new generalized function 'shell-command-guess' from bug#18132: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=dired-context-menu-shell-command-guess.patch diff --git a/lisp/dired.el b/lisp/dired.el index c212e3094f8..bb55add9d33 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -2533,13 +2533,30 @@ dired-context-menu "Populate MENU with Dired mode commands at CLICK." (when (mouse-posn-property (event-start click) 'dired-filename) (define-key menu [dired-separator] menu-bar-separator) - (let ((easy-menu (make-sparse-keymap "Immediate"))) + (require 'mailcap) + (require 'xdg) + (let* ((filename (save-excursion + (mouse-set-point click) + (dired-get-filename nil t))) + (commands (shell-command-guess (list filename))) + (easy-menu (make-sparse-keymap "Immediate"))) (easy-menu-define nil easy-menu nil - '("Immediate" + `("Immediate" ["Find This File" dired-mouse-find-file :help "Edit file at mouse click"] ["Find in Other Window" dired-mouse-find-file-other-window - :help "Edit file at mouse click in other window"])) + :help "Edit file at mouse click in other window"] + ,@(when commands + (list (cons "Open With" + (append + (mapcar (lambda (command) + `[,(or (get-text-property 0 'name command) + command) + (lambda () + (interactive) + (dired-do-async-shell-command + ,command nil (list ,filename)))]) + commands))))))) (dolist (item (reverse (lookup-key easy-menu [menu-bar immediate]))) (when (consp item) (define-key menu (vector (car item)) (cdr item)))))) --=-=-=--