From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jambunathan K Newsgroups: gmane.emacs.bugs Subject: bug#14110: 24.3.50; Add command to open files outside of Emacs (use xdg-open, open etc) Date: Mon, 01 Apr 2013 12:27:58 +0530 Message-ID: <87zjxi4u15.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1364799556 30807 80.91.229.3 (1 Apr 2013 06:59:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 1 Apr 2013 06:59:16 +0000 (UTC) To: 14110@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Apr 01 08:59:43 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UMYiU-0006a9-SE for geb-bug-gnu-emacs@m.gmane.org; Mon, 01 Apr 2013 08:59:43 +0200 Original-Received: from localhost ([::1]:39961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMYi6-0000DF-Fo for geb-bug-gnu-emacs@m.gmane.org; Mon, 01 Apr 2013 02:59:18 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:48153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMYi2-00008i-25 for bug-gnu-emacs@gnu.org; Mon, 01 Apr 2013 02:59:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMYhz-0003dT-W1 for bug-gnu-emacs@gnu.org; Mon, 01 Apr 2013 02:59:14 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:51186) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMYhz-0003dL-Sh for bug-gnu-emacs@gnu.org; Mon, 01 Apr 2013 02:59:11 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UMYkk-0002AN-He for bug-gnu-emacs@gnu.org; Mon, 01 Apr 2013 03:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jambunathan K Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 01 Apr 2013 07:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 14110 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.13647996768267 (code B ref -1); Mon, 01 Apr 2013 07:02:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 Apr 2013 07:01:16 +0000 Original-Received: from localhost ([127.0.0.1]:55295 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UMYjz-00029I-BW for submit@debbugs.gnu.org; Mon, 01 Apr 2013 03:01:15 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36595) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UMYjt-000298-Rv for submit@debbugs.gnu.org; Mon, 01 Apr 2013 03:01:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMYh5-0003Tf-Oo for submit@debbugs.gnu.org; Mon, 01 Apr 2013 02:58:18 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:49368) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMYh5-0003TQ-L7 for submit@debbugs.gnu.org; Mon, 01 Apr 2013 02:58:15 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMYh0-00088r-VV for bug-gnu-emacs@gnu.org; Mon, 01 Apr 2013 02:58:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMYgy-0003Sl-43 for bug-gnu-emacs@gnu.org; Mon, 01 Apr 2013 02:58:10 -0400 Original-Received: from mail-pb0-f45.google.com ([209.85.160.45]:57695) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMYgx-0003Se-Qy for bug-gnu-emacs@gnu.org; Mon, 01 Apr 2013 02:58:08 -0400 Original-Received: by mail-pb0-f45.google.com with SMTP id ro8so1056250pbb.32 for ; Sun, 31 Mar 2013 23:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:subject:date:message-id:mime-version :content-type; bh=qpBn5VgBKyjq/VdVkrmZvAzX4KbgejjzshPws7DxT+c=; b=dRdFxJ/3wySurb1O04+zLOwmM9qUhidPB3JeH34Y/cEBTluj3ER3XPcql5f7XoOL9d Bzd/TlRmpResxvnsL6bN8uaV6RvN8J75MAcNx2r+UbpLxW5M6ORyolqBz4rMUnW85oUo w1Tai4inec5svbtscQ/LC0fOLAvMAozQQVEtvTcCjUY7SvNyoDqZWZ7zrWxObqkKAnYu PpgPkJIBZ56vLTgr+hXm9U7eC6VIDZM4eJp1vIJqzISlqWjI9dU/bUdqX37xemKsRarC KhEOSMe3HjeGmM3IoCbjAVJNtf1ChVl7MA1dPH+CmaNXnkYKcKDibNi3QRORAAa2H2rR oQiQ== X-Received: by 10.68.129.135 with SMTP id nw7mr16518091pbb.58.1364799486972; Sun, 31 Mar 2013 23:58:06 -0700 (PDT) Original-Received: from debian-6.05 ([101.63.135.39]) by mx.google.com with ESMTPS id tf8sm12673725pbc.42.2013.03.31.23.58.03 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Sun, 31 Mar 2013 23:58:06 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 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.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:73056 Archived-At: --=-=-= Content-Type: text/plain Add support for opening files outside of Emacs (use xdg-open, open etc). This is something that I sorely missed or continue to miss. Here is an (initial) patch... --=-=-= Content-Type: text/x-diff Content-Disposition: inline Content-Description: open-file.diff === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-03-31 15:19:19 +0000 +++ lisp/ChangeLog 2013-04-01 06:50:35 +0000 @@ -1,3 +1,13 @@ +2013-04-01 Jambunathan K + + * files.el (open-file-command): New user option. + (open-file): New command. + (ctl-x-map): Bind it to `C-S-f'. + + * dired-aux.el (dired-do-open): New command + + * dired.el (dired-mode-map): Bind it to `C-S-f'. + 2013-03-31 Roland Winkler * emacs-lisp/crm.el (completing-read-multiple): Doc fix. === modified file 'lisp/dired-aux.el' --- lisp/dired-aux.el 2013-02-28 21:51:11 +0000 +++ lisp/dired-aux.el 2013-04-01 05:44:57 +0000 @@ -426,6 +426,18 @@ Uses the shell command coming from varia 'print arg file-list))) (dired-run-shell-command (dired-shell-stuff-it command file-list nil)))) +;;;###autoload +(defun dired-do-open (&optional arg) + "Open the marked (or next ARG) files (presumably) outside of Emacs. +Use shell command coming from variable `open-file-command' to +open the file." + (interactive "P") + (let* ((file-list (dired-get-marked-files t arg)) + (command (dired-mark-read-string "Open %s with: " + (eval (cadr (assq system-type open-file-command))) + t arg file-list))) + (dired-run-shell-command (dired-shell-stuff-it command file-list t)))) + (defun dired-mark-read-string (prompt initial op-symbol arg files &optional default-value collection) "Read args for a Dired marked-files command, prompting with PROMPT. === modified file 'lisp/dired.el' --- lisp/dired.el 2013-02-28 21:51:11 +0000 +++ lisp/dired.el 2013-04-01 06:52:10 +0000 @@ -1426,6 +1426,7 @@ Do so according to the former subdir ali (define-key map "C" 'dired-do-copy) (define-key map "B" 'dired-do-byte-compile) (define-key map "D" 'dired-do-delete) + (define-key map [33554438] 'dired-do-open) ; C-S-f (define-key map "G" 'dired-do-chgrp) (define-key map "H" 'dired-do-hardlink) (define-key map "L" 'dired-do-load) @@ -3958,6 +3959,13 @@ Uses the shell command coming from varia \(fn &optional ARG)" t nil) +(autoload 'dired-do-open "dired-aux" "\ +Open the marked (or next ARG) files (presumably) outside of Emacs. +Use shell command coming from variable `open-file-command' to +open the file. + +\(fn &optional ARG)" t nil) + (autoload 'dired-clean-directory "dired-aux" "\ Flag numerical backups for deletion. Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest. === modified file 'lisp/files.el' --- lisp/files.el 2013-03-24 06:42:25 +0000 +++ lisp/files.el 2013-04-01 06:05:45 +0000 @@ -6805,6 +6805,54 @@ Otherwise, trash FILENAME using the free (rename-file fn new-fn))))))))) +;; Open files outside of Emacs +(defcustom open-file-command '((gnu "xdg-open *") + (gnu/linux "xdg-open *") + (gnu/kfreebsd "xdg-open *") + (darwin "open *") + (windows-nt "open *") + (cygwin "open *") + (ms-dos nil)) + "Shell commands for opening files generically. + +Each element of this list looks like + + (SYSTEM-TYPE COMMAND...) + +SYSTEM-TYPE is one of `system-type's. + +COMMAND can either be a string or a Lisp expression that +evaluates to a string. It follows the same semantics as the +COMMAND param of `dired-do-shell-command'." + :type '(alist :key-type symbol :value-type (group sexp) + :options ((gnu "xdg-open &") + (gnu/linux "xdg-open &") + (gnu/kfreebsd "xdg-open &") + (darwin "open &") + (windows-nt "open &") + (cygwin "open &") + (ms-dos nil))) + :version "24.4" + :group 'file) + +(eval-when-compile + (require 'dired-aux)) + +(defun open-file (filename) + "Open FILENAME (presumably) outside of Emacs. +Use shell command from `open-file-command' to open the file." + (interactive "fOpen file:") + (require 'dired-aux) + (let* ((default-directory (file-name-directory filename)) + (filename (file-name-nondirectory filename)) + (command (or (eval (cadr (assq system-type open-file-command))) + (read-shell-command (format "Open %s with: " filename) nil + 'dired-shell-command-history)))) + (when (and command (string-match "\\S-" command)) + (dired-run-shell-command (dired-shell-stuff-it command (list filename) t))))) + + +(define-key ctl-x-map [33554438] 'open-file) ; C-x C-S-f (define-key ctl-x-map "\C-f" 'find-file) (define-key ctl-x-map "\C-r" 'find-file-read-only) (define-key ctl-x-map "\C-v" 'find-alternate-file) --=-=-= Content-Type: text/plain In GNU Emacs 24.3.50.7 (i686-pc-linux-gnu, GTK+ Version 2.20.1) of 2013-04-01 on debian-6.05 Bzr revision: 112204 jay.p.belanger@gmail.com-20130331202740-d1t6qedxr13vmnzc Windowing system distributor `The X.Org Foundation', version 11.0.10707000 Important settings: value of $LANG: en_IN locale-coding-system: iso-latin-1-unix default enable-multibyte-characters: t --=-=-=--