unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Open file at point with external program
@ 2010-05-03 15:06 michael
  2010-05-03 21:15 ` Andreas Politz
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: michael @ 2010-05-03 15:06 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

suppose I use emacs to edit a file which contains a path to a file,
e.g. /path/to/file/file.pdf, suppose point is at the string /path/to/
file/file.pdf, is it possible to open file.pdf with a single command
using an *external* program (e.g. gnome-open)?

thanks,
michael


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open file at point with external program
  2010-05-03 15:06 Open file at point with external program michael
@ 2010-05-03 21:15 ` Andreas Politz
  2010-05-05  0:24   ` Lennart Borgman
       [not found]   ` <mailman.53.1273019113.29092.help-gnu-emacs@gnu.org>
  2010-05-04  8:36 ` Marc Mientki
  2010-05-04 13:28 ` Xah Lee
  2 siblings, 2 replies; 6+ messages in thread
From: Andreas Politz @ 2010-05-03 21:15 UTC (permalink / raw)
  To: help-gnu-emacs

michael <mchls5714@googlemail.com> writes:

> Hi,
>
> suppose I use emacs to edit a file which contains a path to a file,
> e.g. /path/to/file/file.pdf, suppose point is at the string /path/to/
> file/file.pdf, is it possible to open file.pdf with a single command
> using an *external* program (e.g. gnome-open)?
>
> thanks,
> michael

I abuse org-mode for doing this kind of thing in a dired-buffer.  I
suppose this can also work with,e.g. ffap :

