all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Xah <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: emacs equivalent of vi %
Date: Fri, 15 Aug 2008 12:13:29 -0700 (PDT)	[thread overview]
Message-ID: <18b791f9-e4ad-421e-95b1-529d746b38b8@b30g2000prf.googlegroups.com> (raw)
In-Reply-To: mailman.16820.1218819789.18990.help-gnu-emacs@gnu.org

On Aug 15, 10:02 am, Emmett Grogan <emmettgro...@freenet.de> wrote:
> 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

O, thank you.

The code i did could use some improvement. Right now it doesn't run in
the background. i.e. while it executes, your emacs is as good as
frozen. I meant to make it a background process... but there's more
coding needs to be done to get the outpt when it is done using some
elisp's “process sentinel”...

also, the hard-coded file name suffix and program name map could
perhaps employ magic-mode-alist and or auto-mode-alist...

anyone's very welcome to fork it of course.

  Xah
∑ http://xahlee.org/

       reply	other threads:[~2008-08-15 19:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.16820.1218819789.18990.help-gnu-emacs@gnu.org>
2008-08-15 19:13 ` Xah [this message]
2008-08-16  0:14 ` emacs equivalent of vi % Chat
2008-08-15 17:02 Emmett Grogan
     [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-13  6:52 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=18b791f9-e4ad-421e-95b1-529d746b38b8@b30g2000prf.googlegroups.com \
    --to=xahlee@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.