all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Xah Lee <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Open file at point with external program
Date: Tue, 4 May 2010 06:28:12 -0700 (PDT)	[thread overview]
Message-ID: <26405517-0eb8-4103-806a-6ae332ae487d@a27g2000prj.googlegroups.com> (raw)
In-Reply-To: 8cf09a85-9442-42b2-9f79-aac7789c6304@i10g2000yqh.googlegroups.com

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/

      parent reply	other threads:[~2010-05-04 13:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=26405517-0eb8-4103-806a-6ae332ae487d@a27g2000prj.googlegroups.com \
    --to=xahlee@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.