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

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

extview.el --- open files with external viewer


From: spamfilteraccount
Subject: extview.el --- open files with external viewer
Date: 28 Mar 2006 05:28:27 -0800
User-agent: G2/0.2

With the advent of globalff
(http://www.emacswiki.org/cgi-bin/wiki/GlobalFF) I find cumbersome to
use other applications which use the "traditional" model of file
opening (navigating directories, etc.).

Most of the time I can get faster to a specific file with globalff on
my box, so it seems obvious to use emacs as a file manager to locate
the file, but open it with the appropriate application.

The code below advises find-file and launches an external viewer if the
file name matches any of the prefedefined patterns. This way any file
can be opened in the traditional way or via dired or globalff, etc. and
it is passed to an external application if Emacs cannot handle the
content.

At the moment only pdf files are handled, but it is trivial to add
others.

/Tamas


;;; extview.el --- open files with external viewer

;; Copyright (C) 2006  Free Software Foundation, Inc.

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;; Load the library and try opening a file which has an associated
;; application in `extview-application-associations'.

;;; Code:

(require 'cl)


(defvar extview-application-associations
  '(("\\.pdf$" . "acroread"))
  "List of (REGEXP . APPLICATION) descriptors which are tested for the
file name to be opened. The first matching application is used to open
the file. If no application matches then normal `find-file' is
executed.")


(defadvice find-file (around extview-find-file
                             (filename &optional wildcards) activate)
  "Around advice for find-file which checks if the file should be
opened with an external viewer instead of Emacs."
  (interactive "FFind file: \np")
  (let ((app (some (lambda (descriptor)
                     (if (string-match (car descriptor) filename)
                         (cdr descriptor)))
                   extview-application-associations)))
    (if app
        (let ((logbuffer "*extview log*"))
          (start-process "extview-process" logbuffer
                         app (expand-file-name filename))
          (message (concat "File is opened with an external viewer. "
                           "See buffer %s for status messages")
                   logbuffer))

      ad-do-it)))

(provide 'extview)
;;; extview.el ends here



reply via email to

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