bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#18132: Time for a smarter dired-guess-shell-alist-default? (dired-x.


From: Juri Linkov
Subject: bug#18132: Time for a smarter dired-guess-shell-alist-default? (dired-x.el)
Date: Sat, 23 Oct 2021 21:29:38 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

> Such a command emulates what double clicking on an icon does
> which most of the time is what a user wants (because it's
> configured it do what their most common app need is).

Such a command is long overdue.  I used the following command
for a long time, and forgot it's not in dired-x.  I don't suggest
to use this implementation, but something like this.  Then like
clicking the right mouse button on a file shows a list of
available apps to open the file in, and M-& does practically the same
with the keyboard.  Then like double clicking on an icon,
some key should use the default command to open the file.

#+begin_src emacs-lisp
(define-key dired-mode-map [(control return)] 'my-dired-run-find-file)
(defun my-dired-run-find-file ()
  "View file for dired."
  (interactive)
  (let* ((file (dired-get-filename)))
    (cond
     ((let* ((command
              (and (functionp 'mm-mime-info)
                   (mm-mime-info
                    (mm-extension-to-mime (file-name-extension file))))))
        (if (and command (stringp command))
            ;; always return ‘t’ for ‘cond’
            (or (ignore (async-shell-command (concat (format command file) 
"&")))
                t))))
     ((string-match "\\.html?$" file)
      (cond
       ((fboundp 'browse-url)
        (browse-url file))))
     ((string-match "\\.elc?$" file)
      (load-file file))
     ((string-match "\\.info?$" file)
      (info file))
     ((let* ((file-list (list (dired-get-filename)))
             (command (dired-guess-default file-list))
             (async-shell-command-display-buffer nil))
        (if (listp command)
            (setq command (car command)))
        (if command
            (async-shell-command
             (dired-shell-stuff-it command file-list nil 0)))))
     (t
      (message "%s" file)))))
#+end_src





reply via email to

[Prev in Thread] Current Thread [Next in Thread]