[Top][All Lists]

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

Re: emacs equivalent of vi %

From: Emmett Grogan
Subject: Re: emacs equivalent of vi %
Date: Fri, 15 Aug 2008 19:02:54 +0200
User-agent: Thunderbird (X11/20080724)

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
;; 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
;;; 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,
then it'll call “perl” 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

reply via email to

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