all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* emacs equivalent of vi %
@ 2008-08-13  6:52 Rustom Mody
  2008-08-13  9:34 ` Lennart Borgman (gmail)
  2008-08-13 11:37 ` Arnaldo Mandel
  0 siblings, 2 replies; 19+ messages in thread
From: Rustom Mody @ 2008-08-13  6:52 UTC (permalink / raw)
  To: help-gnu-emacs

In vi one can do, for example,
:!gcc %
and the current file gets compiled -- ingeneral :
:!someCommand options % otherStuff
and the filename gets interpolated.
Is there any way to get the '%' behavior in emacs?
[Note: I know about compile; I am asking a more general question about
getting the filename]




^ permalink raw reply	[flat|nested] 19+ messages in thread
[parent not found: <mailman.16547.1218610362.18990.help-gnu-emacs@gnu.org>]
* Re: emacs equivalent of vi %
@ 2008-08-15 17:02 Emmett Grogan
  0 siblings, 0 replies; 19+ messages in thread
From: Emmett Grogan @ 2008-08-15 17:02 UTC (permalink / raw)
  To: help-gnu-emacs

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





^ permalink raw reply	[flat|nested] 19+ messages in thread
[parent not found: <mailman.16820.1218819789.18990.help-gnu-emacs@gnu.org>]

end of thread, other threads:[~2008-08-16  0:14 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-13  6:52 emacs equivalent of vi % Rustom Mody
2008-08-13  9:34 ` Lennart Borgman (gmail)
2008-08-13 10:44   ` Rustom Mody
2008-08-13 11:10     ` Lennart Borgman (gmail)
2008-08-13 13:24       ` Rustom Mody
2008-08-13 23:27         ` Nikolaj Schumacher
2008-08-13 23:50           ` Nikolaj Schumacher
2008-08-14  0:14             ` Lennart Borgman (gmail)
2008-08-14  2:04               ` Kevin Rodgers
2008-08-14  7:13               ` Rustom Mody
2008-08-14 10:01                 ` Lennart Borgman (gmail)
2008-08-15  1:38                 ` Kevin Rodgers
     [not found]           ` <mailman.16634.1218671422.18990.help-gnu-emacs@gnu.org>
2008-08-14  2:51             ` Jason Rumney
2008-08-13 11:37 ` Arnaldo Mandel
     [not found] <mailman.16547.1218610362.18990.help-gnu-emacs@gnu.org>
2008-08-13 15:14 ` Xah
2008-08-13 17:24 ` Scott Frazer
  -- strict thread matches above, loose matches on Subject: below --
2008-08-15 17:02 Emmett Grogan
     [not found] <mailman.16820.1218819789.18990.help-gnu-emacs@gnu.org>
2008-08-15 19:13 ` Xah
2008-08-16  0:14 ` Chat

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.