unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* C-c C-c for a file extension
@ 2006-05-04 20:59 Rares Vernica
  2006-05-04 23:43 ` Kevin Rodgers
  2006-05-04 23:54 ` liyer.vijay
  0 siblings, 2 replies; 5+ messages in thread
From: Rares Vernica @ 2006-05-04 20:59 UTC (permalink / raw)


Hi,

How can I define a C-c C-c command for a certain file extension.

For example, I have the gnuplot (.plt) file and I would like to run 
"gnuplot %f" (where %f is the file name) when I press C-c C-c on that file.

Thanks a lot,
Ray

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C-c C-c for a file extension
  2006-05-04 20:59 C-c C-c for a file extension Rares Vernica
@ 2006-05-04 23:43 ` Kevin Rodgers
  2006-05-05  7:50   ` Reiner Steib
  2006-05-04 23:54 ` liyer.vijay
  1 sibling, 1 reply; 5+ messages in thread
From: Kevin Rodgers @ 2006-05-04 23:43 UTC (permalink / raw)


Rares Vernica wrote:
> How can I define a C-c C-c command for a certain file extension.

Usuallly a file extension is associated with a major mode (via
auto-mode-alist).  What does `C-h v major-mode' tell you when visiting
such a file?

> For example, I have the gnuplot (.plt) file and I would like to run 
> "gnuplot %f" (where %f is the file name) when I press C-c C-c on that file.

Hmmm, when I visit a .plt file it's in Fundamental mode.  You could
define your own Gnuplot mode (with a local keymap that binds `C-c C-c'
to an Emacs command that runs gnuplot on the visited file) and associate
it with the .plt extension (e.g. with define-generic-mode), but it'd be
a lot easier to use `M-x compile' in conjunction with this:

(defun set-gnuplot-compile-command ()
   (set (make-local-variable 'compile-command)
        (format "gnuplot %s" (file-name-nondirectory buffer-file-name))))

(add-hook 'find-file-hook 'set-gnuplot-compile-command)
(add-hook 'find-file-not-found-hooks 'set-gnuplot-compile-command)

-- 
Kevin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C-c C-c for a file extension
  2006-05-04 20:59 C-c C-c for a file extension Rares Vernica
  2006-05-04 23:43 ` Kevin Rodgers
@ 2006-05-04 23:54 ` liyer.vijay
  1 sibling, 0 replies; 5+ messages in thread
From: liyer.vijay @ 2006-05-04 23:54 UTC (permalink / raw)


The answer would be slightly different if your gnuplot files have a
major mode (do they?), but for now, you can just do

M-: (local-set-key "\C-c\C-c" 'compile)

And then C-c C-c will run the compile command.  The first time you call
compile, it will start with "make -k" but you can change that to
gnuplot <filename>

If you're really lazy, you could do something like this:

(defun compile-gnuplot (filename)
  "Runs gnuplot on FILENAME taking (buffer-file-name) as default."
  (interactive (let ((name (buffer-file-name)))
                 (list (read-string (format "Filename (default %s) "
name)
                                  nil
                                  name))))
  (compile (format "gnuplot %s" filename)))

Then, in your buffer,
M-: (local-set-key "\C-c\C-c" 'compile-gnuplot)

I'm new to emacs lisp so comments on code also requested.  Ideally, the
function should also ask to save the buffer if it is modified.  But I
don't know elisp that well.

Hope this helps.

Cheers
Vijay Lakshminarayanan

> Can we quote you on that?
A long time ago, someone in the Lisp industry told me it was poor form
quote people; it suggests that they lack value.
	-- Kent M Pitman <pitman@world.std.com> in comp.lang.lisp

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C-c C-c for a file extension
  2006-05-04 23:43 ` Kevin Rodgers
@ 2006-05-05  7:50   ` Reiner Steib
  2006-05-12  3:12     ` Rares Vernica
  0 siblings, 1 reply; 5+ messages in thread
From: Reiner Steib @ 2006-05-05  7:50 UTC (permalink / raw)


On Fri, May 05 2006, Kevin Rodgers wrote:

> Rares Vernica wrote:
>> For example, I have the gnuplot (.plt) file and I would like to run
>> "gnuplot %f" (where %f is the file name) when I press C-c C-c on
>> that file.
>
> Hmmm, when I visit a .plt file it's in Fundamental mode.  You could
> define your own Gnuplot mode

gnuplot comes with a gnuplot mode in gnuplot.el (and gnuplot-gui.el).

> (with a local keymap that binds `C-c C-c' to an Emacs command that
> runs gnuplot on the visited file)

gnuplot.el has `C-c C-b' for `gnuplot-send-buffer-to-gnuplot'.  It
would be better if they'd bind `gnuplot-send-buffer-to-gnuplot' or
`gnuplot-send-file-to-gnuplot' instead of
`gnuplot-gui-set-options-and-insert' to `C-c C-c'.

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C-c C-c for a file extension
  2006-05-05  7:50   ` Reiner Steib
@ 2006-05-12  3:12     ` Rares Vernica
  0 siblings, 0 replies; 5+ messages in thread
From: Rares Vernica @ 2006-05-12  3:12 UTC (permalink / raw)


I installed gnuplot-module and everything works great.

Thanks a lot,
Ray

Reiner Steib wrote:
> On Fri, May 05 2006, Kevin Rodgers wrote:
> 
>> Rares Vernica wrote:
>>> For example, I have the gnuplot (.plt) file and I would like to run
>>> "gnuplot %f" (where %f is the file name) when I press C-c C-c on
>>> that file.
>> Hmmm, when I visit a .plt file it's in Fundamental mode.  You could
>> define your own Gnuplot mode
> 
> gnuplot comes with a gnuplot mode in gnuplot.el (and gnuplot-gui.el).
> 
>> (with a local keymap that binds `C-c C-c' to an Emacs command that
>> runs gnuplot on the visited file)
> 
> gnuplot.el has `C-c C-b' for `gnuplot-send-buffer-to-gnuplot'.  It
> would be better if they'd bind `gnuplot-send-buffer-to-gnuplot' or
> `gnuplot-send-file-to-gnuplot' instead of
> `gnuplot-gui-set-options-and-insert' to `C-c C-c'.
> 
> Bye, Reiner.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-05-12  3:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-04 20:59 C-c C-c for a file extension Rares Vernica
2006-05-04 23:43 ` Kevin Rodgers
2006-05-05  7:50   ` Reiner Steib
2006-05-12  3:12     ` Rares Vernica
2006-05-04 23:54 ` liyer.vijay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).