From 70e4bb394f36940c4b72cd87d298d9cdabff5998 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 11 Jan 2018 22:20:05 -0500 Subject: [PATCH] * src/keyboard.c (kbd_buffer_get_event): Use 'switch' ... ...rather than a sequence of else-if. --- src/keyboard.c | 67 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index 714c8fee656..8e3f0e18c01 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -3873,8 +3873,10 @@ kbd_buffer_get_event (KBOARD **kbp, /* These two kinds of events get special handling and don't actually appear to the command loop. We return nil for them. */ - if (event->kind == SELECTION_REQUEST_EVENT - || event->kind == SELECTION_CLEAR_EVENT) + switch (event->kind) + { + case SELECTION_REQUEST_EVENT: + case SELECTION_CLEAR_EVENT: { #ifdef HAVE_X11 /* Remove it from the buffer before processing it, @@ -3890,9 +3892,10 @@ kbd_buffer_get_event (KBOARD **kbp, emacs_abort (); #endif } + break; #if defined (HAVE_NS) - else if (event->kind == NS_TEXT_EVENT) + case NS_TEXT_EVENT: { if (event->ie.code == KEY_NS_PUT_WORKING_TEXT) obj = list1 (intern ("ns-put-working-text")); @@ -3902,60 +3905,67 @@ kbd_buffer_get_event (KBOARD **kbp, if (used_mouse_menu) *used_mouse_menu = true; } + break; #endif #if defined (HAVE_X11) || defined (HAVE_NTGUI) \ || defined (HAVE_NS) - else if (event->kind == DELETE_WINDOW_EVENT) + case DELETE_WINDOW_EVENT: { /* Make an event (delete-frame (FRAME)). */ obj = list2 (Qdelete_frame, list1 (event->ie.frame_or_window)); kbd_fetch_ptr = event + 1; } + break; #endif #ifdef HAVE_NTGUI - else if (event->kind == END_SESSION_EVENT) + case END_SESSION_EVENT: { /* Make an event (end-session). */ obj = list1 (Qend_session); kbd_fetch_ptr = event + 1; } + break; #endif #if defined (HAVE_X11) || defined (HAVE_NTGUI) \ || defined (HAVE_NS) - else if (event->kind == ICONIFY_EVENT) + case ICONIFY_EVENT: { /* Make an event (iconify-frame (FRAME)). */ obj = list2 (Qiconify_frame, list1 (event->ie.frame_or_window)); kbd_fetch_ptr = event + 1; } - else if (event->kind == DEICONIFY_EVENT) + break; + case DEICONIFY_EVENT: { /* Make an event (make-frame-visible (FRAME)). */ obj = list2 (Qmake_frame_visible, list1 (event->ie.frame_or_window)); kbd_fetch_ptr = event + 1; } + break; #endif - else if (event->kind == BUFFER_SWITCH_EVENT) + case BUFFER_SWITCH_EVENT: { /* The value doesn't matter here; only the type is tested. */ XSETBUFFER (obj, current_buffer); kbd_fetch_ptr = event + 1; } + break; #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \ || defined (HAVE_NS) || defined (USE_GTK) - else if (event->kind == MENU_BAR_ACTIVATE_EVENT) + case MENU_BAR_ACTIVATE_EVENT: { kbd_fetch_ptr = event + 1; input_pending = readable_events (0); if (FRAME_LIVE_P (XFRAME (event->ie.frame_or_window))) x_activate_menubar (XFRAME (event->ie.frame_or_window)); } + break; #endif #ifdef HAVE_NTGUI - else if (event->kind == LANGUAGE_CHANGE_EVENT) + case LANGUAGE_CHANGE_EVENT: { /* Make an event (language-change FRAME CODEPAGE LANGUAGE-ID). */ obj = list4 (Qlanguage_change, @@ -3964,9 +3974,10 @@ kbd_buffer_get_event (KBOARD **kbp, make_number (event->ie.modifiers)); kbd_fetch_ptr = event + 1; } + break; #endif #ifdef USE_FILE_NOTIFY - else if (event->kind == FILE_NOTIFY_EVENT) + case FILE_NOTIFY_EVENT: { #ifdef HAVE_W32NOTIFY /* Make an event (file-notify (DESCRIPTOR ACTION FILE) CALLBACK). */ @@ -3976,12 +3987,14 @@ kbd_buffer_get_event (KBOARD **kbp, #endif kbd_fetch_ptr = event + 1; } + break; #endif /* USE_FILE_NOTIFY */ - else if (event->kind == SAVE_SESSION_EVENT) + case SAVE_SESSION_EVENT: { obj = list2 (Qsave_session, event->ie.arg); kbd_fetch_ptr = event + 1; } + break; /* Just discard these, by returning nil. With MULTI_KBOARD, these events are used as placeholders when we need to randomly delete events from the queue. @@ -3990,9 +4003,10 @@ kbd_buffer_get_event (KBOARD **kbp, even without MULTI_KBOARD.) */ /* On Windows NT/9X, NO_EVENT is used to delete extraneous mouse events during a popup-menu call. */ - else if (event->kind == NO_EVENT) + case NO_EVENT: kbd_fetch_ptr = event + 1; - else if (event->kind == HELP_EVENT) + break; + case HELP_EVENT: { Lisp_Object object, position, help, frame, window; @@ -4009,7 +4023,8 @@ kbd_buffer_get_event (KBOARD **kbp, obj = Fcons (Qhelp_echo, list5 (frame, help, window, object, position)); } - else if (event->kind == FOCUS_IN_EVENT) + break; + case FOCUS_IN_EVENT: { /* Notification of a FocusIn event. The frame receiving the focus is in event->frame_or_window. Generate a @@ -4035,7 +4050,8 @@ kbd_buffer_get_event (KBOARD **kbp, internal_last_event_frame = frame; kbd_fetch_ptr = event + 1; } - else if (event->kind == FOCUS_OUT_EVENT) + break; + case FOCUS_OUT_EVENT: { #ifdef HAVE_WINDOW_SYSTEM @@ -4053,39 +4069,45 @@ kbd_buffer_get_event (KBOARD **kbp, kbd_fetch_ptr = event + 1; } + break; #ifdef HAVE_DBUS - else if (event->kind == DBUS_EVENT) + case DBUS_EVENT: { obj = make_lispy_event (&event->ie); kbd_fetch_ptr = event + 1; } + break; #endif #if defined (HAVE_X11) || defined (HAVE_NTGUI) || defined (HAVE_NS) - else if (event->kind == MOVE_FRAME_EVENT) + case MOVE_FRAME_EVENT: { /* Make an event (move-frame (FRAME)). */ obj = list2 (Qmove_frame, list1 (event->ie.frame_or_window)); kbd_fetch_ptr = event + 1; } + break; #endif #ifdef HAVE_XWIDGETS - else if (event->kind == XWIDGET_EVENT) + case XWIDGET_EVENT: { obj = make_lispy_event (&event->ie); kbd_fetch_ptr = event + 1; } + break; #endif - else if (event->kind == CONFIG_CHANGED_EVENT) + case CONFIG_CHANGED_EVENT: { obj = make_lispy_event (&event->ie); kbd_fetch_ptr = event + 1; } - else if (event->kind == SELECT_WINDOW_EVENT) + break; + case SELECT_WINDOW_EVENT: { obj = list2 (Qselect_window, list1 (event->ie.frame_or_window)); kbd_fetch_ptr = event + 1; } - else + break; + default: { /* If this event is on a different frame, return a switch-frame this time, and leave the event in the queue for next time. */ @@ -4139,6 +4161,7 @@ kbd_buffer_get_event (KBOARD **kbp, kbd_fetch_ptr = event + 1; } } + } } /* Try generating a mouse motion event. */ else if (!NILP (do_mouse_tracking) && some_mouse_moved ()) -- 2.39.2