views:

72

answers:

3

I would like to be able to hit <Print Screen> in emacs and trigger a commit in a git repository. My lisp is pretty rusty and know this is broken, but don't know where:

( defun tip-local-write nil "Write to store" ( interactive )
     ( save-buffer )
     ( change-directory "~/tip" )
     ( shell-command "git commit -m checkpoint ." )
     ( shell-command "git submodule foreach git commit -m checkpoint . \\\|\\\| true" ) ) )
( global-set-key [?\M-1] 'tip-local-write )

Currently it is binding to ^1 because I don't know how to represent the <Print Screen> button.

A: 

You need to run this first:

(w32-register-hot-key [snapshot])

After which, you can do this:

(global-set-key [snapshot] 'tip-local-write ) 
mschaef
In the interest of becoming a better contributor to Stack Overflow (I'm new around here), what's wrong with this contribution that it doesn't get mod points? It works (I tested it with a local installation of Emacs), and answered the question that was asked. (I'm less concerned about the points themselves and more concerned about producing useful contributions to the site. I'm taking points to be a proxy for that.)
mschaef
@mschaef Regarding becoming a better contributor, you just keep at it b/c persistence is key. And, about your answer, it didn't work for me until I'd also done `(w32-register-hot-key [print])`. No idea why, but there you go.
Trey Jackson
+2  A: 

A general trick that works for binding keystrokes you don't know the Emacs names for:

  • Hit M-x global-set-key RET <your keystroke> RET <name of function>

Then, hit C-x ESC ESC (which is repeat-complex-command). In the minibufer, you should see a global-set-key function invocation that you can copy into your .emacs file.

ShreevatsaR
I use `C-h k`, which is probably somewhat simpler
Michael Mrozek
You're right, C-h k and C-h c are simpler, but I remember there was some reason for preferring this trick... I can't remember it now. Probably it had merely something to do with tab auto-completion helping you type less. :-)
ShreevatsaR
+2  A: 

You can get the print-screen key with

(kbd "<print>")

As for the actual committing, it's probably much easier to use the version control functions emacs provides:

(vc-git-checkin "." nil "checkpoint")
Michael Mrozek