(defun dired-open-file (arg)
  "Abuse org-open-file to open a file at point externally."
  (interactive "P")
  (require 'org)
  (require 'ffap)
  (org-open-file (or (ffap-guesser)
                     (error "No filename at point"))
                 arg))

-ap
                     

                     


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open file at point with external program
  2010-05-03 15:06 Open file at point with external program michael
  2010-05-03 21:15 ` Andreas Politz
@ 2010-05-04  8:36 ` Marc Mientki
  2010-05-04 13:28 ` Xah Lee
  2 siblings, 0 replies; 6+ messages in thread
From: Marc Mientki @ 2010-05-04  8:36 UTC (permalink / raw)
  To: help-gnu-emacs

Am 03.05.2010 17:06, schrieb michael:
> Hi,
>
> suppose I use emacs to edit a file which contains a path to a file,
> e.g. /path/to/file/file.pdf, suppose point is at the string /path/to/
> file/file.pdf, is it possible to open file.pdf with a single command
> using an *external* program (e.g. gnome-open)?

Simply install and configure openwith.el and do ffap on the file name.

regards
Marc



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open file at point with external program
  2010-05-03 15:06 Open file at point with external program michael
  2010-05-03 21:15 ` Andreas Politz
  2010-05-04  8:36 ` Marc Mientki
@ 2010-05-04 13:28 ` Xah Lee
  2 siblings, 0 replies; 6+ messages in thread
From: Xah Lee @ 2010-05-04 13:28 UTC (permalink / raw)
  To: help-gnu-emacs

On May 3, 8:06 am, michael <mchls5...@googlemail.com> wrote:
> Hi,
>
> suppose I use emacs to edit a file which contains a path to a file,
> e.g. /path/to/file/file.pdf, suppose point is at the string /path/to/
> file/file.pdf, is it possible to open file.pdf with a single command
> using an *external* program (e.g. gnome-open)?

yeah, very easy.

See:

(defun open-in-desktop ()
  "Open the current file in desktop.
Works in Microsoft Windows and Mac OS X."
  (interactive)
  (cond
   ((string-equal system-type "windows-nt")
    (w32-shell-execute "explore"
                       (replace-regexp-in-string "/" "\\" default-
directory t t)))
   ((string-equal system-type "darwin") (shell-command "open ."))
   ) )


(defun xah-find-file-at-point ()
 "Open the file path under cursor.

If there's no current text selection, this command uses current
word as input. If there is a text selection, it uses the text
selection for path. (convenient if the file path contains space)

This is similar to `find-file-at-point' but
customized for Xah Lee.
URL that starts with
“file:///xahdomain/” or “http://xahdomain/”
will also changed to local path.
The following path all works:

/Users/xah/web/xahlee_org/emacs/emacs.html
c:/Users/xah/web/xahlee_org/emacs/emacs.html
~/web/xahlee_org/emacs/emacs.html
file:///C:/Users/xah/web/xahlee_org/emacs/emacs.html
http://xahlee.org/emacs/emacs.html"
 (interactive)
 (let (ff)
   (if (and transient-mark-mode mark-active)
       (progn
         (setq ff (buffer-substring-no-properties (region-beginning)
(region-end) ) )
         )
     (setq ff (thing-at-point 'filename)))

   (setq ff (xahlee-site-url-to-fpath ff))
   (setq ff (local-url-to-file-path ff))
;; ;    (setq ff (windows-style-path-to-unix ff))

   ;; make some path starting with “/” to be “~/web/xahlee_org”
   (when (and
          (string-equal "/" (substring ff 0 1))
          (not (string-equal "/Deskto" (substring ff 0 7)))
          (not (string-equal "/Developer" (substring ff 0 10)))
          (not (string-equal "/Library" (substring ff 0 8)))
          (not (string-equal "/Network" (substring ff 0 8)))
          (not (string-equal "/System" (substring ff 0 7)))
          (not (string-equal "/TheVol" (substring ff 0 7)))
          (not (string-equal "/Volumes" (substring ff 0 8)))
          (not (string-equal "/bin" (substring ff 0 4)))
          (not (string-equal "/cores" (substring ff 0 6)))
          (not (string-equal "/dev" (substring ff 0 4)))
          (not (string-equal "/opt" (substring ff 0 4)))
          (not (string-equal "/private" (substring ff 0 8)))
          (not (string-equal "/sbin" (substring ff 0 5)))
          (not (string-equal "/sw" (substring ff 0 3)))
          (not (string-equal "/usr" (substring ff 0 4)))
          (not (string-equal "/var" (substring ff 0 4)))
          (not (string-equal "/Users/" (substring ff 0 7))))
     (setq ff (concat "~/web/xahlee_org/" ff)))

    (if (not (file-exists-p ff))
        (if (file-exists-p (concat ff ".el"))
            (find-file-at-point (concat ff ".el"))
            (find-file-at-point ff)
            )
      (find-file-at-point ff)
      )
))

btw, emacs 23 can open pdf files inside emacs... though, the feature
is not very robust of course. Some pdf files won't open...

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open file at point with external program
  2010-05-03 21:15 ` Andreas Politz
@ 2010-05-05  0:24   ` Lennart Borgman
       [not found]   ` <mailman.53.1273019113.29092.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: Lennart Borgman @ 2010-05-05  0:24 UTC (permalink / raw)
  To: Andreas Politz; +Cc: help-gnu-emacs

On Mon, May 3, 2010 at 11:15 PM, Andreas Politz <politza@fh-trier.de> wrote:
> michael <mchls5714@googlemail.com> writes:
>
>> Hi,
>>
>> suppose I use emacs to edit a file which contains a path to a file,
>> e.g. /path/to/file/file.pdf, suppose point is at the string /path/to/
>> file/file.pdf, is it possible to open file.pdf with a single command
>> using an *external* program (e.g. gnome-open)?
>>
>> thanks,
>> michael
>
> I abuse org-mode for doing this kind of thing in a dired-buffer.  I
> suppose this can also work with,e.g. ffap :
>
> (defun dired-open-file (arg)
>  "Abuse org-open-file to open a file at point externally."
>  (interactive "P")
>  (require 'org)
>  (require 'ffap)
>  (org-open-file (or (ffap-guesser)
>                     (error "No filename at point"))
>                 arg))

There is also sex-mode.el in nXhtml for this.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open file at point with external program
       [not found]   ` <mailman.53.1273019113.29092.help-gnu-emacs@gnu.org>
@ 2010-05-09 14:18     ` michael
  0 siblings, 0 replies; 6+ messages in thread
From: michael @ 2010-05-09 14:18 UTC (permalink / raw)
  To: help-gnu-emacs

Hi!

Thank you very much for all the suggestions!

Michael


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-05-09 14:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-03 15:06 Open file at point with external program michael
2010-05-03 21:15 ` Andreas Politz
2010-05-05  0:24   ` Lennart Borgman
     [not found]   ` <mailman.53.1273019113.29092.help-gnu-emacs@gnu.org>
2010-05-09 14:18     ` michael
2010-05-04  8:36 ` Marc Mientki
2010-05-04 13:28 ` Xah Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).