unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] frame.c: focus hooks
@ 2013-11-17 17:50 Brian Jenkins
  2013-11-17 18:29 ` Bozhidar Batsov
                   ` (3 more replies)
  0 siblings, 4 replies; 39+ messages in thread
From: Brian Jenkins @ 2013-11-17 17:50 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 446 bytes --]

Hello.

I'd like to contribute the attached patch, which adds hooks into gain and
loss of focus events.

This allows saving all buffers on loss of focus.  (Alt-tabbing between
an editor and browser is a popular workflow for web programmers.)

It also allows reversion of buffers on regain of focus, convenient if
one is switching between Emacs and another editor.

People will probably find other handy uses for these hooks.

Best,
Brian Jenkins

[-- Attachment #1.2: Type: text/html, Size: 651 bytes --]

[-- Attachment #2: focus-hooks.patch --]
[-- Type: application/octet-stream, Size: 1629 bytes --]

diff --git a/src/frame.c b/src/frame.c
index 4494edda..6c89b7e 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -109,6 +109,8 @@ Lisp_Object Qalpha;
 
 Lisp_Object Qface_set_after_frame_default;
 
+static Lisp_Object Qfocus_in_hook;
+static Lisp_Object Qfocus_out_hook;
 static Lisp_Object Qdelete_frame_functions;
 
 static Lisp_Object Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource;
@@ -893,6 +895,7 @@ is not generated.
 This function checks if blink-cursor timers should be turned on again.  */)
   (Lisp_Object event)
 {
+  Frun_hooks (1, &Qfocus_in_hook);
   return call0 (intern ("blink-cursor-check"));
 }
 
@@ -903,6 +906,7 @@ Focus out events occur when no frame has focus.
 This function checks if blink-cursor timers should be turned off.  */)
   (Lisp_Object event)
 {
+  Frun_hooks (1, &Qfocus_out_hook);
   return call0 (intern ("blink-cursor-suspend"));
 }
 
@@ -4465,6 +4469,16 @@ when the mouse is over clickable text.  */);
 The pointer becomes visible again when the mouse is moved.  */);
   Vmake_pointer_invisible = Qt;
 
+  DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
+               doc: /* Normal hook run when a frame gains input focus.*/);
+  Vfocus_in_hook = Qnil;
+  DEFSYM (Qfocus_in_hook, "focus-in-hook");
+
+  DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
+               doc: /* Normal hook run when a frame loses input focus.*/);
+  Vfocus_out_hook = Qnil;
+  DEFSYM (Qfocus_out_hook, "focus-out-hook");
+
   DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
 	       doc: /* Functions run before deleting a frame.
 The functions are run with one arg, the frame to be deleted.

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

end of thread, other threads:[~2014-01-14 18:10 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-17 17:50 [PATCH] frame.c: focus hooks Brian Jenkins
2013-11-17 18:29 ` Bozhidar Batsov
2013-11-17 22:25   ` Brian Jenkins
2013-11-17 22:33     ` Drew Adams
2013-11-18 13:24       ` Brian Jenkins
2013-11-18 14:53         ` Drew Adams
2013-11-19  0:19         ` Stefan Monnier
2013-11-19  8:26         ` Stephen J. Turnbull
2013-11-19 14:10           ` Bozhidar Batsov
2013-11-20  3:10             ` Brian Jenkins
2013-11-18  8:20     ` Bozhidar Batsov
2013-11-18 13:32   ` Stefan Monnier
     [not found]     ` <CAM9Zgm18uL7+PJ+60NjZqtjZJ6tUV77xUbFhXh7UPwqs==1=hg@mail.gmail.com>
2013-11-18 14:20       ` Fwd: " Bozhidar Batsov
2013-11-18 14:23     ` Brian Jenkins
2013-11-18 18:44   ` Richard Stallman
2013-11-18 19:49     ` Brian Jenkins
2013-11-19  6:02       ` Richard Stallman
2013-11-19 18:14         ` Brian Jenkins
2013-11-19 18:53           ` Drew Adams
2013-11-20  0:52             ` Brian Jenkins
2013-11-19 23:42           ` Richard Stallman
2013-11-20  0:52             ` Josh
2013-11-20  3:16               ` Stefan Monnier
2013-11-20  3:36                 ` Josh
2013-11-20  7:34                   ` martin rudalics
2014-01-09 17:01                     ` Josh
2014-01-11 10:25                       ` martin rudalics
2014-01-11 19:05                         ` Josh
2014-01-12  9:54                           ` martin rudalics
2014-01-14 17:30                             ` Josh
2014-01-14 18:10                               ` martin rudalics
2014-01-10 17:31                   ` Stefan Monnier
2014-01-11 19:06                     ` Josh
2013-11-20  0:53             ` Brian Jenkins
2013-11-20  7:46               ` Jarek Czekalski
2013-11-17 19:28 ` Glenn Morris
2013-11-17 21:19 ` Stefan Monnier
2013-11-18  4:11 ` Leo Liu
     [not found]   ` <CADTx1Oy5pUmb9sPU6jm0yt1hJtvgJmfDtZQpeFakmHknhEXE=A@mail.gmail.com>
2013-11-18 13:33     ` Fwd: " Brian Jenkins

Code repositories for project(s) associated with this public inbox

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

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).