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

[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 2.0.0.16 (X11/20080724)

Xah:
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:
;;
;;;###autoload
;;;
(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."
(interactive)
(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]