[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: emacs equivalent of vi %
Re: emacs equivalent of vi %
Fri, 15 Aug 2008 17:14:32 -0700
Emmett Grogan <address@hidden> writes:
>> This code will run the current file:
>> (defun run-current-file ()
>> "Execute or compile the current file....
> I assembled a elisp module out of it. In case someone is interested:
> ;; Version: $Id: run-current-file.el 4518 2008-08-13 21:31:36Z emmettgrogan $
> ;; This program 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 program 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 this program; if not, write to the Free Software
> ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> ;; Commentary:
> ;; Original author: Xah Lee
> ;;; Adapted from http://xahlee.org/emacs/elisp_run_current_file.html
> ;;; Code:
> (defgroup run-current-file-menu nil
> "Execute or compile the current file.")
> (defcustom run-current-file-name-masks
> ("php" . "php")
> ("pl" . "perl")
> ("py" . "python")
> ("sh" . "bash")
> ("java" . "javac")
> "Filename extensions that switch on run-current-file.")
> (defun run-current-file ()
> "Execute or compile the current file.
> For example, if the current buffer is the file x.pl,
> then it'll call “perl x.pl” in a shell.
> The file can be php, perl, python, bash, java.
> File suffix is used to determine what program to run."
> (let (run-current-file-name-masks file-name file-ext prog-name cmd-str)
> ; get the file name
> ; get the program name
> ; run it
> (setq file-name (buffer-file-name))
> (setq file-ext (file-name-extension file-name))
> (setq prog-name (cdr (assoc file-ext run-current-file-name-masks)))
> (setq cmd-str (concat prog-name " " file-name))
> (shell-command cmd-str))
> (provide 'run-current-file)
> ;;; (run-current-file) ends here
This seems to fall into two different cases - one that compiles the file and
another that runs or views the file. The first one can perhaps be done with a
wrapper on "compile" instead of shell-command so that all of the benefits of
compile are abailable.
If you do not want to do that work, Perhaps a default makefile with rules for
all types of files would make M-x compile usable as it is.
RE: emacs equivalent of vi %, Arnaldo Mandel, 2008/08/13
Re: emacs equivalent of vi %, Xah, 2008/08/13
Re: emacs equivalent of vi %, Scott Frazer, 2008/08/13
Re: emacs equivalent of vi %, Emmett Grogan, 2008/08/15
Re: emacs equivalent of vi %, Xah, 2008/08/15
Re: emacs equivalent of vi %,