[Top][All Lists]

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

Re: Open file at point with external program

From: Xah Lee
Subject: Re: Open file at point with external program
Date: Tue, 4 May 2010 06:28:12 -0700 (PDT)
User-agent: G2/1.0

On May 3, 8:06 am, michael <> 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.


(defun open-in-desktop ()
  "Open the current file in desktop.
Works in Microsoft Windows and Mac OS X."
   ((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:

 (let (ff)
   (if (and transient-mark-mode mark-active)
         (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...


reply via email to

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