diff options
| author | Dmitry Antipov | 2012-12-06 10:23:51 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2012-12-06 10:23:51 +0400 |
| commit | 565212e5983cdcc478ed34bcdbd63f154e5e418f (patch) | |
| tree | 3baf084ebfd04533d415cbf44c942f422236de62 | |
| parent | d8ad4d3ff9dcea9c581d72e1e9ec292ea18673b1 (diff) | |
| download | emacs-565212e5983cdcc478ed34bcdbd63f154e5e418f.tar.gz emacs-565212e5983cdcc478ed34bcdbd63f154e5e418f.zip | |
Avoid code duplication between prev_frame and next_frame.
* frame.c (candidate_frame): New function. Add comment.
(prev_frame, next_frame): Use it. Adjust comment.
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/frame.c | 162 |
2 files changed, 68 insertions, 100 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 795582c802b..d9e566eae69 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2012-12-06 Dmitry Antipov <dmantipov@yandex.ru> | ||
| 2 | |||
| 3 | Avoid code duplication between prev_frame and next_frame. | ||
| 4 | * frame.c (candidate_frame): New function. Add comment. | ||
| 5 | (prev_frame, next_frame): Use it. Adjust comment. | ||
| 6 | |||
| 1 | 2012-12-06 Eli Zaretskii <eliz@gnu.org> | 7 | 2012-12-06 Eli Zaretskii <eliz@gnu.org> |
| 2 | 8 | ||
| 3 | * callproc.c (Fcall_process_region) [!HAVE_MKSTEMP]: If mktemp | 9 | * callproc.c (Fcall_process_region) [!HAVE_MKSTEMP]: If mktemp |
diff --git a/src/frame.c b/src/frame.c index 3501fc36675..d94164e0c14 100644 --- a/src/frame.c +++ b/src/frame.c | |||
| @@ -895,13 +895,58 @@ DEFUN ("frame-list", Fframe_list, Sframe_list, | |||
| 895 | return frames; | 895 | return frames; |
| 896 | } | 896 | } |
| 897 | 897 | ||
| 898 | /* Return the next frame in the frame list after FRAME. | 898 | /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the |
| 899 | If MINIBUF is nil, exclude minibuffer-only frames. | 899 | same tty (for tty frames) or among frames which uses FRAME's keyboard. |
| 900 | If MINIBUF is a window, include only its own frame | 900 | If MINIBUF is nil, do not consider minibuffer-only candidate. |
| 901 | and any frame now using that window as the minibuffer. | 901 | If MINIBUF is `visible', do not consider an invisible candidate. |
| 902 | If MINIBUF is `visible', include all visible frames. | 902 | If MINIBUF is a window, consider only its own frame and candidate now |
| 903 | If MINIBUF is 0, include all visible and iconified frames. | 903 | using that window as the minibuffer. |
| 904 | Otherwise, include all frames. */ | 904 | If MINIBUF is 0, consider candidate if it is visible or iconified. |
| 905 | Otherwise consider any candidate and return nil if CANDIDATE is not | ||
| 906 | acceptable. */ | ||
| 907 | |||
| 908 | static Lisp_Object | ||
| 909 | candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf) | ||
| 910 | { | ||
| 911 | struct frame *c = XFRAME (candidate), *f = XFRAME (frame); | ||
| 912 | |||
| 913 | if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f) | ||
| 914 | && FRAME_KBOARD (c) == FRAME_KBOARD (f)) | ||
| 915 | || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f) | ||
| 916 | && FRAME_TTY (c) == FRAME_TTY (f))) | ||
| 917 | { | ||
| 918 | if (NILP (minibuf)) | ||
| 919 | { | ||
| 920 | if (!FRAME_MINIBUF_ONLY_P (c)) | ||
| 921 | return candidate; | ||
| 922 | } | ||
| 923 | else if (EQ (minibuf, Qvisible)) | ||
| 924 | { | ||
| 925 | FRAME_SAMPLE_VISIBILITY (c); | ||
| 926 | if (FRAME_VISIBLE_P (c)) | ||
| 927 | return candidate; | ||
| 928 | } | ||
| 929 | else if (WINDOWP (minibuf)) | ||
| 930 | { | ||
| 931 | if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf) | ||
| 932 | || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate) | ||
| 933 | || EQ (WINDOW_FRAME (XWINDOW (minibuf)), | ||
| 934 | FRAME_FOCUS_FRAME (c))) | ||
| 935 | return candidate; | ||
| 936 | } | ||
| 937 | else if (XFASTINT (minibuf) == 0) | ||
| 938 | { | ||
| 939 | FRAME_SAMPLE_VISIBILITY (c); | ||
| 940 | if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c)) | ||
| 941 | return candidate; | ||
| 942 | } | ||
| 943 | else | ||
| 944 | return candidate; | ||
| 945 | } | ||
| 946 | return Qnil; | ||
| 947 | } | ||
| 948 | |||
| 949 | /* Return the next frame in the frame list after FRAME. */ | ||
| 905 | 950 | ||
| 906 | static Lisp_Object | 951 | static Lisp_Object |
| 907 | next_frame (Lisp_Object frame, Lisp_Object minibuf) | 952 | next_frame (Lisp_Object frame, Lisp_Object minibuf) |
| @@ -910,72 +955,24 @@ next_frame (Lisp_Object frame, Lisp_Object minibuf) | |||
| 910 | int passed = 0; | 955 | int passed = 0; |
| 911 | 956 | ||
| 912 | /* There must always be at least one frame in Vframe_list. */ | 957 | /* There must always be at least one frame in Vframe_list. */ |
| 913 | if (! CONSP (Vframe_list)) | 958 | eassert (CONSP (Vframe_list)); |
| 914 | emacs_abort (); | ||
| 915 | |||
| 916 | /* If this frame is dead, it won't be in Vframe_list, and we'll loop | ||
| 917 | forever. Forestall that. */ | ||
| 918 | CHECK_LIVE_FRAME (frame); | ||
| 919 | 959 | ||
| 920 | while (1) | 960 | while (passed < 2) |
| 921 | FOR_EACH_FRAME (tail, f) | 961 | FOR_EACH_FRAME (tail, f) |
| 922 | { | 962 | { |
| 923 | if (passed | 963 | if (passed) |
| 924 | && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame)) | ||
| 925 | && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame))) | ||
| 926 | || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame)) | ||
| 927 | && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))) | ||
| 928 | { | 964 | { |
| 929 | /* Decide whether this frame is eligible to be returned. */ | 965 | f = candidate_frame (f, frame, minibuf); |
| 930 | 966 | if (!NILP (f)) | |
| 931 | /* If we've looped all the way around without finding any | ||
| 932 | eligible frames, return the original frame. */ | ||
| 933 | if (EQ (f, frame)) | ||
| 934 | return f; | ||
| 935 | |||
| 936 | /* Let minibuf decide if this frame is acceptable. */ | ||
| 937 | if (NILP (minibuf)) | ||
| 938 | { | ||
| 939 | if (! FRAME_MINIBUF_ONLY_P (XFRAME (f))) | ||
| 940 | return f; | ||
| 941 | } | ||
| 942 | else if (EQ (minibuf, Qvisible)) | ||
| 943 | { | ||
| 944 | FRAME_SAMPLE_VISIBILITY (XFRAME (f)); | ||
| 945 | if (FRAME_VISIBLE_P (XFRAME (f))) | ||
| 946 | return f; | ||
| 947 | } | ||
| 948 | else if (INTEGERP (minibuf) && XINT (minibuf) == 0) | ||
| 949 | { | ||
| 950 | FRAME_SAMPLE_VISIBILITY (XFRAME (f)); | ||
| 951 | if (FRAME_VISIBLE_P (XFRAME (f)) | ||
| 952 | || FRAME_ICONIFIED_P (XFRAME (f))) | ||
| 953 | return f; | ||
| 954 | } | ||
| 955 | else if (WINDOWP (minibuf)) | ||
| 956 | { | ||
| 957 | if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf) | ||
| 958 | || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f) | ||
| 959 | || EQ (WINDOW_FRAME (XWINDOW (minibuf)), | ||
| 960 | FRAME_FOCUS_FRAME (XFRAME (f)))) | ||
| 961 | return f; | ||
| 962 | } | ||
| 963 | else | ||
| 964 | return f; | 967 | return f; |
| 965 | } | 968 | } |
| 966 | |||
| 967 | if (EQ (frame, f)) | 969 | if (EQ (frame, f)) |
| 968 | passed++; | 970 | passed++; |
| 969 | } | 971 | } |
| 972 | return frame; | ||
| 970 | } | 973 | } |
| 971 | 974 | ||
| 972 | /* Return the previous frame in the frame list before FRAME. | 975 | /* Return the previous frame in the frame list before FRAME. */ |
| 973 | If MINIBUF is nil, exclude minibuffer-only frames. | ||
| 974 | If MINIBUF is a window, include only its own frame | ||
| 975 | and any frame now using that window as the minibuffer. | ||
| 976 | If MINIBUF is `visible', include all visible frames. | ||
| 977 | If MINIBUF is 0, include all visible and iconified frames. | ||
| 978 | Otherwise, include all frames. */ | ||
| 979 | 976 | ||
| 980 | static Lisp_Object | 977 | static Lisp_Object |
| 981 | prev_frame (Lisp_Object frame, Lisp_Object minibuf) | 978 | prev_frame (Lisp_Object frame, Lisp_Object minibuf) |
| @@ -989,43 +986,9 @@ prev_frame (Lisp_Object frame, Lisp_Object minibuf) | |||
| 989 | { | 986 | { |
| 990 | if (EQ (frame, f) && !NILP (prev)) | 987 | if (EQ (frame, f) && !NILP (prev)) |
| 991 | return prev; | 988 | return prev; |
| 992 | 989 | f = candidate_frame (f, frame, minibuf); | |
| 993 | if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame)) | 990 | if (!NILP (f)) |
| 994 | && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame))) | 991 | prev = f; |
| 995 | || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame)) | ||
| 996 | && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))) | ||
| 997 | { | ||
| 998 | /* Decide whether this frame is eligible to be returned, | ||
| 999 | according to minibuf. */ | ||
| 1000 | if (NILP (minibuf)) | ||
| 1001 | { | ||
| 1002 | if (! FRAME_MINIBUF_ONLY_P (XFRAME (f))) | ||
| 1003 | prev = f; | ||
| 1004 | } | ||
| 1005 | else if (WINDOWP (minibuf)) | ||
| 1006 | { | ||
| 1007 | if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf) | ||
| 1008 | || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f) | ||
| 1009 | || EQ (WINDOW_FRAME (XWINDOW (minibuf)), | ||
| 1010 | FRAME_FOCUS_FRAME (XFRAME (f)))) | ||
| 1011 | prev = f; | ||
| 1012 | } | ||
| 1013 | else if (EQ (minibuf, Qvisible)) | ||
| 1014 | { | ||
| 1015 | FRAME_SAMPLE_VISIBILITY (XFRAME (f)); | ||
| 1016 | if (FRAME_VISIBLE_P (XFRAME (f))) | ||
| 1017 | prev = f; | ||
| 1018 | } | ||
| 1019 | else if (XFASTINT (minibuf) == 0) | ||
| 1020 | { | ||
| 1021 | FRAME_SAMPLE_VISIBILITY (XFRAME (f)); | ||
| 1022 | if (FRAME_VISIBLE_P (XFRAME (f)) | ||
| 1023 | || FRAME_ICONIFIED_P (XFRAME (f))) | ||
| 1024 | prev = f; | ||
| 1025 | } | ||
| 1026 | else | ||
| 1027 | prev = f; | ||
| 1028 | } | ||
| 1029 | } | 992 | } |
| 1030 | 993 | ||
| 1031 | /* We've scanned the entire list. */ | 994 | /* We've scanned the entire list. */ |
| @@ -1056,7 +1019,6 @@ Otherwise, include all frames. */) | |||
| 1056 | { | 1019 | { |
| 1057 | if (NILP (frame)) | 1020 | if (NILP (frame)) |
| 1058 | frame = selected_frame; | 1021 | frame = selected_frame; |
| 1059 | |||
| 1060 | CHECK_LIVE_FRAME (frame); | 1022 | CHECK_LIVE_FRAME (frame); |
| 1061 | return next_frame (frame, miniframe); | 1023 | return next_frame (frame, miniframe); |
| 1062 | } | 1024 | } |